refactor(tpv): 迁移新语法 R1/R2/R7/R8/R3/R4/R5(指针 T*、短别名、define、&/*、__asm__)

按 wiki/新规范:
- T | t.CPtr → T*(无 | 标准)
- t.CInt/t.CUInt64T/t.CChar/t.CDouble 等 → int/uint64/char/double 等短别名
- X: t.CDefine = Y → define X = Y
- c.Asm → __asm__,c.AsmInp/c.AsmOut → asminp/asmout,t.ASM_DESCR. → ASM_DESCR.
- c.Addr(x) → &x,c.Deref(p) → *p,c.DerefAs(p, v) → *p = v

种子自举通过(96s)。
This commit is contained in:
TermiNexus committed 2026-10-04 22:49:01 +08:00
1 parent 9717ce0107
commit 185a2196ca
57 files changed
+1078 -1078

No files matched your search

+24 -24
View File
@@ -88,75 +88,75 @@ def Load_project_config(path: str) -> int:
if bytes_read <= 0: return 1
# 解析 JSON
root: JsonValue | t.CPtr = json_parse(_mbuddy, buf)
root: JsonValue* = json_parse(_mbuddy, buf)
if root is None: return 1
if not root.is_object(): return 1
# 读取顶层字段(使用显式 __getitem__ 调用,兼容旧编译器二进制)
sd_val: JsonValue | t.CPtr = root["source_dir"]
sd_val: JsonValue* = root["source_dir"]
SourceDir = sd_val.as_string() if sd_val is not None else None
# build_dir: 统一构建目录(默认 ./.tpv_build),temp 和 output 作为其子目录
bd_val: JsonValue | t.CPtr = root["build_dir"]
bd_val: JsonValue* = root["build_dir"]
if bd_val is not None and bd_val.is_string():
BuildDir = bd_val.as_string()
else:
BuildDir = "./.tpv_build"
name_val: JsonValue | t.CPtr = root["name"]
name_val: JsonValue* = root["name"]
ProjectName = name_val.as_string() if name_val is not None else None
ver_val: JsonValue | t.CPtr = root["version"]
ver_val: JsonValue* = root["version"]
ProjectVersion = ver_val.as_string() if ver_val is not None else None
# 读取 compiler 子对象
compiler: JsonValue | t.CPtr = root["compiler"]
compiler: JsonValue* = root["compiler"]
if compiler is not None and compiler.is_object():
cc_cmd_val: JsonValue | t.CPtr = compiler["cmd"]
cc_cmd_val: JsonValue* = compiler["cmd"]
CompilerCmd = cc_cmd_val.as_string() if cc_cmd_val is not None else None
# 读取 compiler.flags 数组,拼接成空格分隔的字符串
cc_flags_val: JsonValue | t.CPtr = compiler["flags"]
cc_flags_val: JsonValue* = compiler["flags"]
CompilerFlags = _join_flags_array(cc_flags_val)
# 读取 linker 子对象
linker: JsonValue | t.CPtr = root["linker"]
linker: JsonValue* = root["linker"]
if linker is not None and linker.is_object():
ld_cmd_val: JsonValue | t.CPtr = linker["cmd"]
ld_cmd_val: JsonValue* = linker["cmd"]
LinkerCmd = ld_cmd_val.as_string() if ld_cmd_val is not None else None
ld_out_val: JsonValue | t.CPtr = linker["output"]
ld_out_val: JsonValue* = linker["output"]
LinkerOutput = ld_out_val.as_string() if ld_out_val is not None else None
# 读取 linker.flags 数组,拼接成空格分隔的字符串
ld_flags_val: JsonValue | t.CPtr = linker["flags"]
ld_flags_val: JsonValue* = linker["flags"]
LinkerFlags = _join_flags_array(ld_flags_val)
# 读取 linker.static_libs 数组:显式静态链接文件(.a/.obj),
# 先拼接原样字符串,resolve_paths 中再基于 project_dir 解析绝对路径
sl_val: JsonValue | t.CPtr = linker["static_libs"]
sl_val: JsonValue* = linker["static_libs"]
LinkerStaticLibs = _join_flags_array(sl_val)
# 读取 linker.dynamic_libs 数组:显式动态链接文件(.dll/.so),
# 同样先拼接原样字符串,resolve_paths 中基于 project_dir 解析绝对路径
dl_val: JsonValue | t.CPtr = linker["dynamic_libs"]
dl_val: JsonValue* = linker["dynamic_libs"]
LinkerDynamicLibs = _join_flags_array(dl_val)
# 读取 target 子对象
target: JsonValue | t.CPtr = root["target"]
target: JsonValue* = root["target"]
if target is not None and target.is_object():
tgt_triple_val: JsonValue | t.CPtr = target["triple"]
tgt_triple_val: JsonValue* = target["triple"]
TargetTriple = tgt_triple_val.as_string() if tgt_triple_val is not None else None
tgt_dl_val: JsonValue | t.CPtr = target["datalayout"]
tgt_dl_val: JsonValue* = target["datalayout"]
TargetDataLayout = tgt_dl_val.as_string() if tgt_dl_val is not None else None
# 读取 options 子对象
# Sha1SliceLevel: SHA1 切片层数(默认 1,每层取 SHA1 前 2 字符作为子目录:0=不切片, 1=b7/, 2=b7/90/)
options: JsonValue | t.CPtr = root["options"]
options: JsonValue* = root["options"]
Sha1SliceLevel = 1
StrictMode = 1
if options is not None and options.is_object():
sl: JsonValue | t.CPtr = options["sha1_slice_level"]
sl: JsonValue* = options["sha1_slice_level"]
if sl is not None and sl.is_int():
Sha1SliceLevel = sl.as_int()
sm: JsonValue | t.CPtr = options["strict_mode"]
sm: JsonValue* = options["strict_mode"]
if sm is not None and sm.is_bool():
StrictMode = 1 if sm.as_bool() else 0
# 读取 includes 数组(支持多目录:首元素存 IncludesDir,全部拼接存 IncludesDirs)
includes_val: JsonValue | t.CPtr = root["includes"]
includes_val: JsonValue* = root["includes"]
if includes_val is not None and includes_val.is_array():
arr_len: sizet = len(includes_val)
inc_buf: bytes = stdlib.malloc(2048)
@@ -164,7 +164,7 @@ def Load_project_config(path: str) -> int:
inc_buf[0] = '\0'
inc_pos: sizet = 0
for inc_i in range(arr_len):
inc_item: JsonValue | t.CPtr = includes_val.get_item(inc_i)
inc_item: JsonValue* = includes_val.get_item(inc_i)
if inc_item is None or not inc_item.is_string():
continue
inc_str: str = inc_item.as_string()
@@ -186,7 +186,7 @@ def Load_project_config(path: str) -> int:
return 0
def _join_flags_array(flags_val: JsonValue | t.CPtr) -> str:
def _join_flags_array(flags_val: JsonValue*) -> str:
"""将 JSON 字符串数组拼接成空格分隔的字符串
用于 linker.flags 和 compiler.flags 数组。
@@ -208,7 +208,7 @@ def _join_flags_array(flags_val: JsonValue | t.CPtr) -> str:
# 第一遍:计算总长度(所有 flag 长度 + 空格分隔符)
total_len: sizet = 0
for i in range(arr_len):
item: JsonValue | t.CPtr = flags_val.get_item(i)
item: JsonValue* = flags_val.get_item(i)
if item is not None and item.is_string():
s: str = item.as_string()
if s is not None:
+1 -1
View File
@@ -207,7 +207,7 @@ def CleanDir(dir_path: str) -> int:
return -1
viperlib.snprintf(pattern, dir_len + 8, "%s/*", dir_path)
find_data: w32.win32file.WIN32_FIND_DATAA | t.CPtr = stdlib.malloc(w32.win32file.WIN32_FIND_DATAA.__sizeof__())
find_data: w32.win32file.WIN32_FIND_DATAA* = stdlib.malloc(w32.win32file.WIN32_FIND_DATAA.__sizeof__())
if find_data is None:
stdlib.free(pattern)
return -1