Phase 190 implementation: Detect and emit number accumulation patterns
like `result = result * 10 + digit` in Pattern 2 loops.
## Changes
### Task 190-impl-1: UpdateRhs enum extension
- Added `NumberAccumulation { base, digit_var }` variant to UpdateRhs
- Implemented detection logic in `analyze_update_value()`:
- Detects pattern: `(carrier * base) + digit`
- Supports both Add and Subtract operations
- Base must be integer constant, digit must be variable
- Added 3 unit tests (base10, base2, wrong_lhs cases)
### Task 190-impl-2: Pattern2/4 whitelist update
- Updated `check_carrier_updates_allowed()` in common_init.rs
- NumberAccumulation now allowed in can_lower()
- Pattern 4 (continue) rejects with passthrough (not yet implemented)
### Task 190-impl-3: Carrier update emission
- Implemented NumberAccumulation emission in carrier_update_emitter.rs
- Emits 3 instructions:
1. Const(base)
2. BinOp(Mul, carrier, base) → tmp
3. BinOp(Add/Sub, tmp, digit) → result
- Added 2 unit tests (base10 emission, digit_not_found error)
- Both UpdateEnv and ConditionEnv versions supported
### Task 190-impl-4: E2E tests (in progress)
- Created phase190_atoi_impl.hako (Pattern 2 with break)
- Created phase190_parse_number_impl.hako (Pattern 2 with break)
- Tests compile and use Pattern 2 correctly
- Runtime execution validation pending
## Files Modified
- loop_update_analyzer.rs (+180 lines: enum, detection, 3 tests)
- carrier_update_emitter.rs (+182 lines: emission, 2 tests)
- common_init.rs (+4 lines: whitelist update)
- loop_with_continue_minimal.rs (+16 lines: Pattern 4 passthrough)
## Test Results
- ✅ All analyzer unit tests pass (4/4)
- ✅ All emitter unit tests pass (12/12)
- 🔄 E2E runtime validation in progress
## Architecture Notes
- **Box-first modular design**: Single responsibility per function
- **Fail-fast**: Complex patterns rejected early in can_lower()
- **Pattern 2 only**: Pattern 1/3 don't support carriers yet
- **Pattern 4 future**: Passthrough stub for continue support
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
21 lines
474 B
Plaintext
21 lines
474 B
Plaintext
// Phase 190: Number accumulation test - parse number implementation
|
|
// Tests: num = num * 10 + i pattern with different initial values
|
|
// Uses Pattern 2 (break) to enable carrier support
|
|
|
|
static box ParseNumberImpl {
|
|
method main() {
|
|
local num
|
|
num = 0
|
|
local i
|
|
i = 1
|
|
loop(i < 10) {
|
|
if i > 3 {
|
|
break
|
|
}
|
|
num = num * 10 + i
|
|
i = i + 1
|
|
}
|
|
print(num)
|
|
}
|
|
}
|