WIP: Phase 9.78b - Unified registry integration (import issues pending)

Progress made:
- Add unified registry call to objects.rs execute_new() method
- Initialize unified registry in runner.rs on startup
- Create global registry management in runtime/unified_registry.rs
- Add test case for unified registry validation
- Implement fallback to legacy match statement for compatibility

Current issue:
- Module import errors in runtime/unified_registry.rs preventing build
- Need to resolve box_factory module path visibility from runtime context

Next steps:
- Fix import paths for box_factory modules
- Test unified registry functionality
- Remove legacy match statement after validation

Technical details:
- execute_new() now tries unified registry first, falls back to legacy
- Registry initialized with BuiltinBoxFactory and PluginBoxFactory
- Maintains backward compatibility during transition

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Moe Charm
2025-08-19 16:48:45 +09:00
parent 18d26ed130
commit fbb94aea17
4 changed files with 82 additions and 7 deletions

View File

@ -0,0 +1,16 @@
# Phase 9.78b: Unified BoxFactory Registry test
# Test basic Box creation through unified registry
local str = new StringBox("Hello UnifiedBox!")
print(str.to_string_box().value)
local num = new IntegerBox(42)
print(num.to_string_box().value)
local flag = new BoolBox(true)
print(flag.to_string_box().value)
local arr = new ArrayBox()
print("ArrayBox created: " + arr.type_name())
print("🎉 All unified registry tests passed!")

View File

