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

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,6 +1,7 @@
from stdint import *
import w32.win32console
import t, c
import testcheck
def add_inline(a: t.CInt, b: t.CInt) -> t.CDefine:
@@ -37,122 +38,122 @@ def main() -> t.CInt | t.CExport:
w32.win32console.SetConsoleCP(65001)
w32.win32console.SetConsoleOutputCP(65001)
print("=== Test 1: Raise and catch exact custom exception ===")
testcheck.begin("TestFBProject: 异常处理与LLVMIR测试")
testcheck.section("Test 1: Raise and catch exact custom exception")
try:
raise DiskError("disk error")
except DiskError as e:
print("PASS 1: caught DiskError:", e)
print("caught DiskError:", e)
testcheck.ok("Test 1: caught DiskError")
except:
print("FAIL 1: caught by generic except")
print("")
testcheck.fail("Test 1: caught by generic except")
print("=== Test 2: Catch parent catches child ===")
testcheck.section("Test 2: Catch parent catches child")
try:
raise_disk()
except AppError as e:
print("PASS 2: caught AppError (child DiskError):", e)
print("caught AppError (child DiskError):", e)
testcheck.ok("Test 2: caught AppError (child DiskError)")
except:
print("FAIL 2: caught by generic except")
print("")
testcheck.fail("Test 2: caught by generic except")
print("=== Test 3: Catch parent catches nested child ===")
testcheck.section("Test 3: Catch parent catches nested child")
try:
raise_timeout()
except AppError as e:
print("PASS 3: caught AppError (grandchild TimeoutError):", e)
print("caught AppError (grandchild TimeoutError):", e)
testcheck.ok("Test 3: caught AppError (grandchild TimeoutError)")
except:
print("FAIL 3: caught by generic except")
print("")
testcheck.fail("Test 3: caught by generic except")
print("=== Test 4: Catch mid-level parent ===")
testcheck.section("Test 4: Catch mid-level parent")
try:
raise_timeout()
except NetworkError as e:
print("PASS 4: caught NetworkError (child TimeoutError):", e)
print("caught NetworkError (child TimeoutError):", e)
testcheck.ok("Test 4: caught NetworkError (child TimeoutError)")
except:
print("FAIL 4: caught by generic except")
print("")
testcheck.fail("Test 4: caught by generic except")
print("=== Test 5: Exact catch before parent ===")
testcheck.section("Test 5: Exact catch before parent")
try:
raise_network()
except NetworkError as e:
print("PASS 5: caught NetworkError:", e)
print("caught NetworkError:", e)
testcheck.ok("Test 5: caught NetworkError")
except AppError as e:
print("FAIL 5: caught AppError (should be NetworkError first)")
testcheck.fail("Test 5: caught AppError (should be NetworkError first)")
except:
print("FAIL 5: caught by generic except")
print("")
testcheck.fail("Test 5: caught by generic except")
print("=== Test 6: Parent catch when exact not present ===")
testcheck.section("Test 6: Parent catch when exact not present")
try:
raise_network()
except DiskError as e:
print("FAIL 6: caught DiskError (wrong)")
testcheck.fail("Test 6: caught DiskError (wrong)")
except AppError as e:
print("PASS 6: caught AppError (no NetworkError handler):", e)
print("caught AppError (no NetworkError handler):", e)
testcheck.ok("Test 6: caught AppError (no NetworkError handler)")
except:
print("FAIL 6: caught by generic except")
print("")
testcheck.fail("Test 6: caught by generic except")
print("=== Test 7: Generic except fallback ===")
testcheck.section("Test 7: Generic except fallback")
try:
raise_disk()
except RuntimeError as e:
print("FAIL 7: caught RuntimeError (wrong)")
testcheck.fail("Test 7: caught RuntimeError (wrong)")
except:
print("PASS 7: caught by generic except")
print("")
testcheck.ok("Test 7: caught by generic except")
print("=== Test 8: Cross-function with inheritance ===")
testcheck.section("Test 8: Cross-function with inheritance")
try:
raise_timeout()
except NetworkError as e:
print("PASS 8: caught NetworkError (cross-func TimeoutError):", e)
print("caught NetworkError (cross-func TimeoutError):", e)
testcheck.ok("Test 8: caught NetworkError (cross-func TimeoutError)")
except:
print("FAIL 8: caught by generic except")
print("")
testcheck.fail("Test 8: caught by generic except")
print("=== Test 9: Built-in exception still works ===")
testcheck.section("Test 9: Built-in exception still works")
try:
raise ValueError("test")
except ValueError as e:
print("PASS 9: caught ValueError:", e)
print("caught ValueError:", e)
testcheck.ok("Test 9: caught ValueError")
except:
print("FAIL 9: caught by generic except")
print("")
testcheck.fail("Test 9: caught by generic except")
print("=== Test 10: Mixed built-in and custom ===")
testcheck.section("Test 10: Mixed built-in and custom")
try:
raise RuntimeError("test")
except DiskError as e:
print("FAIL 10: caught DiskError (wrong)")
testcheck.fail("Test 10: caught DiskError (wrong)")
except RuntimeError as e:
print("PASS 10: caught RuntimeError:", e)
print("caught RuntimeError:", e)
testcheck.ok("Test 10: caught RuntimeError")
except:
print("FAIL 10: caught by generic except")
print("")
testcheck.fail("Test 10: caught by generic except")
print("=== All Custom Exception Tests Complete ===")
print("")
print("=== Test LLVMIR: inline LLVM IR add ===")
testcheck.section("Test LLVMIR: inline LLVM IR add")
x: t.CInt = 10
y: t.CInt = 20
r: t.CInt = c.LLVMIR(f"add i32 {c.LInp(x)}, {c.LInp(y)}", t.CInt)
print("LLVMIR add result:", r)
testcheck.check(r == 30, "LLVMIR add (10+20=30)", "LLVMIR add result mismatch")
print("")
print("=== Test CDefine function macro ===")
testcheck.section("Test CDefine function macro")
s: t.CInt = add_inline(3, 4)
print("add_inline(3, 4) =", s)
testcheck.check(s == 7, "add_inline(3, 4) = 7", "add_inline result mismatch")
m: t.CInt = mul_inline(5, 6)
print("mul_inline(5, 6) =", m)
testcheck.check(m == 30, "mul_inline(5, 6) = 30", "mul_inline result mismatch")
print("")
print("=== Test LLVMIR with LOut ===")
testcheck.section("Test LLVMIR with LOut")
out_val: t.CInt = 0
c.LLVMIR(f"{c.LOut(out_val)} = add i32 {c.LInp(x)}, {c.LInp(y)}", t.CInt)
print("LLVMIR LOut result:", out_val)
testcheck.check(out_val == 30, "LLVMIR LOut (10+20=30)", "LLVMIR LOut result mismatch")
return 0
return testcheck.end()

