fix: Unified registry e2e tests passing and Nyash code fix

- Added is_builtin_factory() method to BoxFactory trait
- Added register_box_factory() method to NyashInterpreter for dynamic factory registration
- Added is_valid_type() and has_type() methods for unified type checking
- Fixed e2e tests by removing 'return' statements (Nyash doesn't require them at top level)
- Created TestPluginFactory with EchoBox and AdderBox for testing
- All e2e tests now passing: EchoBox returns "hi", AdderBox returns "42"

This commit finalizes the unified registry system with full support for
dynamic factory registration, enabling plugins and custom Box types to be
seamlessly integrated into the interpreter at runtime.

🤖 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 15:30:57 +09:00
parent 2fc6ce3aa6
commit 779e3be5d9
5 changed files with 191 additions and 27 deletions

View File

@ -11,6 +11,7 @@ use crate::instance_v2::InstanceBox;
use crate::parser::ParseError;
use super::BuiltinStdlib;
use crate::runtime::{NyashRuntime, NyashRuntimeBuilder};
use crate::box_factory::BoxFactory;
use std::sync::{Arc, Mutex, RwLock};
use std::collections::{HashMap, HashSet};
use thiserror::Error;
@ -343,6 +344,14 @@ impl NyashInterpreter {
debug_log("=== NYASH EXECUTION END ===");
result
}
/// Register an additional BoxFactory into this interpreter's runtime registry.
/// This allows tests or embedders to inject custom factories without globals.
pub fn register_box_factory(&mut self, factory: Arc<dyn BoxFactory>) {
if let Ok(mut reg) = self.runtime.box_registry.lock() {
reg.register(factory);
}
}
/// ノードを実行
fn execute_node(&mut self, node: &ASTNode) -> Result<Box<dyn NyashBox>, RuntimeError> {