Compilation
While-loops (and For-loops)
We come from the following internal AST representation of a for-loop:
#![allow(unused)] fn main() { enum Stmt { While { /// The expression that has to evaluate to true while running. condition : Expr, /// The block to run every iteration. consequent : Box<Block>, // ... }, // ... } }
We want to convert that to a series of graphs and edges. This is done as follows:
- Compile the condition to a series of edges computing the condition (this ends in an
EdgeBufferNodeLink::End
if the expression does not fully return); - Compile the consequent to a series of edges (this ends in an [
EdgeBufferNodeLink::End
] if the statements do not fully return); - Write it as a Loop connector, with the ends of the condition and consequent still
End
s - [In
workflow_resolve.rs
] Write the condition to a separate series of edges with resolved indices. - [In
workflow_resolve.rs
] Write the consequence to a separate series of edges with resolved indices. - [In
workflow_resolve.rs
] Write the condition as a branch to the loop-global buffer, with the true-branch being the condition, the false branch being the edges after the loop. - [In
workflow_resolve.rs
] Write the consequence to the loop-global buffer directly after the condition. - [In
workflow_resolve.rs
] Write the loop node, then the loop-global buffers.
So, in conclusion: the result is a Loop-edge, pointing to a series of edges that computes the condition, then a branch that does the body or skips over it. The loop-edge then contains pointers into this buffer, even though the loop itself is quite serialized already.