去除 import t, c
This commit is contained in:
1 parent
579cf8d8e0
commit
e67b80c083
112 files changed
+1235
-1347
No files matched your search
+46
-51
@@ -1,5 +1,3 @@
|
||||
import t, c
|
||||
from t import CInt, CInt32T, CUInt32T, CUInt64T, CFloat64T, CPtr, CChar, CDefine, CUInt16T
|
||||
import viperlib
|
||||
import stdlib
|
||||
import platmacro
|
||||
@@ -24,22 +22,19 @@ define DISABLED = 0
|
||||
define PAGE_SIZE = 4096
|
||||
define BUFFER_LEN = 256
|
||||
|
||||
CODE_SEG: t.CDefine | uint16 = 0x08
|
||||
DATA_SEG: t.CDefine | uint16 = 0x10
|
||||
STACK_SEG: t.CDefine | uint16 = 0x20
|
||||
define CODE_SEG: uint16 = 0x08
|
||||
define DATA_SEG: uint16 = 0x10
|
||||
define STACK_SEG: uint16 = 0x20
|
||||
|
||||
|
||||
def MAKE_FLAG(bit: CInt32T) -> t.CDefine:
|
||||
return 1 << bit
|
||||
define MAKE_FLAG(bit: int32) -> int32: return 1 << bit
|
||||
|
||||
def CLAMP(x: CInt32T, lo: CInt32T, hi: CInt32T) -> t.CDefine:
|
||||
if x < lo:
|
||||
return lo
|
||||
if x > hi:
|
||||
return hi
|
||||
define CLAMP(x: int32, lo: int32, hi: int32) -> int32:
|
||||
if x < lo: return lo
|
||||
if x > hi: return hi
|
||||
return x
|
||||
|
||||
def test_basic_define() -> CInt:
|
||||
def test_basic_define() -> int:
|
||||
print(MAX_SIZE)
|
||||
print(MIN_VAL)
|
||||
print(MAX_VAL)
|
||||
@@ -47,20 +42,20 @@ def test_basic_define() -> CInt:
|
||||
print(SHIFT_BITS)
|
||||
return 0
|
||||
|
||||
def test_define_arithmetic() -> CInt:
|
||||
a: CInt32T = 10
|
||||
b: CInt32T = a + MAX_SIZE
|
||||
def test_define_arithmetic() -> int:
|
||||
a: int32 = 10
|
||||
b: int32 = a + MAX_SIZE
|
||||
print(b)
|
||||
c_val: CInt32T = (a << SHIFT_BITS) & MASK_BYTE
|
||||
c_val: int32 = (a << SHIFT_BITS) & MASK_BYTE
|
||||
print(c_val)
|
||||
d: CInt32T = MAX_VAL - MIN_VAL
|
||||
d: int32 = MAX_VAL - MIN_VAL
|
||||
print(d)
|
||||
e: CInt32T = PAGE_SIZE / 4
|
||||
e: int32 = PAGE_SIZE / 4
|
||||
print(e)
|
||||
return 0
|
||||
|
||||
def test_define_conditional() -> CInt:
|
||||
mode: CInt32T = ENABLED
|
||||
def test_define_conditional() -> int:
|
||||
mode: int32 = ENABLED
|
||||
if mode == ENABLED:
|
||||
print(1)
|
||||
else:
|
||||
@@ -69,7 +64,7 @@ def test_define_conditional() -> CInt:
|
||||
print(0)
|
||||
else:
|
||||
print(1)
|
||||
val: CInt32T = 50
|
||||
val: int32 = 50
|
||||
if val > MAX_VAL:
|
||||
print(1)
|
||||
else:
|
||||
@@ -80,8 +75,8 @@ def test_define_conditional() -> CInt:
|
||||
print(0)
|
||||
return 0
|
||||
|
||||
def test_define_loop() -> CInt:
|
||||
i: CInt32T = 0
|
||||
def test_define_loop() -> int:
|
||||
i: int32 = 0
|
||||
while i < MAX_VAL:
|
||||
i = i + 1
|
||||
if i > 10:
|
||||
@@ -95,16 +90,16 @@ def test_define_loop() -> CInt:
|
||||
print(i)
|
||||
return 0
|
||||
|
||||
def test_typed_define() -> CInt:
|
||||
seg: CUInt16T = CODE_SEG | DATA_SEG | STACK_SEG
|
||||
def test_typed_define() -> int:
|
||||
seg: uint16 = CODE_SEG | DATA_SEG | STACK_SEG
|
||||
print(seg)
|
||||
cs: CUInt16T = CODE_SEG
|
||||
cs: uint16 = CODE_SEG
|
||||
print(cs)
|
||||
ds: CUInt16T = DATA_SEG
|
||||
ds: uint16 = DATA_SEG
|
||||
print(ds)
|
||||
return 0
|
||||
|
||||
def test_define_function() -> CInt:
|
||||
def test_define_function() -> int:
|
||||
flag0 = MAKE_FLAG(0)
|
||||
print(flag0)
|
||||
flag3 = MAKE_FLAG(3)
|
||||
@@ -113,7 +108,7 @@ def test_define_function() -> CInt:
|
||||
print(flag7)
|
||||
return 0
|
||||
|
||||
def test_define_clamp() -> CInt:
|
||||
def test_define_clamp() -> int:
|
||||
v1 = CLAMP(50, 0, 100)
|
||||
print(v1)
|
||||
v2 = CLAMP(-10, 0, 100)
|
||||
@@ -122,24 +117,24 @@ def test_define_clamp() -> CInt:
|
||||
print(v3)
|
||||
return 0
|
||||
|
||||
def test_define_string() -> CInt:
|
||||
buf: CChar | CPtr = CPtr(stdlib.malloc(BUFFER_LEN))
|
||||
def test_define_string() -> int:
|
||||
buf: str = stdlib.malloc(BUFFER_LEN)
|
||||
viperlib.snprintf(buf, BUFFER_LEN, "MAX_SIZE=%d PAGE=%d MASK=0x%x", MAX_SIZE, PAGE_SIZE, MASK_BYTE)
|
||||
print(buf)
|
||||
stdlib.free(buf)
|
||||
return 0
|
||||
|
||||
def test_define_combined() -> CInt:
|
||||
flags: CUInt32T = MAKE_FLAG(0) | MAKE_FLAG(1) | MAKE_FLAG(2)
|
||||
def test_define_combined() -> int:
|
||||
flags: uint32 = MAKE_FLAG(0) | MAKE_FLAG(1) | MAKE_FLAG(2)
|
||||
print(flags)
|
||||
shifted: CUInt32T = MASK_BYTE << SHIFT_BITS
|
||||
shifted: uint32 = MASK_BYTE << SHIFT_BITS
|
||||
print(shifted)
|
||||
total: CUInt32T = PAGE_SIZE + BUFFER_LEN
|
||||
total: uint32 = PAGE_SIZE + BUFFER_LEN
|
||||
print(total)
|
||||
return 0
|
||||
|
||||
|
||||
def test_cif_basic() -> CInt:
|
||||
def test_cif_basic() -> int:
|
||||
cif ENABLED:
|
||||
print(1)
|
||||
celse:
|
||||
@@ -158,7 +153,7 @@ def test_cif_basic() -> CInt:
|
||||
print(1)
|
||||
return 0
|
||||
|
||||
def test_cif_elif_else() -> CInt:
|
||||
def test_cif_elif_else() -> int:
|
||||
# A cif chain can only be pruned at compile time, so the chain selector must be a CDefine
|
||||
# constant (a runtime variable is rejected).
|
||||
define VAL = 2
|
||||
@@ -178,7 +173,7 @@ def test_cif_elif_else() -> CInt:
|
||||
print(VAL)
|
||||
return 0
|
||||
|
||||
def test_cifdef_cifndef() -> CInt:
|
||||
def test_cifdef_cifndef() -> int:
|
||||
cif defined(MAX_SIZE):
|
||||
print(MAX_SIZE)
|
||||
celse:
|
||||
@@ -197,7 +192,7 @@ def test_cifdef_cifndef() -> CInt:
|
||||
print(1)
|
||||
return 0
|
||||
|
||||
def test_cif_platform() -> CInt:
|
||||
def test_cif_platform() -> int:
|
||||
cif defined(_WIN32):
|
||||
print(1)
|
||||
celse:
|
||||
@@ -214,7 +209,7 @@ def test_cif_platform() -> CInt:
|
||||
print(0)
|
||||
return 0
|
||||
|
||||
def test_cif_nested() -> CInt:
|
||||
def test_cif_nested() -> int:
|
||||
cif ENABLED:
|
||||
cif MAX_SIZE > 512:
|
||||
print(1)
|
||||
@@ -228,7 +223,7 @@ def test_cif_nested() -> CInt:
|
||||
print(0)
|
||||
return 0
|
||||
|
||||
def test_cif_expr() -> CInt:
|
||||
def test_cif_expr() -> int:
|
||||
cif MASK_BYTE & 0x0F:
|
||||
print(1)
|
||||
celse:
|
||||
@@ -247,7 +242,7 @@ def test_cif_expr() -> CInt:
|
||||
print(0)
|
||||
return 0
|
||||
|
||||
def test_platmacro_platform() -> CInt:
|
||||
def test_platmacro_platform() -> int:
|
||||
cif defined(platmacro.IS_WINDOWS):
|
||||
print(1)
|
||||
celse:
|
||||
@@ -266,7 +261,7 @@ def test_platmacro_platform() -> CInt:
|
||||
print(0)
|
||||
return 0
|
||||
|
||||
def test_platmacro_sizes() -> CInt:
|
||||
def test_platmacro_sizes() -> int:
|
||||
print(platmacro.PTR_SIZE)
|
||||
print(platmacro.SIZEOF_INT)
|
||||
print(platmacro.SIZEOF_LONG)
|
||||
@@ -275,7 +270,7 @@ def test_platmacro_sizes() -> CInt:
|
||||
print(platmacro.CACHE_LINE_SIZE)
|
||||
return 0
|
||||
|
||||
def test_platmacro_endian() -> CInt:
|
||||
def test_platmacro_endian() -> int:
|
||||
cif platmacro.IS_LITTLE_ENDIAN == 1:
|
||||
print(1)
|
||||
celse:
|
||||
@@ -290,7 +285,7 @@ def test_platmacro_endian() -> CInt:
|
||||
print(0)
|
||||
return 0
|
||||
|
||||
def test_platmacro_features() -> CInt:
|
||||
def test_platmacro_features() -> int:
|
||||
cif platmacro.HAS_SSE2 == 1:
|
||||
print(1)
|
||||
celse:
|
||||
@@ -305,7 +300,7 @@ def test_platmacro_features() -> CInt:
|
||||
print(0)
|
||||
return 0
|
||||
|
||||
def test_platmacro_align() -> CInt:
|
||||
def test_platmacro_align() -> int:
|
||||
print(platmacro.ALIGNOF_INT)
|
||||
print(platmacro.ALIGNOF_PTR)
|
||||
print(platmacro.ALIGNOF_DOUBLE)
|
||||
@@ -315,7 +310,7 @@ def test_platmacro_align() -> CInt:
|
||||
print(0)
|
||||
return 0
|
||||
|
||||
def test_cifdef_cross_module() -> CInt:
|
||||
def test_cifdef_cross_module() -> int:
|
||||
cif defined(platmacro.IS_WINDOWS):
|
||||
cif platmacro.PTR_SIZE == 8:
|
||||
print(64)
|
||||
@@ -333,7 +328,7 @@ def test_cifdef_cross_module() -> CInt:
|
||||
print(0)
|
||||
return 0
|
||||
|
||||
def test_cifdef_guard() -> CInt:
|
||||
def test_cifdef_guard() -> int:
|
||||
define MY_HEADER_GUARD = 1
|
||||
cif not defined(MY_HEADER_GUARD):
|
||||
print(0)
|
||||
@@ -345,7 +340,7 @@ def test_cifdef_guard() -> CInt:
|
||||
print(0)
|
||||
return 0
|
||||
|
||||
def test_cifdef_undefined() -> CInt:
|
||||
def test_cifdef_undefined() -> int:
|
||||
cif not defined(NONEXISTENT_MACRO_ABC):
|
||||
print(1)
|
||||
celse:
|
||||
@@ -360,7 +355,7 @@ def test_cifdef_undefined() -> CInt:
|
||||
print(1)
|
||||
return 0
|
||||
|
||||
def test_cifdef_complex() -> CInt:
|
||||
def test_cifdef_complex() -> int:
|
||||
cif defined(platmacro.IS_WINDOWS) and platmacro.PTR_SIZE == 8:
|
||||
print(1)
|
||||
celse:
|
||||
|
||||
Reference in new issue
Block a user