133 lines
3.6 KiB
Python
133 lines
3.6 KiB
Python
import t, c
|
||
# import stdint
|
||
|
||
|
||
MAX_ORDER = 123
|
||
|
||
print
|
||
|
||
@t.Object
|
||
class ClassObject:
|
||
k: t.CInt
|
||
def __init__(self, k: t.CInt):
|
||
self.k = k
|
||
def __enter__(self) -> 'ClassObject':
|
||
return c.Deref(self)
|
||
def __exit__(self):
|
||
self.work()
|
||
def work(self):
|
||
print(1)
|
||
|
||
@t.Object
|
||
class ClassObject1(ClassObject):
|
||
def __init__(self):
|
||
super().__init__(123)
|
||
ClassObject.__init__(self, 123)
|
||
|
||
class ClassObject2:
|
||
a: t.CInt
|
||
b: t.CInt
|
||
c: t.CInt
|
||
|
||
LONGLONG1: t.CTypedef = t.CLong
|
||
LONGLONG2: t.CTypedef | t.CLong | t.CLong
|
||
LONGLONG3: t.CTypedef = t.CLong | t.CLong
|
||
ULONGLONG: t.CTypedef = t.CUnsignedLong | t.CLong
|
||
|
||
class A:
|
||
a: int
|
||
class B:
|
||
b: int
|
||
ccc: list[B, 1212] | t.CPtr = []
|
||
ccc[0].b
|
||
|
||
class memory_block:
|
||
f: t.CInt
|
||
|
||
class __buddy_system(t.CStruct):
|
||
free_lists1: list[memory_block, 1] | t.CPtr # 空闲块链表
|
||
free_lists1: list[memory_block, 1] | t.CPtr # 空闲块链表
|
||
free_lists2: list[memory_block, MAX_ORDER] | t.CPtr # 空闲块链表
|
||
free_lists3: list[memory_block, 1 + 1] | t.CPtr # 空闲块链表
|
||
free_lists4: list[memory_block, MAX_ORDER + 1] | t.CPtr[t.CArrayPtr[t.CArrayPtr]] # 空闲块链表
|
||
total_memory: t.CUInt64T # 总内存大小
|
||
used_memory: t.CUInt64T # 已使用内存大小
|
||
free_memory: t.CUInt64T # 空闲内存大小
|
||
start_addr: t.CVoid | t.CPtr # 内存起始地址
|
||
end_addr: t.CVoid | t.CPtr # 内存结束地址
|
||
|
||
UINT1: t.CTypedef = t.CUnsignedInt
|
||
UINT: t.CTypedef | t.CUnsignedInt # int must be 16-bit or 32-bit
|
||
BYTE: t.CTypedef | t.CUnsignedChar # char must be 8-bit
|
||
WORD: t.CTypedef | t.CUInt16T # 16-bit unsigned
|
||
DWORD: t.CTypedef | t.CUInt32T # 32-bit unsigned
|
||
QWORD: t.CTypedef | t.CUInt64T # 64-bit unsigned
|
||
TCHAR: t.CTypedef | t.CChar
|
||
WCHAR: t.CTypedef | WORD # UTF-16 code unit
|
||
FSIZE_t: t.CTypedef | DWORD
|
||
LBA_t: t.CTypedef | DWORD
|
||
|
||
def DEF_NAMEBUFF() -> t.CDefine:
|
||
lfn: WCHAR | t.CPtr # Pointer to LFN working buffer and directory entry block scratchpad buffer
|
||
|
||
def add(a: t.CInt, b: t.CInt) -> t.CConst | t.CInt | t.CPtr[t.CPtr]:
|
||
return c.Deref(c.Deref((a + b)))
|
||
|
||
def main(l: t.CInt = 1):
|
||
kkkkkkkkkkkk1: UINT1
|
||
kkkkkkkkkkkk2: UINT
|
||
print(kkkkkkkkkkkk1 + kkkkkkkkkkkkk2)
|
||
ssr: ClassObject | t.CPtr = ClassObject(6)
|
||
with ClassObject(1) as a:
|
||
a.work()
|
||
aaa: t.CInt | t.CPtr[t.CPtr]
|
||
cursor: t.CConst | t.CChar[112] | t.CArrayPtr[t.CArrayPtr]
|
||
k = add(1, 2)
|
||
|
||
co2: ClassObject2
|
||
co22: ClassObject2 = ClassObject2()
|
||
co23 = ClassObject2(a=1, b=1)
|
||
|
||
b: ClassObject | t.CPtr = malloc(ClassObject.__sizeof__())
|
||
b = ClassObject(1)
|
||
with b as llll:
|
||
llll.work()
|
||
|
||
match (l):
|
||
case 1:
|
||
print(1)
|
||
case 2:
|
||
print(2)
|
||
case _:
|
||
print(3)
|
||
if l == 3 and k == 1:
|
||
c.Break()
|
||
print(4)
|
||
c.NoBreak()
|
||
match 3:
|
||
case 1:
|
||
print(1)
|
||
case 2:
|
||
print(2)
|
||
case _:
|
||
print(3)
|
||
if l == 3 and k == 1:
|
||
c.Break()
|
||
print(4)
|
||
c.NoBreak()
|
||
# a := b 格式
|
||
|
||
UINT(123, t.CPtr).__sizeof__() # enum,union的实例化也和typedef一样
|
||
x: t.CInt
|
||
if (x := k) and 666:
|
||
print(x)
|
||
|
||
t.CType(123, UINT).__sizeof__()
|
||
|
||
DEF_NAMEBUFF
|
||
|
||
len(x)
|
||
|
||
math_test: t.CInt = 1+1-2+(3*4/2+1-6)/12+9*9
|
||
|
||
import base64 |