Skip to content

Conversation

@gabizon103
Copy link
Collaborator

Adds if-expressions, closes #436. Each arm of the if currently must be a simple expression; could be extended in a future PR to support blocks of commands that return an expression, if necessary.

Represented in the IR as another member of ir::Expr that takes a condition (ir::Prop) and two expressions. This worked pretty okay, just had to do some reshuffling of code in the monomorphize pass to be able to handle Props at the same time we handle Exprs.

One sort of weird thing happens in Discharge, where we need to convert the if's condition (a Prop) to an SExp as we are converting all of a component's Exprs, which happens before we do the rest of the component's Props. This means that we need to push things to Discharge::prop_map out of order, which means that SExpr needs to implement Default. We can't implement Default for SExpr, so I made a wrapper SExprWrapper that is either an SExpr orSExprEmpty, which lets us implement Default. This is a little wonky, but I couldn't really come up with a way around this.

@gabizon103 gabizon103 marked this pull request as ready for review March 26, 2024 20:41
@gabizon103 gabizon103 merged commit 8731161 into main Mar 28, 2024
@gabizon103 gabizon103 deleted the if-expr branch March 28, 2024 02:46
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.

If-expressions for parameters

1 participant