Files
hakorune/apps/tests/test_pattern5b_recognized.hako

53 lines
1.3 KiB
Plaintext
Raw Normal View History

feat(mir): Phase 92 P2-2 - Body-local variable support for ConditionalStep Phase 92 P2-2完了:ConditionalStepのcondition(ch == '\\'など)でbody-local変数をサポート ## 主要変更 ### 1. condition_lowerer.rs拡張 - `lower_condition_to_joinir`に`body_local_env`パラメータ追加 - 変数解決優先度:ConditionEnv → LoopBodyLocalEnv - すべての再帰ヘルパー(comparison, logical_and, logical_or, not, value_expression)対応 ### 2. conditional_step_emitter.rs修正 - `emit_conditional_step_update`に`body_local_env`パラメータ追加 - condition loweringにbody-local環境を渡す ### 3. loop_with_break_minimal.rs修正 - break condition loweringをbody-local init の**後**に移動(line 411) - header_break_lowering::lower_break_conditionにbody_local_env渡す - emit_conditional_step_updateにbody_local_env渡す(line 620) ### 4. header_break_lowering.rs修正 - `lower_break_condition`に`body_local_env`パラメータ追加 - scope_managerにbody-local環境を渡す ### 5. 全呼び出し箇所修正 - expr_lowerer.rs (2箇所) - method_call_lowerer.rs (2箇所) - loop_with_if_phi_if_sum.rs (3箇所) - loop_with_continue_minimal.rs (1箇所) - carrier_update_emitter.rs (1箇所・legacy) ## アーキテクチャ改善 ### Break Condition Lowering順序修正 旧: Header → **Break Cond** → Body-local Init 新: Header → **Body-local Init** → Break Cond 理由:break conditionが`ch == '\"'`のようにbody-local変数を参照する場合、body-local initが先に必要 ### 変数解決優先度(Phase 92 P2-2) 1. ConditionEnv(ループパラメータ、captured変数) 2. LoopBodyLocalEnv(body-local変数like `ch`) ## テスト ### ビルド ✅ cargo build --release成功(30 warnings、0 errors) ### E2E ⚠️ body-local promotion問題でブロック(Phase 92範囲外) - Pattern2はbody-local変数をcarrier promotionする必要あり - 既存パターン(A-3 Trim, A-4 DigitPos)に`ch = get_char(i)`が該当しない - **Phase 92 P2-2目標(condition loweringでbody-local変数サポート)は達成** ## 次タスク(Phase 92 P3以降) - body-local variable promotion拡張(Pattern2で`ch`のような変数を扱う) - P5b E2Eテスト完全動作確認 ## Phase 92 P2-2完了 ✅ Body-local変数のcondition lowering対応完了 ✅ ConditionalStepでbody-local変数参照可能 ✅ Break condition lowering順序修正
2025-12-16 17:08:15 +09:00
// Phase 92 P2-3: P5b Test That Matches Pattern Recognizer
//
// This test is designed to exactly match what the pattern recognizer expects:
// 1. Body statement with simple ch assignment
// 2. Break check: if ch == "\"" { break }
// 3. Escape check: if ch == "\\" { i = i + 2 } else { i = i + 1 }
//
// Expected behavior (simulated string "a\\b\"c"):
// - i=0: ch='a', not quote, not escape, i=1
// - i=1: ch='\\', not quote, IS escape, i=3
// - i=3: ch='\"', IS quote, break
// - Output: 3
static box Main {
get_char(pos) {
// Simulate string access: "a\\b\"c"
// Position 0: 'a', Position 1: '\\', Position 3: '\"'
if pos == 1 {
return "\\"
}
if pos == 3 {
return "\""
}
return "a"
}
main() {
local i = 0
local len = 5
local ch = "a"
loop(i < len) {
// Body statement: simple assignment (not method call)
ch = me.get_char(i)
// Break check (P5b pattern requirement)
if ch == "\"" {
break
}
// Escape check with conditional increment (P5b pattern)
if ch == "\\" {
i = i + 2 // Escape: skip 2
} else {
i = i + 1 // Normal: skip 1
}
}
print(i)
return 0
}
}