diff --git a/App/lib/core/Gen/VarGenMixin.vp b/App/lib/core/Gen/VarGenMixin.vp index 0402c6f..f092445 100644 --- a/App/lib/core/Gen/VarGenMixin.vp +++ b/App/lib/core/Gen/VarGenMixin.vp @@ -288,27 +288,30 @@ novirtual class VarGenMixin: """Add a variable to the variable table""" if name is None or alloca is None or vars_ptr is None: return 1 if var_count >= HT.MAX_VARS: return 1 + VLogger.info("dbg.a1.enter", "TR") entry_size: sizet = GenTypes.VarEntry.__sizeof__() entry_addr: uint64 = uint64(vars_ptr) + var_count * entry_size entry: GenTypes.VarEntry* = GenTypes.VarEntry*(entry_addr) - # Deep-copy the variable name into stdlib (survives pool reset): storing the AST Name.id pointer lets - # later allocations overwrite it, so find_var's strcmp silently misses and rebuilds a degenerate alloca. + VLogger.info(f"dbg.a2.entry esz={entry_size} cnt={var_count}", "TR") name_len: sizet = string.strlen(name) + VLogger.info(f"dbg.a3.namelen={name_len}", "TR") name_copy: bytes = stdlib.malloc(name_len + 1) if name_copy is None: return 1 string.strcpy(name_copy, name) + VLogger.info("dbg.a4.copied", "TR") entry.Name = name_copy + VLogger.info("dbg.a5.name", "TR") entry.Alloca = alloca entry.Used = 1 - # Explicitly zero the const flag (do not rely on the entry's zero initialization): set_var_const - # sets it to 1 only for real const objects, so zeroing avoids false positives. entry.IsConst = 0 - # 生命期标签显式初始化:未登记 = LIFE_UNKNOWN(保守放行)。 + VLogger.info("dbg.a6.const", "TR") entry.Life = GenTypes.LIFE_UNKNOWN + VLogger.info("dbg.a7.life", "TR") # P2 willFree 的 entry.Freed **不在这里写**:init_vars 已对整块 memset 清零(见 init_vars), # 逐个字段写末端偏移在"结构体刚加字段"时容易踩到;统一依赖整块清零。 # [S3 dual write] Value-type Spec (alloca.Ty is Ptr(value type), so take its pointee) entry.Spec = self._spec_of_var_alloca(alloca) + VLogger.info("dbg.a8.spec", "TR") return 0 def clear_var_freed(self, symtab: GenTypes.SymbolTable*, name: str) -> int: