🎉 Conservative PHI Box理論による完全SSA構築 **Phase 7-B: Conservative PHI実装** - 片方branchのみ定義変数に対応(emit_void使用) - 全変数にPHI生成(Conservative Box理論) - Stage-1 resolver全テスト緑化(3/3 PASS) **Phase 25.1f: ControlForm観測レイヤー** - LoopShape/IfShape/ControlForm構造定義 - Loop/If統一インターフェース実装 - debug_dump/debug_validate機能追加 - NYASH_CONTROL_FORM_TRACE環境変数対応 **主な変更**: - src/mir/builder/phi.rs: Conservative PHI実装 - src/mir/control_form.rs: ControlForm構造(NEW) - src/mir/loop_builder.rs: LoopForm v2デフォルト化 **テスト結果**: ✅ mir_stage1_using_resolver_min_fragment_verifies ✅ mir_stage1_using_resolver_full_collect_entries_verifies ✅ mir_parserbox_parse_program2_harness_parses_minimal_source 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: ChatGPT <chatgpt@openai.com>
61 lines
2.2 KiB
Rust
61 lines
2.2 KiB
Rust
/*!
|
|
* Global Unified Box Registry
|
|
*
|
|
* Manages the global instance of UnifiedBoxRegistry
|
|
* Integrates all Box creation sources (builtin, user-defined, plugin)
|
|
*/
|
|
|
|
use crate::box_factory::builtin::BuiltinBoxFactory;
|
|
#[cfg(feature = "plugins")]
|
|
use crate::box_factory::plugin::PluginBoxFactory;
|
|
use crate::box_factory::UnifiedBoxRegistry;
|
|
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(|| {
|
|
// Phase 15.5: Use environment variable policy (StrictPluginFirst for "Everything is Plugin")
|
|
let mut registry = UnifiedBoxRegistry::with_env_policy();
|
|
// Default: enable builtins unless building with feature "plugins-only"
|
|
#[cfg(not(feature = "plugins-only"))]
|
|
{
|
|
registry.register(std::sync::Arc::new(BuiltinBoxFactory::new()));
|
|
}
|
|
|
|
// Register plugin Box factory (primary)
|
|
#[cfg(feature = "plugins")]
|
|
{
|
|
registry.register(Arc::new(PluginBoxFactory::new()));
|
|
}
|
|
|
|
// TODO: User-defined Box factory will be registered by interpreter
|
|
|
|
// Phase 15.5: FactoryPolicy determines actual priority order
|
|
// StrictPluginFirst: plugins > user > builtin (SOLVES StringBox/IntegerBox issue)
|
|
// BuiltinFirst: builtin > user > plugin (legacy default)
|
|
|
|
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();
|
|
|
|
// Phase 25.1b: delegate to policy-aware register() so that
|
|
// type_cache is rebuilt and user-defined Box types (HakoCli など)
|
|
// are correctly advertised to the registry. Priorityは
|
|
// FactoryPolicy + factory_type に従って決まる。
|
|
registry_lock.register(factory);
|
|
}
|