feat(joinir): Phase 190-impl NumberAccumulation pattern implementation
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>
This commit is contained in:
@ -178,7 +178,8 @@ impl CommonPatternInitializer {
|
||||
let updates = LoopUpdateAnalyzer::analyze_carrier_updates(body, &dummy_carriers);
|
||||
|
||||
// Phase 188: Check if any update is complex (reject only UpdateRhs::Other)
|
||||
// Allow: Const (numeric), Variable (numeric/string), StringLiteral
|
||||
// Phase 190: Allow NumberAccumulation pattern
|
||||
// Allow: Const (numeric), Variable (numeric/string), StringLiteral, NumberAccumulation
|
||||
// Reject: Other (method calls, nested BinOp)
|
||||
for update in updates.values() {
|
||||
if let UpdateExpr::BinOp { rhs, .. } = update {
|
||||
@ -193,6 +194,9 @@ impl CommonPatternInitializer {
|
||||
UpdateRhs::StringLiteral(_) => {
|
||||
// Phase 188: StringAppendLiteral: s = s + "x" (allowed)
|
||||
}
|
||||
UpdateRhs::NumberAccumulation { .. } => {
|
||||
// Phase 190: Number accumulation: result = result * 10 + digit (allowed)
|
||||
}
|
||||
UpdateRhs::Other => {
|
||||
// Phase 188: Complex update (method call, nested BinOp) - reject
|
||||
eprintln!("[common_init/check_carriers] Phase 188: Complex update detected (UpdateRhs::Other), rejecting pattern");
|
||||
|
||||
Reference in New Issue
Block a user