diff --git a/App/lib/core/Handles/HandlesTranslator.vp b/App/lib/core/Handles/HandlesTranslator.vp index 9a2a480..ae9cb0f 100644 --- a/App/lib/core/Handles/HandlesTranslator.vp +++ b/App/lib/core/Handles/HandlesTranslator.vp @@ -513,6 +513,12 @@ class Translator: sub_s: ast.Subscript | t.CPtr = (ast.Subscript | t.CPtr)(node) if sub_s.value is not None: self._check_container_type_node(sub_s.value, need_list_box, need_dict_box) + elif k == ast.ASTKind.List: + # [] 字面量:容器模板仍需注册 + need_list_box[0] = 1 + elif k == ast.ASTKind.Dict: + # {} 字面量:容器模板仍需注册 + need_dict_box[0] = 1 # 递归语句块子节点 if node.children is not None: ch_s: list[ast.AST | t.CPtr] | t.CPtr = node.children diff --git a/App/lib/core/StubMerger.vp b/App/lib/core/StubMerger.vp index 4d298e4..65cd29c 100644 --- a/App/lib/core/StubMerger.vp +++ b/App/lib/core/StubMerger.vp @@ -1664,52 +1664,12 @@ def _BuildReachableSha1Set(mb: memhub.MemBuddy | t.CPtr, source_dir: str, viperlib.snprintf(fb, 1024, "源文件直接依赖: '%s'", worklist) VLogger.debug(fb, "Reachable") - # 2.5. 全局预加入基础容器模块(_list/_dict/json) + # 2.5. 预加入基础模块(builtins) # - # 这些模块定义了 list/dict 等内建容器的泛型模板。 - # 使用 list[...]/dict[...] 语法时需要这些模块被翻译并注册模板。 - # 即使源文件和 includes 文件没有显式 import _list,也预加入以确保可达。 - # 这对应 TPC 的 _inject_auto_imports 机制(TPC 在翻译前自动注入 import _list)。 - # _list - if HandlesImports.is_module_imported(worklist, "_list") == 0: - bsha1_l: str = _FindSha1ByModName(sha1_arr, mod_arr, map_count, "_list") - if bsha1_l is not None: - if wl_len + 7 < 8192: - if wl_len > 0: - worklist[wl_len] = ' ' - wl_len += 1 - string.strcpy(worklist + wl_len, "_list") - wl_len += 5 - worklist[wl_len] = ' ' - wl_len += 1 - worklist[wl_len] = '\0' - # _dict - if HandlesImports.is_module_imported(worklist, "_dict") == 0: - bsha1_d: str = _FindSha1ByModName(sha1_arr, mod_arr, map_count, "_dict") - if bsha1_d is not None: - if wl_len + 7 < 8192: - if wl_len > 0: - worklist[wl_len] = ' ' - wl_len += 1 - string.strcpy(worklist + wl_len, "_dict") - wl_len += 5 - worklist[wl_len] = ' ' - wl_len += 1 - worklist[wl_len] = '\0' - # json - if HandlesImports.is_module_imported(worklist, "json") == 0: - bsha1_j: str = _FindSha1ByModName(sha1_arr, mod_arr, map_count, "json") - if bsha1_j is not None: - if wl_len + 6 < 8192: - if wl_len > 0: - worklist[wl_len] = ' ' - wl_len += 1 - string.strcpy(worklist + wl_len, "json") - wl_len += 4 - worklist[wl_len] = ' ' - wl_len += 1 - worklist[wl_len] = '\0' - # builtins(内置函数模块:ord/chr 等,始终纳入编译链,调用时自动关联) + # builtins(内置函数模块:ord/chr 等)始终纳入编译链,调用时自动关联。 + # _list/_dict 不再无条件预加入:Phase A 翻译 App 源文件时 + # _inject_auto_container_visibility 已按需检测 list/dict 使用并注入 + # _imported_modules(含 []/{} 字面量),json 由 _dict 的真实 import 链带入。 if HandlesImports.is_module_imported(worklist, "builtins") == 0: bsha1_b: str = _FindSha1ByModName(sha1_arr, mod_arr, map_count, "builtins") if bsha1_b is not None: