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

@ -11,6 +11,7 @@ use crate::instance_v2::InstanceBox;
use std::fmt::{Debug, Display};
use std::any::Any;
use std::sync::{Arc, Mutex};
use once_cell::sync::OnceCell;
/// BoxType enum - ChatGPT先生の提案に従い、Box型を分類
#[derive(Debug)]
@ -81,9 +82,10 @@ impl MethodBox {
/// メソッドを呼び出す
pub fn invoke(&self, _args: Vec<Box<dyn NyashBox>>) -> Result<Box<dyn NyashBox>, String> {
// TODO: インタープリタとの統合が必要
// 現在は仮実装
Err(format!("MethodBox.invoke not yet implemented for method '{}'", self.method_name))
if let Some(invoker) = METHOD_INVOKER.get() {
return invoker.invoke(self, _args);
}
Err(format!("MethodBox.invoke not configured (no invoker) for method '{}'", self.method_name))
}
/// インスタンスを取得(内部使用)
@ -92,6 +94,17 @@ impl MethodBox {
}
}
/// Global invoker hook to connect MethodBox to the interpreter
pub trait MethodInvoker: Send + Sync {
fn invoke(&self, method: &MethodBox, args: Vec<Box<dyn NyashBox>>) -> Result<Box<dyn NyashBox>, String>;
}
static METHOD_INVOKER: OnceCell<Arc<dyn MethodInvoker + Send + Sync>> = OnceCell::new();
pub fn set_method_invoker(invoker: Arc<dyn MethodInvoker + Send + Sync>) {
let _ = METHOD_INVOKER.set(invoker);
}
impl NyashBox for MethodBox {
fn to_string_box(&self) -> StringBox {
StringBox::new(format!("<MethodBox: {}>", self.method_name))
@ -217,4 +230,4 @@ impl EphemeralInstance {
/// MethodBox作成用のビルダー構文サポート
pub fn create_method_box(instance: Box<dyn NyashBox>, method_name: &str) -> Box<dyn NyashBox> {
Box::new(MethodBox::new(instance, method_name.to_string()))
}
}