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順序修正
This commit is contained in:
50
apps/tests/test_pattern5b_minimal_p2.hako
Normal file
50
apps/tests/test_pattern5b_minimal_p2.hako
Normal file
@ -0,0 +1,50 @@
|
||||
// Phase 92 P2-3: Minimal P5b E2E Test
|
||||
//
|
||||
// This is a MINIMAL test to verify ConditionalStep emission works.
|
||||
// Pattern: Loop with break check + conditional increment (P5b escape pattern)
|
||||
//
|
||||
// Expected behavior:
|
||||
// - i=0: not quote, not escape, i=1
|
||||
// - i=1: not quote, not escape, i=2
|
||||
// - i=2: not quote, IS escape, i=4
|
||||
// - i=4: IS quote, break
|
||||
// - Output: 4
|
||||
|
||||
static box Main {
|
||||
main() {
|
||||
local i = 0
|
||||
local len = 10
|
||||
local ch = "a"
|
||||
local str = "ab\\cd\"ef"
|
||||
|
||||
loop(i < len) {
|
||||
// Body statement: Simulate character access from string
|
||||
// In real parser, this would be: ch = str.charAt(i)
|
||||
// Here we simplify by checking position
|
||||
if i == 2 {
|
||||
ch = "\\" // Position 2: backslash
|
||||
} else {
|
||||
if i == 4 {
|
||||
ch = "\"" // Position 4: quote
|
||||
} else {
|
||||
ch = "a" // Other positions: normal char
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
}
|
||||
52
apps/tests/test_pattern5b_recognized.hako
Normal file
52
apps/tests/test_pattern5b_recognized.hako
Normal file
@ -0,0 +1,52 @@
|
||||
// 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
|
||||
}
|
||||
}
|
||||
38
apps/tests/test_pattern5b_simple.hako
Normal file
38
apps/tests/test_pattern5b_simple.hako
Normal file
@ -0,0 +1,38 @@
|
||||
// Phase 92 P2-3: Simplest P5b E2E Test (no body-local variables)
|
||||
//
|
||||
// This test uses position-based checks instead of a 'ch' variable
|
||||
// to avoid the body-local variable complexity for initial testing.
|
||||
//
|
||||
// Pattern: Loop with break check + conditional increment (P5b escape pattern)
|
||||
//
|
||||
// Expected behavior:
|
||||
// - i=0: not quote (0!=4), not escape (0!=2), i=1
|
||||
// - i=1: not quote (1!=4), not escape (1!=2), i=2
|
||||
// - i=2: not quote (2!=4), IS escape (2==2), i=4
|
||||
// - i=4: IS quote (4==4), break
|
||||
// - Output: 4
|
||||
|
||||
static box Main {
|
||||
main() {
|
||||
local i = 0
|
||||
local len = 10
|
||||
|
||||
loop(i < len) {
|
||||
// Break check (simulated: position 4 is quote)
|
||||
if i == 4 {
|
||||
break
|
||||
}
|
||||
|
||||
// Escape check with conditional increment (P5b pattern)
|
||||
// Position 2 is escape character
|
||||
if i == 2 {
|
||||
i = i + 2 // Escape: skip 2
|
||||
} else {
|
||||
i = i + 1 // Normal: skip 1
|
||||
}
|
||||
}
|
||||
|
||||
print(i)
|
||||
return 0
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user