初步清理 t. 类型异味

This commit is contained in:
TermiNexus committed 2026-09-11 18:36:32 +08:00
1 parent 4ce55e3ea3
commit cfb92e5da5
84 files changed
+7769 -7907

No files matched your search

+63 -63
View File
@@ -57,36 +57,36 @@ class ClassGenBase:
# --- REnum 变体表(原 _renum_class_names/_renum_class_variant_counts/
# _renum_variant_names/_renum_variant_tags/_renum_class_count) ---
RenumClassNames: t.CSizeT | t.CPtr
RenumClassVariantCounts: t.CSizeT | t.CPtr
RenumVariantNames: t.CSizeT | t.CPtr
RenumVariantTags: t.CSizeT | t.CPtr
RenumClassNames: sizet | t.CPtr
RenumClassVariantCounts: sizet | t.CPtr
RenumVariantNames: sizet | t.CPtr
RenumVariantTags: sizet | t.CPtr
RenumClassCount: int
# --- REnum 字段别名表(原 _renum_alias_class/_renum_alias_field/
# _renum_alias_index/_renum_alias_count) ---
RenumAliasClass: t.CSizeT | t.CPtr
RenumAliasField: t.CSizeT | t.CPtr
RenumAliasIndex: t.CSizeT | t.CPtr
RenumAliasClass: sizet | t.CPtr
RenumAliasField: sizet | t.CPtr
RenumAliasIndex: sizet | t.CPtr
# 变体成员实际 LLVM 类型(对齐 TPC class_members):注册时按注解解析,
# perm_pool 深拷贝持久化。match 绑定用真实成员类型 bitcast 槽位地址
# (Struct.Name: i8*,否则按槽位 i64 读 → is/subscript/strlen 失败)。
RenumAliasTy: t.CSizeT | t.CPtr
RenumAliasTy: sizet | t.CPtr
# 别名所属变体名(perm_pool 拷贝):同一 payload 位置跨变体类型不同
# (Int.Bits=i32 vs Struct.Fields=Ptr),match 绑定按 (class, 变体, 位置)
# 唯一定位成员类型。
RenumAliasVariant: t.CSizeT | t.CPtr
RenumAliasVariant: sizet | t.CPtr
RenumAliasCount: int
# --- 泛型特化缓存(原 _spec_keys/_spec_names/_spec_count) ---
SpecKeys: t.CSizeT | t.CPtr
SpecNames: t.CSizeT | t.CPtr
SpecKeys: sizet | t.CPtr
SpecNames: sizet | t.CPtr
SpecCount: int
# --- 类编译期元数据表(__provides__/__requires__/__require_must__) ---
# perm_pool 分配(跨 mark/reset 存活):每槽 kind(4B) + cls(64B) + field(64B)
# FakeDuck:_str.__requires__=['__mbuddy__'] 等(FakeDuck 移植点 1)
ClassMetaKinds: t.CInt | t.CPtr
ClassMetaKinds: int | t.CPtr
ClassMetaClss: bytes
ClassMetaFields: bytes
ClassMetaCount: int
@@ -100,7 +100,7 @@ class ClassGenBase:
DecoratorFuncNames: bytes
DecoratorWrapNames: bytes
# 装饰器首个常量参数(@repeat(3) 的 3),无参数为 0(每槽 8B,i64)
DecoratorArgs: t.CInt64T | t.CPtr
DecoratorArgs: int64 | t.CPtr
# --- 异常类注册表(try-except,对齐 TPC HandlesClassDef.py L47-61) ---
# perm_pool 分配(跨 mark/reset 存活):每槽类名(128B) + 父类名(128B) + 编码(4B)
@@ -109,7 +109,7 @@ class ClassGenBase:
ExceptionCount: int
ExceptionNames: bytes
ExceptionParents: bytes
ExceptionCodes: t.CInt | t.CPtr
ExceptionCodes: int | t.CPtr
# 下一个待分配的异常编码(用户类,从 100 起)
NextExceptionCode: int
# 递归收集子孙编码用的临时计数(collect_descendant_codes 返回后无效)。
@@ -138,13 +138,13 @@ class ClassGenBase:
# 可能失效(VectorGenericTest 特化 Vector[int].__init__ 的 T.__sizeof__()
# NameError 根因方向);注册时展平深拷贝到 stdlib,特化时从本表恢复。
# 每槽指向一个空格分隔、NUL 结尾的 stdlib 缓冲区(如 "T" 或 "T K")。
GenericClassTpParams: t.CSizeT | t.CPtr
GenericClassTpParams: sizet | t.CPtr
# --- vtable 方法收集表(原 _g_vt_full_names/_g_vt_method_names/
# _g_vt_parent_sha1s/_g_vt_method_count) ---
VtFullNames: t.CSizeT | t.CPtr
VtMethodNames: t.CSizeT | t.CPtr
VtParentSha1s: t.CSizeT | t.CPtr
VtFullNames: sizet | t.CPtr
VtMethodNames: sizet | t.CPtr
VtParentSha1s: sizet | t.CPtr
VtMethodCount: int
# ============================================================
# 以下方法由 P5-2 分簇迁移填充(函数体来自 HandlesClassDef.vp,
@@ -170,7 +170,7 @@ class ClassGenBase:
alias_orig: str = self.Gen.ImportsGen.lookup_from_import_original(
trans._from_imports, nm.id)
if alias_orig is not None:
og_len_ce: t.CSizeT = 0
og_len_ce: sizet = 0
while alias_orig[og_len_ce] != ' ' and alias_orig[og_len_ce] != '\0':
og_len_ce += 1
if og_len_ce == 5 and string.strncmp(alias_orig, "CEnum", 5) == 0:
@@ -195,7 +195,7 @@ class ClassGenBase:
if cd.bases is None:
return 0
bases: list[ast.AST | t.CPtr] | t.CPtr = cd.bases
bn: t.CSizeT = len(bases)
bn: sizet = len(bases)
if bn == 0:
return 0
for bi in range(bn):
@@ -223,7 +223,7 @@ class ClassGenBase:
alias_orig: str = self.Gen.ImportsGen.lookup_from_import_original(
trans._from_imports, nm.id)
if alias_orig is not None:
og_len_cu: t.CSizeT = 0
og_len_cu: sizet = 0
while alias_orig[og_len_cu] != ' ' and alias_orig[og_len_cu] != '\0':
og_len_cu += 1
if og_len_cu == 6 and string.strncmp(alias_orig, "CUnion", 6) == 0:
@@ -248,7 +248,7 @@ class ClassGenBase:
if cd.bases is None:
return 0
bases: list[ast.AST | t.CPtr] | t.CPtr = cd.bases
bn: t.CSizeT = len(bases)
bn: sizet = len(bases)
if bn == 0:
return 0
for bi in range(bn):
@@ -276,7 +276,7 @@ class ClassGenBase:
alias_orig: str = self.Gen.ImportsGen.lookup_from_import_original(
trans._from_imports, nm.id)
if alias_orig is not None:
og_len_cr: t.CSizeT = 0
og_len_cr: sizet = 0
while alias_orig[og_len_cr] != ' ' and alias_orig[og_len_cr] != '\0':
og_len_cr += 1
if og_len_cr == 5 and string.strncmp(alias_orig, "REnum", 5) == 0:
@@ -301,7 +301,7 @@ class ClassGenBase:
if cd.bases is None:
return 0
bases: list[ast.AST | t.CPtr] | t.CPtr = cd.bases
bn: t.CSizeT = len(bases)
bn: sizet = len(bases)
if bn == 0:
return 0
for bi in range(bn):
@@ -316,7 +316,7 @@ class ClassGenBase:
"""检查 decorator_list 中是否有指定装饰器名"""
if decorator_list is None:
return 0
dn: t.CSizeT = len(decorator_list)
dn: sizet = len(decorator_list)
if dn == 0:
return 0
for di in range(dn):
@@ -366,7 +366,7 @@ class ClassGenBase:
"""
if decorator_list is None:
return 0
dn: t.CSizeT = len(decorator_list)
dn: sizet = len(decorator_list)
if dn == 0:
return 0
for di in range(dn):
@@ -384,7 +384,7 @@ class ClassGenBase:
continue
if cl.args is None:
continue
an: t.CSizeT = len(cl.args)
an: sizet = len(cl.args)
for ai in range(an):
ag: ast.AST | t.CPtr = cl.args.get(ai)
if ag is not None and self._tattr_name(ag, attr_name) != 0:
@@ -419,7 +419,7 @@ class ClassGenBase:
"""取 @c.Attribute(t.attr.aligned(N)) 的对齐字节数,无 aligned 返回 0"""
if decorator_list is None:
return 0
dn: t.CSizeT = len(decorator_list)
dn: sizet = len(decorator_list)
if dn == 0:
return 0
for di in range(dn):
@@ -435,7 +435,7 @@ class ClassGenBase:
continue
if cl.args is None:
continue
an: t.CSizeT = len(cl.args)
an: sizet = len(cl.args)
for ai in range(an):
ag: ast.AST | t.CPtr = cl.args.get(ai)
if ag is not None:
@@ -452,7 +452,7 @@ class ClassGenBase:
meta: int = 0
if decorator_list is None:
return meta
dn: t.CSizeT = len(decorator_list)
dn: sizet = len(decorator_list)
if dn == 0:
return meta
for di in range(dn):
@@ -517,7 +517,7 @@ class ClassGenBase:
if string.strcmp(self.ClassMetaClss + i * 64, cls) == 0:
if string.strcmp(self.ClassMetaFields + i * 64, field) == 0:
return 0
idx_cm: t.CSizeT = t.CSizeT(self.ClassMetaCount) * 64
idx_cm: sizet = sizet(self.ClassMetaCount) * 64
self.ClassMetaKinds[self.ClassMetaCount] = kind
string.strncpy(self.ClassMetaClss + idx_cm, cls, 63)
self.ClassMetaClss[idx_cm + 63] = '\0'
@@ -549,7 +549,7 @@ class ClassGenBase:
return None
def register_decorator(self, pool: memhub.MemBuddy | t.CPtr,
func_name: str, wrapper_name: str,
arg0: t.CInt64T) -> int:
arg0: int64) -> int:
"""注册自定义装饰器函数(@log/@skip/@repeat(3) → __decor_wrap_{name})
对齐 TPC HandlesFunctions.py L1621-1631 的 _decorated_funcs 注册。
@@ -577,7 +577,7 @@ class ClassGenBase:
for i in range(self.DecoratorFuncCount):
if string.strcmp(self.DecoratorFuncNames + i * DECOR_NAME_LEN, func_name) == 0:
return 0
idx_dc: t.CSizeT = t.CSizeT(self.DecoratorFuncCount) * DECOR_NAME_LEN
idx_dc: sizet = sizet(self.DecoratorFuncCount) * DECOR_NAME_LEN
string.strncpy(self.DecoratorFuncNames + idx_dc, func_name, DECOR_NAME_LEN - 1)
self.DecoratorFuncNames[idx_dc + DECOR_NAME_LEN - 1] = '\0'
string.strncpy(self.DecoratorWrapNames + idx_dc, wrapper_name, DECOR_NAME_LEN - 1)
@@ -593,7 +593,7 @@ class ClassGenBase:
if string.strcmp(self.DecoratorFuncNames + i * DECOR_NAME_LEN, func_name) == 0:
return self.DecoratorWrapNames + i * DECOR_NAME_LEN
return None
def lookup_decor_arg0(self, func_name: str) -> t.CInt64T:
def lookup_decor_arg0(self, func_name: str) -> int64:
"""按原函数名查装饰器首个常量参数(无参数为 0)"""
if self.DecoratorFuncNames is None or func_name is None:
return 0
@@ -635,7 +635,7 @@ class ClassGenBase:
return self.ExceptionCodes[i]
if self.ExceptionCount >= EXCEPTION_MAX:
return -1
idx_e: t.CSizeT = t.CSizeT(self.ExceptionCount) * EXCEPTION_NAME_LEN
idx_e: sizet = sizet(self.ExceptionCount) * EXCEPTION_NAME_LEN
string.strncpy(self.ExceptionNames + idx_e, class_name, EXCEPTION_NAME_LEN - 1)
self.ExceptionNames[idx_e + EXCEPTION_NAME_LEN - 1] = '\0'
if parent_name is not None:
@@ -697,7 +697,7 @@ class ClassGenBase:
if string.strcmp(self.ExceptionNames + i * EXCEPTION_NAME_LEN, name) == 0:
return 1
return 0
def collect_descendant_codes(self, name: str, out_codes: t.CInt | t.CPtr,
def collect_descendant_codes(self, name: str, out_codes: int | t.CPtr,
max_codes: int) -> int:
"""把 name 及其所有子孙异常类的编码收集到 out_codes,返回数量
(对齐 TPC HandlesTry.py _get_all_match_codes/_collect_descendant_codes:
@@ -707,7 +707,7 @@ class ClassGenBase:
self._exception_codes_tmp_count = 0
self._collect_desc_codes_rec(name, out_codes, max_codes, 0)
return self._exception_codes_tmp_count
def _collect_desc_codes_rec(self, name: str, out_codes: t.CInt | t.CPtr,
def _collect_desc_codes_rec(self, name: str, out_codes: int | t.CPtr,
max_codes: int, depth: int) -> None:
"""递归收集 name 编码 + 全部子孙编码(BFS 语义对齐 TPC)"""
if depth > 32:
@@ -737,7 +737,7 @@ class ClassGenBase:
if cd is None or cd.bases is None:
return 0
bases_e: list[ast.AST | t.CPtr] | t.CPtr = cd.bases
bn_e: t.CSizeT = len(bases_e)
bn_e: sizet = len(bases_e)
for bi_e in range(bn_e):
base_e: ast.AST | t.CPtr = bases_e.get(bi_e)
if base_e is None:
@@ -761,7 +761,7 @@ class ClassGenBase:
if cd is None or cd.bases is None:
return None
bases_e2: list[ast.AST | t.CPtr] | t.CPtr = cd.bases
bn_e2: t.CSizeT = len(bases_e2)
bn_e2: sizet = len(bases_e2)
for bi_e2 in range(bn_e2):
base_e2: ast.AST | t.CPtr = bases_e2.get(bi_e2)
if base_e2 is None:
@@ -798,7 +798,7 @@ class ClassGenBase:
if lst_rcm.elts is None:
return
elts_rcm: list[ast.AST | t.CPtr] | t.CPtr = lst_rcm.elts
en_rcm: t.CSizeT = len(elts_rcm)
en_rcm: sizet = len(elts_rcm)
for ei_rcm in range(en_rcm):
el_rcm: ast.AST | t.CPtr = elts_rcm.get(ei_rcm)
if el_rcm is None or el_rcm.kind() != ast.ASTKind.Constant:
@@ -820,8 +820,8 @@ class ClassGenBase:
string.memset(self.MethodMetaKeys, 0, META_MAX * META_KEY_LEN)
string.memset(self.MethodMetaFlags, 0, META_MAX * 4)
# 构造 key "ClassName.method"
cl_len: t.CSizeT = string.strlen(class_name)
mn_len: t.CSizeT = string.strlen(method_name)
cl_len: sizet = string.strlen(class_name)
mn_len: sizet = string.strlen(method_name)
key_buf: bytes = stdlib.malloc(cl_len + mn_len + 2)
if key_buf is None:
return
@@ -830,8 +830,8 @@ class ClassGenBase:
i: int
for i in range(self.MethodMetaCount):
if string.strcmp(self.MethodMetaKeys + i * META_KEY_LEN, key_buf) == 0:
flags_ptr: t.CPtr = (t.CInt | t.CPtr)(t.CVoid(
t.CUInt64T(self.MethodMetaFlags) + i * 4, t.CPtr))
flags_ptr: t.CPtr = (int | t.CPtr)(t.CVoid(
uint64(self.MethodMetaFlags) + i * 4, t.CPtr))
# 按位或合并:同一属性名先 @property(getter=4) 再 @x.setter(8)/
# @x.deleter(16) 会多次注册(如 Config.value / Counter.value)。
# 若整值替换,后注册的位会覆盖 GETTER 位 → _try_property_getter_attr
@@ -844,8 +844,8 @@ class ClassGenBase:
# 槽位定长 META_KEY_LEN=128 字节,key 超长时 strncpy 钳制防越界写相邻槽
string.strncpy(self.MethodMetaKeys + self.MethodMetaCount * META_KEY_LEN,
key_buf, META_KEY_LEN - 1)
flags_ptr2: t.CPtr = (t.CInt | t.CPtr)(t.CVoid(
t.CUInt64T(self.MethodMetaFlags) + self.MethodMetaCount * 4, t.CPtr))
flags_ptr2: t.CPtr = (int | t.CPtr)(t.CVoid(
uint64(self.MethodMetaFlags) + self.MethodMetaCount * 4, t.CPtr))
flags_ptr2[0] = meta
self.MethodMetaCount += 1
stdlib.free(key_buf)
@@ -855,8 +855,8 @@ class ClassGenBase:
return 0
if self.MethodMetaKeys is None or self.MethodMetaCount <= 0:
return 0
cl_len: t.CSizeT = string.strlen(class_name)
mn_len: t.CSizeT = string.strlen(method_name)
cl_len: sizet = string.strlen(class_name)
mn_len: sizet = string.strlen(method_name)
key_buf: bytes = stdlib.malloc(cl_len + mn_len + 2)
if key_buf is None:
return 0
@@ -865,8 +865,8 @@ class ClassGenBase:
i: int
for i in range(self.MethodMetaCount):
if string.strcmp(self.MethodMetaKeys + i * META_KEY_LEN, key_buf) == 0:
flags_ptr: t.CPtr = (t.CInt | t.CPtr)(t.CVoid(
t.CUInt64T(self.MethodMetaFlags) + i * 4, t.CPtr))
flags_ptr: t.CPtr = (int | t.CPtr)(t.CVoid(
uint64(self.MethodMetaFlags) + i * 4, t.CPtr))
found = flags_ptr[0]
break
stdlib.free(key_buf)
@@ -944,9 +944,9 @@ class ClassGenBase:
if pool is None:
return base_nm
# 拼接特化名 "GSListNode[Value]"
base_len: t.CSizeT = string.strlen(base_nm)
arg_len: t.CSizeT = string.strlen(arg_nm)
total_len: t.CSizeT = base_len + arg_len + 3 # "[" + arg + "]" + NUL
base_len: sizet = string.strlen(base_nm)
arg_len: sizet = string.strlen(arg_nm)
total_len: sizet = base_len + arg_len + 3 # "[" + arg + "]" + NUL
mangled: str = pool.alloc(total_len)
if mangled is None:
return base_nm # 降级
@@ -966,7 +966,7 @@ class ClassGenBase:
if trans is not None:
pool = trans.Pool
bases: list[ast.AST | t.CPtr] | t.CPtr = cd.bases
bn: t.CSizeT = len(bases)
bn: sizet = len(bases)
if bn == 0:
return None
for bi in range(bn):
@@ -1001,7 +1001,7 @@ class ClassGenBase:
# 复制到独立缓冲并按空格截断出干净原始名——否则 _is_marker_base 的
# strcmp 对整串比较失败 → 别名基类(CStruct as cs)被当真实父类 →
# find_struct 失败 → 整类 defer 永不注册 → 变量注解解析失败。
og_len: t.CSizeT = 0
og_len: sizet = 0
while orig[og_len] != ' ' and orig[og_len] != '\0':
og_len += 1
if og_len > 0:
@@ -1013,14 +1013,14 @@ class ClassGenBase:
return base_name
def _collect_parents(self, pool: memhub.MemBuddy | t.CPtr,
cd: ast.ClassDef | t.CPtr,
parents_buf: t.CSizeT | t.CPtr,
parents_buf: sizet | t.CPtr,
max_parents: int,
trans: HT.Translator | t.CPtr = None) -> int:
"""收集所有非 marker 父类名到 parents_buf,返回数量"""
if pool is None or cd is None or cd.bases is None or parents_buf is None:
return 0
bases: list[ast.AST | t.CPtr] | t.CPtr = cd.bases
bn: t.CSizeT = len(bases)
bn: sizet = len(bases)
count: int = 0
for bi in range(bn):
if count >= max_parents:
@@ -1033,16 +1033,16 @@ class ClassGenBase:
# 基类别名解析(同 _get_parent_class,见 _resolve_base_alias)
bname = self._resolve_base_alias(bname, trans)
if self._is_marker_base(bname) == 0:
parents_buf[count] = t.CSizeT(bname)
parents_buf[count] = sizet(bname)
count += 1
return count
def _field_name_exists(self, names_buf: t.CSizeT | t.CPtr,
def _field_name_exists(self, names_buf: sizet | t.CPtr,
count: int, name: str) -> int:
"""检查字段名是否已在 names_buf 中(先声明父类优先,重复跳过)"""
if names_buf is None or name is None:
return 0
for fi in range(count):
addr: t.CSizeT = names_buf[fi]
addr: sizet = names_buf[fi]
if addr != 0:
existing: str = (str | t.CPtr)(t.CVoid(addr, t.CPtr))
if existing is not None and string.strcmp(existing, name) == 0:
@@ -1052,7 +1052,7 @@ class ClassGenBase:
"""检查类体是否声明了字段(AnnAssign),0=纯方法/无字段类"""
if cd is None or cd.children is None:
return 0
cn: t.CSizeT = len(cd.children)
cn: sizet = len(cd.children)
for ci in range(cn):
stmt: ast.AST | t.CPtr = cd.children.get(ci)
if stmt is None:
@@ -1067,7 +1067,7 @@ class ClassGenBase:
return
pool: memhub.MemBuddy | t.CPtr = trans.Pool
bases: list[ast.AST | t.CPtr] | t.CPtr = cd.bases
bn: t.CSizeT = len(bases)
bn: sizet = len(bases)
if bn == 0:
return
for bi in range(bn):
@@ -1107,7 +1107,7 @@ class ClassGenBase:
if cd is None or cd.children is None:
return 0
children: list[ast.AST | t.CPtr] | t.CPtr = cd.children
cn: t.CSizeT = len(children)
cn: sizet = len(children)
for ci in range(cn):
stmt: ast.AST | t.CPtr = children.get(ci)
if stmt is None:
+27 -27
View File
@@ -111,7 +111,7 @@ class ClassGenDef(ClassGenBase.ClassGenBase):
existing.Ty = ty_deep
old_name: str = llvmlite.get_struct_name(existing.Ty)
if old_name is not None:
on_len: t.CSizeT = string.strlen(old_name)
on_len: sizet = string.strlen(old_name)
on_copy: str = CompilerFactory.factory.PermPool.alloc(on_len + 1)
if on_copy is not None:
string.strcpy(on_copy, old_name)
@@ -155,7 +155,7 @@ class ClassGenDef(ClassGenBase.ClassGenBase):
has_vtable: int = self.Gen.ClassGenBase._detect_vtable_status(cd, trans)
parent_name: str = self.Gen.ClassGenBase._get_parent_class(cd, trans)
# 多继承:收集所有真实父类名(跳过 marker base),供字段展平/vtable/MRO 使用
parents_buf: t.CSizeT | t.CPtr = pool.alloc(8 * GenTypes.PARENT_MAX)
parents_buf: sizet | t.CPtr = pool.alloc(8 * GenTypes.PARENT_MAX)
parents_count: int = 0
if parents_buf is not None:
parents_count = self.Gen.ClassGenBase._collect_parents(pool, cd, parents_buf, GenTypes.PARENT_MAX, trans)
@@ -189,10 +189,10 @@ class ClassGenDef(ClassGenBase.ClassGenBase):
# 1. 遍历 class body,收集字段信息
# ============================================================
# 用 CSizeT 数组存储指针值(64 位系统上 8 字节)
field_names_buf: t.CSizeT | t.CPtr = pool.alloc(8 * GenTypes.FIELD_MAX)
field_types_buf: t.CSizeT | t.CPtr = pool.alloc(8 * GenTypes.FIELD_MAX)
field_defaults_buf: t.CSizeT | t.CPtr = pool.alloc(8 * GenTypes.FIELD_MAX)
field_annot_buf: t.CSizeT | t.CPtr = pool.alloc(8 * GenTypes.FIELD_MAX)
field_names_buf: sizet | t.CPtr = pool.alloc(8 * GenTypes.FIELD_MAX)
field_types_buf: sizet | t.CPtr = pool.alloc(8 * GenTypes.FIELD_MAX)
field_defaults_buf: sizet | t.CPtr = pool.alloc(8 * GenTypes.FIELD_MAX)
field_annot_buf: sizet | t.CPtr = pool.alloc(8 * GenTypes.FIELD_MAX)
if field_names_buf is None or field_types_buf is None or field_defaults_buf is None:
return 0
if field_annot_buf is None:
@@ -215,7 +215,7 @@ class ClassGenDef(ClassGenBase.ClassGenBase):
# 多继承字段展平:遍历所有父类(声明顺序),字段名去重(先声明优先)
if parents_count > 0 and parents_buf is not None:
for pi in range(parents_count):
pname_addr: t.CSizeT = parents_buf[pi]
pname_addr: sizet = parents_buf[pi]
if pname_addr == 0:
continue
pname: str = (str | t.CPtr)(t.CVoid(pname_addr, t.CPtr))
@@ -270,14 +270,14 @@ class ClassGenDef(ClassGenBase.ClassGenBase):
pft: llvmlite.LLVMType | t.CPtr = self.Gen.StructGen.get_field_type_ptr(pfe)
pfd: ast.AST | t.CPtr = self.Gen.StructGen.get_field_default_ptr(pfe)
pfa: str = self.Gen.StructGen.get_field_annot_class_name(pfe)
field_names_buf[field_count] = t.CSizeT(pfn)
field_types_buf[field_count] = t.CSizeT(pft)
field_names_buf[field_count] = sizet(pfn)
field_types_buf[field_count] = sizet(pft)
if pfd is not None:
field_defaults_buf[field_count] = t.CSizeT(pfd)
field_defaults_buf[field_count] = sizet(pfd)
else:
field_defaults_buf[field_count] = 0
if pfa is not None:
stored_val: t.CSizeT = t.CSizeT(pfa)
stored_val: sizet = sizet(pfa)
field_annot_buf[field_count] = stored_val
else:
field_annot_buf[field_count] = 0
@@ -287,7 +287,7 @@ class ClassGenDef(ClassGenBase.ClassGenBase):
if children is None:
return 0
cn: t.CSizeT = len(children)
cn: sizet = len(children)
for ci in range(cn):
stmt: ast.AST | t.CPtr = children.get(ci)
if stmt is None:
@@ -323,10 +323,10 @@ class ClassGenDef(ClassGenBase.ClassGenBase):
if field_count < GenTypes.FIELD_MAX:
cdef_ty_l: llvmlite.LLVMType | t.CPtr = llvmlite.Int32(pool)
if cdef_ty_l is not None:
field_names_buf[field_count] = t.CSizeT(tgt.id)
field_types_buf[field_count] = t.CSizeT(cdef_ty_l)
field_names_buf[field_count] = sizet(tgt.id)
field_types_buf[field_count] = sizet(cdef_ty_l)
if aa.value is not None:
field_defaults_buf[field_count] = t.CSizeT(aa.value)
field_defaults_buf[field_count] = sizet(aa.value)
else:
field_defaults_buf[field_count] = 0
field_count += 1
@@ -421,12 +421,12 @@ class ClassGenDef(ClassGenBase.ClassGenBase):
# 存储到数组(指针转 CSizeT)
if field_count < GenTypes.FIELD_MAX:
diag_name_val: t.CSizeT = t.CSizeT(tgt.id)
diag_name_val: sizet = sizet(tgt.id)
field_names_buf[field_count] = diag_name_val
field_types_buf[field_count] = t.CSizeT(field_ty)
field_types_buf[field_count] = sizet(field_ty)
# 存储默认值 AST 指针(None=无默认值)
if aa.value is not None:
field_defaults_buf[field_count] = t.CSizeT(aa.value)
field_defaults_buf[field_count] = sizet(aa.value)
else:
field_defaults_buf[field_count] = 0
# 提取原始类型注解的类名(联合类型简化为 Ptr(i8) 时回退查找结构体)
@@ -435,7 +435,7 @@ class ClassGenDef(ClassGenBase.ClassGenBase):
annot_cn: str = self.Gen.TypeGenResolve.extract_class_name_from_annotation(
aa.annotation, trans._imported_modules, pool, trans._from_imports)
if annot_cn is not None:
diag_cn_val: t.CSizeT = t.CSizeT(annot_cn)
diag_cn_val: sizet = sizet(annot_cn)
field_annot_buf[field_count] = diag_cn_val
else:
field_annot_buf[field_count] = 0
@@ -475,7 +475,7 @@ class ClassGenDef(ClassGenBase.ClassGenBase):
total_field_count = field_count + 1
for fi in range(field_count):
fty_addr: t.CSizeT = field_types_buf[fi]
fty_addr: sizet = field_types_buf[fi]
if fty_addr == 0:
continue
fty: llvmlite.LLVMType | t.CPtr = (llvmlite.LLVMType | t.CPtr)(t.CVoid(fty_addr, t.CPtr))
@@ -504,7 +504,7 @@ class ClassGenDef(ClassGenBase.ClassGenBase):
viperlib.snprintf(name_buf, 64, "%s.%s", trans.ModuleSha1, class_name)
type_name = name_buf
if trans._declare_only == 0 and type_name is not None:
tn_len: t.CSizeT = string.strlen(type_name)
tn_len: sizet = string.strlen(type_name)
tn_copy: str = CompilerFactory.factory.PermPool.alloc(tn_len + 1)
if tn_copy is not None:
string.strcpy(tn_copy, type_name)
@@ -546,7 +546,7 @@ class ClassGenDef(ClassGenBase.ClassGenBase):
# 扫描字段类型,为跨模块结构体引用添加 opaque 声明
# 例如 list[int].__pool__ 引用 memhub.MemManager,需要在当前模块添加 %"sha1.MemManager" = type opaque
for fi in range(field_count):
fty_addr_op: t.CSizeT = field_types_buf[fi]
fty_addr_op: sizet = field_types_buf[fi]
if fty_addr_op == 0:
continue
fty_op: llvmlite.LLVMType | t.CPtr = (llvmlite.LLVMType | t.CPtr)(t.CVoid(fty_addr_op, t.CPtr))
@@ -580,7 +580,7 @@ class ClassGenDef(ClassGenBase.ClassGenBase):
# _translate_oop_methods/_detect_vtable_status 会在后续文件
# find_struct(ParentName) strcmp 解引用 → 用 stdlib 拷贝保证跨文件存活
if self.Gen.StructGen.get_stdlib_alloc() != 0:
pn_len: t.CSizeT = string.strlen(parent_name)
pn_len: sizet = string.strlen(parent_name)
pn_buf: str = CompilerFactory.factory.PermPool.alloc(pn_len + 1)
if pn_buf is not None:
string.strcpy(pn_buf, parent_name)
@@ -598,21 +598,21 @@ class ClassGenDef(ClassGenBase.ClassGenBase):
self.Gen.StructGen.add_field(pool, entry, "__vtable__", i8_ptr_ty2, None, None)
for fi in range(field_count):
fname_addr: t.CSizeT = field_names_buf[fi]
fname_addr: sizet = field_names_buf[fi]
if fname_addr == 0:
continue
fname: str = (str | t.CPtr)(t.CVoid(fname_addr, t.CPtr))
fty_addr2: t.CSizeT = field_types_buf[fi]
fty_addr2: sizet = field_types_buf[fi]
if fty_addr2 == 0:
continue
fty2: llvmlite.LLVMType | t.CPtr = (llvmlite.LLVMType | t.CPtr)(t.CVoid(fty_addr2, t.CPtr))
# 恢复默认值 AST 指针
fdef_addr: t.CSizeT = field_defaults_buf[fi]
fdef_addr: sizet = field_defaults_buf[fi]
fdef: ast.AST | t.CPtr = None
if fdef_addr != 0:
fdef = (ast.AST | t.CPtr)(t.CVoid(fdef_addr, t.CPtr))
# 恢复注解类名指针
fannot_addr: t.CSizeT = field_annot_buf[fi]
fannot_addr: sizet = field_annot_buf[fi]
fannot: str = None
if fannot_addr != 0:
fannot = (str)(t.CVoid(fannot_addr, t.CPtr))
+57 -57
View File
@@ -45,7 +45,7 @@ class ClassGenEnum(ClassGenBase.ClassGenBase):
k: int = ann_node.kind()
# Attribute 节点: t.State / int / t.CInt8T 等
# Attribute 节点: t.State / int / int8 等
if k == ast.ASTKind.Attribute:
at: ast.Attribute | t.CPtr = (ast.Attribute | t.CPtr)(ann_node)
if at.attr is None:
@@ -73,7 +73,7 @@ class ClassGenEnum(ClassGenBase.ClassGenBase):
return ty2
return llvmlite.Int32(pool)
# BinOp 节点: t.State | t.CInt8T(递归查找实际类型)
# BinOp 节点: t.State | int8(递归查找实际类型)
if k == ast.ASTKind.BinOp:
bop: ast.BinOp | t.CPtr = (ast.BinOp | t.CPtr)(ann_node)
if bop.op == ast.OpKind.BitOr:
@@ -117,7 +117,7 @@ class ClassGenEnum(ClassGenBase.ClassGenBase):
return 1
return 0
return 0
def _extract_int_value(self, node: ast.AST | t.CPtr) -> t.CInt64T:
def _extract_int_value(self, node: ast.AST | t.CPtr) -> int64:
"""从 AST 节点提取整数值,失败返回 0"""
if node is None:
return 0
@@ -130,7 +130,7 @@ class ClassGenEnum(ClassGenBase.ClassGenBase):
if k == ast.ASTKind.UnaryOp:
uo: ast.UnaryOp | t.CPtr = (ast.UnaryOp | t.CPtr)(node)
if uo.op == ast.OpKind.USub:
inner: t.CInt64T = self._extract_int_value(uo.operand)
inner: int64 = self._extract_int_value(uo.operand)
return -inner
return 0
return 0
@@ -153,12 +153,12 @@ class ClassGenEnum(ClassGenBase.ClassGenBase):
VLogger.warning(f"{class_name} has no body", "ENUM")
return 0
cn: t.CSizeT = len(children)
cn: sizet = len(children)
# 临时数组存储成员信息
member_names_buf: t.CSizeT | t.CPtr = pool.alloc(8 * ENUM_MEMBER_MAX_LOCAL)
member_types_buf: t.CSizeT | t.CPtr = pool.alloc(8 * ENUM_MEMBER_MAX_LOCAL)
member_values_buf: t.CInt64T | t.CPtr = pool.alloc(8 * ENUM_MEMBER_MAX_LOCAL)
member_names_buf: sizet | t.CPtr = pool.alloc(8 * ENUM_MEMBER_MAX_LOCAL)
member_types_buf: sizet | t.CPtr = pool.alloc(8 * ENUM_MEMBER_MAX_LOCAL)
member_values_buf: int64 | t.CPtr = pool.alloc(8 * ENUM_MEMBER_MAX_LOCAL)
if member_names_buf is None or member_types_buf is None or member_values_buf is None:
return 0
string.memset(member_names_buf, 0, 8 * ENUM_MEMBER_MAX_LOCAL)
@@ -166,7 +166,7 @@ class ClassGenEnum(ClassGenBase.ClassGenBase):
string.memset(member_values_buf, 0, 8 * ENUM_MEMBER_MAX_LOCAL)
member_count: int = 0
next_val: t.CInt64T = 0
next_val: int64 = 0
for ci in range(cn):
stmt: ast.AST | t.CPtr = children.get(ci)
@@ -192,7 +192,7 @@ class ClassGenEnum(ClassGenBase.ClassGenBase):
# 解析成员值
has_value: int = 0
cur_val: t.CInt64T = 0
cur_val: int64 = 0
if aa.value is not None:
cur_val = self._extract_int_value(aa.value)
has_value = 1
@@ -204,8 +204,8 @@ class ClassGenEnum(ClassGenBase.ClassGenBase):
# 存储
if member_count < ENUM_MEMBER_MAX_LOCAL:
member_names_buf[member_count] = t.CSizeT(tgt.id)
member_types_buf[member_count] = t.CSizeT(member_ty)
member_names_buf[member_count] = sizet(tgt.id)
member_types_buf[member_count] = sizet(member_ty)
member_values_buf[member_count] = cur_val
member_count += 1
@@ -216,7 +216,7 @@ class ClassGenEnum(ClassGenBase.ClassGenBase):
if ag is None or ag.targets is None:
continue
tgts: list[ast.AST | t.CPtr] | t.CPtr = ag.targets
tn: t.CSizeT = len(tgts)
tn: sizet = len(tgts)
if tn == 0:
continue
# 取第一个 target 作为成员名
@@ -231,7 +231,7 @@ class ClassGenEnum(ClassGenBase.ClassGenBase):
member_ty_a: llvmlite.LLVMType | t.CPtr = llvmlite.Int32(pool)
# 解析成员值
cur_val_a: t.CInt64T = 0
cur_val_a: int64 = 0
if ag.value is not None:
cur_val_a = self._extract_int_value(ag.value)
else:
@@ -242,8 +242,8 @@ class ClassGenEnum(ClassGenBase.ClassGenBase):
# 存储
if member_count < ENUM_MEMBER_MAX_LOCAL:
member_names_buf[member_count] = t.CSizeT(tgt_a.id)
member_types_buf[member_count] = t.CSizeT(member_ty_a)
member_names_buf[member_count] = sizet(tgt_a.id)
member_types_buf[member_count] = sizet(member_ty_a)
member_values_buf[member_count] = cur_val_a
member_count += 1
@@ -255,7 +255,7 @@ class ClassGenEnum(ClassGenBase.ClassGenBase):
base_ty: llvmlite.LLVMType | t.CPtr = llvmlite.Int32(pool)
max_bits: int = 0
for mi in range(member_count):
ty_addr: t.CSizeT = member_types_buf[mi]
ty_addr: sizet = member_types_buf[mi]
if ty_addr == 0:
continue
mty: llvmlite.LLVMType | t.CPtr = (llvmlite.LLVMType | t.CPtr)(
@@ -274,16 +274,16 @@ class ClassGenEnum(ClassGenBase.ClassGenBase):
# 添加成员
for mi in range(member_count):
fname_addr: t.CSizeT = member_names_buf[mi]
fname_addr: sizet = member_names_buf[mi]
if fname_addr == 0:
continue
mname: str = (str | t.CPtr)(t.CVoid(fname_addr, t.CPtr))
fty_addr2: t.CSizeT = member_types_buf[mi]
fty_addr2: sizet = member_types_buf[mi]
if fty_addr2 == 0:
continue
mty2: llvmlite.LLVMType | t.CPtr = (llvmlite.LLVMType | t.CPtr)(
t.CVoid(fty_addr2, t.CPtr))
mval: t.CInt64T = member_values_buf[mi]
mval: int64 = member_values_buf[mi]
if mname is not None and mty2 is not None:
self.Gen.StmtGenDecl.add_enum_member(pool, entry, mname, mval, mty2)
@@ -408,11 +408,11 @@ class ClassGenEnum(ClassGenBase.ClassGenBase):
VLogger.warning("{class_name} has no body", "UNION")
return 0
cn: t.CSizeT = len(children)
cn: sizet = len(children)
# 临时数组存储字段信息
field_names_buf: t.CSizeT | t.CPtr = pool.alloc(8 * GenTypes.FIELD_MAX)
field_types_buf: t.CSizeT | t.CPtr = pool.alloc(8 * GenTypes.FIELD_MAX)
field_names_buf: sizet | t.CPtr = pool.alloc(8 * GenTypes.FIELD_MAX)
field_types_buf: sizet | t.CPtr = pool.alloc(8 * GenTypes.FIELD_MAX)
if field_names_buf is None or field_types_buf is None:
return 0
string.memset(field_names_buf, 0, 8 * GenTypes.FIELD_MAX)
@@ -462,8 +462,8 @@ class ClassGenEnum(ClassGenBase.ClassGenBase):
# 存储到数组
if field_count < GenTypes.FIELD_MAX:
field_names_buf[field_count] = t.CSizeT(tgt.id)
field_types_buf[field_count] = t.CSizeT(field_ty)
field_names_buf[field_count] = sizet(tgt.id)
field_types_buf[field_count] = sizet(field_ty)
field_count += 1
if field_count == 0:
@@ -527,11 +527,11 @@ class ClassGenEnum(ClassGenBase.ClassGenBase):
# 添加字段信息(所有字段 Index=0,因为共享偏移 0)
for fi in range(field_count):
fname_addr: t.CSizeT = field_names_buf[fi]
fname_addr: sizet = field_names_buf[fi]
if fname_addr == 0:
continue
fname: str = (str | t.CPtr)(t.CVoid(fname_addr, t.CPtr))
fty_addr2: t.CSizeT = field_types_buf[fi]
fty_addr2: sizet = field_types_buf[fi]
if fty_addr2 == 0:
continue
fty2: llvmlite.LLVMType | t.CPtr = (llvmlite.LLVMType | t.CPtr)(
@@ -630,11 +630,11 @@ class ClassGenEnum(ClassGenBase.ClassGenBase):
VLogger.warning(f"{class_name} has no body", "RENUM")
return 0
cn: t.CSizeT = len(children)
cn: sizet = len(children)
# 变体最多 32 个,每个变体最多 16 个字段
# variant_field_sizes[i][j] = 变体 i 的第 j 个字段大小
variant_field_sizes: t.CSizeT | t.CPtr = pool.alloc(8 * 64 * 16)
variant_field_sizes: sizet | t.CPtr = pool.alloc(8 * 64 * 16)
if variant_field_sizes is None:
return 0
string.memset(variant_field_sizes, 0, 8 * 64 * 16)
@@ -655,7 +655,7 @@ class ClassGenEnum(ClassGenBase.ClassGenBase):
variant_count += 1
continue
variant_children: list[ast.AST | t.CPtr] | t.CPtr = variant_cd.children
vcn: t.CSizeT = len(variant_children)
vcn: sizet = len(variant_children)
field_idx: int = 0
for vi in range(vcn):
vstmt: ast.AST | t.CPtr = variant_children.get(vi)
@@ -675,8 +675,8 @@ class ClassGenEnum(ClassGenBase.ClassGenBase):
fsize: int = self._get_annotation_field_size(pool, vaa.annotation)
if variant_count < 32 and field_idx < 16:
# variant_field_sizes[variant_count][field_idx] = fsize
offset: t.CSizeT = variant_count * 16 + field_idx
variant_field_sizes[offset] = t.CSizeT(fsize)
offset: sizet = variant_count * 16 + field_idx
variant_field_sizes[offset] = sizet(fsize)
# 直接注册变体字段名别名(避免 CSizeT→str 转换问题)
# 同时解析成员实际类型(对齐 TPC class_members,供 match
# 绑定 bitcast 槽位地址用)。自引用注解(如
@@ -709,13 +709,13 @@ class ClassGenEnum(ClassGenBase.ClassGenBase):
if total_positions < 2:
total_positions = 2 # 至少 {i32, i32}
position_max_sizes: t.CSizeT | t.CPtr = pool.alloc(8 * total_positions)
position_max_sizes: sizet | t.CPtr = pool.alloc(8 * total_positions)
if position_max_sizes is None:
return 0
string.memset(position_max_sizes, 0, 8 * total_positions)
# 位置 0 = tag = 4 字节
position_max_sizes[0] = t.CSizeT(4)
position_max_sizes[0] = sizet(4)
# 位置 1+ = 每个位置取所有变体的最大字段大小
for pos in range(1, total_positions):
@@ -726,11 +726,11 @@ class ClassGenEnum(ClassGenBase.ClassGenBase):
field_pos: int = pos - 1 # 变体字段从位置 0 开始
if field_pos >= 16:
continue # 超出每变体 16 字段槽位:未写入(memset 为 0),跳过
offset2: t.CSizeT = vi * 16 + field_pos
fsize_val: t.CSizeT = variant_field_sizes[offset2]
offset2: sizet = vi * 16 + field_pos
fsize_val: sizet = variant_field_sizes[offset2]
if fsize_val > pos_max:
pos_max = fsize_val
position_max_sizes[pos] = t.CSizeT(pos_max)
position_max_sizes[pos] = sizet(pos_max)
# 构建 ParamNode 链表
i32_ty: llvmlite.LLVMType | t.CPtr = llvmlite.Int32(pool)
@@ -840,7 +840,7 @@ class ClassGenEnum(ClassGenBase.ClassGenBase):
children: list[ast.AST | t.CPtr] | t.CPtr = cd.children
if children is None:
return
cn: t.CSizeT = len(children)
cn: sizet = len(children)
for ci in range(cn):
stmt: ast.AST | t.CPtr = children.get(ci)
if stmt is None or stmt.kind() != ast.ASTKind.ClassDef:
@@ -850,7 +850,7 @@ class ClassGenEnum(ClassGenBase.ClassGenBase):
or variant_cd.children is None:
continue
vchildren: list[ast.AST | t.CPtr] | t.CPtr = variant_cd.children
vcn: t.CSizeT = len(vchildren)
vcn: sizet = len(vchildren)
field_idx: int = 0
for vi in range(vcn):
vstmt: ast.AST | t.CPtr = vchildren.get(vi)
@@ -912,7 +912,7 @@ class ClassGenEnum(ClassGenBase.ClassGenBase):
string.memset(self.RenumVariantTags, 0, 8 * RENUM_CLASS_MAX * RENUM_VARIANT_PER_CLASS)
self.RenumClassCount = 0
#rcv_chk: t.CUInt64T = t.CUInt64T(self.RenumClassVariantCounts)
#rcv_chk: uint64 = uint64(self.RenumClassVariantCounts)
#if rcv_chk == 0 or rcv_chk < 4096:
# VLogger.error(f"[RENUM-FAIL] RCV={rcv_chk} 异常(lazy init 后应为 perm_pool 地址),RenumClassCount={self.RenumClassCount} class={class_name}", "RENUM")
# stdlib.exit(1)
@@ -930,16 +930,16 @@ class ClassGenEnum(ClassGenBase.ClassGenBase):
# 注册类名(strcpy 到 perm_pool:1a 每文件 reset 后 AST 裸指针悬空,
# _lookup_renum_variant/_is_renum_class_name 的 strcmp 会读毒化内存)
idx: int = self.RenumClassCount
cn_len_rv: t.CSizeT = string.strlen(class_name)
cn_len_rv: sizet = string.strlen(class_name)
cn_buf_rv: str = CompilerFactory.factory.PermPool.alloc(cn_len_rv + 1)
if cn_buf_rv is None:
return
string.strcpy(cn_buf_rv, class_name)
self.RenumClassNames[idx] = t.CSizeT(cn_buf_rv)
self.RenumClassNames[idx] = sizet(cn_buf_rv)
self.RenumClassVariantCounts[idx] = variant_count
# 遍历 children,提取嵌套变体类名并注册
cn: t.CSizeT = len(children)
cn: sizet = len(children)
tag: int = 0
for ci in range(cn):
if tag >= variant_count:
@@ -956,14 +956,14 @@ class ClassGenEnum(ClassGenBase.ClassGenBase):
vcd: ast.ClassDef | t.CPtr = (ast.ClassDef | t.CPtr)(stmt)
if vcd is None or vcd.name is None:
continue
name_offset: t.CSizeT = idx * RENUM_VARIANT_PER_CLASS + tag
name_offset: sizet = idx * RENUM_VARIANT_PER_CLASS + tag
# 变体名同样 strcpy 到 perm_pool(1a 每文件 reset 后 vcd.name 悬空)
vn_len_rv: t.CSizeT = string.strlen(vcd.name)
vn_len_rv: sizet = string.strlen(vcd.name)
vn_buf_rv: str = CompilerFactory.factory.PermPool.alloc(vn_len_rv + 1)
if vn_buf_rv is None:
break
string.strcpy(vn_buf_rv, vcd.name)
self.RenumVariantNames[name_offset] = t.CSizeT(vn_buf_rv)
self.RenumVariantNames[name_offset] = sizet(vn_buf_rv)
self.RenumVariantTags[name_offset] = tag
tag += 1
@@ -979,7 +979,7 @@ class ClassGenEnum(ClassGenBase.ClassGenBase):
for i in range(self.RenumClassCount):
vcount: int = self.RenumClassVariantCounts[i]
for j in range(vcount):
name_offset: t.CSizeT = i * RENUM_VARIANT_PER_CLASS + j
name_offset: sizet = i * RENUM_VARIANT_PER_CLASS + j
vname: str = self.RenumVariantNames[name_offset]
if vname is not None and string.strcmp(vname, variant_name) == 0:
cls_nm: str = self.RenumClassNames[i]
@@ -1004,7 +1004,7 @@ class ClassGenEnum(ClassGenBase.ClassGenBase):
continue
vcount: int = self.RenumClassVariantCounts[i]
for j in range(vcount):
name_offset: t.CSizeT = i * RENUM_VARIANT_PER_CLASS + j
name_offset: sizet = i * RENUM_VARIANT_PER_CLASS + j
vname: str = self.RenumVariantNames[name_offset]
if vname is not None and string.strcmp(vname, variant_name) == 0:
return self.RenumVariantTags[name_offset]
@@ -1067,27 +1067,27 @@ class ClassGenEnum(ClassGenBase.ClassGenBase):
ty_copy_rf2: llvmlite.LLVMType | t.CPtr = llvmlite.DeepCopyType(
CompilerFactory.factory.PermPool, field_ty)
if ty_copy_rf2 is not None:
self.RenumAliasTy[i] = t.CSizeT(ty_copy_rf2)
self.RenumAliasTy[i] = sizet(ty_copy_rf2)
return
idx: int = self.RenumAliasCount
# class_name 同样 strcpy 到 perm_pool(去指针化:查找方任何来源的
# class_name 字符串都可用 strcmp 命中,无需 _update_renum_alias_class_ptr)
cls_len_rfa: t.CSizeT = string.strlen(class_name)
cls_len_rfa: sizet = string.strlen(class_name)
cls_buf_rfa: str = CompilerFactory.factory.PermPool.alloc(cls_len_rfa + 1)
if cls_buf_rfa is None:
return
string.strcpy(cls_buf_rfa, class_name)
self.RenumAliasClass[idx] = t.CSizeT(cls_buf_rfa)
self.RenumAliasClass[idx] = sizet(cls_buf_rfa)
# field_name 存 AST 裸指针,1a 每文件 reset 后悬空;_lookup_renum_field_alias
# 用 strcmp 内容比较 → strcpy 到 perm_pool 不影响查找。
fn_len_rfa: t.CSizeT = string.strlen(field_name)
fn_len_rfa: sizet = string.strlen(field_name)
fn_buf_rfa: str = CompilerFactory.factory.PermPool.alloc(fn_len_rfa + 1)
if fn_buf_rfa is None:
return
string.strcpy(fn_buf_rfa, field_name)
self.RenumAliasField[idx] = t.CSizeT(fn_buf_rfa)
self.RenumAliasIndex[idx] = t.CSizeT(payload_idx)
self.RenumAliasField[idx] = sizet(fn_buf_rfa)
self.RenumAliasIndex[idx] = sizet(payload_idx)
# 成员类型深拷贝到 perm_pool(1a 每文件 reset 后 pool 类型悬空;
# 未解析成功(自引用等)存 0,绑定回退槽位类型)
self.RenumAliasTy[idx] = 0
@@ -1095,15 +1095,15 @@ class ClassGenEnum(ClassGenBase.ClassGenBase):
ty_copy_rfa: llvmlite.LLVMType | t.CPtr = llvmlite.DeepCopyType(
CompilerFactory.factory.PermPool, field_ty)
if ty_copy_rfa is not None:
self.RenumAliasTy[idx] = t.CSizeT(ty_copy_rfa)
self.RenumAliasTy[idx] = sizet(ty_copy_rfa)
# 变体名同样 strcpy 到 perm_pool(1a reset 后 variant_cd.name 悬空)
self.RenumAliasVariant[idx] = 0
if variant_name is not None:
vn_len_rfa: t.CSizeT = string.strlen(variant_name)
vn_len_rfa: sizet = string.strlen(variant_name)
vn_buf_rfa: str = CompilerFactory.factory.PermPool.alloc(vn_len_rfa + 1)
if vn_buf_rfa is not None:
string.strcpy(vn_buf_rfa, variant_name)
self.RenumAliasVariant[idx] = t.CSizeT(vn_buf_rfa)
self.RenumAliasVariant[idx] = sizet(vn_buf_rfa)
self.RenumAliasCount = idx + 1
def _lookup_renum_field_alias(self, class_name: str, field_name: str) -> int:
"""查找 REnum 变体字段名的 payload 索引,返回索引或 -1
+46 -46
View File
@@ -69,8 +69,8 @@ class ClassGenGeneric(ClassGenBase.ClassGenBase):
string.memset(self.GenericClassTpParams, 0, GENERIC_TEMPLATE_MAX * 8)
# 用局部变量接收 list,触发类型推断(避免字段 __len__ 失败)
names_local: list[str] | t.CPtr = self.GenericClassNames
cn: t.CSizeT = len(names_local)
i: t.CSizeT
cn: sizet = len(names_local)
i: sizet
for i in range(cn):
nm: str = names_local.get(i)
if nm is not None and string.strcmp(nm, cd.name) == 0:
@@ -83,7 +83,7 @@ class ClassGenGeneric(ClassGenBase.ClassGenBase):
# 同时保存模板来源文件路径(错误定位用,见字段注释)
self.GenericClassFiles.append(self.Gen.TypeGenResolve.get_current_file())
if tp_names_buf is not None and cn < GENERIC_TEMPLATE_MAX:
self.GenericClassTpParams[cn] = t.CSizeT(tp_names_buf)
self.GenericClassTpParams[cn] = sizet(tp_names_buf)
def _copy_type_params_stdlib(self, tp: list[str] | t.CPtr) -> str:
"""将模板 type_params 深拷贝为空格分隔、NUL 结尾的 stdlib 缓冲区
@@ -94,12 +94,12 @@ class ClassGenGeneric(ClassGenBase.ClassGenBase):
"""
if tp is None:
return None
tp_n: t.CSizeT = len(tp)
tp_n: sizet = len(tp)
if tp_n == 0:
return None
# 计算总长:各名字长度 + (n-1) 个空格 + NUL
total: t.CSizeT = 1
ti: t.CSizeT
total: sizet = 1
ti: sizet
for ti in range(tp_n):
tp_name: str = tp.get(ti)
if tp_name is not None:
@@ -127,14 +127,14 @@ class ClassGenGeneric(ClassGenBase.ClassGenBase):
or self.GenericClassTpParams is None:
return None
names_local: list[str] | t.CPtr = self.GenericClassNames
cn: t.CSizeT = len(names_local)
i: t.CSizeT
cn: sizet = len(names_local)
i: sizet
for i in range(cn):
nm: str = names_local.get(i)
if nm is not None and string.strcmp(nm, class_name) == 0:
if i >= GENERIC_TEMPLATE_MAX:
return None
buf_addr: t.CSizeT = self.GenericClassTpParams[i]
buf_addr: sizet = self.GenericClassTpParams[i]
if buf_addr == 0:
return None
buf_tp: str = (str | t.CPtr)(t.CVoid(buf_addr, t.CPtr))
@@ -146,12 +146,12 @@ class ClassGenGeneric(ClassGenBase.ClassGenBase):
tp_list: list[str] | t.CPtr = list[str](pool, 8)
if tp_list is None:
return None
seg_start: t.CSizeT = 0
pos: t.CSizeT = 0
blen: t.CSizeT = string.strlen(buf_tp)
seg_start: sizet = 0
pos: sizet = 0
blen: sizet = string.strlen(buf_tp)
while pos <= blen:
if buf_tp[pos] == ' ' or buf_tp[pos] == '\0':
seg_len: t.CSizeT = pos - seg_start
seg_len: sizet = pos - seg_start
if seg_len > 0:
seg: str = pool.alloc(seg_len + 1)
if seg is not None:
@@ -169,8 +169,8 @@ class ClassGenGeneric(ClassGenBase.ClassGenBase):
# 用局部变量接收 list,触发类型推断(避免字段 __len__ 失败)
names_local: list[str] | t.CPtr = self.GenericClassNames
nodes_local: list[ast.ClassDef | t.CPtr] | t.CPtr = self.GenericClassNodes
cn: t.CSizeT = len(names_local)
i: t.CSizeT
cn: sizet = len(names_local)
i: sizet
for i in range(cn):
nm: str = names_local.get(i)
if nm is not None and string.strcmp(nm, class_name) == 0:
@@ -184,8 +184,8 @@ class ClassGenGeneric(ClassGenBase.ClassGenBase):
# 用局部变量接收 list,触发类型推断
names_local: list[str] | t.CPtr = self.GenericClassNames
sha1s_local: list[str] | t.CPtr = self.GenericClassSha1s
cn: t.CSizeT = len(names_local)
i: t.CSizeT
cn: sizet = len(names_local)
i: sizet
for i in range(cn):
nm: str = names_local.get(i)
if nm is not None and string.strcmp(nm, class_name) == 0:
@@ -202,8 +202,8 @@ class ClassGenGeneric(ClassGenBase.ClassGenBase):
return None
names_local: list[str] | t.CPtr = self.GenericClassNames
files_local: list[str] | t.CPtr = self.GenericClassFiles
cn: t.CSizeT = len(names_local)
i: t.CSizeT
cn: sizet = len(names_local)
i: sizet
for i in range(cn):
nm: str = names_local.get(i)
if nm is not None and string.strcmp(nm, class_name) == 0:
@@ -219,12 +219,12 @@ class ClassGenGeneric(ClassGenBase.ClassGenBase):
"""
if class_name is None or type_args is None or pool is None:
return class_name
n: t.CSizeT = len(type_args)
n: sizet = len(type_args)
if n == 0:
return class_name
# 计算总长度: class_name + "[" + arg0 + "," + arg1 + ... + "]" + NUL
total_len: t.CSizeT = string.strlen(class_name) + 2 # "[" 和 "]"
i: t.CSizeT
total_len: sizet = string.strlen(class_name) + 2 # "[" 和 "]"
i: sizet
for i in range(n):
if i > 0:
total_len += 1 # ","
@@ -264,8 +264,8 @@ class ClassGenGeneric(ClassGenBase.ClassGenBase):
if k == ast.ASTKind.Name:
nm: ast.Name | t.CPtr = (ast.Name | t.CPtr)(node)
if nm.id is not None:
n: t.CSizeT = len(tp_names) if tp_names is not None else 0
i: t.CSizeT
n: sizet = len(tp_names) if tp_names is not None else 0
i: sizet
for i in range(n):
tpn: str = tp_names.get(i)
if tpn is not None and string.strcmp(nm.id, tpn) == 0:
@@ -302,8 +302,8 @@ class ClassGenGeneric(ClassGenBase.ClassGenBase):
new_elts: list[ast.AST | t.CPtr] | t.CPtr = list[ast.AST | t.CPtr](pool, 8)
if tup.elts is not None:
tup_elts: list[ast.AST | t.CPtr] | t.CPtr = tup.elts
en: t.CSizeT = len(tup_elts)
ei: t.CSizeT
en: sizet = len(tup_elts)
ei: sizet
for ei in range(en):
el: ast.AST | t.CPtr = tup_elts.get(ei)
new_el: ast.AST | t.CPtr = self._clone_annotation(pool, el, tp_names, type_args)
@@ -333,8 +333,8 @@ class ClassGenGeneric(ClassGenBase.ClassGenBase):
new_arg_list: list[ast.AST | t.CPtr] | t.CPtr = list[ast.AST | t.CPtr](pool, 8)
if old_args.args is not None:
old_arg_list: list[ast.AST | t.CPtr] | t.CPtr = old_args.args
an: t.CSizeT = len(old_arg_list)
ai: t.CSizeT
an: sizet = len(old_arg_list)
ai: sizet
for ai in range(an):
arg_node: ast.AST | t.CPtr = old_arg_list.get(ai)
if arg_node is None:
@@ -366,8 +366,8 @@ class ClassGenGeneric(ClassGenBase.ClassGenBase):
# 拷贝 children
if cd.children is not None:
cd_children: list[ast.AST | t.CPtr] | t.CPtr = cd.children
cn: t.CSizeT = len(cd_children)
ci: t.CSizeT
cn: sizet = len(cd_children)
ci: sizet
for ci in range(cn):
child: ast.AST | t.CPtr = cd_children.get(ci)
if child is None:
@@ -391,8 +391,8 @@ class ClassGenGeneric(ClassGenBase.ClassGenBase):
# 方法体直接引用原始节点
if fd.children is not None:
fd_children: list[ast.AST | t.CPtr] | t.CPtr = fd.children
bcn: t.CSizeT = len(fd_children)
bci: t.CSizeT
bcn: sizet = len(fd_children)
bci: sizet
for bci in range(bcn):
body_stmt: ast.AST | t.CPtr = fd_children.get(bci)
if body_stmt is not None:
@@ -409,11 +409,11 @@ class ClassGenGeneric(ClassGenBase.ClassGenBase):
return None
i: int
for i in range(self.SpecCount):
key_addr: t.CSizeT = self.SpecKeys[i]
key_addr: sizet = self.SpecKeys[i]
if key_addr != 0:
k: str = (str | t.CPtr)(t.CVoid(key_addr, t.CPtr))
if k is not None and string.strcmp(k, spec_key) == 0:
name_addr: t.CSizeT = self.SpecNames[i]
name_addr: sizet = self.SpecNames[i]
if name_addr != 0:
return (str | t.CPtr)(t.CVoid(name_addr, t.CPtr))
return None
@@ -432,16 +432,16 @@ class ClassGenGeneric(ClassGenBase.ClassGenBase):
if self.SpecCount >= SPEC_CACHE_MAX:
return
# 深拷贝字符串到 stdlib 区
key_len: t.CSizeT = string.strlen(spec_key)
name_len: t.CSizeT = string.strlen(spec_name)
key_len: sizet = string.strlen(spec_key)
name_len: sizet = string.strlen(spec_name)
key_copy: str = CompilerFactory.factory.PermPool.alloc(key_len + 1)
name_copy: str = CompilerFactory.factory.PermPool.alloc(name_len + 1)
if key_copy is None or name_copy is None:
return
string.strcpy(key_copy, spec_key)
string.strcpy(name_copy, spec_name)
self.SpecKeys[self.SpecCount] = t.CSizeT(key_copy)
self.SpecNames[self.SpecCount] = t.CSizeT(name_copy)
self.SpecKeys[self.SpecCount] = sizet(key_copy)
self.SpecNames[self.SpecCount] = sizet(name_copy)
self.SpecCount += 1
def _merge_template_imports(self, trans: HT.Translator | t.CPtr,
template_sha1: str) -> None:
@@ -455,8 +455,8 @@ class ClassGenGeneric(ClassGenBase.ClassGenBase):
if cur is None or cur[0] == '\0':
trans._imported_modules = tdeps
return
cur_len: t.CSizeT = string.strlen(cur)
td_len: t.CSizeT = string.strlen(tdeps)
cur_len: sizet = string.strlen(cur)
td_len: sizet = string.strlen(tdeps)
merged: str = trans.Pool.alloc(cur_len + td_len + 2)
if merged is None:
return
@@ -480,7 +480,7 @@ class ClassGenGeneric(ClassGenBase.ClassGenBase):
return 0
if string.strcmp(entry_rt.Name, spec_name) != 0:
return 0
ts_len_r: t.CSizeT = string.strlen(trigger_sha1)
ts_len_r: sizet = string.strlen(trigger_sha1)
ts_buf_r: str = CompilerFactory.factory.PermPool.alloc(ts_len_r + 1)
if ts_buf_r is None:
return 0
@@ -520,8 +520,8 @@ class ClassGenGeneric(ClassGenBase.ClassGenBase):
# 防御:泛型上下文内收集的 type_args 若残留未替换的类型参数名(如 "T"),
# 统一替换为具体类型名,避免 ndarray[T] 二次递归特化崩溃。
# 调用方传入的 type_args 均为临时新建列表,就地替换无共享副作用。
ta_cnt_g: t.CSizeT = len(type_args)
ta_i_g: t.CSizeT
ta_cnt_g: sizet = len(type_args)
ta_i_g: sizet
for ta_i_g in range(ta_cnt_g):
ta_raw_g: str = type_args.get(ta_i_g)
if ta_raw_g is not None:
@@ -595,9 +595,9 @@ class ClassGenGeneric(ClassGenBase.ClassGenBase):
# 3. 检查缓存(spec_key 包含所有类型实参,避免多参数泛型缓存冲突)
# 分配新缓冲区避免原地 strcat 溢出
sk_n: t.CSizeT = len(type_args)
sk_total: t.CSizeT = string.strlen(class_name) + 2 # "<" 和 ">"
sk_i: t.CSizeT
sk_n: sizet = len(type_args)
sk_total: sizet = string.strlen(class_name) + 2 # "<" 和 ">"
sk_i: sizet
for sk_i in range(sk_n):
if sk_i > 0:
sk_total += 1 # ","
+33 -33
View File
@@ -36,17 +36,17 @@ class ClassGenVTable(ClassGenBase.ClassGenBase):
# ============================================================
# _vtable_strcat — 将 src 追加到 dst 末尾
# ============================================================
def _vtable_strcat(self, dst: str, dst_size: t.CSizeT,
def _vtable_strcat(self, dst: str, dst_size: sizet,
src: str):
"""将 src 追加到 dst 末尾"""
if dst is None or src is None:
return
dlen: t.CSizeT = string.strlen(dst)
slen: t.CSizeT = string.strlen(src)
remain: t.CSizeT = dst_size - dlen
dlen: sizet = string.strlen(dst)
slen: sizet = string.strlen(src)
remain: sizet = dst_size - dlen
if remain <= 0:
return
i: t.CSizeT = 0
i: sizet = 0
while i < slen and i + 1 < remain:
dst[dlen + i] = src[i]
i += 1
@@ -71,7 +71,7 @@ class ClassGenVTable(ClassGenBase.ClassGenBase):
# 例如: void ({i32, i32}*, i32)
# ============================================================
def _format_func_type_str(self, pool: memhub.MemBuddy | t.CPtr,
buf: str, buf_size: t.CSizeT,
buf: str, buf_size: sizet,
func: llvmlite.Function | t.CPtr) -> int:
"""从 Function 对象生成函数类型字符串"""
if buf is None or func is None or buf_size == 0:
@@ -132,15 +132,15 @@ class ClassGenVTable(ClassGenBase.ClassGenBase):
children: list[ast.AST | t.CPtr] | t.CPtr = cd.children
if children is None:
return 0
cn: t.CSizeT = len(children)
cn: sizet = len(children)
# 1. 收集虚方法信息
# stdlib 分配:method_names_buf 存到 StructEntry.VTableMethods(跨文件永久存活),
# 必须迁出 mb 池 reset 区间,否则 1b 每文件 reset_to(mark1) 会回收导致悬空。
full_names_buf: t.CSizeT | t.CPtr = CompilerFactory.factory.PermPool.alloc(8 * VTBL_METHOD_MAX)
method_names_buf: t.CSizeT | t.CPtr = CompilerFactory.factory.PermPool.alloc(8 * VTBL_METHOD_MAX)
full_names_buf: sizet | t.CPtr = CompilerFactory.factory.PermPool.alloc(8 * VTBL_METHOD_MAX)
method_names_buf: sizet | t.CPtr = CompilerFactory.factory.PermPool.alloc(8 * VTBL_METHOD_MAX)
# 记录每个方法的父类 SHA1(非 0=继承方法用父模块 SHA1 mangling,0=当前类方法)
method_parent_sha1s: t.CSizeT | t.CPtr = CompilerFactory.factory.PermPool.alloc(8 * VTBL_METHOD_MAX)
method_parent_sha1s: sizet | t.CPtr = CompilerFactory.factory.PermPool.alloc(8 * VTBL_METHOD_MAX)
if full_names_buf is None or method_names_buf is None or method_parent_sha1s is None:
return 0
string.memset(full_names_buf, 0, 8 * VTBL_METHOD_MAX)
@@ -218,7 +218,7 @@ class ClassGenVTable(ClassGenBase.ClassGenBase):
else:
def_class = pname
# 多继承:沿 pname 的 MRO 祖先链探测实际定义类(跳过自身,先声明父类优先)
mro_ptr: t.CSizeT | t.CPtr = self.Gen.StructGen.get_mro_chain(pool, pname)
mro_ptr: sizet | t.CPtr = self.Gen.StructGen.get_mro_chain(pool, pname)
mro_i: int = 1
while mro_ptr is not None and mro_ptr[mro_i] != 0:
anc: str = (str | t.CPtr)(t.CVoid(mro_ptr[mro_i], t.CPtr))
@@ -233,13 +233,13 @@ class ClassGenVTable(ClassGenBase.ClassGenBase):
pfname_buf: str = CompilerFactory.factory.PermPool.alloc(128)
if pfname_buf is not None:
viperlib.snprintf(pfname_buf, 128, "%s.%s", def_class, pmethod_name)
full_names_buf[method_count] = t.CSizeT(pfname_buf)
full_names_buf[method_count] = sizet(pfname_buf)
# 复制方法名(短名)
pmname_len: t.CSizeT = string.strlen(pmethod_name)
pmname_len: sizet = string.strlen(pmethod_name)
pmname_buf: str = CompilerFactory.factory.PermPool.alloc(pmname_len + 1)
if pmname_buf is not None:
string.strcpy(pmname_buf, pmethod_name)
method_names_buf[method_count] = t.CSizeT(pmname_buf)
method_names_buf[method_count] = sizet(pmname_buf)
# 记录 mangling 用的 SHA1(继承未覆盖的方法用实际定义类的模块 SHA1)
if child_overrides == 1 and child_nvt == 0:
# 子类覆盖: 用当前模块 SHA1(保持 0)
@@ -249,7 +249,7 @@ class ClassGenVTable(ClassGenBase.ClassGenBase):
def_entry2: GenTypes.StructEntry | t.CPtr = self.Gen.StructGen.find_struct(
def_class)
if def_entry2 is not None and def_entry2.ModuleSha1 is not None:
method_parent_sha1s[method_count] = t.CSizeT(def_entry2.ModuleSha1)
method_parent_sha1s[method_count] = sizet(def_entry2.ModuleSha1)
else:
method_parent_sha1s[method_count] = 0
method_count += 1
@@ -281,7 +281,7 @@ class ClassGenVTable(ClassGenBase.ClassGenBase):
# 检查是否已从父类继承(避免重复)
already_in_vt: int = 0
for mi in range(method_count):
exist_addr: t.CSizeT = method_names_buf[mi]
exist_addr: sizet = method_names_buf[mi]
if exist_addr != 0:
exist_name: str = (str | t.CPtr)(t.CVoid(exist_addr, t.CPtr))
if exist_name is not None and string.strcmp(exist_name, mname) == 0:
@@ -295,14 +295,14 @@ class ClassGenVTable(ClassGenBase.ClassGenBase):
fname_buf: str = CompilerFactory.factory.PermPool.alloc(128)
if fname_buf is not None:
viperlib.snprintf(fname_buf, 128, "%s.%s", class_name, mname)
full_names_buf[method_count] = t.CSizeT(fname_buf)
full_names_buf[method_count] = sizet(fname_buf)
# 复制方法名
mname_len: t.CSizeT = string.strlen(mname)
mname_len: sizet = string.strlen(mname)
mname_buf: str = CompilerFactory.factory.PermPool.alloc(mname_len + 1)
if mname_buf is not None:
string.strcpy(mname_buf, mname)
method_names_buf[method_count] = t.CSizeT(mname_buf)
method_names_buf[method_count] = sizet(mname_buf)
method_count += 1
@@ -345,9 +345,9 @@ class ClassGenVTable(ClassGenBase.ClassGenBase):
# 同时设置 entry.VTableMethodCount/VTableMethods(虚分派查询用)
if self._collect_vtable_methods(trans, cd, class_name) == 0:
return 0
full_names_buf: t.CSizeT | t.CPtr = self.VtFullNames
method_names_buf: t.CSizeT | t.CPtr = self.VtMethodNames
method_parent_sha1s: t.CSizeT | t.CPtr = self.VtParentSha1s
full_names_buf: sizet | t.CPtr = self.VtFullNames
method_names_buf: sizet | t.CPtr = self.VtMethodNames
method_parent_sha1s: sizet | t.CPtr = self.VtParentSha1s
method_count: int = self.VtMethodCount
# 重新获取 entry(后续存储 VTableMethods 用)
vt_self_entry: GenTypes.StructEntry | t.CPtr = self.Gen.StructGen.find_struct_by_module(
@@ -384,7 +384,7 @@ class ClassGenVTable(ClassGenBase.ClassGenBase):
if i > 0:
self._vtable_strcat(init_buf, 16384, ", ")
full_name_addr: t.CSizeT = full_names_buf[i]
full_name_addr: sizet = full_names_buf[i]
if full_name_addr == 0:
self._vtable_strcat(init_buf, 16384, "i8* null")
continue
@@ -392,7 +392,7 @@ class ClassGenVTable(ClassGenBase.ClassGenBase):
full_name: str = (str | t.CPtr)(t.CVoid(full_name_addr, t.CPtr))
# 检查是否是继承方法(method_parent_sha1s 非 0 表示用父模块 SHA1 mangling)
parent_sha1_addr: t.CSizeT = method_parent_sha1s[i]
parent_sha1_addr: sizet = method_parent_sha1s[i]
if parent_sha1_addr != 0:
# 继承方法: 用父类模块 SHA1 做 mangling
parent_sha1: str = (str | t.CPtr)(t.CVoid(parent_sha1_addr, t.CPtr))
@@ -524,7 +524,7 @@ class ClassGenVTable(ClassGenBase.ClassGenBase):
if children is None:
return 0
cn: t.CSizeT = len(children)
cn: sizet = len(children)
has_method: int = 0
has_init: int = 0
has_new: int = 0
@@ -715,11 +715,11 @@ class ClassGenVTable(ClassGenBase.ClassGenBase):
viperlib.snprintf(method_name_buf, 128, "%s", fd.name)
if func_meta & GenTypes.META_PROP_SETTER != 0:
# 128 字节缓冲:追加 "$set" 前检查剩余容量,防 strcat 无界写穿
mn_len2: t.CSizeT = string.strlen(method_name_buf)
mn_len2: sizet = string.strlen(method_name_buf)
if mn_len2 + 5 < 128:
string.strcat(method_name_buf, "$set")
elif func_meta & GenTypes.META_PROP_DELETER != 0:
mn_len2: t.CSizeT = string.strlen(method_name_buf)
mn_len2: sizet = string.strlen(method_name_buf)
if mn_len2 + 5 < 128:
string.strcat(method_name_buf, "$del")
method_name = method_name_buf
@@ -774,7 +774,7 @@ class ClassGenVTable(ClassGenBase.ClassGenBase):
# @staticmethod 无 self,param_count 为完整参数数)
# 注意: 必须先把属性赋给显式类型为 list[...] | t.CPtr 的局部变量再调用 __len__(),
# 否则编译器无法识别属性返回的 list 类型,GEP base 会变成 i32 0 导致 llc 报错
md_defaults: t.CVoid | t.CPtr = None
md_defaults: t.CPtr = None
md_default_count: int = 0
md_param_count: int = 0
md_args_node: ast.Arguments | t.CPtr = fd.args
@@ -819,7 +819,7 @@ class ClassGenVTable(ClassGenBase.ClassGenBase):
ags: ast.Arguments | t.CPtr = (ast.Arguments | t.CPtr)(args_node)
if ags.args is not None:
alist: list[ast.AST | t.CPtr] | t.CPtr = ags.args
an: t.CSizeT = len(alist)
an: sizet = len(alist)
start_idx: int = 0
if is_static_m == 0:
start_idx = 1
@@ -963,7 +963,7 @@ class ClassGenVTable(ClassGenBase.ClassGenBase):
ags2: ast.Arguments | t.CPtr = (ast.Arguments | t.CPtr)(args_node)
if ags2.args is not None:
alist2: list[ast.AST | t.CPtr] | t.CPtr = ags2.args
an2: t.CSizeT = len(alist2)
an2: sizet = len(alist2)
start_idx2: int = 0
if is_static_m == 0:
start_idx2 = 1
@@ -1044,7 +1044,7 @@ class ClassGenVTable(ClassGenBase.ClassGenBase):
# (main.vp __init__ BootInfo memmap 全 0 根因)。
body: list[ast.AST | t.CPtr] | t.CPtr = fd.children
if body is not None:
bn: t.CSizeT = len(body)
bn: sizet = len(body)
for bi in range(bn):
stmt: ast.AST | t.CPtr = body.get(bi)
if stmt is not None:
@@ -1056,7 +1056,7 @@ class ClassGenVTable(ClassGenBase.ClassGenBase):
# 翻译方法体
if body is not None:
bn2: t.CSizeT = len(body)
bn2: sizet = len(body)
for bi2 in range(bn2):
stmt2: ast.AST | t.CPtr = body.get(bi2)
if stmt2 is not None:
@@ -1077,7 +1077,7 @@ class ClassGenVTable(ClassGenBase.ClassGenBase):
# FuncGenMixin 模块级函数路径,方法路径此处追加89 一并同步)
last_is_return: int = 0
# 追加89:bn3 提前初始化,避免 body is None 时下方引用未定义变量
bn3: t.CSizeT = 0
bn3: sizet = 0
if body is not None:
bn3 = len(body)
if bn3 > 0: