diff --git a/App/lib/core/Gen/CallGenBase.vp b/App/lib/core/Gen/CallGenBase.vp index 8f3c694..c9733f9 100644 --- a/App/lib/core/Gen/CallGenBase.vp +++ b/App/lib/core/Gen/CallGenBase.vp @@ -126,11 +126,6 @@ class CallGenBase: # ============================================================ - # ============================================================ - # P4 簇 1+2 迁移方法(函数体来自 HandlesExprCall.vp: - # 模块 SHA1 查询/CExport 注册表/c.* 系列/内联汇编/LLVMIR) - # 本模块函数调用改 self.,外部模块调用保留模块前缀 - # ============================================================ def _lookup_module_sha1(self, mod_name: str) -> str: """查找模块名对应的 SHA1,找不到返回 None @@ -578,13 +573,6 @@ class CallGenBase: # 无需硬编码白名单——返回类型始终来自方法定义处。 # ============================================================ - # ============================================================ - # _lookup_method_ret_ty_via_vpi - 从 vpi stub 返回注解缓存精确获取方法返回类型 - # - # 方法定义处(.vpi stub)的返回注解(如 json.JsonValue._pool_alloc → - # "str")在 stub 注入时由 VpiReader 缓存(_cache_vpi_return_annots_text)。 - # 此函数按 模块SHA1 + 类名 + 方法名 查缓存并纯字符串解析为 LLVMType。 - # 无需硬编码白名单——返回类型始终来自方法定义处。 # ============================================================ def _lookup_method_ret_ty_via_vpi(self, pool: memhub.MemBuddy | t.CPtr, cls_sha1: str, @@ -618,16 +606,6 @@ class CallGenBase: # 在此直接固定,不触发 fail-fast 误报。非特殊方法返回 None。 # ============================================================ - # ============================================================ - # _special_method_ret_ty - 编译器内置特殊方法的固定返回类型 - # - # __before_init__ / __init__:编译器生成/约定返回 void - # __new__:返回 Ptr(StructTy)(存储空间指针) - # - # 这些方法不存在于源码(vpi stub 无条目),跨模块调用时 - # found_func/text.ll/vpi 缓存必然未命中,但返回类型是编译器 - # 确定性语义(与 HandlesClassDef._translate_method 3543-3548 一致), - # 在此直接固定,不触发 fail-fast 误报。非特殊方法返回 None。 # ============================================================ def _special_method_ret_ty(self, pool: memhub.MemBuddy | t.CPtr, class_name: str, @@ -655,13 +633,6 @@ class CallGenBase: # node: 调用点 AST 节点(可选,用于 ERROR 堆栈定位) # ============================================================ - # ============================================================ - # _fail_method_ret_ty - 方法返回类型无法精确获取时 fail-fast - # - # 返回类型来源(按序):当前模块函数 → text.ll define → vpi stub 返回注解缓存。 - # 全部未命中时立即 ERROR + 错误堆栈终止,绝不按名推断白名单/静默默认 i32。 - # - # node: 调用点 AST 节点(可选,用于 ERROR 堆栈定位) # ============================================================ def _fail_method_ret_ty(self, method_name: str, node: ast.AST | t.CPtr = None) -> llvmlite.LLVMType | t.CPtr: @@ -686,11 +657,6 @@ class CallGenBase: # 能够读取依赖模块的 text.ll 文件。 # ============================================================ - # ============================================================ - # SetTempDir - 设置 temp 目录路径 - # - # 在 Phase2.py 的 Phase A 翻译前调用,使 CallGenMixin - # 能够读取依赖模块的 text.ll 文件。 # ============================================================ def SetTempDir(self, temp_dir: str): """设置 temp 目录路径(供跨模块方法返回类型查找使用)""" @@ -722,26 +688,6 @@ class CallGenBase: # LLVM 类型对象,或 None(无法解析) # ============================================================ - # ============================================================ - # _ParseLLVMRetTyStr - 将 LLVM IR 返回类型字符串转换为 llvmlite.LLVMType - # - # 从 define 行中提取的返回类型字符串(define 与 @ 之间的内容), - # 转换为 llvmlite.LLVMType 对象。 - # - # 支持的类型: - # void → Void - # i8/i16/i32/i64 → Int8/Int16/Int32/Int64 - # double → Double, float → Float - # 任何含 * 的类型 → Ptr(Int8)(通用指针,保留 64 位地址) - # - # Args: - # pool: 内存池 - # buf: 包含类型字符串的缓冲区 - # start: 类型字符串起始位置 - # end: 类型字符串结束位置(不含) - # - # Returns: - # LLVM 类型对象,或 None(无法解析) # ============================================================ def _ParseLLVMRetTyStr(self, pool: memhub.MemBuddy | t.CPtr, buf: bytes, @@ -880,25 +826,6 @@ class CallGenBase: # LLVM 类型对象,或 None(未找到/text.ll 不存在) # ============================================================ - # ============================================================ - # _LookupMethodRetTyFromTextLL - 从依赖模块的 text.ll 查找方法返回类型 - # - # 读取 {temp_dir}/{sha1[0:2]}/{sha1}.text.ll (level=1),搜索 - # define 行中包含 "{sha1}.{class_name}.{method_name}" 的函数, - # 提取返回类型并转换为 llvmlite.LLVMType。 - # - # 解决问题: 旧实现 _infer_method_ret_ty(已移除)默认返回 i32,导致指针返回值 - # 被 inttoptr 截断为 32 位(coerce_to_type line 238-239)。 - # 本函数从 text.ll 获取实际返回类型,避免截断。 - # - # Args: - # pool: 内存池 - # class_sha1: 类所属模块的 SHA1 - # class_name: 类名 - # method_name: 方法名 - # - # Returns: - # LLVM 类型对象,或 None(未找到/text.ll 不存在) # ============================================================ def _LookupMethodRetTyFromTextLL(self, pool: memhub.MemBuddy | t.CPtr, class_sha1: str, @@ -1039,13 +966,6 @@ class CallGenBase: # main.vp 先于其 import 的 mbuddytest.vp),标记重试待下遍 # ============================================================ - # ============================================================ - # _dep_text_ll_exists - 探测依赖模块 text.ll 是否已生成 - # - # 用于区分跨模块返回类型精确解析失败的两种场景: - # 1. text.ll 存在但函数未命中 → 真错误(依赖已编译,函数缺失) - # 2. text.ll 不存在 → 依赖模块尚未翻译(Phase A 按文件顺序翻译, - # main.vp 先于其 import 的 mbuddytest.vp),标记重试待下遍 # ============================================================ def _dep_text_ll_exists(self, pool: memhub.MemBuddy | t.CPtr, sha1: str) -> int: diff --git a/App/lib/core/Gen/CallGenCall.vp b/App/lib/core/Gen/CallGenCall.vp index 35c3b44..e91e83f 100644 --- a/App/lib/core/Gen/CallGenCall.vp +++ b/App/lib/core/Gen/CallGenCall.vp @@ -61,23 +61,6 @@ class CallGenCall(CallGenBase.CallGenBase): # ret_ty — 返回类型 # ============================================================ - # ============================================================ - # _do_virtual_call — 通过虚表间接调用虚方法 - # - # IR 模式: - # %1 = getelementptr StructTy, StructTy* %self, i32 0, i32 0 ; i8** - # %2 = load i8*, i8** %1 ; i8* (vtable ptr) - # %3 = bitcast i8* %2 to {i8*, ...}* ; vtable typed ptr - # %4 = getelementptr {i8*, ...}, {i8*, ...}* %3, i32 0, i32 N ; i8** - # %5 = load i8*, i8** %4 ; i8* (func ptr) - # %6 = bitcast i8* %5 to RetTy(Params)* ; func typed ptr - # call RetTy %6(Params %self, ...) - # - # 参数: - # args_head — 已构建好的参数链表头(self_ptr 为首节点) - # args_count — 参数总数(含 self) - # found_func — 方法对应的 Function 对象(用于推断函数签名) - # ret_ty — 返回类型 # ============================================================ def _do_virtual_call(self, pool: memhub.MemBuddy | t.CPtr, builder: llvmlite.IRBuilder | t.CPtr, @@ -238,11 +221,6 @@ class CallGenCall(CallGenBase.CallGenBase): # 如果该方法在虚表中,则走虚方法分发路径(间接调用) # ============================================================ - # ============================================================ - # _call_method_on_ptr — 在结构体指针上调用方法 - # - # 辅助函数:构造 ClassName.method_name 调用,self 指针为首个参数 - # 如果该方法在虚表中,则走虚方法分发路径(间接调用) # ============================================================ def _call_method_on_ptr(self, pool: memhub.MemBuddy | t.CPtr, builder: llvmlite.IRBuilder | t.CPtr, @@ -593,12 +571,6 @@ class CallGenCall(CallGenBase.CallGenBase): # obj_ptr 是对象变量的 alloca(Ptr(StructTy)),作为 self 参数传入 # ============================================================ - # ============================================================ - # _translate_method_call - 翻译方法调用 obj.method(args) - # - # 生成: call @SHA1.ClassName.method_name(Ptr(StructTy) %obj, args...) - # - # obj_ptr 是对象变量的 alloca(Ptr(StructTy)),作为 self 参数传入 # ============================================================ def _translate_method_call(self, pool: memhub.MemBuddy | t.CPtr, builder: llvmlite.IRBuilder | t.CPtr, @@ -1274,16 +1246,6 @@ class CallGenCall(CallGenBase.CallGenBase): # - 静态调用父类实现:不虚分派(super() 不触发子类 override) # ============================================================ - # ============================================================ - # _translate_super_call — super().method(args) → 静态调用父类方法 - # - # Python super 语义(2026-08-10 实现): - # - 当前类来自 self.CurClassName(_translate_method 翻译方法体时设置) - # - 父类查找:沿 get_mro_chain(CurClassName) 跳过自身,找第一个定义 method 的祖先 - # - self 指针:符号表 self 变量 alloca load(对象头,复用 c.Addr(self) 模式) - # - this_adjust:父类字段区在子类中字节偏移 delta>0 时 GEP i8* + delta - # (复用 _field_byte_offset 字节偏移法,与 _translate_method_call 一致) - # - 静态调用父类实现:不虚分派(super() 不触发子类 override) # ============================================================ def _translate_super_call(self, pool: memhub.MemBuddy | t.CPtr, builder: llvmlite.IRBuilder | t.CPtr, @@ -1512,12 +1474,6 @@ class CallGenCall(CallGenBase.CallGenBase): # 供多继承 this 调整(字节偏移法)计算 delta。 # ============================================================ - # ============================================================ - # _field_byte_offset — 计算字段在结构体布局中的字节偏移 - # - # 按 LLVM 布局遍历 struct elements 带对齐累加(与 ClassGenMixin._get_type_size - # 的 padding 规则一致)。field_index 是 FieldEntry.Index(OOP 类 __vtable__ 占 0)。 - # 供多继承 this 调整(字节偏移法)计算 delta。 # ============================================================ def _field_byte_offset(self, pool: memhub.MemBuddy | t.CPtr, entry: HandlesStruct.StructEntry | t.CPtr, diff --git a/App/lib/core/Gen/CallGenCtor.vp b/App/lib/core/Gen/CallGenCtor.vp index 035e276..5640472 100644 --- a/App/lib/core/Gen/CallGenCtor.vp +++ b/App/lib/core/Gen/CallGenCtor.vp @@ -121,17 +121,6 @@ class CallGenCtor(CallGenBase.CallGenBase): # %result = load {i32, i32}, {i32, i32}* %tmp # ============================================================ - # ============================================================ - # _translate_struct_ctor — 结构体构造函数 Point(10, 20) - # - # 生成: - # %tmp = alloca {i32, i32} - # store {i32, i32} zeroinitializer, {i32, i32}* %tmp - # %f0 = getelementptr {i32, i32}, {i32, i32}* %tmp, i32 0, i32 0 - # store i32 10, i32* %f0 - # %f1 = getelementptr {i32, i32}, {i32, i32}* %tmp, i32 0, i32 1 - # store i32 20, i32* %f1 - # %result = load {i32, i32}, {i32, i32}* %tmp # ============================================================ def _translate_struct_ctor(self, pool: memhub.MemBuddy | t.CPtr, builder: llvmlite.IRBuilder | t.CPtr, @@ -384,23 +373,6 @@ class CallGenCtor(CallGenBase.CallGenBase): # 对应 TPC 的 _HandleREnumConstructLlvm # ============================================================ - # ============================================================ - # _translate_renum_construct — REnum 变体构造函数 - # - # 语法: ClassName.VariantName(args...) - # 如 LLVMType.Int(1) → 构造 LLVMType 的 Int 变体,__tag=0,_p1=1 - # - # 生成 IR: - # %tmp = alloca {i32, i32, ...} ; REnum 类型 - # store zeroinitializer, %tmp ; 清零 - # %tag_ptr = gep %tmp, 0, 0 ; __tag 字段 - # store i32 , %tag_ptr ; 写入 tag - # %p1_ptr = gep %tmp, 0, 1 ; _p1 字段 - # store , %p1_ptr ; 写入 payload[0] - # ... (更多 payload 字段) - # return %tmp ; 返回指针 - # - # 对应 TPC 的 _HandleREnumConstructLlvm # ============================================================ def _translate_renum_construct(self, pool: memhub.MemBuddy | t.CPtr, builder: llvmlite.IRBuilder | t.CPtr, @@ -505,14 +477,6 @@ class CallGenCtor(CallGenBase.CallGenBase): # 位置参数按字段索引赋值,关键字参数按字段名查找赋值 # ============================================================ - # ============================================================ - # _translate_struct_ctor_kw — 结构体构造函数(关键字参数) - # - # 支持两种语法: - # Point(x=10, y=20) — 全关键字 - # Point(10, y=20) — 混合(位置 + 关键字) - # - # 位置参数按字段索引赋值,关键字参数按字段名查找赋值 # ============================================================ def _translate_struct_ctor_kw(self, pool: memhub.MemBuddy | t.CPtr, builder: llvmlite.IRBuilder | t.CPtr, @@ -745,18 +709,6 @@ class CallGenCtor(CallGenBase.CallGenBase): # - 浮点 → 浮点: fpext/fptrunc (如 t.CFloat(double_val) → float) # ============================================================ - # ============================================================ - # _translate_t_type_cast - 翻译 t.XXX(value) 类型转换 - # - # 当 func 是 t.XXX 形式且 XXX 是已知类型名(map_t_type 能映射)时, - # 将 value 转换为目标类型: - # - 指针 → 整数: ptrtoint (如 t.CUInt64T(ptr) → i64) - # - 整数 → 指针: inttoptr (如 t.CPtr(int_val) → i8*) - # - 整数 → 整数: trunc/zext (如 t.CInt8T(i32_val) → i8) - # - 指针 → 指针: bitcast (如 t.CPtr(ptr_val) → i8*) - # - 整数 → 浮点: sitofp (如 t.CDouble(i32_val) → double) - # - 浮点 → 整数: fptosi (如 t.CInt(double_val) → i32) - # - 浮点 → 浮点: fpext/fptrunc (如 t.CFloat(double_val) → float) # ============================================================ def _translate_t_type_cast(self, pool: memhub.MemBuddy | t.CPtr, builder: llvmlite.IRBuilder | t.CPtr, @@ -887,20 +839,6 @@ class CallGenCtor(CallGenBase.CallGenBase): # 且缺少 __new__ 方法名后缀,导致链接报 undefined reference。 # ============================================================ - # ============================================================ - # 泛型类构造调用辅助: list[str](pool, 8) → __new__ + __before_init__ + __init__ - # - # 复用 translate_list_literal 的构造逻辑: - # 1. alloca tmp(特化类临时空间,作为 __new__ 的 self) - # 2. 翻译 cl.args 为参数指针数组 - # 3. call __new__(tmp, *args) → storage_ptr - # 4. call __before_init__(storage_ptr) - # 5. call __init__(storage_ptr, *args) - # 6. return storage_ptr - # - # 必须独立于 translate_call 的普通函数路径:spec_name 是类名不是函数名, - # 走裸名路径会被 _lookup_mod_sha1 的 star import 回退误导,用错误的 SHA1 - # 且缺少 __new__ 方法名后缀,导致链接报 undefined reference。 # ============================================================ def _infer_generic_ctor_type_arg(self, pool: memhub.MemBuddy | t.CPtr, arg_node: ast.AST | t.CPtr, diff --git a/App/lib/core/Gen/CallGenFd.vp b/App/lib/core/Gen/CallGenFd.vp index 699f28a..8c702fd 100644 --- a/App/lib/core/Gen/CallGenFd.vp +++ b/App/lib/core/Gen/CallGenFd.vp @@ -50,15 +50,6 @@ class CallGenFd(CallGenBase.CallGenBase): # bitcast i8* → _str* 读取垃圾指针导致 ACCESS_VIOLATION。 # ============================================================ - # ============================================================ - # _translate_fakeduck_call - FakeDuck: str 变量方法调用 → 扩展类 _Type/_str - # - # 对齐 TPC HandlesExprCall.py L2841-2880: - # ClassName 常规解析失败且对象是 char*(i8*)时,遍历扩展类查找 - # {CN}.{method} 函数。对象是 Name 变量且有影子({var}__meta__,fd2 - # 创建)时 self=影子;否则(字符串字面量/匿名 str)在入口创建临时 - # 影子,写 __data__=obj 值、__mbuddy__=NULL 后作 self,避免 - # bitcast i8* → _str* 读取垃圾指针导致 ACCESS_VIOLATION。 # ============================================================ def _translate_fakeduck_call(self, pool: memhub.MemBuddy | t.CPtr, builder: llvmlite.IRBuilder | t.CPtr, @@ -223,15 +214,6 @@ class CallGenFd(CallGenBase.CallGenBase): # _withcontent)时跳过注入,不影响非 with 场景。 # ============================================================ - # ============================================================ - # _inject_requires_fields - FakeDuck: with 上下文注入 requires 字段 - # - # 对齐 TPC HandlesExprCall.py L4021-4079: - # 对类 __requires__ 元数据(fd1 注册)中的每个字段,运行时调用 - # _find_provider(field) 查找 with 上下文提供的指针;非 NULL 时 - # bitcast 到字段类型写入 meta_ptr 对应槽位(条件注入,避免覆盖 - # 用户已手动设置的值)。_find_provider 未注册(未 import - # _withcontent)时跳过注入,不影响非 with 场景。 # ============================================================ def _inject_requires_fields(self, trans: HT.Translator | t.CPtr, pool: memhub.MemBuddy | t.CPtr, @@ -343,14 +325,6 @@ class CallGenFd(CallGenBase.CallGenBase): # 维护 TLS provider 栈,供 _inject_requires_fields 查找。 # ============================================================ - # ============================================================ - # _emit_provider_push / _emit_provider_pop - FakeDuck: with 上下文 - # provider push/pop(__provides__ 元数据,fd1 注册) - # - # 对齐 TPC HandlesWith.py L138-174: - # with 进入时对每个提供字段生成 _push_provider(field_str, ctx_i8); - # 退出时生成等量 _pop_provider()。运行时 _withcontent 模块负责 - # 维护 TLS provider 栈,供 _inject_requires_fields 查找。 # ============================================================ def _emit_provider_push(self, trans: HT.Translator | t.CPtr, pool: memhub.MemBuddy | t.CPtr, diff --git a/App/lib/core/Gen/CallGenLeafKit.vp b/App/lib/core/Gen/CallGenLeafKit.vp index 64fb670..2ab63c9 100644 --- a/App/lib/core/Gen/CallGenLeafKit.vp +++ b/App/lib/core/Gen/CallGenLeafKit.vp @@ -105,22 +105,6 @@ class CallGenLeafKit(CallGenCBuiltin.CallGenCBuiltin): # 否则仅返回默认值);未命中 → ok 块继续 # ============================================================ - # ============================================================ - # _emit_eh_guarded_call - 调用侧 try-except EH 检测(对齐 TPC - # HandlesExprCall._append_eh_msg_out_arg + _check_eh_return) - # - # 被调函数带 EH 输出参数时: - # 1. 确定 msg/code 输出指针: - # - 当前在 try(trans._eh_dispatch_bb 非空):复用 try 的 - # eh_message/exception_code alloca——被调函数直接写入,检查 - # 路径读同一 alloca 即得异常,无需搬运 - # - 当前函数有 EH 输出参数:复用本函数 out 参数(异常直接写进 - # 本函数输出,检查命中后仅返回,由调用方接管传播) - # - 两者皆无:局部 null alloca(异常被吞) - # 2. 调用前清零输出指针(复用 alloca 必须复位,防上次残留误判) - # 3. 追加 msg/code 两个实参(count+2) - # 4. 调用后检查 msg != null:命中 → err 块(try 内分支 DispatchBB; - # 否则仅返回默认值);未命中 → ok 块继续 # ============================================================ def _emit_eh_guarded_call(self, builder: llvmlite.IRBuilder | t.CPtr, pool: memhub.MemBuddy | t.CPtr, @@ -246,16 +230,6 @@ class CallGenLeafKit(CallGenCBuiltin.CallGenCBuiltin): # ============================================================ - # ============================================================ - # isinstance - 运行时 vtable 子类集合比较(2026-08-10) - # - # CVTable 对象头部 vtable 指针唯一标识对象实际类。isinstance(obj, Cls) - # 语义 = Cls 是实际类的祖先(实际类 == Cls 或继承自 Cls)。运行时只能 - # 拿到实际类 vtable 地址,无法向上推导祖先链,因此在编译期沿 - # StructEntry.ParentNames 反向 BFS 枚举 Cls 的全部已知子类(含自身), - # 运行时比较 obj->vtable ∈ {Cls 子类 vtable 地址集合}。 - # NoVTable / 未知类回退编译时静态判断(obj 静态类型 MRO 判断)。 - # ============================================================ def _translate_isinstance(self, pool: memhub.MemBuddy | t.CPtr, builder: llvmlite.IRBuilder | t.CPtr, @@ -531,11 +505,6 @@ class CallGenLeafKit(CallGenCBuiltin.CallGenCBuiltin): # ============================================================ - # ============================================================ - # P4 簇 5+6 迁移方法(函数体来自 HandlesExprCall.vp: - # 闭包调用/函数指针/printf/print/stdarg 糖/变长参数提升/函数表/全局注册表) - # 本模块函数调用改 self.,外部模块调用保留模块前缀,全局变量改 self 字段 - # ============================================================ def translate_closure_call(self, pool: memhub.MemBuddy | t.CPtr, builder: llvmlite.IRBuilder | t.CPtr, diff --git a/App/lib/core/Gen/CallGenLib.vp b/App/lib/core/Gen/CallGenLib.vp index e1e7a46..c432acf 100644 --- a/App/lib/core/Gen/CallGenLib.vp +++ b/App/lib/core/Gen/CallGenLib.vp @@ -473,17 +473,6 @@ class CallGenLib(CallGenBase.CallGenBase): # 3. 按参数顺序构建调用参数链表 # ============================================================ - # ============================================================ - # _translate_call_with_kwargs — 带关键字参数的函数调用 - # - # 支持两种语法: - # add(b=4, a=3) — 全关键字乱序 - # greet("Hello", name="World") — 位置 + 关键字混合 - # - # 策略: 遍历 found_func.Params 链表,对每个参数: - # 1. 若位置参数仍有剩余(param_idx < can),取位置参数 - # 2. 否则按参数名匹配关键字参数 - # 3. 按参数顺序构建调用参数链表 # ============================================================ def _translate_call_with_kwargs(self, pool: memhub.MemBuddy | t.CPtr, builder: llvmlite.IRBuilder | t.CPtr, diff --git a/App/lib/core/Gen/CallGenProp.vp b/App/lib/core/Gen/CallGenProp.vp index e08fb94..ab5096b 100644 --- a/App/lib/core/Gen/CallGenProp.vp +++ b/App/lib/core/Gen/CallGenProp.vp @@ -177,12 +177,6 @@ class CallGenProp(CallGenBase.CallGenBase): # 供属性访问/赋值/删除识别 property 时使用。 # ============================================================ - # ============================================================ - # _resolve_obj_class_name — 解析对象表达式的类名(短名) - # - # 优先从变量注解(AnnotClassName)解析(如 "memhub.MemBuddy" → "MemBuddy"), - # 失败时从 LLVM 类型解析(Ptr(Struct) → 类名)。 - # 供属性访问/赋值/删除识别 property 时使用。 # ============================================================ def _resolve_obj_class_name(self, pool: memhub.MemBuddy | t.CPtr, trans: HT.Translator | t.CPtr, @@ -209,11 +203,6 @@ class CallGenProp(CallGenBase.CallGenBase): # 若有则生成 call Class.attr(obj) 并返回调用结果 Value;否则返回 None。 # ============================================================ - # ============================================================ - # _try_property_getter_attr — 尝试将 obj.attr 翻译为 property getter 调用 - # - # 检查 obj 的类是否有 @property/@x.getter 的 attr 方法; - # 若有则生成 call Class.attr(obj) 并返回调用结果 Value;否则返回 None。 # ============================================================ def _try_property_getter_attr(self, pool: memhub.MemBuddy | t.CPtr, builder: llvmlite.IRBuilder | t.CPtr, @@ -247,11 +236,6 @@ class CallGenProp(CallGenBase.CallGenBase): # 若有则生成 call Class.attr$set(obj, v),返回 1;否则返回 0。 # ============================================================ - # ============================================================ - # _try_property_setter — 尝试将 obj.attr = v 翻译为 property setter 调用 - # - # 检查 obj 的类是否有 @x.setter 的 attr 方法; - # 若有则生成 call Class.attr$set(obj, v),返回 1;否则返回 0。 # ============================================================ def _try_property_setter(self, pool: memhub.MemBuddy | t.CPtr, builder: llvmlite.IRBuilder | t.CPtr, @@ -294,11 +278,6 @@ class CallGenProp(CallGenBase.CallGenBase): # 若有则生成 call Class.attr$del(obj),返回 1;否则返回 0。 # ============================================================ - # ============================================================ - # _try_property_deleter — 尝试将 del obj.attr 翻译为 property deleter 调用 - # - # 检查 obj 的类是否有 @x.deleter 的 attr 方法; - # 若有则生成 call Class.attr$del(obj),返回 1;否则返回 0。 # ============================================================ def _try_property_deleter(self, pool: memhub.MemBuddy | t.CPtr, builder: llvmlite.IRBuilder | t.CPtr, @@ -337,11 +316,6 @@ class CallGenProp(CallGenBase.CallGenBase): # @classmethod: 在参数前插入栈上分配的类实例指针(与 TPC 一致) # ============================================================ - # ============================================================ - # _translate_static_class_call — 翻译 ClassName.method(args) 静态/类方法调用 - # - # @staticmethod: 直接 call Class.method(args...),无 self - # @classmethod: 在参数前插入栈上分配的类实例指针(与 TPC 一致) # ============================================================ def _translate_static_class_call(self, pool: memhub.MemBuddy | t.CPtr, builder: llvmlite.IRBuilder | t.CPtr, @@ -424,17 +398,6 @@ class CallGenProp(CallGenBase.CallGenBase): # 返回: 1=list 内置方法(应落到 list 内置分支),0=普通方法 # ============================================================ - # ============================================================ - # _is_list_builtin_method - 判断是否是 list 泛型内置容器方法 - # - # list[T] 是内置泛型容器(_list.vp),其方法(append/get/set/pop/clear/ - # __iter__/__len__/__getitem__/__setitem__)由 translate_call 的 list - # 内置分支内联 GEP 处理,不注册为方法函数。若 obj.method() 检测把 - # list 特化 struct(如 list[AST | CPtr])误当普通结构体走 - # _translate_method_call,会查不到 append 返回类型 → fail-fast - # (NewAstTest body.append 根因)。此判断用于跳过 method_call 路径。 - # - # 返回: 1=list 内置方法(应落到 list 内置分支),0=普通方法 # ============================================================ def _is_list_builtin_method(self, class_name: str, method_name: str) -> int: diff --git a/App/lib/core/Gen/CallGenVt.vp b/App/lib/core/Gen/CallGenVt.vp index 423dbc3..c8feb73 100644 --- a/App/lib/core/Gen/CallGenVt.vp +++ b/App/lib/core/Gen/CallGenVt.vp @@ -54,17 +54,6 @@ class CallGenVt(CallGenBase.CallGenBase): # 跳过复制直接写槽位)。 # ============================================================ - # ============================================================ - # _write_vtable_slot / _write_vtable_attr — vtable 方法槽位直接写入 - # - # serial0_file.open = serial0_open(devfs 驱动注册模式):把模块级函数 - # 指针写入对象 vtable 的方法槽位。vtable 方法不是数据字段(FieldEntry), - # get_attribute_ptr 查不到 → 此前 fatal_error "属性写入失败"。 - # 对齐 TPC HandlesAssign.py L905-949 的写时复制: - # 对象 vtable 仍指向类默认 vtable 时,先复制一份(internal 全局 + - # llvm.memcpy)并让对象指向副本,再 GEP method_index 槽位 store - # 函数指针(i8*)。多次写入互不覆盖(第二次起 vtable 已非默认, - # 跳过复制直接写槽位)。 # ============================================================ def _write_vtable_slot(self, pool: memhub.MemBuddy | t.CPtr, builder: llvmlite.IRBuilder | t.CPtr,