using: safer seam defaults (fix_braces OFF by default) + path-alias handling; json_native: robust integer parse + EscapeUtils unquote; add JsonCompat layer; builder: preindex static methods + fallback for bare calls; diagnostics: seam dump + function-call trace

This commit is contained in:
Selfhosting Dev
2025-09-25 10:23:14 +09:00
parent 2f306dd6a5
commit 9384c80623
30 changed files with 1786 additions and 527 deletions

View File

@ -6,6 +6,20 @@ NyashでNyashコンパイラを書く、完全なセルフホスティングの
MIR 13命令の美しさを最大限に活かし、外部コンパイラ依存から完全に解放される。
**究極の目標80,000行→20,000行75%削減)→ さらなる最適化へ**
## 🔄 20250926 Update方針の明確化
- 実行系の優先順位: LLVM は Python/llvmlite ハーネスを主経路に固定llvm_sys 依存は前提にしない。Rust VM/JIT は保守最小・比較用。
- パーサ: TokenCursor 統一を env ゲート下で進行。Step2/3主要文の薄ラッパ完了、代表スモーク/パリティは緑。
- PHI: if/else の incoming は「実際の遷移元exit ブロック」を使用する規約で統一。dev 検証を追加pred 重複/自己参照/CFG 包含)。
- ループPHI: `phi_core` に統合IncompletePhi/スナップショット/exit PHI の責務集約)。`loop_builder.rs` は委譲化で軽量化。
- 次の主タスク: Nyash 製 JSON ライブラリJSON v0 DOM: parse/stringify。完了後に Ny Executor最小命令へ直行。
- 既定挙動は不変。新経路はすべて env トグルで optin。
推奨トグル
- `NYASH_LLVM_USE_HARNESS=1`LLVM Python ハーネス)
- `NYASH_PARSER_TOKEN_CURSOR=1`TokenCursor 経路)
- `NYASH_JSON_PROVIDER=ny`Ny JSON ライブラリ)
- `NYASH_SELFHOST_EXEC=1`Ny Executor 最小経路)
## 🎯 フェーズの目的
1. **完全なセルフホスティング**: NyashコンパイラをNyashで実装

View File

