refactor: Major interpreter modularization and P2PBox enhancements

Major Interpreter Refactoring:
- Split core.rs (373 lines removed) into focused modules
- Split expressions/calls.rs (460 lines removed) into cleaner structure
- Added new modules: calls.rs, errors.rs, eval.rs, methods_dispatch.rs, state.rs
- Improved separation of concerns across interpreter components

P2PBox Enhancements:
- Added on_once() for one-time event handlers
- Added off() for handler deregistration
- Implemented handler flags with AtomicBool for thread-safe management
- Added loopback testing cache (last_from, last_intent_name)
- Improved Arc-based state sharing for transport and handlers

Plugin Loader Unification (In Progress):
- Created plugin_loader_unified.rs skeleton
- Created plugin_ffi_common.rs for shared FFI utilities
- Migration plan documented (2400 lines → 1100 lines target)

MIR & VM Improvements:
- Enhanced modularized MIR builder structure
- Added BoxCall dispatch improvements
- Better separation in builder modules

Documentation Updates:
- Added Phase 9.79a unified box dispatch plan
- Created plugin loader migration plan
- Updated CURRENT_TASK.md with latest progress

All tests passing (180 tests) - ready for next phase of refactoring

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Moe Charm
2025-08-26 19:13:57 +09:00
parent bec61e38c5
commit 22212aa314
46 changed files with 2383 additions and 1438 deletions

View File

@ -0,0 +1,58 @@
# Phase 9.79a: Unified Box Dispatch (Minimal) + P2PBox Polish
Status: Planned
Last Updated: 2025-08-26
Owner: core-runtime
## Goals
- Unify basic Box methods (toString/type/equals/clone) at the dispatcher level without breaking NyashBox trait.
- Simplify VM/Interpreter method routing with a single, predictable path for “universal” methods.
- Polish P2PBox: formalize share/clone semantics and safe unregister; finalize multi-node + async UX.
## Scope
1) Dispatcher-level unification (非侵襲)
- VM: universal methods (toString/type/equals/clone) を型分岐前に一括処理。
- Interpreter: 同様の「ユニバーサル優先→型別詳細」パターンを採用。
- NyashBoxトレイトは現状の`to_string_box/type_name/equals/clone_box/share_box`を維持。
2) P2PBox磨きPhase 9.79 継続)
- 共有セマンティクス: share_box()はtransport/handlers/flags共有、clone_box()は新規transport
- InProcess unregister: 一致解除 or refcount で安全に戻す(暫定停止の解除)。
- Transport API: `register_intent_handler`は導入済。WS/WebRTCの下準備薄いshimを設計。
- E2E: on()/onOnce()/off()、self-ping、two-node ping-pong、TimeBox併用のasyncデモ。
- VM: P2PヘルパgetLast*/debug_*のtoString/Console出力をInterpreterに寄せて整合。
## Out of Scope今回はやらない
- 全BoxにUnifiedBoxトレイトを適用する大改修段階的移行のため見送り
- ビルトインBoxの完全プラグイン化Phase 10+ 候補)。
- NyashValueの全面置換機会見つけて漸進導入
## Deep Analysis Docとの整合
- まずはディスパッチャで統一(トレイト変更なし)→ 破壊的変更を避けつつ美しさを担保。
- Nyash言語の`toString/type/equals/clone`はVM/Interpreterで中央集約的にRust側APIへ橋渡し。
- 「Everything is Box」を壊さずに一貫した呼び出し体験を提供する。
## Milestones
- M1Day 12
- VM: universal methods 前置ディスパッチ
- Interpreter: 同様の前置ディスパッチ
- スモーク:既存演算子/print動作の回帰なし
- M2Day 34
- P2PBox unregister安全化endpoint一致 or refcount
- E2E: onOnce/off 追加、two-node ping-pong 安定、asyncデモが確実に出力
- M3Day 5
- VM表示整合P2PヘルパのtoString/ConsoleをInterpreterと一致
- Docs更新言語ガイド/P2Pリファレンス反映
## リスクと対策
- VM分岐に触るリスク → 型別分岐の“前段”に追加、既存分岐はフォールバックとして維持
- unregister回りの退行 → 一致解除テスト/順次Dropテストclone/share/Drop順の組み合わせを追加
## 受け入れ基準
- VM/Interpreterの両方で toString/type/equals/clone が統一パスで動作
- P2PBox: multi-node ping-pong + onOnce/off E2Eが通り、asyncデモが確実にログ出力
- 既存スモークに回帰なし、Docs更新完了
## 備考
- UnifiedBox.dispatch_methodはPhase 10での検討項目として温存。
- NyashValueの活用はMIR/VM安定化と歩調を合わせて拡大。