✅ CRITICAL FIX: Add missing StringBox, IntegerBox, BoolBox constructors
Co-authored-by: moe-charm <217100418+moe-charm@users.noreply.github.com>
This commit is contained in:
@ -17,6 +17,64 @@ impl NyashInterpreter {
|
||||
-> Result<Box<dyn NyashBox>, RuntimeError> {
|
||||
// 組み込みBox型のチェック
|
||||
match class {
|
||||
// Basic Box constructors (CRITICAL - these were missing!)
|
||||
"StringBox" => {
|
||||
// StringBoxは引数1個(文字列値)で作成
|
||||
if arguments.len() != 1 {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("StringBox constructor expects 1 argument, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
let value = self.execute_expression(&arguments[0])?;
|
||||
let string_value = value.to_string_box().value;
|
||||
let string_box = Box::new(StringBox::new(string_value)) as Box<dyn NyashBox>;
|
||||
return Ok(string_box);
|
||||
}
|
||||
"IntegerBox" => {
|
||||
// IntegerBoxは引数1個(整数値)で作成
|
||||
if arguments.len() != 1 {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("IntegerBox constructor expects 1 argument, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
let value = self.execute_expression(&arguments[0])?;
|
||||
if let Some(int_box) = value.as_any().downcast_ref::<IntegerBox>() {
|
||||
let integer_box = Box::new(IntegerBox::new(int_box.value)) as Box<dyn NyashBox>;
|
||||
return Ok(integer_box);
|
||||
} else {
|
||||
// Try to parse from string or other types
|
||||
let int_value = value.to_string_box().value.parse::<i64>()
|
||||
.map_err(|_| RuntimeError::TypeError {
|
||||
message: format!("Cannot convert '{}' to integer", value.to_string_box().value),
|
||||
})?;
|
||||
let integer_box = Box::new(IntegerBox::new(int_value)) as Box<dyn NyashBox>;
|
||||
return Ok(integer_box);
|
||||
}
|
||||
}
|
||||
"BoolBox" => {
|
||||
// BoolBoxは引数1個(真偽値)で作成
|
||||
if arguments.len() != 1 {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("BoolBox constructor expects 1 argument, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
let value = self.execute_expression(&arguments[0])?;
|
||||
if let Some(bool_box) = value.as_any().downcast_ref::<BoolBox>() {
|
||||
let bool_box_new = Box::new(BoolBox::new(bool_box.value)) as Box<dyn NyashBox>;
|
||||
return Ok(bool_box_new);
|
||||
} else {
|
||||
// Try to convert from string or other types
|
||||
let bool_value = match value.to_string_box().value.to_lowercase().as_str() {
|
||||
"true" => true,
|
||||
"false" => false,
|
||||
_ => return Err(RuntimeError::TypeError {
|
||||
message: format!("Cannot convert '{}' to boolean", value.to_string_box().value),
|
||||
}),
|
||||
};
|
||||
let bool_box_new = Box::new(BoolBox::new(bool_value)) as Box<dyn NyashBox>;
|
||||
return Ok(bool_box_new);
|
||||
}
|
||||
}
|
||||
"ArrayBox" => {
|
||||
// ArrayBoxは引数なしで作成
|
||||
if !arguments.is_empty() {
|
||||
|
||||
Reference in New Issue
Block a user