✓
Passing This code compiles and runs correctly.
Code
// Test: ~for compiles to literal for loop with ZERO event overhead
//
// VISION: The ~for transform should use the template system to emit
// a literal Zig for loop, NOT a synthetic event with captured body.
//
// BEFORE (current broken implementation):
// const result = __for_synthetic_event.handler(.{ ... });
// // loop body captured inside synthetic proc
//
// AFTER (zero overhead implementation):
// for (0..5) |i| {
// // each branch inlined directly here
// }
// // done branch inlined after loop
//
// This test uses post.sh to verify the generated code pattern.
~import "$std/io"
~import "$std/control"
const std = @import("std");
~for(0..5)
| each |> std.io:println(text: "iteration")
| done |> std.io:println(text: "done")
Test Configuration
Post-validation Script:
#!/bin/bash
# Verify that the generated code uses literal for loop, NOT synthetic event
OUTPUT_FILE="output_emitted.zig"
# Check that __for synthetic event is NOT present (bad pattern)
# grep -v "^[[:space:]]*//" excludes comment lines
if grep -v "^[[:space:]]*//" "$OUTPUT_FILE" | grep -q "__for.*_event.handler\|for_synthetic.*_event.handler"; then
echo "FAIL: Found synthetic __for event handler call"
echo "The ~for transform should emit 'for (range) |item| { ... }'"
echo "NOT a synthetic event with captured loop body"
exit 1
fi
# Check that literal for loop IS present (good pattern)
if ! grep -qE "for \(0\.\.5\) \|" "$OUTPUT_FILE"; then
echo "FAIL: Expected literal 'for (0..5) |...|' not found"
echo "The ~for transform should emit a literal Zig for loop"
exit 1
fi
echo "PASS: ~for compiles to zero-overhead literal for loop"
exit 0