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:
@ -3,11 +3,12 @@
|
||||
* Arc<Mutex>パターン対応版
|
||||
*/
|
||||
|
||||
use crate::interpreter::core::NyashInterpreter;
|
||||
use crate::interpreter::core::RuntimeError;
|
||||
use crate::interpreter::NyashInterpreter;
|
||||
use crate::interpreter::RuntimeError;
|
||||
use crate::ast::ASTNode;
|
||||
use crate::box_trait::{NyashBox, StringBox};
|
||||
use crate::boxes::{IntentBox};
|
||||
use crate::boxes::{IntentBox, P2PBox};
|
||||
use crate::box_trait::BoolBox;
|
||||
|
||||
impl NyashInterpreter {
|
||||
/// IntentBoxのメソッド実行 (RwLock版)
|
||||
@ -39,75 +40,73 @@ impl NyashInterpreter {
|
||||
}
|
||||
}
|
||||
|
||||
// P2PBoxのメソッド実行 (Arc<Mutex>版) - Temporarily disabled
|
||||
/*
|
||||
// P2PBoxのメソッド実装(RwLockベース)
|
||||
pub(in crate::interpreter) fn execute_p2p_box_method(
|
||||
&mut self,
|
||||
p2p_box: &P2PBox,
|
||||
method: &str,
|
||||
arguments: &[ASTNode],
|
||||
) -> Result<Box<dyn NyashBox>, RuntimeError> {
|
||||
let data = p2p_box.lock().map_err(|_| RuntimeError::UndefinedVariable {
|
||||
name: "Failed to lock P2PBox".to_string(),
|
||||
})?;
|
||||
|
||||
match method {
|
||||
// ノードID取得
|
||||
"getNodeId" | "getId" => {
|
||||
Ok(Box::new(StringBox::new(data.get_node_id().to_string())))
|
||||
}
|
||||
|
||||
"getNodeId" | "getId" => Ok(p2p_box.get_node_id()),
|
||||
|
||||
// トランスポート種類取得
|
||||
"getTransportType" | "transport" => {
|
||||
Ok(Box::new(StringBox::new(data.get_transport_type())))
|
||||
}
|
||||
|
||||
"getTransportType" | "transport" => Ok(p2p_box.get_transport_type()),
|
||||
|
||||
// ノード到達可能性確認
|
||||
"isReachable" => {
|
||||
if arguments.is_empty() {
|
||||
return Err(RuntimeError::UndefinedVariable {
|
||||
name: "isReachable requires node_id argument".to_string(),
|
||||
});
|
||||
return Err(RuntimeError::InvalidOperation { message: "isReachable requires node_id argument".to_string() });
|
||||
}
|
||||
|
||||
let node_id_result = self.execute_expression(&arguments[0])?;
|
||||
let node_id = node_id_result.to_string_box().value;
|
||||
let reachable = data.is_reachable(&node_id);
|
||||
Ok(Box::new(BoolBox::new(reachable)))
|
||||
Ok(p2p_box.is_reachable(node_id_result))
|
||||
}
|
||||
|
||||
// send メソッド実装
|
||||
|
||||
// send メソッド実装(ResultBox返却)
|
||||
"send" => {
|
||||
if arguments.len() < 2 {
|
||||
return Err(RuntimeError::UndefinedVariable {
|
||||
name: "send requires (to, intent) arguments".to_string(),
|
||||
});
|
||||
return Err(RuntimeError::InvalidOperation { message: "send requires (to, intent) arguments".to_string() });
|
||||
}
|
||||
|
||||
let to_result = self.execute_expression(&arguments[0])?;
|
||||
let to = to_result.to_string_box().value;
|
||||
|
||||
let intent_result = self.execute_expression(&arguments[1])?;
|
||||
|
||||
// IntentBoxかチェック
|
||||
if let Some(intent_box) = intent_result.as_any().downcast_ref::<IntentBox>() {
|
||||
match data.send(&to, intent_box.clone()) {
|
||||
Ok(_) => Ok(Box::new(StringBox::new("sent"))),
|
||||
Err(e) => Err(RuntimeError::UndefinedVariable {
|
||||
name: format!("Send failed: {:?}", e),
|
||||
})
|
||||
}
|
||||
} else {
|
||||
Err(RuntimeError::UndefinedVariable {
|
||||
name: "Second argument must be an IntentBox".to_string(),
|
||||
})
|
||||
}
|
||||
Ok(p2p_box.send(to_result, intent_result))
|
||||
}
|
||||
|
||||
_ => Err(RuntimeError::UndefinedVariable {
|
||||
name: format!("P2PBox method '{}' not found", method),
|
||||
})
|
||||
|
||||
// on メソッド実装(ResultBox返却)
|
||||
, "on" => {
|
||||
if arguments.len() < 2 {
|
||||
return Err(RuntimeError::InvalidOperation { message: "on requires (intentName, handler) arguments".to_string() });
|
||||
}
|
||||
let name_val = self.execute_expression(&arguments[0])?;
|
||||
let handler_val = self.execute_expression(&arguments[1])?;
|
||||
Ok(p2p_box.on(name_val, handler_val))
|
||||
}
|
||||
|
||||
// 最後の受信情報(ループバック検証用)
|
||||
"getLastFrom" => Ok(p2p_box.get_last_from()),
|
||||
"getLastIntentName" => Ok(p2p_box.get_last_intent_name()),
|
||||
"debug_nodes" | "debugNodes" => Ok(p2p_box.debug_nodes()),
|
||||
"debug_bus_id" | "debugBusId" => Ok(p2p_box.debug_bus_id()),
|
||||
|
||||
// onOnce / off
|
||||
"onOnce" | "on_once" => {
|
||||
if arguments.len() < 2 {
|
||||
return Err(RuntimeError::InvalidOperation { message: "onOnce requires (intentName, handler) arguments".to_string() });
|
||||
}
|
||||
let name_val = self.execute_expression(&arguments[0])?;
|
||||
let handler_val = self.execute_expression(&arguments[1])?;
|
||||
Ok(p2p_box.on_once(name_val, handler_val))
|
||||
}
|
||||
"off" => {
|
||||
if arguments.len() < 1 {
|
||||
return Err(RuntimeError::InvalidOperation { message: "off requires (intentName) argument".to_string() });
|
||||
}
|
||||
let name_val = self.execute_expression(&arguments[0])?;
|
||||
Ok(p2p_box.off(name_val))
|
||||
}
|
||||
|
||||
_ => Err(RuntimeError::UndefinedVariable { name: format!("P2PBox method '{}' not found", method) }),
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user