feat: Unified registry and major code cleanup by ChatGPT5

- Unified Box Registry: Replaced 600+ line match statement with clean factory pattern
- Code cleanup: Removed unused imports, variables, and dead code
- Import fixes: Fixed RangeBox, NullBox, MapBox imports
- Transport Debug: Added Debug trait implementation for Transport interface
- WASM build: Successfully tested with wasm_playground preset ready for integration
- Performance: Build time stable, WASM package generated successfully (1.89MB)

This commit represents a major architectural improvement with the unified registry
system now fully operational, reducing code duplication and improving maintainability.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Moe Charm
2025-08-21 14:28:24 +09:00
parent bf0229c24a
commit 2fc6ce3aa6
14 changed files with 743 additions and 222 deletions

View File

@ -256,6 +256,33 @@ impl NyashInterpreter {
runtime,
}
}
/// グループ構成を指定して新しいインタープリターを作成
pub fn new_with_groups(groups: crate::box_factory::builtin::BuiltinGroups) -> Self {
let shared = SharedState::new();
use crate::box_factory::user_defined::UserDefinedBoxFactory;
let udf = Arc::new(UserDefinedBoxFactory::new(shared.clone()));
let runtime = NyashRuntimeBuilder::new()
.with_builtin_groups(groups)
.with_factory(udf)
.build();
let mut shared = shared; // 可変化
shared.box_declarations = runtime.box_declarations.clone();
Self {
shared,
local_vars: HashMap::new(),
outbox_vars: HashMap::new(),
control_flow: ControlFlow::None,
current_constructor_context: None,
evaluation_stack: Vec::new(),
invalidated_ids: Arc::new(Mutex::new(HashSet::new())),
stdlib: None,
runtime,
}
}
/// 共有状態から新しいインタープリターを作成(非同期実行用)
pub fn with_shared(shared: SharedState) -> Self {
@ -280,6 +307,31 @@ impl NyashInterpreter {
runtime,
}
}
/// 共有状態+グループ構成を指定して新しいインタープリターを作成(非同期実行用)
pub fn with_shared_and_groups(shared: SharedState, groups: crate::box_factory::builtin::BuiltinGroups) -> Self {
use crate::box_factory::user_defined::UserDefinedBoxFactory;
let udf = Arc::new(UserDefinedBoxFactory::new(shared.clone()));
let runtime = NyashRuntimeBuilder::new()
.with_builtin_groups(groups)
.with_factory(udf)
.build();
let mut shared = shared; // 可変化
shared.box_declarations = runtime.box_declarations.clone();
Self {
shared,
local_vars: HashMap::new(),
outbox_vars: HashMap::new(),
control_flow: ControlFlow::None,
current_constructor_context: None,
evaluation_stack: Vec::new(),
invalidated_ids: Arc::new(Mutex::new(HashSet::new())),
stdlib: None,
runtime,
}
}
/// ASTを実行
pub fn execute(&mut self, ast: ASTNode) -> Result<Box<dyn NyashBox>, RuntimeError> {