实现了 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

@@ -905,12 +905,6 @@ def _asm_add_operand(operands: AsmOperand | t.CPtr,
op.Value = val
op.Constraint = constraint
op.IsOutput = is_output
if val is not None:
stdio.printf("[A] count=%d op=%lld val=%lld val.Ty=%lld val.Name=%lld is_out=%d\n",
count, t.CInt64T(op), t.CInt64T(val), t.CInt64T(val.Ty), t.CInt64T(val.Name), is_output)
else:
stdio.printf("[A] count=%d op=%lld val=None is_out=%d\n", count, t.CInt64T(op), is_output)
stdio.fflush(0)
return count + 1
# ============================================================
@@ -1177,9 +1171,6 @@ def translate_c_asm(pool: memhub.MemBuddy | t.CPtr,
ret_ty: llvmlite.LLVMType | t.CPtr = llvmlite.Void(pool)
if output_count > 0 and first_output_idx >= 0:
out_op: AsmOperand | t.CPtr = _asm_get_operand(operands, first_output_idx)
stdio.printf("[R] out_idx=%d out_op=%lld Val=%lld\n",
first_output_idx, t.CInt64T(out_op), t.CInt64T(out_op.Value))
stdio.fflush(0)
if out_op.Value is not None and out_op.Value.Ty is not None:
# alloca 的类型是指针Pointee 是目标类型
if out_op.Value.Ty.Pointee is not None:
@@ -2352,6 +2343,11 @@ def _call_method_on_ptr(pool: memhub.MemBuddy | t.CPtr,
frt: llvmlite.LLVMType | t.CPtr = llvmlite.function_get_ret_ty(found_func)
if frt is not None:
call_ret_ty = frt
else:
# found_func 为 None跨模块调用 stub 未注入):根据方法名推断返回类型
# __new__ 返回 Ptr(struct_ty),其他方法默认 void
if string.strcmp(method_name, "__new__") == 0 and cmop_struct_ty is not None:
call_ret_ty = llvmlite.Ptr(pool, cmop_struct_ty)
# 构建参数链表: self_ptr → extra_args...
llvmlite.value_set_next(self_ptr, None)
@@ -2449,9 +2445,15 @@ def _infer_method_ret_ty(pool: memhub.MemBuddy | t.CPtr,
# 返回 void 的方法
if string.strcmp(method_name, "__before_init__") == 0:
return llvmlite.Void(pool)
if string.strcmp(method_name, "__init__") == 0:
return llvmlite.Void(pool)
if string.strcmp(method_name, "__exit__") == 0:
return llvmlite.Void(pool)
# 默认 i32free, reset, __init__, __exit__, _fl_push 等
return llvmlite.Int32(pool)
# 默认 i64整数既可安全截断为 i32trunc也可转换为指针inttoptr
# 避免使用指针类型i8*)导致 coerce_to_type 生成 load解引用造成崩溃
# x86-64 ABI 中 i32 返回值在 rax 低 32 位i64 读取后 trunc 取低 32 位是安全的
return llvmlite.Int64(pool)
# ============================================================
# _translate_method_call - 翻译方法调用 obj.method(args)