alan icon indicating copy to clipboard operation
alan copied to clipboard

Conditionals

Open dfellis opened this issue 8 months ago • 1 comments

The Alan v0.2 conditionals concept is that if <conditional> { ... } else ... is rewritten into cond function calls where all function bodies are branchless and must run until the end.

This means return statements are only valid as the last statement in a function body at that point.

This also means that conditional branches that don't return and pass back control flow to the higher layer must instead bolt on the follow-up code to the tail of their own function body. Excepting only if all branches of a conditional do not return, where fall-through is allowed, and all branches where the conditional does return, in which case follow-on code is a failure.

The cond function will be just like any other function, so users can write their own that accepts something other than bools. This will be used for native GPGPU support, as both branches of a conditional need to be transformed into an AST to serialize to wgsl for the GPU.

dfellis avatar Jun 10 '24 23:06 dfellis