Files
hakorune/apps/tests/phase190_atoi_impl.hako

33 lines
875 B
Plaintext
Raw Normal View History

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>
2025-12-09 02:14:57 +09:00
// Phase 190: Number accumulation test - atoi implementation
// Tests: result = result * 10 + i pattern (direct loop variable usage)
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>
2025-12-09 02:14:57 +09:00
// Uses Pattern 2 (break) to enable carrier support
//
// Note: Phase 190-impl-D found that body-local variable support is incomplete.
// Using loop variable directly for now.
//
// Expected calculation:
// i=0: result = 0*10 + 0 = 0
// i=1: result = 0*10 + 1 = 1
// i=2: result = 1*10 + 2 = 12
// i=3: break (condition i >= 3)
// Expected result: 12
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>
2025-12-09 02:14:57 +09:00
static box Main {
main() {
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>
2025-12-09 02:14:57 +09:00
local result
result = 0
local i
i = 0
loop(i < 10) {
if i >= 3 {
break
}
// Phase 190-impl-D: Use loop variable directly instead of body-local
result = result * 10 + i
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>
2025-12-09 02:14:57 +09:00
i = i + 1
}
print(result)
return 0
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>
2025-12-09 02:14:57 +09:00
}
}