refactor(TransPyV): 统一自举写法(novirtual / define / rawptr→* / 去续行反斜杠)

- @t.NoVTable class X → novirtual class X
- t.CDefine = N → define N
- rawptr[X]、X | t.CPtr → X*
- t.CPtr → rawptr(裸指针标记)
- t.Callable[...] → callable[...]
- 去掉 if/elif 条件的行续反斜杠(改单行写法)
- w32.win32file.X → win32file.X(已 import as)
- core/__init__.vp 去掉未使用的 import t, c / from stdint import *

涉及:CompilerFactory、IncludesScanner、Repl、core/__init__、
Gen/Call/{CallGenBase,CallGenCBuiltin,CallGenCall,CallGenDispatch,CallGenLeafKit}、
Gen/Class/ClassGenGeneric。
This commit is contained in:
TermiNexus committed 2026-10-02 02:16:37 +08:00
1 parent 7e82ed6940
commit 1ad7abf33d
10 files changed
+156 -223

No files matched your search

+14 -28
View File
@@ -586,8 +586,7 @@ novirtual class CallGenDispatch(CallGenBase.CallGenBase):
# 兜底:TypeGenBase 上下文为空时(模板 tp_names 跨 phase 失效),
# 直接用 trans 的泛型映射替换 T(list[int] 单态化 _list.vp
# T.__sizeof__ 根因)。
if string.strcmp(sz_cls_name, sz_orig) == 0 and trans is not None \
and trans.GenericTypeParamNames is not None and trans.GenericTypeArgs is not None:
if string.strcmp(sz_cls_name, sz_orig) == 0 and trans is not None and trans.GenericTypeParamNames is not None and trans.GenericTypeArgs is not None:
gp_n: sizet = len(trans.GenericTypeParamNames)
gp_i: sizet
for gp_i in range(gp_n):
@@ -1006,8 +1005,7 @@ novirtual class CallGenDispatch(CallGenBase.CallGenBase):
# 类型落空(实况:CallGenLib.vp:355 `vk_a: int = val.Ty.kind()` 报
# 「指针隐式转整数已禁止」)。
if rk_cls is not None:
if self.Gen.ClassGenEnum._is_renum_class_name(rk_cls) != 0 \
or self.Gen.ClassGenEnum._is_renum_by_entry(rk_cls) != 0:
if self.Gen.ClassGenEnum._is_renum_class_name(rk_cls) != 0 or self.Gen.ClassGenEnum._is_renum_by_entry(rk_cls) != 0:
rk_is_rn = 1
else:
rk_cls = None
@@ -1045,8 +1043,7 @@ novirtual class CallGenDispatch(CallGenBase.CallGenBase):
else:
rk_cls = rk_ab
# 判据同上(表 或 struct 带 __tag),不再只认变体表
if self.Gen.ClassGenEnum._is_renum_class_name(rk_cls) != 0 \
or self.Gen.ClassGenEnum._is_renum_by_entry(rk_cls) != 0:
if self.Gen.ClassGenEnum._is_renum_class_name(rk_cls) != 0 or self.Gen.ClassGenEnum._is_renum_by_entry(rk_cls) != 0:
rk_is_rn = 1
# 第 2 层:按类名取 struct 的 __tag 声明类型
rk_st_b: llvmlite.LLVMType* = self.Gen.StructGen.get_struct_type(rk_cls)
@@ -1063,19 +1060,16 @@ novirtual class CallGenDispatch(CallGenBase.CallGenBase):
# 一层)→ pointee 类名 → 再走 表/__tag 判据。
# CallGenLib.vp:355 `vk_a: int = val.Ty.kind()` 正是此形态:
# Value.Ty 声明为 `rawptr[LLVMType]`(__values.vp:22)。
if rk_is_rn == 0 and rk_at.value is not None \
and rk_at.value.kind() == ast.ASTKind.Attribute and trans is not None:
if rk_is_rn == 0 and rk_at.value is not None and rk_at.value.kind() == ast.ASTKind.Attribute and trans is not None:
rk_bat: ast.Attribute* = ast.Attribute*(rk_at.value)
if rk_bat is not None and rk_bat.attr is not None and rk_bat.value is not None \
and rk_bat.value.kind() == ast.ASTKind.Name:
if rk_bat is not None and rk_bat.attr is not None and rk_bat.value is not None and rk_bat.value.kind() == ast.ASTKind.Name:
rk_bnm: ast.Name* = ast.Name*(rk_bat.value)
if rk_bnm.id is not None:
rk_bve: GenTypes.VarEntry* = self.Gen.VarGen.lookup_var_entry(trans.SymTab, rk_bnm.id)
rk_bannot: str = self.Gen.VarGen.var_annot_class_name(rk_bve)
if rk_bannot is not None:
rk_blen: sizet = 0
while rk_bannot[rk_blen] != '\0' and rk_bannot[rk_blen] != ' ' \
and rk_bannot[rk_blen] != '|' and rk_bannot[rk_blen] != '[':
while rk_bannot[rk_blen] != '\0' and rk_bannot[rk_blen] != ' ' and rk_bannot[rk_blen] != '|' and rk_bannot[rk_blen] != '[':
rk_blen += 1
rk_bbuf: str = pool.alloc(rk_blen + 1)
if rk_bbuf is not None:
@@ -1093,14 +1087,12 @@ novirtual class CallGenDispatch(CallGenBase.CallGenBase):
rk_fpt: llvmlite.LLVMType* = rk_bfe.Ty
if self.Gen.ExprGenBase.is_ptr_type(rk_fpt) != 0:
rk_fpt = rk_fpt.Pointee
if rk_fpt is not None \
and self.Gen.ExprGenBase.is_ptr_type(rk_fpt) != 0:
if rk_fpt is not None and self.Gen.ExprGenBase.is_ptr_type(rk_fpt) != 0:
rk_fpt = rk_fpt.Pointee
if rk_fpt is not None:
rk_fcls: str = self.Gen.StructGen.get_class_name_by_type(pool, rk_fpt)
if rk_fcls is not None:
if self.Gen.ClassGenEnum._is_renum_class_name(rk_fcls) != 0 \
or self.Gen.ClassGenEnum._is_renum_by_entry(rk_fcls) != 0:
if self.Gen.ClassGenEnum._is_renum_class_name(rk_fcls) != 0 or self.Gen.ClassGenEnum._is_renum_by_entry(rk_fcls) != 0:
rk_is_rn = 1
rk_cls = rk_fcls
rk_ffe: GenTypes.FieldEntry* = self.Gen.StructGen.lookup_field(rk_fpt, "__tag")
@@ -1148,8 +1140,7 @@ novirtual class CallGenDispatch(CallGenBase.CallGenBase):
st_nm: ast.Name* = ast.Name*(st_at.value)
if st_nm.id is not None:
st_var: llvmlite.Value* = self.Gen.VarGen.lookup_var(trans.SymTab, st_nm.id)
if st_var is None and self.Gen.StructGen.get_struct_type(st_nm.id) is not None \
and self.Gen.ImportsGen.is_module_imported(trans._imported_modules, st_nm.id) == 0:
if st_var is None and self.Gen.StructGen.get_struct_type(st_nm.id) is not None and self.Gen.ImportsGen.is_module_imported(trans._imported_modules, st_nm.id) == 0:
# REnum 变体构造优先于静态/类方法调用:
if self.Gen.ClassGenEnum._is_renum_class_name(st_nm.id) != 0:
rc_tag_sc: int = self.Gen.ClassGenEnum._lookup_renum_variant_in_class(st_nm.id, func_name)
@@ -1480,8 +1471,7 @@ novirtual class CallGenDispatch(CallGenBase.CallGenBase):
if expr_root is not None and expr_root.kind() == ast.ASTKind.Name:
expr_root_nm: str = ast.Name*(expr_root).id
if expr_root_nm is not None:
if string.strcmp(expr_root_nm, "t") == 0 or \
string.strcmp(expr_root_nm, "c") == 0:
if string.strcmp(expr_root_nm, "t") == 0 or string.strcmp(expr_root_nm, "c") == 0:
is_mod_path_expr = 1
elif trans._imported_modules is not None:
if self.Gen.ImportsGen.is_module_imported(trans._imported_modules, expr_root_nm) != 0:
@@ -1494,8 +1484,7 @@ novirtual class CallGenDispatch(CallGenBase.CallGenBase):
# 递归解 Ptr:识别 X|t.CPtr 联合简化的 Ptr(Ptr(Struct))
# (如 (a*2.0 - b) 中 __mul__ 返回 Vec3**),否则方法
# 调用被当裸函数 @dot 解析 → 链接 undefined symbol
expr_struct_ty: llvmlite.LLVMType* = \
self.Gen.StructGen.get_struct_type_from_value(expr_obj)
expr_struct_ty: llvmlite.LLVMType* = self.Gen.StructGen.get_struct_type_from_value(expr_obj)
if expr_struct_ty is not None:
expr_cls_nm = self.Gen.StructGen.get_class_name_by_type(pool, expr_struct_ty)
# 回退:LLVM 类型为 Ptr(i8)(方法返回 X|t.CPtr 无类型信息)时,
@@ -1632,8 +1621,7 @@ novirtual class CallGenDispatch(CallGenBase.CallGenBase):
# 普通类未注册场景)跳过本分支,避免按 list 布局 GEP 生成
# 错误 IR(dict 的 get 被当 list.get 按 __data__/__elem_size__
# 偏移读写垃圾)。
lm_conf_ty: llvmlite.LLVMType* = \
self.Gen.StructGen.get_struct_type_from_value(lm_obj)
lm_conf_ty: llvmlite.LLVMType* = self.Gen.StructGen.get_struct_type_from_value(lm_obj)
lm_conf_nm: str = None
if lm_conf_ty is not None:
lm_conf_nm = llvmlite.get_struct_name(lm_conf_ty)
@@ -1641,8 +1629,7 @@ novirtual class CallGenDispatch(CallGenBase.CallGenBase):
# 前缀(如 "e94ef9e139461915.list[ast.ASTptr]");SpecTypeNameBaseIs
# 会去前缀、截断泛型实参后精确比 "list"(原 strstr 子串会误命中
# playlist 之类的类名)。
if lm_conf_nm is not None and \
TSpec.SpecTypeNameBaseIs(lm_conf_nm, "list") == 0:
if lm_conf_nm is not None and TSpec.SpecTypeNameBaseIs(lm_conf_nm, "list") == 0:
return None
# list 内置分支命中标记:void 方法(set/clear)成功处理后返回
# None,必须置位 hit_box 区分"已识别为 list 方法路径",否则
@@ -1662,8 +1649,7 @@ novirtual class CallGenDispatch(CallGenBase.CallGenBase):
# pop 读回 0 → ListTest "pop FAILED expect 30" 根因。
# subscript 路径(list_getitem_inline 调用方)已用
# _list_elem_type_from_name 修正,方法调用路径漏改。
lm_esty: llvmlite.LLVMType* = \
self.Gen.StructGen.get_struct_type_from_value(lm_obj)
lm_esty: llvmlite.LLVMType* = self.Gen.StructGen.get_struct_type_from_value(lm_obj)
lm_ename: str = None
if lm_esty is not None:
lm_ename = llvmlite.get_struct_name(lm_esty)