refactor(tpv): 新语法 R10(反斜杠续行合并)+ 回退 R5(语义不等价)

- 反斜杠续行合并为单行(304 处),呼应"尽可能不换行"。
- 回退 c.DerefAs(p, v) → *p = v 两处(StructGenMixin):原写法是 bitcast 后
  store 指针位,新写法按 pointee 值类型赋值,类型不符(i8* → List 值),
  语义不等价,保留 c.DerefAs。

种子自举通过。
This commit is contained in:
TermiNexus committed 2026-10-04 22:56:27 +08:00
1 parent 185a2196ca
commit 30a3da4cd4
43 files changed
+305 -707

No files matched your search

+5 -12
View File
@@ -946,9 +946,7 @@ def _CollectObjFilesImpl(base_dir: str, bd_len: sizet,
_mbuddy.free(sub_dir)
else:
# 检查是否是 .obj 文件
if fname_len > 4 and fname[fname_len - 4] == '.' \
and fname[fname_len - 3] == 'o' and fname[fname_len - 2] == 'b' \
and fname[fname_len - 1] == 'j':
if fname_len > 4 and fname[fname_len - 4] == '.' and fname[fname_len - 3] == 'o' and fname[fname_len - 2] == 'b' and fname[fname_len - 1] == 'j':
need: sizet = bd_len + 1 + fname_len + 2
if out_pos + need >= out_size:
break
@@ -1162,8 +1160,7 @@ def asm_to_obj(asm_path: str, sha1_val: str, output_dir: str,
trip: str = triple
if trip is None or trip[0] == '\0':
trip = "x86_64-none-elf"
cmd_len: sizet = len("llvm-mc -triple=") + len(trip) \
+ len(" -filetype=obj -o ") + len(obj_path) + len(asm_path) + 64
cmd_len: sizet = len("llvm-mc -triple=") + len(trip) + len(" -filetype=obj -o ") + len(obj_path) + len(asm_path) + 64
cmd: bytes = _mbuddy.alloc(cmd_len)
if cmd is None:
return 1
@@ -1923,9 +1920,7 @@ def _tb_read_pe_layout(mb: memhub.MemBuddy*, exe_path: str) -> TbPeLayout*:
have_sec = 1
if va < min_rva:
min_rva = va
if _tb_cc(head, base) == 46 and _tb_cc(head, base + 1) == 116 \
and _tb_cc(head, base + 2) == 101 and _tb_cc(head, base + 3) == 120 \
and _tb_cc(head, base + 4) == 116:
if _tb_cc(head, base) == 46 and _tb_cc(head, base + 1) == 116 and _tb_cc(head, base + 2) == 101 and _tb_cc(head, base + 3) == 120 and _tb_cc(head, base + 4) == 116:
text_rva = va
found_text = 1
si += 1
@@ -2266,8 +2261,7 @@ def _tb_grp_get(grp: bytes, cap: int, caller: str, callee: str, do_insert: int)
return slot
sc: str = rawptr(_tb_rd_u64(grp, off + TB_GRP_OFF_CALLER))
sk: str = rawptr(_tb_rd_u64(grp, off + TB_GRP_OFF_CALLEE))
if sc is not None and sk is not None \
and string.strcmp(sc, caller) == 0 and string.strcmp(sk, callee) == 0:
if sc is not None and sk is not None and string.strcmp(sc, caller) == 0 and string.strcmp(sk, callee) == 0:
return slot
i += 1
return -1
@@ -2635,8 +2629,7 @@ def _tb_scan_objdump(mb: memhub.MemBuddy*, dump: str, img_lo: uint64,
p += 1
tl: sizet = p - ts
ishex: int = 0
if tl == 2 and _tb_hex_digit(_tb_cc(dump, ts)) >= 0 \
and _tb_hex_digit(_tb_cc(dump, ts + 1)) >= 0:
if tl == 2 and _tb_hex_digit(_tb_cc(dump, ts)) >= 0 and _tb_hex_digit(_tb_cc(dump, ts + 1)) >= 0:
ishex = 1
ms = ts
if ishex == 0:
+4 -8
View File
@@ -213,14 +213,12 @@ def _BufHasGenericClassMarker(buf: bytes, blen: sizet) -> int:
return 0
pos: sizet = 0
while pos + 5 < blen:
if buf[pos] == 'c' and buf[pos + 1] == 'l' and buf[pos + 2] == 'a' \
and buf[pos + 3] == 's' and buf[pos + 4] == 's':
if buf[pos] == 'c' and buf[pos + 1] == 'l' and buf[pos + 2] == 'a' and buf[pos + 3] == 's' and buf[pos + 4] == 's':
# class 前是词边界(行首或非标识符字符)
prev_ok: int = 1
if pos > 0:
pc: char = buf[pos - 1]
if(pc >= 'a' and pc <= 'z') or(pc >= 'A' and pc <= 'Z') \
or(pc >= '0' and pc <= '9') or pc == '_':
if(pc >= 'a' and pc <= 'z') or(pc >= 'A' and pc <= 'Z') or(pc >= '0' and pc <= '9') or pc == '_':
prev_ok = 0
if prev_ok != 0:
p: sizet = pos + 5
@@ -263,8 +261,7 @@ def _BufHasGenericFuncMarker(buf: bytes, blen: sizet) -> int:
prev_ok: int = 1
if pos > 0:
pc: char = buf[pos - 1]
if(pc >= 'a' and pc <= 'z') or(pc >= 'A' and pc <= 'Z') \
or(pc >= '0' and pc <= '9') or pc == '_':
if(pc >= 'a' and pc <= 'z') or(pc >= 'A' and pc <= 'Z') or(pc >= '0' and pc <= '9') or pc == '_':
prev_ok = 0
if prev_ok != 0:
p: sizet = pos + 3
@@ -335,8 +332,7 @@ def _PreRegisterAllGenericTemplates(mb: memhub.MemBuddy*,
src_buf_pg[bytes_read_pg] = 0
# 文本扫描筛选:非泛型文件跳过(不 parse、不驻留,防 OOM)。
# 泛型类(class X[)与泛型函数(def f[)任一命中即进入 parse。
if _BufHasGenericClassMarker(src_buf_pg, bytes_read_pg) == 0 \
and _BufHasGenericFuncMarker(src_buf_pg, bytes_read_pg) == 0:
if _BufHasGenericClassMarker(src_buf_pg, bytes_read_pg) == 0 and _BufHasGenericFuncMarker(src_buf_pg, bytes_read_pg) == 0:
stdlib.free(src_buf_pg)
continue
# 泛型文件:永久池解析 → 注册模板(节点/表进 perm_pool,跨 reset 存活)
+3 -6
View File
@@ -116,8 +116,7 @@ def _ScanDirForPyFiles(mb: memhub.MemBuddy*,
break
continue
# 检查是否是 .vp 源文件(Viper 源仅 .vp,不再识别 .py)
if fname_len > 3 and Utils.is_vp_at(fname, 0, fname_len) != 0 \
and file_count < max_files:
if fname_len > 3 and Utils.is_vp_at(fname, 0, fname_len) != 0 and file_count < max_files:
full_path: bytes = Utils.JoinPath(dir_path, fname)
if full_path is not None:
sbuf: bytes = Utils.read_file_to_buf(full_path, SRC_BUF_SIZE)
@@ -891,8 +890,7 @@ def RunMultiFileProject(mb: memhub.MemBuddy*,
for i_app_inc in range(file_count):
ea_app_inc: uint64 = uint64(entries) + i_app_inc * entry_size
ent_app_inc: SrcFileEntry* = (SrcFileEntry*)(ea_app_inc)
if ent_app_inc is not None and ent_app_inc.Sha1 is not None \
and string.strcmp(ent_app_inc.Sha1, inc_sha1_pre) == 0:
if ent_app_inc is not None and ent_app_inc.Sha1 is not None and string.strcmp(ent_app_inc.Sha1, inc_sha1_pre) == 0:
is_app_file_inc = 1
break
if is_app_file_inc != 0 and inc_fail_flags is not None:
@@ -921,8 +919,7 @@ def RunMultiFileProject(mb: memhub.MemBuddy*,
inc_fail_flags[si_inc] = 0
# 依赖填充只在第一遍执行(PopulateIncludesDeps 内部有去重)
# 注意:必须在 reset_to(mark2) 之前调用——内部深拷贝到 stdlib
if pass_inc_i == 0 and tr_inc_pre._imported_modules is not None \
and StubMergerStore.PopulateIncludesDeps(
if pass_inc_i == 0 and tr_inc_pre._imported_modules is not None and StubMergerStore.PopulateIncludesDeps(
inc_sha1_pre, tr_inc_pre._imported_modules) == 0:
deps_filled_pre = deps_filled_pre + 1
# OOM 清理:回收本 includes 文件预注册翻译的瞬时数据