fix: 修复 harness 函数原型和 Object.assign ToObject

This commit is contained in:
爱特每羊队
2026-06-09 19:46:50 +08:00
parent e588fa4c8c
commit 16568c83fe
10 changed files with 131 additions and 16 deletions
+10
View File
@@ -129,6 +129,16 @@ impl CompileCtx {
self.next_reg = checkpoint;
}
pub(crate) fn reserve_reg(&mut self, reg: u8) {
let next = reg.wrapping_add(1);
if self.next_reg <= reg {
self.next_reg = next;
}
if self.max_regs < next {
self.max_regs = next;
}
}
pub(crate) fn add_constant(&mut self, c: Constant) -> u16 {
if let Some(idx) = self.constants.iter().position(|x| x == &c) {
return idx as u16;
+7 -7
View File
@@ -556,14 +556,14 @@ impl Compiler {
// 1-indexed: 0 = no sub_module (sentinel)
let sub_idx = ctx.sub_modules.len() as u32;
// Add BytecodeFunc constant and emit LOAD_CONST + STORE_VAR
// Use the register allocated during the count/hoist pass. Calling
// lookup_or_global here would allocate an extra register during
// emission and desynchronize later function declaration bindings.
let var_reg = ctx.lookup(&name)?;
ctx.reserve_reg(var_reg);
let const_idx = ctx.add_constant(Constant::BytecodeFunc(sub_idx));
let func_reg = ctx.alloc_reg();
ctx.emit_load_const(func_reg, const_idx);
// Get the register that was allocated for this FD in the counter pass
let var_reg = ctx.lookup_or_global(&name);
ctx.emit(opcode::encode(OpCode::STORE_VAR, var_reg, func_reg, 0));
ctx.emit_load_const(var_reg, const_idx);
ctx.emit(opcode::encode(OpCode::STORE_VAR, var_reg, var_reg, 0));
Ok(None)
}