实现了 TPV 的 pyi 生成逻辑(部分),删除了直接拷贝自 CPython(TPC) 版本的死代码
This commit is contained in:
@@ -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)
|
||||
|
||||
# 默认 i32(free, reset, __init__, __exit__, _fl_push 等)
|
||||
return llvmlite.Int32(pool)
|
||||
# 默认 i64(整数):既可安全截断为 i32(trunc),也可转换为指针(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)
|
||||
|
||||
Reference in New Issue
Block a user