🧹 refactor: box_methods.rs大掃除完全成功 - 8モジュールに機能分離

🏗️ アーキテクチャ大幅改善:
• 1822行巨大ファイル → 8つの論理的モジュールに完全分割
• 機能別責任分離でメンテナンス性向上
• ゼロ破壊的変更 - 既存機能すべて正常動作

📂 新モジュール構造:
• basic_methods.rs - StringBox/IntegerBox/BoolBox/FloatBox
• collection_methods.rs - ArrayBox/MapBox
• io_methods.rs - FileBox/ResultBox
• system_methods.rs - TimeBox/DateTimeBox/TimerBox/DebugBox
• math_methods.rs - MathBox/RandomBox
• async_methods.rs - FutureBox/ChannelBox
• web_methods.rs - WebDisplayBox/WebConsoleBox/WebCanvasBox(WASM)
• special_methods.rs - MethodBox/SoundBox

 コード品質向上:
• 可読性 - 機能別分離で理解容易
• 保守性 - 変更影響の局所化
• 拡張性 - 新機能追加が簡単
• テスト性 - 単体テスト作成容易

🎯 プロフェッショナルレベルのコードベース完成\!
Everything is Box哲学の美しい実装構造達成

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Moe Charm
2025-08-09 16:12:14 +09:00
parent 5d4bae2402
commit 2c5fc374da
12 changed files with 2465 additions and 1714 deletions

View File

@ -0,0 +1,107 @@
/*!
* 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
* - ResultBox (execute_result_method) - Error handling and result operations
*/
use super::super::*;
use crate::box_trait::{FileBox, ResultBox, StringBox, NyashBox};
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> {
match method {
"read" => {
if !arguments.is_empty() {
return Err(RuntimeError::InvalidOperation {
message: format!("read() expects 0 arguments, got {}", arguments.len()),
});
}
Ok(file_box.read())
}
"write" => {
if arguments.len() != 1 {
return Err(RuntimeError::InvalidOperation {
message: format!("write() expects 1 argument, got {}", arguments.len()),
});
}
let content = self.execute_expression(&arguments[0])?;
Ok(file_box.write(content))
}
"exists" => {
if !arguments.is_empty() {
return Err(RuntimeError::InvalidOperation {
message: format!("exists() expects 0 arguments, got {}", arguments.len()),
});
}
Ok(file_box.exists())
}
"delete" => {
if !arguments.is_empty() {
return Err(RuntimeError::InvalidOperation {
message: format!("delete() expects 0 arguments, got {}", arguments.len()),
});
}
Ok(file_box.delete())
}
"copy" => {
if arguments.len() != 1 {
return Err(RuntimeError::InvalidOperation {
message: format!("copy() expects 1 argument, got {}", arguments.len()),
});
}
let dest_value = self.execute_expression(&arguments[0])?;
if let Some(dest_str) = dest_value.as_any().downcast_ref::<StringBox>() {
Ok(file_box.copy(&dest_str.value))
} else {
Err(RuntimeError::TypeError {
message: "copy() requires string destination path".to_string(),
})
}
}
_ => 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> {
match method {
"isOk" => {
if !arguments.is_empty() {
return Err(RuntimeError::InvalidOperation {
message: format!("isOk() expects 0 arguments, got {}", arguments.len()),
});
}
Ok(result_box.is_ok())
}
"getValue" => {
if !arguments.is_empty() {
return Err(RuntimeError::InvalidOperation {
message: format!("getValue() expects 0 arguments, got {}", arguments.len()),
});
}
Ok(result_box.get_value())
}
"getError" => {
if !arguments.is_empty() {
return Err(RuntimeError::InvalidOperation {
message: format!("getError() expects 0 arguments, got {}", arguments.len()),
});
}
Ok(result_box.get_error())
}
_ => Err(RuntimeError::InvalidOperation {
message: format!("Unknown method '{}' for ResultBox", method),
})
}
}
}