@ -27,60 +27,23 @@ This roadmap is a living checklist to advance Phase 15 with small, safe boxes. U
## Next (small boxes)
1) EXE-first: Selfhost Parser → EXEPhase 15.2)🚀
- tools/build_compiler_exe.sh で EXE をビルド同梱distパッケージ作成
- dist/nyash_compiler/{nyash_compiler,nyash.toml,plugins/...} で独立実行
- 入力: Nyソース → 出力: JSON v0stdout
- Smokes: sample.nyash→JSON 行生成JSONのみ出力
- リスク: プラグイン解決FileBoxをnyash.tomlで固定
2) LLVM Native EXE GenerationAOTパイプライン継続
- Python/llvmlite implementation as primary path (2400 lines, 10x faster development)
- LLVM backend object → executable pipeline completion
- Separate `nyash-llvm-compiler` crate (reduce main build weight)
- Input: MIR (JSON/binary) → Output: native executable
- Link with nyrt runtime (static/dynamic options)
- Plugin all-direction build strategy (.so/.o/.a simultaneous generation)
- Integration: `nyash --backend llvm --emit exe program.nyash -o program.exe`
3) Standard Ny std impl (P0→実体化)
- Implement P0 methods for string/array/map in Nyash (keep NyRT primitives minimal)
- Enable via `nyash.toml` `[ny_plugins]` (optin); extend `tools/jit_smoke.sh`
4) Ny compiler MVP (Ny→MIR on JIT path) (Phase 15.3) 🎯
- Ny tokenizer + recursivedescent parser (current subset) in Ny; drive existing MIR builder
- Target: 800 lines parser + 2500 lines MIR builder = 3300 lines total
- No circular dependency: nyrt provides StringBox/ArrayBox via C ABI
- Flag path: `NYASH_USE_NY_COMPILER=1` to switch rust→ny compiler; rust parser as fallback
- Add apps/selfhost-compiler/ and minimal smokes
- Stage1 checklist:
- [ ] return/int/string/arithmetic/paren JSON v0 emit
- [ ] Minimal ASInewline separator + continuation tokens
- [ ] Smokes: `return 1+2*3` / grouping / string literal
- Stage2 checklist:
- [ ] local/if/loop/call/method/new/var/logical/compare
- [ ] PHI 合流は Bridge に委譲If/Loop
- [ ] Smokes: nested if / loop 累積 / and/or × if/loop
5) Phase 15.5: Core Box Unification3層→2層革命🎯
- コアBoxnyrt内蔵削除、プラグインBox/ユーザーBoxの2層に統一
- 環境変数制御で段階的移行: `NYASH_USE_PLUGIN_CORE_BOXES=1`
- 削減目標: 約700行nyrt実装600行 + 特別扱い100行
- DLL動作確認→Nyashコード化の安全な移行戦略
- **using構文完全実装**: compiler.nyashのusing構文パース問題解決
- **LLVM ExternCall改善**: print出力問題修正LLVMバックエンド
- 詳細: [phase-15.5-core-box-unification.md](phase-15.5-core-box-unification.md)
6) PHI 自動化は Phase15 後LoopForm = MIR18
- Phase15: 現行の BridgePHI を維持し、E2E 緑とパリティを最優先
- MIR18 (LoopForm): LoopForm 強化逆Loweringで PHI を自動生成(合流点の定型化)
7) Bootstrap loop (c0→c1→c1')
- Use existing trace/hash harness to compare parity; add optional CI gate
- **This achieves self-hosting!** Nyash compiles Nyash
8) VM Layer in Nyash (Phase 15.4) ⚡
- Implement MIR interpreter in Nyash (13 core instructions)
- Dynamic dispatch via MapBox for instruction handlers
- BoxCall/ExternCall bridge to existing infrastructure
- Optional LLVM JIT acceleration for hot paths
- Enable instant execution without compilation
- Expected: 5000 lines for complete VM implementation
9) Plugins CI split (継続)
- Core alwayson (JIT, plugins disabled); Plugins as optional job (strict off by default)
1) Ny JSON ライブラリ(最小 DOM / JSON v0 対応)
- Nyash 製の parse/stringifyobject/array/string/number/bool/null
- Env: `NYASH_JSON_PROVIDER=ny`既定OFF
- Smokes: roundtrip/エラー位置検証quick 任意; CI非ブロック
2) Ny Executor最小命令セット
- ops: const/binop/compare/branch/jump/ret/phiBox 呼び出しは後段)。
- Env: `NYASH_SELFHOST_EXEC=1`既定OFF
- Parity: PyVM/LLVM harness と stdout/exit の一致。
3) 呼び出し最小Console/String/Array/Map P0
- call/externcall/boxcall の最小を接続。未知 extern は STRICT で拒否。
4) Selfhost Parser の EXE 化(任意・後回し可)
- `tools/build_compiler_exe.sh` により JSON v0 emit の単体配布(開発者向け)。
5) PHI 自動化は Phase15 後LoopForm = MIR18
- Phase15: 現行の BridgePHI を維持規約は「incoming pred=実際の遷移元」)。
- MIR18: LoopForm 強化逆Loweringでの自動化に委譲設計のみ先行
6) Plugins CI split継続
- Plugins は任意ジョブstrict offを維持。Core は軽量 quick を常時。
## Later (incremental)
@ -99,6 +62,8 @@ This roadmap is a living checklist to advance Phase 15 with small, safe boxes. U
- JSON dump: `NYASH_DUMP_JSON_IR=1`
- 予告LoopForm: MIR18 で仕様化予定
- Selfhost compiler: `NYASH_USE_NY_COMPILER=1`, child quiet: `NYASH_JSON_ONLY=1`
- JSON provider: `NYASH_JSON_PROVIDER=ny`Ny JSON; 既定OFF
- Ny executor: `NYASH_SELFHOST_EXEC=1`既定OFF
- EXE-first bundle: `tools/build_compiler_exe.sh``dist/nyash_compiler/`
- Load Ny plugins: `NYASH_LOAD_NY_PLUGINS=1` / `--load-ny-plugins`
- AOT smoke: `CLIF_SMOKE_RUN=1`

View File

@ -37,6 +37,7 @@ Rust ランナー側は PyVM 経路にて `NYASH_SELFHOST_EXEC=1` を検出し
### Stage 1 — MIR ローダ23日
- `mir_loader.nyash` で JSON v0 を読み込み、関数/ブロック/命令の構造体に展開(最初は要約のみ)。
- 依存: Nyash 製 JSON ライブラリ(`NYASH_JSON_PROVIDER=ny`)で DOM を提供既定OFF、開発時のみON
- 受け入れ: ロードのみのスモーク(構文要素の個数検証)。
- 備考: 立ち上げ初期は PyVM ハーネス用 MIR JSON`{"functions":…}`も受理し、要約functions数だけ行う既定OFF