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:
16
local_tests/test_unified_registry.nyash
Normal file
16
local_tests/test_unified_registry.nyash
Normal 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!")
|
||||
@ -18,6 +18,41 @@ impl NyashInterpreter {
|
||||
-> Result<Box<dyn NyashBox>, RuntimeError> {
|
||||
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型のチェック
|
||||
eprintln!("🔍 Starting built-in Box type checks...");
|
||||
match class {
|
||||
|
||||
@ -13,9 +13,12 @@ use nyash_rust::{
|
||||
parser::NyashParser,
|
||||
interpreter::NyashInterpreter,
|
||||
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")]
|
||||
use nyash_rust::backend::{llvm_compile_and_execute};
|
||||
use std::{fs, process};
|
||||
@ -36,6 +39,9 @@ impl NyashRunner {
|
||||
|
||||
/// Run Nyash based on the configuration
|
||||
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)
|
||||
self.init_bid_plugins();
|
||||
// Benchmark mode - can run without a file
|
||||
@ -95,11 +101,27 @@ impl NyashRunner {
|
||||
println!("🚀 Nyash MIR Compiler - Processing file: {} 🚀", filename);
|
||||
self.execute_mir_mode(filename);
|
||||
} else if self.config.compile_wasm {
|
||||
println!("🌐 Nyash WASM Compiler - Processing file: {} 🌐", filename);
|
||||
self.execute_wasm_mode(filename);
|
||||
#[cfg(feature = "wasm-backend")]
|
||||
{
|
||||
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 {
|
||||
println!("🚀 Nyash AOT Compiler - Processing file: {} 🚀", filename);
|
||||
self.execute_aot_mode(filename);
|
||||
#[cfg(feature = "wasm-backend")]
|
||||
{
|
||||
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" {
|
||||
println!("🚀 Nyash VM Backend - Executing file: {} 🚀", filename);
|
||||
self.execute_vm_mode(filename);
|
||||
@ -316,6 +338,7 @@ impl NyashRunner {
|
||||
}
|
||||
|
||||
/// Execute WASM compilation mode
|
||||
#[cfg(feature = "wasm-backend")]
|
||||
fn execute_wasm_mode(&self, filename: &str) {
|
||||
// Read the file
|
||||
let code = match fs::read_to_string(filename) {
|
||||
@ -382,6 +405,7 @@ impl NyashRunner {
|
||||
}
|
||||
|
||||
/// Execute AOT compilation mode
|
||||
#[cfg(feature = "wasm-backend")]
|
||||
fn execute_aot_mode(&self, filename: &str) {
|
||||
// Read the file
|
||||
let code = match fs::read_to_string(filename) {
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
* 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};
|
||||
|
||||
/// 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)
|
||||
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 mut registry_lock = registry.lock().unwrap();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user