feat: Phase 10.5 Python統合プラグインとAOTビルド対応

- Pythonプラグイン(PyRuntimeBox/PyObjectBox)を追加
  - eval, import, getattr, call, callKw, strメソッド実装
  - math.sqrtデモ等のサンプルコード追加
- AOTビルドサポート追加
  - libnyrtランタイムライブラリ
  - build_aot.shビルドスクリプト
- .gitignore改善
  - JSONLとDOTファイル除外
  - プラグインのビルド成果物除外
- 不要ファイル削除
  - nekocode-temp, zenn_articles
  - 一時的なログファイル類

Phase 10.1の新計画に基づいて、プラグインBox統一化を推進
This commit is contained in:
Moe Charm
2025-08-29 10:22:44 +09:00
parent 12adde9477
commit d24149d0a1
24 changed files with 1057 additions and 867 deletions

View File

@ -1171,10 +1171,22 @@ impl VM {
if method == "toString" {
return Ok(Box::new(StringBox::new(format!("{}(id={})", plugin_box.box_type, plugin_box.inner.instance_id))));
}
// Other plugin methods should be called via BoxCall instruction
// This path shouldn't normally be reached for plugin methods
eprintln!("Warning: Plugin method '{}' called via call_box_method - should use BoxCall", method);
// Name-based fallback: delegate to unified PluginHost to invoke by (box_type, method)
// This preserves existing semantics but actually performs the plugin call instead of no-op.
let host = crate::runtime::get_global_plugin_host();
if let Ok(h) = host.read() {
// Prepare args as NyashBox list; they are already Box<dyn NyashBox>
let nyash_args: Vec<Box<dyn NyashBox>> = _args.into_iter().map(|b| b).collect();
match h.invoke_instance_method(&plugin_box.box_type, method, plugin_box.inner.instance_id, &nyash_args) {
Ok(Some(ret)) => return Ok(ret),
Ok(None) => return Ok(Box::new(VoidBox::new())),
Err(e) => {
eprintln!("[VM] Plugin invoke error: {}.{} -> {}", plugin_box.box_type, method, e.message());
return Ok(Box::new(VoidBox::new()));
}
}
}
return Ok(Box::new(VoidBox::new()));
}

View File

@ -420,7 +420,7 @@ impl IRBuilder for CraneliftBuilder {
// Clear context for next compilation and finalize definitions
self.module.clear_context(&mut self.ctx);
self.module.finalize_definitions();
let _ = self.module.finalize_definitions();
// Get finalized code pointer and wrap into a safe closure
let code = self.module.get_finalized_function(func_id);

View File

@ -466,6 +466,34 @@ impl PluginBoxV2 {
crate::runtime::plugin_ffi_common::encode::i32(&mut buf, v);
continue;
}
// Bool
if let Some(b) = a.as_any().downcast_ref::<crate::box_trait::BoolBox>() {
eprintln!("[PluginLoaderV2] arg[{}]: Bool({}) -> Bool(tag=1)", idx, b.value);
crate::runtime::plugin_ffi_common::encode::bool(&mut buf, b.value);
continue;
}
// Float (F64)
if let Some(f) = a.as_any().downcast_ref::<crate::boxes::math_box::FloatBox>() {
eprintln!("[PluginLoaderV2] arg[{}]: Float({}) -> F64(tag=5)", idx, f.value);
crate::runtime::plugin_ffi_common::encode::f64(&mut buf, f.value);
continue;
}
// Bytes from Array<uint8>
if let Some(arr) = a.as_any().downcast_ref::<crate::boxes::array::ArrayBox>() {
let items = arr.items.read().unwrap();
let mut tmp = Vec::with_capacity(items.len());
let mut ok = true;
for item in items.iter() {
if let Some(intb) = item.as_any().downcast_ref::<IntegerBox>() {
if intb.value >= 0 && intb.value <= 255 { tmp.push(intb.value as u8); } else { ok = false; break; }
} else { ok = false; break; }
}
if ok {
eprintln!("[PluginLoaderV2] arg[{}]: Array<uint8>[{}] -> Bytes(tag=7)", idx, tmp.len());
crate::runtime::plugin_ffi_common::encode::bytes(&mut buf, &tmp);
continue;
}
}
// String: tag=6
if let Some(s) = a.as_any().downcast_ref::<StringBox>() {
eprintln!("[PluginLoaderV2] arg[{}]: String(len={}) -> String(tag=6)", idx, s.value.len());