Implement ANF transformation for impure expressions to fix evaluation order: Phase 145 P0 (Skeleton): - Add anf/ module with contract/plan/execute 3-layer separation - AnfDiagnosticTag, AnfOutOfScopeReason, AnfPlan enums - Stub execute_box (always returns Ok(None)) - 11 unit tests pass Phase 145 P1 (Minimal success): - String.length() whitelist implementation - BinaryOp + MethodCall pattern: x + s.length() → t = s.length(); result = x + t - Exit code 12 verification (VM + LLVM EXE) - 17 unit tests pass Phase 145 P2 (Generalization): - Recursive ANF for compound expressions - Left-to-right, depth-first evaluation order - Patterns: x + s.length() + z, s1.length() + s2.length() - ANF strict mode (HAKO_ANF_STRICT=1) - Diagnostic tags (joinir/anf/*) - 21 unit tests pass, 0 regression Also includes Phase 143 P2 (else symmetry) completion. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
28 lines
642 B
Plaintext
28 lines
642 B
Plaintext
// Phase 145 P2: Compound expression with nested BinaryOp + MethodCall
|
|
// Pattern: x + s.length() + z
|
|
// Expected: t1 = s.length(); t2 = x + t1; result = t2 + z
|
|
// Exit code: 18 (10 + 5 + 3 = 18)
|
|
|
|
static box Main {
|
|
main() {
|
|
local s
|
|
s = "Hello" // length = 5
|
|
|
|
local x
|
|
x = 10
|
|
|
|
local z
|
|
z = 3
|
|
|
|
// Compound expression: x + s.length() + z
|
|
// Should normalize to:
|
|
// t1 = s.length() (= 5)
|
|
// t2 = x + t1 (= 10 + 5 = 15)
|
|
// result = t2 + z (= 15 + 3 = 18)
|
|
local result
|
|
result = x + s.length() + z
|
|
|
|
return result
|
|
}
|
|
}
|