From ee3337f3c4c58935cf0a74e69bb97ac5df046a42 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Wed, 14 Oct 2026 17:40:53 +0800 Subject: [PATCH] =?UTF-8?q?revert(viperc):=20=E5=9B=9E=E9=80=80=E9=97=AD?= =?UTF-8?q?=E5=8C=85=E5=8F=98=E9=87=8F=E5=8F=96=E5=9D=80=E7=9A=84=E6=94=BE?= =?UTF-8?q?=E8=A1=8C=EF=BC=8C=E4=BB=85=E4=BF=9D=E7=95=99=E2=80=9C=E5=AE=9E?= =?UTF-8?q?=E5=8F=82=E7=BA=A7=E6=8A=A5=E9=94=99=E5=AE=9A=E4=BD=8D=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 回退 a060e1d 中 ExprGenOps 的闭包取址改动与 TypeGenErr 的临时打印移除:&_on_submit 仍按级数不符报 CastError(source level 2 -> target level 1),语义不变、不放行 - 保留 CallGenCall._call_method_on_ptr 的实参级 AST 节点透传:方法/构造实参转换失败时报错定位到具体实参表达式,并显示完整两帧(函数定义帧 + 错误点) --- App/lib/core/Gen/Expr/ExprGenOps.vp | 8 -------- App/lib/core/Gen/Type/TypeGenErr.vp | 9 +++++++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/App/lib/core/Gen/Expr/ExprGenOps.vp b/App/lib/core/Gen/Expr/ExprGenOps.vp index 4a47bde..d547d42 100644 --- a/App/lib/core/Gen/Expr/ExprGenOps.vp +++ b/App/lib/core/Gen/Expr/ExprGenOps.vp @@ -755,14 +755,6 @@ novirtual class ExprGenOps(ExprGenBase.ExprGenBase): gv_ao: mlirlite.GlobalVariable* = self.Gen.ExprGenAttr.find_global_in_module(mod, nm_ao.id) if gv_ao is not None and gv_ao.Name is not None and gv_ao.Ty is not None: v_ao = self.Gen.ExprGenAttr.make_global_ref(pool, gv_ao.Name, gv_ao.Ty) if v_ao is not None and v_ao.Ty is not None: - # 闭包变量(嵌套 `def f()` 被提升后在父函数里是一个 **i8\*\*** 槽,见 - # FuncGenMixin.translate_nested_function_def 第 13e 步):变量自身就是那个 - # 函数的闭包指针,`&f` 应给出它的**值**(一级 i8*),而不是槽地址 i8**(二级) - # ——否则传给 `callback: t.CPtr` 会因级数不符报 CastError(source level 2 -> - # target level 1)。与“函数名即地址(同 C)”一致。闭包槽与普通函数指针变量 - # 同为 i8**、类型上无法区分,故用闭包名表判定(第 13e 步已登记该名字)。 - if self.Gen.CallGenLeafKit.is_closure_name(nm_ao.id) != 0 and v_ao.Ty.Pointee is not None: - return mlirlite.build_load(builder, v_ao.Ty.Pointee, v_ao) # Object-pointer variable (alloca is Ptr(Ptr(Struct))): the variable is the object, return the object pointer (load once), aligned with translate_c_addr. match v_ao.Ty: case mlirlite.LLVMType.Ptr(ao1): diff --git a/App/lib/core/Gen/Type/TypeGenErr.vp b/App/lib/core/Gen/Type/TypeGenErr.vp index d0aceb2..27dc554 100644 --- a/App/lib/core/Gen/Type/TypeGenErr.vp +++ b/App/lib/core/Gen/Type/TypeGenErr.vp @@ -47,6 +47,7 @@ novirtual class TypeGenErr(TypeGenBase.TypeGenBase): # 当前帧(错误点)位置:优先 node,其次调用栈最内层有行号的帧,最后 current_file。 lineno: int = 0 if node is not None: lineno = node.lineno + raw_line: int = lineno # [TEMP-DIAG] 兜底前的原始节点行号(定位完删除) file_name: str = self.Gen.TypeGenResolve.get_current_file() if file_name is None: file_name = "" # 报错位置兜底(“节点位置不可信”时优先用正在翻译的实参位置,精确定位到 @@ -84,6 +85,14 @@ novirtual class TypeGenErr(TypeGenBase.TypeGenBase): Diag.finish() return 0 + # [TEMP-DIAG] 定位“报错位置”问题用(定位完删除):把决策输入打出来 + # node=节点原始行号(0=合成) curarg=当前实参行号 trace=栈深 top=栈最内层行号 + ti_top: int = -1 + if self.Gen.TypeGenBase.TraceCount > 0: + tf_d: GenTypes.TraceFrame* = self.Gen.TypeGenBase._get_trace_frame(self.Gen.TypeGenBase.TraceCount - 1) + if tf_d is not None: ti_top = tf_d.lineno + stdio.printf("[TEMP-DIAG] node=%d curarg=%d trace=%d top=%d -> shown=%d\n", + raw_line, self.Gen.TypeGenBase.CurArgLine, self.Gen.TypeGenBase.TraceCount, ti_top, lineno) Diag.begin(ent, err_type, msg) # 调用链帧(按"自外向内"顺序)**由本类遍历**(只有它拿得到 TraceFrame),填入 entry。 for i in range(int(self.Gen.TypeGenBase.TraceCount)):