Phase 12.7完了 + ChatGPT5によるVMリファクタリング
## 📚 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>
This commit is contained in:
@ -412,6 +412,54 @@ impl NyashInterpreter {
|
||||
}
|
||||
}
|
||||
|
||||
/// Execute a FunctionBox with given NyashBox arguments (crate-visible helper for VM)
|
||||
pub(crate) fn run_function_box(
|
||||
fun: &crate::boxes::function_box::FunctionBox,
|
||||
args: Vec<Box<dyn crate::box_trait::NyashBox>>,
|
||||
) -> Result<Box<dyn crate::box_trait::NyashBox>, RuntimeError> {
|
||||
use crate::box_trait::{NyashBox, VoidBox};
|
||||
if args.len() != fun.params.len() {
|
||||
return Err(RuntimeError::InvalidOperation { message: format!(
|
||||
"Function expects {} args, got {}", fun.params.len(), args.len()
|
||||
)});
|
||||
}
|
||||
|
||||
let mut interp = NyashInterpreter::new();
|
||||
// Captures
|
||||
for (k, v) in fun.env.captures.iter() {
|
||||
interp.declare_local_variable(k, v.clone_or_share());
|
||||
}
|
||||
if let Some(me_w) = &fun.env.me_value {
|
||||
if let Some(me_arc) = me_w.upgrade() {
|
||||
interp.declare_local_variable("me", (*me_arc).clone_or_share());
|
||||
} else {
|
||||
interp.declare_local_variable("me", Box::new(crate::boxes::null_box::NullBox::new()));
|
||||
}
|
||||
}
|
||||
// Params
|
||||
for (p, v) in fun.params.iter().zip(args.into_iter()) {
|
||||
interp.declare_local_variable(p, v);
|
||||
}
|
||||
// Execute body
|
||||
crate::runtime::global_hooks::push_task_scope();
|
||||
let mut result: Box<dyn NyashBox> = Box::new(VoidBox::new());
|
||||
for st in &fun.body {
|
||||
match interp.execute_statement(st) {
|
||||
Ok(val) => {
|
||||
result = val;
|
||||
if let super::ControlFlow::Return(rv) = &interp.control_flow {
|
||||
result = rv.clone_box();
|
||||
interp.control_flow = super::ControlFlow::None;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Err(e) => { crate::runtime::global_hooks::pop_task_scope(); return Err(e); }
|
||||
}
|
||||
}
|
||||
crate::runtime::global_hooks::pop_task_scope();
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
// ===== Tests =====
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user