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:
@@ -7,6 +7,7 @@ rust-version.workspace = true
|
||||
description = "OxideJS - VmHost trait: the abstract Vm interface builtins are written against"
|
||||
|
||||
[dependencies]
|
||||
oxide_bytecode = { path = "../oxide_bytecode" }
|
||||
oxide_types = { path = "../oxide_types" }
|
||||
num-bigint = "0.4"
|
||||
num-traits = "0.2"
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
//! 动态编译服务接口:`Vm` 经它把源码编译为 `CompiledModule`,
|
||||
//! 解耦 `oxide_vm` 对 `oxide_compiler` / `oxide_parser` 的直接依赖。
|
||||
|
||||
use oxide_bytecode::module::CompiledModule;
|
||||
|
||||
/// 动态编译服务:`Vm` 经它把源码编译为 `CompiledModule`。
|
||||
///
|
||||
/// 无状态实现 `Send + Sync`,`Arc<dyn CompilerService>` 可跨线程共享
|
||||
/// (worker 调度、多 realm 场景)。trait 对象安全,`Vm` 以
|
||||
/// `Arc<dyn CompilerService>` 持服务句柄。
|
||||
pub trait CompilerService: Send + Sync {
|
||||
/// 编译普通脚本(source_encoded 形态),返回完整模块树
|
||||
/// (根 flat_id=0 + 子模块)。
|
||||
///
|
||||
/// 供 `Function` 构造器(wrap 源码)与 `$262.evalScript`(普通脚本)。
|
||||
fn compile_script(&self, source: &str) -> Result<CompiledModule, String>;
|
||||
|
||||
/// 编译 eval 脚本(source_encoded + eval_script 形态),返回完整模块树。
|
||||
///
|
||||
/// 顶层 var/function 声明落全局属性 configurable:true。
|
||||
fn compile_eval_script(&self, source: &str) -> Result<CompiledModule, String>;
|
||||
}
|
||||
@@ -12,6 +12,8 @@
|
||||
|
||||
/// ECMAScript 强转函数族。
|
||||
mod coercion;
|
||||
/// 动态编译服务接口(`Vm` 经它解耦对编译器的直接依赖)。
|
||||
pub mod compiler_service;
|
||||
/// builtins 依赖的 `VmHost` 能力面。
|
||||
mod host;
|
||||
/// builtin native 函数的三态返回值。
|
||||
@@ -26,5 +28,6 @@ pub use coercion::{
|
||||
to_string_full, to_string_value_full, to_uint32, to_units_full, well_known_symbol_name, write_number_into,
|
||||
ToPrimitiveHint,
|
||||
};
|
||||
pub use compiler_service::CompilerService;
|
||||
pub use host::VmHost;
|
||||
pub use native_result::NativeResult;
|
||||
|
||||
Reference in New Issue
Block a user