fix(compiler): 重写闭包捕获分析为 AST 级,修复 MAKE_CELL 时序

This commit is contained in:
爱特每羊队
2026-08-05 18:41:48 +08:00
parent 845ba2884a
commit 3390b61453
8 changed files with 506 additions and 318 deletions
+1 -1
View File
@@ -146,7 +146,7 @@ impl Compiler {
return Ok(val_reg);
}
// Check if target is a captured cell
if ctx.scopes.symbols.lookup_is_captured(name) {
if ctx.captured_bindings.contains(name) {
let cell_idx = ctx
.scopes
.cell_registry
+1 -1
View File
@@ -18,7 +18,7 @@ impl Compiler {
}
}
if ctx.scopes.symbols.lookup_is_captured(name) {
if ctx.captured_bindings.contains(name) {
let cell_idx = ctx
.scopes
.cell_registry
@@ -222,7 +222,7 @@ impl Compiler {
let name = id.name.as_str();
// Check if this is an upvalue or captured cell reference
let uv_idx = ctx.current_upvalue_captures.iter().position(|u| u.name == name);
let is_captured = ctx.scopes.symbols.lookup_is_captured(name);
let is_captured = ctx.captured_bindings.contains(name);
if let Some(uv) = uv_idx {
// Upvalue: LOAD_UPVALUE + CONST(1) + ADD/SUB + STORE_UPVALUE
let val_reg = ctx.alloc_reg();