@ -18,6 +18,41 @@ impl NyashInterpreter {
-> Result<Box<dyn NyashBox>, RuntimeError> { -> Result<Box<dyn NyashBox>, RuntimeError> {
eprintln!("🔍 execute_new called for class: {}, with {} arguments", class, arguments.len()); eprintln!("🔍 execute_new called for class: {}, with {} arguments", class, arguments.len());
// 🏭 Phase 9.78b: Try unified registry first
eprintln!("🔍 Trying unified registry for class: {}", class);
// Convert ASTNode arguments to Box<dyn NyashBox>
let nyash_args: Result<Vec<Box<dyn NyashBox>>, RuntimeError> = arguments.iter()
.map(|arg| self.execute_expression(arg))
.collect();
match nyash_args {
Ok(args) => {
// Try unified registry
use crate::runtime::get_global_unified_registry;
let registry = get_global_unified_registry();
let registry_lock = registry.lock().unwrap();
match registry_lock.create_box(class, &args) {
Ok(box_instance) => {
eprintln!("🏭 Unified registry created: {}", class);
return Ok(box_instance);
},
Err(e) => {
eprintln!("🔍 Unified registry failed for {}: {}", class, e);
// Fall through to legacy match statement
}
}
},
Err(e) => {
eprintln!("🔍 Argument evaluation failed: {}", e);
// Fall through to legacy match statement which will re-evaluate args
}
}
// 🚧 Legacy implementation (will be removed in Phase 9.78e)
eprintln!("🔍 Falling back to legacy match statement for: {}", class);
// 組み込みBox型のチェック // 組み込みBox型のチェック
eprintln!("🔍 Starting built-in Box type checks..."); eprintln!("🔍 Starting built-in Box type checks...");
match class { match class {

View File

@ -13,9 +13,12 @@ use nyash_rust::{
parser::NyashParser, parser::NyashParser,
interpreter::NyashInterpreter, interpreter::NyashInterpreter,
mir::{MirCompiler, MirPrinter, MirInstruction}, mir::{MirCompiler, MirPrinter, MirInstruction},
backend::{VM, wasm::WasmBackend, aot::AotBackend}, backend::VM,
}; };
#[cfg(feature = "wasm-backend")]
use nyash_rust::backend::{wasm::WasmBackend, aot::AotBackend};
#[cfg(feature = "llvm")] #[cfg(feature = "llvm")]
use nyash_rust::backend::{llvm_compile_and_execute}; use nyash_rust::backend::{llvm_compile_and_execute};
use std::{fs, process}; use std::{fs, process};
@ -36,6 +39,9 @@ impl NyashRunner {
/// Run Nyash based on the configuration /// Run Nyash based on the configuration
pub fn run(&self) { pub fn run(&self) {
// 🏭 Phase 9.78b: Initialize unified registry
nyash_rust::runtime::init_global_unified_registry();
// Try to initialize BID plugins from nyash.toml (best-effort) // Try to initialize BID plugins from nyash.toml (best-effort)
self.init_bid_plugins(); self.init_bid_plugins();
// Benchmark mode - can run without a file // Benchmark mode - can run without a file
@ -95,11 +101,27 @@ impl NyashRunner {
println!("🚀 Nyash MIR Compiler - Processing file: {} 🚀", filename); println!("🚀 Nyash MIR Compiler - Processing file: {} 🚀", filename);
self.execute_mir_mode(filename); self.execute_mir_mode(filename);
} else if self.config.compile_wasm { } else if self.config.compile_wasm {
println!("🌐 Nyash WASM Compiler - Processing file: {} 🌐", filename); #[cfg(feature = "wasm-backend")]
self.execute_wasm_mode(filename); {
println!("🌐 Nyash WASM Compiler - Processing file: {} 🌐", filename);
self.execute_wasm_mode(filename);
}
#[cfg(not(feature = "wasm-backend"))]
{
eprintln!("❌ WASM backend not available. Please rebuild with: cargo build --features wasm-backend");
process::exit(1);
}
} else if self.config.compile_native { } else if self.config.compile_native {
println!("🚀 Nyash AOT Compiler - Processing file: {} 🚀", filename); #[cfg(feature = "wasm-backend")]
self.execute_aot_mode(filename); {
println!("🚀 Nyash AOT Compiler - Processing file: {} 🚀", filename);
self.execute_aot_mode(filename);
}
#[cfg(not(feature = "wasm-backend"))]
{
eprintln!("❌ AOT backend not available. Please rebuild with: cargo build --features wasm-backend");
process::exit(1);
}
} else if self.config.backend == "vm" { } else if self.config.backend == "vm" {
println!("🚀 Nyash VM Backend - Executing file: {} 🚀", filename); println!("🚀 Nyash VM Backend - Executing file: {} 🚀", filename);
self.execute_vm_mode(filename); self.execute_vm_mode(filename);
@ -316,6 +338,7 @@ impl NyashRunner {
} }
/// Execute WASM compilation mode /// Execute WASM compilation mode
#[cfg(feature = "wasm-backend")]
fn execute_wasm_mode(&self, filename: &str) { fn execute_wasm_mode(&self, filename: &str) {
// Read the file // Read the file
let code = match fs::read_to_string(filename) { let code = match fs::read_to_string(filename) {
@ -382,6 +405,7 @@ impl NyashRunner {
} }
/// Execute AOT compilation mode /// Execute AOT compilation mode
#[cfg(feature = "wasm-backend")]
fn execute_aot_mode(&self, filename: &str) { fn execute_aot_mode(&self, filename: &str) {
// Read the file // Read the file
let code = match fs::read_to_string(filename) { let code = match fs::read_to_string(filename) {

View File

@ -5,7 +5,7 @@
* Integrates all Box creation sources (builtin, user-defined, plugin) * Integrates all Box creation sources (builtin, user-defined, plugin)
*/ */
use crate::box_factory::{UnifiedBoxRegistry, builtin::BuiltinBoxFactory, plugin::PluginBoxFactory}; use super::super::box_factory::{UnifiedBoxRegistry, builtin::BuiltinBoxFactory, plugin::PluginBoxFactory};
use std::sync::{Arc, Mutex, OnceLock}; use std::sync::{Arc, Mutex, OnceLock};
/// Global registry instance /// Global registry instance
@ -35,7 +35,7 @@ pub fn get_global_unified_registry() -> Arc<Mutex<UnifiedBoxRegistry>> {
} }
/// Register a user-defined Box factory (called by interpreter) /// Register a user-defined Box factory (called by interpreter)
pub fn register_user_defined_factory(factory: Arc<dyn crate::box_factory::BoxFactory>) { pub fn register_user_defined_factory(factory: Arc<dyn super::super::box_factory::BoxFactory>) {
let registry = get_global_unified_registry(); let registry = get_global_unified_registry();
let mut registry_lock = registry.lock().unwrap(); let mut registry_lock = registry.lock().unwrap();