Files
hakorune/docs/development/roadmap/phases/phase-10.1/phase_plan.md
Moe Charm c954b1f520 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>
2025-08-29 04:37:30 +09:00

3.3 KiB
Raw Blame History

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.