📚 Phase 12: Nyashスクリプトプラグインシステム設計と埋め込みVM構想
## 主な成果 - Nyashスクリプトでプラグイン作成可能という革命的発見 - C ABI制約の分析と埋め込みVMによる解決策 - MIR/VM/JIT層での箱引数サポートの詳細分析 ## ドキュメント作成 - Phase 12基本構想(README.md) - Gemini/Codex先生の技術分析 - C ABIとの整合性問題と解決策 - 埋め込みVM実装ロードマップ - 箱引数サポートの技術詳細 ## 重要な洞察 - 制約は「リンク時にC ABI必要」のみ - 埋め込みVMでMIRバイトコード実行により解決可能 - Nyashスクリプト→C ABIプラグイン変換が実現可能 Everything is Box → Everything is Plugin → Everything is Possible!
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
//! Boxファクトリレジストリ - Box生成の中央管理
|
||||
//!
|
||||
//! ビルトインBoxとプラグインBoxを統一的に管理し、
|
||||
//! 透過的な置き換えを実現する
|
||||
//! プラグインBoxを中心にBox生成を管理する(Plugin-First)。
|
||||
//! 旧ビルトイン経路は互換目的のAPIとして最小限に保持(テスト用途)。
|
||||
|
||||
use crate::box_trait::NyashBox;
|
||||
use crate::runtime::plugin_config::PluginConfig;
|
||||
@ -10,14 +10,14 @@ use std::sync::{Arc, RwLock};
|
||||
|
||||
/// Box生成方法を表す列挙型
|
||||
pub enum BoxProvider {
|
||||
/// ビルトイン実装(Rust関数)
|
||||
/// 互換用ビルトイン実装(Rust関数、現在は原則未使用)
|
||||
Builtin(BoxConstructor),
|
||||
|
||||
/// プラグイン実装(プラグイン名を保持)
|
||||
Plugin(String),
|
||||
}
|
||||
|
||||
/// ビルトインBoxのコンストラクタ関数型
|
||||
/// 互換用ビルトインBoxのコンストラクタ関数型
|
||||
pub type BoxConstructor = fn(&[Box<dyn NyashBox>]) -> Result<Box<dyn NyashBox>, String>;
|
||||
|
||||
/// Boxファクトリレジストリ
|
||||
@ -34,7 +34,7 @@ impl BoxFactoryRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
/// ビルトインBoxを登録
|
||||
/// 互換用ビルトインBoxを登録(通常は使用しない)
|
||||
pub fn register_builtin(&self, name: &str, constructor: BoxConstructor) {
|
||||
let mut providers = self.providers.write().unwrap();
|
||||
providers.insert(name.to_string(), BoxProvider::Builtin(constructor));
|
||||
|
||||
@ -34,6 +34,8 @@ mod enabled {
|
||||
invoke_fn: unsafe extern "C" fn(u32, u32, u32, *const u8, usize, *mut u8, *mut usize) -> i32,
|
||||
}
|
||||
|
||||
// (moved: public constructor wrapper is declared after the enabled module)
|
||||
|
||||
/// v2 Plugin Box wrapper - temporary implementation
|
||||
#[derive(Debug)]
|
||||
pub struct PluginHandleInner {
|
||||
@ -103,6 +105,11 @@ mod enabled {
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper to construct a PluginBoxV2 from raw ids and invoke pointer safely
|
||||
pub fn make_plugin_box_v2_inner(box_type: String, type_id: u32, instance_id: u32, invoke_fn: unsafe extern "C" fn(u32,u32,u32,*const u8,usize,*mut u8,*mut usize) -> i32) -> PluginBoxV2 {
|
||||
PluginBoxV2 { box_type, inner: std::sync::Arc::new(PluginHandleInner { type_id, invoke_fn, instance_id, fini_method_id: None, finalized: std::sync::atomic::AtomicBool::new(false) }) }
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PluginBoxV2 {
|
||||
pub box_type: String,
|
||||
@ -1207,6 +1214,10 @@ impl PluginLoaderV2 {
|
||||
}
|
||||
}
|
||||
|
||||
// Public constructor wrapper for PluginBoxV2 (enabled build)
|
||||
#[cfg(all(feature = "plugins", not(target_arch = "wasm32")))]
|
||||
pub use self::enabled::make_plugin_box_v2_inner as make_plugin_box_v2;
|
||||
|
||||
#[cfg(any(not(feature = "plugins"), target_arch = "wasm32"))]
|
||||
mod stub {
|
||||
use crate::bid::{BidResult, BidError};
|
||||
|
||||
Reference in New Issue
Block a user