补充
This commit is contained in:
73
.gitignore
vendored
Normal file
73
.gitignore
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
# Python
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
*.so
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
|
||||
# 编译输出
|
||||
*.exe
|
||||
*.out
|
||||
*.o
|
||||
*.obj
|
||||
*.a
|
||||
*.lib
|
||||
*.dll
|
||||
*.so
|
||||
|
||||
# 调试文件
|
||||
*.p2c
|
||||
debug.txt
|
||||
*.ll
|
||||
|
||||
# 备份文件
|
||||
* copy.py
|
||||
* copy.c
|
||||
|
||||
# IDE
|
||||
.vscode/
|
||||
.idea/
|
||||
*.swp
|
||||
*.swo
|
||||
*~
|
||||
|
||||
# 测试输出
|
||||
test.exe
|
||||
test_split.exe
|
||||
|
||||
# 排除独立仓库的目录
|
||||
ViperOS/
|
||||
zlib copy/
|
||||
|
||||
# 磁盘镜像
|
||||
*.img
|
||||
*.vmdk
|
||||
*.7z
|
||||
*.fd
|
||||
|
||||
# 日志文件
|
||||
*.log
|
||||
|
||||
# 字体文件
|
||||
*.ttc
|
||||
*.ttf
|
||||
|
||||
# VMware
|
||||
Undo/vmware/
|
||||
|
||||
# Trae AI
|
||||
.trae/
|
||||
391
BenchmarkProject/App/benchmark_main.py
Normal file
391
BenchmarkProject/App/benchmark_main.py
Normal file
@@ -0,0 +1,391 @@
|
||||
from stdlib import malloc, free
|
||||
from stdint import *
|
||||
import string
|
||||
import w32.win32console
|
||||
from stdarg import va_start, va_end, va_arg, va_list
|
||||
import t
|
||||
import c
|
||||
|
||||
|
||||
class Struct1:
|
||||
a: UINT
|
||||
b: UINT = 123
|
||||
|
||||
|
||||
class Item:
|
||||
data: t.CVoid | t.CPtr
|
||||
size: t.CSizeT
|
||||
|
||||
|
||||
class List:
|
||||
items: Item | t.CPtr
|
||||
count: t.CSizeT = 0
|
||||
capacity: t.CSizeT = 4
|
||||
|
||||
def __init__(self):
|
||||
self.count = 0
|
||||
self.capacity = 4
|
||||
self.items = malloc(self.capacity * Item.__sizeof__())
|
||||
|
||||
def append(self, data: t.CVoid | t.CPtr, size: t.CSizeT):
|
||||
self.count += 1
|
||||
item: Item | t.CPtr = self.items[self.count - 1]
|
||||
item.size = size
|
||||
item.data = malloc(size + 1)
|
||||
memcpy(item.data, data, size)
|
||||
|
||||
def get(self, index: t.CSizeT) -> t.CInt8T | t.CPtr:
|
||||
if index >= self.count:
|
||||
return None
|
||||
return self.items[index].data
|
||||
|
||||
def free(self):
|
||||
i: t.CSizeT = 0
|
||||
for i in range(self.count):
|
||||
if self.items[i].data != 0:
|
||||
free(self.items[i].data)
|
||||
free(self.items)
|
||||
|
||||
|
||||
class EnumTest(t.CEnum):
|
||||
A: c.State
|
||||
B: c.State
|
||||
C: c.State
|
||||
Len: c.State
|
||||
|
||||
|
||||
@t.Object
|
||||
class OOPTest:
|
||||
a: UINT
|
||||
b: UINT = 12345
|
||||
c: UINT
|
||||
|
||||
def __init__(self):
|
||||
self.a = 451
|
||||
|
||||
def set_c(self, v: UINT):
|
||||
self.c = v
|
||||
|
||||
def __call__(self, a: UINT, b: UINT) -> UINT:
|
||||
return a + b
|
||||
|
||||
def __enter__(self) -> 'OOPTest' | t.CPtr:
|
||||
return self
|
||||
|
||||
def __exit__(self):
|
||||
self.a = 99
|
||||
self.b = 99
|
||||
self.c = 99
|
||||
|
||||
def __add__(self, other: 'OOPTest' | t.CPtr) -> 'OOPTest' | t.CPtr:
|
||||
s = OOPTest()
|
||||
s.a = (self.a + other.a)
|
||||
return s
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"OOPTest ({self.a}) ({self.b}) ({self.c})"
|
||||
|
||||
def __bool__(self) -> bool:
|
||||
return bool(self.a != 0)
|
||||
|
||||
def __len__(self) -> UINT:
|
||||
return self.a
|
||||
|
||||
|
||||
@t.Object
|
||||
class RangeOOPSimulation:
|
||||
start: UINT
|
||||
end: UINT
|
||||
|
||||
def __init__(self, start: UINT, end: UINT):
|
||||
self.start = start
|
||||
self.end = end
|
||||
|
||||
def __iter__(self) -> 'RangeOOPSimulation' | t.CPtr:
|
||||
return self
|
||||
|
||||
def __next__(self) -> UINT:
|
||||
if self.start >= self.end:
|
||||
raise StopIteration
|
||||
self.start += 1
|
||||
return self.start - 1
|
||||
|
||||
|
||||
GLOBAL_VAR: t.CInt = 0
|
||||
|
||||
|
||||
def rebutnotreGLOBAL_VAR() -> t.CInt:
|
||||
GLOBAL_VAR = 100
|
||||
|
||||
|
||||
def reGLOBAL_VAR() -> t.CInt:
|
||||
global GLOBAL_VAR
|
||||
GLOBAL_VAR = 100
|
||||
|
||||
|
||||
def function2function() -> t.CInt:
|
||||
def func() -> t.CInt:
|
||||
x = 1000
|
||||
|
||||
def func2() -> t.CInt:
|
||||
nonlocal x
|
||||
x = 1000000
|
||||
|
||||
func2()
|
||||
return x
|
||||
|
||||
return func()
|
||||
|
||||
|
||||
def manyreturn() -> tuple[t.CInt, t.CInt]:
|
||||
return 114, 514
|
||||
|
||||
|
||||
def str_to_hex(s: str) -> str:
|
||||
buf: str = malloc(1024)
|
||||
out: str = buf
|
||||
hex_chars: list[t.CChar, None] = "0123456789ABCDEF"
|
||||
while c.Cast(s) != 0:
|
||||
cr: t.CUnsignedChar = c.CCast(s)
|
||||
c.Set(c.CCast(out), hex_chars[(cr >> 4) & 0xF])
|
||||
out += 1
|
||||
c.Set(c.CCast(out), hex_chars[cr & 0xF])
|
||||
out += 1
|
||||
s += 1
|
||||
c.Set(c.CCast(out), 0)
|
||||
return buf
|
||||
|
||||
|
||||
def int_to_hex(num: int) -> str:
|
||||
buf = t.CChar(malloc(128), t.CPtr)
|
||||
if not buf:
|
||||
return None
|
||||
|
||||
hex_chars: list[t.CChar, None] = "0123456789ABCDEF"
|
||||
i = 0
|
||||
|
||||
buf[i] = '0'
|
||||
buf[i + 1] = 'x'
|
||||
i += 2
|
||||
|
||||
if num == 0:
|
||||
buf[i] = '0'
|
||||
i += 1
|
||||
buf[i] = '0'
|
||||
i += 1
|
||||
buf[i] = '\0'
|
||||
return buf
|
||||
|
||||
temp: list[t.CChar, 32]
|
||||
temp_idx = 0
|
||||
|
||||
n: t.CUnsignedInt = t.CUnsignedInt(num)
|
||||
|
||||
while n > 0:
|
||||
rem: t.CInt = n & 0xF
|
||||
temp[temp_idx] = hex_chars[rem]
|
||||
temp_idx += 1
|
||||
n = n >> 4
|
||||
|
||||
while temp_idx > 0:
|
||||
temp_idx -= 1
|
||||
buf[i] = temp[temp_idx]
|
||||
i += 1
|
||||
|
||||
buf[i] = '\0'
|
||||
return buf
|
||||
|
||||
|
||||
def int_to_str(num: int) -> str:
|
||||
buf: t.CChar | t.CPtr = t.CChar(malloc(128), t.CPtr)
|
||||
if not buf:
|
||||
return None
|
||||
is_negative = 0
|
||||
i = 0
|
||||
if num == 0:
|
||||
buf[i] = '0'
|
||||
i += 1
|
||||
buf[i] = '\0'
|
||||
return buf
|
||||
if num < 0:
|
||||
is_negative = 1
|
||||
num = -num
|
||||
while num > 0:
|
||||
rem = num % 10
|
||||
buf[i] = '0' + rem
|
||||
i += 1
|
||||
num = num / 10
|
||||
if is_negative:
|
||||
buf[i] = '-'
|
||||
i += 1
|
||||
buf[i] = '\0'
|
||||
start = 0
|
||||
end = i - 1
|
||||
while start < end:
|
||||
tr: t.CChar = buf[start]
|
||||
buf[start] = buf[end]
|
||||
buf[end] = tr
|
||||
start += 1
|
||||
end -= 1
|
||||
return buf
|
||||
|
||||
|
||||
def main():
|
||||
w32.win32console.SetConsoleOutputCP(65001)
|
||||
w32.win32console.SetConsoleCP(65001)
|
||||
|
||||
print("============== BENCHMARK 1: Structures & OOP ==============")
|
||||
|
||||
print("\nTesting Struct1:")
|
||||
s1_: Struct1 = Struct1(10)
|
||||
print("s1_.a:", s1_.a)
|
||||
print("s1_.b:", s1_.b)
|
||||
|
||||
print("\nTesting OOPTest class:")
|
||||
d = OOPTest()
|
||||
d.set_c(100)
|
||||
d.a = 1
|
||||
print("d.a:", d.a)
|
||||
print("d.b:", d.b)
|
||||
print("d.c:", d.c)
|
||||
|
||||
print("\nTesting __call__ (d(1, 2)):")
|
||||
print("d(1, 2):", d(1, 2))
|
||||
|
||||
print("\nTesting __bool__:")
|
||||
if d:
|
||||
print("d is truthy (d.a != 0)")
|
||||
else:
|
||||
print("d is falsy (d.a == 0)")
|
||||
|
||||
print("\nTesting __len__:")
|
||||
print("len(d):", len(d))
|
||||
|
||||
print("\nTesting __str__:")
|
||||
print("str(d):", str(d))
|
||||
|
||||
print("\nTesting __add__:")
|
||||
l = OOPTest()
|
||||
l.a = 100
|
||||
result = d + l
|
||||
print("(d + l).a:", result.a)
|
||||
free(l)
|
||||
free(result)
|
||||
|
||||
print("\nTesting context manager (with statement):")
|
||||
with OOPTest() as d2:
|
||||
print("Inside with block, d2(1, 2):", d2(1, 2))
|
||||
print("After exit, d2.__str__():", str(d2))
|
||||
|
||||
print("\nTesting List class:")
|
||||
l = List()
|
||||
nihao = "你好!世界"
|
||||
l.append(c.Addr(114514), t.CInt.__sizeof__())
|
||||
l.append(nihao, len(nihao))
|
||||
print("List count:", l.count)
|
||||
l.free()
|
||||
|
||||
print("\n============== BENCHMARK 2: Global Variables & Functions ==============")
|
||||
|
||||
print("\nTesting global variable re-assignment:")
|
||||
print("Initial GLOBAL_VAR:", GLOBAL_VAR)
|
||||
rebutnotreGLOBAL_VAR()
|
||||
print("After rebutnotreGLOBAL_VAR():", GLOBAL_VAR)
|
||||
reGLOBAL_VAR()
|
||||
print("After reGLOBAL_VAR():", GLOBAL_VAR)
|
||||
|
||||
print("\nTesting function2function with nonlocal:")
|
||||
print("function2function():", function2function())
|
||||
|
||||
print("\nTesting tuple return:")
|
||||
a: t.CInt
|
||||
b: t.CInt
|
||||
a, b = manyreturn()
|
||||
print("manyreturn():", a, b)
|
||||
|
||||
print("\nTesting walrus operator:")
|
||||
kkkkk = 0
|
||||
if not GLOBAL_VAR or (kkkkk := 1):
|
||||
print("GLOBAL_VAR is 0, kkkkk:", kkkkk)
|
||||
print("Final kkkkk:", kkkkk)
|
||||
|
||||
print("\n============== BENCHMARK 3: Memory & Pointers ==============")
|
||||
|
||||
print("\nTesting malloc/free:")
|
||||
p2 = malloc(100)
|
||||
i: t.CInt = 0
|
||||
while i <= 100:
|
||||
p2[i] = 4
|
||||
i += 1
|
||||
all_four = 1
|
||||
for i in range(0, 100 + 1):
|
||||
if p2[i] != 4:
|
||||
all_four = 0
|
||||
break
|
||||
if all_four:
|
||||
print("All 4 - Memory write/read verified")
|
||||
free(p2)
|
||||
|
||||
print("\nTesting for loop with range:")
|
||||
add_num = 0
|
||||
for i in range(0, 100 + 1):
|
||||
add_num += 1
|
||||
print("i:", i, "add_num:", add_num)
|
||||
|
||||
print("\nTesting for loop with continue:")
|
||||
lll = 0
|
||||
for i in range(0, 10 + 1):
|
||||
if i % 2 != 0:
|
||||
continue
|
||||
lll += i
|
||||
print("Sum of even numbers 0-10:", lll)
|
||||
|
||||
print("\n============== BENCHMARK 4: Iteration & Strings ==============")
|
||||
|
||||
print("\nTesting RangeOOPSimulation (custom iterator):")
|
||||
print("Iterating RangeOOPSimulation(0, 6):")
|
||||
for i in RangeOOPSimulation(0, 6):
|
||||
print("RangeOOPSimulation item:", i)
|
||||
|
||||
print("\nTesting str_to_hex:")
|
||||
hex_str = str_to_hex("ABCDEF")
|
||||
print("hex of ABCDEF:", hex_str)
|
||||
free(hex_str)
|
||||
|
||||
print("\nTesting int_to_hex:")
|
||||
hex_num = int_to_hex(255)
|
||||
print("hex of 255:", hex_num)
|
||||
free(hex_num)
|
||||
|
||||
print("\nTesting int_to_str:")
|
||||
num_str = int_to_str(-12345)
|
||||
print("str of -12345:", num_str)
|
||||
free(num_str)
|
||||
|
||||
print("\nTesting f-string with Chinese characters:")
|
||||
chinese = "你好"
|
||||
print(f"{chinese},世界")
|
||||
|
||||
print("\n============== BENCHMARK 5: Exception Handling ==============")
|
||||
|
||||
print("\nTesting try/except/else/finally:")
|
||||
try:
|
||||
print("In try block")
|
||||
assert 1 != 1, "1 == 1"
|
||||
print("This should not print")
|
||||
except AssertionError as e:
|
||||
print("AssertionError caught:", e)
|
||||
except ValueError as e:
|
||||
print("ValueError caught:", e)
|
||||
else:
|
||||
print("No exception in try block")
|
||||
finally:
|
||||
print("Finally block executed")
|
||||
|
||||
free(d)
|
||||
free(d2)
|
||||
|
||||
print("\n============== All Benchmarks Completed ==============")
|
||||
|
||||
|
||||
main()
|
||||
25
BenchmarkProject/project.json
Normal file
25
BenchmarkProject/project.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/TermiNexus/TransPyC/main/schemas/project-schema.json",
|
||||
"name": "BenchmarkProject",
|
||||
"version": "1.0.0",
|
||||
"source_dir": "./App",
|
||||
"temp_dir": "./temp",
|
||||
"output_dir": "./output",
|
||||
"compiler": {
|
||||
"cmd": "llc",
|
||||
"flags": ["-filetype=obj"]
|
||||
},
|
||||
"linker": {
|
||||
"cmd": "clang++",
|
||||
"flags": ["-lmsvcrt", "-lucrt", "-lpthread"],
|
||||
"output": "BenchmarkProject.exe"
|
||||
},
|
||||
"includes": [
|
||||
"./includes"
|
||||
],
|
||||
"options": {
|
||||
"slice_level": 3,
|
||||
"target": "llvm",
|
||||
"strict_mode": true
|
||||
}
|
||||
}
|
||||
18
BenchmarkProject/temp/0a468e9defed89b4.pyi
Normal file
18
BenchmarkProject/temp/0a468e9defed89b4.pyi
Normal file
@@ -0,0 +1,18 @@
|
||||
"""
|
||||
Auto-generated Python stub file from win32.win32console.py
|
||||
Module: win32.win32console
|
||||
"""
|
||||
|
||||
|
||||
c.CIfndef(__WIN32.WIN32CONSOLE_DEFINE__)
|
||||
__WIN32.WIN32CONSOLE_DEFINE__: t.CDefine
|
||||
|
||||
from stdint import *
|
||||
import t, c
|
||||
|
||||
def SetConsoleOutputCP(codepage: UINT) -> BOOL | c.State: pass
|
||||
|
||||
def SetConsoleCP(codepage: UINT) -> BOOL | c.State: pass
|
||||
|
||||
|
||||
c.CEndif()
|
||||
60
BenchmarkProject/temp/0fe4ed83e40705a3.pyi
Normal file
60
BenchmarkProject/temp/0fe4ed83e40705a3.pyi
Normal file
@@ -0,0 +1,60 @@
|
||||
"""
|
||||
Auto-generated Python stub file from stdint.py
|
||||
Module: stdint
|
||||
"""
|
||||
|
||||
import c
|
||||
|
||||
|
||||
c.CIfndef(__STDINT_DEFINE__)
|
||||
__STDINT_DEFINE__: t.CDefine
|
||||
|
||||
import t
|
||||
|
||||
INT: t.CTypedef = t.CInt
|
||||
INTPTR: t.CTypedef = t.CInt | t.CPtr
|
||||
BOOL: t.CTypedef = t.CInt
|
||||
UINT: t.CTypedef = t.CUnsignedInt
|
||||
UINTPTR: t.CTypedef = UINT | t.CPtr
|
||||
BYTE: t.CTypedef = t.CUnsignedChar
|
||||
BYTEPTR: t.CTypedef = BYTE | t.CPtr
|
||||
WORD: t.CTypedef = t.CUInt16T
|
||||
DWORD: t.CTypedef = t.CUInt32T
|
||||
QWORD: t.CTypedef = t.CUInt64T
|
||||
TCHAR: t.CTypedef = t.CChar
|
||||
CHARLIST: t.CTypedef = t.CChar | t.CPtr[t.CPtr]
|
||||
LONGLONG: t.CTypedef = t.CLong | t.CLong
|
||||
ULONGLONG: t.CTypedef = t.CUnsignedLong | t.CLong
|
||||
LONG: t.CTypedef = t.CLong
|
||||
ULONG: t.CTypedef = t.CUnsignedLong
|
||||
WCHAR: t.CTypedef = WORD
|
||||
FSIZE_t: t.CTypedef = DWORD
|
||||
LBA_t: t.CTypedef = DWORD
|
||||
UINTPTR: t.CTypedef = t.CUnsignedInt | t.CPtr
|
||||
VOIDPTR: t.CTypedef = t.CVoid | t.CPtr
|
||||
FLOAT: t.CTypedef = t.CFloat
|
||||
DOUBLE: t.CTypedef = t.CDouble
|
||||
INT8: t.CTypedef = t.CInt8T
|
||||
INT16: t.CTypedef = t.CInt16T
|
||||
INT32: t.CTypedef = t.CInt32T
|
||||
INT64: t.CTypedef = t.CInt64T
|
||||
UINT8: t.CTypedef = t.CUInt8T
|
||||
UINT16: t.CTypedef = t.CUInt16T
|
||||
UINT32: t.CTypedef = t.CUInt32T
|
||||
UINT64: t.CTypedef = t.CUInt64T
|
||||
INT8PTR: t.CTypedef = t.CInt8T | t.CPtr
|
||||
INT16PTR: t.CTypedef = t.CInt16T | t.CPtr
|
||||
INT32PTR: t.CTypedef = t.CInt32T | t.CPtr
|
||||
INT64PTR: t.CTypedef = t.CInt64T | t.CPtr
|
||||
UINT8PTR: t.CTypedef = t.CUInt8T | t.CPtr
|
||||
UINT16PTR: t.CTypedef = t.CUInt16T | t.CPtr
|
||||
UINT32PTR: t.CTypedef = t.CUInt32T | t.CPtr
|
||||
UINT64PTR: t.CTypedef = t.CUInt64T | t.CPtr
|
||||
CHAR8: t.CTypedef = t.CChar8T
|
||||
CHAR16: t.CTypedef = t.CChar16T
|
||||
CHAR32: t.CTypedef = t.CChar32T
|
||||
CHAR8PTR: t.CTypedef = t.CChar8T | t.CPtr
|
||||
CHAR16PTR: t.CTypedef = t.CChar16T | t.CPtr
|
||||
CHAR32PTR: t.CTypedef = t.CChar32T | t.CPtr
|
||||
|
||||
c.CEndif()
|
||||
20
BenchmarkProject/temp/35b3672a3f08a5f6.pyi
Normal file
20
BenchmarkProject/temp/35b3672a3f08a5f6.pyi
Normal file
@@ -0,0 +1,20 @@
|
||||
"""
|
||||
Auto-generated Python stub file from stdlib.py
|
||||
Module: stdlib
|
||||
"""
|
||||
|
||||
|
||||
c.CIfndef(__STDLIB_DEFINE__)
|
||||
__STDLIB_DEFINE__: t.CDefine
|
||||
|
||||
from stdint import *
|
||||
import t, c
|
||||
|
||||
def malloc(size: UINT) -> t.CVoid | t.CPtr | c.State: pass
|
||||
|
||||
def realloc(p: str, p2: t.CLong | t.CLong) -> t.CVoid | t.CPtr | c.State: pass
|
||||
|
||||
def free(p: t.CVoid | t.CPtr) -> None | c.State: pass
|
||||
|
||||
|
||||
c.CEndif()
|
||||
21
BenchmarkProject/temp/6185874d64b55d5f.pyi
Normal file
21
BenchmarkProject/temp/6185874d64b55d5f.pyi
Normal file
@@ -0,0 +1,21 @@
|
||||
"""
|
||||
Auto-generated Python stub file from stdarg.py
|
||||
Module: stdarg
|
||||
"""
|
||||
|
||||
|
||||
c.CIfndef(__STDARG_DEFINE__)
|
||||
__STDARG_DEFINE__: t.CDefine
|
||||
|
||||
import t, c
|
||||
|
||||
def va_start(args: t.CPtr, last_arg: t.CPtr) -> c.State: pass
|
||||
|
||||
def va_arg(args: t.CPtr, type: t.CType) -> t.CType | c.State: pass
|
||||
|
||||
def va_end(args: t.CPtr) -> c.State: pass
|
||||
|
||||
|
||||
va_list: t.CTypedef = t.CUnsignedChar | t.CPtr
|
||||
|
||||
c.CEndif()
|
||||
39
BenchmarkProject/temp/89a417151096c9c8.pyi
Normal file
39
BenchmarkProject/temp/89a417151096c9c8.pyi
Normal file
@@ -0,0 +1,39 @@
|
||||
"""
|
||||
Auto-generated Python stub file from string.py
|
||||
Module: string
|
||||
"""
|
||||
|
||||
|
||||
c.CIfndef(__STRING_DEFINE__)
|
||||
__STRING_DEFINE__: t.CDefine
|
||||
|
||||
import t, c
|
||||
|
||||
def strcpy(dest: t.CChar | t.CPtr, src: t.CConst | t.CChar | t.CPtr) -> t.CChar | t.CPtr | c.State: pass
|
||||
|
||||
def strncpy(dest: t.CChar | t.CPtr, src: t.CConst | t.CChar | t.CPtr, n: t.CSizeT) -> t.CChar | t.CPtr | c.State: pass
|
||||
|
||||
def strlen(str: t.CConst | t.CChar | t.CPtr) -> t.CSizeT | c.State: pass
|
||||
|
||||
def strcmp(str1: t.CConst | t.CChar | t.CPtr, str2: t.CConst | t.CChar | t.CPtr) -> t.CInt | c.State: pass
|
||||
|
||||
def strncmp(str1: t.CConst | t.CChar | t.CPtr, str2: t.CConst | t.CChar | t.CPtr, n: t.CSizeT) -> t.CInt | c.State: pass
|
||||
|
||||
def memcmp(ptr1: t.CConst | t.CVoid | t.CPtr, ptr2: t.CConst | t.CVoid | t.CPtr, n: t.CSizeT) -> t.CInt | c.State: pass
|
||||
|
||||
def strchr(str: t.CConst | t.CChar | t.CPtr, cr: t.CInt) -> t.CChar | t.CPtr | c.State: pass
|
||||
|
||||
def strrchr(str: t.CConst | t.CChar | t.CPtr, cr: t.CInt) -> t.CChar | t.CPtr | c.State: pass
|
||||
|
||||
def memset(ptr: t.CVoid | t.CPtr, value: t.CInt, num: t.CSizeT) -> t.CVoid | t.CPtr | c.State: pass
|
||||
|
||||
def memcpy(dest: t.CVoid | t.CPtr, src: t.CConst | t.CVoid | t.CPtr, num: t.CSizeT) -> t.CVoid | t.CPtr | c.State: pass
|
||||
|
||||
def memmove(dest: t.CVoid | t.CPtr, src: t.CConst | t.CVoid | t.CPtr, num: t.CSizeT) -> t.CVoid | t.CPtr | c.State: pass
|
||||
|
||||
def atoi(s: str) -> t.CInt | c.State: pass
|
||||
|
||||
def snprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: t.CConst | t.CChar | t.CPtr, *args) -> t.CInt | c.State: pass
|
||||
|
||||
|
||||
c.CEndif()
|
||||
6
BenchmarkProject/temp/_sha1_map.txt
Normal file
6
BenchmarkProject/temp/_sha1_map.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
0a468e9defed89b4:includes/win32\win32console.pyi
|
||||
0fe4ed83e40705a3:includes/stdint.pyi
|
||||
35b3672a3f08a5f6:includes/stdlib.pyi
|
||||
6185874d64b55d5f:includes/stdarg.pyi
|
||||
89a417151096c9c8:includes/string.pyi
|
||||
a5c3e35ade4bf308:benchmark_main.py
|
||||
78
BenchmarkProject/temp/a5c3e35ade4bf308.pyi
Normal file
78
BenchmarkProject/temp/a5c3e35ade4bf308.pyi
Normal file
@@ -0,0 +1,78 @@
|
||||
"""
|
||||
Auto-generated Python stub file from benchmark_main.py
|
||||
Module: benchmark_main
|
||||
"""
|
||||
|
||||
|
||||
c.CIfndef(__BENCHMARK_MAIN_DEFINE__)
|
||||
__BENCHMARK_MAIN_DEFINE__: t.CDefine
|
||||
|
||||
from stdlib import malloc, free
|
||||
from stdint import *
|
||||
import string
|
||||
import win32.win32console
|
||||
from stdarg import va_start, va_end, va_arg, va_list
|
||||
import t
|
||||
import c
|
||||
|
||||
class Struct1:
|
||||
a: UINT
|
||||
b: UINT
|
||||
class Item:
|
||||
data: t.CVoid | t.CPtr
|
||||
size: t.CSizeT
|
||||
class List:
|
||||
items: Item | t.CPtr
|
||||
count: t.CSizeT
|
||||
capacity: t.CSizeT
|
||||
def __init__(self: List) -> t.CVoid | c.State: pass
|
||||
def append(self: List, data: t.CVoid | t.CPtr, size: t.CSizeT) -> t.CVoid | c.State: pass
|
||||
def get(self: List, index: t.CSizeT) -> t.CInt8T | t.CPtr | c.State: pass
|
||||
def free(self: List) -> t.CVoid | c.State: pass
|
||||
class EnumTest(t.CEnum):
|
||||
A: c.State
|
||||
B: c.State
|
||||
C: c.State
|
||||
Len: c.State
|
||||
@t.CPythonObject
|
||||
class OOPTest:
|
||||
a: UINT
|
||||
b: UINT
|
||||
c: UINT
|
||||
def __init__(self: OOPTest) -> t.CVoid | c.State: pass
|
||||
def set_c(self: OOPTest, v: UINT) -> t.CVoid | c.State: pass
|
||||
def __call__(self: OOPTest, a: UINT, b: UINT) -> UINT | c.State: pass
|
||||
def __enter__(self: OOPTest) -> 'OOPTest' | t.CPtr | c.State: pass
|
||||
def __exit__(self: OOPTest) -> t.CVoid | c.State: pass
|
||||
def __add__(self: OOPTest, other: 'OOPTest' | t.CPtr) -> 'OOPTest' | t.CPtr | c.State: pass
|
||||
def __str__(self: OOPTest) -> str | c.State: pass
|
||||
def __bool__(self: OOPTest) -> bool | c.State: pass
|
||||
def __len__(self: OOPTest) -> UINT | c.State: pass
|
||||
@t.CPythonObject
|
||||
class RangeOOPSimulation:
|
||||
start: UINT
|
||||
end: UINT
|
||||
def __init__(self: RangeOOPSimulation, start: UINT, end: UINT) -> t.CVoid | c.State: pass
|
||||
def __iter__(self: RangeOOPSimulation) -> 'RangeOOPSimulation' | t.CPtr | c.State: pass
|
||||
def __next__(self: RangeOOPSimulation) -> UINT | c.State: pass
|
||||
|
||||
GLOBAL_VAR: t.CExtern | t.CInt
|
||||
|
||||
def rebutnotreGLOBAL_VAR() -> t.CInt | c.State: pass
|
||||
|
||||
def reGLOBAL_VAR() -> t.CInt | c.State: pass
|
||||
|
||||
def function2function() -> t.CInt | c.State: pass
|
||||
|
||||
def manyreturn() -> tuple[t.CInt, t.CInt] | c.State: pass
|
||||
|
||||
def str_to_hex(s: str) -> str | c.State: pass
|
||||
|
||||
def int_to_hex(num: int) -> str | c.State: pass
|
||||
|
||||
def int_to_str(num: int) -> str | c.State: pass
|
||||
|
||||
def main() -> t.CVoid | c.State: pass
|
||||
|
||||
|
||||
c.CEndif()
|
||||
32
CPython/1.c
Normal file
32
CPython/1.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <Python.h>
|
||||
#include <Windows.h>
|
||||
|
||||
|
||||
// gcc 1.c -ID:\Python312\include -LD:\Python312\libs -lpython312 -static-libgcc -o 1
|
||||
int main() {
|
||||
SetDllDirectoryW(L"D:\\Python312");
|
||||
|
||||
PyConfig config;
|
||||
PyConfig_InitPythonConfig(&config);
|
||||
config.home = Py_DecodeLocale("D:\\Python312", NULL);
|
||||
|
||||
PyStatus status = Py_InitializeFromConfig(&config);
|
||||
PyConfig_Clear(&config);
|
||||
|
||||
if (PyStatus_Exception(status)) {
|
||||
fprintf(stderr, "Failed to initialize Python: %s\n", status.err_msg);
|
||||
return 1;
|
||||
}
|
||||
|
||||
PyObject* py_num = PyLong_FromLong(12345);
|
||||
|
||||
PyObject* py_str = PyObject_Str(py_num);
|
||||
const char* c_str = PyUnicode_AsUTF8(py_str);
|
||||
printf("%s\n", c_str);
|
||||
|
||||
Py_DECREF(py_str);
|
||||
Py_DECREF(py_num);
|
||||
|
||||
Py_Finalize();
|
||||
return 0;
|
||||
}
|
||||
178
CPython/Python/P312/Object.py
Normal file
178
CPython/Python/P312/Object.py
Normal file
@@ -0,0 +1,178 @@
|
||||
import t, c
|
||||
|
||||
|
||||
Py_uintptr_t: t.CTypedef = t.CUIntPtrT
|
||||
Py_intptr_t: t.CTypedef = t.CIntPtrT
|
||||
|
||||
PY_UINT32_T: t.CTypedef = t.CUInt32T
|
||||
PY_UINT64_T: t.CTypedef = t.CUInt64T
|
||||
|
||||
# Signed variants of the above
|
||||
PY_INT32_T: t.CTypedef = t.CInt32T
|
||||
PY_INT64_T: t.CTypedef = t.CInt64T
|
||||
|
||||
# * Py_ssize_t is a signed integral type such that sizeof(Py_ssize_t) ==
|
||||
# * sizeof(size_t). C99 doesn't define such a thing directly (size_t is an
|
||||
# * unsigned integral type). See PEP 353 for details.
|
||||
# * PY_SSIZE_T_MAX is the largest positive value of type Py_ssize_t.
|
||||
|
||||
Py_ssize_t: t.CTypedef = Py_intptr_t
|
||||
Py_hash_t: t.CTypedef = Py_ssize_t
|
||||
|
||||
SIZEOF_VOID_P: t.CDefine = 8
|
||||
|
||||
|
||||
|
||||
# If this structure is modified, Doc/includes/typestruct.h should be updated
|
||||
# as well.
|
||||
class PyTypeObject:
|
||||
ob_base: PyVarObject
|
||||
|
||||
tp_name: t.CConst | str # For printing, in format "<module>.<name>"
|
||||
tp_basicsize: Py_ssize_t
|
||||
tp_itemsize: Py_ssize_t # For allocation
|
||||
|
||||
# Methods to implement standard operations
|
||||
|
||||
tp_dealloc: destructor
|
||||
tp_vectorcall_offset: Py_ssize_t
|
||||
tp_getattr: getattrfunc
|
||||
tp_setattr: setattrfunc
|
||||
tp_as_async: PyAsyncMethods | t.CPtr # formerly known as tp_compare (Python 2) or tp_reserved (Python 3)
|
||||
tp_repr: reprfunc
|
||||
|
||||
# Method suites for standard classes
|
||||
|
||||
tp_as_number: PyNumberMethods | t.CPtr
|
||||
tp_as_sequence: PySequenceMethods | t.CPtr
|
||||
tp_as_mapping: PyMappingMethods | t.CPtr
|
||||
|
||||
# More standard operations (here for binary compatibility)
|
||||
|
||||
tp_hash: hashfunc
|
||||
tp_call: ternaryfunc
|
||||
tp_str: reprfunc
|
||||
tp_getattro: getattrofunc
|
||||
tp_setattro: setattrofunc
|
||||
|
||||
# Functions to access object as input/output buffer
|
||||
tp_as_buffer: PyBufferProcs | t.CPtr
|
||||
|
||||
# Flags to define presence of optional/expanded features
|
||||
tp_flags: t.CUnsignedLong
|
||||
|
||||
tp_doc: t.CConst | str # Documentation string
|
||||
|
||||
# Assigned meaning in release 2.0
|
||||
# call function for all accessible objects
|
||||
tp_traverse: traverseproc
|
||||
|
||||
# delete references to contained objects */
|
||||
tp_clear: inquiry
|
||||
|
||||
# Assigned meaning in release 2.1
|
||||
# rich comparisons
|
||||
tp_richcompare: richcmpfunc
|
||||
|
||||
# weak reference enabler
|
||||
tp_weaklistoffset: Py_ssize_t
|
||||
|
||||
# Iterators
|
||||
tp_iter: getiterfunc
|
||||
tp_iternext: iternextfunc
|
||||
|
||||
# Attribute descriptor and subclassing stuff
|
||||
tp_methods: PyMethodDef | t.CPtr
|
||||
tp_members: PyMemberDef | t.CPtr
|
||||
tp_getset: PyGetSetDef | t.CPtr
|
||||
# Strong reference on a heap type, borrowed reference on a static type
|
||||
tp_base: PyTypeObject | t.CPtr
|
||||
tp_dict: PyObject | t.CPtr
|
||||
tp_descr_get: descrgetfunc
|
||||
tp_descr_set: descrgetfunc
|
||||
tp_dictoffset: Py_ssize_t
|
||||
tp_init: initproc
|
||||
tp_alloc: allocfunc
|
||||
tp_new: newfunc
|
||||
tp_free: freefunc # Low-level free-memory routine
|
||||
tp_is_gc: inquiry # For PyObject_IS_GC
|
||||
tp_bases: PyObjectPtr
|
||||
tp_mro: PyObjectPtr # method resolution order
|
||||
tp_cache: PyObjectPtr # no longer used
|
||||
tp_subclasses: t.CVoid | t.CPtr # for static builtin types this is an index
|
||||
tp_weaklist: PyObjectPtr # not used for static builtin types
|
||||
tp_del: destructor
|
||||
|
||||
# Type attribute cache version tag. Added in version 2.6
|
||||
tp_version_tag: t.CUnsignedInt
|
||||
|
||||
tp_finalize: destructor
|
||||
tp_vectorcall: vectorcallfunc
|
||||
|
||||
# bitset of which type-watchers care about this type
|
||||
tp_watched: t.CUnsignedChar
|
||||
|
||||
|
||||
class PyMethodDef:
|
||||
ml_name: t.CConst | str # The name of the built-in function/method */
|
||||
ml_meth: PyCFunction # The C function that implements it */
|
||||
ml_flags: int # Combination of METH_xxx flags, which mostly describe the args expected by the C func
|
||||
ml_doc: t.CConst | str # The __doc__ attribute, or NULL
|
||||
|
||||
class PyModuleDef:
|
||||
m_base: PyModuleDef_Base
|
||||
m_name: t.CConst | str
|
||||
m_doc: t.CConst | str
|
||||
m_size: Py_ssize_t
|
||||
m_methods: PyMethodDef | t.CPtr
|
||||
m_slots: PyModuleDef_Slot | t.CPtr
|
||||
m_traverse: traverseproc
|
||||
m_clear: inquiry
|
||||
m_free: freefunc
|
||||
|
||||
class PyMemberDef:
|
||||
name: t.CConst | str
|
||||
type: int
|
||||
offset: Py_ssize_t
|
||||
flags: int
|
||||
doc: t.CConst | str
|
||||
|
||||
class PyGetSetDef:
|
||||
name: t.CConst | str
|
||||
get: getter
|
||||
set: setter
|
||||
doc: t.CConst | str
|
||||
closure: t.CVoid | t.CPtr
|
||||
|
||||
|
||||
|
||||
|
||||
class PyVarObject:
|
||||
ob_base: PyObject
|
||||
ob_size: Py_ssize_t # Number of items in variable part
|
||||
|
||||
class PyObject:
|
||||
# _PyObject_HEAD_EXTRA
|
||||
class ob(t.CUnion):
|
||||
ob_refcnt: Py_ssize_t
|
||||
if c.CIf(SIZEOF_VOID_P > 4):
|
||||
ob_refcnt_split: list[PY_UINT32_T, 2]
|
||||
ob_type: PyTypeObject | t.CPtr
|
||||
|
||||
PyObjectPtr: t.CTypedef = PyObject | t.CPtr
|
||||
|
||||
|
||||
#typedef struct PyModuleDef PyModuleDef;
|
||||
#typedef struct PyModuleDef_Slot PyModuleDef_Slot;
|
||||
#typedef struct PyMethodDef PyMethodDef;
|
||||
#typedef struct PyGetSetDef PyGetSetDef;
|
||||
#typedef struct PyMemberDef PyMemberDef;
|
||||
|
||||
#typedef struct _object PyObject;
|
||||
#typedef struct _longobject PyLongObject;
|
||||
#typedef struct _typeobject PyTypeObject;
|
||||
#typedef struct PyCodeObject PyCodeObject;
|
||||
#typedef struct _frame PyFrameObject;
|
||||
|
||||
#typedef struct _ts PyThreadState;
|
||||
#typedef struct _is PyInterpreterState;
|
||||
37
CPython/Python/P312/PyBytesObject.py
Normal file
37
CPython/Python/P312/PyBytesObject.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import Object
|
||||
import t, c
|
||||
|
||||
|
||||
class PyBytesObject:
|
||||
ob_base: Object.PyVarObject
|
||||
ob_shash: Object.Py_hash_t
|
||||
ob_sval: list[t.CChar, 1]
|
||||
|
||||
def _PyBytes_Resize(arg0: Object.PyObjectPtr[t.CPtr], arg1: Object.Py_ssize_t) -> int | t.State: pass
|
||||
def _PyBytes_FormatEx(format: t.CConst | str, format_len: Object.Py_ssize_t, args: Object.PyObjectPtr, use_bytearray: int) -> Object.PyObjectPtr | t.State: pass
|
||||
def _PyBytes_FromHex(string: Object.PyObjectPtr, use_bytearray: int) -> Object.PyObjectPtr | t.State: pass
|
||||
def _PyBytes_DecodeEscape(arg0: t.CConst | str, arg1: Object.Py_ssize_t, arg2: t.CConst | str, arg3: t.CConst | str | t.CPtr) -> Object.PyObjectPtr | t.State: pass
|
||||
|
||||
def _PyBytes_CAST(op) -> t.CDefine | PyBytesObject: (PyBytesObject | t.CPtr)(op)
|
||||
|
||||
def PyBytes_AS_STRING(op: Object.PyObjectPtr) -> t.CStatic | t.CInline | bytes:
|
||||
return _PyBytes_CAST(op).ob_sval
|
||||
|
||||
def _PyBytes_Join(sep: Object.PyObjectPtr, x: Object.PyObjectPtr) -> Object.PyObjectPtr | t.State: pass
|
||||
|
||||
class _PyBytesWriter:
|
||||
buffer: Object.PyObjectPtr
|
||||
allocated: Object.Py_ssize_t
|
||||
min_size: Object.Py_ssize_t
|
||||
use_bytearray: int
|
||||
overallocate: int
|
||||
use_small_buffer: int
|
||||
small_buffer: list[t.CChar, 512]
|
||||
|
||||
def _PyBytesWriter_Init(writer: _PyBytesWriter | t.CPtr) -> t.State: pass
|
||||
def _PyBytesWriter_Finish(writer: _PyBytesWriter | t.CPtr, str: str) -> Object.PyObjectPtr | t.State: pass
|
||||
def _PyBytesWriter_Dealloc(writer: _PyBytesWriter | t.CPtr) -> t.State: pass
|
||||
def _PyBytesWriter_Alloc(writer: _PyBytesWriter | t.CPtr, size: Object.Py_ssize_t) -> bytes | t.State: pass
|
||||
def _PyBytesWriter_Prepare(writer: _PyBytesWriter | t.CPtr, str: str, size: Object.Py_ssize_t) -> bytes | t.State: pass
|
||||
def _PyBytesWriter_Resize(writer: _PyBytesWriter | t.CPtr, str: str, size: Object.Py_ssize_t) -> bytes | t.State: pass
|
||||
def _PyBytesWriter_WriteBytes(writer: _PyBytesWriter | t.CPtr, str: str, bytes: t.CConst | bytes, size: Object.Py_ssize_t) -> bytes | t.State: pass
|
||||
19
CPython/Python/P312/PyFloatObject.py
Normal file
19
CPython/Python/P312/PyFloatObject.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import Object
|
||||
import t, c
|
||||
|
||||
|
||||
class PyFloatObject:
|
||||
ob_base: Object.PyObject
|
||||
ob_fval: t.CDouble
|
||||
|
||||
|
||||
def PyFloat_AS_DOUBLE(op: Object.PyObjectPtr) -> t.CStatic | t.CInline | t.CDouble:
|
||||
return (PyFloatObject | t.CPtr)(op).ob_fval
|
||||
|
||||
def PyFloat_Pack2(x: t.CDouble, p: str, le: int) -> int | t.State: pass
|
||||
def PyFloat_Pack4(x: t.CDouble, p: str, le: int) -> int | t.State: pass
|
||||
def PyFloat_Pack8(x: t.CDouble, p: str, le: int) -> int | t.State: pass
|
||||
|
||||
def PyFloat_Unpack2(p: t.CConst | str, le: int) -> t.CDouble | t.State: pass
|
||||
def PyFloat_Unpack4(p: t.CConst | str, le: int) -> t.CDouble | t.State: pass
|
||||
def PyFloat_Unpack8(p: t.CConst | str, le: int) -> t.CDouble | t.State: pass
|
||||
11
CPython/Python/P312/PyListObject.py
Normal file
11
CPython/Python/P312/PyListObject.py
Normal file
@@ -0,0 +1,11 @@
|
||||
import Object
|
||||
import t, c
|
||||
|
||||
|
||||
class PyListObject:
|
||||
ob_base: Object.PyVarObject
|
||||
ob_item: Object.PyObjectPtr[t.CPtr]
|
||||
allocated: Object.Py_ssize_t
|
||||
|
||||
def _PyList_Extend(arg0: PyListObject | t.CPtr, arg1: PyListObject | t.CPtr) -> PyListObject | t.CPtr | t.State: pass
|
||||
def _PyList_DebugMallocStats(out: FILE | t.CPtr) -> t.State: pass
|
||||
16
CPython/Python/P312/PyLongObject.py
Normal file
16
CPython/Python/P312/PyLongObject.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import Object
|
||||
import t, c
|
||||
|
||||
|
||||
digit: t.CTypedef = t.CUInt32T
|
||||
sdigit: t.CTypedef = t.CInt32T # signed variant of digit
|
||||
twodigits: t.CTypedef = t.CUInt64T
|
||||
stwodigits: t.CTypedef = t.CInt64T # signed variant of twodigits
|
||||
|
||||
class _PyLongValue:
|
||||
lv_tag: t.CUIntPtrT # Number of digits, sign and flags
|
||||
ob_digit: list[digit, 1]
|
||||
|
||||
class PyLongObject:
|
||||
ob_base: Object.PyObject
|
||||
long_value: _PyLongValue
|
||||
38
CPython/Python/P312/PyUnicodeObject.py
Normal file
38
CPython/Python/P312/PyUnicodeObject.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import Object
|
||||
import t, c
|
||||
|
||||
|
||||
# --- Unicode Type -------------------------------------------------------
|
||||
# ASCII-only strings created through PyUnicode_New use the PyASCIIObject
|
||||
# structure. state.ascii and state.compact are set, and the data
|
||||
# immediately follow the structure. utf8_length can be found
|
||||
# in the length field; the utf8 pointer is equal to the data pointer. */
|
||||
class PyASCIIObject:
|
||||
ob_base: Object.PyObject
|
||||
length: Object.Py_ssize_t # Number of code points in the string
|
||||
hash: Object.Py_hash_t # Hash value; -1 if not set
|
||||
class state:
|
||||
interned: t.CUnsignedInt | t.Bit[2]
|
||||
kind: t.CUnsignedInt | t.Bit[3]
|
||||
compact: t.CUnsignedInt | t.Bit[1]
|
||||
ascii: t.CUnsignedInt | t.Bit[1]
|
||||
_: t.CUnsignedInt | t.Bit[25]
|
||||
|
||||
class PyCompactUnicodeObject:
|
||||
_base: PyASCIIObject
|
||||
utf8_length: Object.Py_ssize_t # Number of bytes in utf8, excluding the * terminating \0.
|
||||
utf8: str # UTF-8 representation (null-terminated)
|
||||
|
||||
Py_UCS4: t.CTypedef = t.CUInt32T
|
||||
Py_UCS2: t.CTypedef = t.CUInt16T
|
||||
Py_UCS1: t.CTypedef = t.CUInt8T
|
||||
|
||||
# Object format for Unicode subclasses.
|
||||
class PyUnicodeObject:
|
||||
_base: PyCompactUnicodeObject
|
||||
class data(t.CUnion):
|
||||
any: t.CVoid | t.CPtr
|
||||
latin1: Py_UCS1 | t.CPtr
|
||||
ucs2: Py_UCS2 | t.CPtr
|
||||
ucs4: Py_UCS4 | t.CPtr
|
||||
# Canonical, smallest-form Unicode buffer
|
||||
690
CPython/c.py
Normal file
690
CPython/c.py
Normal file
@@ -0,0 +1,690 @@
|
||||
# C语法定义模块
|
||||
|
||||
import ast
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
||||
|
||||
from . import t
|
||||
|
||||
def _to_str(node):
|
||||
if node is None:
|
||||
return ''
|
||||
if isinstance(node, str):
|
||||
return node
|
||||
if isinstance(node, list):
|
||||
return ' && '.join([_to_str(n) for n in node])
|
||||
NodeType = type(node).__name__
|
||||
if NodeType == 'Constant':
|
||||
return node.value
|
||||
elif NodeType == 'ID':
|
||||
return node.name
|
||||
elif NodeType == 'BinaryOp':
|
||||
left = _to_str(node.left)
|
||||
right = _to_str(node.right)
|
||||
return f'{left} {node.op} {right}'
|
||||
elif NodeType == 'UnaryOp':
|
||||
expr = _to_str(node.expr)
|
||||
return f'{node.op}{expr}'
|
||||
else:
|
||||
return repr(node)
|
||||
|
||||
class Asm:
|
||||
@staticmethod
|
||||
def HandleCall(translator, args, keywords):
|
||||
if not args:
|
||||
return ['__asm__ volatile ("nop");']
|
||||
|
||||
# ========== 核心变量 ==========
|
||||
output_ops = [] # (值表达式, 约束符)
|
||||
input_ops = [] # (值表达式, 约束符)
|
||||
clobbers = [] # 破坏列表实际值
|
||||
operand_seq = 0 # 占位符编号
|
||||
|
||||
# ========== 核心修复:递归提取ASM_DESCR值(支持|组合) ==========
|
||||
def parse_asm_descr(expr):
|
||||
"""
|
||||
递归解析AST节点,确保获取t.ASM_DESCR的实际值,支持|组合
|
||||
处理场景:
|
||||
1. t.ASM_DESCR.XXX → 取属性值
|
||||
2. t.ASM_DESCR.XXX | t.ASM_DESCR.YYY → 拼接两个值
|
||||
3. 常量字符串 → 直接返回
|
||||
"""
|
||||
# 场景1:位或组合(XXX | YYY)
|
||||
if isinstance(expr, ast.BinOp):
|
||||
left_val = parse_asm_descr(expr.left)
|
||||
right_val = parse_asm_descr(expr.right)
|
||||
return left_val + right_val
|
||||
|
||||
# 场景2:t.ASM_DESCR.XXX 多层属性访问
|
||||
elif isinstance(expr, ast.Attribute):
|
||||
# 第一步:判断是否是 t.ASM_DESCR 的属性
|
||||
if isinstance(expr.value, ast.Attribute):
|
||||
# 内层是 t.ASM_DESCR
|
||||
if (isinstance(expr.value.value, ast.Name) and
|
||||
expr.value.value.id == 't' and
|
||||
expr.value.attr == 'ASM_DESCR'):
|
||||
# 取 t.ASM_DESCR.XXX 的实际值
|
||||
AttrName = expr.attr
|
||||
if hasattr(t.ASM_DESCR, AttrName):
|
||||
return getattr(t.ASM_DESCR, AttrName, "")
|
||||
|
||||
# 兼容 t.XXX 简化写法(如果有的话)
|
||||
elif isinstance(expr.value, ast.Name) and expr.value.id == 't':
|
||||
AttrName = expr.attr
|
||||
if hasattr(t.ASM_DESCR, AttrName):
|
||||
return getattr(t.ASM_DESCR, AttrName, "")
|
||||
|
||||
# 场景3:直接传常量(如 "r"、"cc")
|
||||
elif isinstance(expr, ast.Constant):
|
||||
return expr.value
|
||||
|
||||
# 其他场景返回空
|
||||
return ""
|
||||
|
||||
# ========== 步骤1:处理f-string中的内联AsmInp/AsmOut ==========
|
||||
asm_code = ""
|
||||
first_arg = args[0]
|
||||
|
||||
if isinstance(first_arg, ast.JoinedStr):
|
||||
asm_parts = []
|
||||
for part in first_arg.values:
|
||||
if isinstance(part, ast.Constant):
|
||||
asm_parts.append(part.value)
|
||||
elif isinstance(part, ast.FormattedValue):
|
||||
expr = part.value
|
||||
if isinstance(expr, ast.Call) and isinstance(expr.func, ast.Attribute) and expr.func.value.id == 'c':
|
||||
# 解析内联的AsmInp/AsmOut
|
||||
call_node = expr
|
||||
val_ExprNode = translator.HandleExpr(call_node.args[0])[0] if len(call_node.args)>=1 else ""
|
||||
if isinstance(val_ExprNode, str):
|
||||
val_expr = val_ExprNode
|
||||
else:
|
||||
try:
|
||||
val_expr = str(val_ExprNode)
|
||||
except:
|
||||
val_expr = ''
|
||||
constraint = parse_asm_descr(call_node.args[1]) if len(call_node.args)>=2 else ""
|
||||
|
||||
if call_node.func.attr == 'AsmOut':
|
||||
output_ops.append((val_expr, constraint))
|
||||
asm_parts.append(f"%{operand_seq}")
|
||||
operand_seq += 1
|
||||
elif call_node.func.attr == 'AsmInp':
|
||||
input_ops.append((val_expr, constraint))
|
||||
asm_parts.append(f"%{operand_seq}")
|
||||
operand_seq += 1
|
||||
else:
|
||||
asm_parts.append(translator.HandleExpr(expr)[0])
|
||||
asm_code = ''.join(asm_parts)
|
||||
elif isinstance(first_arg, ast.Constant):
|
||||
asm_code = first_arg.value
|
||||
|
||||
# ========== 步骤2:处理参数中的AsmInp/AsmOut和破坏列表 ==========
|
||||
def parse_operand(arg):
|
||||
"""解析 AsmInp/AsmOut 参数"""
|
||||
if isinstance(arg, ast.Call) and isinstance(arg.func, ast.Attribute) and arg.func.value.id == 'c':
|
||||
call_node = arg
|
||||
val_ExprNode = translator.HandleExpr(call_node.args[0])[0] if len(call_node.args)>=1 else ""
|
||||
if isinstance(val_ExprNode, str):
|
||||
val_expr = val_ExprNode
|
||||
else:
|
||||
try:
|
||||
val_expr = str(val_ExprNode)
|
||||
except:
|
||||
val_expr = ''
|
||||
constraint = parse_asm_descr(call_node.args[1]) if len(call_node.args)>=2 else ""
|
||||
|
||||
if call_node.func.attr == 'AsmOut':
|
||||
return ('out', val_expr, constraint)
|
||||
elif call_node.func.attr == 'AsmInp':
|
||||
return ('in', val_expr, constraint)
|
||||
return None
|
||||
|
||||
for arg in args[1:]:
|
||||
result = parse_operand(arg)
|
||||
if result:
|
||||
direction, val_expr, constraint = result
|
||||
if direction == 'out':
|
||||
output_ops.append((val_expr, constraint))
|
||||
operand_seq += 1
|
||||
elif direction == 'in':
|
||||
input_ops.append((val_expr, constraint))
|
||||
operand_seq += 1
|
||||
elif isinstance(arg, ast.List):
|
||||
# 解析破坏列表(支持|组合)
|
||||
for elt in arg.elts:
|
||||
clobber_val = parse_asm_descr(elt)
|
||||
if clobber_val:
|
||||
clobbers.append(clobber_val)
|
||||
|
||||
# ========== 步骤2.5:处理关键字参数 out 和 op ==========
|
||||
for kw in keywords:
|
||||
if kw.arg == 'out':
|
||||
# 处理 out 关键字参数 (输出操作数)
|
||||
if isinstance(kw.value, ast.List):
|
||||
for elt in kw.value.elts:
|
||||
result = parse_operand(elt)
|
||||
if result and result[0] == 'out':
|
||||
output_ops.append((result[1], result[2]))
|
||||
operand_seq += 1
|
||||
elif isinstance(kw.value, ast.Call):
|
||||
result = parse_operand(kw.value)
|
||||
if result and result[0] == 'out':
|
||||
output_ops.append((result[1], result[2]))
|
||||
operand_seq += 1
|
||||
elif kw.arg == 'op':
|
||||
# 处理 op 关键字参数 (clobber,破坏列表)
|
||||
if isinstance(kw.value, ast.List):
|
||||
for elt in kw.value.elts:
|
||||
clobber_val = parse_asm_descr(elt)
|
||||
if clobber_val:
|
||||
clobbers.append(clobber_val)
|
||||
elif kw.arg == 'inp' or kw.arg == 'inputs':
|
||||
# 处理 inp/inputs 关键字参数 (输入操作数,追加到f-string中已有输入之后)
|
||||
if isinstance(kw.value, ast.List):
|
||||
for elt in kw.value.elts:
|
||||
if isinstance(elt, ast.Tuple):
|
||||
# 处理列表中的 (value, constraint) 元组格式
|
||||
if len(elt.elts) >= 2:
|
||||
val_ExprNode = translator.HandleExpr(elt.elts[0])[0] if len(elt.elts) >= 1 else ""
|
||||
if isinstance(val_ExprNode, str):
|
||||
val_expr = val_ExprNode
|
||||
else:
|
||||
try:
|
||||
val_expr = str(val_ExprNode)
|
||||
except:
|
||||
val_expr = ''
|
||||
constraint = parse_asm_descr(elt.elts[1])
|
||||
input_ops.append((val_expr, constraint))
|
||||
operand_seq += 1
|
||||
else:
|
||||
result = parse_operand(elt)
|
||||
if result and result[0] == 'in':
|
||||
input_ops.append((result[1], result[2]))
|
||||
operand_seq += 1
|
||||
elif isinstance(kw.value, ast.Call):
|
||||
result = parse_operand(kw.value)
|
||||
if result and result[0] == 'in':
|
||||
input_ops.append((result[1], result[2]))
|
||||
operand_seq += 1
|
||||
elif isinstance(kw.value, ast.Tuple):
|
||||
# 处理 (value, constraint) 元组格式
|
||||
if len(kw.value.elts) >= 2:
|
||||
val_ExprNode = translator.HandleExpr(kw.value.elts[0])[0] if len(kw.value.elts) >= 1 else ""
|
||||
if isinstance(val_ExprNode, str):
|
||||
val_expr = val_ExprNode
|
||||
else:
|
||||
try:
|
||||
val_expr = str(val_ExprNode)
|
||||
except:
|
||||
val_expr = ''
|
||||
constraint = parse_asm_descr(kw.value.elts[1])
|
||||
input_ops.append((val_expr, constraint))
|
||||
operand_seq += 1
|
||||
elif kw.arg == 'clobber':
|
||||
# 处理 clobber 关键字参数
|
||||
if isinstance(kw.value, ast.List):
|
||||
for elt in kw.value.elts:
|
||||
clobber_val = parse_asm_descr(elt)
|
||||
if clobber_val:
|
||||
clobbers.append(clobber_val)
|
||||
|
||||
# ========== 步骤3:格式化汇编代码 ==========
|
||||
asm_lines = [line.strip() for line in asm_code.split('\n') if line.strip()]
|
||||
formatted_asm = '\n '.join([f'"{line}\\n"' for line in asm_lines])
|
||||
|
||||
# ========== 步骤4:拼接约束字符串 ==========
|
||||
# 输出约束:如果约束已包含 = 或 +,直接使用;否则添加 =
|
||||
def format_constraint(constraint, is_output=True):
|
||||
if not constraint:
|
||||
return ""
|
||||
# 如果约束已包含修饰符,直接返回
|
||||
if '=' in constraint or '+' in constraint:
|
||||
return constraint
|
||||
# 否则添加适当的修饰符
|
||||
return ('=' if is_output else '') + constraint
|
||||
|
||||
out_const = ', '.join([f'"{format_constraint(c, True)}"({v})' for v, c in output_ops]) if output_ops else ""
|
||||
in_const = ', '.join([f'"{format_constraint(c, False)}"({v})' for v, c in input_ops]) if input_ops else ""
|
||||
clobber_const = ', '.join([f'"{x}"' for x in clobbers]) if clobbers else ""
|
||||
|
||||
# 构建约束部分:确保冒号格式正确
|
||||
constraint_parts = []
|
||||
# 输出约束
|
||||
if output_ops:
|
||||
constraint_parts.append(f': {out_const}')
|
||||
elif input_ops or clobbers:
|
||||
constraint_parts.append(':')
|
||||
|
||||
# 输入约束
|
||||
if input_ops:
|
||||
constraint_parts.append(f': {in_const}')
|
||||
elif clobbers:
|
||||
constraint_parts.append(':')
|
||||
|
||||
# 破坏列表
|
||||
if clobbers:
|
||||
constraint_parts.append(f': {clobber_const}')
|
||||
|
||||
constraint_str = ' '.join(constraint_parts)
|
||||
|
||||
# ========== 生成最终代码 ==========
|
||||
final_asm = f'__asm__ __volatile__ (\n {formatted_asm} {constraint_str});'
|
||||
return [final_asm]
|
||||
|
||||
class AsmInp:
|
||||
def __init__(self, value, constraint):
|
||||
self.value = value
|
||||
self.constraint = constraint
|
||||
@staticmethod
|
||||
def HandleCall(translator, args, keywords):
|
||||
return []
|
||||
|
||||
class AsmOut:
|
||||
def __init__(self, value, constraint):
|
||||
self.value = value
|
||||
self.constraint = constraint
|
||||
@staticmethod
|
||||
def HandleCall(translator, args, keywords):
|
||||
return []
|
||||
|
||||
class NoBreak:
|
||||
""" switch 分支无break """
|
||||
pass
|
||||
|
||||
class Break:
|
||||
""" switch 分支提前break """
|
||||
pass
|
||||
|
||||
class Load:
|
||||
"""解引用a写入b,等价于 *b = *a,无拷贝副作用"""
|
||||
def __init__(self, src, dst):
|
||||
self.src = src
|
||||
self.dst = dst
|
||||
|
||||
@staticmethod
|
||||
def HandleCall(translator, args, keywords):
|
||||
if len(args) >= 2:
|
||||
src = translator.HandleExpr(args[0])[0]
|
||||
dst = translator.HandleExpr(args[1])[0]
|
||||
return [f'*({dst}) = *({src})']
|
||||
return []
|
||||
|
||||
|
||||
class Addr:
|
||||
"""取地址"""
|
||||
def __init__(self, addr):
|
||||
self.addr = addr
|
||||
|
||||
@staticmethod
|
||||
def HandleCall(translator, args, keywords):
|
||||
"""处理 c.Addr() 调用"""
|
||||
if args:
|
||||
expr = translator.HandleExpr(args[0])[0]
|
||||
if isinstance(expr, str):
|
||||
return [f'&{expr}']
|
||||
return [f'&{_to_str(expr)}']
|
||||
return ['0']
|
||||
|
||||
|
||||
class Deref:
|
||||
"""解引用"""
|
||||
def __init__(self, ptr):
|
||||
self.ptr = ptr
|
||||
|
||||
@staticmethod
|
||||
def HandleCall(translator, args, keywords):
|
||||
"""处理 c.Deref() 调用"""
|
||||
if args:
|
||||
expr = translator.HandleExpr(args[0])[0]
|
||||
if hasattr(expr, 'op') and expr.op == '*':
|
||||
return [expr]
|
||||
return [f'*({_to_str(expr)})']
|
||||
return ['0']
|
||||
|
||||
|
||||
class DerefAs:
|
||||
"""解引用写入,等价于 *ptr = value"""
|
||||
def __init__(self, ptr, value):
|
||||
self.ptr = ptr
|
||||
self.value = value
|
||||
|
||||
@staticmethod
|
||||
def HandleCall(translator, args, keywords):
|
||||
"""处理 c.DerefAs() 调用"""
|
||||
if len(args) >= 2:
|
||||
ptr = translator.HandleExpr(args[0])[0]
|
||||
val = translator.HandleExpr(args[1])[0]
|
||||
return [f'*({_to_str(ptr)}) = {_to_str(val)}']
|
||||
return []
|
||||
|
||||
|
||||
class Set:
|
||||
"""设置值"""
|
||||
def __init__(self, key, value):
|
||||
self.key = key
|
||||
self.value = value
|
||||
|
||||
@staticmethod
|
||||
def HandleCall(translator, args, keywords):
|
||||
"""处理 c.Set() 调用"""
|
||||
if len(args) >= 2:
|
||||
target = translator.HandleExpr(args[0])[0]
|
||||
value = translator.HandleExpr(args[1])[0]
|
||||
return [f'{_to_str(target)} = {_to_str(value)}']
|
||||
return []
|
||||
|
||||
|
||||
class CReturn:
|
||||
"""多返回值装饰器
|
||||
|
||||
用于实现函数多返回值,通过匿名结构体返回实现。
|
||||
例如:@c.CReturn(t.CInt, t.CInt) 表示函数返回两个 int 值。
|
||||
等价于 -> tuple[t.CInt, t.CInt] 返回类型注解。
|
||||
|
||||
规则:
|
||||
1. CReturn 中有几个类型就说明要返回几个值
|
||||
2. 函数返回类型为匿名结构体 { type1, type2, ... }
|
||||
3. return 语句使用 insert_value 构建结构体
|
||||
4. 调用处使用 extract_value 提取各字段
|
||||
"""
|
||||
def __init__(self, *ReturnTypes):
|
||||
self.ReturnTypes = ReturnTypes
|
||||
|
||||
def __call__(self, func):
|
||||
"""装饰器调用"""
|
||||
# 将返回类型信息附加到函数上
|
||||
func._CreturnTypes = self.ReturnTypes
|
||||
return func
|
||||
|
||||
|
||||
class CDefine:
|
||||
"""#define 宏定义"""
|
||||
def __init__(self, name, value):
|
||||
self.name = name
|
||||
self.value = value
|
||||
|
||||
@staticmethod
|
||||
def HandleCall(translator, args, keywords):
|
||||
"""处理 c.CDefine() 调用"""
|
||||
if len(args) >= 1:
|
||||
if isinstance(args[0], ast.Constant):
|
||||
name = args[0].value
|
||||
else:
|
||||
name = 'MACRO'
|
||||
if len(args) >= 2:
|
||||
value = translator.HandleExpr(args[1])[0]
|
||||
return ['#define ' + str(name) + ' ' + _to_str(value)]
|
||||
return ['#define ' + str(name)]
|
||||
return []
|
||||
|
||||
|
||||
class CIfndef:
|
||||
"""#ifndef 条件编译"""
|
||||
def __init__(self, condition):
|
||||
self.condition = condition
|
||||
|
||||
@staticmethod
|
||||
def HandleCall(translator, args, keywords):
|
||||
"""处理 c.CIfndef() 调用"""
|
||||
if args:
|
||||
condition = translator.HandleExpr(args[0])[0]
|
||||
return ['#ifndef ' + _to_str(condition)]
|
||||
return ['#if 0']
|
||||
|
||||
class CIfdef:
|
||||
"""#ifdef 条件编译"""
|
||||
def __init__(self, condition):
|
||||
self.condition = condition
|
||||
|
||||
@staticmethod
|
||||
def HandleCall(translator, args, keywords):
|
||||
"""处理 c.CIfdef() 调用"""
|
||||
if args:
|
||||
condition = translator.HandleExpr(args[0])[0]
|
||||
return ['#ifdef ' + _to_str(condition)]
|
||||
return ['#if 0']
|
||||
|
||||
class CError:
|
||||
"""#error 错误信息"""
|
||||
def __init__(self, condition):
|
||||
self.condition = condition
|
||||
|
||||
@staticmethod
|
||||
def HandleCall(translator, args, keywords):
|
||||
"""处理 c.CError() 调用"""
|
||||
if args:
|
||||
# 如果是字符串常量,保留引号
|
||||
if isinstance(args[0], ast.Constant) and isinstance(args[0].value, str):
|
||||
return ['#error "' + args[0].value + '"']
|
||||
elif isinstance(args[0], ast.Str):
|
||||
return ['#error "' + args[0].s + '"']
|
||||
else:
|
||||
condition = translator.HandleExpr(args[0])[0]
|
||||
return ['#error ' + _to_str(condition)]
|
||||
return ['#error "Error: Condition is not met."']
|
||||
|
||||
|
||||
class TokenPast:
|
||||
"""## 连接符"""
|
||||
def __init__(self, left, right):
|
||||
self.left = left
|
||||
self.right = right
|
||||
|
||||
@staticmethod
|
||||
def HandleCall(translator, args, keywords):
|
||||
"""处理 c.TokenPast() 调用"""
|
||||
if len(args) >= 2:
|
||||
# 处理左操作数 - 去掉引号
|
||||
if isinstance(args[0], ast.Constant):
|
||||
left = str(args[0].value)
|
||||
elif isinstance(args[0], ast.Str):
|
||||
left = str(args[0].s)
|
||||
elif isinstance(args[0], ast.Name):
|
||||
left = args[0].id
|
||||
else:
|
||||
left = _to_str(translator.HandleExpr(args[0])[0])
|
||||
|
||||
# 处理右操作数 - 去掉引号
|
||||
if isinstance(args[1], ast.Constant):
|
||||
right = str(args[1].value)
|
||||
elif isinstance(args[1], ast.Str):
|
||||
right = str(args[1].s)
|
||||
elif isinstance(args[1], ast.Name):
|
||||
right = args[1].id
|
||||
else:
|
||||
right = _to_str(translator.HandleExpr(args[1])[0])
|
||||
|
||||
# 返回字符串,但用特殊标记包装,让 _AstNodeToStr 能正确处理
|
||||
result = left + ' ## ' + right
|
||||
# 使用一个特殊的类来包装结果,让 _AstNodeToStr 直接返回其值
|
||||
class TokenPastResult:
|
||||
def __init__(self, value):
|
||||
self.value = value
|
||||
def __str__(self):
|
||||
return self.value
|
||||
return [TokenPastResult(result)]
|
||||
return ['']
|
||||
|
||||
|
||||
class CIf:
|
||||
"""#if 条件编译"""
|
||||
def __init__(self, condition):
|
||||
self.condition = condition
|
||||
|
||||
@staticmethod
|
||||
def HandleCall(translator, args, keywords):
|
||||
"""处理 c.CIf() 调用"""
|
||||
if args:
|
||||
condition = translator.HandleExpr(args[0])[0]
|
||||
return ['#if ' + _to_str(condition)]
|
||||
return ['#if 0']
|
||||
|
||||
|
||||
class CElif:
|
||||
"""#elif 条件编译"""
|
||||
def __init__(self, condition):
|
||||
self.condition = condition
|
||||
|
||||
@staticmethod
|
||||
def HandleCall(translator, args, keywords):
|
||||
"""处理 c.CElif() 调用"""
|
||||
if args:
|
||||
condition = translator.HandleExpr(args[0])[0]
|
||||
return ['#elif ' + _to_str(condition)]
|
||||
return ['#else']
|
||||
|
||||
|
||||
class CElse:
|
||||
"""#else 条件编译"""
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def HandleCall(translator, args, keywords):
|
||||
"""处理 c.CElse() 调用"""
|
||||
return ['#else']
|
||||
|
||||
|
||||
class CEndif:
|
||||
"""#endif 条件编译"""
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def HandleCall(translator, args, keywords):
|
||||
"""处理 c.CEndif() 调用"""
|
||||
return ['#endif']
|
||||
|
||||
|
||||
class CUndef:
|
||||
"""#undef 取消宏定义"""
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
|
||||
@staticmethod
|
||||
def HandleCall(translator, args, keywords):
|
||||
"""处理 c.CUndef(name) 调用"""
|
||||
import ast
|
||||
if args:
|
||||
arg = args[0]
|
||||
if isinstance(arg, str):
|
||||
name = arg
|
||||
elif isinstance(arg, ast.Name):
|
||||
name = arg.id
|
||||
elif isinstance(arg, ast.Constant):
|
||||
name = str(arg.value)
|
||||
else:
|
||||
name = str(arg)
|
||||
return [f'#undef {name}']
|
||||
return ['#undef']
|
||||
|
||||
|
||||
class LLVMIR:
|
||||
"""内联 LLVM IR
|
||||
|
||||
用法: c.LLVMIR(f"add i32 {c.LInp(a)}, {c.LInp(b)}", t.CInt)
|
||||
或: c.LLVMIR(f"%{c.LOut(result)} = add i32 {c.LInp(a)}, {c.LInp(b)}", t.CInt)
|
||||
|
||||
c.LInp(expr) - 输入操作数,翻译后替换为对应的 LLVM 临时变量名
|
||||
c.LOut(expr) - 输出操作数,翻译后替换为对应的 LLVM 临时变量名
|
||||
"""
|
||||
def __init__(self, ir_template, ret_type=None):
|
||||
self.ir_template = ir_template
|
||||
self.ret_type = ret_type
|
||||
|
||||
@staticmethod
|
||||
def HandleCall(translator, args, keywords):
|
||||
return ['/* LLVMIR */']
|
||||
|
||||
|
||||
class LInp:
|
||||
"""LLVM IR 输入操作数标记
|
||||
|
||||
用法: c.LInp(expr) - 标记 expr 为输入操作数
|
||||
在 c.LLVMIR 的 f-string 中使用,翻译后替换为 %N 形式的操作数引用
|
||||
"""
|
||||
def __init__(self, value):
|
||||
self.value = value
|
||||
|
||||
@staticmethod
|
||||
def HandleCall(translator, args, keywords):
|
||||
return []
|
||||
|
||||
|
||||
class LOut:
|
||||
"""LLVM IR 输出操作数标记
|
||||
|
||||
用法: c.LOut(expr) - 标记 expr 为输出操作数
|
||||
在 c.LLVMIR 的 f-string 中使用,翻译后替换为 %N 形式的操作数引用
|
||||
"""
|
||||
def __init__(self, value):
|
||||
self.value = value
|
||||
|
||||
@staticmethod
|
||||
def HandleCall(translator, args, keywords):
|
||||
return []
|
||||
|
||||
|
||||
class CPragma:
|
||||
"""#pragma 指令
|
||||
|
||||
用于生成 C 语言的 #pragma 指令。
|
||||
例如:c.CPragma("GCC diagnostic push") 生成 #pragma GCC diagnostic push
|
||||
"""
|
||||
def __init__(self, directive):
|
||||
self.directive = directive
|
||||
|
||||
@staticmethod
|
||||
def HandleCall(translator, args, keywords):
|
||||
"""处理 c.CPragma() 调用"""
|
||||
if args:
|
||||
arg = args[0]
|
||||
if isinstance(arg, ast.Constant):
|
||||
directive = arg.value
|
||||
elif isinstance(arg, ast.Str):
|
||||
directive = arg.s
|
||||
else:
|
||||
expr = translator.HandleExpr(arg)[0]
|
||||
directive = _to_str(expr)
|
||||
return [f'#pragma {directive}']
|
||||
return ['#pragma']
|
||||
|
||||
|
||||
# C 库类字典,用于 HandleCSpecialCall
|
||||
Library_C = {
|
||||
'Asm': Asm,
|
||||
'Load': Load,
|
||||
'Addr': Addr,
|
||||
'Deref': Deref,
|
||||
'Set': Set,
|
||||
'AsmInp': AsmInp,
|
||||
'AsmOut': AsmOut,
|
||||
'CDefine': CDefine,
|
||||
'CIfndef': CIfndef,
|
||||
'CIfdef': CIfdef,
|
||||
'CIf': CIf,
|
||||
'CElif': CElif,
|
||||
'CElse': CElse,
|
||||
'CEndif': CEndif,
|
||||
'CUndef': CUndef,
|
||||
'CError': CError,
|
||||
'TokenPast': TokenPast,
|
||||
'CReturn': CReturn,
|
||||
'CPragma': CPragma,
|
||||
'LLVMIR': LLVMIR,
|
||||
'LInp': LInp,
|
||||
'LOut': LOut,
|
||||
}
|
||||
|
||||
|
||||
class Attribute:
|
||||
"""函数/变量属性装饰器"""
|
||||
def __init__(self, *attrs):
|
||||
self.attrs = attrs
|
||||
|
||||
def __call__(self, func):
|
||||
# 将属性附加到函数上
|
||||
func._c_attributes = self.attrs
|
||||
return func
|
||||
1283
CPython/t.py
Normal file
1283
CPython/t.py
Normal file
File diff suppressed because it is too large
Load Diff
24
LIST
Normal file
24
LIST
Normal file
@@ -0,0 +1,24 @@
|
||||
### 问题 3:isr32_handler 中调用 _yield() 的安全性
|
||||
idt.py:165-169 :
|
||||
|
||||
```
|
||||
def isr32_handler():
|
||||
timer.timer_handler()
|
||||
if s.needs_reschedule:
|
||||
sched.Scheduler._yield()
|
||||
```
|
||||
_yield() 内部会切换栈帧( _do_switch 修改 RSP)。但在中断上下文中,当前栈是中断帧(由 ISR_NOERR 32 宏 push 的寄存器)。如果 _yield() 切换到另一个线程,那个线程的 _do_switch 返回时会 ret 到 _yield() 的调用者——而不是 iretq 返回中断。
|
||||
|
||||
这意味着中断帧被"遗弃"在旧线程的栈上 ,直到旧线程再次被调度回来时, _yield() 返回,然后 isr32_handler 返回,ISR_NOERR 宏执行 iretq 。
|
||||
|
||||
这个设计是 可以工作的 ,因为:
|
||||
|
||||
1. _yield() 保存了完整的 callee-saved 寄存器
|
||||
2. 中断帧在旧线程栈上,旧线程恢复时会继续执行 iretq
|
||||
3. _yield() 内部有自旋锁保护
|
||||
但有一个隐患:如果在中断上下文中 _yield() 切换到的线程也触发了定时器中断,就会 嵌套中断 + 嵌套 _yield() 。虽然自旋锁 _yield_lock 会阻止第二次 _yield() ,但这意味着时间片到期后无法切换,直到第一次 _yield() 返回。
|
||||
|
||||
|
||||
继续进行剩余的进程隔离,内存管理增强,以及上述的几个工作,依旧是分步
|
||||
注意,需要循序渐进,每一步后立即进行测试,也就是在每个小改进后立即进行测试,我将在出现任何问题后立即告诉你
|
||||
|
||||
3742
Projectrans.py
Normal file
3742
Projectrans.py
Normal file
File diff suppressed because it is too large
Load Diff
37
README.md
Normal file
37
README.md
Normal file
@@ -0,0 +1,37 @@
|
||||
# Viper 语言规范
|
||||
|
||||
Viper 是一种基于 Python 语法的系统级编程语言,通过 TransPyC 编译器编译为 LLVM IR,最终生成原生机器码。Viper 不是 Python 的子集,也不是 C 的语法糖——它拥有独立的类型系统、两阶段编译模型和 SHA1 命名空间机制,适用于操作系统内核、嵌入式系统、驱动程序等底层开发场景。
|
||||
|
||||
## 核心设计理念
|
||||
|
||||
- **Python 语法,LLVM 语义**:源文件是合法的 Python 语法,但通过 `t` 模块类型注解赋予 LLVM 级别的语义
|
||||
- **类型注解即编译指令**:类型注解决定 LLVM IR 的生成,不是可选的提示
|
||||
- **两阶段编译**:先提取声明接口(`.pyi` + `.stub.ll`),再翻译源文件为含代码的 `.ll`
|
||||
- **SHA1 命名空间**:每个源文件按内容 SHA1 哈希命名,自动消除跨模块符号冲突
|
||||
- **零运行时开销**:编译为原生代码,无 GC、无解释器、无虚拟机
|
||||
|
||||
## 模块总览
|
||||
|
||||
Viper 语言通过两个核心模块提供类型和操作支持:
|
||||
|
||||
| 模块 | 用途 | 导入方式 |
|
||||
|------|------|----------|
|
||||
| `t` | 类型定义系统 | `import t` |
|
||||
| `c` | C 语言操作指令 | `import c` |
|
||||
|
||||
## 文档索引
|
||||
|
||||
| 文件 | 内容 |
|
||||
|------|------|
|
||||
| [01-overview.md](01-overview.md) | 语言概述、两阶段编译流程、SHA1 命名空间、`t.CDefine`/`t.CExport`/`t.CInline` 深度解析 |
|
||||
| [02-type-system.md](02-type-system.md) | 类型系统(基本类型、指针、数组、结构体、联合体、枚举、typedef、`__attribute__`) |
|
||||
| [03-variables.md](03-variables.md) | 变量声明与赋值(含 `t.CDefine` 常量) |
|
||||
| [04-functions.md](04-functions.md) | 函数定义与调用(含 `t.CExport`、`t.CInline`、`t.CDefine` 函数、`@c.CReturn`) |
|
||||
| [05-classes.md](05-classes.md) | 类与数据布局(结构体、联合体、枚举、typedef、位域) |
|
||||
| [06-oop.md](06-oop.md) | 面向对象与运算符重载(`@t.Object`、`@t.CVTable`、继承、dunder 方法) |
|
||||
| [07-control-flow.md](07-control-flow.md) | 控制流(条件、循环、match) |
|
||||
| [08-c-operations.md](08-c-operations.md) | C 语言操作(指针、内联汇编、预处理指令、LLVM IR 内联) |
|
||||
| [09-exceptions.md](09-exceptions.md) | 异常处理 |
|
||||
| [10-imports.md](10-imports.md) | 模块与导入系统(存根生成、SHA1 命名空间与导入) |
|
||||
| [11-builtins.md](11-builtins.md) | 内置函数与运算符 |
|
||||
| [12-project.md](12-project.md) | 项目配置与构建(增量编译、SHA1 映射) |
|
||||
1337
StubGen.py
Normal file
1337
StubGen.py
Normal file
File diff suppressed because it is too large
Load Diff
271
Test/BuiltinDecoratorTest/App/main.py
Normal file
271
Test/BuiltinDecoratorTest/App/main.py
Normal file
@@ -0,0 +1,271 @@
|
||||
import t
|
||||
from stdint import *
|
||||
from stdio import printf
|
||||
|
||||
# ============================================================
|
||||
# 测试计数器
|
||||
# ============================================================
|
||||
_pass_count: t.CInt = 0
|
||||
_fail_count: t.CInt = 0
|
||||
|
||||
def check(name: t.CChar | t.CPtr, condition: bool):
|
||||
global _pass_count, _fail_count
|
||||
if condition:
|
||||
_pass_count += 1
|
||||
printf(" [PASS] %s\n", name)
|
||||
else:
|
||||
_fail_count += 1
|
||||
printf(" [FAIL] %s\n", name)
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 测试 1:@property getter
|
||||
# ============================================================
|
||||
class Rect:
|
||||
width: t.CInt
|
||||
height: t.CInt
|
||||
|
||||
def __init__(self, w: t.CInt, h: t.CInt):
|
||||
self.width = w
|
||||
self.height = h
|
||||
|
||||
@property
|
||||
def area(self) -> t.CInt:
|
||||
return self.width * self.height
|
||||
|
||||
@property
|
||||
def is_square(self) -> bool:
|
||||
return self.width == self.height
|
||||
|
||||
|
||||
def test_property_getter():
|
||||
printf("\n+-- @property getter --+\n")
|
||||
r: Rect = Rect(3, 4)
|
||||
check("area == 12", r.area == 12)
|
||||
check("not square", not r.is_square)
|
||||
r2: Rect = Rect(5, 5)
|
||||
check("square area == 25", r2.area == 25)
|
||||
check("is_square", r2.is_square)
|
||||
printf("+--------------------------------------------+\n")
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 测试 2:@property.setter
|
||||
# ============================================================
|
||||
class Temperature:
|
||||
_celsius: t.CDouble
|
||||
|
||||
def __init__(self, c: t.CDouble):
|
||||
self._celsius = c
|
||||
|
||||
@property
|
||||
def celsius(self) -> t.CDouble:
|
||||
return self._celsius
|
||||
|
||||
@celsius.setter
|
||||
def celsius(self, val: t.CDouble):
|
||||
self._celsius = val
|
||||
|
||||
@property
|
||||
def fahrenheit(self) -> t.CDouble:
|
||||
return self._celsius * 1.8 + 32.0
|
||||
|
||||
|
||||
def test_property_setter():
|
||||
printf("\n+-- @property.setter --+\n")
|
||||
t1: Temperature = Temperature(0.0)
|
||||
check("0C == 32F", t1.fahrenheit > 31.9 and t1.fahrenheit < 32.1)
|
||||
t1.celsius = 100.0
|
||||
check("100C == 212F", t1.fahrenheit > 211.9 and t1.fahrenheit < 212.1)
|
||||
check("celsius == 100", t1.celsius > 99.9 and t1.celsius < 100.1)
|
||||
printf("+--------------------------------------------+\n")
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 测试 3:@property.getter(重新定义 getter)
|
||||
# ============================================================
|
||||
class Counter:
|
||||
_count: t.CInt
|
||||
|
||||
def __init__(self):
|
||||
self._count = 0
|
||||
|
||||
@property
|
||||
def value(self) -> t.CInt:
|
||||
return self._count
|
||||
|
||||
@value.setter
|
||||
def value(self, v: t.CInt):
|
||||
self._count = v
|
||||
|
||||
|
||||
def test_property_getter_redef():
|
||||
printf("\n+-- @property.getter redef --+\n")
|
||||
c: Counter = Counter()
|
||||
check("init == 0", c.value == 0)
|
||||
c.value = 42
|
||||
check("set == 42", c.value == 42)
|
||||
printf("+--------------------------------------------+\n")
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 测试 4:@property.deleter
|
||||
# ============================================================
|
||||
class Config:
|
||||
_value: t.CInt
|
||||
_deleted: t.CInt
|
||||
|
||||
def __init__(self, v: t.CInt):
|
||||
self._value = v
|
||||
self._deleted = 0
|
||||
|
||||
@property
|
||||
def value(self) -> t.CInt:
|
||||
return self._value
|
||||
|
||||
@value.setter
|
||||
def value(self, v: t.CInt):
|
||||
self._value = v
|
||||
|
||||
@value.deleter
|
||||
def value(self):
|
||||
self._value = 0
|
||||
self._deleted = 1
|
||||
|
||||
def is_deleted(self) -> bool:
|
||||
return self._deleted != 0
|
||||
|
||||
|
||||
def test_property_deleter():
|
||||
printf("\n+-- @property.deleter --+\n")
|
||||
cfg: Config = Config(99)
|
||||
check("init == 99", cfg.value == 99)
|
||||
check("not deleted", not cfg.is_deleted())
|
||||
del cfg.value
|
||||
check("after del == 0", cfg.value == 0)
|
||||
check("is_deleted", cfg.is_deleted())
|
||||
printf("+--------------------------------------------+\n")
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 测试 5:@staticmethod
|
||||
# ============================================================
|
||||
class MathUtils:
|
||||
@staticmethod
|
||||
def add(a: t.CInt, b: t.CInt) -> t.CInt:
|
||||
return a + b
|
||||
|
||||
@staticmethod
|
||||
def max_val(a: t.CInt, b: t.CInt) -> t.CInt:
|
||||
return a if a > b else b
|
||||
|
||||
|
||||
def test_staticmethod():
|
||||
printf("\n+-- @staticmethod --+\n")
|
||||
# 通过类名调用
|
||||
check("MathUtils.add(3,4)==7", MathUtils.add(3, 4) == 7)
|
||||
check("MathUtils.max(5,10)==10", MathUtils.max_val(5, 10) == 10)
|
||||
# 通过实例调用
|
||||
m: MathUtils = MathUtils()
|
||||
check("instance.add(1,2)==3", m.add(1, 2) == 3)
|
||||
check("instance.max(8,3)==8", m.max_val(8, 3) == 8)
|
||||
printf("+--------------------------------------------+\n")
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 测试 6:@classmethod
|
||||
# ============================================================
|
||||
class Point:
|
||||
x: t.CDouble
|
||||
y: t.CDouble
|
||||
|
||||
def __init__(self, x: t.CDouble, y: t.CDouble):
|
||||
self.x = x
|
||||
self.y = y
|
||||
|
||||
@classmethod
|
||||
def origin(cls: Point) -> Point:
|
||||
return Point(0.0, 0.0)
|
||||
|
||||
@classmethod
|
||||
def from_int(cls: Point, x: t.CInt, y: t.CInt) -> Point:
|
||||
return Point(x * 1.0, y * 1.0)
|
||||
|
||||
def dist_sq(self) -> t.CDouble:
|
||||
return self.x * self.x + self.y * self.y
|
||||
|
||||
|
||||
def test_classmethod():
|
||||
printf("\n+-- @classmethod --+\n")
|
||||
# 通过类名调用
|
||||
p1: Point = Point.origin()
|
||||
check("origin.x ~= 0", p1.x > -0.01 and p1.x < 0.01)
|
||||
check("origin.y ~= 0", p1.y > -0.01 and p1.y < 0.01)
|
||||
check("origin.dist ~= 0", p1.dist_sq() < 0.01)
|
||||
|
||||
p2: Point = Point.from_int(3, 4)
|
||||
check("from_int(3,4).x ~= 3", p2.x > 2.99 and p2.x < 3.01)
|
||||
check("from_int(3,4).y ~= 4", p2.y > 3.99 and p2.y < 4.01)
|
||||
check("dist_sq ~= 25", p2.dist_sq() > 24.99 and p2.dist_sq() < 25.01)
|
||||
printf("+--------------------------------------------+\n")
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 测试 7:综合测试 — @property + @staticmethod + @classmethod
|
||||
# ============================================================
|
||||
class Circle:
|
||||
_radius: t.CDouble
|
||||
|
||||
def __init__(self, r: t.CDouble):
|
||||
self._radius = r
|
||||
|
||||
@property
|
||||
def radius(self) -> t.CDouble:
|
||||
return self._radius
|
||||
|
||||
@radius.setter
|
||||
def radius(self, val: t.CDouble):
|
||||
self._radius = val
|
||||
|
||||
@property
|
||||
def area(self) -> t.CDouble:
|
||||
return 3.14159265 * self._radius * self._radius
|
||||
|
||||
@staticmethod
|
||||
def is_unit(r: t.CDouble) -> bool:
|
||||
return r > 0.99 and r < 1.01
|
||||
|
||||
@classmethod
|
||||
def unit(cls: Circle) -> Circle:
|
||||
return Circle(1.0)
|
||||
|
||||
|
||||
def test_combined():
|
||||
printf("\n+-- Combined @property + @staticmethod + @classmethod --+\n")
|
||||
c: Circle = Circle.unit()
|
||||
check("unit radius ~= 1", c.radius > 0.99 and c.radius < 1.01)
|
||||
check("is_unit(1.0)", Circle.is_unit(1.0))
|
||||
check("not is_unit(2.0)", not Circle.is_unit(2.0))
|
||||
check("unit area ~= pi", c.area > 3.14 and c.area < 3.15)
|
||||
c.radius = 2.0
|
||||
check("radius 2.0", c.radius > 1.99 and c.radius < 2.01)
|
||||
check("area ~= 4pi", c.area > 12.56 and c.area < 12.58)
|
||||
printf("+--------------------------------------------+\n")
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 主函数
|
||||
# ============================================================
|
||||
def main() -> t.CInt | t.CExport:
|
||||
printf("=== Builtin Decorator Test ===\n")
|
||||
|
||||
test_property_getter()
|
||||
test_property_setter()
|
||||
test_property_getter_redef()
|
||||
test_property_deleter()
|
||||
test_staticmethod()
|
||||
test_classmethod()
|
||||
test_combined()
|
||||
|
||||
printf("\n=== Results: %d passed, %d failed ===\n", _pass_count, _fail_count)
|
||||
return 0
|
||||
28
Test/BuiltinDecoratorTest/project.json
Normal file
28
Test/BuiltinDecoratorTest/project.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "BuiltinDecoratorTest",
|
||||
"version": "1.0.0",
|
||||
"source_dir": "./App",
|
||||
"temp_dir": "./temp",
|
||||
"output_dir": "./output",
|
||||
"compiler": {
|
||||
"cmd": "llc",
|
||||
"flags": ["-filetype=obj", "-relocation-model=pic"]
|
||||
},
|
||||
"linker": {
|
||||
"cmd": "clang++",
|
||||
"flags": ["-Wl,--allow-multiple-definition", "-Wl,--unresolved-symbols=ignore-in-object-files", "-lmsvcrt", "-lucrt", "-lpthread", "-lmingwex", "-lkernel32", "-luser32", "-latomic"],
|
||||
"output": "BuiltinDecoratorTest.exe"
|
||||
},
|
||||
"includes": [
|
||||
"../../includes"
|
||||
],
|
||||
"target": {
|
||||
"triple": "x86_64-pc-windows-gnu",
|
||||
"datalayout": "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
|
||||
},
|
||||
"options": {
|
||||
"slice_level": 3,
|
||||
"target": "llvm",
|
||||
"strict_mode": true
|
||||
}
|
||||
}
|
||||
67
Test/BuiltinDecoratorTest/temp/56cdd754a8a09347.pyi
Normal file
67
Test/BuiltinDecoratorTest/temp/56cdd754a8a09347.pyi
Normal file
@@ -0,0 +1,67 @@
|
||||
"""
|
||||
Auto-generated Python stub file from stdint.py
|
||||
Module: stdint
|
||||
"""
|
||||
|
||||
import c
|
||||
|
||||
|
||||
import t
|
||||
|
||||
INT: t.CTypedef = t.CInt
|
||||
INTPTR: t.CTypedef = t.CInt | t.CPtr
|
||||
BOOL: t.CTypedef = t.CInt
|
||||
UINT: t.CTypedef = t.CUnsignedInt
|
||||
UINTPTR: t.CTypedef = UINT | t.CPtr
|
||||
BYTE: t.CTypedef = t.CUnsignedChar
|
||||
BYTEPTR: t.CTypedef = BYTE | t.CPtr
|
||||
WORD: t.CTypedef = t.CUInt16T
|
||||
DWORD: t.CTypedef = t.CUInt32T
|
||||
QWORD: t.CTypedef = t.CUInt64T
|
||||
TCHAR: t.CTypedef = t.CChar
|
||||
CHARLIST: t.CTypedef = str | t.CPtr
|
||||
VOID: t.CTypedef = t.CVoid
|
||||
SHORT: t.CTypedef = t.CShort
|
||||
SHORTPTR: t.CTypedef = t.CShort | t.CPtr
|
||||
USHORT: t.CTypedef = t.CUnsignedShort
|
||||
USHORTPTR: t.CTypedef = t.CUnsignedShort | t.CPtr
|
||||
LONGLONG: t.CTypedef = t.CLong | t.CLong
|
||||
ULONGLONG: t.CTypedef = t.CUnsignedLong | t.CLong
|
||||
LONG: t.CTypedef = t.CLong
|
||||
ULONG: t.CTypedef = t.CUnsignedLong
|
||||
WCHAR: t.CTypedef = WORD
|
||||
WCHARPTR: t.CTypedef = WORD | t.CPtr
|
||||
CHARPTR: t.CTypedef = t.CChar | t.CPtr
|
||||
FSIZE_t: t.CTypedef = DWORD
|
||||
LBA_t: t.CTypedef = DWORD
|
||||
UINTPTR: t.CTypedef = t.CUnsignedInt | t.CPtr
|
||||
VOIDPTR: t.CTypedef = t.CVoid | t.CPtr
|
||||
FLOAT: t.CTypedef = t.CFloat
|
||||
DOUBLE: t.CTypedef = t.CDouble
|
||||
FLOAT8: t.CTypedef = t.CFloat8T
|
||||
FLOAT16: t.CTypedef = t.CFloat16T
|
||||
FLOAT32: t.CTypedef = t.CFloat32T
|
||||
FLOAT64: t.CTypedef = t.CFloat64T
|
||||
FLOAT128: t.CTypedef = t.CFloat128T
|
||||
INT8: t.CTypedef = t.CInt8T
|
||||
INT16: t.CTypedef = t.CInt16T
|
||||
INT32: t.CTypedef = t.CInt32T
|
||||
INT64: t.CTypedef = t.CInt64T
|
||||
UINT8: t.CTypedef = t.CUInt8T
|
||||
UINT16: t.CTypedef = t.CUInt16T
|
||||
UINT32: t.CTypedef = t.CUInt32T
|
||||
UINT64: t.CTypedef = t.CUInt64T
|
||||
INT8PTR: t.CTypedef = t.CInt8T | t.CPtr
|
||||
INT16PTR: t.CTypedef = t.CInt16T | t.CPtr
|
||||
INT32PTR: t.CTypedef = t.CInt32T | t.CPtr
|
||||
INT64PTR: t.CTypedef = t.CInt64T | t.CPtr
|
||||
UINT8PTR: t.CTypedef = t.CUInt8T | t.CPtr
|
||||
UINT16PTR: t.CTypedef = t.CUInt16T | t.CPtr
|
||||
UINT32PTR: t.CTypedef = t.CUInt32T | t.CPtr
|
||||
UINT64PTR: t.CTypedef = t.CUInt64T | t.CPtr
|
||||
CHAR8: t.CTypedef = t.CChar8T
|
||||
CHAR16: t.CTypedef = t.CChar16T
|
||||
CHAR32: t.CTypedef = t.CChar32T
|
||||
CHAR8PTR: t.CTypedef = t.CChar8T | t.CPtr
|
||||
CHAR16PTR: t.CTypedef = t.CChar16T | t.CPtr
|
||||
CHAR32PTR: t.CTypedef = t.CChar32T | t.CPtr
|
||||
28
Test/BuiltinDecoratorTest/temp/73edbcf76e32d00b.pyi
Normal file
28
Test/BuiltinDecoratorTest/temp/73edbcf76e32d00b.pyi
Normal file
@@ -0,0 +1,28 @@
|
||||
"""
|
||||
Auto-generated Python stub file from stdio.py
|
||||
Module: stdio
|
||||
"""
|
||||
|
||||
|
||||
import t, c
|
||||
|
||||
def printf(fmt: t.CChar | t.CConst | t.CPtr, *args) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def fprintf(stream: t.CVoid | t.CPtr, fmt: t.CChar | t.CConst | t.CPtr, *args) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def sprintf(buf: t.CChar | t.CPtr, fmt: t.CChar | t.CConst | t.CPtr, *args) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def snprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: t.CChar | t.CConst | t.CPtr, *args) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def puts(s: t.CChar | t.CConst | t.CPtr) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def fputs(s: t.CChar | t.CConst | t.CPtr, stream: t.CVoid | t.CPtr) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def fgets(buf: t.CChar | t.CPtr, size: t.CInt, stream: t.CVoid | t.CPtr) -> t.CChar | t.CPtr | t.CExtern | t.CExport: pass
|
||||
|
||||
def fflush(stream: t.CVoid | t.CPtr) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
|
||||
stdin: t.CExtern | t.CVoid | t.CPtr
|
||||
stdout: t.CExtern | t.CVoid | t.CPtr
|
||||
stderr: t.CExtern | t.CVoid | t.CPtr
|
||||
108
Test/BuiltinDecoratorTest/temp/7d5b7ce7c134ada7.pyi
Normal file
108
Test/BuiltinDecoratorTest/temp/7d5b7ce7c134ada7.pyi
Normal file
@@ -0,0 +1,108 @@
|
||||
"""
|
||||
Auto-generated Python stub file from main.py
|
||||
Module: main
|
||||
"""
|
||||
|
||||
import c
|
||||
|
||||
|
||||
import t
|
||||
from stdint import *
|
||||
from stdio import printf
|
||||
|
||||
_pass_count: t.CExtern | t.CInt
|
||||
_fail_count: t.CExtern | t.CInt
|
||||
|
||||
def check(name: t.CChar | t.CPtr, condition: bool) -> t.CInt: pass
|
||||
|
||||
|
||||
class Rect:
|
||||
width: t.CInt
|
||||
height: t.CInt
|
||||
def __init__(self: Rect, w: t.CInt, h: t.CInt) -> t.CInt: pass
|
||||
@property
|
||||
def area(self: Rect) -> t.CInt: pass
|
||||
@property
|
||||
def is_square(self: Rect) -> bool: pass
|
||||
|
||||
def test_property_getter() -> t.CInt: pass
|
||||
|
||||
|
||||
class Temperature:
|
||||
_celsius: t.CDouble
|
||||
def __init__(self: Temperature, c: t.CDouble) -> t.CInt: pass
|
||||
@property
|
||||
def celsius(self: Temperature) -> t.CDouble: pass
|
||||
@celsius.setter
|
||||
def celsius(self: Temperature, val: t.CDouble) -> t.CInt: pass
|
||||
@property
|
||||
def fahrenheit(self: Temperature) -> t.CDouble: pass
|
||||
|
||||
def test_property_setter() -> t.CInt: pass
|
||||
|
||||
|
||||
class Counter:
|
||||
_count: t.CInt
|
||||
def __init__(self: Counter) -> t.CInt: pass
|
||||
@property
|
||||
def value(self: Counter) -> t.CInt: pass
|
||||
@value.setter
|
||||
def value(self: Counter, v: t.CInt) -> t.CInt: pass
|
||||
|
||||
def test_property_getter_redef() -> t.CInt: pass
|
||||
|
||||
|
||||
class Config:
|
||||
_value: t.CInt
|
||||
_deleted: t.CInt
|
||||
def __init__(self: Config, v: t.CInt) -> t.CInt: pass
|
||||
@property
|
||||
def value(self: Config) -> t.CInt: pass
|
||||
@value.setter
|
||||
def value(self: Config, v: t.CInt) -> t.CInt: pass
|
||||
@value.deleter
|
||||
def value(self: Config) -> t.CInt: pass
|
||||
def is_deleted(self: Config) -> bool: pass
|
||||
|
||||
def test_property_deleter() -> t.CInt: pass
|
||||
|
||||
|
||||
class MathUtils:
|
||||
@staticmethod
|
||||
def add(a: t.CInt, b: t.CInt) -> t.CInt: pass
|
||||
@staticmethod
|
||||
def max_val(a: t.CInt, b: t.CInt) -> t.CInt: pass
|
||||
|
||||
def test_staticmethod() -> t.CInt: pass
|
||||
|
||||
|
||||
class Point:
|
||||
x: t.CDouble
|
||||
y: t.CDouble
|
||||
def __init__(self: Point, x: t.CDouble, y: t.CDouble) -> t.CInt: pass
|
||||
@classmethod
|
||||
def origin(cls: Point) -> Point: pass
|
||||
@classmethod
|
||||
def from_int(cls: Point, x: t.CInt, y: t.CInt) -> Point: pass
|
||||
def dist_sq(self: Point) -> t.CDouble: pass
|
||||
|
||||
def test_classmethod() -> t.CInt: pass
|
||||
|
||||
|
||||
class Circle:
|
||||
_radius: t.CDouble
|
||||
def __init__(self: Circle, r: t.CDouble) -> t.CInt: pass
|
||||
@property
|
||||
def radius(self: Circle) -> t.CDouble: pass
|
||||
@radius.setter
|
||||
def radius(self: Circle, val: t.CDouble) -> t.CInt: pass
|
||||
@property
|
||||
def area(self: Circle) -> t.CDouble: pass
|
||||
@staticmethod
|
||||
def is_unit(r: t.CDouble) -> bool: pass
|
||||
@classmethod
|
||||
def unit(cls: Circle) -> Circle: pass
|
||||
|
||||
def test_combined() -> t.CInt: pass
|
||||
|
||||
def main() -> t.CInt | t.CExport: pass
|
||||
3
Test/BuiltinDecoratorTest/temp/_sha1_map.txt
Normal file
3
Test/BuiltinDecoratorTest/temp/_sha1_map.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
56cdd754a8a09347:includes/stdint.py
|
||||
73edbcf76e32d00b:includes/stdio.py
|
||||
7d5b7ce7c134ada7:main.py
|
||||
25
Test/CPythonTest/App/cpython.py
Normal file
25
Test/CPythonTest/App/cpython.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import t, c
|
||||
|
||||
|
||||
class PyObject:
|
||||
ob_refcnt: t.CLong
|
||||
ob_type: t.CPtr
|
||||
|
||||
|
||||
def Py_Initialize() -> t.CVoid | t.CExtern:
|
||||
pass
|
||||
|
||||
def PyLong_FromLong(value: t.CLong) -> PyObject | t.CPtr | t.CExtern:
|
||||
pass
|
||||
|
||||
def PyObject_Str(obj: PyObject | t.CPtr) -> PyObject | t.CPtr | t.CExtern:
|
||||
pass
|
||||
|
||||
def PyUnicode_AsUTF8(unicode_obj: PyObject | t.CPtr) -> str | t.CExtern:
|
||||
pass
|
||||
|
||||
def Py_DecRef(obj: PyObject | t.CPtr) -> t.CVoid | t.CExtern:
|
||||
pass
|
||||
|
||||
def Py_Finalize() -> t.CVoid | t.CExtern:
|
||||
pass
|
||||
28
Test/CPythonTest/App/main.py
Normal file
28
Test/CPythonTest/App/main.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import t, c
|
||||
from t import CInt, CPtr, CChar, CLong
|
||||
import viperlib
|
||||
import cpython
|
||||
|
||||
|
||||
def SetDllDirectoryA(lpPathName: str | CPtr) -> CInt | t.CExtern:
|
||||
pass
|
||||
|
||||
def main() -> CInt | t.CExport:
|
||||
SetDllDirectoryA("D:\\Python312")
|
||||
|
||||
cpython.Py_Initialize()
|
||||
|
||||
py_num: cpython.PyObject | t.CPtr = cpython.PyLong_FromLong(12345)
|
||||
|
||||
py_str: cpython.PyObject | t.CPtr = cpython.PyObject_Str(py_num)
|
||||
c_str: str = cpython.PyUnicode_AsUTF8(py_str)
|
||||
print(c_str)
|
||||
|
||||
cpython.Py_DecRef(py_str)
|
||||
cpython.Py_DecRef(py_num)
|
||||
|
||||
cpython.Py_Finalize()
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
1
Test/CPythonTest/output/3e1c3f98e99cff7a.deps.json
Normal file
1
Test/CPythonTest/output/3e1c3f98e99cff7a.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"viperlib": "4d342c40331fc964", "stdint": "56cdd754a8a09347", "main": "6999814920e8b3d5", "stdarg": "81ac26077a460417", "viperio": "c9f4be41ca1cc2b4"}
|
||||
1
Test/CPythonTest/output/4d342c40331fc964.deps.json
Normal file
1
Test/CPythonTest/output/4d342c40331fc964.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"cpython": "3e1c3f98e99cff7a", "stdarg": "81ac26077a460417", "main": "93131e2ff5450838", "viperio": "d771d4d68d9e75b3"}
|
||||
1
Test/CPythonTest/output/6999814920e8b3d5.deps.json
Normal file
1
Test/CPythonTest/output/6999814920e8b3d5.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"cpython": "3e1c3f98e99cff7a", "viperlib": "4d342c40331fc964", "stdint": "56cdd754a8a09347", "stdarg": "81ac26077a460417", "viperio": "c9f4be41ca1cc2b4"}
|
||||
BIN
Test/CPythonTest/output/CPythonTest.exe.tmp0
Normal file
BIN
Test/CPythonTest/output/CPythonTest.exe.tmp0
Normal file
Binary file not shown.
1
Test/CPythonTest/output/c9f4be41ca1cc2b4.deps.json
Normal file
1
Test/CPythonTest/output/c9f4be41ca1cc2b4.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"cpython": "3e1c3f98e99cff7a", "viperlib": "4d342c40331fc964", "stdint": "56cdd754a8a09347", "main": "6999814920e8b3d5", "stdarg": "81ac26077a460417"}
|
||||
29
Test/CPythonTest/project.json
Normal file
29
Test/CPythonTest/project.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/TermiNexus/TransPyC/main/schemas/project-schema.json",
|
||||
"name": "CPythonTest",
|
||||
"version": "1.0.0",
|
||||
"source_dir": "./App",
|
||||
"temp_dir": "./temp",
|
||||
"output_dir": "./output",
|
||||
"compiler": {
|
||||
"cmd": "llc",
|
||||
"flags": ["-filetype=obj", "-relocation-model=pic"]
|
||||
},
|
||||
"linker": {
|
||||
"cmd": "clang++",
|
||||
"flags": ["-L", "D:\\Python312", "-lmsvcrt", "-lucrt", "-lpthread", "D:\\Python312\\python312.dll"],
|
||||
"output": "CPythonTest.exe"
|
||||
},
|
||||
"includes": [
|
||||
"./includes"
|
||||
],
|
||||
"target": {
|
||||
"triple": "x86_64-pc-windows-msvc",
|
||||
"datalayout": "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
|
||||
},
|
||||
"options": {
|
||||
"slice_level": 3,
|
||||
"target": "llvm",
|
||||
"strict_mode": true
|
||||
}
|
||||
}
|
||||
23
Test/CPythonTest/temp/3e1c3f98e99cff7a.pyi
Normal file
23
Test/CPythonTest/temp/3e1c3f98e99cff7a.pyi
Normal file
@@ -0,0 +1,23 @@
|
||||
"""
|
||||
Auto-generated Python stub file from cpython.py
|
||||
Module: cpython
|
||||
"""
|
||||
|
||||
|
||||
import t, c
|
||||
|
||||
class PyObject:
|
||||
ob_refcnt: t.CLong
|
||||
ob_type: t.CPtr
|
||||
|
||||
def Py_Initialize() -> t.CVoid | t.CExtern | t.State: pass
|
||||
|
||||
def PyLong_FromLong(value: t.CLong) -> PyObject | t.CPtr | t.CExtern | t.State: pass
|
||||
|
||||
def PyObject_Str(obj: PyObject | t.CPtr) -> PyObject | t.CPtr | t.CExtern | t.State: pass
|
||||
|
||||
def PyUnicode_AsUTF8(unicode_obj: PyObject | t.CPtr) -> str | t.CExtern | t.State: pass
|
||||
|
||||
def Py_DecRef(obj: PyObject | t.CPtr) -> t.CVoid | t.CExtern | t.State: pass
|
||||
|
||||
def Py_Finalize() -> t.CVoid | t.CExtern | t.State: pass
|
||||
19
Test/CPythonTest/temp/4d342c40331fc964.pyi
Normal file
19
Test/CPythonTest/temp/4d342c40331fc964.pyi
Normal file
@@ -0,0 +1,19 @@
|
||||
"""
|
||||
Auto-generated Python stub file from viperlib.py
|
||||
Module: viperlib
|
||||
"""
|
||||
|
||||
|
||||
import t, c
|
||||
import viperio
|
||||
from stdarg import arg
|
||||
|
||||
TEMP_BUF_SIZE: t.CDefine = 24
|
||||
|
||||
def get_digit_count(num: t.CUnsignedInt, base: t.CInt) -> t.CStatic | t.CInt | t.State: pass
|
||||
|
||||
def sprintf(buf: t.CChar | t.CPtr, rule: str, *args) -> t.CVoid | t.State: pass
|
||||
|
||||
def vsprintf(buf: t.CChar | t.CPtr, rule: str, *args) -> t.CInt | t.State: pass
|
||||
|
||||
def snprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: str, *args) -> t.CInt | t.State: pass
|
||||
67
Test/CPythonTest/temp/56cdd754a8a09347.pyi
Normal file
67
Test/CPythonTest/temp/56cdd754a8a09347.pyi
Normal file
@@ -0,0 +1,67 @@
|
||||
"""
|
||||
Auto-generated Python stub file from stdint.py
|
||||
Module: stdint
|
||||
"""
|
||||
|
||||
import c
|
||||
|
||||
|
||||
import t
|
||||
|
||||
INT: t.CTypedef = t.CInt
|
||||
INTPTR: t.CTypedef = t.CInt | t.CPtr
|
||||
BOOL: t.CTypedef = t.CInt
|
||||
UINT: t.CTypedef = t.CUnsignedInt
|
||||
UINTPTR: t.CTypedef = UINT | t.CPtr
|
||||
BYTE: t.CTypedef = t.CUnsignedChar
|
||||
BYTEPTR: t.CTypedef = BYTE | t.CPtr
|
||||
WORD: t.CTypedef = t.CUInt16T
|
||||
DWORD: t.CTypedef = t.CUInt32T
|
||||
QWORD: t.CTypedef = t.CUInt64T
|
||||
TCHAR: t.CTypedef = t.CChar
|
||||
CHARLIST: t.CTypedef = str | t.CPtr
|
||||
VOID: t.CTypedef = t.CVoid
|
||||
SHORT: t.CTypedef = t.CShort
|
||||
SHORTPTR: t.CTypedef = t.CShort | t.CPtr
|
||||
USHORT: t.CTypedef = t.CUnsignedShort
|
||||
USHORTPTR: t.CTypedef = t.CUnsignedShort | t.CPtr
|
||||
LONGLONG: t.CTypedef = t.CLong | t.CLong
|
||||
ULONGLONG: t.CTypedef = t.CUnsignedLong | t.CLong
|
||||
LONG: t.CTypedef = t.CLong
|
||||
ULONG: t.CTypedef = t.CUnsignedLong
|
||||
WCHAR: t.CTypedef = WORD
|
||||
WCHARPTR: t.CTypedef = WORD | t.CPtr
|
||||
CHARPTR: t.CTypedef = t.CChar | t.CPtr
|
||||
FSIZE_t: t.CTypedef = DWORD
|
||||
LBA_t: t.CTypedef = DWORD
|
||||
UINTPTR: t.CTypedef = t.CUnsignedInt | t.CPtr
|
||||
VOIDPTR: t.CTypedef = t.CVoid | t.CPtr
|
||||
FLOAT: t.CTypedef = t.CFloat
|
||||
DOUBLE: t.CTypedef = t.CDouble
|
||||
FLOAT8: t.CTypedef = t.CFloat8T
|
||||
FLOAT16: t.CTypedef = t.CFloat16T
|
||||
FLOAT32: t.CTypedef = t.CFloat32T
|
||||
FLOAT64: t.CTypedef = t.CFloat64T
|
||||
FLOAT128: t.CTypedef = t.CFloat128T
|
||||
INT8: t.CTypedef = t.CInt8T
|
||||
INT16: t.CTypedef = t.CInt16T
|
||||
INT32: t.CTypedef = t.CInt32T
|
||||
INT64: t.CTypedef = t.CInt64T
|
||||
UINT8: t.CTypedef = t.CUInt8T
|
||||
UINT16: t.CTypedef = t.CUInt16T
|
||||
UINT32: t.CTypedef = t.CUInt32T
|
||||
UINT64: t.CTypedef = t.CUInt64T
|
||||
INT8PTR: t.CTypedef = t.CInt8T | t.CPtr
|
||||
INT16PTR: t.CTypedef = t.CInt16T | t.CPtr
|
||||
INT32PTR: t.CTypedef = t.CInt32T | t.CPtr
|
||||
INT64PTR: t.CTypedef = t.CInt64T | t.CPtr
|
||||
UINT8PTR: t.CTypedef = t.CUInt8T | t.CPtr
|
||||
UINT16PTR: t.CTypedef = t.CUInt16T | t.CPtr
|
||||
UINT32PTR: t.CTypedef = t.CUInt32T | t.CPtr
|
||||
UINT64PTR: t.CTypedef = t.CUInt64T | t.CPtr
|
||||
CHAR8: t.CTypedef = t.CChar8T
|
||||
CHAR16: t.CTypedef = t.CChar16T
|
||||
CHAR32: t.CTypedef = t.CChar32T
|
||||
CHAR8PTR: t.CTypedef = t.CChar8T | t.CPtr
|
||||
CHAR16PTR: t.CTypedef = t.CChar16T | t.CPtr
|
||||
CHAR32PTR: t.CTypedef = t.CChar32T | t.CPtr
|
||||
14
Test/CPythonTest/temp/6999814920e8b3d5.pyi
Normal file
14
Test/CPythonTest/temp/6999814920e8b3d5.pyi
Normal file
@@ -0,0 +1,14 @@
|
||||
"""
|
||||
Auto-generated Python stub file from main.py
|
||||
Module: main
|
||||
"""
|
||||
|
||||
|
||||
import t, c
|
||||
from t import CInt, CPtr, CChar, CLong
|
||||
import viperlib
|
||||
import cpython
|
||||
|
||||
def SetDllDirectoryA(lpPathName: str | CPtr) -> CInt | t.CExtern | t.State: pass
|
||||
|
||||
def main() -> CInt | t.CExport | t.State: pass
|
||||
20
Test/CPythonTest/temp/81ac26077a460417.pyi
Normal file
20
Test/CPythonTest/temp/81ac26077a460417.pyi
Normal file
@@ -0,0 +1,20 @@
|
||||
"""
|
||||
Auto-generated Python stub file from stdarg.py
|
||||
Module: stdarg
|
||||
"""
|
||||
|
||||
import c
|
||||
|
||||
|
||||
import t
|
||||
|
||||
def va_start(args: t.CPtr, last_arg: t.CPtr) -> t.State | t.CExtern | t.CExport: pass
|
||||
|
||||
def va_arg(args: t.CPtr, type: t.CType) -> t.CType | t.CExtern | t.CExport | t.State: pass
|
||||
|
||||
def va_end(args: t.CPtr) -> t.State | t.CExtern | t.CExport: pass
|
||||
|
||||
|
||||
va_list: t.CTypedef = t.CUnsignedChar | t.CPtr
|
||||
|
||||
def arg(type: t.CType) -> t.State | t.CExtern | t.CExport: pass
|
||||
14
Test/CPythonTest/temp/93131e2ff5450838.pyi
Normal file
14
Test/CPythonTest/temp/93131e2ff5450838.pyi
Normal file
@@ -0,0 +1,14 @@
|
||||
"""
|
||||
Auto-generated Python stub file from main.py
|
||||
Module: main
|
||||
"""
|
||||
|
||||
|
||||
import t, c
|
||||
from t import CInt, CPtr, CChar, CLong
|
||||
import viperlib
|
||||
import cpython
|
||||
|
||||
def SetDllDirectoryA(lpPathName: str | CPtr) -> CInt | t.CExtern | t.State: pass
|
||||
|
||||
def main() -> CInt | t.CExport | t.State: pass
|
||||
6
Test/CPythonTest/temp/_sha1_map.txt
Normal file
6
Test/CPythonTest/temp/_sha1_map.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
3e1c3f98e99cff7a:cpython.py
|
||||
4d342c40331fc964:includes/viperlib.py
|
||||
56cdd754a8a09347:includes/stdint.py
|
||||
6999814920e8b3d5:main.py
|
||||
81ac26077a460417:includes/stdarg.py
|
||||
c9f4be41ca1cc2b4:includes/viperio.py
|
||||
BIN
Test/CPythonTest/temp/_shared_sym.pkl
Normal file
BIN
Test/CPythonTest/temp/_shared_sym.pkl
Normal file
Binary file not shown.
22
Test/CPythonTest/temp/c9f4be41ca1cc2b4.pyi
Normal file
22
Test/CPythonTest/temp/c9f4be41ca1cc2b4.pyi
Normal file
@@ -0,0 +1,22 @@
|
||||
"""
|
||||
Auto-generated Python stub file from viperio.py
|
||||
Module: viperio
|
||||
"""
|
||||
|
||||
|
||||
import t, c
|
||||
from stdint import *
|
||||
|
||||
class Buf:
|
||||
data: t.CChar | t.CPtr
|
||||
length: t.CSizeT
|
||||
capacity: t.CSizeT
|
||||
owned: bool
|
||||
def __init__(self: Buf, data: t.CChar | t.CPtr, capacity: t.CSizeT, length: t.CSizeT, owned: bool) -> t.CVoid | t.State: pass
|
||||
def clear(self: Buf) -> t.CVoid | t.State: pass
|
||||
def write(self: Buf, src: t.CChar | t.CPtr, count: t.CSizeT) -> t.CSizeT | t.State: pass
|
||||
def cstr(self: Buf) -> t.CChar | t.CPtr | t.State: pass
|
||||
def reset(self: Buf) -> t.CVoid | t.State: pass
|
||||
def __enter__(self: Buf) -> 'Buf' | t.CPtr | t.State: pass
|
||||
def __exit__(self: Buf) -> t.CVoid | t.State: pass
|
||||
def free(self: Buf) -> t.CVoid | t.State: pass
|
||||
17
Test/CPythonTest/temp/d771d4d68d9e75b3.pyi
Normal file
17
Test/CPythonTest/temp/d771d4d68d9e75b3.pyi
Normal file
@@ -0,0 +1,17 @@
|
||||
"""
|
||||
Auto-generated Python stub file from viperio.py
|
||||
Module: viperio
|
||||
"""
|
||||
|
||||
|
||||
import t, c
|
||||
|
||||
@t.Object
|
||||
class Buf:
|
||||
buf: str
|
||||
length: t.CSizeT
|
||||
capacity: t.CSizeT
|
||||
onHeap: bool
|
||||
def __init__(self: Buf, buf: str, length: t.CSizeT, onHeap: bool) -> t.CVoid | t.State: pass
|
||||
def free(self: Buf) -> t.CVoid | t.State: pass
|
||||
def __del__(self: Buf) -> t.CVoid | t.State: pass
|
||||
194
Test/ClosureTest/App/main.py
Normal file
194
Test/ClosureTest/App/main.py
Normal file
@@ -0,0 +1,194 @@
|
||||
import t
|
||||
import stdio
|
||||
|
||||
# ============================================================
|
||||
# Test 1: global 在嵌套函数中
|
||||
# ============================================================
|
||||
g_val: t.CInt = 100
|
||||
|
||||
def outer_modify_global():
|
||||
global g_val
|
||||
def inner_modify():
|
||||
global g_val
|
||||
g_val += 50
|
||||
inner_modify()
|
||||
|
||||
def test_global_in_nested():
|
||||
stdio.printf("--- Test 1: global in nested function ---\n")
|
||||
global g_val
|
||||
g_val = 100
|
||||
outer_modify_global()
|
||||
if g_val == 150:
|
||||
stdio.printf("PASS: global nested (g_val=%d)\n", g_val)
|
||||
else:
|
||||
stdio.printf("FAIL: global nested (g_val=%d, expect 150)\n", g_val)
|
||||
|
||||
# ============================================================
|
||||
# Test 2: nonlocal 在多层嵌套中
|
||||
# ============================================================
|
||||
def test_nonlocal_multi_level():
|
||||
stdio.printf("--- Test 2: nonlocal multi-level ---\n")
|
||||
x: t.CInt = 1
|
||||
def level1():
|
||||
nonlocal x
|
||||
x += 10
|
||||
def level2():
|
||||
nonlocal x
|
||||
x += 100
|
||||
def level3():
|
||||
nonlocal x
|
||||
x += 1000
|
||||
level3()
|
||||
level2()
|
||||
level1()
|
||||
if x == 1111:
|
||||
stdio.printf("PASS: nonlocal multi (x=%d)\n", x)
|
||||
else:
|
||||
stdio.printf("FAIL: nonlocal multi (x=%d, expect 1111)\n", x)
|
||||
|
||||
# ============================================================
|
||||
# Test 3: global 和 nonlocal 混合
|
||||
# ============================================================
|
||||
g_mixed: t.CInt = 0
|
||||
|
||||
def test_global_nonlocal_mixed():
|
||||
stdio.printf("--- Test 3: global + nonlocal mixed ---\n")
|
||||
global g_mixed
|
||||
g_mixed = 0
|
||||
local_var: t.CInt = 0
|
||||
def modify_both():
|
||||
nonlocal local_var
|
||||
global g_mixed
|
||||
g_mixed += 10
|
||||
local_var += 20
|
||||
modify_both()
|
||||
modify_both()
|
||||
if g_mixed == 20 and local_var == 40:
|
||||
stdio.printf("PASS: mixed (global=%d local=%d)\n", g_mixed, local_var)
|
||||
else:
|
||||
stdio.printf("FAIL: mixed (global=%d local=%d, expect 20 40)\n", g_mixed, local_var)
|
||||
|
||||
# ============================================================
|
||||
# Test 4: lambda 捕获多个变量
|
||||
# ============================================================
|
||||
def test_lambda_multi_capture():
|
||||
stdio.printf("--- Test 4: lambda multi-capture ---\n")
|
||||
a: t.CInt = 10
|
||||
b: t.CInt = 20
|
||||
f = lambda: a + b
|
||||
r: t.CInt = f()
|
||||
if r == 30:
|
||||
stdio.printf("PASS: lambda multi-capture (a+b=%d)\n", r)
|
||||
else:
|
||||
stdio.printf("FAIL: lambda multi-capture (a+b=%d, expect 30)\n", r)
|
||||
|
||||
# ============================================================
|
||||
# Test 5: lambda 带参数 + 捕获
|
||||
# ============================================================
|
||||
def test_lambda_arg_capture():
|
||||
stdio.printf("--- Test 5: lambda arg + capture ---\n")
|
||||
base: t.CInt = 100
|
||||
add = lambda x: base + x
|
||||
r: t.CInt = add(42)
|
||||
if r == 142:
|
||||
stdio.printf("PASS: lambda arg+capture (100+42=%d)\n", r)
|
||||
else:
|
||||
stdio.printf("FAIL: lambda arg+capture (result=%d, expect 142)\n", r)
|
||||
|
||||
# ============================================================
|
||||
# Test 6: 嵌套函数返回值
|
||||
# ============================================================
|
||||
def test_nested_return():
|
||||
stdio.printf("--- Test 6: nested function return ---\n")
|
||||
x: t.CInt = 5
|
||||
def double_x() -> t.CInt:
|
||||
nonlocal x
|
||||
x = x * 2
|
||||
return x
|
||||
r: t.CInt = double_x()
|
||||
if r == 10 and x == 10:
|
||||
stdio.printf("PASS: nested return (r=%d x=%d)\n", r, x)
|
||||
else:
|
||||
stdio.printf("FAIL: nested return (r=%d x=%d, expect 10 10)\n", r, x)
|
||||
|
||||
# ============================================================
|
||||
# Test 7: nonlocal 与循环变量
|
||||
# ============================================================
|
||||
def test_nonlocal_loop():
|
||||
stdio.printf("--- Test 7: nonlocal with loop ---\n")
|
||||
total: t.CInt = 0
|
||||
def accumulate(n: t.CInt):
|
||||
nonlocal total
|
||||
for i in range(n):
|
||||
total += i
|
||||
accumulate(5)
|
||||
accumulate(5)
|
||||
# 0+1+2+3+4 = 10, twice = 20
|
||||
if total == 20:
|
||||
stdio.printf("PASS: nonlocal loop (total=%d)\n", total)
|
||||
else:
|
||||
stdio.printf("FAIL: nonlocal loop (total=%d, expect 20)\n", total)
|
||||
|
||||
# ============================================================
|
||||
# Test 8: global 数组操作
|
||||
# ============================================================
|
||||
g_arr: list[t.CInt, 4] = [0]
|
||||
|
||||
def test_global_array():
|
||||
stdio.printf("--- Test 8: global array ---\n")
|
||||
global g_arr
|
||||
g_arr[0] = 10
|
||||
g_arr[1] = 20
|
||||
g_arr[2] = 30
|
||||
g_arr[3] = 40
|
||||
total: t.CInt = g_arr[0] + g_arr[1] + g_arr[2] + g_arr[3]
|
||||
if total == 100:
|
||||
stdio.printf("PASS: global array (total=%d)\n", total)
|
||||
else:
|
||||
stdio.printf("FAIL: global array (total=%d, expect 100)\n", total)
|
||||
|
||||
# ============================================================
|
||||
# Test 9: 嵌套函数条件调用
|
||||
# ============================================================
|
||||
def test_nested_conditional():
|
||||
stdio.printf("--- Test 9: nested conditional call ---\n")
|
||||
result: t.CInt = 0
|
||||
def set_result(val: t.CInt):
|
||||
nonlocal result
|
||||
result = val
|
||||
if 1:
|
||||
set_result(42)
|
||||
else:
|
||||
set_result(99)
|
||||
if result == 42:
|
||||
stdio.printf("PASS: nested conditional (result=%d)\n", result)
|
||||
else:
|
||||
stdio.printf("FAIL: nested conditional (result=%d, expect 42)\n", result)
|
||||
|
||||
# ============================================================
|
||||
# Test 10: lambda 链式调用
|
||||
# ============================================================
|
||||
def test_lambda_chain():
|
||||
stdio.printf("--- Test 10: lambda chain ---\n")
|
||||
f1 = lambda: 10
|
||||
f2 = lambda: 20
|
||||
r: t.CInt = f1() + f2()
|
||||
if r == 30:
|
||||
stdio.printf("PASS: lambda chain (10+20=%d)\n", r)
|
||||
else:
|
||||
stdio.printf("FAIL: lambda chain (result=%d, expect 30)\n", r)
|
||||
|
||||
def main() -> t.CInt:
|
||||
stdio.printf("=== ClosureAdvancedTest: 高级闭包测试 ===\n\n")
|
||||
test_global_in_nested()
|
||||
test_nonlocal_multi_level()
|
||||
test_global_nonlocal_mixed()
|
||||
test_lambda_multi_capture()
|
||||
test_lambda_arg_capture()
|
||||
test_nested_return()
|
||||
test_nonlocal_loop()
|
||||
test_global_array()
|
||||
test_nested_conditional()
|
||||
test_lambda_chain()
|
||||
stdio.printf("\n=== ClosureAdvancedTest Complete ===\n")
|
||||
return 0
|
||||
1
Test/ClosureTest/output/7dbf085f7e3e8944.deps.json
Normal file
1
Test/ClosureTest/output/7dbf085f7e3e8944.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"stdio": "73edbcf76e32d00b"}
|
||||
29
Test/ClosureTest/project.json
Normal file
29
Test/ClosureTest/project.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/TermiNexus/TransPyC/main/schemas/project-schema.json",
|
||||
"name": "ClosureTest",
|
||||
"version": "1.0.0",
|
||||
"source_dir": "./App",
|
||||
"temp_dir": "./temp",
|
||||
"output_dir": "./output",
|
||||
"compiler": {
|
||||
"cmd": "llc",
|
||||
"flags": ["-filetype=obj", "-relocation-model=pic"]
|
||||
},
|
||||
"linker": {
|
||||
"cmd": "clang++",
|
||||
"flags": ["-Wl,--allow-multiple-definition", "-Wl,--unresolved-symbols=ignore-in-object-files", "-lmsvcrt", "-lucrt", "-lpthread", "-lmingwex", "-lkernel32", "-luser32", "-latomic"],
|
||||
"output": "ClosureTest.exe"
|
||||
},
|
||||
"includes": [
|
||||
"../../includes"
|
||||
],
|
||||
"target": {
|
||||
"triple": "x86_64-pc-windows-gnu",
|
||||
"datalayout": "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
|
||||
},
|
||||
"options": {
|
||||
"slice_level": 3,
|
||||
"target": "llvm",
|
||||
"strict_mode": true
|
||||
}
|
||||
}
|
||||
28
Test/ClosureTest/temp/73edbcf76e32d00b.pyi
Normal file
28
Test/ClosureTest/temp/73edbcf76e32d00b.pyi
Normal file
@@ -0,0 +1,28 @@
|
||||
"""
|
||||
Auto-generated Python stub file from stdio.py
|
||||
Module: stdio
|
||||
"""
|
||||
|
||||
|
||||
import t, c
|
||||
|
||||
def printf(fmt: t.CChar | t.CConst | t.CPtr, *args) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def fprintf(stream: t.CVoid | t.CPtr, fmt: t.CChar | t.CConst | t.CPtr, *args) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def sprintf(buf: t.CChar | t.CPtr, fmt: t.CChar | t.CConst | t.CPtr, *args) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def snprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: t.CChar | t.CConst | t.CPtr, *args) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def puts(s: t.CChar | t.CConst | t.CPtr) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def fputs(s: t.CChar | t.CConst | t.CPtr, stream: t.CVoid | t.CPtr) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def fgets(buf: t.CChar | t.CPtr, size: t.CInt, stream: t.CVoid | t.CPtr) -> t.CChar | t.CPtr | t.CExtern | t.CExport: pass
|
||||
|
||||
def fflush(stream: t.CVoid | t.CPtr) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
|
||||
stdin: t.CExtern | t.CVoid | t.CPtr
|
||||
stdout: t.CExtern | t.CVoid | t.CPtr
|
||||
stderr: t.CExtern | t.CVoid | t.CPtr
|
||||
42
Test/ClosureTest/temp/7dbf085f7e3e8944.pyi
Normal file
42
Test/ClosureTest/temp/7dbf085f7e3e8944.pyi
Normal file
@@ -0,0 +1,42 @@
|
||||
"""
|
||||
Auto-generated Python stub file from main.py
|
||||
Module: main
|
||||
"""
|
||||
|
||||
import c
|
||||
|
||||
|
||||
import t
|
||||
import stdio
|
||||
|
||||
g_val: t.CExtern | t.CInt
|
||||
|
||||
def outer_modify_global() -> t.CInt: pass
|
||||
|
||||
def test_global_in_nested() -> t.CInt: pass
|
||||
|
||||
def test_nonlocal_multi_level() -> t.CInt: pass
|
||||
|
||||
|
||||
g_mixed: t.CExtern | t.CInt
|
||||
|
||||
def test_global_nonlocal_mixed() -> t.CInt: pass
|
||||
|
||||
def test_lambda_multi_capture() -> t.CInt: pass
|
||||
|
||||
def test_lambda_arg_capture() -> t.CInt: pass
|
||||
|
||||
def test_nested_return() -> t.CInt: pass
|
||||
|
||||
def test_nonlocal_loop() -> t.CInt: pass
|
||||
|
||||
|
||||
g_arr: t.CExtern | list[t.CInt, 4]
|
||||
|
||||
def test_global_array() -> t.CInt: pass
|
||||
|
||||
def test_nested_conditional() -> t.CInt: pass
|
||||
|
||||
def test_lambda_chain() -> t.CInt: pass
|
||||
|
||||
def main() -> t.CInt: pass
|
||||
2
Test/ClosureTest/temp/_sha1_map.txt
Normal file
2
Test/ClosureTest/temp/_sha1_map.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
73edbcf76e32d00b:includes/stdio.py
|
||||
7dbf085f7e3e8944:main.py
|
||||
256
Test/ClosureTest2/App/main.py
Normal file
256
Test/ClosureTest2/App/main.py
Normal file
@@ -0,0 +1,256 @@
|
||||
import t
|
||||
import stdio
|
||||
|
||||
# ============================================================
|
||||
# Test 1: nonlocal 在条件分支中修改
|
||||
# ============================================================
|
||||
def test_nonlocal_conditional():
|
||||
stdio.printf("--- Test 1: nonlocal in conditional branches ---\n")
|
||||
x: t.CInt = 0
|
||||
def modify(flag: t.CInt):
|
||||
nonlocal x
|
||||
if flag:
|
||||
x += 10
|
||||
else:
|
||||
x += 100
|
||||
modify(1)
|
||||
modify(0)
|
||||
modify(1)
|
||||
if x == 120:
|
||||
stdio.printf("PASS: nonlocal conditional (x=%d)\n", x)
|
||||
else:
|
||||
stdio.printf("FAIL: nonlocal conditional (x=%d, expect 120)\n", x)
|
||||
|
||||
# ============================================================
|
||||
# Test 2: 多个nonlocal变量同时修改
|
||||
# ============================================================
|
||||
def test_nonlocal_multi_var():
|
||||
stdio.printf("--- Test 2: multiple nonlocal variables ---\n")
|
||||
a: t.CInt = 1
|
||||
b: t.CInt = 2
|
||||
c_val: t.CInt = 3
|
||||
def swap_add():
|
||||
nonlocal a, b, c_val
|
||||
tmp: t.CInt = a
|
||||
a = b
|
||||
b = c_val
|
||||
c_val = tmp
|
||||
swap_add()
|
||||
if a == 2 and b == 3 and c_val == 1:
|
||||
stdio.printf("PASS: multi nonlocal (a=%d b=%d c=%d)\n", a, b, c_val)
|
||||
else:
|
||||
stdio.printf("FAIL: multi nonlocal (a=%d b=%d c=%d, expect 2 3 1)\n", a, b, c_val)
|
||||
|
||||
# ============================================================
|
||||
# Test 3: global 在多个函数中交叉修改
|
||||
# ============================================================
|
||||
g_counter: t.CInt = 0
|
||||
|
||||
def inc_global():
|
||||
global g_counter
|
||||
g_counter += 1
|
||||
|
||||
def add_global(n: t.CInt):
|
||||
global g_counter
|
||||
g_counter += n
|
||||
|
||||
def test_global_cross_functions():
|
||||
stdio.printf("--- Test 3: global cross-function modification ---\n")
|
||||
global g_counter
|
||||
g_counter = 0
|
||||
inc_global()
|
||||
inc_global()
|
||||
add_global(10)
|
||||
inc_global()
|
||||
if g_counter == 13:
|
||||
stdio.printf("PASS: global cross (g_counter=%d)\n", g_counter)
|
||||
else:
|
||||
stdio.printf("FAIL: global cross (g_counter=%d, expect 13)\n", g_counter)
|
||||
|
||||
# ============================================================
|
||||
# Test 4: 嵌套函数修改外层局部变量(引用捕获)
|
||||
# ============================================================
|
||||
def test_nested_ref_capture():
|
||||
stdio.printf("--- Test 4: nested function ref capture ---\n")
|
||||
arr: list[t.CInt, 4] = [0]
|
||||
def fill():
|
||||
nonlocal arr
|
||||
for i in range(4):
|
||||
arr[i] = (i + 1) * 10
|
||||
fill()
|
||||
total: t.CInt = arr[0] + arr[1] + arr[2] + arr[3]
|
||||
if total == 100:
|
||||
stdio.printf("PASS: ref capture (total=%d)\n", total)
|
||||
else:
|
||||
stdio.printf("FAIL: ref capture (total=%d, expect 100)\n", total)
|
||||
|
||||
# ============================================================
|
||||
# Test 5: lambda捕获后修改原变量
|
||||
# ============================================================
|
||||
def test_lambda_capture_then_modify():
|
||||
stdio.printf("--- Test 5: lambda capture then modify ---\n")
|
||||
x: t.CInt = 10
|
||||
f = lambda: x
|
||||
r1: t.CInt = f()
|
||||
x = 20
|
||||
r2: t.CInt = f()
|
||||
if r1 == 10 and r2 == 10:
|
||||
stdio.printf("PASS: lambda value capture (before=%d after=%d)\n", r1, r2)
|
||||
else:
|
||||
stdio.printf("FAIL: lambda value capture (before=%d after=%d, expect 10 10)\n", r1, r2)
|
||||
|
||||
# ============================================================
|
||||
# Test 6: 嵌套函数中nonlocal与循环结合
|
||||
# ============================================================
|
||||
def test_nonlocal_loop_accumulate():
|
||||
stdio.printf("--- Test 6: nonlocal with loop accumulate ---\n")
|
||||
sum_val: t.CInt = 0
|
||||
count: t.CInt = 0
|
||||
def add_numbers(n: t.CInt):
|
||||
nonlocal sum_val, count
|
||||
for i in range(1, n + 1):
|
||||
sum_val += i
|
||||
count += 1
|
||||
add_numbers(5) # 1+2+3+4+5=15
|
||||
add_numbers(3) # 1+2+3=6
|
||||
if sum_val == 21 and count == 8:
|
||||
stdio.printf("PASS: loop accumulate (sum=%d count=%d)\n", sum_val, count)
|
||||
else:
|
||||
stdio.printf("FAIL: loop accumulate (sum=%d count=%d, expect 21 8)\n", sum_val, count)
|
||||
|
||||
# ============================================================
|
||||
# Test 7: 三层嵌套中每层修改不同变量
|
||||
# ============================================================
|
||||
def test_deep_nested_vars():
|
||||
stdio.printf("--- Test 7: deep nested different vars ---\n")
|
||||
a: t.CInt = 0
|
||||
b: t.CInt = 0
|
||||
c_val: t.CInt = 0
|
||||
def level1():
|
||||
nonlocal a
|
||||
a += 1
|
||||
def level2():
|
||||
nonlocal b
|
||||
b += 10
|
||||
def level3():
|
||||
nonlocal c_val
|
||||
c_val += 100
|
||||
level3()
|
||||
level2()
|
||||
level1()
|
||||
level1()
|
||||
if a == 2 and b == 20 and c_val == 200:
|
||||
stdio.printf("PASS: deep nested (a=%d b=%d c=%d)\n", a, b, c_val)
|
||||
else:
|
||||
stdio.printf("FAIL: deep nested (a=%d b=%d c=%d, expect 2 20 200)\n", a, b, c_val)
|
||||
|
||||
# ============================================================
|
||||
# Test 8: global + nonlocal 在同一嵌套函数中
|
||||
# ============================================================
|
||||
g_state: t.CInt = 0
|
||||
|
||||
def test_global_nonlocal_same_func():
|
||||
stdio.printf("--- Test 8: global+nonlocal in same nested func ---\n")
|
||||
global g_state
|
||||
g_state = 0
|
||||
local_state: t.CInt = 0
|
||||
def worker(n: t.CInt):
|
||||
nonlocal local_state
|
||||
global g_state
|
||||
for i in range(n):
|
||||
g_state += 1
|
||||
local_state += 2
|
||||
worker(5)
|
||||
if g_state == 5 and local_state == 10:
|
||||
stdio.printf("PASS: global+nonlocal same (g=%d l=%d)\n", g_state, local_state)
|
||||
else:
|
||||
stdio.printf("FAIL: global+nonlocal same (g=%d l=%d, expect 5 10)\n", g_state, local_state)
|
||||
|
||||
# ============================================================
|
||||
# Test 9: lambda带默认参数与捕获
|
||||
# ============================================================
|
||||
def test_lambda_default_and_capture():
|
||||
stdio.printf("--- Test 9: lambda with arg and capture ---\n")
|
||||
base: t.CInt = 100
|
||||
multiply = lambda x: base * x
|
||||
r1: t.CInt = multiply(3)
|
||||
r2: t.CInt = multiply(5)
|
||||
if r1 == 300 and r2 == 500:
|
||||
stdio.printf("PASS: lambda arg+capture (100*3=%d 100*5=%d)\n", r1, r2)
|
||||
else:
|
||||
stdio.printf("FAIL: lambda arg+capture (100*3=%d 100*5=%d, expect 300 500)\n", r1, r2)
|
||||
|
||||
# ============================================================
|
||||
# Test 10: 嵌套函数多次调用累积
|
||||
# ============================================================
|
||||
def test_nested_accumulate():
|
||||
stdio.printf("--- Test 10: nested function accumulate ---\n")
|
||||
total: t.CInt = 0
|
||||
def add_val(n: t.CInt):
|
||||
nonlocal total
|
||||
total += n
|
||||
add_val(10)
|
||||
add_val(20)
|
||||
add_val(30)
|
||||
if total == 60:
|
||||
stdio.printf("PASS: nested accumulate (total=%d)\n", total)
|
||||
else:
|
||||
stdio.printf("FAIL: nested accumulate (total=%d, expect 60)\n", total)
|
||||
|
||||
# ============================================================
|
||||
# Test 11: nonlocal在while循环中
|
||||
# ============================================================
|
||||
def test_nonlocal_while():
|
||||
stdio.printf("--- Test 11: nonlocal in while loop ---\n")
|
||||
result: t.CInt = 0
|
||||
def countdown(n: t.CInt):
|
||||
nonlocal result
|
||||
i: t.CInt = n
|
||||
while i > 0:
|
||||
result += i
|
||||
i -= 1
|
||||
countdown(5) # 5+4+3+2+1=15
|
||||
if result == 15:
|
||||
stdio.printf("PASS: nonlocal while (result=%d)\n", result)
|
||||
else:
|
||||
stdio.printf("FAIL: nonlocal while (result=%d, expect 15)\n", result)
|
||||
|
||||
# ============================================================
|
||||
# Test 12: 嵌套函数修改结构体字段
|
||||
# ============================================================
|
||||
class Point:
|
||||
x: t.CInt
|
||||
y: t.CInt
|
||||
|
||||
def test_nested_modify_struct():
|
||||
stdio.printf("--- Test 12: nested modify struct ---\n")
|
||||
p: Point = Point()
|
||||
p.x = 0
|
||||
p.y = 0
|
||||
def translate(dx: t.CInt, dy: t.CInt):
|
||||
nonlocal p
|
||||
p.x += dx
|
||||
p.y += dy
|
||||
translate(10, 20)
|
||||
translate(5, 15)
|
||||
if p.x == 15 and p.y == 35:
|
||||
stdio.printf("PASS: nested struct (x=%d y=%d)\n", p.x, p.y)
|
||||
else:
|
||||
stdio.printf("FAIL: nested struct (x=%d y=%d, expect 15 35)\n", p.x, p.y)
|
||||
|
||||
def main() -> t.CInt:
|
||||
stdio.printf("=== ClosureTest2: Advanced Closure/Lambda/Global/Nonlocal ===\n\n")
|
||||
test_nonlocal_conditional()
|
||||
test_nonlocal_multi_var()
|
||||
test_global_cross_functions()
|
||||
test_nested_ref_capture()
|
||||
test_lambda_capture_then_modify()
|
||||
test_nonlocal_loop_accumulate()
|
||||
test_deep_nested_vars()
|
||||
test_global_nonlocal_same_func()
|
||||
test_lambda_default_and_capture()
|
||||
test_nested_accumulate()
|
||||
test_nonlocal_while()
|
||||
test_nested_modify_struct()
|
||||
stdio.printf("\n=== ClosureTest2 Complete ===\n")
|
||||
return 0
|
||||
1
Test/ClosureTest2/output/052c7f96b9eefa2c.deps.json
Normal file
1
Test/ClosureTest2/output/052c7f96b9eefa2c.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"stdio": "73edbcf76e32d00b"}
|
||||
29
Test/ClosureTest2/project.json
Normal file
29
Test/ClosureTest2/project.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/TermiNexus/TransPyC/main/schemas/project-schema.json",
|
||||
"name": "ClosureTest2",
|
||||
"version": "1.0.0",
|
||||
"source_dir": "./App",
|
||||
"temp_dir": "./temp",
|
||||
"output_dir": "./output",
|
||||
"compiler": {
|
||||
"cmd": "llc",
|
||||
"flags": ["-filetype=obj", "-relocation-model=pic"]
|
||||
},
|
||||
"linker": {
|
||||
"cmd": "clang++",
|
||||
"flags": ["-Wl,--allow-multiple-definition", "-Wl,--unresolved-symbols=ignore-in-object-files", "-lmsvcrt", "-lucrt", "-lpthread", "-lmingwex", "-lkernel32", "-luser32", "-latomic"],
|
||||
"output": "ClosureTest2.exe"
|
||||
},
|
||||
"includes": [
|
||||
"../../includes"
|
||||
],
|
||||
"target": {
|
||||
"triple": "x86_64-pc-windows-gnu",
|
||||
"datalayout": "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
|
||||
},
|
||||
"options": {
|
||||
"slice_level": 3,
|
||||
"target": "llvm",
|
||||
"strict_mode": true
|
||||
}
|
||||
}
|
||||
51
Test/ClosureTest2/temp/052c7f96b9eefa2c.pyi
Normal file
51
Test/ClosureTest2/temp/052c7f96b9eefa2c.pyi
Normal file
@@ -0,0 +1,51 @@
|
||||
"""
|
||||
Auto-generated Python stub file from main.py
|
||||
Module: main
|
||||
"""
|
||||
|
||||
import c
|
||||
|
||||
|
||||
import t
|
||||
import stdio
|
||||
|
||||
def test_nonlocal_conditional() -> t.CInt: pass
|
||||
|
||||
def test_nonlocal_multi_var() -> t.CInt: pass
|
||||
|
||||
|
||||
g_counter: t.CExtern | t.CInt
|
||||
|
||||
def inc_global() -> t.CInt: pass
|
||||
|
||||
def add_global(n: t.CInt) -> t.CInt: pass
|
||||
|
||||
def test_global_cross_functions() -> t.CInt: pass
|
||||
|
||||
def test_nested_ref_capture() -> t.CInt: pass
|
||||
|
||||
def test_lambda_capture_then_modify() -> t.CInt: pass
|
||||
|
||||
def test_nonlocal_loop_accumulate() -> t.CInt: pass
|
||||
|
||||
def test_deep_nested_vars() -> t.CInt: pass
|
||||
|
||||
|
||||
g_state: t.CExtern | t.CInt
|
||||
|
||||
def test_global_nonlocal_same_func() -> t.CInt: pass
|
||||
|
||||
def test_lambda_default_and_capture() -> t.CInt: pass
|
||||
|
||||
def test_nested_accumulate() -> t.CInt: pass
|
||||
|
||||
def test_nonlocal_while() -> t.CInt: pass
|
||||
|
||||
|
||||
class Point:
|
||||
x: t.CInt
|
||||
y: t.CInt
|
||||
|
||||
def test_nested_modify_struct() -> t.CInt: pass
|
||||
|
||||
def main() -> t.CInt: pass
|
||||
28
Test/ClosureTest2/temp/73edbcf76e32d00b.pyi
Normal file
28
Test/ClosureTest2/temp/73edbcf76e32d00b.pyi
Normal file
@@ -0,0 +1,28 @@
|
||||
"""
|
||||
Auto-generated Python stub file from stdio.py
|
||||
Module: stdio
|
||||
"""
|
||||
|
||||
|
||||
import t, c
|
||||
|
||||
def printf(fmt: t.CChar | t.CConst | t.CPtr, *args) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def fprintf(stream: t.CVoid | t.CPtr, fmt: t.CChar | t.CConst | t.CPtr, *args) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def sprintf(buf: t.CChar | t.CPtr, fmt: t.CChar | t.CConst | t.CPtr, *args) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def snprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: t.CChar | t.CConst | t.CPtr, *args) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def puts(s: t.CChar | t.CConst | t.CPtr) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def fputs(s: t.CChar | t.CConst | t.CPtr, stream: t.CVoid | t.CPtr) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def fgets(buf: t.CChar | t.CPtr, size: t.CInt, stream: t.CVoid | t.CPtr) -> t.CChar | t.CPtr | t.CExtern | t.CExport: pass
|
||||
|
||||
def fflush(stream: t.CVoid | t.CPtr) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
|
||||
stdin: t.CExtern | t.CVoid | t.CPtr
|
||||
stdout: t.CExtern | t.CVoid | t.CPtr
|
||||
stderr: t.CExtern | t.CVoid | t.CPtr
|
||||
2
Test/ClosureTest2/temp/_sha1_map.txt
Normal file
2
Test/ClosureTest2/temp/_sha1_map.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
052c7f96b9eefa2c:main.py
|
||||
73edbcf76e32d00b:includes/stdio.py
|
||||
290
Test/DecoratorTest/App/main.py
Normal file
290
Test/DecoratorTest/App/main.py
Normal file
@@ -0,0 +1,290 @@
|
||||
import t
|
||||
from stdio import printf
|
||||
|
||||
# ============================================================
|
||||
# 自定义装饰器处理函数
|
||||
# 调用约定 (v4):
|
||||
# i32 decor_name(i8* ctx, i8* func_name, i32 phase,
|
||||
# i8* args_ptr, i8* ret_ptr, i8* decor_args_ptr)
|
||||
#
|
||||
# ctx: 栈帧局部上下文(32字节),每次调用独立,线程/递归安全
|
||||
# args_ptr: 可读写,装饰器可修改函数入参
|
||||
# ret_ptr: 后置阶段可读写,装饰器可修改返回值
|
||||
# 返回值(前置阶段):
|
||||
# 0 = 跳过原函数调用
|
||||
# 1 = 正常调用一次
|
||||
# N = 循环调用 N 次
|
||||
# ============================================================
|
||||
|
||||
# @log 装饰器:打印函数进入/退出,返回 1(正常调用一次)
|
||||
def log(ctx: t.CVoid | t.CPtr, func_name: str, phase: t.CInt,
|
||||
args_ptr: t.CVoid | t.CPtr,
|
||||
ret_ptr: t.CVoid | t.CPtr,
|
||||
decor_args_ptr: t.CVoid | t.CPtr) -> t.CInt | t.CExport:
|
||||
if phase == 0:
|
||||
printf("[LOG] >> %s enter\n", func_name)
|
||||
return 1
|
||||
else:
|
||||
printf("[LOG] << %s exit\n", func_name)
|
||||
return 0
|
||||
|
||||
# @trace 装饰器:详细追踪
|
||||
def trace(ctx: t.CVoid | t.CPtr, func_name: str, phase: t.CInt,
|
||||
args_ptr: t.CVoid | t.CPtr,
|
||||
ret_ptr: t.CVoid | t.CPtr,
|
||||
decor_args_ptr: t.CVoid | t.CPtr) -> t.CInt | t.CExport:
|
||||
if phase == 0:
|
||||
printf("[TRACE] calling %s...\n", func_name)
|
||||
return 1
|
||||
else:
|
||||
printf("[TRACE] %s returned\n", func_name)
|
||||
return 0
|
||||
|
||||
# @timing 装饰器:使用全局变量记录计时
|
||||
# 注意:理想情况下应使用 ctx 栈帧局部上下文替代全局变量,
|
||||
# 但 Viper 当前前端尚不支持 i8* 到 i32* 的指针转型,
|
||||
# 因此暂时使用全局变量演示计时逻辑
|
||||
_timing_tmp: t.CInt = 0
|
||||
|
||||
def timing(ctx: t.CVoid | t.CPtr, func_name: str, phase: t.CInt,
|
||||
args_ptr: t.CVoid | t.CPtr,
|
||||
ret_ptr: t.CVoid | t.CPtr,
|
||||
decor_args_ptr: t.CVoid | t.CPtr) -> t.CInt | t.CExport:
|
||||
global _timing_tmp
|
||||
if phase == 0:
|
||||
_timing_tmp = 100
|
||||
printf("[TIMING] %s start at t=%d\n", func_name, _timing_tmp)
|
||||
return 1
|
||||
else:
|
||||
elapsed: t.CInt = 105 - _timing_tmp
|
||||
printf("[TIMING] %s took %d ms\n", func_name, elapsed)
|
||||
return 0
|
||||
|
||||
# @repeat 装饰器(带参数,流程劫持):循环调用原函数 N 次
|
||||
def repeat(ctx: t.CVoid | t.CPtr, func_name: str, phase: t.CInt,
|
||||
args_ptr: t.CVoid | t.CPtr,
|
||||
ret_ptr: t.CVoid | t.CPtr,
|
||||
decor_args_ptr: t.CVoid | t.CPtr) -> t.CInt | t.CExport:
|
||||
if phase == 0:
|
||||
printf("[REPEAT] %s will run 3 times\n", func_name)
|
||||
return 3
|
||||
else:
|
||||
printf("[REPEAT] %s all iterations done\n", func_name)
|
||||
return 0
|
||||
|
||||
# @skip 装饰器:跳过原函数调用(流程劫持,返回 0)
|
||||
_skip_count: t.CInt = 0
|
||||
|
||||
def skip(ctx: t.CVoid | t.CPtr, func_name: str, phase: t.CInt,
|
||||
args_ptr: t.CVoid | t.CPtr,
|
||||
ret_ptr: t.CVoid | t.CPtr,
|
||||
decor_args_ptr: t.CVoid | t.CPtr) -> t.CInt | t.CExport:
|
||||
global _skip_count
|
||||
if phase == 0:
|
||||
_skip_count = _skip_count + 1
|
||||
printf("[SKIP] %s skipped! (call #%d)\n", func_name, _skip_count)
|
||||
return 0
|
||||
else:
|
||||
printf("[SKIP] %s post (ret_ptr=%p)\n", func_name, ret_ptr)
|
||||
return 0
|
||||
|
||||
# @count_calls 装饰器:统计函数被调用次数(递归保护测试用)
|
||||
_call_count: t.CInt = 0
|
||||
|
||||
def count_calls(ctx: t.CVoid | t.CPtr, func_name: str, phase: t.CInt,
|
||||
args_ptr: t.CVoid | t.CPtr,
|
||||
ret_ptr: t.CVoid | t.CPtr,
|
||||
decor_args_ptr: t.CVoid | t.CPtr) -> t.CInt | t.CExport:
|
||||
global _call_count
|
||||
if phase == 0:
|
||||
_call_count = _call_count + 1
|
||||
printf("[COUNT] %s call #%d\n", func_name, _call_count)
|
||||
return 1
|
||||
else:
|
||||
printf("[COUNT] %s done (total calls: %d)\n", func_name, _call_count)
|
||||
return 0
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 测试 1:单个装饰器 @log
|
||||
# ============================================================
|
||||
|
||||
@log
|
||||
def add(a: t.CInt, b: t.CInt) -> t.CInt | t.CExport:
|
||||
return a + b
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 测试 2:链式装饰器 @log @trace => log(trace(f))
|
||||
# 执行顺序:log_pre → trace_pre → f → trace_post → log_post
|
||||
# ============================================================
|
||||
|
||||
@log
|
||||
@trace
|
||||
def multiply(a: t.CInt, b: t.CInt) -> t.CInt | t.CExport:
|
||||
return a * b
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 测试 3:装饰器修饰 void 返回函数
|
||||
# ============================================================
|
||||
|
||||
@log
|
||||
def greet(name: str) -> t.CVoid | t.CExport:
|
||||
printf("Hello, %s!\n", name)
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 测试 4:装饰器修饰无参数函数
|
||||
# ============================================================
|
||||
|
||||
@log
|
||||
def get_value() -> t.CInt | t.CExport:
|
||||
return 42
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 测试 5:@timing 装饰器
|
||||
# ============================================================
|
||||
|
||||
@timing
|
||||
def compute(x: t.CInt) -> t.CInt | t.CExport:
|
||||
return x * x + 1
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 测试 6:带参数装饰器 @repeat(3) — 流程劫持,循环调用 3 次
|
||||
# ============================================================
|
||||
|
||||
@repeat(3)
|
||||
def echo(msg: str) -> t.CVoid | t.CExport:
|
||||
printf(" echo: %s\n", msg)
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 测试 7:链式 @timing @log
|
||||
# ============================================================
|
||||
|
||||
@timing
|
||||
@log
|
||||
def power(base: t.CInt, exp: t.CInt) -> t.CInt | t.CExport:
|
||||
result: t.CInt = 1
|
||||
i: t.CInt = 0
|
||||
while i < exp:
|
||||
result = result * base
|
||||
i = i + 1
|
||||
return result
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 测试 8:@skip 装饰器 — 流程劫持,跳过原函数调用
|
||||
# ============================================================
|
||||
|
||||
@skip
|
||||
def dangerous() -> t.CInt | t.CExport:
|
||||
printf("This should NOT be printed!\n")
|
||||
return 999
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 测试 9:@repeat(3) 修饰有返回值的函数
|
||||
# ============================================================
|
||||
|
||||
@repeat(3)
|
||||
def accumulate(x: t.CInt) -> t.CInt | t.CExport:
|
||||
printf(" accumulate(%d)\n", x)
|
||||
return x * 10
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 测试 10:递归装饰保护 — @count_calls 修饰递归函数
|
||||
# v4 递归保护:最外层 wrapper 检查全局标志位,
|
||||
# 递归调用时跳过所有装饰逻辑,仅最外层调用触发装饰器
|
||||
# ============================================================
|
||||
|
||||
@count_calls
|
||||
def factorial(n: t.CInt) -> t.CInt | t.CExport:
|
||||
if n <= 1:
|
||||
return 1
|
||||
return n * factorial(n - 1)
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 测试 11:@log 修饰递归函数 — 验证递归保护
|
||||
# 递归保护确保只有最外层调用打印 LOG,内部递归不触发
|
||||
# ============================================================
|
||||
|
||||
@log
|
||||
def fib(n: t.CInt) -> t.CInt | t.CExport:
|
||||
if n <= 1:
|
||||
return n
|
||||
return fib(n - 1) + fib(n - 2)
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 主函数
|
||||
# ============================================================
|
||||
|
||||
def main() -> t.CInt | t.CExport:
|
||||
printf("=== Decorator Test v4 ===\n\n")
|
||||
|
||||
# 测试 1:单个 @log
|
||||
printf("--- Test 1: single @log ---\n")
|
||||
r1: t.CInt = add(3, 4)
|
||||
printf("add(3,4) = %d\n\n", r1)
|
||||
|
||||
# 测试 2:链式 @log @trace
|
||||
printf("--- Test 2: chained @log @trace ---\n")
|
||||
r2: t.CInt = multiply(5, 6)
|
||||
printf("multiply(5,6) = %d\n\n", r2)
|
||||
|
||||
# 测试 3:void 返回
|
||||
printf("--- Test 3: @log on void function ---\n")
|
||||
greet("Viper")
|
||||
printf("\n")
|
||||
|
||||
# 测试 4:无参数
|
||||
printf("--- Test 4: @log on no-arg function ---\n")
|
||||
r4: t.CInt = get_value()
|
||||
printf("get_value() = %d\n\n", r4)
|
||||
|
||||
# 测试 5:@timing
|
||||
printf("--- Test 5: @timing ---\n")
|
||||
r5: t.CInt = compute(7)
|
||||
printf("compute(7) = %d\n\n", r5)
|
||||
|
||||
# 测试 6:@repeat(3) — 流程劫持,循环 3 次
|
||||
printf("--- Test 6: @repeat(3) flow hijack ---\n")
|
||||
echo("hello")
|
||||
printf("\n")
|
||||
|
||||
# 测试 7:链式 @timing @log
|
||||
printf("--- Test 7: chained @timing @log ---\n")
|
||||
r7: t.CInt = power(2, 10)
|
||||
printf("power(2,10) = %d\n\n", r7)
|
||||
|
||||
# 测试 8:@skip — 跳过原函数调用
|
||||
printf("--- Test 8: @skip flow hijack ---\n")
|
||||
r8: t.CInt = dangerous()
|
||||
printf("dangerous() = %d (should be 0, skipped)\n\n", r8)
|
||||
|
||||
# 测试 9:@repeat(3) 有返回值
|
||||
printf("--- Test 9: @repeat(3) with return value ---\n")
|
||||
r9: t.CInt = accumulate(5)
|
||||
printf("accumulate(5) = %d (last iteration result)\n\n", r9)
|
||||
|
||||
# 测试 10:递归装饰保护 — @count_calls
|
||||
printf("--- Test 10: recursive decoration protection ---\n")
|
||||
_call_count = 0
|
||||
r10: t.CInt = factorial(5)
|
||||
printf("factorial(5) = %d (should be 120)\n", r10)
|
||||
printf(" decorator call count = %d (should be 1, not 5)\n\n", _call_count)
|
||||
|
||||
# 测试 11:@log 递归保护 — fib
|
||||
printf("--- Test 11: @log on recursive fib ---\n")
|
||||
r11: t.CInt = fib(6)
|
||||
printf("fib(6) = %d (should be 8)\n", r11)
|
||||
printf(" (should see only 1 LOG enter/exit pair)\n\n")
|
||||
|
||||
printf("=== All decorator tests done ===\n")
|
||||
return 0
|
||||
1
Test/DecoratorTest/output/577f9e1aa32b17f8.deps.json
Normal file
1
Test/DecoratorTest/output/577f9e1aa32b17f8.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"stdio": "73edbcf76e32d00b"}
|
||||
28
Test/DecoratorTest/project.json
Normal file
28
Test/DecoratorTest/project.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "DecoratorTest",
|
||||
"version": "1.0.0",
|
||||
"source_dir": "./App",
|
||||
"temp_dir": "./temp",
|
||||
"output_dir": "./output",
|
||||
"compiler": {
|
||||
"cmd": "llc",
|
||||
"flags": ["-filetype=obj", "-relocation-model=pic"]
|
||||
},
|
||||
"linker": {
|
||||
"cmd": "clang++",
|
||||
"flags": ["-Wl,--allow-multiple-definition", "-Wl,--unresolved-symbols=ignore-in-object-files", "-lmsvcrt", "-lucrt", "-lpthread", "-lmingwex", "-lkernel32", "-luser32", "-latomic"],
|
||||
"output": "DecoratorTest.exe"
|
||||
},
|
||||
"includes": [
|
||||
"../../includes"
|
||||
],
|
||||
"target": {
|
||||
"triple": "x86_64-pc-windows-gnu",
|
||||
"datalayout": "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
|
||||
},
|
||||
"options": {
|
||||
"slice_level": 3,
|
||||
"target": "llvm",
|
||||
"strict_mode": true
|
||||
}
|
||||
}
|
||||
68
Test/DecoratorTest/temp/577f9e1aa32b17f8.pyi
Normal file
68
Test/DecoratorTest/temp/577f9e1aa32b17f8.pyi
Normal file
@@ -0,0 +1,68 @@
|
||||
"""
|
||||
Auto-generated Python stub file from main.py
|
||||
Module: main
|
||||
"""
|
||||
|
||||
import c
|
||||
|
||||
|
||||
import t
|
||||
from stdio import printf
|
||||
|
||||
def log(ctx: t.CVoid | t.CPtr, func_name: str, phase: t.CInt, args_ptr: t.CVoid | t.CPtr, ret_ptr: t.CVoid | t.CPtr, decor_args_ptr: t.CVoid | t.CPtr) -> t.CInt | t.CExport: pass
|
||||
|
||||
def trace(ctx: t.CVoid | t.CPtr, func_name: str, phase: t.CInt, args_ptr: t.CVoid | t.CPtr, ret_ptr: t.CVoid | t.CPtr, decor_args_ptr: t.CVoid | t.CPtr) -> t.CInt | t.CExport: pass
|
||||
|
||||
|
||||
_timing_tmp: t.CExtern | t.CInt
|
||||
|
||||
def timing(ctx: t.CVoid | t.CPtr, func_name: str, phase: t.CInt, args_ptr: t.CVoid | t.CPtr, ret_ptr: t.CVoid | t.CPtr, decor_args_ptr: t.CVoid | t.CPtr) -> t.CInt | t.CExport: pass
|
||||
|
||||
def repeat(ctx: t.CVoid | t.CPtr, func_name: str, phase: t.CInt, args_ptr: t.CVoid | t.CPtr, ret_ptr: t.CVoid | t.CPtr, decor_args_ptr: t.CVoid | t.CPtr) -> t.CInt | t.CExport: pass
|
||||
|
||||
|
||||
_skip_count: t.CExtern | t.CInt
|
||||
|
||||
def skip(ctx: t.CVoid | t.CPtr, func_name: str, phase: t.CInt, args_ptr: t.CVoid | t.CPtr, ret_ptr: t.CVoid | t.CPtr, decor_args_ptr: t.CVoid | t.CPtr) -> t.CInt | t.CExport: pass
|
||||
|
||||
|
||||
_call_count: t.CExtern | t.CInt
|
||||
|
||||
def count_calls(ctx: t.CVoid | t.CPtr, func_name: str, phase: t.CInt, args_ptr: t.CVoid | t.CPtr, ret_ptr: t.CVoid | t.CPtr, decor_args_ptr: t.CVoid | t.CPtr) -> t.CInt | t.CExport: pass
|
||||
|
||||
@log
|
||||
def add(a: t.CInt, b: t.CInt) -> t.CInt | t.CExport: pass
|
||||
|
||||
@log
|
||||
@trace
|
||||
def multiply(a: t.CInt, b: t.CInt) -> t.CInt | t.CExport: pass
|
||||
|
||||
@log
|
||||
def greet(name: str) -> t.CVoid | t.CExport: pass
|
||||
|
||||
@log
|
||||
def get_value() -> t.CInt | t.CExport: pass
|
||||
|
||||
@timing
|
||||
def compute(x: t.CInt) -> t.CInt | t.CExport: pass
|
||||
|
||||
@repeat(3)
|
||||
def echo(msg: str) -> t.CVoid | t.CExport: pass
|
||||
|
||||
@timing
|
||||
@log
|
||||
def power(base: t.CInt, exp: t.CInt) -> t.CInt | t.CExport: pass
|
||||
|
||||
@skip
|
||||
def dangerous() -> t.CInt | t.CExport: pass
|
||||
|
||||
@repeat(3)
|
||||
def accumulate(x: t.CInt) -> t.CInt | t.CExport: pass
|
||||
|
||||
@count_calls
|
||||
def factorial(n: t.CInt) -> t.CInt | t.CExport: pass
|
||||
|
||||
@log
|
||||
def fib(n: t.CInt) -> t.CInt | t.CExport: pass
|
||||
|
||||
def main() -> t.CInt | t.CExport: pass
|
||||
28
Test/DecoratorTest/temp/73edbcf76e32d00b.pyi
Normal file
28
Test/DecoratorTest/temp/73edbcf76e32d00b.pyi
Normal file
@@ -0,0 +1,28 @@
|
||||
"""
|
||||
Auto-generated Python stub file from stdio.py
|
||||
Module: stdio
|
||||
"""
|
||||
|
||||
|
||||
import t, c
|
||||
|
||||
def printf(fmt: t.CChar | t.CConst | t.CPtr, *args) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def fprintf(stream: t.CVoid | t.CPtr, fmt: t.CChar | t.CConst | t.CPtr, *args) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def sprintf(buf: t.CChar | t.CPtr, fmt: t.CChar | t.CConst | t.CPtr, *args) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def snprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: t.CChar | t.CConst | t.CPtr, *args) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def puts(s: t.CChar | t.CConst | t.CPtr) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def fputs(s: t.CChar | t.CConst | t.CPtr, stream: t.CVoid | t.CPtr) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def fgets(buf: t.CChar | t.CPtr, size: t.CInt, stream: t.CVoid | t.CPtr) -> t.CChar | t.CPtr | t.CExtern | t.CExport: pass
|
||||
|
||||
def fflush(stream: t.CVoid | t.CPtr) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
|
||||
stdin: t.CExtern | t.CVoid | t.CPtr
|
||||
stdout: t.CExtern | t.CVoid | t.CPtr
|
||||
stderr: t.CExtern | t.CVoid | t.CPtr
|
||||
2
Test/DecoratorTest/temp/_sha1_map.txt
Normal file
2
Test/DecoratorTest/temp/_sha1_map.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
577f9e1aa32b17f8:main.py
|
||||
73edbcf76e32d00b:includes/stdio.py
|
||||
130
Test/FuncTest/App/main.py
Normal file
130
Test/FuncTest/App/main.py
Normal file
@@ -0,0 +1,130 @@
|
||||
import t
|
||||
import stdio
|
||||
|
||||
# 测试基本函数调用
|
||||
def add(a: t.CInt, b: t.CInt) -> t.CInt:
|
||||
return a + b
|
||||
|
||||
def sub(a: t.CInt, b: t.CInt) -> t.CInt:
|
||||
return a - b
|
||||
|
||||
# 测试多参数
|
||||
def multi_args(a: t.CInt, b: t.CInt, c: t.CInt, d: t.CInt) -> t.CInt:
|
||||
return a + b + c + d
|
||||
|
||||
# 测试递归
|
||||
def factorial(n: t.CInt) -> t.CInt:
|
||||
if n <= 1:
|
||||
return 1
|
||||
return n * factorial(n - 1)
|
||||
|
||||
# 测试尾递归式斐波那契
|
||||
def fib(n: t.CInt) -> t.CInt:
|
||||
if n <= 0:
|
||||
return 0
|
||||
if n == 1:
|
||||
return 1
|
||||
return fib(n - 1) + fib(n - 2)
|
||||
|
||||
# 测试指针参数
|
||||
def add_via_ptr(p: t.CInt | t.CPtr, val: t.CInt):
|
||||
p[0] = p[0] + val
|
||||
|
||||
# 测试 u64 返回值
|
||||
def make_u64() -> t.CUInt64T:
|
||||
return t.CUInt64T(0xDEADBEEF)
|
||||
|
||||
# 测试 bool 返回值
|
||||
def is_even(n: t.CInt) -> t.CBool:
|
||||
return n % 2 == 0
|
||||
|
||||
def test_basic_call():
|
||||
stdio.printf("--- Test 1: basic function call ---\n")
|
||||
r: t.CInt = add(10, 20)
|
||||
if r == 30:
|
||||
stdio.printf("PASS: add(10,20)=%d\n", r)
|
||||
else:
|
||||
stdio.printf("FAIL: add(10,20)=%d, expect 30\n", r)
|
||||
|
||||
def test_multi_args():
|
||||
stdio.printf("--- Test 2: multi args ---\n")
|
||||
r: t.CInt = multi_args(1, 2, 3, 4)
|
||||
if r == 10:
|
||||
stdio.printf("PASS: multi_args(1,2,3,4)=%d\n", r)
|
||||
else:
|
||||
stdio.printf("FAIL: multi_args(1,2,3,4)=%d, expect 10\n", r)
|
||||
|
||||
def test_recursion():
|
||||
stdio.printf("--- Test 3: recursion (factorial) ---\n")
|
||||
r: t.CInt = factorial(10)
|
||||
# 10! = 3628800
|
||||
if r == 3628800:
|
||||
stdio.printf("PASS: factorial(10)=%d\n", r)
|
||||
else:
|
||||
stdio.printf("FAIL: factorial(10)=%d, expect 3628800\n", r)
|
||||
|
||||
def test_fibonacci():
|
||||
stdio.printf("--- Test 4: fibonacci ---\n")
|
||||
r: t.CInt = fib(10)
|
||||
# fib(10) = 55
|
||||
if r == 55:
|
||||
stdio.printf("PASS: fib(10)=%d\n", r)
|
||||
else:
|
||||
stdio.printf("FAIL: fib(10)=%d, expect 55\n", r)
|
||||
|
||||
def test_ptr_param():
|
||||
stdio.printf("--- Test 5: pointer parameter ---\n")
|
||||
x: t.CInt = 10
|
||||
# 需要取 x 的地址
|
||||
import w32.win32memory
|
||||
buf: t.CInt | t.CPtr = w32.win32memory.VirtualAlloc(t.CVoid(0, t.CPtr), 64, 12288, 4)
|
||||
if t.CUInt64T(buf) == 0:
|
||||
stdio.printf("SKIP: VirtualAlloc returned NULL\n")
|
||||
return
|
||||
buf[0] = 10
|
||||
add_via_ptr(buf, 25)
|
||||
if buf[0] == 35:
|
||||
stdio.printf("PASS: ptr param (result=%d)\n", buf[0])
|
||||
else:
|
||||
stdio.printf("FAIL: ptr param (result=%d, expect 35)\n", buf[0])
|
||||
|
||||
def test_u64_return():
|
||||
stdio.printf("--- Test 6: u64 return ---\n")
|
||||
r: t.CUInt64T = make_u64()
|
||||
if r == t.CUInt64T(0xDEADBEEF):
|
||||
stdio.printf("PASS: u64 return (0x%lx)\n", r)
|
||||
else:
|
||||
stdio.printf("FAIL: u64 return (0x%lx, expect 0xdeadbeef)\n", r)
|
||||
|
||||
def test_bool_return():
|
||||
stdio.printf("--- Test 7: bool return ---\n")
|
||||
r1: t.CBool = is_even(4)
|
||||
r2: t.CBool = is_even(7)
|
||||
if r1 and not r2:
|
||||
stdio.printf("PASS: bool return (is_even(4)=%d, is_even(7)=%d)\n", r1, r2)
|
||||
else:
|
||||
stdio.printf("FAIL: bool return (is_even(4)=%d, is_even(7)=%d)\n", r1, r2)
|
||||
|
||||
def test_nested_call():
|
||||
stdio.printf("--- Test 8: nested function call ---\n")
|
||||
r: t.CInt = add(factorial(3), sub(10, 3))
|
||||
# 3! = 6, 10-3 = 7, 6+7 = 13
|
||||
if r == 13:
|
||||
stdio.printf("PASS: nested call (add(factorial(3), sub(10,3))=%d)\n", r)
|
||||
else:
|
||||
stdio.printf("FAIL: nested call (result=%d, expect 13)\n", r)
|
||||
|
||||
import w32.win32memory
|
||||
|
||||
def main() -> t.CInt:
|
||||
stdio.printf("=== FuncTest: 函数调用基准测试 ===\n\n")
|
||||
test_basic_call()
|
||||
test_multi_args()
|
||||
test_recursion()
|
||||
test_fibonacci()
|
||||
test_ptr_param()
|
||||
test_u64_return()
|
||||
test_bool_return()
|
||||
test_nested_call()
|
||||
stdio.printf("\n=== FuncTest Complete ===\n")
|
||||
return 0
|
||||
1
Test/FuncTest/output/067c78e9f121dce3.deps.json
Normal file
1
Test/FuncTest/output/067c78e9f121dce3.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "main": "d6f1d57732bde476", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e", "w32.win32process": "067c78e9f121dce3", "win32process": "067c78e9f121dce3"}
|
||||
1
Test/FuncTest/output/29813d57621099a9.deps.json
Normal file
1
Test/FuncTest/output/29813d57621099a9.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "main": "d6f1d57732bde476", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e", "w32.win32process": "067c78e9f121dce3", "win32process": "067c78e9f121dce3", "w32.win32sync": "29813d57621099a9", "win32sync": "29813d57621099a9"}
|
||||
1
Test/FuncTest/output/5a6a2137958c28c5.deps.json
Normal file
1
Test/FuncTest/output/5a6a2137958c28c5.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "main": "d6f1d57732bde476", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950"}
|
||||
1
Test/FuncTest/output/72e2d5ccb7cedcf1.deps.json
Normal file
1
Test/FuncTest/output/72e2d5ccb7cedcf1.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "main": "d6f1d57732bde476", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e"}
|
||||
1
Test/FuncTest/output/abf9ce3160c9279e.deps.json
Normal file
1
Test/FuncTest/output/abf9ce3160c9279e.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "main": "d6f1d57732bde476", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e"}
|
||||
1
Test/FuncTest/output/bbdf3bbd4c3bc28c.deps.json
Normal file
1
Test/FuncTest/output/bbdf3bbd4c3bc28c.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "main": "d6f1d57732bde476", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c"}
|
||||
1
Test/FuncTest/output/d6f1d57732bde476.deps.json
Normal file
1
Test/FuncTest/output/d6f1d57732bde476.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b"}
|
||||
1
Test/FuncTest/output/fa3691e66b426950.deps.json
Normal file
1
Test/FuncTest/output/fa3691e66b426950.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "main": "d6f1d57732bde476", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950"}
|
||||
29
Test/FuncTest/project.json
Normal file
29
Test/FuncTest/project.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/TermiNexus/TransPyC/main/schemas/project-schema.json",
|
||||
"name": "FuncTest",
|
||||
"version": "1.0.0",
|
||||
"source_dir": "./App",
|
||||
"temp_dir": "./temp",
|
||||
"output_dir": "./output",
|
||||
"compiler": {
|
||||
"cmd": "llc",
|
||||
"flags": ["-filetype=obj", "-relocation-model=pic"]
|
||||
},
|
||||
"linker": {
|
||||
"cmd": "clang++",
|
||||
"flags": ["-Wl,--allow-multiple-definition", "-Wl,--unresolved-symbols=ignore-in-object-files", "-lmsvcrt", "-lucrt", "-lpthread", "-lmingwex", "-lkernel32", "-luser32", "-latomic"],
|
||||
"output": "FuncTest.exe"
|
||||
},
|
||||
"includes": [
|
||||
"../../includes"
|
||||
],
|
||||
"target": {
|
||||
"triple": "x86_64-pc-windows-gnu",
|
||||
"datalayout": "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
|
||||
},
|
||||
"options": {
|
||||
"slice_level": 3,
|
||||
"target": "llvm",
|
||||
"strict_mode": true
|
||||
}
|
||||
}
|
||||
136
Test/FuncTest/temp/067c78e9f121dce3.pyi
Normal file
136
Test/FuncTest/temp/067c78e9f121dce3.pyi
Normal file
@@ -0,0 +1,136 @@
|
||||
"""
|
||||
Auto-generated Python stub file from w32.win32process.py
|
||||
Module: w32.win32process
|
||||
"""
|
||||
|
||||
import c
|
||||
|
||||
|
||||
import t
|
||||
from stdint import *
|
||||
from w32.win32base import *
|
||||
|
||||
PROCESS_TERMINATE: t.CDefine = 0x0001
|
||||
PROCESS_CREATE_THREAD: t.CDefine = 0x0002
|
||||
PROCESS_VM_OPERATION: t.CDefine = 0x0008
|
||||
PROCESS_VM_READ: t.CDefine = 0x0010
|
||||
PROCESS_VM_WRITE: t.CDefine = 0x0020
|
||||
PROCESS_QUERY_INFORMATION: t.CDefine = 0x0400
|
||||
PROCESS_ALL_ACCESS: t.CDefine = 0x001FFFFF
|
||||
THREAD_TERMINATE: t.CDefine = 0x0001
|
||||
THREAD_SUSPEND_RESUME: t.CDefine = 0x0002
|
||||
THREAD_GET_CONTEXT: t.CDefine = 0x0008
|
||||
THREAD_SET_CONTEXT: t.CDefine = 0x0010
|
||||
THREAD_QUERY_INFORMATION: t.CDefine = 0x0040
|
||||
THREAD_ALL_ACCESS: t.CDefine = 0x001FFFFF
|
||||
CREATE_SUSPENDED: t.CDefine = 0x00000004
|
||||
CREATE_NEW_CONSOLE: t.CDefine = 0x00000010
|
||||
CREATE_NEW_PROCESS_GROUP: t.CDefine = 0x00000200
|
||||
CREATE_NO_WINDOW: t.CDefine = 0x08000000
|
||||
DETACHED_PROCESS: t.CDefine = 0x00000008
|
||||
STARTF_USESHOWWINDOW: t.CDefine = 0x00000001
|
||||
STARTF_USESTDHANDLES: t.CDefine = 0x00000100
|
||||
SW_HIDE: t.CDefine = 0
|
||||
SW_SHOW: t.CDefine = 5
|
||||
SW_MINIMIZE: t.CDefine = 6
|
||||
NORMAL_PRIORITY_CLASS: t.CDefine = 0x00000020
|
||||
IDLE_PRIORITY_CLASS: t.CDefine = 0x00000040
|
||||
HIGH_PRIORITY_CLASS: t.CDefine = 0x00000080
|
||||
REALTIME_PRIORITY_CLASS: t.CDefine = 0x00000100
|
||||
BELOW_NORMAL_PRIORITY_CLASS: t.CDefine = 0x00004000
|
||||
ABOVE_NORMAL_PRIORITY_CLASS: t.CDefine = 0x00008000
|
||||
STILL_ACTIVE: t.CDefine = 259
|
||||
|
||||
class STARTUPINFOA:
|
||||
cb: ULONG
|
||||
lpReserved: CHARPTR
|
||||
lpDesktop: CHARPTR
|
||||
lpTitle: CHARPTR
|
||||
dwX: ULONG
|
||||
dwY: ULONG
|
||||
dwXSize: ULONG
|
||||
dwYSize: ULONG
|
||||
dwXCountChars: ULONG
|
||||
dwYCountChars: ULONG
|
||||
dwFillAttribute: ULONG
|
||||
dwFlags: ULONG
|
||||
wShowWindow: WORD
|
||||
cbReserved2: WORD
|
||||
lpReserved2: VOIDPTR
|
||||
hStdInput: HANDLE
|
||||
hStdOutput: HANDLE
|
||||
hStdError: HANDLE
|
||||
class STARTUPINFOW:
|
||||
cb: ULONG
|
||||
lpReserved: WCHARPTR
|
||||
lpDesktop: WCHARPTR
|
||||
lpTitle: WCHARPTR
|
||||
dwX: ULONG
|
||||
dwY: ULONG
|
||||
dwXSize: ULONG
|
||||
dwYSize: ULONG
|
||||
dwXCountChars: ULONG
|
||||
dwYCountChars: ULONG
|
||||
dwFillAttribute: ULONG
|
||||
dwFlags: ULONG
|
||||
wShowWindow: WORD
|
||||
cbReserved2: WORD
|
||||
lpReserved2: VOIDPTR
|
||||
hStdInput: HANDLE
|
||||
hStdOutput: HANDLE
|
||||
hStdError: HANDLE
|
||||
class PROCESS_INFORMATION:
|
||||
hProcess: HANDLE
|
||||
hThread: HANDLE
|
||||
dwProcessId: ULONG
|
||||
dwThreadId: ULONG
|
||||
|
||||
def CreateProcessA(lpApplicationName: LPCSTR, lpCommandLine: CHARPTR, lpProcessAttributes: SECURITY_ATTRIBUTES | t.CPtr, lpThreadAttributes: SECURITY_ATTRIBUTES | t.CPtr, bInheritHandles: BOOL, dwCreationFlags: ULONG, lpEnvironment: VOIDPTR, lpCurrentDirectory: LPCSTR, lpStartupInfo: STARTUPINFOA | t.CPtr, lpProcessInformation: PROCESS_INFORMATION | t.CPtr) -> BOOL | t.State: pass
|
||||
|
||||
def CreateProcessW(lpApplicationName: LPCWSTR, lpCommandLine: WCHARPTR, lpProcessAttributes: SECURITY_ATTRIBUTES | t.CPtr, lpThreadAttributes: SECURITY_ATTRIBUTES | t.CPtr, bInheritHandles: BOOL, dwCreationFlags: ULONG, lpEnvironment: VOIDPTR, lpCurrentDirectory: LPCWSTR, lpStartupInfo: STARTUPINFOW | t.CPtr, lpProcessInformation: PROCESS_INFORMATION | t.CPtr) -> BOOL | t.State: pass
|
||||
|
||||
def TerminateProcess(hProcess: HANDLE, uExitCode: UINT) -> BOOL | t.State: pass
|
||||
|
||||
def GetExitCodeProcess(hProcess: HANDLE, lpExitCode: ULONG | t.CPtr) -> BOOL | t.State: pass
|
||||
|
||||
def GetExitCodeThread(hThread: HANDLE, lpExitCode: ULONG | t.CPtr) -> BOOL | t.State: pass
|
||||
|
||||
def OpenProcess(dwDesiredAccess: ULONG, bInheritHandle: BOOL, dwProcessId: ULONG) -> HANDLE | t.State: pass
|
||||
|
||||
def GetCurrentProcess() -> HANDLE | t.State: pass
|
||||
|
||||
def GetCurrentProcessId() -> ULONG | t.State: pass
|
||||
|
||||
def CreateThread(lpThreadAttributes: SECURITY_ATTRIBUTES | t.CPtr, dwStackSize: t.CSizeT, lpStartAddress: VOIDPTR, lpParameter: VOIDPTR, dwCreationFlags: ULONG, lpThreadId: ULONG | t.CPtr) -> HANDLE | t.State: pass
|
||||
|
||||
def OpenThread(dwDesiredAccess: ULONG, bInheritHandle: BOOL, dwThreadId: ULONG) -> HANDLE | t.State: pass
|
||||
|
||||
def SuspendThread(hThread: HANDLE) -> ULONG | t.State: pass
|
||||
|
||||
def ResumeThread(hThread: HANDLE) -> ULONG | t.State: pass
|
||||
|
||||
def TerminateThread(hThread: HANDLE, dwExitCode: ULONG) -> BOOL | t.State: pass
|
||||
|
||||
def GetCurrentThread() -> HANDLE | t.State: pass
|
||||
|
||||
def GetCurrentThreadId() -> ULONG | t.State: pass
|
||||
|
||||
def GetThreadId(hThread: HANDLE) -> ULONG | t.State: pass
|
||||
|
||||
def GetProcessId(hProcess: HANDLE) -> ULONG | t.State: pass
|
||||
|
||||
def SetThreadPriority(hThread: HANDLE, nPriority: INT) -> BOOL | t.State: pass
|
||||
|
||||
def GetThreadPriority(hThread: HANDLE) -> INT | t.State: pass
|
||||
|
||||
def ExitProcess(uExitCode: UINT) -> VOID | t.State: pass
|
||||
|
||||
def ExitThread(dwExitCode: ULONG) -> VOID | t.State: pass
|
||||
|
||||
def TlsAlloc() -> ULONG | t.State: pass
|
||||
|
||||
def TlsFree(dwTlsIndex: ULONG) -> BOOL | t.State: pass
|
||||
|
||||
def TlsGetValue(dwTlsIndex: ULONG) -> VOIDPTR | t.State: pass
|
||||
|
||||
def TlsSetValue(dwTlsIndex: ULONG, lpTlsValue: VOIDPTR) -> BOOL | t.State: pass
|
||||
85
Test/FuncTest/temp/29813d57621099a9.pyi
Normal file
85
Test/FuncTest/temp/29813d57621099a9.pyi
Normal file
@@ -0,0 +1,85 @@
|
||||
"""
|
||||
Auto-generated Python stub file from w32.win32sync.py
|
||||
Module: w32.win32sync
|
||||
"""
|
||||
|
||||
import c
|
||||
|
||||
|
||||
import t
|
||||
from stdint import *
|
||||
from w32.win32base import *
|
||||
|
||||
class CRITICAL_SECTION:
|
||||
DebugInfo: VOIDPTR
|
||||
LockCount: LONG
|
||||
RecursionCount: LONG
|
||||
OwningThread: HANDLE
|
||||
LockSemaphore: HANDLE
|
||||
SpinCount: QWORD
|
||||
|
||||
def InitializeCriticalSection(lpCriticalSection: CRITICAL_SECTION | t.CPtr) -> VOID | t.State: pass
|
||||
|
||||
def EnterCriticalSection(lpCriticalSection: CRITICAL_SECTION | t.CPtr) -> VOID | t.State: pass
|
||||
|
||||
def LeaveCriticalSection(lpCriticalSection: CRITICAL_SECTION | t.CPtr) -> VOID | t.State: pass
|
||||
|
||||
def DeleteCriticalSection(lpCriticalSection: CRITICAL_SECTION | t.CPtr) -> VOID | t.State: pass
|
||||
|
||||
def TryEnterCriticalSection(lpCriticalSection: CRITICAL_SECTION | t.CPtr) -> BOOL | t.State: pass
|
||||
|
||||
def SetCriticalSectionSpinCount(lpCriticalSection: CRITICAL_SECTION | t.CPtr, dwSpinCount: ULONG) -> ULONG | t.State: pass
|
||||
|
||||
def InitializeCriticalSectionAndSpinCount(lpCriticalSection: CRITICAL_SECTION | t.CPtr, dwSpinCount: ULONG) -> BOOL | t.State: pass
|
||||
|
||||
def CreateMutexA(lpMutexAttributes: SECURITY_ATTRIBUTES | t.CPtr, bInitialOwner: BOOL, lpName: LPCSTR) -> HANDLE | t.State: pass
|
||||
|
||||
def CreateMutexW(lpMutexAttributes: SECURITY_ATTRIBUTES | t.CPtr, bInitialOwner: BOOL, lpName: LPCWSTR) -> HANDLE | t.State: pass
|
||||
|
||||
def OpenMutexA(dwDesiredAccess: ULONG, bInheritHandle: BOOL, lpName: LPCSTR) -> HANDLE | t.State: pass
|
||||
|
||||
def OpenMutexW(dwDesiredAccess: ULONG, bInheritHandle: BOOL, lpName: LPCWSTR) -> HANDLE | t.State: pass
|
||||
|
||||
def ReleaseMutex(hMutex: HANDLE) -> BOOL | t.State: pass
|
||||
|
||||
def CreateEventA(lpEventAttributes: SECURITY_ATTRIBUTES | t.CPtr, bManualReset: BOOL, bInitialState: BOOL, lpName: LPCSTR) -> HANDLE | t.State: pass
|
||||
|
||||
def CreateEventW(lpEventAttributes: SECURITY_ATTRIBUTES | t.CPtr, bManualReset: BOOL, bInitialState: BOOL, lpName: LPCWSTR) -> HANDLE | t.State: pass
|
||||
|
||||
def OpenEventA(dwDesiredAccess: ULONG, bInheritHandle: BOOL, lpName: LPCSTR) -> HANDLE | t.State: pass
|
||||
|
||||
def OpenEventW(dwDesiredAccess: ULONG, bInheritHandle: BOOL, lpName: LPCWSTR) -> HANDLE | t.State: pass
|
||||
|
||||
def SetEvent(hEvent: HANDLE) -> BOOL | t.State: pass
|
||||
|
||||
def ResetEvent(hEvent: HANDLE) -> BOOL | t.State: pass
|
||||
|
||||
def PulseEvent(hEvent: HANDLE) -> BOOL | t.State: pass
|
||||
|
||||
def CreateSemaphoreA(lpSemaphoreAttributes: SECURITY_ATTRIBUTES | t.CPtr, lInitialCount: LONG, lMaximumCount: LONG, lpName: LPCSTR) -> HANDLE | t.State: pass
|
||||
|
||||
def CreateSemaphoreW(lpSemaphoreAttributes: SECURITY_ATTRIBUTES | t.CPtr, lInitialCount: LONG, lMaximumCount: LONG, lpName: LPCWSTR) -> HANDLE | t.State: pass
|
||||
|
||||
def OpenSemaphoreA(dwDesiredAccess: ULONG, bInheritHandle: BOOL, lpName: LPCSTR) -> HANDLE | t.State: pass
|
||||
|
||||
def OpenSemaphoreW(dwDesiredAccess: ULONG, bInheritHandle: BOOL, lpName: LPCWSTR) -> HANDLE | t.State: pass
|
||||
|
||||
def ReleaseSemaphore(hSemaphore: HANDLE, lReleaseCount: LONG, lpPreviousCount: LONG | t.CPtr) -> BOOL | t.State: pass
|
||||
|
||||
def WaitForSingleObject(hHandle: HANDLE, dwMilliseconds: ULONG) -> ULONG | t.State: pass
|
||||
|
||||
def WaitForSingleObjectEx(hHandle: HANDLE, dwMilliseconds: ULONG, bAlertable: BOOL) -> ULONG | t.State: pass
|
||||
|
||||
def WaitForMultipleObjects(nCount: ULONG, lpHandles: VOIDPTR, bWaitAll: BOOL, dwMilliseconds: ULONG) -> ULONG | t.State: pass
|
||||
|
||||
def WaitForMultipleObjectsEx(nCount: ULONG, lpHandles: VOIDPTR, bWaitAll: BOOL, dwMilliseconds: ULONG, bAlertable: BOOL) -> ULONG | t.State: pass
|
||||
|
||||
def InitializeSRWLock(SRWLock: VOIDPTR) -> VOID | t.State: pass
|
||||
|
||||
def AcquireSRWLockExclusive(SRWLock: VOIDPTR) -> VOID | t.State: pass
|
||||
|
||||
def AcquireSRWLockShared(SRWLock: VOIDPTR) -> VOID | t.State: pass
|
||||
|
||||
def ReleaseSRWLockExclusive(SRWLock: VOIDPTR) -> VOID | t.State: pass
|
||||
|
||||
def ReleaseSRWLockShared(SRWLock: VOIDPTR) -> VOID | t.State: pass
|
||||
67
Test/FuncTest/temp/56cdd754a8a09347.pyi
Normal file
67
Test/FuncTest/temp/56cdd754a8a09347.pyi
Normal file
@@ -0,0 +1,67 @@
|
||||
"""
|
||||
Auto-generated Python stub file from stdint.py
|
||||
Module: stdint
|
||||
"""
|
||||
|
||||
import c
|
||||
|
||||
|
||||
import t
|
||||
|
||||
INT: t.CTypedef = t.CInt
|
||||
INTPTR: t.CTypedef = t.CInt | t.CPtr
|
||||
BOOL: t.CTypedef = t.CInt
|
||||
UINT: t.CTypedef = t.CUnsignedInt
|
||||
UINTPTR: t.CTypedef = UINT | t.CPtr
|
||||
BYTE: t.CTypedef = t.CUnsignedChar
|
||||
BYTEPTR: t.CTypedef = BYTE | t.CPtr
|
||||
WORD: t.CTypedef = t.CUInt16T
|
||||
DWORD: t.CTypedef = t.CUInt32T
|
||||
QWORD: t.CTypedef = t.CUInt64T
|
||||
TCHAR: t.CTypedef = t.CChar
|
||||
CHARLIST: t.CTypedef = str | t.CPtr
|
||||
VOID: t.CTypedef = t.CVoid
|
||||
SHORT: t.CTypedef = t.CShort
|
||||
SHORTPTR: t.CTypedef = t.CShort | t.CPtr
|
||||
USHORT: t.CTypedef = t.CUnsignedShort
|
||||
USHORTPTR: t.CTypedef = t.CUnsignedShort | t.CPtr
|
||||
LONGLONG: t.CTypedef = t.CLong | t.CLong
|
||||
ULONGLONG: t.CTypedef = t.CUnsignedLong | t.CLong
|
||||
LONG: t.CTypedef = t.CLong
|
||||
ULONG: t.CTypedef = t.CUnsignedLong
|
||||
WCHAR: t.CTypedef = WORD
|
||||
WCHARPTR: t.CTypedef = WORD | t.CPtr
|
||||
CHARPTR: t.CTypedef = t.CChar | t.CPtr
|
||||
FSIZE_t: t.CTypedef = DWORD
|
||||
LBA_t: t.CTypedef = DWORD
|
||||
UINTPTR: t.CTypedef = t.CUnsignedInt | t.CPtr
|
||||
VOIDPTR: t.CTypedef = t.CVoid | t.CPtr
|
||||
FLOAT: t.CTypedef = t.CFloat
|
||||
DOUBLE: t.CTypedef = t.CDouble
|
||||
FLOAT8: t.CTypedef = t.CFloat8T
|
||||
FLOAT16: t.CTypedef = t.CFloat16T
|
||||
FLOAT32: t.CTypedef = t.CFloat32T
|
||||
FLOAT64: t.CTypedef = t.CFloat64T
|
||||
FLOAT128: t.CTypedef = t.CFloat128T
|
||||
INT8: t.CTypedef = t.CInt8T
|
||||
INT16: t.CTypedef = t.CInt16T
|
||||
INT32: t.CTypedef = t.CInt32T
|
||||
INT64: t.CTypedef = t.CInt64T
|
||||
UINT8: t.CTypedef = t.CUInt8T
|
||||
UINT16: t.CTypedef = t.CUInt16T
|
||||
UINT32: t.CTypedef = t.CUInt32T
|
||||
UINT64: t.CTypedef = t.CUInt64T
|
||||
INT8PTR: t.CTypedef = t.CInt8T | t.CPtr
|
||||
INT16PTR: t.CTypedef = t.CInt16T | t.CPtr
|
||||
INT32PTR: t.CTypedef = t.CInt32T | t.CPtr
|
||||
INT64PTR: t.CTypedef = t.CInt64T | t.CPtr
|
||||
UINT8PTR: t.CTypedef = t.CUInt8T | t.CPtr
|
||||
UINT16PTR: t.CTypedef = t.CUInt16T | t.CPtr
|
||||
UINT32PTR: t.CTypedef = t.CUInt32T | t.CPtr
|
||||
UINT64PTR: t.CTypedef = t.CUInt64T | t.CPtr
|
||||
CHAR8: t.CTypedef = t.CChar8T
|
||||
CHAR16: t.CTypedef = t.CChar16T
|
||||
CHAR32: t.CTypedef = t.CChar32T
|
||||
CHAR8PTR: t.CTypedef = t.CChar8T | t.CPtr
|
||||
CHAR16PTR: t.CTypedef = t.CChar16T | t.CPtr
|
||||
CHAR32PTR: t.CTypedef = t.CChar32T | t.CPtr
|
||||
98
Test/FuncTest/temp/5a6a2137958c28c5.pyi
Normal file
98
Test/FuncTest/temp/5a6a2137958c28c5.pyi
Normal file
@@ -0,0 +1,98 @@
|
||||
"""
|
||||
Auto-generated Python stub file from w32.win32base.py
|
||||
Module: w32.win32base
|
||||
"""
|
||||
|
||||
import c
|
||||
|
||||
|
||||
import t
|
||||
from stdint import *
|
||||
|
||||
HANDLE: t.CTypedef = VOIDPTR
|
||||
LPCSTR: t.CTypedef = t.CConst | t.CChar | t.CPtr
|
||||
LPCWSTR: t.CTypedef = t.CConst | t.CUnsignedShort | t.CPtr
|
||||
INVALID_HANDLE_VALUE: t.CDefine = t.CVoid(-1)
|
||||
NULL: t.CDefine = 0
|
||||
TRUE: t.CDefine = 1
|
||||
FALSE: t.CDefine = 0
|
||||
INFINITE: t.CDefine = 0xFFFFFFFF
|
||||
WAIT_FAILED: t.CDefine = 0xFFFFFFFF
|
||||
WAIT_OBJECT_0: t.CDefine = 0
|
||||
WAIT_TIMEOUT: t.CDefine = 258
|
||||
WAIT_ABANDONED: t.CDefine = 0x80
|
||||
MAX_PATH: t.CDefine = 260
|
||||
ERROR_SUCCESS: t.CDefine = 0
|
||||
ERROR_FILE_NOT_FOUND: t.CDefine = 2
|
||||
ERROR_ACCESS_DENIED: t.CDefine = 5
|
||||
ERROR_INSUFFICIENT_BUFFER: t.CDefine = 122
|
||||
|
||||
class SECURITY_ATTRIBUTES:
|
||||
nLength: ULONG
|
||||
lpSecurityDescriptor: VOIDPTR
|
||||
bInheritHandle: BOOL
|
||||
class OVERLAPPED:
|
||||
Internal: ULONGLONG
|
||||
InternalHigh: ULONGLONG
|
||||
Offset: ULONG
|
||||
OffsetHigh: ULONG
|
||||
hEvent: HANDLE
|
||||
class FILETIME:
|
||||
dwLowDateTime: DWORD
|
||||
dwHighDateTime: DWORD
|
||||
class SYSTEMTIME:
|
||||
wYear: WORD
|
||||
wMonth: WORD
|
||||
wDayOfWeek: WORD
|
||||
wDay: WORD
|
||||
wHour: WORD
|
||||
wMinute: WORD
|
||||
wSecond: WORD
|
||||
wMilliseconds: WORD
|
||||
class GUID:
|
||||
Data1: DWORD
|
||||
Data2: WORD
|
||||
Data3: WORD
|
||||
Data4: BYTEPTR
|
||||
class LARGE_INTEGER:
|
||||
QuadPart: LONGLONG
|
||||
class ULARGE_INTEGER:
|
||||
QuadPart: ULONGLONG
|
||||
|
||||
def GetLastError() -> ULONG | t.State: pass
|
||||
|
||||
def SetLastError(dwErrCode: ULONG) -> t.State: pass
|
||||
|
||||
def CloseHandle(hObject: HANDLE) -> BOOL | t.State: pass
|
||||
|
||||
def GetProcAddress(hModule: HANDLE, lpProcName: LPCSTR) -> VOIDPTR | t.State: pass
|
||||
|
||||
def GetModuleHandleA(lpModuleName: LPCSTR) -> HANDLE | t.State: pass
|
||||
|
||||
def GetModuleHandleW(lpModuleName: LPCWSTR) -> HANDLE | t.State: pass
|
||||
|
||||
def LoadLibraryA(lpLibFileName: LPCSTR) -> HANDLE | t.State: pass
|
||||
|
||||
def LoadLibraryW(lpLibFileName: LPCWSTR) -> HANDLE | t.State: pass
|
||||
|
||||
def FreeLibrary(hLibModule: HANDLE) -> BOOL | t.State: pass
|
||||
|
||||
def GetSystemTime(lpSystemTime: SYSTEMTIME | t.CPtr) -> t.State: pass
|
||||
|
||||
def GetLocalTime(lpSystemTime: SYSTEMTIME | t.CPtr) -> t.State: pass
|
||||
|
||||
def FileTimeToSystemTime(lpFileTime: FILETIME | t.CPtr, lpSystemTime: SYSTEMTIME | t.CPtr) -> BOOL | t.State: pass
|
||||
|
||||
def SystemTimeToFileTime(lpSystemTime: SYSTEMTIME | t.CPtr, lpFileTime: FILETIME | t.CPtr) -> BOOL | t.State: pass
|
||||
|
||||
def QueryPerformanceCounter(lpPerformanceCount: LARGE_INTEGER | t.CPtr) -> BOOL | t.State: pass
|
||||
|
||||
def QueryPerformanceFrequency(lpFrequency: LARGE_INTEGER | t.CPtr) -> BOOL | t.State: pass
|
||||
|
||||
def Sleep(dwMilliseconds: ULONG) -> t.State: pass
|
||||
|
||||
def SleepEx(dwMilliseconds: ULONG, bAlertable: BOOL) -> ULONG | t.State: pass
|
||||
|
||||
def GetTickCount() -> ULONG | t.State: pass
|
||||
|
||||
def GetTickCount64() -> ULONGLONG | t.State: pass
|
||||
91
Test/FuncTest/temp/72e2d5ccb7cedcf1.pyi
Normal file
91
Test/FuncTest/temp/72e2d5ccb7cedcf1.pyi
Normal file
@@ -0,0 +1,91 @@
|
||||
"""
|
||||
Auto-generated Python stub file from w32.win32memory.py
|
||||
Module: w32.win32memory
|
||||
"""
|
||||
|
||||
import c
|
||||
|
||||
|
||||
import t
|
||||
from stdint import *
|
||||
from w32.win32base import *
|
||||
|
||||
MEM_COMMIT: t.CDefine = 0x00001000
|
||||
MEM_RESERVE: t.CDefine = 0x00002000
|
||||
MEM_DECOMMIT: t.CDefine = 0x00004000
|
||||
MEM_RELEASE: t.CDefine = 0x00008000
|
||||
MEM_FREE: t.CDefine = 0x00010000
|
||||
MEM_RESET: t.CDefine = 0x00080000
|
||||
MEM_TOP_DOWN: t.CDefine = 0x00100000
|
||||
MEM_WRITE_WATCH: t.CDefine = 0x00200000
|
||||
MEM_PHYSICAL: t.CDefine = 0x00400000
|
||||
MEM_LARGE_PAGES: t.CDefine = 0x20000000
|
||||
PAGE_NOACCESS: t.CDefine = 0x01
|
||||
PAGE_READONLY: t.CDefine = 0x02
|
||||
PAGE_READWRITE: t.CDefine = 0x04
|
||||
PAGE_WRITECOPY: t.CDefine = 0x08
|
||||
PAGE_EXECUTE: t.CDefine = 0x10
|
||||
PAGE_EXECUTE_READ: t.CDefine = 0x20
|
||||
PAGE_EXECUTE_READWRITE: t.CDefine = 0x40
|
||||
PAGE_EXECUTE_WRITECOPY: t.CDefine = 0x80
|
||||
PAGE_GUARD: t.CDefine = 0x100
|
||||
PAGE_NOCACHE: t.CDefine = 0x200
|
||||
PAGE_WRITECOMBINE: t.CDefine = 0x400
|
||||
HEAP_NO_SERIALIZE: t.CDefine = 0x00000001
|
||||
HEAP_GROWABLE: t.CDefine = 0x00000002
|
||||
HEAP_GENERATE_EXCEPTIONS: t.CDefine = 0x00000004
|
||||
HEAP_ZERO_MEMORY: t.CDefine = 0x00000008
|
||||
HEAP_REALLOC_IN_PLACE_ONLY: t.CDefine = 0x00000010
|
||||
|
||||
class MEMORY_BASIC_INFORMATION:
|
||||
BaseAddress: VOIDPTR
|
||||
AllocationBase: VOIDPTR
|
||||
AllocationProtect: ULONG
|
||||
RegionSize: t.CSizeT
|
||||
State: ULONG
|
||||
Protect: ULONG
|
||||
Type: ULONG
|
||||
|
||||
def VirtualAlloc(lpAddress: VOIDPTR, dwSize: t.CSizeT, flAllocationType: ULONG, flProtect: ULONG) -> VOIDPTR | t.State: pass
|
||||
|
||||
def VirtualFree(lpAddress: VOIDPTR, dwSize: t.CSizeT, dwFreeType: ULONG) -> BOOL | t.State: pass
|
||||
|
||||
def VirtualProtect(lpAddress: VOIDPTR, dwSize: t.CSizeT, flNewProtect: ULONG, lpflOldProtect: ULONG | t.CPtr) -> BOOL | t.State: pass
|
||||
|
||||
def VirtualQuery(lpAddress: t.CConst | VOIDPTR, lpBuffer: MEMORY_BASIC_INFORMATION | t.CPtr, dwLength: t.CSizeT) -> t.CSizeT | t.State: pass
|
||||
|
||||
def VirtualLock(lpAddress: VOIDPTR, dwSize: t.CSizeT) -> BOOL | t.State: pass
|
||||
|
||||
def VirtualUnlock(lpAddress: VOIDPTR, dwSize: t.CSizeT) -> BOOL | t.State: pass
|
||||
|
||||
def GetProcessHeap() -> HANDLE | t.State: pass
|
||||
|
||||
def HeapCreate(flOptions: ULONG, dwInitialSize: t.CSizeT, dwMaximumSize: t.CSizeT) -> HANDLE | t.State: pass
|
||||
|
||||
def HeapDestroy(hHeap: HANDLE) -> BOOL | t.State: pass
|
||||
|
||||
def HeapAlloc(hHeap: HANDLE, dwFlags: ULONG, dwBytes: t.CSizeT) -> VOIDPTR | t.State: pass
|
||||
|
||||
def HeapReAlloc(hHeap: HANDLE, dwFlags: ULONG, lpMem: VOIDPTR, dwBytes: t.CSizeT) -> VOIDPTR | t.State: pass
|
||||
|
||||
def HeapFree(hHeap: HANDLE, dwFlags: ULONG, lpMem: VOIDPTR) -> BOOL | t.State: pass
|
||||
|
||||
def HeapSize(hHeap: HANDLE, dwFlags: ULONG, lpMem: t.CConst | VOIDPTR) -> t.CSizeT | t.State: pass
|
||||
|
||||
def HeapValidate(hHeap: HANDLE, dwFlags: ULONG, lpMem: t.CConst | VOIDPTR) -> BOOL | t.State: pass
|
||||
|
||||
def HeapCompact(hHeap: HANDLE, dwFlags: ULONG) -> t.CSizeT | t.State: pass
|
||||
|
||||
def GlobalAlloc(uFlags: UINT, dwBytes: t.CSizeT) -> VOIDPTR | t.State: pass
|
||||
|
||||
def GlobalFree(hMem: VOIDPTR) -> VOIDPTR | t.State: pass
|
||||
|
||||
def GlobalLock(hMem: VOIDPTR) -> VOIDPTR | t.State: pass
|
||||
|
||||
def GlobalUnlock(hMem: VOIDPTR) -> BOOL | t.State: pass
|
||||
|
||||
def GlobalSize(hMem: VOIDPTR) -> t.CSizeT | t.State: pass
|
||||
|
||||
def LocalAlloc(uFlags: UINT, dwBytes: t.CSizeT) -> VOIDPTR | t.State: pass
|
||||
|
||||
def LocalFree(hMem: VOIDPTR) -> VOIDPTR | t.State: pass
|
||||
28
Test/FuncTest/temp/73edbcf76e32d00b.pyi
Normal file
28
Test/FuncTest/temp/73edbcf76e32d00b.pyi
Normal file
@@ -0,0 +1,28 @@
|
||||
"""
|
||||
Auto-generated Python stub file from stdio.py
|
||||
Module: stdio
|
||||
"""
|
||||
|
||||
|
||||
import t, c
|
||||
|
||||
def printf(fmt: t.CChar | t.CConst | t.CPtr, *args) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def fprintf(stream: t.CVoid | t.CPtr, fmt: t.CChar | t.CConst | t.CPtr, *args) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def sprintf(buf: t.CChar | t.CPtr, fmt: t.CChar | t.CConst | t.CPtr, *args) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def snprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: t.CChar | t.CConst | t.CPtr, *args) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def puts(s: t.CChar | t.CConst | t.CPtr) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def fputs(s: t.CChar | t.CConst | t.CPtr, stream: t.CVoid | t.CPtr) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def fgets(buf: t.CChar | t.CPtr, size: t.CInt, stream: t.CVoid | t.CPtr) -> t.CChar | t.CPtr | t.CExtern | t.CExport: pass
|
||||
|
||||
def fflush(stream: t.CVoid | t.CPtr) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
|
||||
stdin: t.CExtern | t.CVoid | t.CPtr
|
||||
stdout: t.CExtern | t.CVoid | t.CPtr
|
||||
stderr: t.CExtern | t.CVoid | t.CPtr
|
||||
5
Test/FuncTest/temp/_sha1_map.txt
Normal file
5
Test/FuncTest/temp/_sha1_map.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
56cdd754a8a09347:includes/stdint.py
|
||||
5a6a2137958c28c5:includes/w32\win32base.py
|
||||
72e2d5ccb7cedcf1:includes/w32\win32memory.py
|
||||
73edbcf76e32d00b:includes/stdio.py
|
||||
d6f1d57732bde476:main.py
|
||||
179
Test/FuncTest/temp/abf9ce3160c9279e.pyi
Normal file
179
Test/FuncTest/temp/abf9ce3160c9279e.pyi
Normal file
@@ -0,0 +1,179 @@
|
||||
"""
|
||||
Auto-generated Python stub file from w32.win32file.py
|
||||
Module: w32.win32file
|
||||
"""
|
||||
|
||||
import c
|
||||
|
||||
|
||||
import t
|
||||
from stdint import *
|
||||
from w32.win32base import *
|
||||
|
||||
GENERIC_READ: t.CDefine = 0x80000000
|
||||
GENERIC_WRITE: t.CDefine = 0x40000000
|
||||
GENERIC_EXECUTE: t.CDefine = 0x20000000
|
||||
GENERIC_ALL: t.CDefine = 0x10000000
|
||||
FILE_SHARE_READ: t.CDefine = 0x00000001
|
||||
FILE_SHARE_WRITE: t.CDefine = 0x00000002
|
||||
FILE_SHARE_DELETE: t.CDefine = 0x00000004
|
||||
CREATE_NEW: t.CDefine = 1
|
||||
CREATE_ALWAYS: t.CDefine = 2
|
||||
OPEN_EXISTING: t.CDefine = 3
|
||||
OPEN_ALWAYS: t.CDefine = 4
|
||||
TRUNCATE_EXISTING: t.CDefine = 5
|
||||
FILE_ATTRIBUTE_READONLY: t.CDefine = 0x00000001
|
||||
FILE_ATTRIBUTE_HIDDEN: t.CDefine = 0x00000002
|
||||
FILE_ATTRIBUTE_SYSTEM: t.CDefine = 0x00000004
|
||||
FILE_ATTRIBUTE_DIRECTORY: t.CDefine = 0x00000010
|
||||
FILE_ATTRIBUTE_ARCHIVE: t.CDefine = 0x00000020
|
||||
FILE_ATTRIBUTE_NORMAL: t.CDefine = 0x00000080
|
||||
FILE_ATTRIBUTE_TEMPORARY: t.CDefine = 0x00000100
|
||||
FILE_ATTRIBUTE_COMPRESSED: t.CDefine = 0x00000800
|
||||
FILE_ATTRIBUTE_OFFLINE: t.CDefine = 0x00001000
|
||||
FILE_ATTRIBUTE_ENCRYPTED: t.CDefine = 0x00004000
|
||||
FILE_FLAG_WRITE_THROUGH: t.CDefine = 0x80000000
|
||||
FILE_FLAG_OVERLAPPED: t.CDefine = 0x40000000
|
||||
FILE_FLAG_NO_BUFFERING: t.CDefine = 0x20000000
|
||||
FILE_FLAG_RANDOM_ACCESS: t.CDefine = 0x10000000
|
||||
FILE_FLAG_SEQUENTIAL_SCAN: t.CDefine = 0x08000000
|
||||
FILE_FLAG_DELETE_ON_CLOSE: t.CDefine = 0x04000000
|
||||
FILE_FLAG_BACKUP_SEMANTICS: t.CDefine = 0x02000000
|
||||
FILE_FLAG_POSIX_SEMANTICS: t.CDefine = 0x01000000
|
||||
FILE_BEGIN: t.CDefine = 0
|
||||
FILE_CURRENT: t.CDefine = 1
|
||||
FILE_END: t.CDefine = 2
|
||||
STD_INPUT_HANDLE: t.CDefine = t.CUnsignedLong(-10)
|
||||
STD_OUTPUT_HANDLE: t.CDefine = t.CUnsignedLong(-11)
|
||||
STD_ERROR_HANDLE: t.CDefine = t.CUnsignedLong(-12)
|
||||
MOVEFILE_REPLACE_EXISTING: t.CDefine = 0x00000001
|
||||
MOVEFILE_COPY_ALLOWED: t.CDefine = 0x00000002
|
||||
MOVEFILE_WRITE_THROUGH: t.CDefine = 0x00000008
|
||||
|
||||
class BY_HANDLE_FILE_INFORMATION:
|
||||
dwFileAttributes: ULONG
|
||||
ftCreationTime: FILETIME
|
||||
ftLastAccessTime: FILETIME
|
||||
ftLastWriteTime: FILETIME
|
||||
dwVolumeSerialNumber: ULONG
|
||||
nFileSizeHigh: ULONG
|
||||
nFileSizeLow: ULONG
|
||||
nNumberOfLinks: ULONG
|
||||
nFileIndexHigh: ULONG
|
||||
nFileIndexLow: ULONG
|
||||
class WIN32_FIND_DATAA:
|
||||
dwFileAttributes: ULONG
|
||||
ftCreationTime: FILETIME
|
||||
ftLastAccessTime: FILETIME
|
||||
ftLastWriteTime: FILETIME
|
||||
nFileSizeHigh: ULONG
|
||||
nFileSizeLow: ULONG
|
||||
dwReserved0: ULONG
|
||||
dwReserved1: ULONG
|
||||
cFileName: CHARPTR
|
||||
cAlternateFileName: CHARPTR
|
||||
class WIN32_FIND_DATAW:
|
||||
dwFileAttributes: ULONG
|
||||
ftCreationTime: FILETIME
|
||||
ftLastAccessTime: FILETIME
|
||||
ftLastWriteTime: FILETIME
|
||||
nFileSizeHigh: ULONG
|
||||
nFileSizeLow: ULONG
|
||||
dwReserved0: ULONG
|
||||
dwReserved1: ULONG
|
||||
cFileName: WCHARPTR
|
||||
cAlternateFileName: WCHARPTR
|
||||
|
||||
def CreateFileA(lpFileName: LPCSTR, dwDesiredAccess: ULONG, dwShareMode: ULONG, lpSecurityAttributes: SECURITY_ATTRIBUTES | t.CPtr, dwCreationDisposition: ULONG, dwFlagsAndAttributes: ULONG, hTemplateFile: HANDLE) -> HANDLE | t.State: pass
|
||||
|
||||
def CreateFileW(lpFileName: LPCWSTR, dwDesiredAccess: ULONG, dwShareMode: ULONG, lpSecurityAttributes: SECURITY_ATTRIBUTES | t.CPtr, dwCreationDisposition: ULONG, dwFlagsAndAttributes: ULONG, hTemplateFile: HANDLE) -> HANDLE | t.State: pass
|
||||
|
||||
def ReadFile(hFile: HANDLE, lpBuffer: VOIDPTR, nNumberOfBytesToRead: ULONG, lpNumberOfBytesRead: ULONG | t.CPtr, lpOverlapped: OVERLAPPED | t.CPtr) -> BOOL | t.State: pass
|
||||
|
||||
def WriteFile(hFile: HANDLE, lpBuffer: t.CConst | VOIDPTR, nNumberOfBytesToWrite: ULONG, lpNumberOfBytesWritten: ULONG | t.CPtr, lpOverlapped: OVERLAPPED | t.CPtr) -> BOOL | t.State: pass
|
||||
|
||||
def SetFilePointer(hFile: HANDLE, lDistanceToMove: LONG, lpDistanceToMoveHigh: LONG | t.CPtr, dwMoveMethod: ULONG) -> LONG | t.State: pass
|
||||
|
||||
def SetFilePointerEx(hFile: HANDLE, liDistanceToMove: LARGE_INTEGER | t.CPtr, lpNewFilePointer: LARGE_INTEGER | t.CPtr, dwMoveMethod: ULONG) -> BOOL | t.State: pass
|
||||
|
||||
def GetFileSize(hFile: HANDLE, lpFileSizeHigh: ULONG | t.CPtr) -> ULONG | t.State: pass
|
||||
|
||||
def GetFileSizeEx(hFile: HANDLE, lpFileSize: LARGE_INTEGER | t.CPtr) -> BOOL | t.State: pass
|
||||
|
||||
def SetEndOfFile(hFile: HANDLE) -> BOOL | t.State: pass
|
||||
|
||||
def FlushFileBuffers(hFile: HANDLE) -> BOOL | t.State: pass
|
||||
|
||||
def GetFileType(hFile: HANDLE) -> ULONG | t.State: pass
|
||||
|
||||
def GetFileAttributesA(lpFileName: LPCSTR) -> ULONG | t.State: pass
|
||||
|
||||
def GetFileAttributesW(lpFileName: LPCWSTR) -> ULONG | t.State: pass
|
||||
|
||||
def SetFileAttributesA(lpFileName: LPCSTR, dwFileAttributes: ULONG) -> BOOL | t.State: pass
|
||||
|
||||
def SetFileAttributesW(lpFileName: LPCWSTR, dwFileAttributes: ULONG) -> BOOL | t.State: pass
|
||||
|
||||
def DeleteFileA(lpFileName: LPCSTR) -> BOOL | t.State: pass
|
||||
|
||||
def DeleteFileW(lpFileName: LPCWSTR) -> BOOL | t.State: pass
|
||||
|
||||
def MoveFileA(lpExistingFileName: LPCSTR, lpNewFileName: LPCSTR) -> BOOL | t.State: pass
|
||||
|
||||
def MoveFileW(lpExistingFileName: LPCWSTR, lpNewFileName: LPCWSTR) -> BOOL | t.State: pass
|
||||
|
||||
def MoveFileExA(lpExistingFileName: LPCSTR, lpNewFileName: LPCSTR, dwFlags: ULONG) -> BOOL | t.State: pass
|
||||
|
||||
def MoveFileExW(lpExistingFileName: LPCWSTR, lpNewFileName: LPCWSTR, dwFlags: ULONG) -> BOOL | t.State: pass
|
||||
|
||||
def CopyFileA(lpExistingFileName: LPCSTR, lpNewFileName: LPCSTR, bFailIfExists: BOOL) -> BOOL | t.State: pass
|
||||
|
||||
def CopyFileW(lpExistingFileName: LPCWSTR, lpNewFileName: LPCWSTR, bFailIfExists: BOOL) -> BOOL | t.State: pass
|
||||
|
||||
def CreateDirectoryA(lpPathName: LPCSTR, lpSecurityAttributes: SECURITY_ATTRIBUTES | t.CPtr) -> BOOL | t.State: pass
|
||||
|
||||
def CreateDirectoryW(lpPathName: LPCWSTR, lpSecurityAttributes: SECURITY_ATTRIBUTES | t.CPtr) -> BOOL | t.State: pass
|
||||
|
||||
def RemoveDirectoryA(lpPathName: LPCSTR) -> BOOL | t.State: pass
|
||||
|
||||
def RemoveDirectoryW(lpPathName: LPCWSTR) -> BOOL | t.State: pass
|
||||
|
||||
def FindFirstFileA(lpFileName: LPCSTR, lpFindFileData: WIN32_FIND_DATAA | t.CPtr) -> HANDLE | t.State: pass
|
||||
|
||||
def FindFirstFileW(lpFileName: LPCWSTR, lpFindFileData: WIN32_FIND_DATAW | t.CPtr) -> HANDLE | t.State: pass
|
||||
|
||||
def FindNextFileA(hFindFile: HANDLE, lpFindFileData: WIN32_FIND_DATAA | t.CPtr) -> BOOL | t.State: pass
|
||||
|
||||
def FindNextFileW(hFindFile: HANDLE, lpFindFileData: WIN32_FIND_DATAW | t.CPtr) -> BOOL | t.State: pass
|
||||
|
||||
def FindClose(hFindFile: HANDLE) -> BOOL | t.State: pass
|
||||
|
||||
def GetStdHandle(nStdHandle: ULONG) -> HANDLE | t.State: pass
|
||||
|
||||
def SetStdHandle(nStdHandle: ULONG, hHandle: HANDLE) -> BOOL | t.State: pass
|
||||
|
||||
def GetFileInformationByHandle(hFile: HANDLE, lpFileInformation: BY_HANDLE_FILE_INFORMATION | t.CPtr) -> BOOL | t.State: pass
|
||||
|
||||
def LockFile(hFile: HANDLE, dwFileOffsetLow: ULONG, dwFileOffsetHigh: ULONG, nNumberOfBytesToLockLow: ULONG, nNumberOfBytesToLockHigh: ULONG) -> BOOL | t.State: pass
|
||||
|
||||
def UnlockFile(hFile: HANDLE, dwFileOffsetLow: ULONG, dwFileOffsetHigh: ULONG, nNumberOfBytesToUnlockLow: ULONG, nNumberOfBytesToUnlockHigh: ULONG) -> BOOL | t.State: pass
|
||||
|
||||
def GetTempPathA(nBufferLength: ULONG, lpBuffer: CHARPTR) -> ULONG | t.State: pass
|
||||
|
||||
def GetTempPathW(nBufferLength: ULONG, lpBuffer: WCHARPTR) -> ULONG | t.State: pass
|
||||
|
||||
def GetTempFileNameA(lpPathName: LPCSTR, lpPrefixString: LPCSTR, uUnique: UINT, lpTempFileName: CHARPTR) -> UINT | t.State: pass
|
||||
|
||||
def GetTempFileNameW(lpPathName: LPCWSTR, lpPrefixString: LPCWSTR, uUnique: UINT, lpTempFileName: WCHARPTR) -> UINT | t.State: pass
|
||||
|
||||
def GetCurrentDirectoryA(nBufferLength: ULONG, lpBuffer: CHARPTR) -> ULONG | t.State: pass
|
||||
|
||||
def GetCurrentDirectoryW(nBufferLength: ULONG, lpBuffer: WCHARPTR) -> ULONG | t.State: pass
|
||||
|
||||
def SetCurrentDirectoryA(lpPathName: LPCSTR) -> BOOL | t.State: pass
|
||||
|
||||
def SetCurrentDirectoryW(lpPathName: LPCWSTR) -> BOOL | t.State: pass
|
||||
|
||||
def GetModuleFileNameA(hModule: HANDLE, lpFilename: CHARPTR, nSize: ULONG) -> ULONG | t.State: pass
|
||||
|
||||
def GetModuleFileNameW(hModule: HANDLE, lpFilename: WCHARPTR, nSize: ULONG) -> ULONG | t.State: pass
|
||||
138
Test/FuncTest/temp/bbdf3bbd4c3bc28c.pyi
Normal file
138
Test/FuncTest/temp/bbdf3bbd4c3bc28c.pyi
Normal file
@@ -0,0 +1,138 @@
|
||||
"""
|
||||
Auto-generated Python stub file from w32.win32console.py
|
||||
Module: w32.win32console
|
||||
"""
|
||||
|
||||
import c
|
||||
|
||||
|
||||
import t
|
||||
from stdint import *
|
||||
from w32.win32base import *
|
||||
|
||||
ENABLE_PROCESSED_INPUT: t.CDefine = 0x0001
|
||||
ENABLE_LINE_INPUT: t.CDefine = 0x0002
|
||||
ENABLE_ECHO_INPUT: t.CDefine = 0x0004
|
||||
ENABLE_WINDOW_INPUT: t.CDefine = 0x0008
|
||||
ENABLE_MOUSE_INPUT: t.CDefine = 0x0010
|
||||
ENABLE_INSERT_MODE: t.CDefine = 0x0020
|
||||
ENABLE_QUICK_EDIT_MODE: t.CDefine = 0x0040
|
||||
ENABLE_EXTENDED_FLAGS: t.CDefine = 0x0080
|
||||
ENABLE_PROCESSED_OUTPUT: t.CDefine = 0x0001
|
||||
ENABLE_WRAP_AT_EOL_OUTPUT: t.CDefine = 0x0002
|
||||
ENABLE_VIRTUAL_TERMINAL_PROCESSING: t.CDefine = 0x0004
|
||||
DISABLE_NEWLINE_AUTO_RETURN: t.CDefine = 0x0008
|
||||
ENABLE_LVB_GRID_WORLDWIDE: t.CDefine = 0x0010
|
||||
FOREGROUND_BLUE: t.CDefine = 0x0001
|
||||
FOREGROUND_GREEN: t.CDefine = 0x0002
|
||||
FOREGROUND_RED: t.CDefine = 0x0004
|
||||
FOREGROUND_INTENSITY: t.CDefine = 0x0008
|
||||
BACKGROUND_BLUE: t.CDefine = 0x0010
|
||||
BACKGROUND_GREEN: t.CDefine = 0x0020
|
||||
BACKGROUND_RED: t.CDefine = 0x0040
|
||||
BACKGROUND_INTENSITY: t.CDefine = 0x0080
|
||||
KEY_EVENT: t.CDefine = 0x0001
|
||||
MOUSE_EVENT: t.CDefine = 0x0002
|
||||
WINDOW_BUFFER_SIZE_EVENT: t.CDefine = 0x0004
|
||||
MENU_EVENT: t.CDefine = 0x0008
|
||||
FOCUS_EVENT: t.CDefine = 0x0010
|
||||
|
||||
class COORD:
|
||||
X: SHORT
|
||||
Y: SHORT
|
||||
class SMALL_RECT:
|
||||
Left: SHORT
|
||||
Top: SHORT
|
||||
Right: SHORT
|
||||
Bottom: SHORT
|
||||
class CONSOLE_SCREEN_BUFFER_INFO:
|
||||
dwSize: COORD
|
||||
dwCursorPosition: COORD
|
||||
wAttributes: WORD
|
||||
srWindow: SMALL_RECT
|
||||
dwMaximumWindowSize: COORD
|
||||
class CONSOLE_CURSOR_INFO:
|
||||
dwSize: ULONG
|
||||
bVisible: BOOL
|
||||
class CHAR_INFO:
|
||||
UnicodeChar: WCHAR
|
||||
Attributes: WORD
|
||||
class KEY_EVENT_RECORD:
|
||||
bKeyDown: BOOL
|
||||
wRepeatCount: WORD
|
||||
wVirtualKeyCode: WORD
|
||||
wVirtualScanCode: WORD
|
||||
uChar: WCHAR
|
||||
dwControlKeyState: ULONG
|
||||
class MOUSE_EVENT_RECORD:
|
||||
dwMousePosition: COORD
|
||||
dwButtonState: ULONG
|
||||
dwControlKeyState: ULONG
|
||||
dwEventFlags: ULONG
|
||||
class WINDOW_BUFFER_SIZE_RECORD:
|
||||
dwSize: COORD
|
||||
class INPUT_RECORD:
|
||||
EventType: WORD
|
||||
Event: KEY_EVENT_RECORD
|
||||
|
||||
def SetConsoleOutputCP(codepage: UINT) -> BOOL | t.State: pass
|
||||
|
||||
def SetConsoleCP(codepage: UINT) -> BOOL | t.State: pass
|
||||
|
||||
def GetConsoleCP() -> UINT | t.State: pass
|
||||
|
||||
def GetConsoleOutputCP() -> UINT | t.State: pass
|
||||
|
||||
def GetConsoleScreenBufferInfo(hConsoleOutput: HANDLE, lpConsoleScreenBufferInfo: CONSOLE_SCREEN_BUFFER_INFO | t.CPtr) -> BOOL | t.State: pass
|
||||
|
||||
def SetConsoleScreenBufferSize(hConsoleOutput: HANDLE, dwSize: COORD) -> BOOL | t.State: pass
|
||||
|
||||
def SetConsoleCursorPosition(hConsoleOutput: HANDLE, dwCursorPosition: COORD) -> BOOL | t.State: pass
|
||||
|
||||
def GetConsoleCursorInfo(hConsoleOutput: HANDLE, lpConsoleCursorInfo: CONSOLE_CURSOR_INFO | t.CPtr) -> BOOL | t.State: pass
|
||||
|
||||
def SetConsoleCursorInfo(hConsoleOutput: HANDLE, lpConsoleCursorInfo: CONSOLE_CURSOR_INFO | t.CPtr) -> BOOL | t.State: pass
|
||||
|
||||
def SetConsoleTextAttribute(hConsoleOutput: HANDLE, wAttributes: WORD) -> BOOL | t.State: pass
|
||||
|
||||
def FillConsoleOutputCharacterA(hConsoleOutput: HANDLE, cCharacter: t.CChar, nLength: ULONG, dwWriteCoord: COORD, lpNumberOfCharsWritten: ULONG | t.CPtr) -> BOOL | t.State: pass
|
||||
|
||||
def FillConsoleOutputCharacterW(hConsoleOutput: HANDLE, cCharacter: WCHAR, nLength: ULONG, dwWriteCoord: COORD, lpNumberOfCharsWritten: ULONG | t.CPtr) -> BOOL | t.State: pass
|
||||
|
||||
def FillConsoleOutputAttribute(hConsoleOutput: HANDLE, wAttribute: WORD, nLength: ULONG, dwWriteCoord: COORD, lpNumberOfAttrsWritten: ULONG | t.CPtr) -> BOOL | t.State: pass
|
||||
|
||||
def WriteConsoleA(hConsoleOutput: HANDLE, lpBuffer: t.CConst | VOIDPTR, nNumberOfCharsToWrite: ULONG, lpNumberOfCharsWritten: ULONG | t.CPtr, lpReserved: VOIDPTR) -> BOOL | t.State: pass
|
||||
|
||||
def WriteConsoleW(hConsoleOutput: HANDLE, lpBuffer: t.CConst | VOIDPTR, nNumberOfCharsToWrite: ULONG, lpNumberOfCharsWritten: ULONG | t.CPtr, lpReserved: VOIDPTR) -> BOOL | t.State: pass
|
||||
|
||||
def ReadConsoleA(hConsoleInput: HANDLE, lpBuffer: VOIDPTR, nNumberOfCharsToRead: ULONG, lpNumberOfCharsRead: ULONG | t.CPtr, pInputControl: VOIDPTR) -> BOOL | t.State: pass
|
||||
|
||||
def ReadConsoleW(hConsoleInput: HANDLE, lpBuffer: VOIDPTR, nNumberOfCharsToRead: ULONG, lpNumberOfCharsRead: ULONG | t.CPtr, pInputControl: VOIDPTR) -> BOOL | t.State: pass
|
||||
|
||||
def GetConsoleMode(hConsoleHandle: HANDLE, lpMode: ULONG | t.CPtr) -> BOOL | t.State: pass
|
||||
|
||||
def SetConsoleMode(hConsoleHandle: HANDLE, dwMode: ULONG) -> BOOL | t.State: pass
|
||||
|
||||
def ReadConsoleInputA(hConsoleInput: HANDLE, lpBuffer: INPUT_RECORD | t.CPtr, nLength: ULONG, lpNumberOfEventsRead: ULONG | t.CPtr) -> BOOL | t.State: pass
|
||||
|
||||
def ReadConsoleInputW(hConsoleInput: HANDLE, lpBuffer: INPUT_RECORD | t.CPtr, nLength: ULONG, lpNumberOfEventsRead: ULONG | t.CPtr) -> BOOL | t.State: pass
|
||||
|
||||
def GetNumberOfConsoleInputEvents(hConsoleInput: HANDLE, lpNumberOfEvents: ULONG | t.CPtr) -> BOOL | t.State: pass
|
||||
|
||||
def FlushConsoleInputBuffer(hConsoleInput: HANDLE) -> BOOL | t.State: pass
|
||||
|
||||
def SetConsoleTitleA(lpConsoleTitle: LPCSTR) -> BOOL | t.State: pass
|
||||
|
||||
def SetConsoleTitleW(lpConsoleTitle: LPCWSTR) -> BOOL | t.State: pass
|
||||
|
||||
def GetConsoleTitleA(lpConsoleTitle: CHARPTR, nSize: ULONG) -> ULONG | t.State: pass
|
||||
|
||||
def GetConsoleTitleW(lpConsoleTitle: WCHARPTR, nSize: ULONG) -> ULONG | t.State: pass
|
||||
|
||||
def AllocConsole() -> BOOL | t.State: pass
|
||||
|
||||
def FreeConsole() -> BOOL | t.State: pass
|
||||
|
||||
def SetConsoleWindowInfo(hConsoleOutput: HANDLE, bAbsolute: BOOL, lpConsoleWindow: SMALL_RECT | t.CPtr) -> BOOL | t.State: pass
|
||||
|
||||
def ScrollConsoleScreenBufferA(hConsoleOutput: HANDLE, lpScrollRectangle: SMALL_RECT | t.CPtr, lpClipRectangle: SMALL_RECT | t.CPtr, dwDestinationOrigin: COORD, lpFill: CHAR_INFO | t.CPtr) -> BOOL | t.State: pass
|
||||
47
Test/FuncTest/temp/d6f1d57732bde476.pyi
Normal file
47
Test/FuncTest/temp/d6f1d57732bde476.pyi
Normal file
@@ -0,0 +1,47 @@
|
||||
"""
|
||||
Auto-generated Python stub file from main.py
|
||||
Module: main
|
||||
"""
|
||||
|
||||
import c
|
||||
|
||||
|
||||
import t
|
||||
import stdio
|
||||
|
||||
def add(a: t.CInt, b: t.CInt) -> t.CInt: pass
|
||||
|
||||
def sub(a: t.CInt, b: t.CInt) -> t.CInt: pass
|
||||
|
||||
def multi_args(a: t.CInt, b: t.CInt, c: t.CInt, d: t.CInt) -> t.CInt: pass
|
||||
|
||||
def factorial(n: t.CInt) -> t.CInt: pass
|
||||
|
||||
def fib(n: t.CInt) -> t.CInt: pass
|
||||
|
||||
def add_via_ptr(p: t.CInt | t.CPtr, val: t.CInt) -> t.CInt: pass
|
||||
|
||||
def make_u64() -> t.CUInt64T: pass
|
||||
|
||||
def is_even(n: t.CInt) -> t.CBool: pass
|
||||
|
||||
def test_basic_call() -> t.CInt: pass
|
||||
|
||||
def test_multi_args() -> t.CInt: pass
|
||||
|
||||
def test_recursion() -> t.CInt: pass
|
||||
|
||||
def test_fibonacci() -> t.CInt: pass
|
||||
|
||||
def test_ptr_param() -> t.CInt: pass
|
||||
|
||||
def test_u64_return() -> t.CInt: pass
|
||||
|
||||
def test_bool_return() -> t.CInt: pass
|
||||
|
||||
def test_nested_call() -> t.CInt: pass
|
||||
|
||||
|
||||
import w32.win32memory
|
||||
|
||||
def main() -> t.CInt: pass
|
||||
80
Test/FuncTest/temp/fa3691e66b426950.pyi
Normal file
80
Test/FuncTest/temp/fa3691e66b426950.pyi
Normal file
@@ -0,0 +1,80 @@
|
||||
"""
|
||||
Auto-generated Python stub file from w32.fileio.py
|
||||
Module: w32.fileio
|
||||
"""
|
||||
|
||||
|
||||
import t, c
|
||||
from stdint import *
|
||||
import w32.win32base
|
||||
import w32.win32file
|
||||
|
||||
class MODE(t.CEnum):
|
||||
R = 0
|
||||
W = 1
|
||||
A = 2
|
||||
RP = 3
|
||||
WP = 4
|
||||
AP = 5
|
||||
X = 6
|
||||
XP = 7
|
||||
class FRESULT(t.CEnum):
|
||||
OK = 0
|
||||
ERR = -1
|
||||
ERR_CLOSED = -2
|
||||
ERR_PERM = -3
|
||||
ERR_IO = -4
|
||||
ERR_NOTFOUND = -5
|
||||
|
||||
SEEK_SET: t.CDefine = 0
|
||||
SEEK_CUR: t.CDefine = 1
|
||||
SEEK_END: t.CDefine = 2
|
||||
INVALID_SET_FILE_POINTER: t.CDefine = -1
|
||||
SHARE_READ: t.CDefine = 0x00000001
|
||||
SHARE_WRITE: t.CDefine = 0x00000002
|
||||
SHARE_DELETE: t.CDefine = 0x00000004
|
||||
|
||||
class File:
|
||||
handle: w32.win32base.HANDLE
|
||||
closed: bool
|
||||
can_read: bool
|
||||
can_write: bool
|
||||
is_append: bool
|
||||
_share_mode: ULONG
|
||||
def __init__(self: File, filename: str, mode: ULONG, share: ULONG) -> t.CInt: pass
|
||||
def __enter__(self: File) -> 'File' | t.CPtr: pass
|
||||
def __exit__(self: File) -> t.CInt: pass
|
||||
def read(self: File, buf: bytes, count: ULONG) -> LONG: pass
|
||||
def write(self: File, buf: bytes, count: ULONG) -> LONG: pass
|
||||
def write_str(self: File, s: str) -> LONG: pass
|
||||
def seek(self: File, offset: LONG, origin: ULONG) -> LONG: pass
|
||||
def tell(self: File) -> LONG: pass
|
||||
def close(self: File) -> LONG: pass
|
||||
def flush(self: File) -> LONG: pass
|
||||
def size(self: File) -> LONGLONG: pass
|
||||
def readline(self: File, buf: bytes, max_count: ULONG) -> LONG: pass
|
||||
def read_all(self: File, buf: bytes, max_count: ULONG) -> LONG: pass
|
||||
class FileW:
|
||||
handle: HANDLE
|
||||
closed: bool
|
||||
can_read: bool
|
||||
can_write: bool
|
||||
is_append: bool
|
||||
_share_mode: ULONG
|
||||
def __init__(self: FileW, filename: LPCWSTR, mode: ULONG, share: ULONG) -> t.CInt: pass
|
||||
def __enter__(self: FileW) -> 'FileW' | t.CPtr: pass
|
||||
def __exit__(self: FileW) -> t.CInt: pass
|
||||
def read(self: FileW, buf: bytes, count: ULONG) -> LONG: pass
|
||||
def write(self: FileW, buf: bytes, count: ULONG) -> LONG: pass
|
||||
def write_str(self: FileW, s: str) -> LONG: pass
|
||||
def seek(self: FileW, offset: LONG, origin: ULONG) -> LONG: pass
|
||||
def tell(self: FileW) -> LONG: pass
|
||||
def close(self: FileW) -> LONG: pass
|
||||
def flush(self: FileW) -> LONG: pass
|
||||
def size(self: FileW) -> LONGLONG: pass
|
||||
def readline(self: FileW, buf: bytes, max_count: ULONG) -> LONG: pass
|
||||
def read_all(self: FileW, buf: bytes, max_count: ULONG) -> LONG: pass
|
||||
|
||||
def open(filename: str, mode: ULONG, share: ULONG) -> File | t.CPtr: pass
|
||||
|
||||
def openw(filename: LPCWSTR, mode: ULONG, share: ULONG) -> FileW | t.CPtr: pass
|
||||
197
Test/GenericTest/App/main.py
Normal file
197
Test/GenericTest/App/main.py
Normal file
@@ -0,0 +1,197 @@
|
||||
import t
|
||||
import stdio
|
||||
|
||||
# ============================================================
|
||||
# Test 1: 泛型函数 - 基本加法
|
||||
# ============================================================
|
||||
def add[T](a: T, b: T) -> T:
|
||||
return a + b
|
||||
|
||||
def test_generic_add():
|
||||
stdio.printf("--- Test 1: generic add ---\n")
|
||||
r1: t.CInt = add(3, 5)
|
||||
r2: t.CInt = add(100, 200)
|
||||
if r1 == 8 and r2 == 300:
|
||||
stdio.printf("PASS: generic add (3+5=%d, 100+200=%d)\n", r1, r2)
|
||||
else:
|
||||
stdio.printf("FAIL: generic add (3+5=%d, 100+200=%d)\n", r1, r2)
|
||||
|
||||
# ============================================================
|
||||
# Test 2: 泛型函数 - 多类型参数
|
||||
# ============================================================
|
||||
def combine[T1, T2](a: T1, b: T2) -> T1:
|
||||
return a + T1(b)
|
||||
|
||||
def test_generic_combine():
|
||||
stdio.printf("--- Test 2: generic combine ---\n")
|
||||
r: t.CInt = combine(10, 20)
|
||||
if r == 30:
|
||||
stdio.printf("PASS: generic combine (10+T1(20)=%d)\n", r)
|
||||
else:
|
||||
stdio.printf("FAIL: generic combine (result=%d, expect 30)\n", r)
|
||||
|
||||
# ============================================================
|
||||
# Test 3: 泛型函数 - 最大值
|
||||
# ============================================================
|
||||
def max_val[T](a: T, b: T) -> T:
|
||||
if a > b:
|
||||
return a
|
||||
return b
|
||||
|
||||
def test_generic_max():
|
||||
stdio.printf("--- Test 3: generic max ---\n")
|
||||
r1: t.CInt = max_val(10, 20)
|
||||
r2: t.CInt = max_val(50, 30)
|
||||
if r1 == 20 and r2 == 50:
|
||||
stdio.printf("PASS: generic max (max(10,20)=%d, max(50,30)=%d)\n", r1, r2)
|
||||
else:
|
||||
stdio.printf("FAIL: generic max (max(10,20)=%d, max(50,30)=%d)\n", r1, r2)
|
||||
|
||||
# ============================================================
|
||||
# Test 4: 泛型类 - Box[T]
|
||||
# ============================================================
|
||||
class Box[T]():
|
||||
value: T
|
||||
|
||||
def __init__(self, v: T):
|
||||
self.value = T(v)
|
||||
|
||||
def get(self) -> T:
|
||||
return self.value
|
||||
|
||||
def set(self, v: T):
|
||||
self.value = T(v)
|
||||
|
||||
def test_generic_box():
|
||||
stdio.printf("--- Test 4: generic Box[T] ---\n")
|
||||
b = Box(42)
|
||||
v: t.CInt = b.get()
|
||||
if v == 42:
|
||||
stdio.printf("PASS: Box[int] (get=%d)\n", v)
|
||||
else:
|
||||
stdio.printf("FAIL: Box[int] (get=%d, expect 42)\n", v)
|
||||
|
||||
# ============================================================
|
||||
# Test 5: 泛型类 - Pair[T1, T2]
|
||||
# ============================================================
|
||||
class Pair[T1, T2]():
|
||||
first: T1
|
||||
second: T2
|
||||
|
||||
def __init__(self, a: T1, b: T2):
|
||||
self.first = T1(a)
|
||||
self.second = T2(b)
|
||||
|
||||
def sum_as_int(self) -> t.CInt:
|
||||
return t.CInt(self.first) + t.CInt(self.second)
|
||||
|
||||
def test_generic_pair():
|
||||
stdio.printf("--- Test 5: generic Pair[T1,T2] ---\n")
|
||||
p = Pair(10, 20)
|
||||
r: t.CInt = p.sum_as_int()
|
||||
if r == 30:
|
||||
stdio.printf("PASS: Pair[int,int] (sum=%d)\n", r)
|
||||
else:
|
||||
stdio.printf("FAIL: Pair[int,int] (sum=%d, expect 30)\n", r)
|
||||
|
||||
# ============================================================
|
||||
# Test 6: list[T, N] 固定数组
|
||||
# ============================================================
|
||||
def test_fixed_array():
|
||||
stdio.printf("--- Test 6: list[T, N] fixed array ---\n")
|
||||
arr: list[t.CInt, 5] = [0]
|
||||
for i in range(5):
|
||||
arr[i] = i * 10
|
||||
total: t.CInt = 0
|
||||
for i in range(5):
|
||||
total += arr[i]
|
||||
# 0+10+20+30+40 = 100
|
||||
if total == 100:
|
||||
stdio.printf("PASS: fixed array (total=%d)\n", total)
|
||||
else:
|
||||
stdio.printf("FAIL: fixed array (total=%d, expect 100)\n", total)
|
||||
|
||||
# ============================================================
|
||||
# Test 7: list[t.CChar, N] 字符数组
|
||||
# ============================================================
|
||||
def test_char_array():
|
||||
stdio.printf("--- Test 7: list[t.CChar, N] char array ---\n")
|
||||
buf: list[t.CChar, 32] = [0]
|
||||
buf[0] = 72 # H
|
||||
buf[1] = 105 # i
|
||||
buf[2] = 0
|
||||
if buf[0] == 72 and buf[1] == 105:
|
||||
stdio.printf("PASS: char array (H=%d i=%d)\n", buf[0], buf[1])
|
||||
else:
|
||||
stdio.printf("FAIL: char array (H=%d i=%d)\n", buf[0], buf[1])
|
||||
|
||||
# ============================================================
|
||||
# Test 8: 泛型函数多次特化
|
||||
# ============================================================
|
||||
def identity[T](x: T) -> T:
|
||||
return x
|
||||
|
||||
def test_generic_identity():
|
||||
stdio.printf("--- Test 8: generic identity ---\n")
|
||||
r1: t.CInt = identity(42)
|
||||
r2: t.CInt = identity(0)
|
||||
if r1 == 42 and r2 == 0:
|
||||
stdio.printf("PASS: identity (42=%d, 0=%d)\n", r1, r2)
|
||||
else:
|
||||
stdio.printf("FAIL: identity (42=%d, 0=%d)\n", r1, r2)
|
||||
|
||||
# ============================================================
|
||||
# Test 9: 泛型函数嵌套调用
|
||||
# ============================================================
|
||||
def double_val[T](x: T) -> T:
|
||||
return add(x, x)
|
||||
|
||||
def test_generic_nested():
|
||||
stdio.printf("--- Test 9: generic nested call ---\n")
|
||||
r: t.CInt = double_val(21)
|
||||
if r == 42:
|
||||
stdio.printf("PASS: generic nested (double(21)=%d)\n", r)
|
||||
else:
|
||||
stdio.printf("FAIL: generic nested (double(21)=%d, expect 42)\n", r)
|
||||
|
||||
# ============================================================
|
||||
# Test 10: 泛型类方法调用
|
||||
# ============================================================
|
||||
class Counter[T]():
|
||||
count: T
|
||||
|
||||
def __init__(self, start: T):
|
||||
self.count = T(start)
|
||||
|
||||
def increment(self):
|
||||
self.count = add(self.count, T(1))
|
||||
|
||||
def get_count(self) -> T:
|
||||
return self.count
|
||||
|
||||
def test_generic_counter():
|
||||
stdio.printf("--- Test 10: generic Counter[T] ---\n")
|
||||
c = Counter(0)
|
||||
c.increment()
|
||||
c.increment()
|
||||
c.increment()
|
||||
r: t.CInt = c.get_count()
|
||||
if r == 3:
|
||||
stdio.printf("PASS: Counter[int] (count=%d)\n", r)
|
||||
else:
|
||||
stdio.printf("FAIL: Counter[int] (count=%d, expect 3)\n", r)
|
||||
|
||||
def main() -> t.CInt:
|
||||
stdio.printf("=== GenericTest: 泛型测试 ===\n\n")
|
||||
test_generic_add()
|
||||
test_generic_combine()
|
||||
test_generic_max()
|
||||
test_generic_box()
|
||||
test_generic_pair()
|
||||
test_fixed_array()
|
||||
test_char_array()
|
||||
test_generic_identity()
|
||||
test_generic_nested()
|
||||
test_generic_counter()
|
||||
stdio.printf("\n=== GenericTest Complete ===\n")
|
||||
return 0
|
||||
1
Test/GenericTest/output/47df358e08cc5c0e.deps.json
Normal file
1
Test/GenericTest/output/47df358e08cc5c0e.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"stdio": "73edbcf76e32d00b"}
|
||||
29
Test/GenericTest/project.json
Normal file
29
Test/GenericTest/project.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/TermiNexus/TransPyC/main/schemas/project-schema.json",
|
||||
"name": "GenericTest",
|
||||
"version": "1.0.0",
|
||||
"source_dir": "./App",
|
||||
"temp_dir": "./temp",
|
||||
"output_dir": "./output",
|
||||
"compiler": {
|
||||
"cmd": "llc",
|
||||
"flags": ["-filetype=obj", "-relocation-model=pic"]
|
||||
},
|
||||
"linker": {
|
||||
"cmd": "clang++",
|
||||
"flags": ["-Wl,--allow-multiple-definition", "-Wl,--unresolved-symbols=ignore-in-object-files", "-lmsvcrt", "-lucrt", "-lpthread", "-lmingwex", "-lkernel32", "-luser32", "-latomic"],
|
||||
"output": "GenericTest.exe"
|
||||
},
|
||||
"includes": [
|
||||
"../../includes"
|
||||
],
|
||||
"target": {
|
||||
"triple": "x86_64-pc-windows-gnu",
|
||||
"datalayout": "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
|
||||
},
|
||||
"options": {
|
||||
"slice_level": 3,
|
||||
"target": "llvm",
|
||||
"strict_mode": true
|
||||
}
|
||||
}
|
||||
63
Test/GenericTest/temp/47df358e08cc5c0e.pyi
Normal file
63
Test/GenericTest/temp/47df358e08cc5c0e.pyi
Normal file
@@ -0,0 +1,63 @@
|
||||
"""
|
||||
Auto-generated Python stub file from main.py
|
||||
Module: main
|
||||
"""
|
||||
|
||||
import c
|
||||
|
||||
|
||||
import t
|
||||
import stdio
|
||||
|
||||
def add[T](a: T, b: T) -> T: pass
|
||||
|
||||
def test_generic_add() -> t.CInt: pass
|
||||
|
||||
def combine[T1, T2](a: T1, b: T2) -> T1: pass
|
||||
|
||||
def test_generic_combine() -> t.CInt: pass
|
||||
|
||||
def max_val[T](a: T, b: T) -> T: pass
|
||||
|
||||
def test_generic_max() -> t.CInt: pass
|
||||
|
||||
|
||||
class Box[T]:
|
||||
value: T
|
||||
def __init__(self: Box, v: T) -> t.CInt: pass
|
||||
def get(self: Box) -> T: pass
|
||||
def set(self: Box, v: T) -> t.CInt: pass
|
||||
|
||||
def test_generic_box() -> t.CInt: pass
|
||||
|
||||
|
||||
class Pair[T1, T2]:
|
||||
first: T1
|
||||
second: T2
|
||||
def __init__(self: Pair, a: T1, b: T2) -> t.CInt: pass
|
||||
def sum_as_int(self: Pair) -> t.CInt: pass
|
||||
|
||||
def test_generic_pair() -> t.CInt: pass
|
||||
|
||||
def test_fixed_array() -> t.CInt: pass
|
||||
|
||||
def test_char_array() -> t.CInt: pass
|
||||
|
||||
def identity[T](x: T) -> T: pass
|
||||
|
||||
def test_generic_identity() -> t.CInt: pass
|
||||
|
||||
def double_val[T](x: T) -> T: pass
|
||||
|
||||
def test_generic_nested() -> t.CInt: pass
|
||||
|
||||
|
||||
class Counter[T]:
|
||||
count: T
|
||||
def __init__(self: Counter, start: T) -> t.CInt: pass
|
||||
def increment(self: Counter) -> t.CInt: pass
|
||||
def get_count(self: Counter) -> T: pass
|
||||
|
||||
def test_generic_counter() -> t.CInt: pass
|
||||
|
||||
def main() -> t.CInt: pass
|
||||
28
Test/GenericTest/temp/73edbcf76e32d00b.pyi
Normal file
28
Test/GenericTest/temp/73edbcf76e32d00b.pyi
Normal file
@@ -0,0 +1,28 @@
|
||||
"""
|
||||
Auto-generated Python stub file from stdio.py
|
||||
Module: stdio
|
||||
"""
|
||||
|
||||
|
||||
import t, c
|
||||
|
||||
def printf(fmt: t.CChar | t.CConst | t.CPtr, *args) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def fprintf(stream: t.CVoid | t.CPtr, fmt: t.CChar | t.CConst | t.CPtr, *args) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def sprintf(buf: t.CChar | t.CPtr, fmt: t.CChar | t.CConst | t.CPtr, *args) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def snprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: t.CChar | t.CConst | t.CPtr, *args) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def puts(s: t.CChar | t.CConst | t.CPtr) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def fputs(s: t.CChar | t.CConst | t.CPtr, stream: t.CVoid | t.CPtr) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def fgets(buf: t.CChar | t.CPtr, size: t.CInt, stream: t.CVoid | t.CPtr) -> t.CChar | t.CPtr | t.CExtern | t.CExport: pass
|
||||
|
||||
def fflush(stream: t.CVoid | t.CPtr) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
|
||||
stdin: t.CExtern | t.CVoid | t.CPtr
|
||||
stdout: t.CExtern | t.CVoid | t.CPtr
|
||||
stderr: t.CExtern | t.CVoid | t.CPtr
|
||||
2
Test/GenericTest/temp/_sha1_map.txt
Normal file
2
Test/GenericTest/temp/_sha1_map.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
47df358e08cc5c0e:main.py
|
||||
73edbcf76e32d00b:includes/stdio.py
|
||||
274
Test/GenericTest2/App/main.py
Normal file
274
Test/GenericTest2/App/main.py
Normal file
@@ -0,0 +1,274 @@
|
||||
import t
|
||||
import stdio
|
||||
import c
|
||||
|
||||
# ============================================================
|
||||
# Test 1: 泛型函数 - 不同整数类型特化
|
||||
# ============================================================
|
||||
def square[T](x: T) -> T:
|
||||
return x * x
|
||||
|
||||
def test_generic_square_types():
|
||||
stdio.printf("--- Test 1: generic square with different types ---\n")
|
||||
r1: t.CInt = square(5)
|
||||
r2: t.CInt = square(10)
|
||||
if r1 == 25 and r2 == 100:
|
||||
stdio.printf("PASS: square (5^2=%d 10^2=%d)\n", r1, r2)
|
||||
else:
|
||||
stdio.printf("FAIL: square (5^2=%d 10^2=%d, expect 25 100)\n", r1, r2)
|
||||
|
||||
# ============================================================
|
||||
# Test 2: 泛型函数 - 三参数
|
||||
# ============================================================
|
||||
def clamp[T](val: T, lo: T, hi: T) -> T:
|
||||
if val < lo:
|
||||
return lo
|
||||
if val > hi:
|
||||
return hi
|
||||
return val
|
||||
|
||||
def test_generic_clamp():
|
||||
stdio.printf("--- Test 2: generic clamp ---\n")
|
||||
r1: t.CInt = clamp(5, 0, 10)
|
||||
r2: t.CInt = clamp(-3, 0, 10)
|
||||
r3: t.CInt = clamp(15, 0, 10)
|
||||
if r1 == 5 and r2 == 0 and r3 == 10:
|
||||
stdio.printf("PASS: clamp (%d %d %d)\n", r1, r2, r3)
|
||||
else:
|
||||
stdio.printf("FAIL: clamp (%d %d %d, expect 5 0 10)\n", r1, r2, r3)
|
||||
|
||||
# ============================================================
|
||||
# Test 3: 泛型类 - Stack[T]
|
||||
# ============================================================
|
||||
class Stack[T]():
|
||||
data: list[t.CInt, 16]
|
||||
top: t.CInt
|
||||
|
||||
def __init__(self):
|
||||
self.top = 0
|
||||
|
||||
def push(self, val: T):
|
||||
self.data[self.top] = t.CInt(val)
|
||||
self.top += 1
|
||||
|
||||
def pop(self) -> T:
|
||||
self.top -= 1
|
||||
return T(self.data[self.top])
|
||||
|
||||
def is_empty(self) -> t.CInt:
|
||||
if self.top == 0:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
def test_generic_stack():
|
||||
stdio.printf("--- Test 3: generic Stack[T] ---\n")
|
||||
s = Stack()
|
||||
s.push(10)
|
||||
s.push(20)
|
||||
s.push(30)
|
||||
r1: t.CInt = s.pop()
|
||||
r2: t.CInt = s.pop()
|
||||
r3: t.CInt = s.pop()
|
||||
if r1 == 30 and r2 == 20 and r3 == 10:
|
||||
stdio.printf("PASS: Stack (pop=%d %d %d)\n", r1, r2, r3)
|
||||
else:
|
||||
stdio.printf("FAIL: Stack (pop=%d %d %d, expect 30 20 10)\n", r1, r2, r3)
|
||||
|
||||
# ============================================================
|
||||
# Test 4: 泛型函数 - swap via pointer
|
||||
# ============================================================
|
||||
class IntPair:
|
||||
a: t.CInt
|
||||
b: t.CInt
|
||||
|
||||
def generic_swap[T](p: IntPair | t.CPtr):
|
||||
tmp: t.CInt = c.Deref(p).a
|
||||
c.Deref(p).a = c.Deref(p).b
|
||||
c.Deref(p).b = tmp
|
||||
|
||||
def test_generic_swap():
|
||||
stdio.printf("--- Test 4: generic swap via pointer ---\n")
|
||||
p: IntPair = IntPair()
|
||||
p.a = 100
|
||||
p.b = 200
|
||||
generic_swap(c.Addr(p))
|
||||
if p.a == 200 and p.b == 100:
|
||||
stdio.printf("PASS: swap (a=%d b=%d)\n", p.a, p.b)
|
||||
else:
|
||||
stdio.printf("FAIL: swap (a=%d b=%d, expect 200 100)\n", p.a, p.b)
|
||||
|
||||
# ============================================================
|
||||
# Test 5: 泛型类 - Range[T] 迭代器
|
||||
# ============================================================
|
||||
class Range[T]():
|
||||
start: T
|
||||
end_val: T
|
||||
step: T
|
||||
|
||||
def __init__(self, s: T, e: T, st: T):
|
||||
self.start = T(s)
|
||||
self.end_val = T(e)
|
||||
self.step = T(st)
|
||||
|
||||
def sum_all(self) -> T:
|
||||
result: T = T(0)
|
||||
i: T = self.start
|
||||
while i < self.end_val:
|
||||
result = result + i
|
||||
i = i + self.step
|
||||
return result
|
||||
|
||||
def test_generic_range():
|
||||
stdio.printf("--- Test 5: generic Range[T] ---\n")
|
||||
r = Range(0, 10, 1) # 0+1+2+...+9=45
|
||||
s: t.CInt = r.sum_all()
|
||||
if s == 45:
|
||||
stdio.printf("PASS: Range sum (0..9=%d)\n", s)
|
||||
else:
|
||||
stdio.printf("FAIL: Range sum (0..9=%d, expect 45)\n", s)
|
||||
|
||||
# ============================================================
|
||||
# Test 6: 泛型函数 - 数组求和(非泛型数组参数)
|
||||
# ============================================================
|
||||
def array_sum(arr: list[t.CInt, 8], n: t.CInt) -> t.CInt:
|
||||
result: t.CInt = 0
|
||||
for i in range(n):
|
||||
result += arr[i]
|
||||
return result
|
||||
|
||||
def test_generic_array_sum():
|
||||
stdio.printf("--- Test 6: array sum ---\n")
|
||||
arr: list[t.CInt, 8] = [0]
|
||||
for i in range(8):
|
||||
arr[i] = (i + 1) * 10
|
||||
s: t.CInt = array_sum(arr, 8)
|
||||
if s == 360:
|
||||
stdio.printf("PASS: array sum (%d)\n", s)
|
||||
else:
|
||||
stdio.printf("FAIL: array sum (%d, expect 360)\n", s)
|
||||
|
||||
# ============================================================
|
||||
# Test 7: 泛型函数 - 比较并返回较大值
|
||||
# ============================================================
|
||||
def max_of_three[T](a: T, b: T, c_val: T) -> T:
|
||||
m: T = a
|
||||
if b > m:
|
||||
m = b
|
||||
if c_val > m:
|
||||
m = c_val
|
||||
return m
|
||||
|
||||
def test_generic_max_three():
|
||||
stdio.printf("--- Test 7: generic max of three ---\n")
|
||||
r1: t.CInt = max_of_three(1, 2, 3)
|
||||
r2: t.CInt = max_of_three(10, 30, 20)
|
||||
r3: t.CInt = max_of_three(50, 50, 50)
|
||||
if r1 == 3 and r2 == 30 and r3 == 50:
|
||||
stdio.printf("PASS: max3 (%d %d %d)\n", r1, r2, r3)
|
||||
else:
|
||||
stdio.printf("FAIL: max3 (%d %d %d, expect 3 30 50)\n", r1, r2, r3)
|
||||
|
||||
# ============================================================
|
||||
# Test 8: 泛型类 - 带方法的容器
|
||||
# ============================================================
|
||||
class Container[T]():
|
||||
values: list[t.CInt, 8]
|
||||
size: t.CInt
|
||||
|
||||
def __init__(self):
|
||||
self.size = 0
|
||||
|
||||
def add(self, v: T):
|
||||
self.values[self.size] = t.CInt(v)
|
||||
self.size += 1
|
||||
|
||||
def get(self, idx: t.CInt) -> T:
|
||||
return T(self.values[idx])
|
||||
|
||||
def contains(self, v: T) -> t.CInt:
|
||||
for i in range(self.size):
|
||||
if self.values[i] == t.CInt(v):
|
||||
return 1
|
||||
return 0
|
||||
|
||||
def total(self) -> T:
|
||||
result: T = T(0)
|
||||
for i in range(self.size):
|
||||
result = result + T(self.values[i])
|
||||
return result
|
||||
|
||||
def test_generic_container():
|
||||
stdio.printf("--- Test 8: generic Container[T] ---\n")
|
||||
c = Container()
|
||||
c.add(10)
|
||||
c.add(20)
|
||||
c.add(30)
|
||||
has20: t.CInt = c.contains(20)
|
||||
has99: t.CInt = c.contains(99)
|
||||
total: t.CInt = c.total()
|
||||
if has20 == 1 and has99 == 0 and total == 60:
|
||||
stdio.printf("PASS: Container (has20=%d has99=%d total=%d)\n", has20, has99, total)
|
||||
else:
|
||||
stdio.printf("FAIL: Container (has20=%d has99=%d total=%d, expect 1 0 60)\n", has20, has99, total)
|
||||
|
||||
# ============================================================
|
||||
# Test 9: 泛型函数 - 阶乘
|
||||
# ============================================================
|
||||
def factorial[T](n: T) -> T:
|
||||
result: T = T(1)
|
||||
i: T = T(2)
|
||||
while i <= n:
|
||||
result = result * i
|
||||
i = i + T(1)
|
||||
return result
|
||||
|
||||
def test_generic_factorial():
|
||||
stdio.printf("--- Test 9: generic factorial ---\n")
|
||||
r1: t.CInt = factorial(5)
|
||||
r2: t.CInt = factorial(10)
|
||||
if r1 == 120 and r2 == 3628800:
|
||||
stdio.printf("PASS: factorial (5!=%d 10!=%d)\n", r1, r2)
|
||||
else:
|
||||
stdio.printf("FAIL: factorial (5!=%d 10!=%d, expect 120 3628800)\n", r1, r2)
|
||||
|
||||
# ============================================================
|
||||
# Test 10: 泛型类 - 累加器
|
||||
# ============================================================
|
||||
class Accumulator[T]():
|
||||
total: T
|
||||
|
||||
def __init__(self, start: T):
|
||||
self.total = T(start)
|
||||
|
||||
def add_val(self, v: T):
|
||||
self.total = self.total + v
|
||||
|
||||
def get_result(self) -> T:
|
||||
return self.total
|
||||
|
||||
def test_generic_accumulator():
|
||||
stdio.printf("--- Test 10: generic Accumulator[T] ---\n")
|
||||
a = Accumulator(0)
|
||||
a.add_val(10)
|
||||
a.add_val(20)
|
||||
a.add_val(30)
|
||||
r: t.CInt = a.get_result()
|
||||
if r == 60:
|
||||
stdio.printf("PASS: Accumulator (result=%d)\n", r)
|
||||
else:
|
||||
stdio.printf("FAIL: Accumulator (result=%d, expect 60)\n", r)
|
||||
|
||||
def main() -> t.CInt:
|
||||
stdio.printf("=== GenericTest2: Advanced Generic Tests ===\n\n")
|
||||
test_generic_square_types()
|
||||
test_generic_clamp()
|
||||
test_generic_stack()
|
||||
test_generic_swap()
|
||||
test_generic_range()
|
||||
test_generic_array_sum()
|
||||
test_generic_max_three()
|
||||
test_generic_container()
|
||||
test_generic_factorial()
|
||||
test_generic_accumulator()
|
||||
stdio.printf("\n=== GenericTest2 Complete ===\n")
|
||||
return 0
|
||||
1
Test/GenericTest2/output/1348b0e29ea228ad.deps.json
Normal file
1
Test/GenericTest2/output/1348b0e29ea228ad.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"stdio": "73edbcf76e32d00b"}
|
||||
29
Test/GenericTest2/project.json
Normal file
29
Test/GenericTest2/project.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/TermiNexus/TransPyC/main/schemas/project-schema.json",
|
||||
"name": "GenericTest2",
|
||||
"version": "1.0.0",
|
||||
"source_dir": "./App",
|
||||
"temp_dir": "./temp",
|
||||
"output_dir": "./output",
|
||||
"compiler": {
|
||||
"cmd": "llc",
|
||||
"flags": ["-filetype=obj", "-relocation-model=pic"]
|
||||
},
|
||||
"linker": {
|
||||
"cmd": "clang++",
|
||||
"flags": ["-Wl,--allow-multiple-definition", "-Wl,--unresolved-symbols=ignore-in-object-files", "-lmsvcrt", "-lucrt", "-lpthread", "-lmingwex", "-lkernel32", "-luser32", "-latomic"],
|
||||
"output": "GenericTest2.exe"
|
||||
},
|
||||
"includes": [
|
||||
"../../includes"
|
||||
],
|
||||
"target": {
|
||||
"triple": "x86_64-pc-windows-gnu",
|
||||
"datalayout": "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
|
||||
},
|
||||
"options": {
|
||||
"slice_level": 3,
|
||||
"target": "llvm",
|
||||
"strict_mode": true
|
||||
}
|
||||
}
|
||||
82
Test/GenericTest2/temp/1348b0e29ea228ad.pyi
Normal file
82
Test/GenericTest2/temp/1348b0e29ea228ad.pyi
Normal file
@@ -0,0 +1,82 @@
|
||||
"""
|
||||
Auto-generated Python stub file from main.py
|
||||
Module: main
|
||||
"""
|
||||
|
||||
|
||||
import t
|
||||
import stdio
|
||||
import c
|
||||
|
||||
def square[T](x: T) -> T: pass
|
||||
|
||||
def test_generic_square_types() -> t.CInt: pass
|
||||
|
||||
def clamp[T](val: T, lo: T, hi: T) -> T: pass
|
||||
|
||||
def test_generic_clamp() -> t.CInt: pass
|
||||
|
||||
|
||||
class Stack[T]:
|
||||
data: list[t.CInt, 16]
|
||||
top: t.CInt
|
||||
def __init__(self: Stack) -> t.CInt: pass
|
||||
def push(self: Stack, val: T) -> t.CInt: pass
|
||||
def pop(self: Stack) -> T: pass
|
||||
def is_empty(self: Stack) -> t.CInt: pass
|
||||
|
||||
def test_generic_stack() -> t.CInt: pass
|
||||
|
||||
|
||||
class IntPair:
|
||||
a: t.CInt
|
||||
b: t.CInt
|
||||
|
||||
def generic_swap[T](p: IntPair | t.CPtr) -> t.CInt: pass
|
||||
|
||||
def test_generic_swap() -> t.CInt: pass
|
||||
|
||||
|
||||
class Range[T]:
|
||||
start: T
|
||||
end_val: T
|
||||
step: T
|
||||
def __init__(self: Range, s: T, e: T, st: T) -> t.CInt: pass
|
||||
def sum_all(self: Range) -> T: pass
|
||||
|
||||
def test_generic_range() -> t.CInt: pass
|
||||
|
||||
def array_sum(arr: list[t.CInt, 8], n: t.CInt) -> t.CInt: pass
|
||||
|
||||
def test_generic_array_sum() -> t.CInt: pass
|
||||
|
||||
def max_of_three[T](a: T, b: T, c_val: T) -> T: pass
|
||||
|
||||
def test_generic_max_three() -> t.CInt: pass
|
||||
|
||||
|
||||
class Container[T]:
|
||||
values: list[t.CInt, 8]
|
||||
size: t.CInt
|
||||
def __init__(self: Container) -> t.CInt: pass
|
||||
def add(self: Container, v: T) -> t.CInt: pass
|
||||
def get(self: Container, idx: t.CInt) -> T: pass
|
||||
def contains(self: Container, v: T) -> t.CInt: pass
|
||||
def total(self: Container) -> T: pass
|
||||
|
||||
def test_generic_container() -> t.CInt: pass
|
||||
|
||||
def factorial[T](n: T) -> T: pass
|
||||
|
||||
def test_generic_factorial() -> t.CInt: pass
|
||||
|
||||
|
||||
class Accumulator[T]:
|
||||
total: T
|
||||
def __init__(self: Accumulator, start: T) -> t.CInt: pass
|
||||
def add_val(self: Accumulator, v: T) -> t.CInt: pass
|
||||
def get_result(self: Accumulator) -> T: pass
|
||||
|
||||
def test_generic_accumulator() -> t.CInt: pass
|
||||
|
||||
def main() -> t.CInt: pass
|
||||
28
Test/GenericTest2/temp/73edbcf76e32d00b.pyi
Normal file
28
Test/GenericTest2/temp/73edbcf76e32d00b.pyi
Normal file
@@ -0,0 +1,28 @@
|
||||
"""
|
||||
Auto-generated Python stub file from stdio.py
|
||||
Module: stdio
|
||||
"""
|
||||
|
||||
|
||||
import t, c
|
||||
|
||||
def printf(fmt: t.CChar | t.CConst | t.CPtr, *args) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def fprintf(stream: t.CVoid | t.CPtr, fmt: t.CChar | t.CConst | t.CPtr, *args) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def sprintf(buf: t.CChar | t.CPtr, fmt: t.CChar | t.CConst | t.CPtr, *args) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def snprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: t.CChar | t.CConst | t.CPtr, *args) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def puts(s: t.CChar | t.CConst | t.CPtr) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def fputs(s: t.CChar | t.CConst | t.CPtr, stream: t.CVoid | t.CPtr) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
def fgets(buf: t.CChar | t.CPtr, size: t.CInt, stream: t.CVoid | t.CPtr) -> t.CChar | t.CPtr | t.CExtern | t.CExport: pass
|
||||
|
||||
def fflush(stream: t.CVoid | t.CPtr) -> t.CInt | t.CExtern | t.CExport: pass
|
||||
|
||||
|
||||
stdin: t.CExtern | t.CVoid | t.CPtr
|
||||
stdout: t.CExtern | t.CVoid | t.CPtr
|
||||
stderr: t.CExtern | t.CVoid | t.CPtr
|
||||
2
Test/GenericTest2/temp/_sha1_map.txt
Normal file
2
Test/GenericTest2/temp/_sha1_map.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
1348b0e29ea228ad:main.py
|
||||
73edbcf76e32d00b:includes/stdio.py
|
||||
61
Test/IterTest/App/main.py
Normal file
61
Test/IterTest/App/main.py
Normal file
@@ -0,0 +1,61 @@
|
||||
import t
|
||||
import stdio
|
||||
import string
|
||||
|
||||
def test_for_in_string():
|
||||
stdio.printf("--- Test 1: for-in string iteration ---\n")
|
||||
s: t.CChar | t.CPtr = "Hello"
|
||||
result: t.CInt = 0
|
||||
for ch in s:
|
||||
result += ch
|
||||
# H=72, e=101, l=108, l=108, o=111 => 500
|
||||
if result == 500:
|
||||
stdio.printf("PASS: for-in string (sum=%d)\n", result)
|
||||
else:
|
||||
stdio.printf("FAIL: for-in string (sum=%d, expect 500)\n", result)
|
||||
|
||||
def test_for_in_char_ptr():
|
||||
stdio.printf("--- Test 2: for-in char* iteration ---\n")
|
||||
s: t.CChar | t.CPtr = "ABC"
|
||||
chars: list[t.CInt, 4] = [0]
|
||||
idx: t.CInt = 0
|
||||
for ch in s:
|
||||
if idx < 3:
|
||||
chars[idx] = ch
|
||||
idx += 1
|
||||
if chars[0] == 65 and chars[1] == 66 and chars[2] == 67:
|
||||
stdio.printf("PASS: for-in char* (A=%d B=%d C=%d)\n", chars[0], chars[1], chars[2])
|
||||
else:
|
||||
stdio.printf("FAIL: for-in char* (A=%d B=%d C=%d, expect 65 66 67)\n", chars[0], chars[1], chars[2])
|
||||
|
||||
def test_strcpy_for_in():
|
||||
stdio.printf("--- Test 3: strcpy using for-in ---\n")
|
||||
src: t.CChar | t.CPtr = "test"
|
||||
# 手动实现 strcpy 用 for-in
|
||||
import w32.win32memory
|
||||
buf: t.CChar | t.CPtr = w32.win32memory.VirtualAlloc(t.CVoid(0, t.CPtr), 64, 12288, 4)
|
||||
if t.CUInt64T(buf) == 0:
|
||||
stdio.printf("SKIP: VirtualAlloc returned NULL\n")
|
||||
return
|
||||
string.memset(buf, 0, 64)
|
||||
# 用 for-in 复制
|
||||
p: t.CChar | t.CPtr = buf
|
||||
for ch in src:
|
||||
p[0] = ch
|
||||
p += 1
|
||||
p[0] = 0
|
||||
cmp_result: t.CInt = string.strcmp(buf, "test")
|
||||
if cmp_result == 0:
|
||||
stdio.printf("PASS: strcpy for-in (result=%s)\n", buf)
|
||||
else:
|
||||
stdio.printf("FAIL: strcpy for-in (cmp=%d)\n", cmp_result)
|
||||
|
||||
import w32.win32memory
|
||||
|
||||
def main() -> t.CInt:
|
||||
stdio.printf("=== IterTest: 指针迭代测试 ===\n\n")
|
||||
test_for_in_string()
|
||||
test_for_in_char_ptr()
|
||||
test_strcpy_for_in()
|
||||
stdio.printf("\n=== IterTest Complete ===\n")
|
||||
return 0
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user