🔧 refactor: P2PBox複雑実装を削除し段階的実装方針に変更
- 複雑なP2PBox関連実装を削除: * Transport trait + MessageBus + MessageIntentBox + NewP2PBox * 依存関係が複雑で一度に追加すると失敗することを学習 - nyashバイナリのビルドを安定化: * 全てのimportエラーを修正 * cargo build --bin nyash が正常に動作 - CURRENT_TASK.mdに新しい段階的実装方針を記載: * Phase 1: FloatBox (依存なし) * Phase 2: ArrayBox改良 * Phase 3: 演算子システム改良 - 教訓: 一つずつ確実に実装し、テストファーストで進める 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -6,7 +6,7 @@ use crate::interpreter::core::NyashInterpreter;
|
||||
use crate::interpreter::core::RuntimeError;
|
||||
use crate::ast::ASTNode;
|
||||
use crate::box_trait::{NyashBox, StringBox};
|
||||
use crate::boxes::{IntentBox, P2PBox, NewP2PBox, MessageIntentBox};
|
||||
use crate::boxes::{IntentBox, P2PBox};
|
||||
use crate::method_box::MethodBox;
|
||||
|
||||
impl NyashInterpreter {
|
||||
@ -115,143 +115,4 @@ impl NyashInterpreter {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// NewP2PBoxのメソッド実行(天才アルゴリズム版)
|
||||
pub(in crate::interpreter) fn execute_new_p2p_box_method(
|
||||
&mut self,
|
||||
p2p_box: &NewP2PBox,
|
||||
method: &str,
|
||||
arguments: &[ASTNode],
|
||||
) -> Result<Box<dyn NyashBox>, RuntimeError> {
|
||||
match method {
|
||||
// ノードID取得
|
||||
"getNodeId" | "getId" => {
|
||||
Ok(Box::new(StringBox::new(p2p_box.get_node_id())))
|
||||
}
|
||||
|
||||
// メッセージ送信(天才アルゴリズム)
|
||||
"send" => {
|
||||
if arguments.len() != 2 {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: "send requires 2 arguments: target, message_intent_box".to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
let target = self.execute_expression(&arguments[0])?;
|
||||
let message_box = self.execute_expression(&arguments[1])?;
|
||||
|
||||
if let Some(target_str) = target.as_any().downcast_ref::<StringBox>() {
|
||||
if let Some(intent_box) = message_box.as_any().downcast_ref::<MessageIntentBox>() {
|
||||
match p2p_box.send(&target_str.value, intent_box) {
|
||||
Ok(()) => Ok(Box::new(StringBox::new("sent"))),
|
||||
Err(e) => Err(RuntimeError::InvalidOperation { message: e }),
|
||||
}
|
||||
} else {
|
||||
Err(RuntimeError::TypeError {
|
||||
message: "send requires MessageIntentBox as second argument".to_string(),
|
||||
})
|
||||
}
|
||||
} else {
|
||||
Err(RuntimeError::TypeError {
|
||||
message: "send requires string target as first argument".to_string(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// リスナー登録(MethodBox版)
|
||||
"onMethod" => {
|
||||
if arguments.len() != 2 {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: "onMethod requires 2 arguments: intent, method_box".to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
let intent = self.execute_expression(&arguments[0])?;
|
||||
let method_box = self.execute_expression(&arguments[1])?;
|
||||
|
||||
if let Some(intent_str) = intent.as_any().downcast_ref::<StringBox>() {
|
||||
if let Some(method_box) = method_box.as_any().downcast_ref::<MethodBox>() {
|
||||
match p2p_box.on_method(&intent_str.value, method_box.clone()) {
|
||||
Ok(()) => Ok(Box::new(StringBox::new("listener registered"))),
|
||||
Err(e) => Err(RuntimeError::InvalidOperation { message: e }),
|
||||
}
|
||||
} else {
|
||||
Err(RuntimeError::TypeError {
|
||||
message: "onMethod requires MethodBox as second argument".to_string(),
|
||||
})
|
||||
}
|
||||
} else {
|
||||
Err(RuntimeError::TypeError {
|
||||
message: "onMethod requires string intent as first argument".to_string(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
_ => Err(RuntimeError::UndefinedVariable {
|
||||
name: format!("NewP2PBox method '{}' not found", method),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// MessageIntentBoxのメソッド実行
|
||||
pub(in crate::interpreter) fn execute_message_intent_box_method(
|
||||
&mut self,
|
||||
message_box: &mut MessageIntentBox,
|
||||
method: &str,
|
||||
arguments: &[ASTNode],
|
||||
) -> Result<Box<dyn NyashBox>, RuntimeError> {
|
||||
match method {
|
||||
// intent取得
|
||||
"getIntent" | "intent" => {
|
||||
Ok(Box::new(StringBox::new(&message_box.intent)))
|
||||
}
|
||||
|
||||
// データ設定
|
||||
"set" => {
|
||||
if arguments.len() != 2 {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: "set requires 2 arguments: key, value".to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
let key = self.execute_expression(&arguments[0])?;
|
||||
let value = self.execute_expression(&arguments[1])?;
|
||||
|
||||
if let Some(key_str) = key.as_any().downcast_ref::<StringBox>() {
|
||||
message_box.set(&key_str.value, value);
|
||||
Ok(Box::new(StringBox::new("set")))
|
||||
} else {
|
||||
Err(RuntimeError::TypeError {
|
||||
message: "set requires string key as first argument".to_string(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// データ取得
|
||||
"get" => {
|
||||
if arguments.len() != 1 {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: "get requires 1 argument: key".to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
let key = self.execute_expression(&arguments[0])?;
|
||||
if let Some(key_str) = key.as_any().downcast_ref::<StringBox>() {
|
||||
if let Some(value) = message_box.get(&key_str.value) {
|
||||
Ok(value.clone_box())
|
||||
} else {
|
||||
Ok(Box::new(crate::boxes::NullBox::new()))
|
||||
}
|
||||
} else {
|
||||
Err(RuntimeError::TypeError {
|
||||
message: "get requires string key as argument".to_string(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
_ => Err(RuntimeError::UndefinedVariable {
|
||||
name: format!("MessageIntentBox method '{}' not found", method),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user