mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-24 02:31:13 +08:00
refactor: 动态编译改经 CompilerService 注入,oxide_vm 去编译器依赖
This commit is contained in:
@@ -5,6 +5,7 @@ use std::sync::Arc;
|
||||
|
||||
use oxide_bytecode::module::CompiledModule;
|
||||
use oxide_compiler::compiler::Compiler;
|
||||
use oxide_compiler::DefaultCompilerService;
|
||||
use oxide_parser::Allocator;
|
||||
use oxide_types::value::JsValue;
|
||||
use oxide_vm::vm::Vm;
|
||||
@@ -18,6 +19,7 @@ fn eval(source: &str) -> JsValue {
|
||||
|
||||
fn run(module: &Arc<CompiledModule>) -> JsValue {
|
||||
let mut vm = Vm::new();
|
||||
vm.set_compiler_service(Arc::new(DefaultCompilerService));
|
||||
vm.run(module).expect("vm run failed")
|
||||
}
|
||||
|
||||
@@ -26,6 +28,7 @@ fn eval_str(source: &str) -> String {
|
||||
let program = oxide_parser::parse(&allocator, source).expect("parse failed");
|
||||
let module = Arc::new(Compiler::new().compile(&program).expect("compile failed"));
|
||||
let mut vm = Vm::new();
|
||||
vm.set_compiler_service(Arc::new(DefaultCompilerService));
|
||||
let v = vm.run(&module).expect("vm run failed");
|
||||
// 字符串结果须在同一 VM 上读:perm 串指向 VM 私有内核,VM drop 后指针悬垂。
|
||||
if v.is_string() {
|
||||
|
||||
Reference in New Issue
Block a user