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

(all) Add support for postfix increment and decrement #17

Merged
merged 1 commit into from
Feb 4, 2020

Conversation

perlun
Copy link
Collaborator

@perlun perlun commented Feb 2, 2020

This is not ready yet, will complete another day. Reasonably complete now.

Things currently missing:

  • Support for decrement also, not just increment

  • Ensure that we put this at a reasonable level of precedence. (The way I did it now was just a slightly lame approximation)

    Maybe we can live with this as it is now after all. Right now I put it between "assignment" and "logical or". I would love to detect invalid usages such as foo(c++) which I consider very bad practice, but we can perhaps live without that at this stage. Note: even though these are postfix operators at the moment, they work like prefix operators do in other languages. I.e. var c = 0; some_function(c++); will use 1 as the value of the the parameter passed to the function.

    I tried to document this now in the syntax grammar, which is btw again heavily inspired by the Lox specification: (docs) Add syntax-grammar.md document #18.

  • Properly handle cases when the user tries to do things like var a = "foo"; a++; and similar folly. This is clearly an area where a static type checker would make things immensely much better; then interpreter/compiler in the future will then have to take much less precautions in ensuring that things are of the expected types all the time.

@perlun perlun force-pushed the feature/support-postfix-increment branch 2 times, most recently from 3a45c7e to 8b3ce39 Compare February 3, 2020 21:30
@perlun
Copy link
Collaborator Author

perlun commented Feb 3, 2020

Making process, but there are still some things that are broken - the failing tests indicate this. There is something causing the resolution of local variables to fail, which is quite odd given that prefix operators work flawlessly.

I tried moving the unary postfix operators into a separate method now (instead of just tucking it into the Assignment() method), but it doesn't change a thing. It feels like there some oddness in the variable resolver going on; I guess I just have to continue digging...

@perlun perlun force-pushed the feature/support-postfix-increment branch from 8b3ce39 to 301c4c2 Compare February 4, 2020 13:27
@perlun perlun force-pushed the feature/support-postfix-increment branch from 301c4c2 to 6b2d2bb Compare February 4, 2020 13:30
@perlun perlun changed the title WIP: (all) Add support for postfix increment (all) Add support for postfix increment Feb 4, 2020
@perlun perlun changed the title (all) Add support for postfix increment (all) Add support for postfix increment and decrement Feb 4, 2020
@perlun
Copy link
Collaborator Author

perlun commented Feb 4, 2020

Making process, but there are still some things that are broken - the failing tests indicate this. There is something causing the resolution of local variables to fail, which is quite odd given that prefix operators work flawlessly.

The thing missing was the ResolveLocal() call in VisitUnaryPostfixExpr(); this is necessary to be able to resolve variables and other locals. Isn't it interesting how things sometimes are much easier if you leave it for a while and revisit the problem the next day? 🙂

@perlun perlun merged commit 48acdf3 into master Feb 4, 2020
@perlun perlun deleted the feature/support-postfix-increment branch February 4, 2020 18:29
@perlun
Copy link
Collaborator Author

perlun commented Feb 18, 2022

  • Note: even though these are postfix operators at the moment, they work like prefix operators do in other languages. I.e. var c = 0; some_function(c++); will use 1 as the value of the the parameter passed to the function.

This was subsequently revisited in #145. Using different semantics than other languages here was simply discovered to be a pretty bad idea.

@perlun perlun added this to the 0.1.0 milestone Feb 18, 2022
@perlun perlun added the language Language features (or bugs) label Feb 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language Language features (or bugs)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant