chore(fmt): add legacy stubs and strip trailing whitespace to unblock cargo fmt

This commit is contained in:
Selfhosting Dev
2025-09-17 07:43:07 +09:00
parent fcf8ce1f3c
commit adbb0201a9
385 changed files with 35622 additions and 15004 deletions

View File

@ -1,22 +1,26 @@
/*!
* Basic Box Methods Module
*
*
* Extracted from box_methods.rs
* Contains method implementations for:
* - StringBox (execute_string_method)
* - IntegerBox (execute_integer_method)
* - IntegerBox (execute_integer_method)
* - BoolBox (execute_bool_method)
* - FloatBox (execute_float_method)
*/
use super::super::*;
use crate::box_trait::{StringBox, IntegerBox, BoolBox, VoidBox};
use crate::box_trait::{BoolBox, IntegerBox, StringBox, VoidBox};
use crate::boxes::FloatBox;
impl NyashInterpreter {
/// StringBoxのメソッド呼び出しを実行
pub(in crate::interpreter) fn execute_string_method(&mut self, string_box: &StringBox, method: &str, arguments: &[ASTNode])
-> Result<Box<dyn NyashBox>, RuntimeError> {
pub(in crate::interpreter) fn execute_string_method(
&mut self,
string_box: &StringBox,
method: &str,
arguments: &[ASTNode],
) -> Result<Box<dyn NyashBox>, RuntimeError> {
match method {
"split" => {
if arguments.len() != 1 {
@ -93,7 +97,7 @@ impl NyashInterpreter {
let new_value = self.execute_expression(&arguments[1])?;
if let (Some(old_str), Some(new_str)) = (
old_value.as_any().downcast_ref::<StringBox>(),
new_value.as_any().downcast_ref::<StringBox>()
new_value.as_any().downcast_ref::<StringBox>(),
) {
Ok(string_box.replace(&old_str.value, &new_str.value))
} else {
@ -129,7 +133,10 @@ impl NyashInterpreter {
"toInteger" => {
if !arguments.is_empty() {
return Err(RuntimeError::InvalidOperation {
message: format!("toInteger() expects 0 arguments, got {}", arguments.len()),
message: format!(
"toInteger() expects 0 arguments, got {}",
arguments.len()
),
});
}
Ok(string_box.to_integer())
@ -137,12 +144,15 @@ impl NyashInterpreter {
"substring" => {
if arguments.len() != 2 {
return Err(RuntimeError::InvalidOperation {
message: format!("substring() expects 2 arguments, got {}", arguments.len()),
message: format!(
"substring() expects 2 arguments, got {}",
arguments.len()
),
});
}
let start = self.execute_expression(&arguments[0])?;
let end = self.execute_expression(&arguments[1])?;
// Convert arguments to integers
let start_int = if let Some(int_box) = start.as_any().downcast_ref::<IntegerBox>() {
int_box.value as usize
@ -151,7 +161,7 @@ impl NyashInterpreter {
message: "substring() expects integer arguments".to_string(),
});
};
let end_int = if let Some(int_box) = end.as_any().downcast_ref::<IntegerBox>() {
int_box.value as usize
} else {
@ -159,20 +169,22 @@ impl NyashInterpreter {
message: "substring() expects integer arguments".to_string(),
});
};
Ok(string_box.substring(start_int, end_int))
}
_ => {
Err(RuntimeError::InvalidOperation {
message: format!("Unknown method '{}' for StringBox", method),
})
}
_ => Err(RuntimeError::InvalidOperation {
message: format!("Unknown method '{}' for StringBox", method),
}),
}
}
/// IntegerBoxのメソッド呼び出しを実行
pub(in crate::interpreter) fn execute_integer_method(&mut self, integer_box: &IntegerBox, method: &str, arguments: &[ASTNode])
-> Result<Box<dyn NyashBox>, RuntimeError> {
pub(in crate::interpreter) fn execute_integer_method(
&mut self,
integer_box: &IntegerBox,
method: &str,
arguments: &[ASTNode],
) -> Result<Box<dyn NyashBox>, RuntimeError> {
match method {
"toString" => {
if !arguments.is_empty() {
@ -198,7 +210,9 @@ impl NyashInterpreter {
}
let other_value = self.execute_expression(&arguments[0])?;
if let Some(other_int) = other_value.as_any().downcast_ref::<IntegerBox>() {
Ok(Box::new(IntegerBox::new(integer_box.value.max(other_int.value))))
Ok(Box::new(IntegerBox::new(
integer_box.value.max(other_int.value),
)))
} else {
Err(RuntimeError::TypeError {
message: "max() requires integer argument".to_string(),
@ -213,7 +227,9 @@ impl NyashInterpreter {
}
let other_value = self.execute_expression(&arguments[0])?;
if let Some(other_int) = other_value.as_any().downcast_ref::<IntegerBox>() {
Ok(Box::new(IntegerBox::new(integer_box.value.min(other_int.value))))
Ok(Box::new(IntegerBox::new(
integer_box.value.min(other_int.value),
)))
} else {
Err(RuntimeError::TypeError {
message: "min() requires integer argument".to_string(),
@ -249,17 +265,19 @@ impl NyashInterpreter {
})
}
}
_ => {
Err(RuntimeError::InvalidOperation {
message: format!("Unknown method '{}' for IntegerBox", method),
})
}
_ => Err(RuntimeError::InvalidOperation {
message: format!("Unknown method '{}' for IntegerBox", method),
}),
}
}
/// BoolBoxのメソッド呼び出しを実行
pub(in crate::interpreter) fn execute_bool_method(&mut self, bool_box: &BoolBox, method: &str, arguments: &[ASTNode])
-> Result<Box<dyn NyashBox>, RuntimeError> {
pub(in crate::interpreter) fn execute_bool_method(
&mut self,
bool_box: &BoolBox,
method: &str,
arguments: &[ASTNode],
) -> Result<Box<dyn NyashBox>, RuntimeError> {
match method {
"toString" => {
if !arguments.is_empty() {
@ -316,17 +334,19 @@ impl NyashInterpreter {
let other_value = self.execute_expression(&arguments[0])?;
Ok(Box::new(bool_box.equals(&*other_value)))
}
_ => {
Err(RuntimeError::InvalidOperation {
message: format!("Unknown method '{}' for BoolBox", method),
})
}
_ => Err(RuntimeError::InvalidOperation {
message: format!("Unknown method '{}' for BoolBox", method),
}),
}
}
/// FloatBoxのメソッド呼び出しを実行
pub(in crate::interpreter) fn execute_float_method(&mut self, float_box: &FloatBox, method: &str, arguments: &[ASTNode])
-> Result<Box<dyn NyashBox>, RuntimeError> {
pub(in crate::interpreter) fn execute_float_method(
&mut self,
float_box: &FloatBox,
method: &str,
arguments: &[ASTNode],
) -> Result<Box<dyn NyashBox>, RuntimeError> {
match method {
"toString" => {
if !arguments.is_empty() {
@ -371,7 +391,10 @@ impl NyashInterpreter {
"toInteger" => {
if !arguments.is_empty() {
return Err(RuntimeError::InvalidOperation {
message: format!("toInteger() expects 0 arguments, got {}", arguments.len()),
message: format!(
"toInteger() expects 0 arguments, got {}",
arguments.len()
),
});
}
Ok(Box::new(IntegerBox::new(float_box.value as i64)))
@ -384,9 +407,13 @@ impl NyashInterpreter {
}
let other_value = self.execute_expression(&arguments[0])?;
if let Some(other_float) = other_value.as_any().downcast_ref::<FloatBox>() {
Ok(Box::new(FloatBox::new(float_box.value.max(other_float.value))))
Ok(Box::new(FloatBox::new(
float_box.value.max(other_float.value),
)))
} else if let Some(other_int) = other_value.as_any().downcast_ref::<IntegerBox>() {
Ok(Box::new(FloatBox::new(float_box.value.max(other_int.value as f64))))
Ok(Box::new(FloatBox::new(
float_box.value.max(other_int.value as f64),
)))
} else {
Err(RuntimeError::TypeError {
message: "max() requires numeric argument".to_string(),
@ -401,9 +428,13 @@ impl NyashInterpreter {
}
let other_value = self.execute_expression(&arguments[0])?;
if let Some(other_float) = other_value.as_any().downcast_ref::<FloatBox>() {
Ok(Box::new(FloatBox::new(float_box.value.min(other_float.value))))
Ok(Box::new(FloatBox::new(
float_box.value.min(other_float.value),
)))
} else if let Some(other_int) = other_value.as_any().downcast_ref::<IntegerBox>() {
Ok(Box::new(FloatBox::new(float_box.value.min(other_int.value as f64))))
Ok(Box::new(FloatBox::new(
float_box.value.min(other_int.value as f64),
)))
} else {
Err(RuntimeError::TypeError {
message: "min() requires numeric argument".to_string(),
@ -418,9 +449,15 @@ impl NyashInterpreter {
}
let exponent_value = self.execute_expression(&arguments[0])?;
if let Some(exponent_float) = exponent_value.as_any().downcast_ref::<FloatBox>() {
Ok(Box::new(FloatBox::new(float_box.value.powf(exponent_float.value))))
} else if let Some(exponent_int) = exponent_value.as_any().downcast_ref::<IntegerBox>() {
Ok(Box::new(FloatBox::new(float_box.value.powf(exponent_int.value as f64))))
Ok(Box::new(FloatBox::new(
float_box.value.powf(exponent_float.value),
)))
} else if let Some(exponent_int) =
exponent_value.as_any().downcast_ref::<IntegerBox>()
{
Ok(Box::new(FloatBox::new(
float_box.value.powf(exponent_int.value as f64),
)))
} else {
Err(RuntimeError::TypeError {
message: "pow() requires numeric exponent".to_string(),
@ -512,7 +549,10 @@ impl NyashInterpreter {
"isInfinite" => {
if !arguments.is_empty() {
return Err(RuntimeError::InvalidOperation {
message: format!("isInfinite() expects 0 arguments, got {}", arguments.len()),
message: format!(
"isInfinite() expects 0 arguments, got {}",
arguments.len()
),
});
}
Ok(Box::new(BoolBox::new(float_box.value.is_infinite())))
@ -534,11 +574,9 @@ impl NyashInterpreter {
let other_value = self.execute_expression(&arguments[0])?;
Ok(Box::new(float_box.equals(&*other_value)))
}
_ => {
Err(RuntimeError::InvalidOperation {
message: format!("Unknown method '{}' for FloatBox", method),
})
}
_ => Err(RuntimeError::InvalidOperation {
message: format!("Unknown method '{}' for FloatBox", method),
}),
}
}
}
}

View File

@ -1,6 +1,6 @@
/*!
* Collection Methods Module
*
*
* Extracted from box_methods.rs
* Contains method implementations for collection types:
* - ArrayBox (execute_array_method)
@ -8,13 +8,17 @@
*/
use super::super::*;
use crate::box_trait::{IntegerBox, NyashBox, BoolBox};
use crate::box_trait::{BoolBox, IntegerBox, NyashBox};
use crate::boxes::{ArrayBox, MapBox};
impl NyashInterpreter {
/// ArrayBoxのメソッド呼び出しを実行
pub(in crate::interpreter) fn execute_array_method(&mut self, array_box: &ArrayBox, method: &str, arguments: &[ASTNode])
-> Result<Box<dyn NyashBox>, RuntimeError> {
pub(in crate::interpreter) fn execute_array_method(
&mut self,
array_box: &ArrayBox,
method: &str,
arguments: &[ASTNode],
) -> Result<Box<dyn NyashBox>, RuntimeError> {
match method {
"of" => {
// Build a new ArrayBox from provided arguments
@ -154,25 +158,29 @@ impl NyashInterpreter {
"slice" => {
if arguments.len() != 2 {
return Err(RuntimeError::InvalidOperation {
message: format!("slice() expects 2 arguments (start, end), got {}", arguments.len()),
message: format!(
"slice() expects 2 arguments (start, end), got {}",
arguments.len()
),
});
}
let start_value = self.execute_expression(&arguments[0])?;
let end_value = self.execute_expression(&arguments[1])?;
Ok(array_box.slice(start_value, end_value))
}
_ => {
Err(RuntimeError::InvalidOperation {
message: format!("Unknown method '{}' for ArrayBox", method),
})
}
_ => Err(RuntimeError::InvalidOperation {
message: format!("Unknown method '{}' for ArrayBox", method),
}),
}
}
/// MapBoxのメソッド呼び出しを実行
pub(in crate::interpreter) fn execute_map_method(&mut self, map_box: &MapBox, method: &str, arguments: &[ASTNode])
-> Result<Box<dyn NyashBox>, RuntimeError> {
pub(in crate::interpreter) fn execute_map_method(
&mut self,
map_box: &MapBox,
method: &str,
arguments: &[ASTNode],
) -> Result<Box<dyn NyashBox>, RuntimeError> {
// メソッドを実行(必要時評価方式)
match method {
"set" => {
@ -260,7 +268,10 @@ impl NyashInterpreter {
"containsKey" => {
if arguments.len() != 1 {
return Err(RuntimeError::InvalidOperation {
message: format!("containsKey() expects 1 argument, got {}", arguments.len()),
message: format!(
"containsKey() expects 1 argument, got {}",
arguments.len()
),
});
}
let key_value = self.execute_expression(&arguments[0])?;
@ -269,7 +280,10 @@ impl NyashInterpreter {
"containsValue" => {
if arguments.len() != 1 {
return Err(RuntimeError::InvalidOperation {
message: format!("containsValue() expects 1 argument, got {}", arguments.len()),
message: format!(
"containsValue() expects 1 argument, got {}",
arguments.len()
),
});
}
let _value = self.execute_expression(&arguments[0])?;
@ -303,11 +317,9 @@ impl NyashInterpreter {
}
Ok(Box::new(map_box.to_string_box()))
}
_ => {
Err(RuntimeError::InvalidOperation {
message: format!("Unknown MapBox method: {}", method),
})
}
_ => Err(RuntimeError::InvalidOperation {
message: format!("Unknown MapBox method: {}", method),
}),
}
}
}

View File

@ -1,6 +1,6 @@
/*!
* Data Processing Box Methods Module
*
*
* Contains method implementations for data processing Box types:
* - BufferBox (execute_buffer_method) - Binary data operations
* - JSONBox (execute_json_method) - JSON parsing and manipulation
@ -13,8 +13,12 @@ use crate::boxes::{buffer::BufferBox, JSONBox, RegexBox};
impl NyashInterpreter {
/// BufferBoxのメソッド呼び出しを実行
pub(in crate::interpreter) fn execute_buffer_method(&mut self, buffer_box: &BufferBox, method: &str, arguments: &[ASTNode])
-> Result<Box<dyn NyashBox>, RuntimeError> {
pub(in crate::interpreter) fn execute_buffer_method(
&mut self,
buffer_box: &BufferBox,
method: &str,
arguments: &[ASTNode],
) -> Result<Box<dyn NyashBox>, RuntimeError> {
match method {
"write" => {
if arguments.len() != 1 {
@ -81,7 +85,10 @@ impl NyashInterpreter {
"is_shared_with" => {
if arguments.len() != 1 {
return Err(RuntimeError::InvalidOperation {
message: format!("is_shared_with() expects 1 argument, got {}", arguments.len()),
message: format!(
"is_shared_with() expects 1 argument, got {}",
arguments.len()
),
});
}
let other = self.execute_expression(&arguments[0])?;
@ -90,7 +97,10 @@ impl NyashInterpreter {
"share_reference" => {
if arguments.len() != 1 {
return Err(RuntimeError::InvalidOperation {
message: format!("share_reference() expects 1 argument, got {}", arguments.len()),
message: format!(
"share_reference() expects 1 argument, got {}",
arguments.len()
),
});
}
let data = self.execute_expression(&arguments[0])?;
@ -99,20 +109,27 @@ impl NyashInterpreter {
"memory_footprint" => {
if !arguments.is_empty() {
return Err(RuntimeError::InvalidOperation {
message: format!("memory_footprint() expects 0 arguments, got {}", arguments.len()),
message: format!(
"memory_footprint() expects 0 arguments, got {}",
arguments.len()
),
});
}
Ok(buffer_box.memory_footprint())
}
_ => Err(RuntimeError::InvalidOperation {
message: format!("Unknown method '{}' for BufferBox", method),
})
}),
}
}
/// JSONBoxのメソッド呼び出しを実行
pub(in crate::interpreter) fn execute_json_method(&mut self, json_box: &JSONBox, method: &str, arguments: &[ASTNode])
-> Result<Box<dyn NyashBox>, RuntimeError> {
pub(in crate::interpreter) fn execute_json_method(
&mut self,
json_box: &JSONBox,
method: &str,
arguments: &[ASTNode],
) -> Result<Box<dyn NyashBox>, RuntimeError> {
match method {
"parse" => {
if arguments.len() != 1 {
@ -126,7 +143,10 @@ impl NyashInterpreter {
"stringify" => {
if !arguments.is_empty() {
return Err(RuntimeError::InvalidOperation {
message: format!("stringify() expects 0 arguments, got {}", arguments.len()),
message: format!(
"stringify() expects 0 arguments, got {}",
arguments.len()
),
});
}
Ok(json_box.stringify())
@ -169,13 +189,17 @@ impl NyashInterpreter {
}
_ => Err(RuntimeError::InvalidOperation {
message: format!("Unknown method '{}' for JSONBox", method),
})
}),
}
}
/// RegexBoxのメソッド呼び出しを実行
pub(in crate::interpreter) fn execute_regex_method(&mut self, regex_box: &RegexBox, method: &str, arguments: &[ASTNode])
-> Result<Box<dyn NyashBox>, RuntimeError> {
pub(in crate::interpreter) fn execute_regex_method(
&mut self,
regex_box: &RegexBox,
method: &str,
arguments: &[ASTNode],
) -> Result<Box<dyn NyashBox>, RuntimeError> {
match method {
"test" => {
if arguments.len() != 1 {
@ -225,7 +249,7 @@ impl NyashInterpreter {
}
_ => Err(RuntimeError::InvalidOperation {
message: format!("Unknown method '{}' for RegexBox", method),
})
}),
}
}
}
}

View File

@ -1,19 +1,19 @@
/*! 🌐 HTTP Method Implementations
*
*
* HTTP関連Boxのメソッド実行を実装
* SocketBox, HTTPServerBox, HTTPRequestBox, HTTPResponseBox
*/
use super::super::*;
use crate::boxes::{SocketBox, HTTPServerBox, HTTPRequestBox, HTTPResponseBox};
use crate::boxes::{HTTPRequestBox, HTTPResponseBox, HTTPServerBox, SocketBox};
impl NyashInterpreter {
/// SocketBox methods
pub(in crate::interpreter) fn execute_socket_method(
&mut self,
socket_box: &SocketBox,
method: &str,
arguments: &[ASTNode]
&mut self,
socket_box: &SocketBox,
method: &str,
arguments: &[ASTNode],
) -> Result<Box<dyn NyashBox>, RuntimeError> {
match method {
"bind" => {
@ -22,7 +22,7 @@ impl NyashInterpreter {
message: format!("bind() expects 2 arguments, got {}", arguments.len()),
});
}
let address = self.execute_expression(&arguments[0])?;
let port = self.execute_expression(&arguments[1])?;
let result = socket_box.bind(address, port);
@ -34,7 +34,7 @@ impl NyashInterpreter {
message: format!("listen() expects 1 argument, got {}", arguments.len()),
});
}
let backlog = self.execute_expression(&arguments[0])?;
Ok(socket_box.listen(backlog))
}
@ -44,13 +44,16 @@ impl NyashInterpreter {
message: format!("accept() expects 0 arguments, got {}", arguments.len()),
});
}
Ok(socket_box.accept())
}
"acceptTimeout" | "accept_timeout" => {
if arguments.len() != 1 {
return Err(RuntimeError::InvalidOperation {
message: format!("acceptTimeout(ms) expects 1 argument, got {}", arguments.len()),
message: format!(
"acceptTimeout(ms) expects 1 argument, got {}",
arguments.len()
),
});
}
let ms = self.execute_expression(&arguments[0])?;
@ -62,7 +65,7 @@ impl NyashInterpreter {
message: format!("connect() expects 2 arguments, got {}", arguments.len()),
});
}
let address = self.execute_expression(&arguments[0])?;
let port = self.execute_expression(&arguments[1])?;
Ok(socket_box.connect(address, port))
@ -73,13 +76,16 @@ impl NyashInterpreter {
message: format!("read() expects 0 arguments, got {}", arguments.len()),
});
}
Ok(socket_box.read())
}
"recvTimeout" | "recv_timeout" => {
if arguments.len() != 1 {
return Err(RuntimeError::InvalidOperation {
message: format!("recvTimeout(ms) expects 1 argument, got {}", arguments.len()),
message: format!(
"recvTimeout(ms) expects 1 argument, got {}",
arguments.len()
),
});
}
let ms = self.execute_expression(&arguments[0])?;
@ -88,10 +94,13 @@ impl NyashInterpreter {
"readHttpRequest" => {
if !arguments.is_empty() {
return Err(RuntimeError::InvalidOperation {
message: format!("readHttpRequest() expects 0 arguments, got {}", arguments.len()),
message: format!(
"readHttpRequest() expects 0 arguments, got {}",
arguments.len()
),
});
}
Ok(socket_box.read_http_request())
}
"write" => {
@ -100,7 +109,7 @@ impl NyashInterpreter {
message: format!("write() expects 1 argument, got {}", arguments.len()),
});
}
let data = self.execute_expression(&arguments[0])?;
Ok(socket_box.write(data))
}
@ -110,16 +119,19 @@ impl NyashInterpreter {
message: format!("close() expects 0 arguments, got {}", arguments.len()),
});
}
Ok(socket_box.close())
}
"isConnected" => {
if !arguments.is_empty() {
return Err(RuntimeError::InvalidOperation {
message: format!("isConnected() expects 0 arguments, got {}", arguments.len()),
message: format!(
"isConnected() expects 0 arguments, got {}",
arguments.len()
),
});
}
Ok(socket_box.is_connected())
}
"isServer" => {
@ -128,7 +140,7 @@ impl NyashInterpreter {
message: format!("isServer() expects 0 arguments, got {}", arguments.len()),
});
}
Ok(socket_box.is_server())
}
"toString" => {
@ -137,7 +149,7 @@ impl NyashInterpreter {
message: format!("toString() expects 0 arguments, got {}", arguments.len()),
});
}
Ok(Box::new(socket_box.to_string_box()))
}
_ => Err(RuntimeError::UndefinedVariable {
@ -148,10 +160,10 @@ impl NyashInterpreter {
/// HTTPServerBox methods
pub(in crate::interpreter) fn execute_http_server_method(
&mut self,
server_box: &HTTPServerBox,
method: &str,
arguments: &[ASTNode]
&mut self,
server_box: &HTTPServerBox,
method: &str,
arguments: &[ASTNode],
) -> Result<Box<dyn NyashBox>, RuntimeError> {
match method {
"bind" => {
@ -160,7 +172,7 @@ impl NyashInterpreter {
message: format!("bind() expects 2 arguments, got {}", arguments.len()),
});
}
let address = self.execute_expression(&arguments[0])?;
let port = self.execute_expression(&arguments[1])?;
Ok(server_box.bind(address, port))
@ -171,7 +183,7 @@ impl NyashInterpreter {
message: format!("listen() expects 1 argument, got {}", arguments.len()),
});
}
let backlog = self.execute_expression(&arguments[0])?;
Ok(server_box.listen(backlog))
}
@ -181,7 +193,7 @@ impl NyashInterpreter {
message: format!("start() expects 0 arguments, got {}", arguments.len()),
});
}
Ok(server_box.start())
}
"stop" => {
@ -190,7 +202,7 @@ impl NyashInterpreter {
message: format!("stop() expects 0 arguments, got {}", arguments.len()),
});
}
Ok(server_box.stop())
}
"get" => {
@ -199,7 +211,7 @@ impl NyashInterpreter {
message: format!("get() expects 2 arguments, got {}", arguments.len()),
});
}
let path = self.execute_expression(&arguments[0])?;
let handler = self.execute_expression(&arguments[1])?;
Ok(server_box.get(path, handler))
@ -210,7 +222,7 @@ impl NyashInterpreter {
message: format!("toString() expects 0 arguments, got {}", arguments.len()),
});
}
Ok(Box::new(server_box.to_string_box()))
}
_ => Err(RuntimeError::UndefinedVariable {
@ -221,19 +233,22 @@ impl NyashInterpreter {
/// HTTPRequestBox methods
pub(in crate::interpreter) fn execute_http_request_method(
&mut self,
request_box: &HTTPRequestBox,
method: &str,
arguments: &[ASTNode]
&mut self,
request_box: &HTTPRequestBox,
method: &str,
arguments: &[ASTNode],
) -> Result<Box<dyn NyashBox>, RuntimeError> {
match method {
"getMethod" => {
if !arguments.is_empty() {
return Err(RuntimeError::InvalidOperation {
message: format!("getMethod() expects 0 arguments, got {}", arguments.len()),
message: format!(
"getMethod() expects 0 arguments, got {}",
arguments.len()
),
});
}
Ok(request_box.get_method())
}
"getPath" => {
@ -242,7 +257,7 @@ impl NyashInterpreter {
message: format!("getPath() expects 0 arguments, got {}", arguments.len()),
});
}
Ok(request_box.get_path())
}
"toString" => {
@ -251,7 +266,7 @@ impl NyashInterpreter {
message: format!("toString() expects 0 arguments, got {}", arguments.len()),
});
}
Ok(Box::new(request_box.to_string_box()))
}
_ => Err(RuntimeError::UndefinedVariable {
@ -262,19 +277,22 @@ impl NyashInterpreter {
/// HTTPResponseBox methods
pub(in crate::interpreter) fn execute_http_response_method(
&mut self,
response_box: &HTTPResponseBox,
method: &str,
arguments: &[ASTNode]
&mut self,
response_box: &HTTPResponseBox,
method: &str,
arguments: &[ASTNode],
) -> Result<Box<dyn NyashBox>, RuntimeError> {
match method {
"setStatus" => {
if arguments.len() != 2 {
return Err(RuntimeError::InvalidOperation {
message: format!("setStatus() expects 2 arguments, got {}", arguments.len()),
message: format!(
"setStatus() expects 2 arguments, got {}",
arguments.len()
),
});
}
let code = self.execute_expression(&arguments[0])?;
let message = self.execute_expression(&arguments[1])?;
Ok(response_box.set_status(code, message))
@ -282,10 +300,13 @@ impl NyashInterpreter {
"toHttpString" => {
if !arguments.is_empty() {
return Err(RuntimeError::InvalidOperation {
message: format!("toHttpString() expects 0 arguments, got {}", arguments.len()),
message: format!(
"toHttpString() expects 0 arguments, got {}",
arguments.len()
),
});
}
Ok(response_box.to_http_string())
}
"toString" => {
@ -294,7 +315,7 @@ impl NyashInterpreter {
message: format!("toString() expects 0 arguments, got {}", arguments.len()),
});
}
Ok(Box::new(response_box.to_string_box()))
}
_ => Err(RuntimeError::UndefinedVariable {

View File

@ -1,6 +1,6 @@
/*!
* I/O Operations Box Methods Module
*
*
* Extracted from box_methods.rs
* Contains method implementations for I/O and error handling operations:
* - FileBox (execute_file_method) - File I/O operations
@ -8,17 +8,21 @@
*/
use super::super::*;
use crate::boxes::ResultBox;
use crate::box_trait::{StringBox, NyashBox};
use crate::boxes::FileBox;
use crate::box_trait::{NyashBox, StringBox};
use crate::boxes::ref_cell_box::RefCellBox;
use crate::boxes::FileBox;
use crate::boxes::ResultBox;
// use crate::bid::plugin_box::PluginFileBox; // legacy - FileBox専用
impl NyashInterpreter {
/// FileBoxのメソッド呼び出しを実行
/// Handles file I/O operations including read, write, exists, delete, and copy
pub(in crate::interpreter) fn execute_file_method(&mut self, file_box: &FileBox, method: &str, arguments: &[ASTNode])
-> Result<Box<dyn NyashBox>, RuntimeError> {
pub(in crate::interpreter) fn execute_file_method(
&mut self,
file_box: &FileBox,
method: &str,
arguments: &[ASTNode],
) -> Result<Box<dyn NyashBox>, RuntimeError> {
match method {
"read" => {
if !arguments.is_empty() {
@ -70,14 +74,18 @@ impl NyashInterpreter {
}
_ => Err(RuntimeError::InvalidOperation {
message: format!("Unknown method '{}' for FileBox", method),
})
}),
}
}
/// ResultBoxのメソッド呼び出しを実行
/// Handles result/error checking operations for error handling patterns
pub(in crate::interpreter) fn execute_result_method(&mut self, result_box: &ResultBox, method: &str, arguments: &[ASTNode])
-> Result<Box<dyn NyashBox>, RuntimeError> {
pub(in crate::interpreter) fn execute_result_method(
&mut self,
result_box: &ResultBox,
method: &str,
arguments: &[ASTNode],
) -> Result<Box<dyn NyashBox>, RuntimeError> {
match method {
"isOk" | "is_ok" => {
if !arguments.is_empty() {
@ -105,38 +113,50 @@ impl NyashInterpreter {
}
_ => Err(RuntimeError::InvalidOperation {
message: format!("Unknown method '{}' for ResultBox", method),
})
}),
}
}
/// RefCellBox のメソッド: get()/set(value)
pub(in crate::interpreter) fn execute_refcell_method(&mut self, cell: &RefCellBox, method: &str, arguments: &[ASTNode])
-> Result<Box<dyn NyashBox>, RuntimeError> {
pub(in crate::interpreter) fn execute_refcell_method(
&mut self,
cell: &RefCellBox,
method: &str,
arguments: &[ASTNode],
) -> Result<Box<dyn NyashBox>, RuntimeError> {
match method {
"get" => {
if !arguments.is_empty() {
return Err(RuntimeError::InvalidOperation { message: format!("get() expects 0 arguments, got {}", arguments.len()) });
return Err(RuntimeError::InvalidOperation {
message: format!("get() expects 0 arguments, got {}", arguments.len()),
});
}
Ok(cell.borrow())
}
"set" => {
if arguments.len() != 1 { return Err(RuntimeError::InvalidOperation { message: format!("set() expects 1 argument, got {}", arguments.len()) }); }
if arguments.len() != 1 {
return Err(RuntimeError::InvalidOperation {
message: format!("set() expects 1 argument, got {}", arguments.len()),
});
}
let v = self.execute_expression(&arguments[0])?;
cell.replace(v);
Ok(Box::new(crate::box_trait::VoidBox::new()))
}
_ => Err(RuntimeError::InvalidOperation { message: format!("Unknown method '{}' for RefCellBox", method) })
_ => Err(RuntimeError::InvalidOperation {
message: format!("Unknown method '{}' for RefCellBox", method),
}),
}
}
/* legacy - PluginFileBox専用
/// 汎用プラグインメソッド呼び出し実行 (BID-FFI system)
/// Handles generic plugin method calls via dynamic method discovery
pub(in crate::interpreter) fn execute_plugin_method_generic(&mut self, plugin_box: &PluginFileBox, method: &str, arguments: &[ASTNode])
pub(in crate::interpreter) fn execute_plugin_method_generic(&mut self, plugin_box: &PluginFileBox, method: &str, arguments: &[ASTNode])
-> Result<Box<dyn NyashBox>, RuntimeError> {
eprintln!("🔍 execute_plugin_method_generic: method='{}', args_count={}", method, arguments.len());
// まず利用可能なメソッドを確認
match plugin_box.get_available_methods() {
Ok(methods) => {
@ -147,11 +167,11 @@ impl NyashInterpreter {
}
Err(e) => eprintln!("⚠️ Failed to get plugin methods: {:?}", e),
}
// 引数をTLVエンコードメソッド名も渡す
let encoded_args = self.encode_arguments_to_tlv(arguments, method)?;
eprintln!("🔍 Encoded args length: {} bytes", encoded_args.len());
// プラグインのメソッドを動的呼び出し
match plugin_box.call_method(method, &encoded_args) {
Ok(response_bytes) => {
@ -172,25 +192,25 @@ impl NyashInterpreter {
fn encode_arguments_to_tlv(&mut self, arguments: &[ASTNode], method_name: &str) -> Result<Vec<u8>, RuntimeError> {
use crate::bid::tlv::TlvEncoder;
use crate::bid::registry;
let mut encoder = TlvEncoder::new();
// 型情報を取得FileBoxのみ対応、後で拡張
let type_info = registry::global()
.and_then(|reg| reg.get_method_type_info("FileBox", method_name));
// 型情報がある場合は、それに従って変換
if let Some(type_info) = type_info {
eprintln!("✨ Using type info for method '{}'", method_name);
// 引数の数をチェック
if arguments.len() != type_info.args.len() {
return Err(RuntimeError::InvalidOperation {
message: format!("{} expects {} arguments, got {}",
message: format!("{} expects {} arguments, got {}",
method_name, type_info.args.len(), arguments.len()),
});
}
// 各引数を型情報に従ってエンコード
for (i, (arg, mapping)) in arguments.iter().zip(&type_info.args).enumerate() {
eprintln!(" 🔄 Arg[{}]: {} -> {} conversion", i, mapping.from, mapping.to);
@ -205,15 +225,15 @@ impl NyashInterpreter {
self.encode_value_default(&mut encoder, value)?;
}
}
Ok(encoder.finish())
}
/// 型マッピングに基づいて値をエンコード(美しい!)
fn encode_value_with_mapping(
&self,
encoder: &mut crate::bid::tlv::TlvEncoder,
value: Box<dyn NyashBox>,
&self,
encoder: &mut crate::bid::tlv::TlvEncoder,
value: Box<dyn NyashBox>,
mapping: &crate::bid::ArgTypeMapping
) -> Result<(), RuntimeError> {
// determine_bid_tag()を使って適切なタグを決定
@ -221,7 +241,7 @@ impl NyashInterpreter {
.ok_or_else(|| RuntimeError::InvalidOperation {
message: format!("Unsupported type mapping: {} -> {}", mapping.from, mapping.to),
})?;
// タグに応じてエンコード
match tag {
crate::bid::BidTag::String => {
@ -267,7 +287,7 @@ impl NyashInterpreter {
})
}
}
/// デフォルトエンコード(型情報がない場合のフォールバック)
fn encode_value_default(
&self,
@ -297,26 +317,26 @@ impl NyashInterpreter {
})
}
}
/// TLVレスポンスをNyashBoxに変換
fn decode_tlv_to_nyash_box(&self, response_bytes: &[u8], method_name: &str) -> Result<Box<dyn NyashBox>, RuntimeError> {
use crate::bid::tlv::TlvDecoder;
use crate::bid::types::BidTag;
if response_bytes.is_empty() {
return Ok(Box::new(StringBox::new("".to_string())));
}
let mut decoder = TlvDecoder::new(response_bytes)
.map_err(|e| RuntimeError::InvalidOperation {
message: format!("TLV decoder creation failed: {:?}", e),
})?;
if let Some((tag, payload)) = decoder.decode_next()
.map_err(|e| RuntimeError::InvalidOperation {
message: format!("TLV decoding failed: {:?}", e),
})? {
match tag {
BidTag::String => {
let text = String::from_utf8_lossy(payload).to_string();
@ -359,7 +379,7 @@ impl NyashInterpreter {
/// Handles plugin-backed file I/O operations via FFI interface
/// 🚨 DEPRECATED: This method has hardcoded method names and violates BID-FFI principles
/// Use execute_plugin_method_generic instead for true dynamic method calling
pub(in crate::interpreter) fn execute_plugin_file_method(&mut self, plugin_file_box: &PluginFileBox, method: &str, arguments: &[ASTNode])
pub(in crate::interpreter) fn execute_plugin_file_method(&mut self, plugin_file_box: &PluginFileBox, method: &str, arguments: &[ASTNode])
-> Result<Box<dyn NyashBox>, RuntimeError> {
// 🎯 新しい汎用システムにリダイレクト
self.execute_plugin_method_generic(plugin_file_box, method, arguments)

View File

@ -1,11 +1,11 @@
/*!
* Box Methods Module Organization
*
*
* 旧box_methods.rsを機能別に分割したモジュール群
* 保守性と可読性の向上を目的とした再構成
*
*
* Current implementation:
* - basic_methods: StringBox, IntegerBox, BoolBox, FloatBox
* - basic_methods: StringBox, IntegerBox, BoolBox, FloatBox
* - collection_methods: ArrayBox, MapBox
* - io_methods: FileBox, ResultBox ✅ IMPLEMENTED
* Future modules (planned):
@ -16,13 +16,13 @@
* - special_methods: MethodBox, SoundBox
*/
pub mod basic_methods; // StringBox, IntegerBox, BoolBox, FloatBox
pub mod basic_methods; // StringBox, IntegerBox, BoolBox, FloatBox
pub mod collection_methods; // ArrayBox, MapBox
pub mod io_methods; // FileBox, ResultBox
pub mod data_methods; // BufferBox, JSONBox, RegexBox
pub mod network_methods; // HttpClientBox, StreamBox
pub mod p2p_methods; // IntentBox, P2PBox
pub mod http_methods; // SocketBox, HTTPServerBox, HTTPRequestBox, HTTPResponseBox
pub mod system_methods; // GcConfigBox, DebugConfigBox
pub mod data_methods; // BufferBox, JSONBox, RegexBox
pub mod http_methods; // SocketBox, HTTPServerBox, HTTPRequestBox, HTTPResponseBox
pub mod io_methods; // FileBox, ResultBox
pub mod network_methods; // HttpClientBox, StreamBox
pub mod p2p_methods; // IntentBox, P2PBox
pub mod system_methods; // GcConfigBox, DebugConfigBox
// Re-export methods for easy access

View File

@ -1,6 +1,6 @@
/*!
* Network and Communication Box Methods Module
*
*
* Contains method implementations for network-related Box types:
* - HttpClientBox (execute_http_method) - HTTP client operations
* - StreamBox (execute_stream_method) - Stream processing operations
@ -12,8 +12,12 @@ use crate::boxes::{HttpClientBox, StreamBox};
impl NyashInterpreter {
/// HttpClientBoxのメソッド呼び出しを実行
pub(in crate::interpreter) fn execute_http_method(&mut self, http_box: &HttpClientBox, method: &str, arguments: &[ASTNode])
-> Result<Box<dyn NyashBox>, RuntimeError> {
pub(in crate::interpreter) fn execute_http_method(
&mut self,
http_box: &HttpClientBox,
method: &str,
arguments: &[ASTNode],
) -> Result<Box<dyn NyashBox>, RuntimeError> {
match method {
"get" => {
if arguments.len() != 1 {
@ -66,13 +70,17 @@ impl NyashInterpreter {
}
_ => Err(RuntimeError::InvalidOperation {
message: format!("Unknown method '{}' for HttpClientBox", method),
})
}),
}
}
/// StreamBoxのメソッド呼び出しを実行
pub(in crate::interpreter) fn execute_stream_method(&mut self, stream_box: &StreamBox, method: &str, arguments: &[ASTNode])
-> Result<Box<dyn NyashBox>, RuntimeError> {
pub(in crate::interpreter) fn execute_stream_method(
&mut self,
stream_box: &StreamBox,
method: &str,
arguments: &[ASTNode],
) -> Result<Box<dyn NyashBox>, RuntimeError> {
match method {
"write" => {
if arguments.len() != 1 {
@ -118,7 +126,7 @@ impl NyashInterpreter {
}
_ => Err(RuntimeError::InvalidOperation {
message: format!("Unknown method '{}' for StreamBox", method),
})
}),
}
}
}
}

View File

@ -3,11 +3,11 @@
* Arc<Mutex>パターン対応版
*/
use crate::interpreter::NyashInterpreter;
use crate::interpreter::RuntimeError;
use crate::ast::ASTNode;
use crate::box_trait::{NyashBox, StringBox};
use crate::boxes::{IntentBox, P2PBox};
use crate::interpreter::NyashInterpreter;
use crate::interpreter::RuntimeError;
impl NyashInterpreter {
/// IntentBoxのメソッド実行 (RwLock版)
@ -16,29 +16,23 @@ impl NyashInterpreter {
intent_box: &IntentBox,
method: &str,
_arguments: &[ASTNode],
) -> Result<Box<dyn NyashBox>, RuntimeError> {
) -> Result<Box<dyn NyashBox>, RuntimeError> {
match method {
// メッセージ名取得
"getName" | "name" => {
Ok(intent_box.get_name())
}
"getName" | "name" => Ok(intent_box.get_name()),
// ペイロード取得JSON文字列として
"getPayload" | "payload" => {
Ok(intent_box.get_payload())
}
"getPayload" | "payload" => Ok(intent_box.get_payload()),
// 型情報取得
"getType" | "type" => {
Ok(Box::new(StringBox::new("IntentBox")))
}
"getType" | "type" => Ok(Box::new(StringBox::new("IntentBox"))),
_ => Err(RuntimeError::UndefinedVariable {
name: format!("IntentBox method '{}' not found", method),
})
}),
}
}
// P2PBoxのメソッド実装RwLockベース
pub(in crate::interpreter) fn execute_p2p_box_method(
&mut self,
@ -46,8 +40,14 @@ impl NyashInterpreter {
method: &str,
arguments: &[ASTNode],
) -> Result<Box<dyn NyashBox>, RuntimeError> {
if crate::interpreter::utils::debug_on() || std::env::var("NYASH_DEBUG_P2P").unwrap_or_default() == "1" {
eprintln!("[Interp:P2P] {}(..) called with {} args", method, arguments.len());
if crate::interpreter::utils::debug_on()
|| std::env::var("NYASH_DEBUG_P2P").unwrap_or_default() == "1"
{
eprintln!(
"[Interp:P2P] {}(..) called with {} args",
method,
arguments.len()
);
}
match method {
// ードID取得
@ -59,7 +59,9 @@ impl NyashInterpreter {
// ノード到達可能性確認
"isReachable" => {
if arguments.is_empty() {
return Err(RuntimeError::InvalidOperation { message: "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])?;
Ok(p2p_box.is_reachable(node_id_result))
@ -68,7 +70,9 @@ impl NyashInterpreter {
// send メソッド実装ResultBox返却
"send" => {
if arguments.len() < 2 {
return Err(RuntimeError::InvalidOperation { message: "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 intent_result = self.execute_expression(&arguments[1])?;
@ -78,7 +82,9 @@ impl NyashInterpreter {
// ping: health check using sys.ping/sys.pong
"ping" => {
if arguments.is_empty() {
return Err(RuntimeError::InvalidOperation { message: "ping requires (to [, timeout_ms]) arguments".to_string() });
return Err(RuntimeError::InvalidOperation {
message: "ping requires (to [, timeout_ms]) arguments".to_string(),
});
}
let to_result = self.execute_expression(&arguments[0])?;
if arguments.len() >= 2 {
@ -93,7 +99,9 @@ impl NyashInterpreter {
// on メソッド実装ResultBox返却
"on" => {
if arguments.len() < 2 {
return Err(RuntimeError::InvalidOperation { message: "on requires (intentName, handler) arguments".to_string() });
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])?;
@ -109,7 +117,9 @@ impl NyashInterpreter {
// onOnce / off
"onOnce" | "on_once" => {
if arguments.len() < 2 {
return Err(RuntimeError::InvalidOperation { message: "onOnce requires (intentName, handler) arguments".to_string() });
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])?;
@ -117,13 +127,17 @@ impl NyashInterpreter {
}
"off" => {
if arguments.len() < 1 {
return Err(RuntimeError::InvalidOperation { message: "off requires (intentName) argument".to_string() });
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) }),
_ => Err(RuntimeError::UndefinedVariable {
name: format!("P2PBox method '{}' not found", method),
}),
}
}
}

View File

@ -1,15 +1,15 @@
/*!
* System Methods Module
*
*
* Contains system-level Box type method implementations:
* - GcConfigBox: Garbage collector configuration
* - DebugConfigBox: Debug and observability configuration
*/
use crate::ast::ASTNode;
use crate::box_trait::{NyashBox, BoolBox};
use crate::boxes::gc_config_box::GcConfigBox;
use crate::box_trait::{BoolBox, NyashBox};
use crate::boxes::debug_config_box::DebugConfigBox;
use crate::boxes::gc_config_box::GcConfigBox;
use crate::interpreter::{NyashInterpreter, RuntimeError};
impl NyashInterpreter {
@ -24,59 +24,71 @@ impl NyashInterpreter {
"setFlag" => {
if arguments.len() != 2 {
return Err(RuntimeError::InvalidOperation {
message: format!("GcConfigBox.setFlag expects 2 arguments, got {}", arguments.len()),
message: format!(
"GcConfigBox.setFlag expects 2 arguments, got {}",
arguments.len()
),
});
}
let name = self.execute_expression(&arguments[0])?;
let on = self.execute_expression(&arguments[1])?;
let name_str = name.to_string_box().value;
let on_bool = if let Some(b) = on.as_any().downcast_ref::<BoolBox>() {
b.value
} else {
on.to_string_box().value.to_lowercase() == "true"
};
let mut gc_clone = gc_box.clone();
gc_clone.set_flag(&name_str, on_bool);
Ok(Box::new(gc_clone))
}
"getFlag" => {
if arguments.len() != 1 {
return Err(RuntimeError::InvalidOperation {
message: format!("GcConfigBox.getFlag expects 1 argument, got {}", arguments.len()),
message: format!(
"GcConfigBox.getFlag expects 1 argument, got {}",
arguments.len()
),
});
}
let name = self.execute_expression(&arguments[0])?;
let name_str = name.to_string_box().value;
Ok(gc_box.get_flag(&name_str))
}
"apply" => {
if !arguments.is_empty() {
return Err(RuntimeError::InvalidOperation {
message: format!("GcConfigBox.apply expects 0 arguments, got {}", arguments.len()),
message: format!(
"GcConfigBox.apply expects 0 arguments, got {}",
arguments.len()
),
});
}
Ok(gc_box.apply())
}
"summary" => {
if !arguments.is_empty() {
return Err(RuntimeError::InvalidOperation {
message: format!("GcConfigBox.summary expects 0 arguments, got {}", arguments.len()),
message: format!(
"GcConfigBox.summary expects 0 arguments, got {}",
arguments.len()
),
});
}
Ok(gc_box.summary())
}
_ => Err(RuntimeError::InvalidOperation {
message: format!("GcConfigBox has no method '{}'", method),
}),
}
}
/// Execute DebugConfigBox methods
pub(crate) fn execute_debug_config_method(
&mut self,
@ -88,81 +100,99 @@ impl NyashInterpreter {
"setFlag" => {
if arguments.len() != 2 {
return Err(RuntimeError::InvalidOperation {
message: format!("DebugConfigBox.setFlag expects 2 arguments, got {}", arguments.len()),
message: format!(
"DebugConfigBox.setFlag expects 2 arguments, got {}",
arguments.len()
),
});
}
let name = self.execute_expression(&arguments[0])?;
let on = self.execute_expression(&arguments[1])?;
let name_str = name.to_string_box().value;
let on_bool = if let Some(b) = on.as_any().downcast_ref::<BoolBox>() {
b.value
} else {
on.to_string_box().value.to_lowercase() == "true"
};
let mut debug_clone = debug_box.clone();
debug_clone.set_flag(&name_str, on_bool);
Ok(Box::new(debug_clone))
}
"setPath" => {
if arguments.len() != 2 {
return Err(RuntimeError::InvalidOperation {
message: format!("DebugConfigBox.setPath expects 2 arguments, got {}", arguments.len()),
message: format!(
"DebugConfigBox.setPath expects 2 arguments, got {}",
arguments.len()
),
});
}
let name = self.execute_expression(&arguments[0])?;
let path = self.execute_expression(&arguments[1])?;
let name_str = name.to_string_box().value;
let path_str = path.to_string_box().value;
let mut debug_clone = debug_box.clone();
debug_clone.set_path(&name_str, &path_str);
Ok(Box::new(debug_clone))
}
"getFlag" => {
if arguments.len() != 1 {
return Err(RuntimeError::InvalidOperation {
message: format!("DebugConfigBox.getFlag expects 1 argument, got {}", arguments.len()),
message: format!(
"DebugConfigBox.getFlag expects 1 argument, got {}",
arguments.len()
),
});
}
let name = self.execute_expression(&arguments[0])?;
let name_str = name.to_string_box().value;
Ok(debug_box.get_flag(&name_str))
}
"getPath" => {
if arguments.len() != 1 {
return Err(RuntimeError::InvalidOperation {
message: format!("DebugConfigBox.getPath expects 1 argument, got {}", arguments.len()),
message: format!(
"DebugConfigBox.getPath expects 1 argument, got {}",
arguments.len()
),
});
}
let name = self.execute_expression(&arguments[0])?;
let name_str = name.to_string_box().value;
Ok(debug_box.get_path(&name_str))
}
"apply" => {
if !arguments.is_empty() {
return Err(RuntimeError::InvalidOperation {
message: format!("DebugConfigBox.apply expects 0 arguments, got {}", arguments.len()),
message: format!(
"DebugConfigBox.apply expects 0 arguments, got {}",
arguments.len()
),
});
}
Ok(debug_box.apply())
}
"summary" => {
if !arguments.is_empty() {
return Err(RuntimeError::InvalidOperation {
message: format!("DebugConfigBox.summary expects 0 arguments, got {}", arguments.len()),
message: format!(
"DebugConfigBox.summary expects 0 arguments, got {}",
arguments.len()
),
});
}
Ok(debug_box.summary())
}
_ => Err(RuntimeError::InvalidOperation {
message: format!("DebugConfigBox has no method '{}'", method),
}),