lfortran icon indicating copy to clipboard operation
lfortran copied to clipboard

Template instantiation syntax

Open Oshanath opened this issue 3 years ago • 8 comments

@certik This is what I came up with. It doesn't work yet. When trying to generate asr it says

Token ')' is unexpected here
  --> examples/swap_m.f90:27:32
   |
27 |         instantiate swap_t(real), only: swap => swap_generic
   |                                ^ 
  • Maybe it's because I used the wrong type for the var types list.

  • In this case I used decl_star. Maybe that's where I went wrong. Should it just be id and convert it into types in ASR?

  • Or should it be var_type, in which case there is no var_type_star yet, which I think should be used in this case.

  • If this is the case should I create a new type var_type_star?

I would like some help to move forward.

Oshanath avatar Jul 31 '22 15:07 Oshanath

Can you please rebase your work on top of the latest master? (Or just merge master into your PR and resolve all conflicts.)

certik avatar Jul 31 '22 15:07 certik

Yes, you should create var_type_plus, which is one or more var_type, separated by a comma. Good point.

certik avatar Jul 31 '22 16:07 certik

Otherwise I think you got it! Thanks for working on this. After this works, we can meet and work on getting it instantiated in ASR.

certik avatar Jul 31 '22 16:07 certik

I think we can treat the instantiation like a "use" statement. So just add it next to the use statement in the parser. In AST I think it is already defined next to the use statement, so that should work.

certik avatar Jul 31 '22 17:07 certik

I still can't get the Instantiate node to print. Maybe there is something missing in the printing function. Could you please tell me where that file is?

Oshanath avatar Jul 31 '22 18:07 Oshanath

I am not sure, I would have to debug it. I can do that tomorrow.

certik avatar Jul 31 '22 19:07 certik

TODO:

  • [ ] implement visit_Instantiate in the symbol table visitor (just empty function)
  • [ ] Get --show-asr working again, update tests

certik avatar Aug 02 '22 07:08 certik

The ci fails because there is an unused parameter in visit_Instantiate(). But it'll be gone when I actually implement that function.

Oshanath avatar Aug 03 '22 10:08 Oshanath

Merged as part of #90.

certik avatar Oct 04 '22 23:10 certik