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>
23 lines
462 B
Plaintext
23 lines
462 B
Plaintext
// Phase 145 P1: ANF minimal test - String.length() hoist in BinaryOp
|
|
//
|
|
// Pattern: x + s.length()
|
|
// ↓ ANF transformation
|
|
// t = s.length()
|
|
// result = x + t
|
|
//
|
|
// Expected: exit code 12 (5 + 3 + 4)
|
|
|
|
static box Main {
|
|
main() {
|
|
local s
|
|
s = "abc" // String with length 3
|
|
|
|
local x
|
|
x = 5
|
|
|
|
local result
|
|
result = x + s.length() // 5 + 3 = 8
|
|
return result + 4 // 8 + 4 = 12
|
|
}
|
|
}
|