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:

  1. Compile the condition to a series of edges computing the condition (this ends in an EdgeBufferNodeLink::End if the expression does not fully return);
  2. Compile the consequent to a series of edges (this ends in an [EdgeBufferNodeLink::End] if the statements do not fully return);
  3. Write it as a Loop connector, with the ends of the condition and consequent still Ends
  4. [In workflow_resolve.rs] Write the condition to a separate series of edges with resolved indices.
  5. [In workflow_resolve.rs] Write the consequence to a separate series of edges with resolved indices.
  6. [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.
  7. [In workflow_resolve.rs] Write the consequence to the loop-global buffer directly after the condition.
  8. [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.