Major milestone: - Set up apps/selfhost-compiler/ directory structure - Implement basic Nyash compiler in Nyash (CompilerBox) - Stage-1: Basic arithmetic parser (int/string/+/-/*/括弧/return) - JSON v0 output compatible with --ny-parser-pipe - Runner integration with NYASH_USE_NY_COMPILER=1 flag - Comprehensive smoke tests for PHI/Bridge/Stage-2 Technical updates: - Updated CLAUDE.md with Phase 15.3 status and MIR14 details - Statement separation policy: newline-based with minimal ASI - Fixed runaway ny-parser-pipe processes (CPU 94.9%) - Clarified MIR14 as canonical instruction set (not 13/18) - LoopForm strategy: PHI auto-generation during reverse lowering Collaborative development: - ChatGPT5 implementing compiler skeleton - Codex provided LoopForm PHI generation guidance - Claude maintaining documentation and coordination 🎉 セルフホスティングの歴史的一歩!自分自身をコンパイルする日が近いにゃ! Co-Authored-By: ChatGPT <noreply@openai.com>
6.3 KiB
6.3 KiB
Phase 15 — Box Stacking Roadmap (Living)
This roadmap is a living checklist to advance Phase 15 with small, safe boxes. Update continuously as we progress.
Now (ready/green)
- v0 Ny parser (Ny→JSON IR v0) with wrappers (Unix/Windows)
- Runner JSON v0 bridge (
--ny-parser-pipe) → MIR → MIR-Interp - E2E + roundtrip practical recipes (Windows/Unix)
- Docs path unify (phase-15 under roadmap tree)
- Direct bridge (design + skeleton; feature-gated)
- AOT P2 stubs (CraneliftAotBox/LinkerBox) + RUN smoke wiring
- JIT‑only baseline stabilized (core smokes green; plugins optional)
- Roundtrip (Case A/B) aligned; Case A re‑enabled via parser pipe
- using/namespace (gated) + nyash.link minimal resolver
- NyModules + ny_plugins regression suite (Windows path normalization/namespace derivation)
- Standard Ny scripts scaffolds added (string/array/map P0) + examples + jit_smoke
Next (small boxes)
- LLVM Native EXE Generation (Phase 15.2) 🚀
- Python/llvmlite implementation as primary path (2400 lines, 10x faster development)
- LLVM backend object → executable pipeline completion
- Separate
nyash-llvm-compilercrate (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
- Standard Ny std impl (P0→実体化)
- Implement P0 methods for string/array/map in Nyash (keep NyRT primitives minimal)
- Enable via
nyash.toml[ny_plugins](opt‑in); extendtools/jit_smoke.sh
- Ny compiler MVP (Ny→MIR on JIT path) (Phase 15.3) 🎯
- Ny tokenizer + recursive‑descent 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=1to switch rust→ny compiler; rust parser as fallback - Add apps/selfhost-compiler/ and minimal smokes
- Stage‑1 checklist:
- return/int/string/arithmetic/paren JSON v0 emit
- Minimal ASI(newline separator + continuation tokens)
- Smokes:
return 1+2*3/ grouping / string literal
- Stage‑2 checklist:
- local/if/loop/call/method/new/var/logical/compare
- PHI 合流は Bridge に委譲(If/Loop)
- Smokes: nested if / loop 累積 / and/or × if/loop
- PHI 自動化は Phase‑15 後(Core‑14 LoopForm)
- Phase‑15: 現行の Bridge‑PHI を維持し、E2E 緑とパリティを最優先
- Core‑14: LoopForm 強化+逆Loweringで PHI を自動生成(合流点の定型化)
- Bootstrap loop (c0→c1→c1')
- Use existing trace/hash harness to compare parity; add optional CI gate
- This achieves self-hosting! Nyash compiles Nyash
- 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
- Plugins CI split (継続)
- Core always‑on (JIT, plugins disabled); Plugins as optional job (strict off by default)
Later (incremental)
- v1 Ny parser (let/if/call) behind
NYASH_JSON_IR_VERSION=1 - JSON v1 bridge → MirBuilder (back-compat v0)
- 12.7 sugars normalized patterns in bridge (?. / ?? / range)
- E2E CI-lite matrix (no LLVM) for v0/v1/bridge roundtrip
- Ny script plugin examples under
apps/plugins-scripts/ - Expand std Ny impl (String P1: trim/split/startsWith/endsWith; Array P1: map/each/filter; Map P1: values/entries/forEach)
- using/nyash.link E2E samples under
apps/(small project template) - Tighten Plugins job: migrate samples to Core‑13; re‑enable strict diagnostics
Operational switches
- Parser path:
--parser {rust|ny}orNYASH_USE_NY_PARSER=1 - JSON dump:
NYASH_DUMP_JSON_IR=1 - (予告)LoopForm: Core‑14 で仕様化予定
- Selfhost compiler:
NYASH_USE_NY_COMPILER=1, child quiet:NYASH_JSON_ONLY=1 - Load Ny plugins:
NYASH_LOAD_NY_PLUGINS=1/--load-ny-plugins - AOT smoke:
CLIF_SMOKE_RUN=1
Recipes / Smokes
- JSON v0 bridge:
tools/ny_parser_bridge_smoke.sh/tools/ny_parser_bridge_smoke.ps1 - E2E roundtrip:
tools/ny_roundtrip_smoke.sh/tools/ny_roundtrip_smoke.ps1
Implementation Dependencies
- Phase 15.2 (LLVM EXE) → Phase 15.3 (Nyash Compiler) → Phase 15.4 (VM in Nyash)
- Python llvmlite serves as rapid prototyping path while Rust/inkwell continues
- Plugin all-direction build enables static executable generation
- Total expected Nyash code: ~20,000 lines (75% reduction from 80k Rust)
Stop criteria (Phase 15)
- v0 E2E green (parser pipe + direct bridge) including Ny compiler MVP switch
- v1 minimal samples pass via JSON bridge
- AOT P2: emit→link→run stable for constant/arith
- Phase‑15 STOP には PHI 切替を含めない(PHI は LoopForm/Core‑14 で扱う)
- 15.3: Stage‑1 代表サンプル緑 + Bootstrap smoke(フォールバック許容)+ 文分離ポリシー公開
- Docs/recipes usable on Windows/Unix
Notes
- JSON is a temporary, safe boundary. We will keep it for observability even after the in-proc bridge is default.
- Favor smallest viable steps; do not couple large refactors with new features.
Ny Plugins → Namespace (Plan)
- Phase A (minimal): Add a shared
NyModulesregistry (env.modules.{set,get}).- Map file path → namespace (project‑relative, separators →
., trim extension). - R5 hook: if a Ny plugin returns an exports map/static box, register it under the derived namespace.
- Guard: reject reserved prefixes (e.g.,
nyashstd.*,system.*).
- Map file path → namespace (project‑relative, separators →
- Phase B (scope): Optionally run
[ny_plugins]in a shared Interpreter to share static definitions.- Flag:
NYASH_NY_PLUGINS_SHARED=0to keep isolated execution. - Logs:
[ny_plugins] <ns>: REGISTERED | FAIL(reason).
- Flag:
- Phase C (language bridge): Resolve
using foo.barviaNyModules, then fallback to file/package resolver (nyash.link).- Keep IDE‑friendly fully qualified access; integrate with future
nyash_modules/.
- Keep IDE‑friendly fully qualified access; integrate with future