feat(TPC): 拓展 isinstance 跨模块支持
vtable linkage 改默认外部强定义(含 initializer 自动归一为空),跨模块可引用 sha1.Class_Vtable;外部引用声明为 i8* 避免 array 类型不匹配;_ResolveVtableAddr 增加 CVTable 状态检查,NoVTable 类回退编译时静态判断避免坏引用。新增 geom_lib.vp 跨模块测试库,main.vp 增加跨模块继承/运行时多态/NoVTable 场景。
This commit is contained in:
1 parent
8783340385
commit
1b89225130
4 files changed
+90
-6
No files matched your search
@@ -560,7 +560,10 @@ class StructGenMixin:
|
||||
VtableType: ir.ArrayType = ir.ArrayType(ir.PointerType(ir.IntType(8)), len(methods))
|
||||
Vtable: ir.GlobalVariable = ir.GlobalVariable(self.module, VtableType, name=self._mangle_name(f"{ClassName}_Vtable"))
|
||||
Vtable.initializer = ir.Constant(VtableType, [ir.Constant(ir.PointerType(ir.IntType(8)), None)] * len(methods))
|
||||
Vtable.linkage = 'internal'
|
||||
# 保持默认 linkage(空字符串,带 initializer 自动打印为外部强定义
|
||||
# global,llvmlite descr 规则:initializer 非空时 linkage 归一为空)。
|
||||
# 2026-08-10:跨模块 isinstance 需引用 sha1.Class_Vtable 符号,
|
||||
# vtable 名含模块 sha1 前缀全局唯一,外部可见不会冲突。
|
||||
self.Vtables[ClassName] = Vtable
|
||||
|
||||
def _create_vtable_for_class(self, ClassName: str) -> None:
|
||||
@@ -589,7 +592,7 @@ class StructGenMixin:
|
||||
VtableType: ir.ArrayType = ir.ArrayType(ir.PointerType(ir.IntType(8)), len(methods))
|
||||
Vtable: ir.GlobalVariable = ir.GlobalVariable(self.module, VtableType, name=_vtable_name)
|
||||
Vtable.initializer = ir.Constant(VtableType, [ir.Constant(ir.PointerType(ir.IntType(8)), None)] * len(methods))
|
||||
Vtable.linkage = 'internal'
|
||||
# 默认 linkage(外部强定义),跨模块 isinstance 引用(与 _create_Vtable_globals 一致)
|
||||
self.Vtables[ClassName] = Vtable
|
||||
|
||||
def _fix_global_var_init(self) -> None:
|
||||
|
||||
Reference in new issue
Block a user