修复了大量存在的问题,增加了假鸭子类型等等机制
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import t
|
||||
import stdio
|
||||
import string
|
||||
import testcheck
|
||||
|
||||
# 定义结构体
|
||||
class Point(t.Struct):
|
||||
@@ -16,29 +17,23 @@ class Node(t.Struct):
|
||||
next: t.CPtr | t.CVoid # Node* 类型
|
||||
|
||||
def test_struct_basic():
|
||||
stdio.printf("--- Test 1: struct basic ---\n")
|
||||
testcheck.section("Test 1: struct basic")
|
||||
p: Point = Point()
|
||||
p.x = 10
|
||||
p.y = 20
|
||||
if p.x == 10 and p.y == 20:
|
||||
stdio.printf("PASS: struct basic (x=%d y=%d)\n", p.x, p.y)
|
||||
else:
|
||||
stdio.printf("FAIL: struct basic (x=%d y=%d, expect 10 20)\n", p.x, p.y)
|
||||
testcheck.check(p.x == 10 and p.y == 20, "struct basic (x=10 y=20)", "struct basic (x y expect 10 20)")
|
||||
|
||||
def test_struct_nested():
|
||||
stdio.printf("--- Test 2: struct nested ---\n")
|
||||
testcheck.section("Test 2: struct nested")
|
||||
r: Rect = Rect()
|
||||
r.origin.x = 1
|
||||
r.origin.y = 2
|
||||
r.size.x = 100
|
||||
r.size.y = 200
|
||||
if r.origin.x == 1 and r.origin.y == 2 and r.size.x == 100 and r.size.y == 200:
|
||||
stdio.printf("PASS: struct nested (origin=%d,%d size=%d,%d)\n", r.origin.x, r.origin.y, r.size.x, r.size.y)
|
||||
else:
|
||||
stdio.printf("FAIL: struct nested\n")
|
||||
testcheck.check(r.origin.x == 1 and r.origin.y == 2 and r.size.x == 100 and r.size.y == 200, "struct nested (origin=1,2 size=100,200)", "struct nested (mismatch)")
|
||||
|
||||
def test_struct_pointer():
|
||||
stdio.printf("--- Test 3: struct pointer ---\n")
|
||||
testcheck.section("Test 3: struct pointer")
|
||||
p: Point = Point()
|
||||
p.x = 42
|
||||
p.y = 84
|
||||
@@ -48,27 +43,21 @@ def test_struct_pointer():
|
||||
pp.x = 100
|
||||
pp.y = 200
|
||||
# 检查原始结构体是否被修改
|
||||
if p.x == 100 and p.y == 200:
|
||||
stdio.printf("PASS: struct pointer (x=%d y=%d)\n", p.x, p.y)
|
||||
else:
|
||||
stdio.printf("FAIL: struct pointer (x=%d y=%d, expect 100 200)\n", p.x, p.y)
|
||||
testcheck.check(p.x == 100 and p.y == 200, "struct pointer (x=100 y=200)", "struct pointer (x y expect 100 200)")
|
||||
|
||||
def test_struct_param():
|
||||
stdio.printf("--- Test 4: struct as parameter ---\n")
|
||||
testcheck.section("Test 4: struct as parameter")
|
||||
p: Point = Point()
|
||||
p.x = 5
|
||||
p.y = 15
|
||||
sum_val: t.CInt = point_sum(p)
|
||||
if sum_val == 20:
|
||||
stdio.printf("PASS: struct param (sum=%d)\n", sum_val)
|
||||
else:
|
||||
stdio.printf("FAIL: struct param (sum=%d, expect 20)\n", sum_val)
|
||||
testcheck.check(sum_val == 20, "struct param (sum=20)", "struct param (sum expect 20)")
|
||||
|
||||
def point_sum(p: Point) -> t.CInt:
|
||||
return p.x + p.y
|
||||
|
||||
def test_struct_array():
|
||||
stdio.printf("--- Test 5: struct array ---\n")
|
||||
testcheck.section("Test 5: struct array")
|
||||
# 分配结构体数组
|
||||
buf: t.CUInt8T | t.CPtr = w32.win32memory.VirtualAlloc(t.CVoid(0, t.CPtr), 256, 12288, 4)
|
||||
if t.CUInt64T(buf) == 0:
|
||||
@@ -82,19 +71,15 @@ def test_struct_array():
|
||||
pts[1].x = 3
|
||||
pts[1].y = 4
|
||||
total: t.CInt = pts[0].x + pts[0].y + pts[1].x + pts[1].y
|
||||
if total == 10:
|
||||
stdio.printf("PASS: struct array (total=%d)\n", total)
|
||||
else:
|
||||
stdio.printf("FAIL: struct array (total=%d, expect 10)\n", total)
|
||||
testcheck.check(total == 10, "struct array (total=10)", "struct array (total expect 10)")
|
||||
|
||||
import w32.win32memory
|
||||
|
||||
def main() -> t.CInt:
|
||||
stdio.printf("=== StructTest: 结构体操作基准测试 ===\n\n")
|
||||
testcheck.begin("StructTest: 结构体操作基准测试")
|
||||
test_struct_basic()
|
||||
test_struct_nested()
|
||||
test_struct_pointer()
|
||||
test_struct_param()
|
||||
test_struct_array()
|
||||
stdio.printf("\n=== StructTest Complete ===\n")
|
||||
return 0
|
||||
return testcheck.end()
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "string": "6aee24fdefa3cbc0", "main": "6f6ee14c129ac228", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e", "w32.win32process": "067c78e9f121dce3", "win32process": "067c78e9f121dce3"}
|
||||
{"main": "24e26a8de1173993", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950", "w32.win32process": "067c78e9f121dce3", "win32process": "067c78e9f121dce3"}
|
||||
1
Test/StructTest/output/24e26a8de1173993.deps.json
Normal file
1
Test/StructTest/output/24e26a8de1173993.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd"}
|
||||
@@ -1 +1 @@
|
||||
{"stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "string": "6aee24fdefa3cbc0", "main": "6f6ee14c129ac228", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "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": "24e26a8de1173993", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "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"}
|
||||
@@ -1 +1 @@
|
||||
{"stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "string": "6aee24fdefa3cbc0", "main": "6f6ee14c129ac228", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950"}
|
||||
{"main": "24e26a8de1173993", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd"}
|
||||
@@ -1 +0,0 @@
|
||||
{"stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "string": "6aee24fdefa3cbc0", "main": "6f6ee14c129ac228", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b"}
|
||||
@@ -1 +0,0 @@
|
||||
{"stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "string": "6aee24fdefa3cbc0", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b"}
|
||||
@@ -1 +1 @@
|
||||
{"stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "string": "6aee24fdefa3cbc0", "main": "6f6ee14c129ac228", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e"}
|
||||
{"main": "24e26a8de1173993", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950"}
|
||||
1
Test/StructTest/output/9dbecd0942a39782.deps.json
Normal file
1
Test/StructTest/output/9dbecd0942a39782.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"main": "24e26a8de1173993", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd"}
|
||||
@@ -1 +1 @@
|
||||
{"stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "string": "6aee24fdefa3cbc0", "main": "6f6ee14c129ac228", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e"}
|
||||
{"main": "24e26a8de1173993", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e"}
|
||||
1
Test/StructTest/output/b5f1dc665c52a1bd.deps.json
Normal file
1
Test/StructTest/output/b5f1dc665c52a1bd.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"main": "24e26a8de1173993", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd"}
|
||||
@@ -1 +1 @@
|
||||
{"stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "string": "6aee24fdefa3cbc0", "main": "6f6ee14c129ac228", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c"}
|
||||
{"main": "24e26a8de1173993", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c"}
|
||||
@@ -1 +1 @@
|
||||
{"stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "string": "6aee24fdefa3cbc0", "main": "6f6ee14c129ac228", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950"}
|
||||
{"main": "24e26a8de1173993", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950"}
|
||||
@@ -9,6 +9,7 @@ import c
|
||||
import t
|
||||
import stdio
|
||||
import string
|
||||
import testcheck
|
||||
|
||||
class Point(t.Struct):
|
||||
x: t.CInt
|
||||
@@ -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
|
||||
25
Test/StructTest/temp/9dbecd0942a39782.pyi
Normal file
25
Test/StructTest/temp/9dbecd0942a39782.pyi
Normal 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
|
||||
@@ -1,6 +1,7 @@
|
||||
56cdd754a8a09347:includes/stdint.py
|
||||
24e26a8de1173993:main.py
|
||||
49bd8cba55979f76:includes/stdint.py
|
||||
5a6a2137958c28c5:includes/w32\win32base.py
|
||||
6aee24fdefa3cbc0:includes/string.py
|
||||
6f6ee14c129ac228:main.py
|
||||
72e2d5ccb7cedcf1:includes/w32\win32memory.py
|
||||
73edbcf76e32d00b:includes/stdio.py
|
||||
9dbecd0942a39782:includes/testcheck.py
|
||||
b5f1dc665c52a1bd:includes/string.py
|
||||
|
||||
@@ -41,4 +41,4 @@ def atoll(src: str) -> t.CInt64T: pass
|
||||
|
||||
def atof(src: str) -> t.CDouble: pass
|
||||
|
||||
def split(s: str, delim: str, result: list[str]) -> int: pass
|
||||
def split(s: str, delim: str, result: t.CArray[str]) -> int: pass
|
||||
Reference in New Issue
Block a user