refactor: 动态编译改经 CompilerService 注入,oxide_vm 去编译器依赖

This commit is contained in:
2026-10-08 05:51:58 +00:00
parent 66735f802f
commit 4f9b6ab444
94 changed files with 459 additions and 67 deletions
@@ -2,6 +2,7 @@ use std::sync::Arc;
use oxide_builtins::array::{array_constructor, array_push};
use oxide_compiler::compiler::Compiler;
use oxide_compiler::DefaultCompilerService;
use oxide_types::value::JsValue;
use oxide_vm::vm::Vm;
@@ -10,6 +11,7 @@ fn eval(source: &str) -> Result<(Vm, JsValue), String> {
let program = oxide_parser::parse(&allocator, source).map_err(|e| format!("Parse error: {:?}", e))?;
let module = Compiler::new().compile(&program).map_err(|e| format!("Compile error: {}", e))?;
let mut vm = Vm::new();
vm.set_compiler_service(Arc::new(DefaultCompilerService));
let result = vm.run(&Arc::new(module))?;
Ok((vm, result))
}
@@ -40,6 +42,7 @@ fn array_push_returns_length() {
#[test]
fn array_push_returns_true_length_beyond_31() {
let mut vm = Vm::new();
vm.set_compiler_service(Arc::new(DefaultCompilerService));
vm.set_reg(1, oxide_types::value::JsValue::int(31));
let array = array_constructor(&mut vm, &[0, 1]).unwrap();
vm.set_reg(0, array);