Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't instantiate r-value ModuleReferences #5

Closed
kwikius opened this issue Oct 2, 2022 · 2 comments
Closed

Can't instantiate r-value ModuleReferences #5

kwikius opened this issue Oct 2, 2022 · 2 comments

Comments

@kwikius
Copy link
Owner

kwikius commented Oct 2, 2022

ar = [ module cube(10)];
m = ar[0];
m();  // ok instantiate cube
ar[0]();  // syntax error

Currently the workaround is to create an l-value ( e.g a name to assign the module_reference) and instantiate that as shown above.
Allowing instantiation of r-values will require mods to the parser

@kwikius
Copy link
Owner Author

kwikius commented Oct 2, 2022

One syntax which works is to wrap the expression in brackets

ar = [ module cube(10)];
(ar[0])();  // 

ar1 = [ module cube];
(ar1[0])(10);  // showing args to instantiation

Parser.y is modified to

instantiation_expr
     : module_id
       { $$ = $1;}
     | '(' expr ')'
           { $$ = $2;}
      ;

single_module_instantiation
        : instantiation_expr '(' arguments ')'
            {
                $$ = new ModuleInstantiation($1, *$3, LOCD("modulecall", @$));
                free($1);
                delete $3;
            }
        ;

@kwikius
Copy link
Owner Author

kwikius commented Oct 2, 2022

Fixed by 2a33ede

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant