fix(compiler): 完善闭包捕获(cell 索引稳定、参数遮蔽、函数/类名捕获、b 槽立即数)

This commit is contained in:
爱特每羊队
2026-08-05 19:19:29 +08:00
parent 3390b61453
commit b611e26f11
11 changed files with 87 additions and 70 deletions
@@ -35,7 +35,11 @@ impl Compiler {
let var_reg = ctx.lookup(&name)?;
ctx.reserve_reg(var_reg);
ctx.inst(Inst::create_closure(Operand::Reg(var_reg as u32), ctx.nested.len() as u16));
ctx.inst(Inst::new(OpCode::STORE_VAR, Operand::Reg(var_reg as u32), Operand::Reg(var_reg as u32), Operand::None));
if let Some(&cell_idx) = ctx.captured_bindings.get(&name) {
ctx.inst(Inst::new(OpCode::MAKE_CELL, Operand::Reg(var_reg as u32), Operand::Imm(cell_idx as u16), Operand::None));
} else {
ctx.inst(Inst::new(OpCode::STORE_VAR, Operand::Reg(var_reg as u32), Operand::Reg(var_reg as u32), Operand::None));
}
Ok(None)
}
}