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 return #135

Merged
merged 3 commits into from
Feb 16, 2024
Merged

Implement return #135

merged 3 commits into from
Feb 16, 2024

Conversation

jlapeyre
Copy link
Collaborator

@jlapeyre jlapeyre commented Feb 16, 2024

Breaking recursion in enum Expr done differently here

Note that in enum Expr in asg.rs, variants before this PR have looked like this:

pub enum Expr {
ArraySlice(ArraySlice),
BinaryExpr(BinaryExpr),
UnaryExpr(UnaryExpr),

For return expressions we introduce a variant Return(Box<ReturnExpression>). This probably means that consumers have to treat Return differently because the indirection happens in a different place (in the variant). The other choice would be to continue with the previous pattern of putting the Box in the struct ReturnExpression.

It probably makes sense to choose one way and do it uniformly.

Change in fn from_expr in syntax_to_semantics.rs

Before the expression from the AST was unwrapped and passed to from_expr. This is changed in this PR. Now we pass the Option to from_expr. This simplifies much code in syntax_to_semantics.rs (as is evident by looking at this PR). panics due to unwrap will be moved to different places in the code. Of course, eventually, we need to avoid panic ing altogether.

Note that there is a check for return in global scope. But we need something more systematic than this

Closes #133

@jlapeyre jlapeyre merged commit e7d1156 into main Feb 16, 2024
7 checks passed
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.

return: implement
1 participant