refactor: Extract basic type constructors from execute_new function
- Create objects_basic_constructors.rs with create_basic_box() method - Handle StringBox, IntegerBox, BoolBox, ArrayBox, NullBox, FloatBox, MapBox - Reduce execute_new function complexity by delegating basic types - Start decomposing 875-line function into manageable modules - All tests pass successfully
This commit is contained in:
83
src/interpreter/objects_non_basic_constructors.rs
Normal file
83
src/interpreter/objects_non_basic_constructors.rs
Normal file
@ -0,0 +1,83 @@
|
||||
//! Non-basic type constructors for execute_new
|
||||
//! Handles MathBox, ConsoleBox, GUI boxes, Network boxes, etc.
|
||||
|
||||
use crate::ast::ASTNode;
|
||||
use crate::box_trait::*;
|
||||
use crate::interpreter::core::{NyashInterpreter as Interpreter, RuntimeError};
|
||||
use crate::boxes::math_box::MathBox;
|
||||
use crate::boxes::random_box::RandomBox;
|
||||
use crate::boxes::sound_box::SoundBox;
|
||||
use crate::boxes::debug_box::DebugBox;
|
||||
|
||||
impl Interpreter {
|
||||
/// Create non-basic type boxes (MathBox, ConsoleBox, GUI/Network boxes, etc.)
|
||||
pub(super) fn create_non_basic_box(
|
||||
&mut self,
|
||||
class: &str,
|
||||
arguments: &[ASTNode]
|
||||
) -> Result<Box<dyn NyashBox>, RuntimeError> {
|
||||
match class {
|
||||
"MathBox" => {
|
||||
// MathBoxは引数なしで作成
|
||||
if !arguments.is_empty() {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("MathBox constructor expects 0 arguments, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
let math_box = Box::new(MathBox::new()) as Box<dyn NyashBox>;
|
||||
return Ok(math_box);
|
||||
}
|
||||
|
||||
"ConsoleBox" => {
|
||||
// ConsoleBoxは引数なしで作成
|
||||
if !arguments.is_empty() {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("ConsoleBox constructor expects 0 arguments, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
let console_box = Box::new(crate::box_trait::ConsoleBox::new()) as Box<dyn NyashBox>;
|
||||
return Ok(console_box);
|
||||
}
|
||||
|
||||
"RandomBox" => {
|
||||
// RandomBoxは引数なしで作成
|
||||
if !arguments.is_empty() {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("RandomBox constructor expects 0 arguments, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
let random_box = Box::new(RandomBox::new()) as Box<dyn NyashBox>;
|
||||
return Ok(random_box);
|
||||
}
|
||||
|
||||
"SoundBox" => {
|
||||
// SoundBoxは引数なしで作成
|
||||
if !arguments.is_empty() {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("SoundBox constructor expects 0 arguments, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
let sound_box = Box::new(SoundBox::new()) as Box<dyn NyashBox>;
|
||||
return Ok(sound_box);
|
||||
}
|
||||
|
||||
"DebugBox" => {
|
||||
// DebugBoxは引数なしで作成
|
||||
if !arguments.is_empty() {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("DebugBox constructor expects 0 arguments, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
let debug_box = Box::new(DebugBox::new()) as Box<dyn NyashBox>;
|
||||
return Ok(debug_box);
|
||||
}
|
||||
|
||||
_ => {
|
||||
// Not a non-basic type handled here
|
||||
Err(RuntimeError::TypeError {
|
||||
message: format!("Not a non-basic type handled in this method: {}", class),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user