Phase 185: Body-local Pattern2/4 integration skeleton - Added collect_body_local_variables() helper - Integrated UpdateEnv usage in loop_with_break_minimal - Test files created (blocked by init lowering) Phase 186: Body-local init lowering infrastructure - Created LoopBodyLocalInitLowerer box (378 lines) - Supports BinOp (+/-/*//) + Const + Variable - Fail-Fast for method calls/string operations - 3 unit tests passing Phase 187: String UpdateLowering design (doc-only) - Defined UpdateKind whitelist (6 categories) - StringAppendChar/Literal patterns identified - 3-layer architecture documented - No code changes 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
35 lines
1.0 KiB
Plaintext
35 lines
1.0 KiB
Plaintext
// Phase 186: Simple Body-local Init Lowering Test (Pattern2)
|
|
//
|
|
// Tests body-local init expressions used ONLY in updates, NOT in conditions.
|
|
// This is within Phase 186 scope (int/arithmetic init, condition-free usage).
|
|
//
|
|
// Expected behavior:
|
|
// - loop(pos < 5) iterates 5 times with break condition on pos
|
|
// - Each iteration:
|
|
// - local offset = pos - 0 (body-local init: always equals pos)
|
|
// - if pos >= 3 { break } (condition uses pos, NOT offset)
|
|
// - sum = sum + offset (use body-local in update)
|
|
// - pos = pos + 1
|
|
// - Expected sum: 0 + (0-0) + (1-0) + (2-0) = 0+0+1+2 = 3
|
|
|
|
static box Main {
|
|
main() {
|
|
local sum = 0
|
|
local pos = 0
|
|
|
|
loop (pos < 5) {
|
|
local offset = pos - 0 // Body-local init (Phase 186: BinOp)
|
|
|
|
if pos >= 3 { // Condition uses pos (loop var), NOT offset!
|
|
break
|
|
}
|
|
|
|
sum = sum + offset // Update uses offset (body-local)
|
|
pos = pos + 1
|
|
}
|
|
|
|
print(sum) // Expected: 3 (0+0+1+2)
|
|
return sum
|
|
}
|
|
}
|