实现了 TPV 的 pyi 生成逻辑(部分),删除了直接拷贝自 CPython(TPC) 版本的死代码

This commit is contained in:
2026-07-22 19:47:23 +08:00
parent a99d2a5ad9
commit 751dc72d61
19 changed files with 641 additions and 1436 deletions

View File

@@ -1626,11 +1626,9 @@ def translate_class_def(trans: HT.Translator | t.CPtr,
if fname is not None and fty2 is not None:
HandlesStruct.add_field(pool, entry, fname, fty2, fdef, fannot)
stdio.printf("[CLASS] registered %s with %d fields (vtable=%d)\n",
class_name, field_count, has_vtable)
# Phase 1a 声明模式:只注册 struct不翻译方法体
# Phase 1a 声明模式:只注册 struct + 设置 OOP 标志,不翻译方法体
if trans._declare_only == 1:
_translate_oop_methods(trans, cd, struct_ty, class_name, 1)
return 0
# ============================================================
@@ -1997,8 +1995,6 @@ def _generate_vtable(trans: HT.Translator | t.CPtr,
vt_self_entry.VTableMethods = method_names_buf
vt_self_entry.VTableMethodCount = method_count
stdio.printf("[VTABLE] generated vtable for %s with %d methods\n",
class_name, method_count)
return 0
@@ -2023,8 +2019,12 @@ def _generate_vtable(trans: HT.Translator | t.CPtr,
def _translate_oop_methods(trans: HT.Translator | t.CPtr,
cd: ast.ClassDef | t.CPtr,
struct_ty: llvmlite.LLVMType | t.CPtr,
class_name: str) -> int:
"""扫描 class body 中的方法并翻译,生成 __before_init__"""
class_name: str,
mark_only: int = 0) -> int:
"""扫描 class body 中的方法并翻译,生成 __before_init__
mark_only: 0=全量翻译默认1=只设置 IsOOP/HasNew/HasInit 标志(不翻译方法体)
"""
if trans is None or cd is None or struct_ty is None or class_name is None:
return 0
@@ -2075,6 +2075,10 @@ def _translate_oop_methods(trans: HT.Translator | t.CPtr,
if has_new != 0:
oop_entry.HasNew = 1
# mark_only 模式:只设置标志,不翻译方法体
if mark_only != 0:
return 0
# 第二遍:翻译每个方法
for ci in range(cn):
stmt: ast.AST | t.CPtr = children.get(ci)