mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-23 18:21:13 +08:00
feat: 生成器基础支持(YIELD 帧快照挂起/恢复 + GeneratorPrototype next/return/throw)
- 新增 YIELD/SUSPEND_BODY opcode;function* 识别与 yield emit - GeneratorState 全量快照 VM 执行上下文(regs/pc/bytecode/spill/save/try/cell 栈段/迭代器) - 调用时参数初始化(默认值/解构副作用与异常在 g() 时刻生效) - %GeneratorPrototype%/%GeneratorFunction.prototype% 内建对象与 next/return/throw - session GC trace 生成器状态 JsValues;闭包捕获分析补 yield/赋值目标扫描
This commit is contained in:
@@ -68,6 +68,8 @@ pub struct CompiledModule {
|
||||
pub is_derived_constructor: bool,
|
||||
/// 原型方法是否需要运行时 home_object。
|
||||
pub needs_home_object: bool,
|
||||
/// 是否为生成器函数体(`function*`):调用返回迭代器对象,body 挂起/恢复执行。
|
||||
pub is_generator: bool,
|
||||
pub upvalue_captures: Vec<UpvalueCapture>,
|
||||
pub cells_needed: u8,
|
||||
/// 全局扁平模块 id:编译末端 flatten 阶段分配(顶层 0,子模块 DFS 递增)。
|
||||
@@ -93,6 +95,7 @@ impl CompiledModule {
|
||||
is_class_constructor: false,
|
||||
is_derived_constructor: false,
|
||||
needs_home_object: false,
|
||||
is_generator: false,
|
||||
upvalue_captures: Vec::new(),
|
||||
cells_needed: 0,
|
||||
flat_id: 0,
|
||||
@@ -123,6 +126,7 @@ impl Clone for CompiledModule {
|
||||
is_class_constructor: self.is_class_constructor,
|
||||
is_derived_constructor: self.is_derived_constructor,
|
||||
needs_home_object: self.needs_home_object,
|
||||
is_generator: self.is_generator,
|
||||
upvalue_captures: self.upvalue_captures.clone(),
|
||||
cells_needed: self.cells_needed,
|
||||
flat_id: self.flat_id,
|
||||
|
||||
@@ -189,7 +189,7 @@ define_opcodes! {
|
||||
PROFILE_BRANCH = 0x6B => "PROFILE_BRANCH",
|
||||
PROFILE_CALL = 0x6C => "PROFILE_CALL",
|
||||
|
||||
// ── 并行 — 占位符 (0x70-0x7F) ──
|
||||
// ── 并行 — 占位符 (0x70-0x75) ──
|
||||
FORK = 0x70 => "FORK",
|
||||
JOIN = 0x71 => "JOIN",
|
||||
GET_PRIVATE = 0x72 => "GET_PRIVATE",
|
||||
@@ -197,6 +197,11 @@ define_opcodes! {
|
||||
INIT_PRIVATE = 0x74 => "INIT_PRIVATE",
|
||||
PRIVATE_BRAND_IN = 0x75 => "PRIVATE_BRAND_IN",
|
||||
|
||||
// ── 生成器 (0x76-0x77) ──
|
||||
YIELD = 0x76 => "YIELD", // rd=被让出的值(结果经 reg 0 交付,见 contract.rs)
|
||||
// 生成器 body 起点标记:调用时参数初始化完成后挂起于此,首次 next() 从这继续。
|
||||
SUSPEND_BODY = 0x77 => "SUSPEND_BODY",
|
||||
|
||||
// ── 位运算 (0x80-0x8F) ──
|
||||
BIT_AND = 0x80 => "BIT_AND",
|
||||
BIT_OR = 0x81 => "BIT_OR",
|
||||
|
||||
Reference in New Issue
Block a user