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 while statement parsing and evaluation #22

Merged
merged 4 commits into from
Oct 4, 2022
Merged

Conversation

juliaogris
Copy link
Member

Implement while statement parsing and evaluation by reusing conditional
Block execution from If-statements parsing and evaluation and factor
out shared code.

Fix various bugs that popped up while implementing while statements:

  • evaluator: Fix control flow for conditional return statements
  • evaluator: Set variable value in correct scope
  • parser: Intern basic parser types

Intern basic parser types - Number, String, Bool, any - to make pointer
comparison trivial without requiring deep comparison.
@github-actions
Copy link

github-actions bot commented Oct 4, 2022

Visit the preview URL for this PR (updated for commit 6284a93):

https://evy-lang--pr22-while-9nzpficc.web.app

(expires Tue, 11 Oct 2022 22:45:20 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Copy link
Contributor

@camh- camh- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice. I like how simple it is to add the while construct. Confirms that you have a good parsing structure in place. 🐉

return nil, false
}
if _, ok := s.values[name]; ok {
return s, ok
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would make this return s, true. Since ok is always true in this branch, the literal makes it easier to read and understand at a glance.

Fix setting variable value in correct scope. The variable value needs to
be updated in the scope the variable was declared rather than in the
current scope so that an update inside a block is still available when
the block has terminated.
Ensure the value of a `return` is propagated along with whether a
conditional block was executed as `val, ok`. Previously we only
returned TRUE or FALSE for branch taken or not which swallowed returned
statements.
Implement while statement parsing and evaluation. Reuse conditional
Block execution from If-statements parsing and evaluation and factor
out shared code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants