feat(joinir): Phase 188 Pattern 1 Core Implementation + Phase 189 Planning

Phase 188 Status: Planning & Foundation Complete (100%)

Completed Tasks:
 Task 188-1: Error Inventory (5 patterns identified)
 Task 188-2: Pattern Classification (3 patterns selected)
 Task 188-3: Design (51KB comprehensive blueprint)
 Task 188-4: Implementation Foundation (1,802 lines scaffolding)
 Task 188-5: Verification & Documentation
 Pattern 1 Core Implementation: Detection + Lowering + Routing

Pattern 1 Implementation (322 lines):
- Pattern Detection: is_simple_while_pattern() in loop_pattern_detection.rs
- JoinIR Lowering: lower_simple_while_to_joinir() in simple_while_minimal.rs (219 lines)
  - Generates 3 functions: entry, loop_step (tail-recursive), k_exit
  - Implements condition negation: exit_cond = !(i < 3)
  - Tail-recursive Call pattern with state propagation
- Routing: Added "main" to function routing list in control_flow.rs
- Build:  SUCCESS (0 errors, 34 warnings)

Infrastructure Blocker Identified:
- merge_joinir_mir_blocks() only handles single-function JoinIR modules
- Pattern 1 generates 3 functions (entry + loop_step + k_exit)
- Current implementation only merges first function → loop body never executes
- Root cause: control_flow.rs line ~850 takes only .next() function

Phase 189 Planning Complete:
- Goal: Refactor merge_joinir_mir_blocks() for multi-function support
- Strategy: Sequential Merge (Option A) - merge all functions in call order
- Effort estimate: 5.5-7.5 hours
- Deliverables: README.md (16KB), current-analysis.md (15KB), QUICKSTART.md (5.8KB)

Files Modified/Created:
- src/mir/loop_pattern_detection.rs (+50 lines) - Pattern detection
- src/mir/join_ir/lowering/simple_while_minimal.rs (+219 lines) - Lowering
- src/mir/join_ir/lowering/loop_patterns.rs (+803 lines) - Foundation skeleton
- src/mir/join_ir/lowering/mod.rs (+2 lines) - Module registration
- src/mir/builder/control_flow.rs (+1 line) - Routing fix
- src/mir/builder/loop_frontend_binding.rs (+20 lines) - Binding updates
- tools/test_phase188_foundation.sh (executable) - Foundation verification
- CURRENT_TASK.md (updated) - Phase 188/189 status

Next: Phase 189 implementation (merge_joinir_mir_blocks refactor)

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-12-05 07:47:22 +09:00
parent 2d41039f62
commit 5bc0fa861f
13 changed files with 2213 additions and 31 deletions

View File

@ -50,6 +50,8 @@ pub enum BoundExpr {
Variable(String),
/// メソッド呼び出し (e.g., "me.tokens", "length")
MethodCall { receiver: String, method: String },
/// 定数値 (e.g., 3 for `i < 3`) - Phase 188-Impl-1
Constant(i64),
}
/// ループパターン種別
@ -135,6 +137,35 @@ impl LoopFrontendBinding {
}
}
/// Phase 188-Impl-1: main function simple while loop binding
///
/// Structure for loop_min_while.hako:
/// ```nyash
/// local i = 0
/// loop(i < 3) {
/// print(i)
/// i = i + 1
/// }
/// ```
///
/// This is a simple counter loop with:
/// - Counter variable: i (starts at 0)
/// - Bound: constant 3
/// - No accumulator (side-effect only loop)
/// - No external refs
pub fn for_main_simple_while() -> Self {
Self {
counter_var: "i".to_string(),
counter_init: 0,
accumulator_var: None, // No accumulator
bound_expr: BoundExpr::Constant(3), // Constant bound
external_refs: vec![], // No external refs
pattern: LoopPattern::Simple {
has_accumulator: false,
},
}
}
/// ループ条件と本体から変数パターンを分析して Binding を生成
///
/// Phase 50-3 で実装予定の汎用分析。現在は関数名ベースのハードコード。
@ -266,6 +297,18 @@ impl LoopFrontendBinding {
}
})
}
BoundExpr::Constant(value) => {
// Phase 188-Impl-1: 定数値loop_min_while.hako の 3 等)
// JoinIR Frontend expects "Int" type with direct "value" field
json!({
"type": "Local",
"name": "n",
"expr": {
"type": "Int",
"value": value
}
})
}
};
(i_local, acc_local, n_local)