🚀 feat: VM ExternCall実装 - ChatGPT5による plugin loader v2 統合

Phase 9.78b の続き:
- VM::execute_instruction に ExternCall 完全実装
- plugin loader v2 経由でenv.console.log等を処理
- MirBuilder::build_method_call に最適化追加(new Class().method() → 直接Call)
- extern_call メソッドを plugin_loader_v2 に追加

ChatGPT5によるVMとプラグインシステムの統合作業
This commit is contained in:
Moe Charm
2025-08-20 19:10:30 +09:00
parent 41361a2f50
commit 41832b2c88
3 changed files with 104 additions and 41 deletions

View File

@ -193,7 +193,7 @@ impl PluginBoxV2 {
}
/// Load all plugins from config
pub fn load_all_plugins(&self) -> BidResult<()> {
pub fn load_all_plugins(&self) -> BidResult<()> {
let config = self.config.as_ref()
.ok_or(BidError::PluginError)?;
@ -205,6 +205,32 @@ impl PluginBoxV2 {
Ok(())
}
/// Perform an external host call (env.* namespace) or return an error if unsupported
/// Returns Some(Box) for a value result, or None for void-like calls
pub fn extern_call(
&self,
iface_name: &str,
method_name: &str,
args: &[Box<dyn NyashBox>],
) -> BidResult<Option<Box<dyn NyashBox>>> {
match (iface_name, method_name) {
("env.console", "log") => {
for a in args {
println!("{}", a.to_string_box().value);
}
Ok(None)
}
("env.canvas", _) => {
eprintln!("[env.canvas] {} invoked (stub)", method_name);
Ok(None)
}
_ => {
// Future: route to plugin-defined extern interfaces via config
Err(BidError::InvalidMethod)
}
}
}
/// Load single plugin
pub fn load_plugin(&self, lib_name: &str, lib_def: &LibraryDefinition) -> BidResult<()> {
@ -413,6 +439,15 @@ mod stub {
pub fn create_box(&self, _t: &str, _a: &[Box<dyn NyashBox>]) -> BidResult<Box<dyn NyashBox>> {
Err(BidError::PluginError)
}
pub fn extern_call(
&self,
_iface_name: &str,
_method_name: &str,
_args: &[Box<dyn NyashBox>],
) -> BidResult<Option<Box<dyn NyashBox>>> {
Err(BidError::PluginError)
}
}
static GLOBAL_LOADER_V2: Lazy<Arc<RwLock<PluginLoaderV2>>> =