feat: async/await 语法支持(AWAIT 帧快照挂起/恢复 + 微任务驱动 + AsyncFunction intrinsics)

This commit is contained in:
爱特每羊队
2026-08-09 22:02:15 +08:00
parent dcbe3d9320
commit 0d9e6eabc9
28 changed files with 1055 additions and 28 deletions
+4
View File
@@ -70,6 +70,8 @@ pub struct CompiledModule {
pub needs_home_object: bool,
/// 是否为生成器函数体(`function*`):调用返回迭代器对象,body 挂起/恢复执行。
pub is_generator: bool,
/// 是否为异步函数体(`async function` / async 箭头):调用返回 promise,body 挂起/恢复执行。
pub is_async: bool,
pub upvalue_captures: Vec<UpvalueCapture>,
pub cells_needed: u8,
/// 全局扁平模块 id:编译末端 flatten 阶段分配(顶层 0,子模块 DFS 递增)。
@@ -96,6 +98,7 @@ impl CompiledModule {
is_derived_constructor: false,
needs_home_object: false,
is_generator: false,
is_async: false,
upvalue_captures: Vec::new(),
cells_needed: 0,
flat_id: 0,
@@ -127,6 +130,7 @@ impl Clone for CompiledModule {
is_derived_constructor: self.is_derived_constructor,
needs_home_object: self.needs_home_object,
is_generator: self.is_generator,
is_async: self.is_async,
upvalue_captures: self.upvalue_captures.clone(),
cells_needed: self.cells_needed,
flat_id: self.flat_id,
+2
View File
@@ -203,6 +203,8 @@ define_opcodes! {
SUSPEND_BODY = 0x77 => "SUSPEND_BODY",
// `yield*` 委托:rd=内层可迭代对象;委托完成值经 reg 0 交付(与 YIELD 同协议)。
YIELD_STAR = 0x78 => "YIELD_STAR",
// `await`:rd=被等待的值(PromiseResolve 包装);挂起异步帧,恢复值经 reg 0 交付。
AWAIT = 0x79 => "AWAIT",
// ── 位运算 (0x80-0x8F) ──
BIT_AND = 0x80 => "BIT_AND",