30 lines
734 B
Python
30 lines
734 B
Python
import t, c
|
|
import stdlib
|
|
import circ_b
|
|
|
|
|
|
# ============================================================
|
|
# 循环引用测试:模块 A
|
|
#
|
|
# circ_a imports circ_b, circ_b imports circ_a — 循环引用
|
|
# ClassA.MakeB() 返回 circ_b.ClassB 实例(跨模块构造 + 类型注解)
|
|
# ============================================================
|
|
|
|
|
|
class ClassA:
|
|
x: t.CInt
|
|
|
|
def __new__(self, val: t.CInt):
|
|
r: ClassA | t.CPtr = stdlib.malloc(ClassA.__sizeof__())
|
|
return r
|
|
|
|
def __init__(self, val: t.CInt):
|
|
self.x = val
|
|
|
|
def GetValue(self) -> t.CInt:
|
|
return self.x
|
|
|
|
def MakeB(self) -> circ_b.ClassB | t.CPtr:
|
|
b: circ_b.ClassB | t.CPtr = circ_b.ClassB(self.x)
|
|
return b
|