nim-works / phy

compiler and vm experiments
MIT License
3 stars 2 forks source link

lang: add locals and assignments #55

Closed zerbina closed 1 month ago

zerbina commented 1 month ago

Summary

Details

Language

The specification for assignments already covers the copy/move/ destruction behaviour, although there's current no way to test it.

Current Limitations

For the initial version, the additions are kept as simple as possible. Notably:

The plan is to lift/remove all of the above limitations/restrictions/ shortcomings at a later date.

Source2IL

Tests are added to ensure the declarations and assignments work as specified.


To-Do

zerbina commented 1 month ago

One thing that's also not present, when compared to NimSkull, is the style-insensitivity for identifiers. Personally, I like NimSkull's style-insensitivity rules, and they're something I would also add to Phy, but it's not something that should happen as part of this PR.

zerbina commented 1 month ago

In order to not treat declarations as expression, the language grammar grammar needs to be extended with groups, so that the Exprs grammar can be changed to:

(Exprs (<local_decl>* <expr>)+)

* matches greedily, which is why (Exprs <expr_or_decl>* <expr>) cannot work.

~I'll make a separate PR for this extension.~

Edit: For the moment, it's simpler to treat declarations as expressions, so I'm not going to change the current behaviour. Treating declarations as expression might also be the better long-term direction.