把 81 个 .vp 文件的中文 # 注释与三引号文档串改写为简洁英文,每个连续注释块 <=2 行;运行时中文字符串字面量(testcheck.begin/print 等用户可见消息)保持原样。骨架比对 HEAD 与工作区 112 文件漂移 0,全量 77/77 顺序回归通过。
143 lines
3.6 KiB
Plaintext
143 lines
3.6 KiB
Plaintext
import t
|
|
import string
|
|
from linkedlist import GSListNode, GSList
|
|
import memhub
|
|
|
|
|
|
# ===== G5Node: test node extending GSListNode[G5Node] =====
|
|
# Phase1 _specialize_member_types degrades the Next field type T to i8*, not G5Node*.
|
|
|
|
@t.NoVTable
|
|
class G5Node(GSListNode[G5Node]):
|
|
Value: int
|
|
|
|
|
|
# ===== G5Container: container holding a GSList[G5Node] field =====
|
|
# In Phase1 GSList[T] is opaque, so List.Head/Tail/Count access emits no GEP.
|
|
|
|
@t.NoVTable
|
|
class G5Container:
|
|
List: GSList[G5Node]*
|
|
|
|
|
|
# ===== Factory functions =====
|
|
|
|
# G5Node hardcoded size: Next(8) + Value(4) + padding(4) = 16 bytes
|
|
define G5NODE_SIZE = 16
|
|
|
|
def new_g5node(pool: memhub.MemBuddy*) -> G5Node*:
|
|
"""Allocate and zero-initialize a G5Node from pool."""
|
|
ptr: G5Node* = pool.alloc(G5NODE_SIZE)
|
|
if ptr is None: return None
|
|
string.memset(ptr, 0, G5NODE_SIZE)
|
|
return ptr
|
|
|
|
|
|
# GSList hardcoded size: Head(8) + Tail(8) + Count(8) = 24 bytes
|
|
define G5LIST_SIZE = 24
|
|
|
|
def new_g5list(pool: memhub.MemBuddy*) -> GSList[G5Node]*:
|
|
"""Allocate and zero-initialize a GSList container from pool."""
|
|
gsl: t.CPtr = pool.alloc(G5LIST_SIZE)
|
|
if gsl is None: return None
|
|
string.memset(gsl, 0, G5LIST_SIZE)
|
|
return gsl
|
|
|
|
|
|
# G5Container hardcoded size: List(8) = 8 bytes
|
|
define G5CONTAINER_SIZE = 8
|
|
|
|
def new_g5container(pool: memhub.MemBuddy*) -> G5Container*:
|
|
"""Allocate and zero-initialize a G5Container from pool."""
|
|
ptr: G5Container* = pool.alloc(G5CONTAINER_SIZE)
|
|
if ptr is None: return None
|
|
string.memset(ptr, 0, G5CONTAINER_SIZE)
|
|
return ptr
|
|
|
|
|
|
# ===== Field accessors (bypass stub-type limits in other modules) =====
|
|
# Cross-module GSList is opaque, so field access silently emits no GEP; these run here.
|
|
|
|
def g5list_get_head(lst: GSList[G5Node]*) -> G5Node*:
|
|
"""Get the list head node."""
|
|
if lst is None: return None
|
|
return lst.Head
|
|
|
|
|
|
def g5list_get_tail(lst: GSList[G5Node]*) -> G5Node*:
|
|
"""Get the list tail node."""
|
|
if lst is None: return None
|
|
return lst.Tail
|
|
|
|
|
|
def g5list_get_count(lst: GSList[G5Node]*) -> sizet:
|
|
"""Get the list node count."""
|
|
if lst is None: return 0
|
|
return lst.Count
|
|
|
|
|
|
def g5list_set_head(lst: GSList[G5Node]*, node: G5Node*):
|
|
"""Set the list head node."""
|
|
if lst is None: return
|
|
lst.Head = node
|
|
|
|
|
|
def g5list_set_tail(lst: GSList[G5Node]*, node: G5Node*):
|
|
"""Set the list tail node."""
|
|
if lst is None: return
|
|
lst.Tail = node
|
|
|
|
|
|
def g5list_set_count(lst: GSList[G5Node]*, count: sizet):
|
|
"""Set the list node count."""
|
|
if lst is None: return
|
|
lst.Count = count
|
|
|
|
|
|
def g5list_append(lst: GSList[G5Node]*, node: G5Node*):
|
|
"""Append node to the list end (O(1)) by directly updating
|
|
Head/Tail/Count, since GSList.append may be missing cross-module.
|
|
"""
|
|
if lst is None or node is None: return
|
|
node.Next = None
|
|
if lst.Head is None:
|
|
lst.Head = node
|
|
else:
|
|
lst.Tail.Next = node
|
|
lst.Tail = node
|
|
lst.Count += 1
|
|
|
|
|
|
# ===== G5Node accessors =====
|
|
|
|
def g5node_get_value(node: G5Node*) -> int:
|
|
if node is None: return 0
|
|
return node.Value
|
|
|
|
|
|
def g5node_set_value(node: G5Node*, value: int):
|
|
if node is None: return
|
|
node.Value = value
|
|
|
|
|
|
def g5node_get_next(node: G5Node*) -> G5Node*:
|
|
if node is None: return None
|
|
return node.Next
|
|
|
|
|
|
def g5node_set_next(node: G5Node*, next_node: G5Node*):
|
|
if node is None: return
|
|
node.Next = next_node
|
|
|
|
|
|
# ===== G5Container accessors =====
|
|
|
|
def g5container_get_list(container: G5Container*) -> GSList[G5Node]*:
|
|
if container is None: return None
|
|
return container.List
|
|
|
|
|
|
def g5container_set_list(container: G5Container*, lst: GSList[G5Node]*):
|
|
if container is None: return
|
|
container.List = lst
|