Files
Viper_RegressionTesting/VectorGenericTest/App/vectortest.vp
T
TermiNexus f5da836fbb chore(test): 迁移测试夹具到新语法
机械规则 R2/R3/R4/R6/R7/R8/R13 + R16 保守子集,共 86 文件 2127 行。R1(T | t.CPtr)与 R12(while 下标循环)未做,仍列为待办。全量 77/77 顺序回归通过。
2026-10-05 19:59:02 +08:00

44 lines
1.2 KiB
Plaintext

import t, c
from t import CInt, CPtr, CChar, CFloat64T
import viperlib
import stdlib
import vector
import memhub
define POOL_SIZE = 4096
def vector_main() -> CInt:
buf: str = stdlib.malloc(256)
pool_mem: t.CPtr = stdlib.malloc(POOL_SIZE)
pool: memhub.MemPool | CPtr = memhub.MemPool(pool_mem, POOL_SIZE)
vi: vector.Vector[CInt] | CPtr = vector.Vector(pool, 10, CInt(0))
vi.push(CInt(10))
vi.push(CInt(20))
vi.push(CInt(30))
viperlib.snprintf(buf, 256, "Vector[int]: len=%d, [0]=%d, [1]=%d, [2]=%d", vi.len(), vi.get(0), vi.get(1), vi.get(2))
print(buf)
vi.set(1, CInt(99))
viperlib.snprintf(buf, 256, "Vector[int]: set[1]=99, [1]=%d", vi.get(1))
print(buf)
vi.clear()
viperlib.snprintf(buf, 256, "Vector[int]: cleared, len=%d", vi.len())
print(buf)
vi.free()
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))
viperlib.snprintf(buf, 256, "Vector[double]: len=%d, [0]=%.1f, [1]=%.1f, [2]=%.2f", vd.len(), vd.get(0), vd.get(1), vd.get(2))
print(buf)
vd.free()
stdlib.free(pool_mem)
stdlib.free(buf)
return 0