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

This commit is contained in:
2026-08-05 19:19:29 +08:00
parent 179960ed75
commit 050f75c952
11 changed files with 87 additions and 70 deletions
+1 -3
View File
@@ -42,9 +42,7 @@ impl Compiler {
ctx.declare(name, var_reg, kind, is_const)?;
var_reg
};
if ctx.captured_bindings.contains(name) {
let cell_idx = ctx.scopes.cell_registry.len() as u8;
ctx.scopes.cell_registry.push((name.to_string(), cell_idx));
if let Some(&cell_idx) = ctx.captured_bindings.get(name) {
ctx.inst(Inst::new(OpCode::MAKE_CELL, Operand::Reg(src_reg as u32), Operand::Imm(cell_idx as u16), Operand::None));
} else {
ctx.inst(Inst::new(OpCode::STORE_VAR, Operand::Reg(target_reg as u32), Operand::Reg(src_reg as u32), Operand::Imm(if is_const { 1 } else { 0 })));