refactor: 大規模ファイル分割とプラグインリファクタリング
## 🎯 プラグイン整理 - ✅ **nyash-json-plugin**: プロバイダー抽象化、NodeRep統一 - ✅ **nyash-string-plugin**: TLVヘルパー整理 - ✅ **nyash-net-plugin**: HTTPヘルパー分離、ソケット管理改善 - ✅ **nyash-counter-plugin/fixture-plugin**: 基本構造整理 ## 📂 mir_interpreter分割 - ✅ **mir_interpreter.rs → mir_interpreter/ディレクトリ** - mod.rs: メイン構造体定義 - execution.rs: 実行エンジン - memory.rs: メモリ管理 - instructions/: 命令別実装 ## 🔧 その他の改善 - テストファイル群の最適化 - LLVMコンパイラのメイン関数整理 - 不要なインポート削除 1000行超のファイルを適切なモジュール構造に分割完了! 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -61,4 +61,3 @@ pub(crate) const M_CONN_SEND: u32 = 1; // bytes/string -> void
|
||||
pub(crate) const M_CONN_RECV: u32 = 2; // -> bytes
|
||||
pub(crate) const M_CONN_CLOSE: u32 = 3; // -> void
|
||||
pub(crate) const M_CONN_RECV_TIMEOUT: u32 = 4; // ms -> bytes (empty if timeout)
|
||||
|
||||
|
||||
@ -149,11 +149,17 @@ pub fn parse_client_response_into(resp_id: u32, conn_id: u32) {
|
||||
let mut tmp = [0u8; 2048];
|
||||
loop {
|
||||
match s.read(&mut tmp) {
|
||||
Ok(0) => { return; }
|
||||
Ok(0) => {
|
||||
return;
|
||||
}
|
||||
Ok(n) => {
|
||||
buf.extend_from_slice(&tmp[..n]);
|
||||
if find_header_end(&buf).is_some() { break; }
|
||||
if buf.len() > 256 * 1024 { break; }
|
||||
if find_header_end(&buf).is_some() {
|
||||
break;
|
||||
}
|
||||
if buf.len() > 256 * 1024 {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Err(_) => return,
|
||||
}
|
||||
@ -191,7 +197,9 @@ pub fn parse_client_response_into(resp_id: u32, conn_id: u32) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if should_remove { map.remove(&conn_id); }
|
||||
if should_remove {
|
||||
map.remove(&conn_id);
|
||||
}
|
||||
}
|
||||
if let Some(rp) = state::RESPONSES.lock().unwrap().get_mut(&resp_id) {
|
||||
rp.status = status;
|
||||
@ -201,4 +209,3 @@ pub fn parse_client_response_into(resp_id: u32, conn_id: u32) {
|
||||
rp.client_conn_id = None;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
//! Provides ServerBox/RequestBox/ResponseBox/ClientBox and socket variants.
|
||||
//! Pure in-process HTTP over localhost for E2E of BoxRef args/returns.
|
||||
|
||||
use crate::state::{ClientState, RequestState, ResponseState, ServerState, SockConnState};
|
||||
use once_cell::sync::Lazy;
|
||||
use std::collections::{HashMap, VecDeque};
|
||||
use std::io::Write as IoWrite;
|
||||
@ -11,7 +12,6 @@ use std::sync::{
|
||||
Arc, Mutex,
|
||||
};
|
||||
use std::time::Duration;
|
||||
use crate::state::{ClientState, RequestState, ResponseState, ServerState, SockConnState};
|
||||
|
||||
// ===== Simple logger (enabled when NYASH_NET_LOG=1) =====
|
||||
static LOG_ON: Lazy<bool> = Lazy::new(|| std::env::var("NYASH_NET_LOG").unwrap_or_default() == "1");
|
||||
@ -234,7 +234,9 @@ extern "C" fn sockserver_invoke_id(
|
||||
result: *mut u8,
|
||||
result_len: *mut usize,
|
||||
) -> i32 {
|
||||
unsafe { sockets::sock_server_invoke(method_id, instance_id, args, args_len, result, result_len) }
|
||||
unsafe {
|
||||
sockets::sock_server_invoke(method_id, instance_id, args, args_len, result, result_len)
|
||||
}
|
||||
}
|
||||
#[no_mangle]
|
||||
pub static nyash_typebox_SockServerBox: NyashTypeBoxFfi = NyashTypeBoxFfi {
|
||||
@ -268,7 +270,9 @@ extern "C" fn sockclient_invoke_id(
|
||||
result: *mut u8,
|
||||
result_len: *mut usize,
|
||||
) -> i32 {
|
||||
unsafe { sockets::sock_client_invoke(method_id, instance_id, args, args_len, result, result_len) }
|
||||
unsafe {
|
||||
sockets::sock_client_invoke(method_id, instance_id, args, args_len, result, result_len)
|
||||
}
|
||||
}
|
||||
#[no_mangle]
|
||||
pub static nyash_typebox_SockClientBox: NyashTypeBoxFfi = NyashTypeBoxFfi {
|
||||
@ -1012,7 +1016,8 @@ unsafe fn client_invoke(
|
||||
let body_len = body.len();
|
||||
// Create client response handle
|
||||
let resp_id = state::next_response_id();
|
||||
let (_h, _p, req_bytes) = http_helpers::build_http_request("POST", &url, Some(&body), resp_id);
|
||||
let (_h, _p, req_bytes) =
|
||||
http_helpers::build_http_request("POST", &url, Some(&body), resp_id);
|
||||
let mut tcp_ok = false;
|
||||
if let Ok(mut stream) = TcpStream::connect(format!("{}:{}", host, port)) {
|
||||
let _ = stream.write_all(&req_bytes);
|
||||
@ -1086,9 +1091,9 @@ unsafe fn client_invoke(
|
||||
|
||||
// ===== Helpers =====
|
||||
use ffi::slice;
|
||||
mod tlv;
|
||||
mod http_helpers;
|
||||
mod sockets;
|
||||
mod tlv;
|
||||
|
||||
// ===== HTTP helpers =====
|
||||
// moved
|
||||
|
||||
@ -1,14 +1,19 @@
|
||||
use std::collections::VecDeque;
|
||||
use std::io::{Read, Write as IoWrite};
|
||||
use std::net::{TcpListener, TcpStream};
|
||||
use std::sync::{atomic::{AtomicBool, Ordering}, Arc, Mutex};
|
||||
use std::sync::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
Arc, Mutex,
|
||||
};
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::consts::*;
|
||||
use crate::state::{self, SockConnState, SockServerState};
|
||||
|
||||
// Utilities provided by parent module
|
||||
fn logf(s: String) { super::net_log(&s); }
|
||||
fn logf(s: String) {
|
||||
super::net_log(&s);
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn sock_server_invoke(
|
||||
m: u32,
|
||||
@ -51,7 +56,9 @@ pub(crate) unsafe fn sock_server_invoke(
|
||||
let conn_id = state::next_sock_conn_id();
|
||||
state::SOCK_CONNS.lock().unwrap().insert(
|
||||
conn_id,
|
||||
SockConnState { stream: Mutex::new(stream) },
|
||||
SockConnState {
|
||||
stream: Mutex::new(stream),
|
||||
},
|
||||
);
|
||||
logf(format!("sock:accept conn_id={}", conn_id));
|
||||
pending.lock().unwrap().push_back(conn_id);
|
||||
@ -161,7 +168,9 @@ pub(crate) unsafe fn sock_client_invoke(
|
||||
let conn_id = state::next_sock_conn_id();
|
||||
state::SOCK_CONNS.lock().unwrap().insert(
|
||||
conn_id,
|
||||
SockConnState { stream: Mutex::new(stream) },
|
||||
SockConnState {
|
||||
stream: Mutex::new(stream),
|
||||
},
|
||||
);
|
||||
logf(format!("sock:connect ok conn_id={}", conn_id));
|
||||
crate::tlv::write_tlv_handle(T_SOCK_CONN, conn_id, res, res_len)
|
||||
@ -190,7 +199,8 @@ pub(crate) unsafe fn sock_conn_invoke(
|
||||
crate::tlv::write_u32(0, res, res_len)
|
||||
}
|
||||
M_CONN_SEND => {
|
||||
let bytes = crate::tlv::tlv_parse_bytes(super::ffi::slice(args, args_len)).unwrap_or_default();
|
||||
let bytes =
|
||||
crate::tlv::tlv_parse_bytes(super::ffi::slice(args, args_len)).unwrap_or_default();
|
||||
if let Some(conn) = state::SOCK_CONNS.lock().unwrap().get(&id) {
|
||||
if let Ok(mut s) = conn.stream.lock() {
|
||||
let _ = s.write_all(&bytes);
|
||||
@ -229,11 +239,17 @@ pub(crate) unsafe fn sock_conn_invoke(
|
||||
match resv {
|
||||
Ok(n) => {
|
||||
buf.truncate(n);
|
||||
logf(format!("sock:recvTimeout id={} n={} ms={}", id, n, timeout_ms));
|
||||
logf(format!(
|
||||
"sock:recvTimeout id={} n={} ms={}",
|
||||
id, n, timeout_ms
|
||||
));
|
||||
return crate::tlv::write_tlv_bytes(&buf, res, res_len);
|
||||
}
|
||||
Err(e) => {
|
||||
logf(format!("sock:recvTimeout error id={} ms={} err={:?}", id, timeout_ms, e));
|
||||
logf(format!(
|
||||
"sock:recvTimeout error id={} ms={} err={:?}",
|
||||
id, timeout_ms, e
|
||||
));
|
||||
return E_ERR;
|
||||
}
|
||||
}
|
||||
@ -249,4 +265,3 @@ pub(crate) unsafe fn sock_conn_invoke(
|
||||
_ => E_INV_METHOD,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user