🎉 merge: Arc<Mutex>革命をmainブランチに統合完了!
## 🔥 統合された革命的成果 - **全9種類のBox統一**: Arc<Mutex>パターンで内部可変性実現 - **&selfメソッド**: すべてのBoxで統一されたメソッドシグネチャ - **スレッドセーフ**: マルチスレッド環境で安全動作保証 - **メモリ安全**: Rustの所有権システムと完全統合 ## ✅ 統合されたBox実装 - ArrayBox: Arc<Mutex<Vec<dyn NyashBox>>>で配列操作 - BufferBox: Arc<Mutex<Vec<u8>>>でバイナリデータ処理 - RegexBox: Arc<Regex>で正規表現処理 - JSONBox: Arc<Mutex<Value>>でJSON解析・操作 - StreamBox: Arc<Mutex<Vec<u8>>>でストリーム処理 - HttpClientBox: HTTP通信(stub実装) - ResultBox/FutureBox: エラー・非同期処理(確認済み) ## 🏗️ アーキテクチャ革新 - **"Everything is Box"哲学の完全実現** - **GitHub Copilotとの協働成果をmainに統合** - **統一されたArc<Mutex>パターン** - **内部可変性と外部安全性の両立** 🎊 Arc<Mutex>革命 - mainブランチ統合完了記念日: 2025年8月10日 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
204
src/interpreter/methods/data_methods.rs
Normal file
204
src/interpreter/methods/data_methods.rs
Normal file
@ -0,0 +1,204 @@
|
||||
/*!
|
||||
* 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
|
||||
* - RegexBox (execute_regex_method) - Regular expression operations
|
||||
*/
|
||||
|
||||
use super::super::*;
|
||||
use crate::box_trait::{NyashBox, StringBox, IntegerBox};
|
||||
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> {
|
||||
match method {
|
||||
"write" => {
|
||||
if arguments.len() != 1 {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("write() expects 1 argument, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
let data = self.execute_expression(&arguments[0])?;
|
||||
Ok(buffer_box.write(data))
|
||||
}
|
||||
"readAll" => {
|
||||
if !arguments.is_empty() {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("readAll() expects 0 arguments, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
Ok(buffer_box.readAll())
|
||||
}
|
||||
"read" => {
|
||||
if arguments.len() != 1 {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("read() expects 1 argument, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
let count = self.execute_expression(&arguments[0])?;
|
||||
Ok(buffer_box.read(count))
|
||||
}
|
||||
"clear" => {
|
||||
if !arguments.is_empty() {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("clear() expects 0 arguments, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
Ok(buffer_box.clear())
|
||||
}
|
||||
"length" => {
|
||||
if !arguments.is_empty() {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("length() expects 0 arguments, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
Ok(buffer_box.length())
|
||||
}
|
||||
"append" => {
|
||||
if arguments.len() != 1 {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("append() expects 1 argument, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
let other = self.execute_expression(&arguments[0])?;
|
||||
Ok(buffer_box.append(other))
|
||||
}
|
||||
"slice" => {
|
||||
if arguments.len() != 2 {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("slice() expects 2 arguments, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
let start = self.execute_expression(&arguments[0])?;
|
||||
let end = self.execute_expression(&arguments[1])?;
|
||||
Ok(buffer_box.slice(start, end))
|
||||
}
|
||||
_ => 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> {
|
||||
match method {
|
||||
"parse" => {
|
||||
if arguments.len() != 1 {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("parse() expects 1 argument, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
let data = self.execute_expression(&arguments[0])?;
|
||||
Ok(JSONBox::parse(data))
|
||||
}
|
||||
"stringify" => {
|
||||
if !arguments.is_empty() {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("stringify() expects 0 arguments, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
Ok(json_box.stringify())
|
||||
}
|
||||
"get" => {
|
||||
if arguments.len() != 1 {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("get() expects 1 argument, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
let key = self.execute_expression(&arguments[0])?;
|
||||
Ok(json_box.get(key))
|
||||
}
|
||||
"set" => {
|
||||
if arguments.len() != 2 {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("set() expects 2 arguments, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
let key = self.execute_expression(&arguments[0])?;
|
||||
let value = self.execute_expression(&arguments[1])?;
|
||||
Ok(json_box.set(key, value))
|
||||
}
|
||||
"has" => {
|
||||
if arguments.len() != 1 {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("has() expects 1 argument, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
let key = self.execute_expression(&arguments[0])?;
|
||||
Ok(json_box.has(key))
|
||||
}
|
||||
"keys" => {
|
||||
if !arguments.is_empty() {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("keys() expects 0 arguments, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
Ok(json_box.keys())
|
||||
}
|
||||
_ => 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> {
|
||||
match method {
|
||||
"test" => {
|
||||
if arguments.len() != 1 {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("test() expects 1 argument, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
let text = self.execute_expression(&arguments[0])?;
|
||||
Ok(regex_box.test(text))
|
||||
}
|
||||
"find" => {
|
||||
if arguments.len() != 1 {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("find() expects 1 argument, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
let text = self.execute_expression(&arguments[0])?;
|
||||
Ok(regex_box.find(text))
|
||||
}
|
||||
"findAll" => {
|
||||
if arguments.len() != 1 {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("findAll() expects 1 argument, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
let text = self.execute_expression(&arguments[0])?;
|
||||
Ok(regex_box.find_all(text))
|
||||
}
|
||||
"replace" => {
|
||||
if arguments.len() != 2 {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("replace() expects 2 arguments, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
let text = self.execute_expression(&arguments[0])?;
|
||||
let replacement = self.execute_expression(&arguments[1])?;
|
||||
Ok(regex_box.replace(text, replacement))
|
||||
}
|
||||
"split" => {
|
||||
if arguments.len() != 1 {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("split() expects 1 argument, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
let text = self.execute_expression(&arguments[0])?;
|
||||
Ok(regex_box.split(text))
|
||||
}
|
||||
_ => Err(RuntimeError::InvalidOperation {
|
||||
message: format!("Unknown method '{}' for RegexBox", method),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -19,8 +19,12 @@
|
||||
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
|
||||
|
||||
// Re-export methods for easy access
|
||||
pub use basic_methods::*;
|
||||
pub use collection_methods::*;
|
||||
pub use io_methods::*;
|
||||
pub use io_methods::*;
|
||||
pub use data_methods::*;
|
||||
pub use network_methods::*;
|
||||
124
src/interpreter/methods/network_methods.rs
Normal file
124
src/interpreter/methods/network_methods.rs
Normal file
@ -0,0 +1,124 @@
|
||||
/*!
|
||||
* 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
|
||||
*/
|
||||
|
||||
use super::super::*;
|
||||
use crate::box_trait::{NyashBox, StringBox};
|
||||
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> {
|
||||
match method {
|
||||
"get" => {
|
||||
if arguments.len() != 1 {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("get() expects 1 argument, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
let url = self.execute_expression(&arguments[0])?;
|
||||
Ok(http_box.http_get(url))
|
||||
}
|
||||
"post" => {
|
||||
if arguments.len() != 2 {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("post() expects 2 arguments, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
let url = self.execute_expression(&arguments[0])?;
|
||||
let body = self.execute_expression(&arguments[1])?;
|
||||
Ok(http_box.post(url, body))
|
||||
}
|
||||
"put" => {
|
||||
if arguments.len() != 2 {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("put() expects 2 arguments, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
let url = self.execute_expression(&arguments[0])?;
|
||||
let body = self.execute_expression(&arguments[1])?;
|
||||
Ok(http_box.put(url, body))
|
||||
}
|
||||
"delete" => {
|
||||
if arguments.len() != 1 {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("delete() expects 1 argument, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
let url = self.execute_expression(&arguments[0])?;
|
||||
Ok(http_box.delete(url))
|
||||
}
|
||||
"request" => {
|
||||
if arguments.len() != 3 {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("request() expects 3 arguments, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
let method_arg = self.execute_expression(&arguments[0])?;
|
||||
let url = self.execute_expression(&arguments[1])?;
|
||||
let options = self.execute_expression(&arguments[2])?;
|
||||
Ok(http_box.request(method_arg, url, options))
|
||||
}
|
||||
_ => 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> {
|
||||
match method {
|
||||
"write" => {
|
||||
if arguments.len() != 1 {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("write() expects 1 argument, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
let data = self.execute_expression(&arguments[0])?;
|
||||
Ok(stream_box.stream_write(data))
|
||||
}
|
||||
"read" => {
|
||||
if arguments.len() != 1 {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("read() expects 1 argument, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
let count = self.execute_expression(&arguments[0])?;
|
||||
Ok(stream_box.stream_read(count))
|
||||
}
|
||||
"position" => {
|
||||
if !arguments.is_empty() {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("position() expects 0 arguments, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
Ok(stream_box.get_position())
|
||||
}
|
||||
"length" => {
|
||||
if !arguments.is_empty() {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("length() expects 0 arguments, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
Ok(stream_box.get_length())
|
||||
}
|
||||
"reset" => {
|
||||
if !arguments.is_empty() {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("reset() expects 0 arguments, got {}", arguments.len()),
|
||||
});
|
||||
}
|
||||
Ok(stream_box.stream_reset())
|
||||
}
|
||||
_ => Err(RuntimeError::InvalidOperation {
|
||||
message: format!("Unknown method '{}' for StreamBox", method),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user