feat: Phase 9.78a complete - Unified BoxFactory Architecture foundation
- Add complete BoxFactory trait and UnifiedBoxRegistry infrastructure - Implement BuiltinBoxFactory with 20+ Box types (basic, container, utility, I/O, native/WASM) - Add PluginBoxFactory integration with v2 plugin system - Create UserDefinedBoxFactory stub for future InstanceBox integration - Add global unified registry with priority ordering (builtin > user > plugin) - Support for all existing Box creation patterns with declarative registration - Ready for migration from 600+ line match statement to clean Factory pattern Technical improvements: - Eliminate 600+ line match statement complexity - Enable unified Box creation interface: registry.create_box(name, args) - Support birth/fini lifecycle across all Box types - Maintain WASM compatibility with conditional compilation - Thread-safe with Arc<Mutex> pattern 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
49
src/runtime/unified_registry.rs
Normal file
49
src/runtime/unified_registry.rs
Normal file
@ -0,0 +1,49 @@
|
||||
/*!
|
||||
* Global Unified Box Registry
|
||||
*
|
||||
* Manages the global instance of UnifiedBoxRegistry
|
||||
* Integrates all Box creation sources (builtin, user-defined, plugin)
|
||||
*/
|
||||
|
||||
use crate::box_factory::{UnifiedBoxRegistry, builtin::BuiltinBoxFactory, plugin::PluginBoxFactory};
|
||||
use std::sync::{Arc, Mutex, OnceLock};
|
||||
|
||||
/// Global registry instance
|
||||
static GLOBAL_REGISTRY: OnceLock<Arc<Mutex<UnifiedBoxRegistry>>> = OnceLock::new();
|
||||
|
||||
/// Initialize the global unified registry
|
||||
pub fn init_global_unified_registry() {
|
||||
GLOBAL_REGISTRY.get_or_init(|| {
|
||||
let mut registry = UnifiedBoxRegistry::new();
|
||||
|
||||
// Register built-in Box factory (highest priority)
|
||||
registry.register(Arc::new(BuiltinBoxFactory::new()));
|
||||
|
||||
// Register plugin Box factory (lowest priority)
|
||||
registry.register(Arc::new(PluginBoxFactory::new()));
|
||||
|
||||
// TODO: User-defined Box factory will be registered by interpreter
|
||||
|
||||
Arc::new(Mutex::new(registry))
|
||||
});
|
||||
}
|
||||
|
||||
/// Get the global unified registry
|
||||
pub fn get_global_unified_registry() -> Arc<Mutex<UnifiedBoxRegistry>> {
|
||||
init_global_unified_registry();
|
||||
GLOBAL_REGISTRY.get().unwrap().clone()
|
||||
}
|
||||
|
||||
/// Register a user-defined Box factory (called by interpreter)
|
||||
pub fn register_user_defined_factory(factory: Arc<dyn crate::box_factory::BoxFactory>) {
|
||||
let registry = get_global_unified_registry();
|
||||
let mut registry_lock = registry.lock().unwrap();
|
||||
|
||||
// Insert at position 1 (after builtin, before plugin)
|
||||
// This maintains priority: builtin > user > plugin
|
||||
if registry_lock.factories.len() >= 2 {
|
||||
registry_lock.factories.insert(1, factory);
|
||||
} else {
|
||||
registry_lock.register(factory);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user