🚀 feat: Phase 9.78b Step 1&2完了 - ChatGPT5による実装

ChatGPT5が実装したPhase 9.78b Step 1&2の統合

## 🎯 実装内容
1. Phase 9.78b Step 1: BoxDeclarationをcore::modelへ移動
   - src/core/mod.rs, model.rs 新規作成
   - BoxDeclarationを純粋データモデルとして分離

2. Phase 9.78b Step 2: NyashRuntime骨組み作成
   - src/runtime/nyash_runtime.rs 追加
   - 統一Box管理の基盤

3. ビルドエラー修正
   - Arc重複インポート修正
   - as_str() → as_ref() 変更
   - parent_name.to_string() 型変換
   - インポートパス調整

## 📊 ビルド結果
-  フルビルド成功 (47.34秒)
-  ユニットテスト: 145/145成功
-  統合テスト: 16/16成功
-  WASMビルド成功 (1.9MB)
-  MIRテスト: 1失敗 (ref_new命令)

## 🚀 次のステップ
- Phase 9.78b Step 3: BoxFactory dyn化
- Codexの設計に基づく段階的実装継続
This commit is contained in:
Moe Charm
2025-08-20 18:57:10 +09:00
parent 86b9f7719b
commit 41361a2f50
15 changed files with 571 additions and 95 deletions

View File

@ -6,6 +6,7 @@ pub mod plugin_config;
pub mod box_registry;
pub mod plugin_loader_v2;
pub mod unified_registry;
pub mod nyash_runtime;
// pub mod plugin_box; // legacy - 古いPluginBox
// pub mod plugin_loader; // legacy - Host VTable使用
@ -16,6 +17,7 @@ pub use plugin_config::PluginConfig;
pub use box_registry::{BoxFactoryRegistry, BoxProvider, get_global_registry};
pub use plugin_loader_v2::{PluginLoaderV2, get_global_loader_v2, init_global_loader_v2};
pub use unified_registry::{get_global_unified_registry, init_global_unified_registry, register_user_defined_factory};
pub use nyash_runtime::{NyashRuntime, NyashRuntimeBuilder};
// pub use plugin_box::PluginBox; // legacy
// Use unified plugin loader (formerly v2)
// pub use plugin_loader::{PluginLoaderV2 as PluginLoader, get_global_loader_v2 as get_global_loader}; // legacy
// pub use plugin_loader::{PluginLoaderV2 as PluginLoader, get_global_loader_v2 as get_global_loader}; // legacy

View File

@ -0,0 +1,78 @@
//! Minimal NyashRuntime skeleton shared by interpreter and VM
//!
//! Focused on dependency inversion: core models + runtime services,
//! while execution strategies live in interpreter/VM layers.
use std::collections::HashMap;
use std::sync::{Arc, Mutex, RwLock};
use crate::core::model::BoxDeclaration;
use crate::box_factory::{UnifiedBoxRegistry, BoxFactory};
use crate::box_factory::builtin::BuiltinBoxFactory;
#[cfg(feature = "plugins")]
use crate::box_factory::plugin::PluginBoxFactory;
/// Core runtime container for executing Nyash programs
pub struct NyashRuntime {
/// Unified registry that can create any Box type
pub box_registry: Arc<Mutex<UnifiedBoxRegistry>>,
/// User-defined box declarations collected from source
pub box_declarations: Arc<RwLock<HashMap<String, BoxDeclaration>>>,
}
impl NyashRuntime {
/// Create a new runtime with defaults
pub fn new() -> Self {
Self {
box_registry: create_default_registry(),
box_declarations: Arc::new(RwLock::new(HashMap::new())),
}
}
}
/// Builder for NyashRuntime allowing DI without globals (future-proof)
pub struct NyashRuntimeBuilder {
box_registry: Option<Arc<Mutex<UnifiedBoxRegistry>>>,
box_declarations: Option<Arc<RwLock<HashMap<String, BoxDeclaration>>>>,
}
impl NyashRuntimeBuilder {
pub fn new() -> Self {
Self { box_registry: None, box_declarations: None }
}
/// Inject a BoxFactory implementation directly into a private registry
pub fn with_factory(mut self, factory: Arc<dyn BoxFactory>) -> Self {
let registry = self.box_registry.take().unwrap_or_else(|| create_default_registry());
if let Ok(mut reg) = registry.lock() {
reg.register(factory);
}
self.box_registry = Some(registry);
self
}
pub fn with_box_declarations(
mut self,
decls: Arc<RwLock<HashMap<String, BoxDeclaration>>>,
) -> Self {
self.box_declarations = Some(decls);
self
}
pub fn build(self) -> NyashRuntime {
NyashRuntime {
box_registry: self.box_registry.unwrap_or_else(|| create_default_registry()),
box_declarations: self.box_declarations.unwrap_or_else(|| Arc::new(RwLock::new(HashMap::new()))),
}
}
}
fn create_default_registry() -> Arc<Mutex<UnifiedBoxRegistry>> {
let mut registry = UnifiedBoxRegistry::new();
registry.register(Arc::new(BuiltinBoxFactory::new()));
#[cfg(feature = "plugins")]
{
registry.register(Arc::new(PluginBoxFactory::new()));
}
Arc::new(Mutex::new(registry))
}