Implement Maths operations in constant expressions #3732
+1,261
−320
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #1488
This PR implements support for binary operations in constants.
A few notes:
It's still missing tests. This probably needs a lot of tests.
This is implemented differently on Erlang and Javascript, due to the different languages being somewhat different.
For example, this code:
Compiles to this Javascript:
And this erlang:
Although this constant folding process could be done in the analysis stage instead and be applied to javascript as well.
I've been having some trouble trying to get the formatter to play nicely with this; I still don't really understand how it works. If someone who is more familiar with it could point me in the right direction, that would be amazing.
I'm not super happy with the parser code for constant binary operations: I had to copy a lot of the expression-parsing code. It might be good to merge this code somehow.