From efb4aada15040928da5ed7e81ebae2a13911d579 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Sat, 8 Aug 2026 18:18:52 +0800 Subject: [PATCH] =?UTF-8?q?chore(includes):=20=E6=B7=BB=E5=8A=A0=E6=B5=AE?= =?UTF-8?q?=E7=82=B9=E5=AD=97=E9=9D=A2=E9=87=8F=E8=A7=A3=E6=9E=90=E5=AE=9A?= =?UTF-8?q?=E4=BD=8D=E6=8F=92=E6=A1=A9=20-=20string.atof=20=E6=89=93?= =?UTF-8?q?=E5=8D=B0=E9=95=BF=E5=AD=97=E9=9D=A2=E9=87=8F=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E4=B8=AD=E9=97=B4=E5=80=BC(ATOF-DBG);=20parser.=5Fnew=5Fconst?= =?UTF-8?q?=5Ffloat=20=E6=89=93=E5=8D=B0=E6=9E=84=E9=80=A0=E5=80=BC/readba?= =?UTF-8?q?ck/=E8=8A=82=E7=82=B9=E8=A6=86=E5=86=99=E7=9B=91=E6=8E=A7(NEWF-?= =?UTF-8?q?DBG/OVW-DBG);=20=E7=94=A8=E4=BA=8E=E5=AE=9A=E4=BD=8D=E6=B5=AE?= =?UTF-8?q?=E7=82=B9=20CDefine=20=E5=80=BC=E9=94=99=E8=AF=AF(llc=20ret=20i?= =?UTF-8?q?32=200)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/ast/parser.vp | 36 +++++++++++++++++++++++++++++++++++- includes/string.vp | 4 ++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/includes/ast/parser.vp b/includes/ast/parser.vp index 462c9b8..f1136a1 100644 --- a/includes/ast/parser.vp +++ b/includes/ast/parser.vp @@ -2,6 +2,8 @@ import t, c from stdint import * import memhub import string +import stdio +import stdlib from .tokens import (Token, TokenType, Keyword, TokOp) from .base import ( AST, ASTCtx, ASTKind, OpKind, ASTFlag, @@ -165,7 +167,39 @@ def _new_const_int(pool: memhub.MemManager | t.CPtr, val: t.CInt64T, def _new_const_float(pool: memhub.MemManager | t.CPtr, val: t.CDouble, lineno: t.CInt, col: t.CInt) -> AST | t.CPtr: - return Constant(pool, CONST_FLOAT, 0, val, None, lineno, col) + global _g_dbg_pts, _g_dbg_vals, _g_dbg_cnt + new_c: Constant | t.CPtr = Constant(pool, CONST_FLOAT, 0, val, None, lineno, col) + # OVW-DBG: 检查之前构造的浮点节点是否已被覆写(定位覆写者) + if _g_dbg_cnt > 0 and _g_dbg_pts is not None and _g_dbg_vals is not None: + chk: t.CSizeT = 0 + while chk < _g_dbg_cnt: + old_ptr: t.CUInt64T = _g_dbg_pts[chk] + if old_ptr != 0: + old_val: t.CDouble = _g_dbg_vals[chk] + old_c: Constant | t.CPtr = (Constant | t.CPtr)(t.CVoid(old_ptr, t.CPtr)) + if old_c.float_val != old_val: + stdio.printf("[OVW-DBG] 构造新字面量 val=%.17g 后,之前节点 ptr=%p 的 float_val 从 %.17g 变 %.17g\n", + val, t.CUInt64T(old_ptr), old_val, old_c.float_val) + _g_dbg_pts[chk] = 0 + chk += 1 + # 记录当前节点 + if _g_dbg_pts is None: + _g_dbg_pts = stdlib.malloc(512 * 8) + _g_dbg_vals = stdlib.malloc(512 * 8) + if _g_dbg_cnt < 512 and _g_dbg_pts is not None and _g_dbg_vals is not None: + _g_dbg_pts[_g_dbg_cnt] = t.CUInt64T(new_c) + _g_dbg_vals[_g_dbg_cnt] = val + _g_dbg_cnt += 1 + # NEWF-DBG: 打印浮点常量构造值+节点指针+存储后读回(定位浮点 CDefine 值错误) + stdio.printf("[NEWF-DBG] val=%.17g ptr=%p readback=%.17g int_val=%lld\n", + val, t.CSizeT(new_c), new_c.float_val, new_c.int_val) + return new_c + + +# OVW-DBG: 浮点节点监控表(stdlib 分配,避免污染 pool) +_g_dbg_pts: t.CUInt64T | t.CPtr = None +_g_dbg_vals: t.CDouble | t.CPtr = None +_g_dbg_cnt: int = 0 def _new_const_str(pool: memhub.MemManager | t.CPtr, val: str, diff --git a/includes/string.vp b/includes/string.vp index 6ad1adb..e44a386 100644 --- a/includes/string.vp +++ b/includes/string.vp @@ -365,6 +365,10 @@ def atof(src: str) -> t.CDouble: while exp < 0: result = result / 10.0 exp += 1 + # ATOF-DBG: 打印长浮点字面量解析过程(定位浮点 CDefine 值错误) + if src is not None and strlen(src) >= 12: + stdio.printf("[ATOF-DBG] src=%s int=%.17g frac=%.17g div=%.17g result=%.17g\n", + src, int_part, frac_part, frac_div, result) return result def split(s: str, delim: str, result: t.CArray[str]) -> int: