🔧 refactor: すべてのBoxをArc<Mutex>パターンで統一
CopilotのBox実装を私たちのArc<Mutex>パターンで統一:
- BufferBox: Arc<Mutex<Vec<u8>>>で内部可変性を実現
- FileBox: Arc<Mutex<File>>でファイルハンドル管理
- JSONBox: Arc<Mutex<Value>>でJSON値を保持
- HttpClientBox: Arc<Mutex<Client>>でHTTPクライアント管理
- StreamBox: Arc<Mutex>でストリームバッファと位置を管理
- RegexBox: Arc<Regex>で軽量ラッパー実装
各Boxに実用的なメソッドも追加:
- BufferBox: write, read, readAll, clear, length, append, slice
- FileBox: read, write, exists, delete, copy
- JSONBox: parse, stringify, get, set, has, keys
- HttpClientBox: get, post, put, delete, request
- StreamBox: write, read, position, length, reset
- RegexBox: test, find, findAll, replace, split
interpreterに新Box用のメソッド実行を追加:
- data_methods.rs: BufferBox, JSONBox, RegexBox
- network_methods.rs: HttpClientBox, StreamBox
これでコードベース全体が一貫性のあるArc<Mutex>パターンで統一されました!
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-10 13:03:42 +09:00
|
|
|
/*!
|
|
|
|
|
* 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::*;
|
2025-08-16 17:39:04 +09:00
|
|
|
use crate::box_trait::NyashBox;
|
🔧 refactor: すべてのBoxをArc<Mutex>パターンで統一
CopilotのBox実装を私たちのArc<Mutex>パターンで統一:
- BufferBox: Arc<Mutex<Vec<u8>>>で内部可変性を実現
- FileBox: Arc<Mutex<File>>でファイルハンドル管理
- JSONBox: Arc<Mutex<Value>>でJSON値を保持
- HttpClientBox: Arc<Mutex<Client>>でHTTPクライアント管理
- StreamBox: Arc<Mutex>でストリームバッファと位置を管理
- RegexBox: Arc<Regex>で軽量ラッパー実装
各Boxに実用的なメソッドも追加:
- BufferBox: write, read, readAll, clear, length, append, slice
- FileBox: read, write, exists, delete, copy
- JSONBox: parse, stringify, get, set, has, keys
- HttpClientBox: get, post, put, delete, request
- StreamBox: write, read, position, length, reset
- RegexBox: test, find, findAll, replace, split
interpreterに新Box用のメソッド実行を追加:
- data_methods.rs: BufferBox, JSONBox, RegexBox
- network_methods.rs: HttpClientBox, StreamBox
これでコードベース全体が一貫性のあるArc<Mutex>パターンで統一されました!
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-10 13:03:42 +09:00
|
|
|
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),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|