diff --git a/App/lib/core/Handles/HandlesClassDef.vp b/App/lib/core/Handles/HandlesClassDef.vp index 13e2c0a..83eb588 100644 --- a/App/lib/core/Handles/HandlesClassDef.vp +++ b/App/lib/core/Handles/HandlesClassDef.vp @@ -16,7 +16,7 @@ import lib.core.Handles.HandlesEnum as HandlesEnum # 枚举成员临时数组最大数量(本地常量) -ENUM_MEMBER_MAX_LOCAL: t.CDefine = 64 +ENUM_MEMBER_MAX_LOCAL: t.CDefine = 128 # REnum 变体表容量上限(本地常量) RENUM_CLASS_MAX: t.CDefine = 64 @@ -3382,6 +3382,13 @@ def _translate_oop_methods(trans: HT.Translator | t.CPtr, if mark_only != 0: return 0 + # 防重入:方法体翻译前先标记 MethodsEmitted=1。 + # 根因:若等全部方法译完再标记,翻译 __iter__(返回 list[T]|t.CPtr)时, + # 返回类型注解会再次触发 _specialize_generic_class,此时 MethodsEmitted + # 仍为 0,走补译分支把同一特化类方法全部重发 → invalid redefinition。 + if oop_entry is not None: + oop_entry.MethodsEmitted = 1 + # 第二遍:翻译每个方法 # 翻译方法体前先预注册 vtable 元数据(VTableMethods/VTableMethodCount)。 # 根因:方法体翻译先于 _generate_vtable,若不预注册,方法体内的 @@ -3414,11 +3421,6 @@ def _translate_oop_methods(trans: HT.Translator | t.CPtr, # 生成 __before_init__ 函数(零值填充 + 默认值赋值 + vtable 指针设置) _generate_before_init(trans, struct_ty, class_name) - # 治本修复:标记方法体已翻译,供 _specialize_generic_class 已注册分支判断 - # Phase 1a mark_only==1 不设此标志,Phase B 补译时据此判断需补译方法体 - if oop_entry is not None: - oop_entry.MethodsEmitted = 1 - return 0 diff --git a/App/lib/core/Handles/HandlesEnum.vp b/App/lib/core/Handles/HandlesEnum.vp index 6b8a1c2..f60d349 100644 --- a/App/lib/core/Handles/HandlesEnum.vp +++ b/App/lib/core/Handles/HandlesEnum.vp @@ -19,7 +19,7 @@ import lib.core.VLogger as VLogger # ============================================================ ENUM_MAX: t.CDefine = 64 -ENUM_MEMBER_MAX: t.CDefine = 64 +ENUM_MEMBER_MAX: t.CDefine = 128 # ============================================================ diff --git a/App/lib/core/Handles/HandlesExprCall.vp b/App/lib/core/Handles/HandlesExprCall.vp index 3677f96..e357b4e 100644 --- a/App/lib/core/Handles/HandlesExprCall.vp +++ b/App/lib/core/Handles/HandlesExprCall.vp @@ -5245,6 +5245,34 @@ def translate_call(pool: memhub.MemBuddy | t.CPtr, gen_ctor_entry = HandlesStruct.find_struct(func_name) if gen_ctor_entry is not None: struct_ty = gen_ctor_entry.Ty + # 别名导入的类构造: from X import Class as Alias → Alias(args) + # 可见性列表按别名注册(HandleImportFromNames 用 local_name=asname),但结构体 + # 按原名注册(如 Keyword as KwNode → 可见 "KwNode"、注册名 "Keyword")。 + # 直接按别名 find_struct 查不到 → 误走普通函数路径生成 @sha1.Keyword 调用 + # (该函数不存在)→ 链接期 undefined reference。此处解析别名→原名再查结构体。 + if gen_ctor_entry is None and trans is not None and cl.func is not None and cl.func.kind() == ast.ASTKind.Name: + if trans._from_imports is not None: + ctor_sha1: str = _lookup_mod_sha1(pool, trans._from_imports, func_name, 0) + if ctor_sha1 is not None: + ctor_orig: str = HandlesImports.lookup_from_import_original( + trans._from_imports, func_name) + if ctor_orig is not None: + # 复制到独立 null 终止缓冲区(from_imports 内部缓冲未终止) + co_len: t.CSizeT = 0 + while ctor_orig[co_len] != ' ' and ctor_orig[co_len] != '\0': + co_len += 1 + co_buf: str = pool.alloc(co_len + 1) + if co_buf is not None: + for co_i in range(co_len): + co_buf[co_i] = ctor_orig[co_i] + co_buf[co_len] = '\0' + # 原名结构体查找(可见性已由别名保证,原名无需再查) + gen_ctor_entry = HandlesStruct.find_struct_by_module(co_buf, ctor_sha1) + if gen_ctor_entry is None: + gen_ctor_entry = HandlesStruct.find_struct(co_buf) + if gen_ctor_entry is not None: + struct_ty = gen_ctor_entry.Ty + func_name = co_buf if struct_ty is not None: if can == 0 and kw_count == 0: # OOP 结构体:即使无参数也调用 __before_init__ diff --git a/App/lib/core/Phase1.vp b/App/lib/core/Phase1.vp index c1ae0ed..b2a9f71 100644 --- a/App/lib/core/Phase1.vp +++ b/App/lib/core/Phase1.vp @@ -650,6 +650,9 @@ def RunPhase1(mb: memhub.MemBuddy | t.CPtr, includes_dir: str, temp_dir: str, stdlib.free(deps_path_a) # 填充内存依赖存储器(供 _BuildReachableSha1Set 使用,不读 .deps.txt) if tr_a._imported_modules is not None: + # [DBG-MC] 临时诊断(验证后移除):只打印 ast/ 的依赖 + if string.strncmp(entry_a.RelPath, "ast", 3) == 0: + stdio.printf("[DBG] deps %s: %s\n", entry_a.RelPath, tr_a._imported_modules) StubMerger.PopulateIncludesDeps(sha1_a, tr_a._imported_modules) # 释放 Translator 的 C malloc 资源 diff --git a/App/lib/core/Phase2.vp b/App/lib/core/Phase2.vp index 0803600..16bc522 100644 --- a/App/lib/core/Phase2.vp +++ b/App/lib/core/Phase2.vp @@ -422,6 +422,10 @@ def RunMultiFileProject(mb: memhub.MemBuddy | t.CPtr, ent: SrcFileEntry | t.CPtr = (SrcFileEntry | t.CPtr)(t.CVoid(ea, t.CPtr)) if ent is None or ent.Path is None: continue + fb_loop: t.CChar | t.CPtr = VLogger.fmt_buf() + if fb_loop is not None: + viperlib.snprintf(fb_loop, 1024, "Phase A 开始翻译: %s", ent.Path) + VLogger.info(fb_loop, "PhaseA-DBG") # 计算源文件的包名(相对 source_dir 的目录部分) src_dir_len_pa: t.CSizeT = string.strlen(source_dir) pkg_pa: str = None @@ -431,6 +435,10 @@ def RunMultiFileProject(mb: memhub.MemBuddy | t.CPtr, tr_a: HandlesTranslator.Translator | t.CPtr = BuildPipeline.TranslateFileGetTrans(mb, ent.Path, ent.Sha1, pkg_pa, 0, temp_dir) if tr_a is None: continue + fb_ok: t.CChar | t.CPtr = VLogger.fmt_buf() + if fb_ok is not None: + viperlib.snprintf(fb_ok, 1024, "Phase A 翻译完成: %s", ent.Path) + VLogger.info(fb_ok, "PhaseA-DBG") # dump stub IR (declarations only) stub_buf_a: bytes = stdlib.malloc(PHASE_A_IR_SIZE)