From 1ad7abf33ddac9c76db507cabfec1c349fecca3c Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Fri, 2 Oct 2026 02:16:37 +0800 Subject: [PATCH] =?UTF-8?q?refactor(TransPyV):=20=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E8=87=AA=E4=B8=BE=E5=86=99=E6=B3=95=EF=BC=88novirtual=20/=20de?= =?UTF-8?q?fine=20/=20rawptr=E2=86=92*=20/=20=E5=8E=BB=E7=BB=AD=E8=A1=8C?= =?UTF-8?q?=E5=8F=8D=E6=96=9C=E6=9D=A0=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - @t.NoVTable class X → novirtual class X - t.CDefine = N → define N - rawptr[X]、X | t.CPtr → X* - t.CPtr → rawptr(裸指针标记) - t.Callable[...] → callable[...] - 去掉 if/elif 条件的行续反斜杠(改单行写法) - w32.win32file.X → win32file.X(已 import as) - core/__init__.vp 去掉未使用的 import t, c / from stdint import * 涉及:CompilerFactory、IncludesScanner、Repl、core/__init__、 Gen/Call/{CallGenBase,CallGenCBuiltin,CallGenCall,CallGenDispatch,CallGenLeafKit}、 Gen/Class/ClassGenGeneric。 --- App/lib/core/CompilerFactory.vp | 5 +- App/lib/core/Gen/Call/CallGenBase.vp | 29 ++-- App/lib/core/Gen/Call/CallGenCBuiltin.vp | 23 +-- App/lib/core/Gen/Call/CallGenCall.vp | 180 ++++++++++------------ App/lib/core/Gen/Call/CallGenDispatch.vp | 42 ++--- App/lib/core/Gen/Call/CallGenLeafKit.vp | 3 +- App/lib/core/Gen/Class/ClassGenGeneric.vp | 1 - App/lib/core/IncludesScanner.vp | 75 ++++----- App/lib/core/Repl.vp | 18 +-- App/lib/core/__init__.vp | 3 - 10 files changed, 156 insertions(+), 223 deletions(-) diff --git a/App/lib/core/CompilerFactory.vp b/App/lib/core/CompilerFactory.vp index 9b8585c..2edc91d 100644 --- a/App/lib/core/CompilerFactory.vp +++ b/App/lib/core/CompilerFactory.vp @@ -5,8 +5,7 @@ import memhub # ============================================================ # CompilerFactory - 编译器结构体工厂(对齐 TPC Translator 装配模式) # ============================================================ -@t.NoVTable -class CompilerFactory: +novirtual class CompilerFactory: """编译器结构体工厂(持有主池/永久池等共享对象)""" Pool: memhub.MemBuddy* # 主内存池(瞬时数据,mark/reset 回收) PermPool: memhub.MemBuddy* # 永久内存池(持久数据,从不 reset) @@ -32,4 +31,4 @@ class CompilerFactory: self.PermPool = perm_pool # 全局工厂单例 -factory: rawptr[CompilerFactory] = None +factory: CompilerFactory* = None diff --git a/App/lib/core/Gen/Call/CallGenBase.vp b/App/lib/core/Gen/Call/CallGenBase.vp index 645fde4..f6da577 100644 --- a/App/lib/core/Gen/Call/CallGenBase.vp +++ b/App/lib/core/Gen/Call/CallGenBase.vp @@ -200,8 +200,7 @@ novirtual class CallGenBase: if pos < total: pos += 1 # 自含定义检测(须在 from-import 行匹配之前,对所有行生效):模块级 def 行首无缩进,类内方法 def 有缩进不会误命中 - if ll > 4 and buf[ls] == 'd' and buf[ls + 1] == 'e' \ - and buf[ls + 2] == 'f' and buf[ls + 3] == ' ': + if ll > 4 and buf[ls] == 'd' and buf[ls + 1] == 'e' and buf[ls + 2] == 'f' and buf[ls + 3] == ' ': fstart_od: sizet = ls + 4 fend_od: sizet = fstart_od while fend_od < ls + ll and buf[fend_od] != '(' and buf[fend_od] != ' ': @@ -226,9 +225,7 @@ novirtual class CallGenBase: # 找 " import " 分隔符 imp_pos: sizet = ls + 5 while imp_pos + 7 <= ls + ll: - if buf[imp_pos] == ' ' and buf[imp_pos + 1] == 'i' and buf[imp_pos + 2] == 'm' and \ - buf[imp_pos + 3] == 'p' and buf[imp_pos + 4] == 'o' and buf[imp_pos + 5] == 'r' and \ - buf[imp_pos + 6] == 't' and buf[imp_pos + 7] == ' ': + if buf[imp_pos] == ' ' and buf[imp_pos + 1] == 'i' and buf[imp_pos + 2] == 'm' and buf[imp_pos + 3] == 'p' and buf[imp_pos + 4] == 'o' and buf[imp_pos + 5] == 'r' and buf[imp_pos + 6] == 't' and buf[imp_pos + 7] == ' ': break imp_pos += 1 if imp_pos + 7 > ls + ll: @@ -453,8 +450,7 @@ novirtual class CallGenBase: """ if sha1 is None or func_name is None: return 0 - if self.Gen is None or self.Gen.CallGenBase.TempDir is None \ - or self.Gen.CallGenBase.TempDirLen <= 0: + if self.Gen is None or self.Gen.CallGenBase.TempDir is None or self.Gen.CallGenBase.TempDirLen <= 0: return 0 VpiReader._ensure_vpi_ret_annot_loaded(sha1, self.Gen.CallGenBase.TempDir) cexp_annot: str = VpiReader._lookup_vpi_ret_annot(sha1, None, func_name) @@ -657,8 +653,7 @@ novirtual class CallGenBase: VLogger.repl_abort() if existing.Name is not None: # 快速路径:strcmp 判等蕴含首字符相等,首字符不同者跳过 strcmp - if existing.Name[0] == call_name[0] \ - and string.strcmp(existing.Name, call_name) == 0: + if existing.Name[0] == call_name[0] and string.strcmp(existing.Name, call_name) == 0: # 已存在:仅当是 declare 且参数数量不足时追加缺失参数 if existing.IsDeclared == 1: # 变长函数(*args,IsVarArg=1)不追加参数:多余实参由 @@ -703,11 +698,11 @@ novirtual class CallGenBase: func: llvmlite.Function* = llvmlite.new_function(pool, call_name, ret_ty) if func is None: return func.IsDeclared = 1 - # 定义侧参数类型优先:从 call_name 提取 {sha1}.{cls}.{method} 查 vpi 参数注解取定义侧类型。 - # · 整数:仅当定义宽度更宽时采用定义宽度(反方向由 CallGenLib._coerce_args_to_def_params 在调用点先窄化实参) - # · 指针:**一律采用定义侧类型**——declare 被同模块所有调用点共用,若沿用"首个调用点的实参类型", - # 后续调用传入别的具体指针类型就会被这条被冻住的形参类型 coerce,报"非基本类型指针间隐式转换" - # (现场 VarGenMixin.repl_ensure_entry 的 node: ast.AST*:先被 translate_annassign 以 AnnAssign* + # 定义侧参数类型优先:从 call_name 提取 {sha1}.{cls}.{method} 查 vpi 参数注解取定义侧类型。 + # · 整数:仅当定义宽度更宽时采用定义宽度(反方向由 CallGenLib._coerce_args_to_def_params 在调用点先窄化实参) + # · 指针:**一律采用定义侧类型**——declare 被同模块所有调用点共用,若沿用"首个调用点的实参类型", + # 后续调用传入别的具体指针类型就会被这条被冻住的形参类型 coerce,报"非基本类型指针间隐式转换" + # (现场 VarGenMixin.repl_ensure_entry 的 node: ast.AST*:先被 translate_annassign 以 AnnAssign* # 建 declare,后 translate_assign 传 AST* 即报"源类型 …AST* → 目标类型 …AnnAssign*") sha1_d: str = None cls_d: str = None @@ -832,8 +827,7 @@ novirtual class CallGenBase: """编译器内置特殊方法的固定返回类型;非特殊返回 None""" if pool is None or method_name is None: return None - if string.strcmp(method_name, "__before_init__") == 0 or \ - string.strcmp(method_name, "__init__") == 0: + if string.strcmp(method_name, "__before_init__") == 0 or string.strcmp(method_name, "__init__") == 0: return llvmlite.Void(pool) if string.strcmp(method_name, "__new__") == 0: if class_name is not None: @@ -1121,8 +1115,7 @@ novirtual class CallGenBase: name_len: sizet = name_end - name_start # 只登记本模块 mangled 名 "{sha1}.{后缀}"(查询键恒为此前缀);表不可用时跳过登记 if cache_on != 0 and name_len > sha1_len + 1: - if string.strncmp(text_buf + name_start, class_sha1, sha1_len) == 0 \ - and text_buf[name_start + sha1_len] == '.': + if string.strncmp(text_buf + name_start, class_sha1, sha1_len) == 0 and text_buf[name_start + sha1_len] == '.': key_buf: bytes = stdlib.malloc(name_len + 1) if key_buf is not None: string.strncpy(key_buf, text_buf + name_start, name_len) diff --git a/App/lib/core/Gen/Call/CallGenCBuiltin.vp b/App/lib/core/Gen/Call/CallGenCBuiltin.vp index 55e02f0..810fad9 100644 --- a/App/lib/core/Gen/Call/CallGenCBuiltin.vp +++ b/App/lib/core/Gen/Call/CallGenCBuiltin.vp @@ -371,8 +371,7 @@ novirtual class CallGenCBuiltin(CallGenBase.CallGenBase): if at_addr is None or at_addr.attr is None or at_addr.value is None: return None # 跨模块函数地址 c.Addr(serial.puts) → 函数符号本身(@sha1.puts):不可回退 ExprGenAttr 当全局变量处理,否则与 vpi 注入的 puts 函数 declare 同名冲突(llc "redefinition of function") - if at_addr.value.kind() == ast.ASTKind.Name and trans is not None \ - and trans._imported_modules is not None: + if at_addr.value.kind() == ast.ASTKind.Name and trans is not None and trans._imported_modules is not None: mod_nm2: ast.Name* = ast.Name*(at_addr.value) if mod_nm2.id is not None: if self.Gen.ImportsGen.is_module_imported(trans._imported_modules, mod_nm2.id) != 0: @@ -1064,8 +1063,7 @@ novirtual class CallGenCBuiltin(CallGenBase.CallGenBase): # 分支)。仅 Name 检查时 Attribute 被跳过 → # 空操作数 "mov , cr3"(process.vp L127/L208 根因)。 at_a: ast.Attribute* = ast.Attribute*(val_node) - if at_a.attr is not None and at_a.value is not None \ - and at_a.value.kind() == ast.ASTKind.Name: + if at_a.attr is not None and at_a.value is not None and at_a.value.kind() == ast.ASTKind.Name: base_nm_a: ast.Name* = ast.Name*(at_a.value) if base_nm_a.id is not None: base_alloca_a: llvmlite.Value* = self.Gen.VarGen.lookup_var(trans.SymTab, base_nm_a.id) @@ -1252,9 +1250,8 @@ novirtual class CallGenCBuiltin(CallGenBase.CallGenBase): pty5: llvmlite.LLVMType* = None # 优先收集时按序缓存的直接类型,再回退从槽读回 if out_ptys is not None and out_seq < out_pty_n: - pty5 = (llvmlite.LLVMType*)(out_ptys[out_seq]) - elif op5.Value is not None and op5.Value.Ty is not None \ - and op5.Value.Ty.Pointee != 0: + pty5 = llvmlite.LLVMType*(out_ptys[out_seq]) + elif op5.Value is not None and op5.Value.Ty is not None and op5.Value.Ty.Pointee != 0: pty5 = op5.Value.Ty.Pointee out_seq += 1 if pty5 is None: @@ -1278,8 +1275,7 @@ novirtual class CallGenCBuiltin(CallGenBase.CallGenBase): # 优先用收集时缓存的元素类型(对齐 python 参考),再回退从槽读回 if out_ret_ty_first is not None: out_pt = out_ret_ty_first - elif out_op is not None and out_op.Value is not None \ - and out_op.Value.Ty is not None and out_op.Value.Ty.Pointee != 0: + elif out_op is not None and out_op.Value is not None and out_op.Value.Ty is not None and out_op.Value.Ty.Pointee != 0: out_pt = out_op.Value.Ty.Pointee if out_pt is not None: ret_ty = out_pt @@ -1476,12 +1472,10 @@ novirtual class CallGenCBuiltin(CallGenBase.CallGenBase): llvmlite.TypePrint(ret_ty_buf, 64, ret_ty, pool) if is_void == 1: - viperlib.snprintf(line, ASM_LINE_BUF_SIZE, - "call %s asm sideeffect inteldialect \"%s\", \"%s\"(%s)", + viperlib.snprintf(line, ASM_LINE_BUF_SIZE, "call %s asm sideeffect inteldialect \"%s\", \"%s\"(%s)", ret_ty_buf, escaped_asm, const_buf, args_buf) else: - viperlib.snprintf(line, ASM_LINE_BUF_SIZE, - "%s = call %s asm sideeffect inteldialect \"%s\", \"%s\"(%s)", + viperlib.snprintf(line, ASM_LINE_BUF_SIZE, "%s = call %s asm sideeffect inteldialect \"%s\", \"%s\"(%s)", ssa_name, ret_ty_buf, escaped_asm, const_buf, args_buf) # 发射 IR 到当前块 @@ -1500,8 +1494,7 @@ novirtual class CallGenCBuiltin(CallGenBase.CallGenBase): continue if output_count > 1: # 多输出:extractvalue 取第 out_emit_idx 个元素后 store - if oo.Value is not None and oo.Value.Ty is not None \ - and oo.Value.Ty.Pointee != 0: + if oo.Value is not None and oo.Value.Ty is not None and oo.Value.Ty.Pointee != 0: ev_name: str = pool.alloc(32) ev_line: str = pool.alloc(ASM_LINE_BUF_SIZE) if ev_name is not None and ev_line is not None: diff --git a/App/lib/core/Gen/Call/CallGenCall.vp b/App/lib/core/Gen/Call/CallGenCall.vp index 1bcc789..44ef49e 100644 --- a/App/lib/core/Gen/Call/CallGenCall.vp +++ b/App/lib/core/Gen/Call/CallGenCall.vp @@ -274,8 +274,7 @@ novirtual class CallGenCall(CallGenBase.CallGenBase): # 静默截断 ⇒ 报错文本丢失定位信息。改为按精确长度分配 # (-4 = 格式串里两个 "%s" 占位符各占 2 字节)。 msg_fmt: str = "类 '%s' 方法 '%s' 找不到模块 SHA1" - msg_size: sizet = string.strlen(msg_fmt) \ - + string.strlen(class_name) + string.strlen(method_name) - 4 + 1 + msg_size: sizet = string.strlen(msg_fmt) + string.strlen(class_name) + string.strlen(method_name) - 4 + 1 err_msg: str = pool.alloc(msg_size) if err_msg is not None: viperlib.snprintf(err_msg, msg_size, msg_fmt, class_name, method_name) @@ -313,8 +312,7 @@ novirtual class CallGenCall(CallGenBase.CallGenBase): # 否则走 text.ll/vpi 解析失败 → fail-fast 误报 # (CPythonTest PyLongObj() 构造:类未定义 __init__/__before_init__ # 但实例化仍生成调用 → "PyLongObj.__before_init__ 返回类型无法确定"根因)。 - if string.strcmp(method_name, "__before_init__") == 0 or \ - string.strcmp(method_name, "__init__") == 0: + if string.strcmp(method_name, "__before_init__") == 0 or string.strcmp(method_name, "__init__") == 0: call_ret_ty = void_ty # __new__ 返回 Ptr(struct_ty)(构造函数返回自身指针,可推断)。 # __getitem__ 返回类型无法从 self 推断(可返回 i8* 如 HashTable.__getitem__ @@ -355,9 +353,7 @@ novirtual class CallGenCall(CallGenBase.CallGenBase): # 目标模块 sha1 == 当前正在翻译的模块 sha1 时,自己的 text.ll # 尚未生成 → _dep_text_ll_exists 恒 0 → 误判 pending 死锁。 # 从当前 IR 已声明的本地函数取返回类型,不查自身 text.ll/vpi。 - if cls_sha1 is not None and trans is not None \ - and trans.ModuleSha1 is not None \ - and string.strncmp(cls_sha1, trans.ModuleSha1, 16) == 0: + if cls_sha1 is not None and trans is not None and trans.ModuleSha1 is not None and string.strncmp(cls_sha1, trans.ModuleSha1, 16) == 0: local_lk_cm2: str = pool.alloc(string.strlen(class_name) + string.strlen(method_name) + 2) if local_lk_cm2 is not None: viperlib.snprintf(local_lk_cm2, @@ -529,8 +525,7 @@ novirtual class CallGenCall(CallGenBase.CallGenBase): seg_cur_v += 1 seg_start_v: sizet = seg_cur_v seg_len_v: sizet = 0 - while vpi_pa[seg_start_v + seg_len_v] != '\0' \ - and vpi_pa[seg_start_v + seg_len_v] != '@': + while vpi_pa[seg_start_v + seg_len_v] != '\0' and vpi_pa[seg_start_v + seg_len_v] != '@': seg_len_v += 1 if seg_no_v == seg_idx_v: pty_v: llvmlite.LLVMType* = llvmlite.Ptr(pool, llvmlite.Int8(pool)) @@ -655,9 +650,7 @@ novirtual class CallGenCall(CallGenBase.CallGenBase): # 保证本次构造对对象内存的写入不可被消除或跨越重排。仅对构造三方法生效, # 不给普通方法调用引入额外访存。 if is_volatile != 0 and self_ptr is not None and self_ptr.Ty is not None: - if string.strcmp(method_name, "__new__") == 0 \ - or string.strcmp(method_name, "__before_init__") == 0 \ - or string.strcmp(method_name, "__init__") == 0: + if string.strcmp(method_name, "__new__") == 0 or string.strcmp(method_name, "__before_init__") == 0 or string.strcmp(method_name, "__init__") == 0: cmop_i8_ty: llvmlite.LLVMType* = llvmlite.Int8(pool) cmop_i8_ptr_ty: llvmlite.LLVMType* = llvmlite.Ptr(pool, cmop_i8_ty) cmop_bar_ptr: llvmlite.Value* = self_ptr @@ -693,8 +686,7 @@ novirtual class CallGenCall(CallGenBase.CallGenBase): # [D25 分派修复] class_name 可能因注解在 Handle 阶段退化而为空串,使 list 内建拦截(_is_list_builtin_method)与 D25 泛型基类 fail-fast 双双失效 ⇒ 误绑到无关特化。接收者的**实际 struct 名**比退化注解可靠,用它补全判定来源(提升到分支外声明,D25 fail-fast 同样使用) lb_src: str = class_name if lb_src is None or lb_src[0] == '\0': - lb_sty_s: llvmlite.LLVMType* = \ - self.Gen.StructGen.get_struct_type_from_value(obj_ptr) + lb_sty_s: llvmlite.LLVMType* = self.Gen.StructGen.get_struct_type_from_value(obj_ptr) if lb_sty_s is not None: lb_nm_s: str = llvmlite.get_struct_name(lb_sty_s) if lb_nm_s is not None: @@ -900,8 +892,7 @@ novirtual class CallGenCall(CallGenBase.CallGenBase): case _: pass if sp_anc_sha1 is not None: - ml_sp: sizet = string.strlen(sp_anc_sha1) + string.strlen(sp_anc_name) \ - + string.strlen(method_name) + 3 + ml_sp: sizet = string.strlen(sp_anc_sha1) + string.strlen(sp_anc_name) + string.strlen(method_name) + 3 mangled_sp: str = pool.alloc(ml_sp) if mangled_sp is not None: viperlib.snprintf(mangled_sp, ml_sp, "%s.%s.%s", @@ -1061,9 +1052,7 @@ novirtual class CallGenCall(CallGenBase.CallGenBase): # 根因:方法定义在 ExprGenMixin(Mixin 模块),Phase A 顺序中 # ExprGenMixin 的 text.ll 尚未生成 → MRO 链查找全部未命中 → # fail-fast 误报。ret_anc_sha1 为 None 同样视为依赖未就绪。 - if ret_anc_sha1 is None \ - or (ret_anc_sha1 is not None - and self._dep_text_ll_exists(pool, ret_anc_sha1) == 0): + if ret_anc_sha1 is None or (ret_anc_sha1 is not None and self._dep_text_ll_exists(pool, ret_anc_sha1) == 0): # 依赖未就绪:保持默认 i32 继续而非 Void——build_call(Void) # 返回 None,方法调用结果喂进表达式(if 条件/比较)时 fatal # "if 条件表达式翻译失败"(ExprGenAttr._get_cderef_attr_base @@ -1085,8 +1074,7 @@ novirtual class CallGenCall(CallGenBase.CallGenBase): anc_p2: str = rawptr(mro_p2[mi_p2]) if anc_p2 is not None: anc_sha1_p2: str = self.Gen.StructGen.get_struct_sha1(anc_p2) - if anc_sha1_p2 is None \ - or self._dep_text_ll_exists(pool, anc_sha1_p2) == 0: + if anc_sha1_p2 is None or self._dep_text_ll_exists(pool, anc_sha1_p2) == 0: anc_missing_p2 = 1 break mi_p2 += 1 @@ -1121,8 +1109,7 @@ novirtual class CallGenCall(CallGenBase.CallGenBase): case _: pass if ret_anc_name is not None and ret_anc_sha1 is not None: - ml_anc: sizet = string.strlen(ret_anc_sha1) + string.strlen(ret_anc_name) \ - + string.strlen(method_name) + 3 + ml_anc: sizet = string.strlen(ret_anc_sha1) + string.strlen(ret_anc_name) + string.strlen(method_name) + 3 mangled_anc: str = pool.alloc(ml_anc) if mangled_anc is not None: viperlib.snprintf(mangled_anc, ml_anc, "%s.%s.%s", @@ -1497,8 +1484,7 @@ novirtual class CallGenCall(CallGenBase.CallGenBase): seg_cur_v += 1 seg_start_v: sizet = seg_cur_v seg_len_v: sizet = 0 - while vpi_pa[seg_start_v + seg_len_v] != '\0' \ - and vpi_pa[seg_start_v + seg_len_v] != '@': + while vpi_pa[seg_start_v + seg_len_v] != '\0' and vpi_pa[seg_start_v + seg_len_v] != '@': seg_len_v += 1 if seg_no_v == seg_idx_v: pty_v: llvmlite.LLVMType* = llvmlite.Ptr(pool, llvmlite.Int8(pool)) @@ -1582,8 +1568,7 @@ novirtual class CallGenCall(CallGenBase.CallGenBase): i8_ptr_ty: llvmlite.LLVMType* = llvmlite.Ptr(pool, i8_ty) # 元素类型 T:从 list 特化类型名解析(list[int]→i32、list[str]→i8*、 # 未知/指针元素→i8*),与 CallGenDispatch 尾部 list 分支一致 - lm_esty: llvmlite.LLVMType* = \ - self.Gen.StructGen.get_struct_type_from_value(lm_obj) + lm_esty: llvmlite.LLVMType* = self.Gen.StructGen.get_struct_type_from_value(lm_obj) lm_ename: str = None if lm_esty is not None: lm_ename = llvmlite.get_struct_name(lm_esty) @@ -1697,8 +1682,7 @@ novirtual class CallGenCall(CallGenBase.CallGenBase): # {sha1}.list.append。lm_obj 类型即特化结构体 Ptr(list[...]), # 从类型解析特化类名拼接调用名,否则 ld.lld undefined symbol ap_spec_nm: str = None - ap_struct_ty: llvmlite.LLVMType* = \ - self.Gen.StructGen.get_struct_type_from_value(lm_obj) + ap_struct_ty: llvmlite.LLVMType* = self.Gen.StructGen.get_struct_type_from_value(lm_obj) if ap_struct_ty is not None: ap_spec_nm = self.Gen.StructGen.get_class_name_by_type(pool, ap_struct_ty) if ap_spec_nm is None: @@ -1738,8 +1722,7 @@ novirtual class CallGenCall(CallGenBase.CallGenBase): self.Gen.ClassGenGeneric._specialize_generic_class(trans, base_buf_ap, args_ap) # 调用名 "{sha1}.{spec}.append": # sha1(16) + '.'(1) + spec + '.append'(7) + NUL(1) = spec + 25 - ap_mlen: sizet = string.strlen(ap_sha1) + \ - string.strlen(ap_spec_nm) + 26 + ap_mlen: sizet = string.strlen(ap_sha1) + string.strlen(ap_spec_nm) + 26 ap_mangled: str = pool.alloc(ap_mlen) if ap_mangled is not None: viperlib.snprintf(ap_mangled, ap_mlen, "%s.%s.append", ap_sha1, ap_spec_nm) @@ -1957,8 +1940,7 @@ novirtual class CallGenCall(CallGenBase.CallGenBase): else: # Phase A 依赖未就绪(anc_sha1_sp None / 定义模块 text.ll 未生成): # 保持默认 i32(build_call(Void) 返回 None 会破坏表达式翻译)。 - if anc_sha1_sp is None \ - or self._dep_text_ll_exists(pool, anc_sha1_sp) == 0: + if anc_sha1_sp is None or self._dep_text_ll_exists(pool, anc_sha1_sp) == 0: ret_ty_sp = llvmlite.Int32(pool) else: self._fail_method_ret_ty(method_name, cl) @@ -1967,72 +1949,72 @@ novirtual class CallGenCall(CallGenBase.CallGenBase): self._ensure_method_declare(pool, mod, call_name, ret_ty_sp, head, arg_count_sp) is_variadic_sp: int = self.Gen.CallGenVa._check_and_promote_variadic_call(pool, builder, mod, call_name, head, arg_count_sp, cargs_sp, 1, trans) return llvmlite.build_call(builder, call_name, head, arg_count_sp, ret_ty_sp, is_variadic_sp) - # ============================================================ - # _recv_is_mixin_base - 判据①:接收类是否"被当作父类组合使用"(真 Mixin) - # - # 用于兄弟 Mixin 方法解析:只有当接收类确实是某个已注册类的**直接父类**时, - # 才可能存在"组合类的布局里有该字段区"的情形。反例:FileW 无人继承 ⇒ - # FileW.__init__ 里的 self.seek() 不得绑到同名方法 File.seek。 - # ============================================================ - def _recv_is_mixin_base(self, class_name: str) -> int: - """接收类是否为某个已注册类的直接父类(1=是 / 0=否)""" - if class_name is None: - return 0 - if self.Gen is None: - return 0 - j: int = 0 - n: int = self.Gen.StructGen.get_struct_count() - while j < n: - e: GenTypes.StructEntry* = self.Gen.StructGen._get_struct_entry(j) - if e is not None and e.Name is not None: - pc: int = self.Gen.StructGen.get_parent_count(e.Name) - pj: int = 0 - while pj < pc: - pn: str = self.Gen.StructGen.get_parent_name_at(e.Name, pj) - if pn is not None: - if string.strcmp(pn, class_name) == 0: - return 1 - pj += 1 - j += 1 - return 0 - - # ============================================================ - # _mixin_sibling_same_composite - 判据②:两类是否同处某个组合类的 MRO - # - # 兄弟 Mixin 的充要条件:存在一个已注册类 K,其 MRO 同时含 class_name 与 - # cand_name(如 Combined(BaseA, BaseB):MRO 含 BaseA 与 BaseB ⇒ 二者是兄弟)。 - # 只有满足它才允许把 self.() 绑到同名的兄弟类方法上。 - # ============================================================ - def _mixin_sibling_same_composite(self, pool: memhub.MemBuddy*, - class_name: str, cand_name: str) -> int: - """两类是否同处某个已注册组合类的 MRO(1=是 / 0=否)""" - if class_name is None or cand_name is None or pool is None: - return 0 - if self.Gen is None: - return 0 - j: int = 0 - n: int = self.Gen.StructGen.get_struct_count() - while j < n: - k_entry: GenTypes.StructEntry* = self.Gen.StructGen._get_struct_entry(j) - if k_entry is not None and k_entry.Name is not None: - mro: sizet* = self.Gen.StructGen.get_mro_chain(pool, k_entry.Name) - if mro is not None: - has_self: int = 0 - has_cand: int = 0 - mi: int = 0 - while mro[mi] != 0: - nm: str = rawptr(mro[mi]) - if nm is not None: - if string.strcmp(nm, class_name) == 0: - has_self = 1 - elif string.strcmp(nm, cand_name) == 0: - has_cand = 1 - if has_self != 0 and has_cand != 0: - return 1 - mi += 1 - j += 1 - return 0 - + # ============================================================ + # _recv_is_mixin_base - 判据①:接收类是否"被当作父类组合使用"(真 Mixin) + # + # 用于兄弟 Mixin 方法解析:只有当接收类确实是某个已注册类的**直接父类**时, + # 才可能存在"组合类的布局里有该字段区"的情形。反例:FileW 无人继承 ⇒ + # FileW.__init__ 里的 self.seek() 不得绑到同名方法 File.seek。 + # ============================================================ + def _recv_is_mixin_base(self, class_name: str) -> int: + """接收类是否为某个已注册类的直接父类(1=是 / 0=否)""" + if class_name is None: + return 0 + if self.Gen is None: + return 0 + j: int = 0 + n: int = self.Gen.StructGen.get_struct_count() + while j < n: + e: GenTypes.StructEntry* = self.Gen.StructGen._get_struct_entry(j) + if e is not None and e.Name is not None: + pc: int = self.Gen.StructGen.get_parent_count(e.Name) + pj: int = 0 + while pj < pc: + pn: str = self.Gen.StructGen.get_parent_name_at(e.Name, pj) + if pn is not None: + if string.strcmp(pn, class_name) == 0: + return 1 + pj += 1 + j += 1 + return 0 + + # ============================================================ + # _mixin_sibling_same_composite - 判据②:两类是否同处某个组合类的 MRO + # + # 兄弟 Mixin 的充要条件:存在一个已注册类 K,其 MRO 同时含 class_name 与 + # cand_name(如 Combined(BaseA, BaseB):MRO 含 BaseA 与 BaseB ⇒ 二者是兄弟)。 + # 只有满足它才允许把 self.() 绑到同名的兄弟类方法上。 + # ============================================================ + def _mixin_sibling_same_composite(self, pool: memhub.MemBuddy*, + class_name: str, cand_name: str) -> int: + """两类是否同处某个已注册组合类的 MRO(1=是 / 0=否)""" + if class_name is None or cand_name is None or pool is None: + return 0 + if self.Gen is None: + return 0 + j: int = 0 + n: int = self.Gen.StructGen.get_struct_count() + while j < n: + k_entry: GenTypes.StructEntry* = self.Gen.StructGen._get_struct_entry(j) + if k_entry is not None and k_entry.Name is not None: + mro: sizet* = self.Gen.StructGen.get_mro_chain(pool, k_entry.Name) + if mro is not None: + has_self: int = 0 + has_cand: int = 0 + mi: int = 0 + while mro[mi] != 0: + nm: str = rawptr(mro[mi]) + if nm is not None: + if string.strcmp(nm, class_name) == 0: + has_self = 1 + elif string.strcmp(nm, cand_name) == 0: + has_cand = 1 + if has_self != 0 and has_cand != 0: + return 1 + mi += 1 + j += 1 + return 0 + # ============================================================ # _field_byte_offset — 计算字段在结构体布局中的字节偏移 # diff --git a/App/lib/core/Gen/Call/CallGenDispatch.vp b/App/lib/core/Gen/Call/CallGenDispatch.vp index 0ba744f..1d42548 100644 --- a/App/lib/core/Gen/Call/CallGenDispatch.vp +++ b/App/lib/core/Gen/Call/CallGenDispatch.vp @@ -586,8 +586,7 @@ novirtual class CallGenDispatch(CallGenBase.CallGenBase): # 兜底:TypeGenBase 上下文为空时(模板 tp_names 跨 phase 失效), # 直接用 trans 的泛型映射替换 T(list[int] 单态化 _list.vp # T.__sizeof__ 根因)。 - if string.strcmp(sz_cls_name, sz_orig) == 0 and trans is not None \ - and trans.GenericTypeParamNames is not None and trans.GenericTypeArgs is not None: + if string.strcmp(sz_cls_name, sz_orig) == 0 and trans is not None and trans.GenericTypeParamNames is not None and trans.GenericTypeArgs is not None: gp_n: sizet = len(trans.GenericTypeParamNames) gp_i: sizet for gp_i in range(gp_n): @@ -1006,8 +1005,7 @@ novirtual class CallGenDispatch(CallGenBase.CallGenBase): # 类型落空(实况:CallGenLib.vp:355 `vk_a: int = val.Ty.kind()` 报 # 「指针隐式转整数已禁止」)。 if rk_cls is not None: - if self.Gen.ClassGenEnum._is_renum_class_name(rk_cls) != 0 \ - or self.Gen.ClassGenEnum._is_renum_by_entry(rk_cls) != 0: + if self.Gen.ClassGenEnum._is_renum_class_name(rk_cls) != 0 or self.Gen.ClassGenEnum._is_renum_by_entry(rk_cls) != 0: rk_is_rn = 1 else: rk_cls = None @@ -1045,8 +1043,7 @@ novirtual class CallGenDispatch(CallGenBase.CallGenBase): else: rk_cls = rk_ab # 判据同上(表 或 struct 带 __tag),不再只认变体表 - if self.Gen.ClassGenEnum._is_renum_class_name(rk_cls) != 0 \ - or self.Gen.ClassGenEnum._is_renum_by_entry(rk_cls) != 0: + if self.Gen.ClassGenEnum._is_renum_class_name(rk_cls) != 0 or self.Gen.ClassGenEnum._is_renum_by_entry(rk_cls) != 0: rk_is_rn = 1 # 第 2 层:按类名取 struct 的 __tag 声明类型 rk_st_b: llvmlite.LLVMType* = self.Gen.StructGen.get_struct_type(rk_cls) @@ -1063,19 +1060,16 @@ novirtual class CallGenDispatch(CallGenBase.CallGenBase): # 一层)→ pointee 类名 → 再走 表/__tag 判据。 # CallGenLib.vp:355 `vk_a: int = val.Ty.kind()` 正是此形态: # Value.Ty 声明为 `rawptr[LLVMType]`(__values.vp:22)。 - if rk_is_rn == 0 and rk_at.value is not None \ - and rk_at.value.kind() == ast.ASTKind.Attribute and trans is not None: + if rk_is_rn == 0 and rk_at.value is not None and rk_at.value.kind() == ast.ASTKind.Attribute and trans is not None: rk_bat: ast.Attribute* = ast.Attribute*(rk_at.value) - if rk_bat is not None and rk_bat.attr is not None and rk_bat.value is not None \ - and rk_bat.value.kind() == ast.ASTKind.Name: + if rk_bat is not None and rk_bat.attr is not None and rk_bat.value is not None and rk_bat.value.kind() == ast.ASTKind.Name: rk_bnm: ast.Name* = ast.Name*(rk_bat.value) if rk_bnm.id is not None: rk_bve: GenTypes.VarEntry* = self.Gen.VarGen.lookup_var_entry(trans.SymTab, rk_bnm.id) rk_bannot: str = self.Gen.VarGen.var_annot_class_name(rk_bve) if rk_bannot is not None: rk_blen: sizet = 0 - while rk_bannot[rk_blen] != '\0' and rk_bannot[rk_blen] != ' ' \ - and rk_bannot[rk_blen] != '|' and rk_bannot[rk_blen] != '[': + while rk_bannot[rk_blen] != '\0' and rk_bannot[rk_blen] != ' ' and rk_bannot[rk_blen] != '|' and rk_bannot[rk_blen] != '[': rk_blen += 1 rk_bbuf: str = pool.alloc(rk_blen + 1) if rk_bbuf is not None: @@ -1093,14 +1087,12 @@ novirtual class CallGenDispatch(CallGenBase.CallGenBase): rk_fpt: llvmlite.LLVMType* = rk_bfe.Ty if self.Gen.ExprGenBase.is_ptr_type(rk_fpt) != 0: rk_fpt = rk_fpt.Pointee - if rk_fpt is not None \ - and self.Gen.ExprGenBase.is_ptr_type(rk_fpt) != 0: + if rk_fpt is not None and self.Gen.ExprGenBase.is_ptr_type(rk_fpt) != 0: rk_fpt = rk_fpt.Pointee if rk_fpt is not None: rk_fcls: str = self.Gen.StructGen.get_class_name_by_type(pool, rk_fpt) if rk_fcls is not None: - if self.Gen.ClassGenEnum._is_renum_class_name(rk_fcls) != 0 \ - or self.Gen.ClassGenEnum._is_renum_by_entry(rk_fcls) != 0: + if self.Gen.ClassGenEnum._is_renum_class_name(rk_fcls) != 0 or self.Gen.ClassGenEnum._is_renum_by_entry(rk_fcls) != 0: rk_is_rn = 1 rk_cls = rk_fcls rk_ffe: GenTypes.FieldEntry* = self.Gen.StructGen.lookup_field(rk_fpt, "__tag") @@ -1148,8 +1140,7 @@ novirtual class CallGenDispatch(CallGenBase.CallGenBase): st_nm: ast.Name* = ast.Name*(st_at.value) if st_nm.id is not None: st_var: llvmlite.Value* = self.Gen.VarGen.lookup_var(trans.SymTab, st_nm.id) - if st_var is None and self.Gen.StructGen.get_struct_type(st_nm.id) is not None \ - and self.Gen.ImportsGen.is_module_imported(trans._imported_modules, st_nm.id) == 0: + if st_var is None and self.Gen.StructGen.get_struct_type(st_nm.id) is not None and self.Gen.ImportsGen.is_module_imported(trans._imported_modules, st_nm.id) == 0: # REnum 变体构造优先于静态/类方法调用: if self.Gen.ClassGenEnum._is_renum_class_name(st_nm.id) != 0: rc_tag_sc: int = self.Gen.ClassGenEnum._lookup_renum_variant_in_class(st_nm.id, func_name) @@ -1480,8 +1471,7 @@ novirtual class CallGenDispatch(CallGenBase.CallGenBase): if expr_root is not None and expr_root.kind() == ast.ASTKind.Name: expr_root_nm: str = ast.Name*(expr_root).id if expr_root_nm is not None: - if string.strcmp(expr_root_nm, "t") == 0 or \ - string.strcmp(expr_root_nm, "c") == 0: + if string.strcmp(expr_root_nm, "t") == 0 or string.strcmp(expr_root_nm, "c") == 0: is_mod_path_expr = 1 elif trans._imported_modules is not None: if self.Gen.ImportsGen.is_module_imported(trans._imported_modules, expr_root_nm) != 0: @@ -1494,8 +1484,7 @@ novirtual class CallGenDispatch(CallGenBase.CallGenBase): # 递归解 Ptr:识别 X|t.CPtr 联合简化的 Ptr(Ptr(Struct)) # (如 (a*2.0 - b) 中 __mul__ 返回 Vec3**),否则方法 # 调用被当裸函数 @dot 解析 → 链接 undefined symbol - expr_struct_ty: llvmlite.LLVMType* = \ - self.Gen.StructGen.get_struct_type_from_value(expr_obj) + expr_struct_ty: llvmlite.LLVMType* = self.Gen.StructGen.get_struct_type_from_value(expr_obj) if expr_struct_ty is not None: expr_cls_nm = self.Gen.StructGen.get_class_name_by_type(pool, expr_struct_ty) # 回退:LLVM 类型为 Ptr(i8)(方法返回 X|t.CPtr 无类型信息)时, @@ -1632,8 +1621,7 @@ novirtual class CallGenDispatch(CallGenBase.CallGenBase): # 普通类未注册场景)跳过本分支,避免按 list 布局 GEP 生成 # 错误 IR(dict 的 get 被当 list.get 按 __data__/__elem_size__ # 偏移读写垃圾)。 - lm_conf_ty: llvmlite.LLVMType* = \ - self.Gen.StructGen.get_struct_type_from_value(lm_obj) + lm_conf_ty: llvmlite.LLVMType* = self.Gen.StructGen.get_struct_type_from_value(lm_obj) lm_conf_nm: str = None if lm_conf_ty is not None: lm_conf_nm = llvmlite.get_struct_name(lm_conf_ty) @@ -1641,8 +1629,7 @@ novirtual class CallGenDispatch(CallGenBase.CallGenBase): # 前缀(如 "e94ef9e139461915.list[ast.ASTptr]");SpecTypeNameBaseIs # 会去前缀、截断泛型实参后精确比 "list"(原 strstr 子串会误命中 # playlist 之类的类名)。 - if lm_conf_nm is not None and \ - TSpec.SpecTypeNameBaseIs(lm_conf_nm, "list") == 0: + if lm_conf_nm is not None and TSpec.SpecTypeNameBaseIs(lm_conf_nm, "list") == 0: return None # list 内置分支命中标记:void 方法(set/clear)成功处理后返回 # None,必须置位 hit_box 区分"已识别为 list 方法路径",否则 @@ -1662,8 +1649,7 @@ novirtual class CallGenDispatch(CallGenBase.CallGenBase): # pop 读回 0 → ListTest "pop FAILED expect 30" 根因。 # subscript 路径(list_getitem_inline 调用方)已用 # _list_elem_type_from_name 修正,方法调用路径漏改。 - lm_esty: llvmlite.LLVMType* = \ - self.Gen.StructGen.get_struct_type_from_value(lm_obj) + lm_esty: llvmlite.LLVMType* = self.Gen.StructGen.get_struct_type_from_value(lm_obj) lm_ename: str = None if lm_esty is not None: lm_ename = llvmlite.get_struct_name(lm_esty) diff --git a/App/lib/core/Gen/Call/CallGenLeafKit.vp b/App/lib/core/Gen/Call/CallGenLeafKit.vp index 977c28c..9079ca5 100644 --- a/App/lib/core/Gen/Call/CallGenLeafKit.vp +++ b/App/lib/core/Gen/Call/CallGenLeafKit.vp @@ -177,8 +177,7 @@ novirtual class CallGenLeafKit(CallGenCBuiltin.CallGenCBuiltin): if trans._eh_msg_ptr is not None and trans._eh_code_ptr is not None: msg_ptr = trans._eh_msg_ptr code_ptr = trans._eh_code_ptr - elif trans._cur_func_has_eh != 0 and trans._eh_msg_out_param is not None \ - and trans._eh_code_out_param is not None: + elif trans._cur_func_has_eh != 0 and trans._eh_msg_out_param is not None and trans._eh_code_out_param is not None: msg_ptr = trans._eh_msg_out_param code_ptr = trans._eh_code_out_param if msg_ptr is None: diff --git a/App/lib/core/Gen/Class/ClassGenGeneric.vp b/App/lib/core/Gen/Class/ClassGenGeneric.vp index 4a1f957..f79db9b 100644 --- a/App/lib/core/Gen/Class/ClassGenGeneric.vp +++ b/App/lib/core/Gen/Class/ClassGenGeneric.vp @@ -100,7 +100,6 @@ novirtual class ClassGenGeneric(ClassGenBase.ClassGenBase): # 用局部变量接收 list,触发类型推断(避免字段 __len__ 失败) names_local: list[str]* = self.GenericClassNames 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: return diff --git a/App/lib/core/IncludesScanner.vp b/App/lib/core/IncludesScanner.vp index 2feb0dc..f73102b 100644 --- a/App/lib/core/IncludesScanner.vp +++ b/App/lib/core/IncludesScanner.vp @@ -21,16 +21,15 @@ import lib.core.VLogger as VLogger _mbuddy: memhub.MemBuddy* # 文件路径最大长度 -MAX_PATH_LEN: t.CDefine = 512 +define MAX_PATH_LEN = 512 # 单次扫描最大文件数 -MAX_FILES: t.CDefine = 1024 +define MAX_FILES = 1024 # ============================================================ # FileEntry - 文件条目(路径 + SHA1) # ============================================================ -@t.NoVTable -class FileEntry: +novirtual class FileEntry: """扫描到的文件条目""" Path: str # 文件绝对路径 Sha1: str # SHA1 前16字符(16字节+null) @@ -42,10 +41,9 @@ class FileEntry: # ============================================================ # ScanResult - 扫描结果 # ============================================================ -@t.NoVTable -class ScanResult: +novirtual class ScanResult: """扫描结果集合""" - Entries: FileEntry | t.CPtr # FileEntry 数组 + Entries: FileEntry* # FileEntry 数组 Count: int Capacity: int @@ -53,20 +51,17 @@ class ScanResult: # ============================================================ # create_scan_result - 创建扫描结果容器 # ============================================================ -def create_scan_result(pool: memhub.MemBuddy*) -> ScanResult | t.CPtr: +def create_scan_result(pool: memhub.MemBuddy*) -> ScanResult*: """创建扫描结果容器,预分配 MAX_FILES 个槽位""" - if pool is None: - return None + if pool is None: return None size: sizet = MAX_FILES * FileEntry.__sizeof__() # 使用 stdlib.malloc 避免 mbuddy 池耗尽(与 StubMerger 保持一致) - entries: FileEntry | t.CPtr = stdlib.malloc(size) - if entries is None: - return None + entries: FileEntry* = stdlib.malloc(size) + if entries is None: return None string.memset(entries, 0, size) - result: ScanResult | t.CPtr = stdlib.malloc(ScanResult.__sizeof__()) - if result is None: - return None + result: ScanResult* = stdlib.malloc(ScanResult.__sizeof__()) + if result is None: return None string.memset(result, 0, ScanResult.__sizeof__()) result.Entries = entries result.Count = 0 @@ -77,47 +72,40 @@ def create_scan_result(pool: memhub.MemBuddy*) -> ScanResult | t.CPtr: # ============================================================ # add_file_entry - 向扫描结果添加文件条目 # ============================================================ -def add_file_entry(result: ScanResult | t.CPtr, +def add_file_entry(result: ScanResult*, pool: memhub.MemBuddy*, abs_path: str, rel_path: str, sha1: str, inc_dir: str) -> int: """添加文件条目到扫描结果,返回 0 成功(inc_dir 为所属 includes 根目录)""" - if result is None or pool is None: - return 1 - if result.Count >= result.Capacity: - return 1 + if result is None or pool is None: return 1 + if result.Count >= result.Capacity: return 1 # 计算模块名:rel_path 中 / 替换为 .,去掉 .vp/.py 扩展名(__init__.vp 特判由 Utils 统一处理) mod_buf: str = Utils.PathToModuleName(rel_path, 0) - if mod_buf is None: - return 1 + if mod_buf is None: return 1 # 获取条目地址 entry_size: sizet = FileEntry.__sizeof__() entry_addr: uint64 = uint64(result.Entries) + result.Count * entry_size - entry: FileEntry | t.CPtr = (FileEntry | t.CPtr)(entry_addr) - if entry is None: - return 1 + entry: FileEntry* = (FileEntry*)(entry_addr) + if entry is None: return 1 # 复制路径字符串 abs_len: sizet = string.strlen(abs_path) abs_buf: str = stdlib.malloc(abs_len + 1) - if abs_buf is None: - return 1 + if abs_buf is None: return 1 string.strcpy(abs_buf, abs_path) entry.Path = abs_buf # 复制 SHA1 sha1_buf: str = stdlib.malloc(17) - if sha1_buf is None: - return 1 + if sha1_buf is None: return 1 string.strcpy(sha1_buf, sha1) entry.Sha1 = sha1_buf # 复制相对路径 rel_buf: str = stdlib.malloc(string.strlen(rel_path) + 1) - if rel_buf is None: - return 1 + if rel_buf is None: return 1 string.strcpy(rel_buf, rel_path) entry.RelPath = rel_buf @@ -140,17 +128,14 @@ def add_file_entry(result: ScanResult | t.CPtr, # ============================================================ # compute_file_sha1 - 读取文件内容并计算 SHA1(CRLF→LF 后计算,与 Projectrans.py 一致) # ============================================================ -def compute_file_sha1(pool: memhub.MemBuddy*, - file_path: str) -> str: +def compute_file_sha1(pool: memhub.MemBuddy*, file_path: str) -> str: """读取文件内容并计算 SHA1 前16字符(CRLF→LF 后计算,与 Projectrans.py 一致)""" - if pool is None or file_path is None: - return None + if pool is None or file_path is None: return None # 读取文件内容(stdlib.malloc 分配,避免 mbuddy 池耗尽);BUF_SIZE 须与翻译侧 SRC_BUF_SIZE(1MB)一致,否则尾部变更不改 SHA1 导致缓存永不失效 BUF_SIZE: sizet = 1048576 buf: bytes = Utils.read_file_to_buf(file_path, BUF_SIZE) - if buf is None: - return None + if buf is None: return None # 原地去除 \r(CRLF → LF),与 Projectrans.py 文本模式读取一致 buf_len: sizet = string.strlen(buf) @@ -189,7 +174,7 @@ def compute_file_sha1(pool: memhub.MemBuddy*, def scan_directory_recursive(pool: memhub.MemBuddy*, root_dir: str, rel_prefix: str, - result: ScanResult | t.CPtr, + result: ScanResult*, inc_dir: str) -> int: """递归扫描目录,收集 .vp/.py 文件(inc_dir 为所属 includes 根目录)""" if pool is None or root_dir is None or result is None: @@ -301,12 +286,12 @@ def scan_directory_recursive(pool: memhub.MemBuddy*, # scan_includes - 扫描 includes 目录入口(返回所有 .vp 文件路径与 SHA1) # ============================================================ def scan_includes(pool: memhub.MemBuddy*, - includes_dirs: str) -> ScanResult | t.CPtr: + includes_dirs: str) -> ScanResult*: """扫描 includes 目录(支持空格分隔的多目录),返回所有 .vp/.py 文件的扫描结果""" if pool is None or includes_dirs is None: return None - result: ScanResult | t.CPtr = create_scan_result(pool) + result: ScanResult* = create_scan_result(pool) if result is None: return None @@ -338,15 +323,15 @@ def scan_includes(pool: memhub.MemBuddy*, # ============================================================ # find_entry_by_module - 按模块名查找文件条目 # ============================================================ -def find_entry_by_module(result: ScanResult | t.CPtr, - module_name: str) -> FileEntry | t.CPtr: +def find_entry_by_module(result: ScanResult*, + module_name: str) -> FileEntry*: """按模块名查找文件条目""" if result is None or module_name is None: return None entry_size: sizet = FileEntry.__sizeof__() for i in range(result.Count): entry_addr: uint64 = uint64(result.Entries) + i * entry_size - entry: FileEntry | t.CPtr = (FileEntry | t.CPtr)(entry_addr) + entry: FileEntry* = (FileEntry*)(entry_addr) if entry is not None: if entry.ModuleName is not None: if string.strcmp(entry.ModuleName, module_name) == 0: @@ -367,7 +352,7 @@ def _PathExistsA(path: str) -> int: """ if path is None: return 0 - attr: ULONG = w32.win32file.GetFileAttributesA(path) + attr: ULONG = win32file.GetFileAttributesA(path) if attr == 0xFFFFFFFF: # INVALID_FILE_ATTRIBUTES return 0 return 1 diff --git a/App/lib/core/Repl.vp b/App/lib/core/Repl.vp index 63d51b9..b32d46a 100644 --- a/App/lib/core/Repl.vp +++ b/App/lib/core/Repl.vp @@ -72,8 +72,8 @@ define _REPL_JMPBUF_SIZE = 256 # setjmp/longjmp:mingw-w64 x86_64 的 _setjmp 第二参数为 frame 指针, # setjmp 宏即展开为 _setjmp(buf, NULL)(非 SEH 场景传 None 即可) -extern def _setjmp(buf: t.CPtr, frame: t.CPtr) -> int -extern def longjmp(buf: t.CPtr, val: int) +extern def _setjmp(buf: rawptr, frame: rawptr) -> int +extern def longjmp(buf: rawptr, val: int) # PermPool(由 main 注入):jmp_buf 生命周期须覆盖整个会话,不能被 mb.reset_to 回收 _perm_pool: memhub.MemBuddy* @@ -304,7 +304,7 @@ def ReplFindProject(Out: bytes, Cap: int, Diag: bytes, DiagCap: int) -> int: # 模块级 AnnAssign 的返回类型签名由 TranslatorGenMixin.vp:721-742 登记 → # 调用点经 CallGenMixin.vp:960-984 走"按实参构造签名 + 间接 call"路径。 # M2 约定:唯一实参是 ctx 基址(i8*),返回状态码 int(结果经 ctx 回传)。 -ReplFragFn: t.Callable[[t.CPtr], int] = None +ReplFragFn: callable[[rawptr], int] = None # 片段序号:模块级(longjmp 恢复后仍单调递增)→ 符号名/DLL 文件名在会话内不复用 ReplFragNo: int = 1 # 会话临时目录 %TEMP%\TransPyV_repl\(不污染用户工程目录;pid 隔离并发会话) @@ -336,7 +336,7 @@ ReplVarTable: rawptr[GenTypes.ReplVarEntry] = None ReplScratch: rawptr[GenTypes.ReplVarEntry] = None # 恢复点 jmp_buf(PermPool,会话期存活):run 里 _setjmp 到它, # VLogger.repl_abort 从流水线任意深度 longjmp 回它。每片段入口重注册(幂等)。 -ReplJmpBuf: t.CPtr = None +ReplJmpBuf: rawptr = None # 片段开始时的会话表水位(ReplCtxObj.Count):恢复时回滚到它, # 丢弃失败片段的半成品登记(repl_ensure_entry 已 Count+1 但 repl_seal 报错的条目)。 ReplSavedVarCount: int = 0 @@ -652,7 +652,7 @@ def _repl_echo_result(frag_name: str, res: rawptr[GenTypes.ReplResult]) -> int: stdio.printf("%s => %f\n", frag_name, fv.F) return 0 if k == GenTypes.REPL_RES_STR: - sp: t.CPtr = t.CPtr(res.A) + sp: rawptr = rawptr(res.A) if sp is None: stdio.printf("%s => \n", frag_name) return 0 @@ -768,8 +768,8 @@ def ReplBaselineCapture() -> int: cdef_names: list[str]* = GenApi._g_gen.TypeGenCDef.CDefineNames if cdef_names is not None: cdef_vals: list[str]* = GenApi._g_gen.TypeGenCDef.CDefineValues - cdef_dbl: list[int] | t.CPtr = GenApi._g_gen.TypeGenCDef.CDefineDoubleFlags - cdef_str: list[int] | t.CPtr = GenApi._g_gen.TypeGenCDef.CDefineStrFlags + cdef_dbl: list[int]* = GenApi._g_gen.TypeGenCDef.CDefineDoubleFlags + cdef_str: list[int]* = GenApi._g_gen.TypeGenCDef.CDefineStrFlags n: sizet = len(cdef_names) i: sizet for i in range(n): @@ -1931,7 +1931,7 @@ def _repl_precheck_session_funcs() -> int: if rc == 2: stdio.printf("M3: 会话函数 '%s' 的签名含不受支持的类型 '%s'\n" " M3 支持 void / i1 / i8 / i16 / i32 / i64 / float / double / " - "i8*(str、bytes、t.CPtr);结构体值/数组/多级指针请改用指针参数" + "i8*(str、bytes、rawptr);结构体值/数组/多级指针请改用指针参数" "或等 M4\n", nm, ReplSigResult.BadType) return 1 @@ -2756,7 +2756,7 @@ def run(mb: memhub.MemBuddy*) -> int: # 若建在 mb 上会被每行 reset_to(mark) 释放 → 下一行解析 use-after-free 崩溃。 ast._init_tables(_perm_pool) - jb: t.CPtr = _perm_pool.alloc(_REPL_JMPBUF_SIZE) + jb: rawptr = _perm_pool.alloc(_REPL_JMPBUF_SIZE) if jb is None: stdio.printf("REPL: jmp_buf 分配失败\n") return 1 diff --git a/App/lib/core/__init__.vp b/App/lib/core/__init__.vp index 0f67288..8f268b2 100644 --- a/App/lib/core/__init__.vp +++ b/App/lib/core/__init__.vp @@ -1,6 +1,3 @@ -import t, c -from stdint import * - # ============================================================ # core 包入口 # ============================================================