module scheme struct CaptureVisit { function &Function finish bool } // Direct lexical addresses establish each function's outer depth. A nested // child can also require a path through its parent's environment. Propagate // those needs after all bodies are built: let* constructs its child chain // before compiling the innermost body, and that chain can be very long. fn finalize_captures(root &Function) { mut pending := [CaptureVisit{root, false}] for pending.len > 0 { visit := pending.pop() mut function := visit.function if !visit.finish { pending << CaptureVisit{function, true} for child in function.children { pending << CaptureVisit{child, false} } } else { for child in function.children { depth := child.capture_depth - 1 if depth > function.capture_depth { function.capture_depth = depth } } function.prepare_integer_tail_loop() } } }