-
Notifications
You must be signed in to change notification settings - Fork 45
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
Add support for numeric match at runtime #143
Conversation
pub struct SwitchExpandExpr<I: Int, C: CubePrimitive> { | ||
value: ExpandElementTyped<I>, | ||
out: ExpandElementTyped<C>, | ||
default: CubeContext, | ||
cases: Vec<(ExpandElementTyped<I>, CubeContext)>, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the difference between the SwitchExpand
and SwitchExpandExpr
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SwitchExpandExpr
creates an outer output variables and adds an assign statement to each branch to assign the return to the outer variable. It's the same as the IfExpandExpr
, it's used to emulate Rust behaviour that allows using match as value in assignments. For typing reasons and to avoid a pointless assign in every branch, the two are split based on whether the match has a return value.
Parses match statements with only numeric and wildcard arms as switch statements.
Or
match arms are unrolled into their component elements for simplicity. Could theoretically use fallthrough or multiple selectors incuda
andwgsl
respectively, but this also works.Works the same as
if else
when the value is used as an expression.Testing
Adds several runtime tests for the new switch statements.