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

Make names declared as constants immutable #13

Merged
merged 4 commits into from
Feb 21, 2020

Conversation

arsalan0c
Copy link
Collaborator

@arsalan0c arsalan0c commented Feb 14, 2020

add #12

This is done by storing an additional variable (is_variable) which indicates whether a name was declared as a variable. When assigning a value to a name, the value of this variable is then checked. If it is true, (eg. for names declared with let), then the assignment is allowed. Otherwise, an error is thrown.

@arsalan0c arsalan0c self-assigned this Feb 14, 2020
@arsalan0c arsalan0c added the enhancement New feature or request label Feb 14, 2020
@arsalan0c
Copy link
Collaborator Author

arsalan0c commented Feb 14, 2020

We might need another way to automatically test this due to the inability to catch errors in Source

evaluator.js Show resolved Hide resolved
evaluator.js Outdated Show resolved Hide resolved
evaluator.js Outdated Show resolved Hide resolved
@anubh-v
Copy link
Owner

anubh-v commented Feb 14, 2020

We might need another way to automatically test this due to the inability to catch errors in Source

We could add some data structure (at the global level) and use it to track errors. And then inspect it in the tests.

evaluator.js Outdated Show resolved Hide resolved
evaluator.js Outdated Show resolved Hide resolved
@arsalan0c
Copy link
Collaborator Author

arsalan0c commented Feb 17, 2020

We might need another way to automatically test this due to the inability to catch errors in Source

We could add some data structure (at the global level) and use it to track errors. And then inspect it in the tests.

Could you clarify how we could use a data structure to track errors?
As my understanding is that when testing it in Source, the test program will abort due to an error.

For example, if the following is a test then an error will be thrown due to constant reassignment.

parse_and_eval("const x = 2; x = 4; x;");

assert_equal(2, final_result);

evaluator.js Show resolved Hide resolved
evaluator.js Show resolved Hide resolved
evaluator.js Outdated Show resolved Hide resolved
@arsalan0c arsalan0c merged commit 81c8b83 into master Feb 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants