🚀 Break/Continue/Try-Catch構文のサポート追加とMIRループ制御強化
## 主な変更点 ### 🎯 MIRループ制御の実装(根治対応) - src/mir/loop_builder.rs: Break/Continue対応のループコンテキスト管理 - ループのbreak/continueターゲットブロック追跡 - ネストループの適切な処理 - src/mir/builder.rs: Break/Continue文のMIR生成実装 - src/tokenizer.rs: Break/Continue/Tryトークン認識追加 ### 📝 セルフホストパーサーの拡張 - apps/selfhost-compiler/boxes/parser_box.nyash: - Stage-3: break/continue構文受理(no-op実装) - Stage-3: try-catch-finally構文受理(構文解析のみ) - エラー処理構文の将来対応準備 ### 📚 ドキュメント更新 - 論文K(爆速事件簿): 45事例に更新(4件追加) - PyVM迂回路の混乱事件 - Break/Continue無限ループ事件 - EXE-first戦略の再発見 - 論文I(開発秘話): Day 38の重要決定追加 ### 🧪 テストケース追加 - apps/tests/: ループ制御とPHIのテストケース - nested_loop_inner_break_isolated.nyash - nested_loop_inner_continue_isolated.nyash - loop_phi_one_sided.nyash - shortcircuit関連テスト ## 技術的詳細 - Break/ContinueをMIRレベルで適切に処理 - 無限ループ問題(CPU 99.9%暴走)の根本解決 - 将来の例外処理機能への準備 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
8
tests/json_v0/arith.json
Normal file
8
tests/json_v0/arith.json
Normal file
@ -0,0 +1,8 @@
|
||||
{"version":0,"kind":"Program","body":[
|
||||
{"type":"Return","expr":{
|
||||
"type":"Binary","op":"+",
|
||||
"lhs":{"type":"Int","value":1},
|
||||
"rhs":{"type":"Binary","op":"*","lhs":{"type":"Int","value":2},"rhs":{"type":"Int","value":3}}
|
||||
}}
|
||||
]}
|
||||
|
||||
9
tests/json_v0/if_then_else.json
Normal file
9
tests/json_v0/if_then_else.json
Normal file
@ -0,0 +1,9 @@
|
||||
{"version":0,"kind":"Program","body":[
|
||||
{"type":"Local","name":"x","expr":{"type":"Int","value":1}},
|
||||
{"type":"If","cond":{"type":"Compare","op":"<","lhs":{"type":"Int","value":1},"rhs":{"type":"Int","value":2}},
|
||||
"then":[{"type":"Local","name":"x","expr":{"type":"Int","value":10}}],
|
||||
"else":[{"type":"Local","name":"x","expr":{"type":"Int","value":20}}]
|
||||
},
|
||||
{"type":"Return","expr":{"type":"Var","name":"x"}}
|
||||
]}
|
||||
|
||||
11
tests/json_v0/logical_nested.json
Normal file
11
tests/json_v0/logical_nested.json
Normal file
@ -0,0 +1,11 @@
|
||||
{"version":0,"kind":"Program","body":[
|
||||
{"type":"Return","expr":{
|
||||
"type":"Logical","op":"&&",
|
||||
"lhs":{"type":"Bool","value":true},
|
||||
"rhs":{"type":"Logical","op":"||",
|
||||
"lhs":{"type":"Bool","value":false},
|
||||
"rhs":{"type":"Compare","op":"<","lhs":{"type":"Int","value":1},"rhs":{"type":"Int","value":2}}
|
||||
}
|
||||
}}
|
||||
]}
|
||||
|
||||
10
tests/json_v0/logical_shortcircuit_and.json
Normal file
10
tests/json_v0/logical_shortcircuit_and.json
Normal file
@ -0,0 +1,10 @@
|
||||
{"version":0,"kind":"Program","body":[
|
||||
{"type":"Local","name":"a","expr":{"type":"New","class":"ArrayBox","args":[]}},
|
||||
{"type":"Local","name":"f","expr":{"type":"Bool","value":false}},
|
||||
{"type":"Expr","expr":{"type":"Logical","op":"&&",
|
||||
"lhs":{"type":"Var","name":"f"},
|
||||
"rhs":{"type":"Method","recv":{"type":"Var","name":"a"},"method":"push","args":[{"type":"Int","value":1}]}
|
||||
}},
|
||||
{"type":"Return","expr":{"type":"Method","recv":{"type":"Var","name":"a"},"method":"size","args":[]}}
|
||||
]}
|
||||
|
||||
10
tests/json_v0/logical_shortcircuit_or.json
Normal file
10
tests/json_v0/logical_shortcircuit_or.json
Normal file
@ -0,0 +1,10 @@
|
||||
{"version":0,"kind":"Program","body":[
|
||||
{"type":"Local","name":"a","expr":{"type":"New","class":"ArrayBox","args":[]}},
|
||||
{"type":"Local","name":"t","expr":{"type":"Bool","value":true}},
|
||||
{"type":"Expr","expr":{"type":"Logical","op":"||",
|
||||
"lhs":{"type":"Var","name":"t"},
|
||||
"rhs":{"type":"Method","recv":{"type":"Var","name":"a"},"method":"push","args":[{"type":"Int","value":1}]}
|
||||
}},
|
||||
{"type":"Return","expr":{"type":"Method","recv":{"type":"Var","name":"a"},"method":"size","args":[]}}
|
||||
]}
|
||||
|
||||
4
tests/json_v0/method_string_length.json
Normal file
4
tests/json_v0/method_string_length.json
Normal file
@ -0,0 +1,4 @@
|
||||
{"version":0,"kind":"Program","body":[
|
||||
{"type":"Return","expr":{"type":"Method","recv":{"type":"Str","value":"abc"},"method":"length","args":[]}}
|
||||
]}
|
||||
|
||||
10
tests/json_v0/string_chain.json
Normal file
10
tests/json_v0/string_chain.json
Normal file
@ -0,0 +1,10 @@
|
||||
{"version":0,"kind":"Program","body":[
|
||||
{"type":"Return","expr":{
|
||||
"type":"Method","recv":{
|
||||
"type":"Method","recv":{"type":"Str","value":"abcd"},
|
||||
"method":"substring","args":[{"type":"Int","value":1},{"type":"Int","value":3}]
|
||||
},
|
||||
"method":"length","args":[]
|
||||
}}
|
||||
]}
|
||||
|
||||
12
tests/json_v0/while_sum.json
Normal file
12
tests/json_v0/while_sum.json
Normal file
@ -0,0 +1,12 @@
|
||||
{"version":0,"kind":"Program","body":[
|
||||
{"type":"Local","name":"i","expr":{"type":"Int","value":0}},
|
||||
{"type":"Local","name":"s","expr":{"type":"Int","value":0}},
|
||||
{"type":"Loop","cond":{"type":"Compare","op":"<","lhs":{"type":"Var","name":"i"},"rhs":{"type":"Int","value":3}},
|
||||
"body":[
|
||||
{"type":"Local","name":"s","expr":{"type":"Binary","op":"+","lhs":{"type":"Var","name":"s"},"rhs":{"type":"Int","value":1}}},
|
||||
{"type":"Local","name":"i","expr":{"type":"Binary","op":"+","lhs":{"type":"Var","name":"i"},"rhs":{"type":"Int","value":1}}}
|
||||
]
|
||||
},
|
||||
{"type":"Return","expr":{"type":"Var","name":"s"}}
|
||||
]}
|
||||
|
||||
Reference in New Issue
Block a user