修正了种子编译器的错误

This commit is contained in:
2026-07-22 21:55:36 +08:00
parent 135aa05485
commit ca7c2120b8
1185 changed files with 12056 additions and 2673 deletions

View File

@@ -166,6 +166,11 @@ class BaseGenMixin:
self._current_tree: Any = None
self._DefineConstants: dict = {}
self._all_define_constants: dict = {}
# 闭包追踪:记录返回闭包的函数和变量
# _closure_return_types: func_name -> (fn_return_type, nonlocal_arg_types)
self._closure_return_types: dict[str, tuple[Any, list[Any]]] = {}
# _closure_var_types: var_name -> (fn_return_type, nonlocal_arg_types)
self._closure_var_types: dict[str, tuple[Any, list[Any]]] = {}
pi: dict[str, bool | int] = self._platform_info
# 根据目标平台设置宏(声明式,从三元组推导)
if pi['is_windows']:
@@ -328,11 +333,17 @@ class BaseGenMixin:
# _parse_llvm_type 先通过此路径创建 opaque 结构体_TryLoadStructFromStub 再 set_body。
elif Entry and Entry.IsEnum and clean_name not in self.class_methods:
return ir.IntType(32)
if Entry and Entry.IsExceptionClass:
# 治本修复:当 clean_name 是已注册的类(在 class_methods 或 class_members 中)时,
# 不应走 IsExceptionClass/IsFunction/IsVariable 分支返回非结构体类型。
# 否则 _get_or_create_struct 返回指针类型(如 _TypedPointerType而非 IdentifiedStructType
# 导致 _TryLoadStructFromStub 的 set_body 被跳过isinstance 检查失败),
# struct 保持不完整字段数,引发跨模块 GEP 越界崩溃。
_is_class_name: bool = clean_name in self.class_methods or clean_name in self.class_members
if Entry and Entry.IsExceptionClass and not _is_class_name:
return ir.IntType(32)
if Entry and Entry.IsFunction:
if Entry and Entry.IsFunction and not _is_class_name:
return ir.PointerType(ir.IntType(8))
if Entry and Entry.IsVariable:
if Entry and Entry.IsVariable and not _is_class_name:
return ir.PointerType(ir.IntType(8))
if Entry and Entry.BaseType:
if isinstance(Entry.BaseType, type) and issubclass(Entry.BaseType, _t.CEnum):

View File

@@ -386,11 +386,27 @@ class StructGenMixin:
continue
# struct body 不完整,清除 _elements 和 stub 缓存以便重新加载
existing_st._elements = None
# 同时清除 sha1 全名 key 的 _elements
# self.structs 中可能同时存在 'Value'(短名) 和 'f9e36e2cd6fa659f.Value'(sha1全名) 两个 key
# _TryLoadStructFromStub 调用 _get_or_create_struct 时会返回 sha1全名 key 的 struct。
# 若只清除短名 key 的 _elementssha1全名 key 的 struct 仍保持错误 bodyis_opaque=False
# 导致 _TryLoadStructFromStub 跳过 set_bodystruct 保持不完整字段数。
_imported_sha1_pre: str = self.class_sha1_map.get(ClassName, '')
if _imported_sha1_pre:
_full_key_pre: str = f"{_imported_sha1_pre}.{ClassName}"
_full_st_pre: ir.IdentifiedStructType | None = self.structs.get(_full_key_pre)
if _full_st_pre is not None and isinstance(_full_st_pre, ir.IdentifiedStructType):
_full_st_pre._elements = None
_import_handler_pre: Any = self._import_handler_ref
if _import_handler_pre is not None:
_cache_key_pre: tuple = (id(self), ClassName)
if _cache_key_pre in _import_handler_pre._struct_Load_cache:
del _import_handler_pre._struct_Load_cache[_cache_key_pre]
# 同时清除 sha1全名 key 的 stub 缓存
if _imported_sha1_pre:
_cache_key_full_pre: tuple = (id(self), f"{_imported_sha1_pre}.{ClassName}")
if _cache_key_full_pre in _import_handler_pre._struct_Load_cache:
del _import_handler_pre._struct_Load_cache[_cache_key_full_pre]
has_vtable: bool = ClassName in self.class_vtable or ClassName in self._cross_module_vtable_classes
if not has_vtable:
p: str | None = self.class_parent.get(ClassName)