From 76e1acf4dac2fc1c066186d8c04626c6fb99dd2c Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Sat, 3 Oct 2026 11:16:47 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E6=B3=9B=E5=9E=8B=E7=B1=BB=E6=B3=A8?= =?UTF-8?q?=E8=A7=A3=E8=A1=A5=E5=85=A8=E7=B1=BB=E5=9E=8B=E5=AE=9E=E5=8F=82?= =?UTF-8?q?=EF=BC=88G5=20=E7=9A=84=20GSList[G5Node]=E3=80=81VectorGenericT?= =?UTF-8?q?est=20=E7=9A=84=20Vector[CInt]/[CFloat64T]=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 配合 TransPyV 新增的「泛型类注解必须带类型实参」fail-fast,把裸泛型注解改为带实参写法。 --- G5/includes/g5container.vp | 20 ++++++++++---------- VectorGenericTest/App/vectortest.vp | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/G5/includes/g5container.vp b/G5/includes/g5container.vp index 829a29c..90534a9 100644 --- a/G5/includes/g5container.vp +++ b/G5/includes/g5container.vp @@ -53,7 +53,7 @@ def new_g5node(pool: memhub.MemBuddy | t.CPtr) -> G5Node | t.CPtr: # GSList 硬编码大小: Head(8) + Tail(8) + Count(8) = 24 字节 G5LIST_SIZE: t.CDefine = 24 -def new_g5list(pool: memhub.MemBuddy | t.CPtr) -> GSList | t.CPtr: +def new_g5list(pool: memhub.MemBuddy | t.CPtr) -> GSList[G5Node] | t.CPtr: """从 pool 分配并零初始化一个 GSList 容器(Head/Tail/Count 全零)""" gsl: t.CPtr = pool.alloc(G5LIST_SIZE) if gsl is None: return None @@ -83,43 +83,43 @@ def new_g5container(pool: memhub.MemBuddy | t.CPtr) -> G5Container | t.CPtr: # 所有字段。其他模块通过函数调用获取字段值,绕过 stub 限制。 # ============================================================ -def g5list_get_head(lst: GSList | t.CPtr) -> G5Node | t.CPtr: +def g5list_get_head(lst: GSList[G5Node] | t.CPtr) -> G5Node | t.CPtr: """获取链表头节点""" if lst is None: return None return lst.Head -def g5list_get_tail(lst: GSList | t.CPtr) -> G5Node | t.CPtr: +def g5list_get_tail(lst: GSList[G5Node] | t.CPtr) -> G5Node | t.CPtr: """获取链表尾节点""" if lst is None: return None return lst.Tail -def g5list_get_count(lst: GSList | t.CPtr) -> t.CSizeT: +def g5list_get_count(lst: GSList[G5Node] | t.CPtr) -> t.CSizeT: """获取链表节点数""" if lst is None: return 0 return lst.Count -def g5list_set_head(lst: GSList | t.CPtr, node: G5Node | t.CPtr): +def g5list_set_head(lst: GSList[G5Node] | t.CPtr, node: G5Node | t.CPtr): """设置链表头节点""" if lst is None: return lst.Head = node -def g5list_set_tail(lst: GSList | t.CPtr, node: G5Node | t.CPtr): +def g5list_set_tail(lst: GSList[G5Node] | t.CPtr, node: G5Node | t.CPtr): """设置链表尾节点""" if lst is None: return lst.Tail = node -def g5list_set_count(lst: GSList | t.CPtr, count: t.CSizeT): +def g5list_set_count(lst: GSList[G5Node] | t.CPtr, count: t.CSizeT): """设置链表节点数""" if lst is None: return lst.Count = count -def g5list_append(lst: GSList | t.CPtr, node: G5Node | t.CPtr): +def g5list_append(lst: GSList[G5Node] | t.CPtr, node: G5Node | t.CPtr): """将 node 追加到链表末尾(O(1)) 直接操作 Head/Tail/Count 字段,不依赖 GSList.append 方法 @@ -163,11 +163,11 @@ def g5node_set_next(node: G5Node | t.CPtr, next_node: G5Node | t.CPtr): # G5Container 访问器 # ============================================================ -def g5container_get_list(container: G5Container | t.CPtr) -> GSList | t.CPtr: +def g5container_get_list(container: G5Container | t.CPtr) -> GSList[G5Node] | t.CPtr: if container is None: return None return container.List -def g5container_set_list(container: G5Container | t.CPtr, lst: GSList | t.CPtr): +def g5container_set_list(container: G5Container | t.CPtr, lst: GSList[G5Node] | t.CPtr): if container is None: return container.List = lst diff --git a/VectorGenericTest/App/vectortest.vp b/VectorGenericTest/App/vectortest.vp index d481c80..73ed21e 100644 --- a/VectorGenericTest/App/vectortest.vp +++ b/VectorGenericTest/App/vectortest.vp @@ -12,7 +12,7 @@ def vector_main() -> CInt: pool_mem: t.CPtr = stdlib.malloc(POOL_SIZE) pool: memhub.MemPool | CPtr = memhub.MemPool(pool_mem, POOL_SIZE) - vi: vector.Vector | CPtr = vector.Vector(pool, 10, CInt(0)) + vi: vector.Vector[CInt] | CPtr = vector.Vector(pool, 10, CInt(0)) vi.push(CInt(10)) vi.push(CInt(20)) vi.push(CInt(30)) @@ -29,7 +29,7 @@ def vector_main() -> CInt: vi.free() - vd: vector.Vector | CPtr = vector.Vector(pool, 8, CFloat64T(0.0)) + vd: vector.Vector[CFloat64T] | CPtr = vector.Vector(pool, 8, CFloat64T(0.0)) vd.push(CFloat64T(1.5)) vd.push(CFloat64T(2.7)) vd.push(CFloat64T(3.14))