View File

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

View File

@@ -1 +1 @@
{"main": "3727eb00d15bf59d", "stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "w32.win32process": "067c78e9f121dce3", "win32process": "067c78e9f121dce3", "w32.win32sync": "29813d57621099a9", "win32sync": "29813d57621099a9"}
{"stdint": "49bd8cba55979f76", "main": "4fb8940ff5ab1022", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "w32.win32process": "067c78e9f121dce3", "win32process": "067c78e9f121dce3", "w32.win32sync": "29813d57621099a9", "win32sync": "29813d57621099a9"}

View File

@@ -1 +0,0 @@
{"stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c"}

View File

@@ -0,0 +1 @@
{"stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c"}

View File

@@ -1 +1 @@
{"main": "3727eb00d15bf59d", "stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950"}
{"stdint": "49bd8cba55979f76", "main": "4fb8940ff5ab1022", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c"}

View File

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

View File

@@ -0,0 +1 @@
{"stdint": "49bd8cba55979f76", "main": "4fb8940ff5ab1022", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c"}

View File

@@ -1 +1 @@
{"main": "3727eb00d15bf59d", "stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e"}
{"stdint": "49bd8cba55979f76", "main": "4fb8940ff5ab1022", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e"}

View File

@@ -1 +1 @@
{"main": "3727eb00d15bf59d", "stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950"}
{"stdint": "49bd8cba55979f76", "main": "4fb8940ff5ab1022", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c"}

View File

@@ -1 +1 @@
{"main": "3727eb00d15bf59d", "stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950"}
{"stdint": "49bd8cba55979f76", "main": "4fb8940ff5ab1022", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950"}

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

@@ -7,12 +7,13 @@ Module: main
from stdint import *
import w32.win32console
import t, c
import testcheck
def add_inline(a: t.CInt, b: t.CInt) -> t.CDefine:
pass
return a + b
def mul_inline(a: t.CInt, b: t.CInt) -> t.CDefine:
pass
return a * b
class AppError(Exception):

View 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

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,4 +1,6 @@
3727eb00d15bf59d:main.py
56cdd754a8a09347:includes/stdint.py
49bd8cba55979f76:includes/stdint.py
4fb8940ff5ab1022:main.py
5a6a2137958c28c5:includes/w32\win32base.py
73edbcf76e32d00b:includes/stdio.py
9dbecd0942a39782:includes/testcheck.py
bbdf3bbd4c3bc28c:includes/w32\win32console.py