feat: 增加 CreateClosure 字节码,函数字面量每次执行创建新闭包

This commit is contained in:
2026-06-25 10:16:32 +08:00
parent d7bc6a9b4e
commit c378b92d1a
8 changed files with 29 additions and 13 deletions
@@ -37,9 +37,8 @@ impl Compiler {
// 1-indexed: 0 = no sub_module (sentinel)
let sub_idx = ctx.sub_modules.len() as u32;
let const_idx = ctx.add_constant(Constant::BytecodeFunc(sub_idx));
let r = ctx.alloc_reg();
ctx.emit_load_const(r, const_idx);
ctx.emit_create_closure(r, sub_idx);
Ok(r)
}
@@ -72,9 +71,8 @@ impl Compiler {
// 1-indexed: 0 = no sub_module (sentinel)
let sub_idx = ctx.sub_modules.len() as u32;
let const_idx = ctx.add_constant(Constant::BytecodeFunc(sub_idx));
let r = ctx.alloc_reg();
ctx.emit_load_const(r, const_idx);
ctx.emit_create_closure(r, sub_idx);
Ok(r)
}