## 📚 Phase 12.7 ドキュメント整理 - ChatGPT5作成のANCP Token仕様書v1を整備 - フォルダ構造を機能別に再編成: - ancp-specs/ : ANCP圧縮技法仕様 - grammar-specs/ : 文法改革仕様 - implementation/ : 実装計画 - ai-feedback/ : AIアドバイザーフィードバック - 各フォルダにREADME.md作成で導線改善 ## 🔧 ChatGPT5によるVMリファクタリング - vm_instructions.rs (1927行) をモジュール分割: - boxcall.rs : Box呼び出し処理 - call.rs : 関数呼び出し処理 - extern_call.rs : 外部関数処理 - function_new.rs : FunctionBox生成 - newbox.rs : Box生成処理 - plugin_invoke.rs : プラグイン呼び出し - VM実行をファイル分割で整理: - vm_state.rs : 状態管理 - vm_exec.rs : 実行エンジン - vm_control_flow.rs : 制御フロー - vm_gc.rs : GC処理 - plugin_loader_v2もモジュール化 ## ✨ 新機能実装 - FunctionBox呼び出しのVM/MIR統一進捗 - ラムダ式のFunctionBox変換テスト追加 - 関数値の直接呼び出し基盤整備 次ステップ: ANCPプロトタイプ実装開始(Week 1) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
42 lines
2.1 KiB
Rust
42 lines
2.1 KiB
Rust
use crate::box_trait::NyashBox;
|
|
use crate::mir::ValueId;
|
|
use crate::backend::vm::ControlFlow;
|
|
use crate::backend::{VM, VMError, VMValue};
|
|
|
|
impl VM {
|
|
/// Execute Call instruction (supports function name or FunctionBox value)
|
|
pub(crate) fn execute_call(&mut self, dst: Option<ValueId>, func: ValueId, args: &[ValueId]) -> Result<ControlFlow, VMError> {
|
|
// Evaluate function value
|
|
let fval = self.get_value(func)?;
|
|
match fval {
|
|
VMValue::String(func_name) => {
|
|
// Legacy: call function by name
|
|
let arg_values: Vec<VMValue> = args.iter().map(|arg| self.get_value(*arg)).collect::<Result<Vec<_>, _>>()?;
|
|
let result = self.call_function_by_name(&func_name, arg_values)?;
|
|
if let Some(dst_id) = dst { self.set_value(dst_id, result); }
|
|
Ok(ControlFlow::Continue)
|
|
}
|
|
VMValue::BoxRef(arc_box) => {
|
|
// FunctionBox call path
|
|
if let Some(fun) = arc_box.as_any().downcast_ref::<crate::boxes::function_box::FunctionBox>() {
|
|
// Convert args to NyashBox for interpreter helper
|
|
let nyash_args: Vec<Box<dyn NyashBox>> = args.iter()
|
|
.map(|a| self.get_value(*a).map(|v| v.to_nyash_box()))
|
|
.collect::<Result<Vec<_>, VMError>>()?;
|
|
// Execute via interpreter helper
|
|
match crate::interpreter::run_function_box(fun, nyash_args) {
|
|
Ok(out) => {
|
|
if let Some(dst_id) = dst { self.set_value(dst_id, VMValue::from_nyash_box(out)); }
|
|
Ok(ControlFlow::Continue)
|
|
}
|
|
Err(e) => Err(VMError::InvalidInstruction(format!("FunctionBox call failed: {:?}", e)))
|
|
}
|
|
} else {
|
|
Err(VMError::TypeError(format!("Call target not callable: {}", arc_box.type_name())))
|
|
}
|
|
}
|
|
other => Err(VMError::TypeError(format!("Call target must be function name or FunctionBox, got {:?}", other))),
|
|
}
|
|
}
|
|
}
|