fix(includes): atof_out 输出参数版绕开跨模块 double 返回 bug; 浮点节点构造值记录+查询(parser); NEWF/ATOF/LKP 定位插桩; ast 导出查表函数

This commit is contained in:
TermiNexus committed 2026-08-08 19:42:55 +08:00
1 parent efb4aada15
commit 61e578fe9a
3 files changed
+57 -18

No files matched your search

+1
View File
@@ -52,6 +52,7 @@ from .match import (
from .lexer import Lexer, _lexer_init, tokenize, new_lexer
from .parser import Parser, _parser_init, parse_tokens, new_parser
from .parser import _parse_test
from .parser import _dbg_lookup_lit_val, _dbg_lit_found
# ============================================================
# Global Memory Pool Pointer (follows project rules: declare _mbuddy)
+43 -18
View File
@@ -169,24 +169,21 @@ def _new_const_float(pool: memhub.MemManager | t.CPtr, val: t.CDouble,
lineno: t.CInt, col: t.CInt) -> AST | t.CPtr:
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
# 记录当前节点
# 把数字文本存到 str_val(stdlib 分配,绕开 pool 对 float_val 字段的覆写)
# REG-SRC 用 string.atof(str_val) 恢复原始值
lit_txt: str = stdlib.malloc(64)
if lit_txt is not None:
stdio.snprintf(lit_txt, 64, "%.17g", val)
new_c.str_val = lit_txt
# 记录浮点节点 ptr→val 到 stdlib 表(构造时值正确,供 REG-SRC 查表绕开 pool 覆写)
# 表满时重置:旧记录对应已翻译完的文件,从当前节点重新记录
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 = stdlib.malloc(4096 * 8)
_g_dbg_vals = stdlib.malloc(4096 * 8)
_g_dbg_cnt = 0
elif _g_dbg_cnt >= 4096:
_g_dbg_cnt = 0
if _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
@@ -196,10 +193,38 @@ def _new_const_float(pool: memhub.MemManager | t.CPtr, val: t.CDouble,
return new_c
# OVW-DBG: 浮点节点监控表(stdlib 分配,避免污染 pool)
# 浮点节点构造值表(stdlib 分配,避免污染 pool)
_g_dbg_pts: t.CUInt64T | t.CPtr = None
_g_dbg_vals: t.CDouble | t.CPtr = None
_g_dbg_cnt: int = 0
# 最近一次 _dbg_lookup_lit_val 是否命中
_g_dbg_lit_found: int = 0
def _dbg_lookup_lit_val(ptr: t.CUInt64T) -> double:
"""查浮点节点构造值表:返回 ptr 节点的原始构造值(未命中返回 0 并置 found=0)
用于绕开 pool 分配对 AST float_val 字段的覆写(构造时值正确,读取时可能被覆写)。
"""
global _g_dbg_lit_found
_g_dbg_lit_found = 0
if _g_dbg_pts is None or _g_dbg_vals is None:
stdio.printf("[LKP-DBG] pts null cnt=%d\n", _g_dbg_cnt)
return 0.0
i: t.CSizeT = 0
while i < _g_dbg_cnt:
if _g_dbg_pts[i] == ptr:
_g_dbg_lit_found = 1
stdio.printf("[LKP-DBG] HIT ptr=%p val=%.17g cnt=%d\n", ptr, _g_dbg_vals[i], _g_dbg_cnt)
return _g_dbg_vals[i]
i += 1
stdio.printf("[LKP-DBG] MISS ptr=%p cnt=%d\n", ptr, _g_dbg_cnt)
return 0.0
def _dbg_lit_found() -> int:
"""检查最近一次 _dbg_lookup_lit_val 是否命中"""
return _g_dbg_lit_found
def _new_const_str(pool: memhub.MemManager | t.CPtr, val: str,
+13
View File
@@ -371,6 +371,19 @@ def atof(src: str) -> t.CDouble:
src, int_part, frac_part, frac_div, result)
return result
def atof_out(src: str, out: t.CDouble | t.CPtr) -> t.CInt:
"""atof 结果写入 out[0](输出参数方式,避免跨模块 double 返回值传递 bug)
返回值仅表示成功与否(1=成功,0=失败),结果值通过 out 指针传递,
不依赖 double 返回值的跨模块传递。
"""
if out is None:
return 0
v: t.CDouble = atof(src)
out[0] = v
return 1
def split(s: str, delim: str, result: t.CArray[str]) -> int:
count: int = 0
start: str = s