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

Implement <const> from Lua 5.4 #487

Open
hugomg opened this issue Sep 27, 2021 · 3 comments
Open

Implement <const> from Lua 5.4 #487

hugomg opened this issue Sep 27, 2021 · 3 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@hugomg
Copy link
Member

hugomg commented Sep 27, 2021

It would be nice if we implemented Lua 5.4 variable attributes in Pallene. We can start with <const>, which should be the easiest one to implement. When we get that working, it will pave the way for <close>.

local x <const> = 2
x = 10 --  this should be a compile-time error
@hugomg hugomg added enhancement New feature or request good first issue Good for newcomers labels Sep 27, 2021
@sudojarvis
Copy link

could you suggest from where I can start? I am a newbie to this.

@hugomg
Copy link
Member Author

hugomg commented Oct 5, 2021

Absolutely, help is always welcome :)

First step would be to teach the compiler how to parse the const declarations. We would have to modify the ast.lua, to add an extra field somewhere which says if a variable declaration is constant. (I haven't stopped to think about what node should get an extra field. Do you have a suggestion?). After this, we will have to modify the recursive descent parser in the parser.lua, to teach it how to parse the const declaration. This might be a good place for a first pull request.

The second pull request would be to modify the typechecker to enforce the requirement that the const variables are not reassigned.

It's normal if there are questions along the way, don't be afraid to ask.

@srijan-paul
Copy link
Member

For the type checking, a simple way could be to add a _is_const annotation / field to every symbol in the checker.
Then for assignment nodes, make sure no symbol in the LHS has the is_const annotation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants