feat: 字节码VM基础设施 — 编译器、VM执行循环、Runtime trait

Phase 1-3: 基础VM架构
- 新增 Runtime trait: 抽象树遍历解释器和VM的共同接口
- NativeFn 改为接受 &mut dyn Runtime
- 重构所有内置函数使用新签名
- vm/opcode.rs: 33个字节码指令 + 编码/解码辅助函数
- vm/compiler.rs: AST→字节码编译器,支持变量解析、跳转回填、作用域
- vm/vm.rs: 栈式VM执行循环,支持全局变量、原生函数调用
- lib.rs: 新增 run_file_vm() + --vm CLI标志
- 修复: 跳转偏移计算、对象字面量编译

工作特性: 算术、变量、while/for循环、条件、数组、对象、字符串
待完成: 用户定义函数调用、闭包/upvalue捕获、完整require支持

Release模式: 1M算术循环 VM 0.44s vs 树遍历 0.89s (2.0x加速)
This commit is contained in:
2026-06-25 01:08:49 +08:00
parent 89952139c5
commit d854b22006
15 changed files with 2185 additions and 74 deletions
+3 -3
View File
@@ -1,8 +1,8 @@
//! 内置函数模块:按功能分组注册,便于扩展和维护。
mod core;
mod io;
mod os;
pub mod core;
pub mod io;
pub mod os;
pub mod string;
use crate::interpreter::{Env, Value};