修复了大量存在的问题,增加了假鸭子类型等等机制

This commit is contained in:
2026-06-25 14:49:46 +08:00
parent 19f2787db0
commit d88d11b646
827 changed files with 32617 additions and 18316 deletions

View File

@@ -1,5 +1,6 @@
import t
import stdio
import testcheck
# 测试基本函数调用
def add(a: t.CInt, b: t.CInt) -> t.CInt:
@@ -39,85 +40,61 @@ def is_even(n: t.CInt) -> t.CBool:
return n % 2 == 0
def test_basic_call():
stdio.printf("--- Test 1: basic function call ---\n")
testcheck.section("Test 1: basic function call")
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)
testcheck.check(r == 30, "add(10,20)=30", "add(10,20) expect 30")
def test_multi_args():
stdio.printf("--- Test 2: multi args ---\n")
testcheck.section("Test 2: multi args")
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)
testcheck.check(r == 10, "multi_args(1,2,3,4)=10", "multi_args(1,2,3,4) expect 10")
def test_recursion():
stdio.printf("--- Test 3: recursion (factorial) ---\n")
testcheck.section("Test 3: recursion (factorial)")
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)
testcheck.check(r == 3628800, "factorial(10)=3628800", "factorial(10) expect 3628800")
def test_fibonacci():
stdio.printf("--- Test 4: fibonacci ---\n")
testcheck.section("Test 4: fibonacci")
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)
testcheck.check(r == 55, "fib(10)=55", "fib(10) expect 55")
def test_ptr_param():
stdio.printf("--- Test 5: pointer parameter ---\n")
testcheck.section("Test 5: pointer parameter")
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")
testcheck.info("SKIP: VirtualAlloc returned NULL")
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])
testcheck.check(buf[0] == 35, "ptr param (result=35)", "ptr param expect 35")
def test_u64_return():
stdio.printf("--- Test 6: u64 return ---\n")
testcheck.section("Test 6: u64 return")
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)
testcheck.check(r == t.CUInt64T(0xDEADBEEF), "u64 return (0xdeadbeef)", "u64 return expect 0xdeadbeef")
def test_bool_return():
stdio.printf("--- Test 7: bool return ---\n")
testcheck.section("Test 7: bool return")
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)
testcheck.check(r1 and not r2, "bool return (is_even(4)=1, is_even(7)=0)", "bool return expect is_even(4)=1, is_even(7)=0")
def test_nested_call():
stdio.printf("--- Test 8: nested function call ---\n")
testcheck.section("Test 8: nested function call")
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)
testcheck.check(r == 13, "nested call (add(factorial(3), sub(10,3))=13)", "nested call expect 13")
import w32.win32memory
def main() -> t.CInt:
stdio.printf("=== FuncTest: 函数调用基准测试 ===\n\n")
testcheck.begin("FuncTest: 函数调用基准测试")
test_basic_call()
test_multi_args()
test_recursion()
@@ -126,5 +103,4 @@ def main() -> t.CInt:
test_u64_return()
test_bool_return()
test_nested_call()
stdio.printf("\n=== FuncTest Complete ===\n")
return 0
return testcheck.end()

View File

@@ -1 +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"}
{"main": "067f811511854c88", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950", "w32.win32process": "067c78e9f121dce3", "win32process": "067c78e9f121dce3"}

View File

@@ -1 +1 @@
{"stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b"}
{"stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782"}

View File

@@ -1 +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"}
{"main": "067f811511854c88", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950", "w32.win32process": "067c78e9f121dce3", "win32process": "067c78e9f121dce3", "w32.win32sync": "29813d57621099a9", "win32sync": "29813d57621099a9"}

View File

@@ -1 +1 @@
{"stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "main": "d6f1d57732bde476", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950"}
{"main": "067f811511854c88", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782"}

View File

@@ -1 +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"}
{"main": "067f811511854c88", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950"}

View File

@@ -0,0 +1 @@
{"main": "067f811511854c88", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782"}

View File

@@ -1 +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"}
{"main": "067f811511854c88", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e"}

View File

@@ -1 +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"}
{"main": "067f811511854c88", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c"}

View File

@@ -1 +1 @@
{"stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "main": "d6f1d57732bde476", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950"}
{"main": "067f811511854c88", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950"}

View File

@@ -8,6 +8,7 @@ import c
import t
import stdio
import testcheck
def add(a: t.CInt, b: t.CInt) -> t.CInt: pass

View File

@@ -64,4 +64,12 @@ 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
CHAR32PTR: t.CTypedef = t.CChar32T | t.CPtr
i8: t.CTypedef = t.CInt8T
i16: t.CTypedef = t.CInt16T
i32: t.CTypedef = t.CInt32T
i64: t.CTypedef = t.CInt64T
u8: t.CTypedef = t.CUInt8T
u16: t.CTypedef = t.CUInt16T
u32: t.CTypedef = t.CUInt32T
u64: t.CTypedef = t.CUInt64T

View File

@@ -0,0 +1,25 @@
"""
Auto-generated Python stub file from testcheck.py
Module: testcheck
"""
import t, c
import stdio
_pass_count: t.CExtern | t.CInt
_fail_count: t.CExtern | t.CInt
def begin(name: str) -> t.CInt: pass
def section(name: str) -> t.CInt: pass
def ok(msg: str) -> t.CInt: pass
def fail(msg: str) -> t.CInt: pass
def check(cond: t.CInt, ok_msg: str, fail_msg: str) -> t.CInt: pass
def info(msg: str) -> t.CInt: pass
def end() -> t.CInt: pass

View File

@@ -1,5 +1,6 @@
56cdd754a8a09347:includes/stdint.py
067f811511854c88:main.py
49bd8cba55979f76:includes/stdint.py
5a6a2137958c28c5:includes/w32\win32base.py
72e2d5ccb7cedcf1:includes/w32\win32memory.py
73edbcf76e32d00b:includes/stdio.py
d6f1d57732bde476:main.py
9dbecd0942a39782:includes/testcheck.py