Files
hakorune/docs/guides/loopform.md

33 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# LoopForm ガイド — ループ正規化(ユーザーマクロ)
目的
- while/for/foreach を Nyash のユーザーマクロで“キャリアタプル”に正規化し、MIR/LLVMにとって最適化しやすい形へ落とし込む。
使い方(予定)
- マクロ登録(例):
```
export NYASH_MACRO_ENABLE=1
export NYASH_MACRO_PATHS=apps/macros/examples/loop_normalize_macro.nyash
```
- 自己ホスト前展開autoを利用して、parse直後にLoopForm展開を有効化PyVM環境
正規化の考え方
- ループで更新される変数群をタプルに束ね、ヘッダに“1個のφ”を置く。
- break/continue は“次キャリア”または“現キャリア”で遷移し、一貫した合流点を保つ。
対応状況MVP→順次拡張
- Week1: whilebreak/continue無し
- Week2: break/continue/ネスト最小対応、キャリア自動抽出
- Week3: for/foreach限定
制約MVP
- try/finally/throwとの相互作用は未対応。例外は後続フェーズで設計を明記。
検証
- macrogolden展開後ASTのゴールデン
- LLVM PHI健全性スモーク空PHI無し、先頭グループ化
参考
- docs/development/roadmap/phases/phase-17-loopform-selfhost/