feat(plugins): ArrayBox/MapBoxプラグイン実装とPhase 10.1計画

🎯 革命的発見: プラグインC ABI = JIT→EXE変換の統一基盤

## 主な変更点
- ArrayBoxプラグイン: get/set/push/size/is_empty実装
- MapBoxプラグイン: size/get/has実装(ROメソッドのみ)
- Phase 10.1ドキュメント: プラグインBox統一化計画
- デモファイル3種: プラグイン動作確認用

## 技術的詳細
- BID-FFI (Box ID Foreign Function Interface) 活用
- 既存のプラグインシステムでJIT/AOT統一可能
- スタティックリンクでオーバーヘッド解消
- "Everything is Box → Everything is Plugin → Everything is Executable"

## テスト済み
- array_plugin_demo.nyash: 基本動作確認 
- array_plugin_set_demo.nyash: set操作確認 
- map_plugin_ro_demo.nyash: RO操作確認 

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Moe Charm
2025-08-29 04:37:30 +09:00
parent 3a576a665c
commit c954b1f520
12 changed files with 620 additions and 11 deletions

View File

@ -26,22 +26,22 @@
## 🚀 実装計画
### Week 1: ArrayBoxプラグイン化PoC
### Week 1: ArrayBoxプラグイン化PoC(詳細は phase_plan.md 参照)
- ArrayBoxをプラグインとして再実装
- JITからのプラグイン呼び出しテスト
- パフォーマンス測定HostCall vs Plugin
### Week 2: 主要Box移行
### Week 2: 主要Box移行(詳細は phase_plan.md 参照)
- StringBox、IntegerBox、BoolBoxのプラグイン化
- JIT lowering層の統一plugin_invoke経由
- 既存HostCallとの共存メカニズム
### Week 3: 静的リンク基盤
### Week 3: 静的リンク基盤(詳細は phase_plan.md 参照)
- プラグインの`.a`ライブラリビルド
- 最小ランタイムnyash-runtime設計
- リンカースクリプト作成
### Week 4: EXE生成実証
### Week 4: EXE生成実証(詳細は phase_plan.md 参照)
- Hello Worldレベルのスタンドアロン実行
- Linux/macOSでの動作確認
- デバッグ情報とunwind対応
@ -62,6 +62,8 @@ plugins/
## 🔗 関連資料
- フェーズ計画の詳細: [phase_plan.md](./phase_plan.md)
- [革新的アプローチ詳細](../../../ideas/new-features/2025-08-28-jit-exe-via-plugin-unification.md)
- [プラグインAPI仕様](../../../../reference/plugin-system/)
- [Phase 10.5: Python統合計画](../phase-10.5/) 旧10.1
@ -90,4 +92,4 @@ plugins/
---
*"Everything is Box → Everything is Plugin → Everything is Possible"*
*"Everything is Box → Everything is Plugin → Everything is Possible"*

View File

@ -0,0 +1,77 @@
# Phase 10.1 Plugin Unification Path (MIR→JIT/AOT via C ABI)
This plan refines how we leverage the existing plugin system (BID-FFI) to unify JIT and AOT (EXE) paths using a single C ABI surface.
## Goals
- Unify calls from JIT and AOT to the same C ABI (`nyrt_*` / `nyplug_*`).
- Convert builtin Boxes to Plugin Boxes in small steps (read-only first).
- Produce a minimal standalone EXE via static linking after unification.
## Feasibility Summary
- JIT: emit calls to `extern "C"` symbols (no change in semantics, only target).
- AOT: emit `.o` with unresolved `nyrt_*` / `nyplug_*` and link with `libnyrt.a` + plugin `.a`.
- Compatibility: guard with `NYASH_USE_PLUGIN_BUILTINS` and keep HostCall fallback.
## Phase Breakdown
### 10.1: Plugin PoC + C ABI base (1 week)
- Deliverables:
- Minimal headers: `nyrt.h` (runtime), `nyplug_array.h` (ArrayBox plugin).
- ArrayBox as a plugin (`cdylib` + `staticlib`), ABI version functions.
- VM loader integration and `NYASH_USE_PLUGIN_BUILTINS` switch.
- Smoke: `new/len/push/get` working via plugin.
- DoD:
- Array plugin works on VM path; perf regression ≤10% on micro bench.
### 10.2: JIT Lowering unification (Array first) (11.5 weeks)
- Deliverables:
- IRBuilder: `emit_plugin_invoke(type_id, method_id, args, sig)`.
- LowerCore BoxCall for Array routes to `plugin_invoke` (events/stats intact).
- Feature-flagged enablement: `NYASH_USE_PLUGIN_BUILTINS=1`.
- DoD:
- JIT execution of Array read/write (policy-constrained) via plugin path.
- Behavior parity with HostCall; no regressions on CI smoke.
### 10.3: Broaden plugin coverage + Compatibility (2 weeks)
- Targets: String/Integer/Bool/Map (read-only first).
- Deliverables:
- Pluginized Boxes and `plugin_invoke` lowering for BoxCall.
- HostCall route retained; whitelist-driven co-existence.
- Added smoke and microbenches comparing HostCall vs Plugin.
- DoD:
- ≥5 builtin Boxes pluginized; `NYASH_USE_PLUGIN_BUILTINS=1` green on smoke.
### 10.4: AOT/EXE minimal pipeline (23 weeks)
- Deliverables:
- ObjectWriter path to emit `.o` with unresolved `nyrt_*`/`nyplug_*`.
- `libnyrt.a` minimal runtime + selected plugin `.a`.
- Link scripts and `nyc build-aot` proof-of-concept.
- Hello World-level standalone EXE on Linux/macOS.
- DoD:
- `nyc build-aot <file.nyash> -o app` runs without JIT/VM.
- Basic debug info and minimal unwind.
### 10.5: Python Integration (moved; separate phase)
- Python work is deferred to 10.5 and builds on the plugin/AOT foundation.
## Flags & Compatibility
- `NYASH_USE_PLUGIN_BUILTINS=1` enables plugin path for builtin Boxes.
- `NYASH_JIT_HOSTCALL=1` preserves HostCall path for comparison.
- Call conv alignment: x86_64 SysV, aarch64 AAPCS64, Win64.
- ABI version checks: `nyrt_abi_version()`, `nyplug_*_abi_version()` hard-fail on mismatch.
## Risks & Mitigations
- ABI drift: minimal headers + version checks.
- Linking complexity: start with the smallest set (Array/Print/GC-minimal), expand gradually.
- Performance: keep RO-first; benchmark and fall back to HostCall if needed.
- Windows linkage: prioritize Linux/macOS, then handle Win specifics in a follow-up task.
## References
- `c_abi_unified_design.md`
- `implementation_steps.md`
- `../phase-10.5/` (Python integration)
---
Everything is Plugin → unified paths for JIT and AOT.