feat(joinir): Phase P2-P4 Loop Pattern boxification

- P2: Create loop_patterns/ module structure
  - common.rs: shared helpers (ParsedProgram, LoopContext, etc.)
  - simple.rs: generic loop lowering
  - filter.rs, print_tokens.rs: delegate to simple
  - break_pattern.rs, continue_pattern.rs: new modules

- P3: Create LoopFrontendBinding layer
  - Separate function name detection from pattern lowering
  - detect_loop_pattern() for pattern classification

- P4: Break/Continue pattern migration
  - Move Break/Continue handling from loop_patterns_old.rs
  - Add LoopPattern::Break and LoopPattern::Continue variants

- Design: 3-layer architecture
  - LoopFrontendBinding: function name → LoopPattern
  - loop_patterns: LoopPattern → JoinIR
  - Bridge/VM: Box semantics

All 56 JoinIR tests pass.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-11-29 09:04:18 +09:00
parent fd83903f87
commit 3af98964ed
12 changed files with 1753 additions and 8 deletions

View File

@ -30,7 +30,9 @@ mod context;
mod expr;
mod if_in_loop;
mod if_return;
mod loop_frontend_binding;
mod loop_patterns;
mod loop_patterns_old;
mod nested_if;
mod read_quoted;
mod stmt_handlers;
@ -83,18 +85,20 @@ impl AstToJoinIrLowerer {
.as_str()
.expect("Function must have 'name'");
// 3. 関数名で分岐Phase 34-2/34-3/34-4/34-5/34-7/34-8/41-4/45
// test/local/_read_value_from_pair: If Return pattern
// simple: Loop pattern (Phase 34-7/34-8)
// parse_loop: Phase 41-4 NestedIfMerge pattern
// read_quoted_from: Phase 45 Guard if + Loop with break + accumulator
// 3. 関数名で分岐Phase P3: LoopFrontendBinding 層導入
//
// パターン分類:
// - If Return pattern: test/local/_read_value_from_pair
// - Loop pattern: simple 等 → LoopFrontendBinding 経由
// - NestedIfMerge pattern: parse_loop (dev flag gated)
// - ReadQuoted pattern: read_quoted_from (dev flag gated)
match func_name {
"test" | "local" | "_read_value_from_pair" => {
self.lower_if_return_pattern(program_json)
}
"simple" => {
// Phase 34-8: Loop パターンの詳細分析break/continue 検出)
self.lower_loop_with_break_continue(program_json)
"simple" | "filter" | "print_tokens" | "map" | "reduce" | "fold" => {
// Phase P3: LoopFrontendBinding 層経由でディスパッチ
loop_frontend_binding::lower_loop_by_function_name(self, program_json)
}
"parse_loop" => {
// Phase 41-4: NestedIfMerge pattern (dev flag gated)