feat(joinir): Phase 185-187 body-local infrastructure + string design
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>
This commit is contained in:
27
apps/tests/phase185_p2_body_local_int_min.hako
Normal file
27
apps/tests/phase185_p2_body_local_int_min.hako
Normal file
@ -0,0 +1,27 @@
|
||||
// Phase 185: Minimal JsonParser-style loop with body-local integer calculation
|
||||
// Tests Pattern2 integration with LoopBodyLocalEnv
|
||||
|
||||
static box Main {
|
||||
main() {
|
||||
local sum = 0
|
||||
local pos = 0
|
||||
local start = 0
|
||||
local end = 5
|
||||
|
||||
// Pattern2: break loop with body-local digit_pos
|
||||
loop(pos < end) {
|
||||
local digit_pos = pos - start // Body-local calculation
|
||||
sum = sum * 10
|
||||
sum = sum + digit_pos // Use body-local in update
|
||||
pos = pos + 1
|
||||
|
||||
if (sum > 50) {
|
||||
break // Break condition
|
||||
}
|
||||
}
|
||||
|
||||
print(sum) // Expected: 0*10+0 → 0*10+1 → 1*10+2 → 12*10+3 → 123 → break
|
||||
// Output: 123 (breaks before digit_pos=4)
|
||||
return 0
|
||||
}
|
||||
}
|
||||
34
apps/tests/phase186_p2_body_local_digit_pos_min.hako
Normal file
34
apps/tests/phase186_p2_body_local_digit_pos_min.hako
Normal file
@ -0,0 +1,34 @@
|
||||
// Phase 186: Minimal Body-local Init Lowering Test (Pattern2)
|
||||
//
|
||||
// Tests that body-local variables with init expressions can be used in update expressions.
|
||||
//
|
||||
// Expected behavior:
|
||||
// - loop(pos < 10) iterates with break condition
|
||||
// - Each iteration:
|
||||
// - local digit_pos = pos - start (body-local init expression)
|
||||
// - if digit_pos >= 3 { break }
|
||||
// - sum = sum + digit_pos (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
|
||||
local start = 0
|
||||
|
||||
loop (pos < 10) {
|
||||
local digit_pos = pos - start // Body-local init expression (Phase 186)
|
||||
|
||||
if digit_pos >= 3 {
|
||||
break // Break when digit_pos reaches 3
|
||||
}
|
||||
|
||||
sum = sum + digit_pos // Use body-local in update (Phase 184)
|
||||
pos = pos + 1
|
||||
}
|
||||
|
||||
print(sum) // Expected: 3 (0+0+1+2)
|
||||
return sum
|
||||
}
|
||||
}
|
||||
34
apps/tests/phase186_p2_body_local_init_simple.hako
Normal file
34
apps/tests/phase186_p2_body_local_init_simple.hako
Normal file
@ -0,0 +1,34 @@
|
||||
// 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user