去除 import t, c
This commit is contained in:
1 parent
579cf8d8e0
commit
e67b80c083
112 files changed
+1235
-1347
No files matched your search
@@ -1,9 +1,8 @@
|
||||
import t, c
|
||||
import testcheck
|
||||
import vectortest
|
||||
|
||||
|
||||
def main() -> int | t.CExport:
|
||||
export def main() -> int:
|
||||
testcheck.begin("VectorGenericTest: Vector 泛型测试")
|
||||
testcheck.section("Vector 泛型")
|
||||
vectortest.vector_main()
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import t, c
|
||||
from t import CInt, CPtr, CChar, CFloat64T
|
||||
import viperlib
|
||||
import stdlib
|
||||
import vector
|
||||
@@ -7,19 +5,19 @@ import memhub
|
||||
|
||||
define POOL_SIZE = 4096
|
||||
|
||||
def vector_main() -> CInt:
|
||||
def vector_main() -> int:
|
||||
buf: str = stdlib.malloc(256)
|
||||
pool_mem: t.CPtr = stdlib.malloc(POOL_SIZE)
|
||||
pool: memhub.MemPool | CPtr = memhub.MemPool(pool_mem, POOL_SIZE)
|
||||
pool_mem: bytes = stdlib.malloc(POOL_SIZE)
|
||||
pool: memhub.MemPool* = 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))
|
||||
vi: vector.Vector[int]* = vector.Vector(pool, 10, int(0))
|
||||
vi.push(int(10))
|
||||
vi.push(int(20))
|
||||
vi.push(int(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))
|
||||
vi.set(1, int(99))
|
||||
viperlib.snprintf(buf, 256, "Vector[int]: set[1]=99, [1]=%d", vi.get(1))
|
||||
print(buf)
|
||||
|
||||
@@ -29,10 +27,10 @@ def vector_main() -> CInt:
|
||||
|
||||
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))
|
||||
vd: vector.Vector[double]* = vector.Vector(pool, 8, double(0.0))
|
||||
vd.push(double(1.5))
|
||||
vd.push(double(2.7))
|
||||
vd.push(double(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)
|
||||
|
||||
|
||||
Reference in new issue
Block a user