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

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

@@ -32,7 +32,7 @@ def main222():
stdio.printf("UU: %s\n", uu_out)
free(uu_out)
hqx_in: list[t.CChar, 4] = ['A', 'B', 'C', '\0']
hqx_in: t.CArray[t.CChar, 4] = ['A', 'B', 'C', '\0']
hqx_crc: t.CUnsignedShort = 0
hqx_out: str
unhqx: str

View File

@@ -35,8 +35,8 @@ def main1() -> t.CInt:
print("原文", plain)
# ---------- Base64 测试 ----------
b64_out: list[t.CChar, 256]
b64_dec: list[t.CUInt8T, 256]
b64_out: t.CArray[t.CChar, 256]
b64_dec: t.CArray[t.CUInt8T, 256]
base64.b64encode(plain, b64_out)
print("Base64 编码:", b64_out)
dlen: t.CSizeT = base64.b64decode(b64_out, b64_dec)
@@ -44,7 +44,7 @@ def main1() -> t.CInt:
print("Base64 解码:", b64_dec)
# ---------- MD5 测试 ----------
md5_buf: list[t.CUInt8T, hashlib.MD5_DIGEST_LEN]
md5_buf: t.CArray[t.CUInt8T, hashlib.MD5_DIGEST_LEN]
mctx = hashlib.md5()
mctx.update(plain)
mctx.final(md5_buf)
@@ -52,7 +52,7 @@ def main1() -> t.CInt:
print_hex(md5_buf, hashlib.MD5_DIGEST_LEN)
# ---------- SHA1 测试 ----------
sha1_buf: list[t.CUInt8T, hashlib.SHA1_DIGEST_LEN]
sha1_buf: t.CArray[t.CUInt8T, hashlib.SHA1_DIGEST_LEN]
s1ctx = hashlib.sha1()
s1ctx.update(plain)
s1ctx.final(sha1_buf)
@@ -60,7 +60,7 @@ def main1() -> t.CInt:
print_hex(sha1_buf, hashlib.SHA1_DIGEST_LEN)
# ---------- SHA256 测试 ----------
sha256_buf: list[t.CUInt8T, hashlib.SHA256_DIGEST_LEN]
sha256_buf: t.CArray[t.CUInt8T, hashlib.SHA256_DIGEST_LEN]
s2ctx = hashlib.sha256()
s2ctx.update(plain)
s2ctx.final(sha256_buf)
@@ -68,7 +68,7 @@ def main1() -> t.CInt:
print_hex(sha256_buf, hashlib.SHA256_DIGEST_LEN)
# ---------- SHA512 测试 ----------
sha512_buf: list[t.CUInt8T, hashlib.SHA512_DIGEST_LEN]
sha512_buf: t.CArray[t.CUInt8T, hashlib.SHA512_DIGEST_LEN]
s5ctx = hashlib.sha512()
s5ctx.update(plain)
s5ctx.final(sha512_buf)

View File

@@ -1,23 +1,216 @@
from stdint import *
import w32.win32console
import config
import HASHLIB
import BINASCII
import zlib.pyzlib as zp
import test_zlib as tpz
import test_numpy as tn
import t, c
def main() -> t.CInt | t.CExport:
w32.win32console.SetConsoleCP(65001)
w32.win32console.SetConsoleOutputCP(65001)
print(zp.runtime_version())
tpz.main123456()
tn.test_numpy_main()
print("END")
import stdio
import stdint
import zc.config as config
import zc.test as test
import zc.logic_test as logic
import zc.class_test as class_test
import testcheck
def main() -> stdint.INT:
testcheck.begin("Hello World!")
testcheck.section("Cross-module macros")
stdio.printf(" POSMAX: %d\n", config.POSMAX)
stdio.printf(" MATH_SCALE: %d\n", config.MATH_SCALE)
stdio.printf(" THRESHOLD: %d\n", config.THRESHOLD)
stdio.printf(" SHIFT_AMOUNT: %d\n", config.SHIFT_AMOUNT)
stdio.printf(" MASK_VALUE: 0x%x\n", config.MASK_VALUE)
testcheck.ok("config macros accessible")
testcheck.section("While Loop Test")
test.AboutSizeTWhileTest(10)
testcheck.ok("While Loop Test (10)")
testcheck.section("Math Basic Test (20, 6)")
test.MathBasicTest(20, 6)
testcheck.ok("Math Basic Test (20, 6)")
testcheck.section("Math Advanced Test (value=15)")
test.MathAdvancedTest(15)
testcheck.ok("Math Advanced Test (value=15)")
testcheck.section("While with Elif-Else Test (-2 to 12)")
test.WhileWithElifElseTest(-2, 12)
testcheck.ok("While with Elif-Else Test (-2 to 12)")
testcheck.section("Nested While with Macros Test")
test.NestedWhileWithMacrosTest(3, 4)
testcheck.ok("Nested While with Macros Test (3, 4)")
testcheck.section("Complex Condition Test (1, 2, 3)")
test.ComplexConditionTest(1, 2, 3)
testcheck.ok("Complex Condition Test (1, 2, 3)")
testcheck.section("Retry Loop Test (8)")
test.RetryLoopTest(8)
testcheck.ok("Retry Loop Test (8)")
testcheck.section("Bitwise Operations Test (0b1101101)")
test.BitwiseOperationsTest(109)
testcheck.ok("Bitwise Operations Test (109)")
testcheck.section("Compound Assignment Math Test (15, 4)")
test.CompoundAssignmentMathTest(15, 4)
testcheck.ok("Compound Assignment Math Test (15, 4)")
testcheck.section("Power and Modulo Test (2, 8)")
test.PowerAndModuloTest(2, 8)
testcheck.ok("Power and Modulo Test (2, 8)")
testcheck.section("Mixed Arithmetic Test (5, 3, 4)")
test.MixedArithmeticTest(5, 3, 4)
testcheck.ok("Mixed Arithmetic Test (5, 3, 4)")
testcheck.section("Math with While Loop Test (start=1, count=5)")
test.MathWithWhileLoopTest(1, 5)
testcheck.ok("Math with While Loop Test (1, 5)")
testcheck.section("Complex Nested Math Test (7, 3)")
test.ComplexNestedMathTest(7, 3)
testcheck.ok("Complex Nested Math Test (7, 3)")
testcheck.section("Conditional Math Chain Test (value=10)")
test.ConditionalMathChainTest(10)
testcheck.ok("Conditional Math Chain Test (value=10)")
testcheck.section("Bit Manipulation Math Test (0xABCD)")
test.BitManipulationMathTest(0xABCD)
testcheck.ok("Bit Manipulation Math Test (0xABCD)")
testcheck.section("COMPLEX LOGIC TESTS")
testcheck.section("For Range Basic Test (stop=5)")
logic.ForRangeBasicTest(5)
testcheck.ok("For Range Basic Test (5)")
testcheck.section("For Range With Start Stop Step (start=1, stop=10, step=2)")
logic.ForRangeWithStartStop(1, 10, 2)
testcheck.ok("For Range With Start Stop (1, 10, 2)")
testcheck.section("Nested For Range Test (rows=2, cols=3)")
logic.NestedForRangeTest(2, 3)
testcheck.ok("Nested For Range Test (2, 3)")
testcheck.section("For With If Break Test (size=8)")
logic.ForWithIfBreakTest(8)
testcheck.ok("For With If Break Test (8)")
testcheck.section("For With If Continue Test (n=10)")
logic.ForWithIfContinueTest(10)
testcheck.ok("For With If Continue Test (10)")
testcheck.section("For With Elif Branch Test (value=10)")
logic.ForWithElifBranchTest(10)
testcheck.ok("For With Elif Branch Test (10)")
testcheck.section("While With If Elif Else Test (iterations=7)")
logic.WhileWithIfElifElseTest(7)
testcheck.ok("While With If Elif Else Test (7)")
testcheck.section("While With Nested If Test (limit=4)")
logic.WhileWithNestedIfTest(4)
testcheck.ok("While With Nested If Test (4)")
testcheck.section("While With Match Case Test (value=2)")
logic.WhileWithMatchCaseTest(2)
testcheck.ok("While With Match Case Test (2)")
testcheck.section("While With Match Case Test (value=99)")
logic.WhileWithMatchCaseTest(99)
testcheck.ok("While With Match Case Test (99)")
testcheck.section("While With Match Case NoBreak Test (value=3)")
logic.WhileWithMatchCaseNoBreakTest(3)
testcheck.ok("While With Match Case NoBreak Test (3)")
testcheck.section("Complex For While Match Test (outer=3, inner=3)")
logic.ComplexForWhileMatchTest(3, 3)
testcheck.ok("Complex For While Match Test (3, 3)")
testcheck.section("For With Case And NoBreak Test (n=5)")
logic.ForWithCaseAndNoBreakTest(5)
testcheck.ok("For With Case And NoBreak Test (5)")
testcheck.section("While With Break Condition Test (limit=6)")
logic.WhileWithBreakConditionTest(6)
testcheck.ok("While With Break Condition Test (6)")
testcheck.section("Nested While With Multiple BreakPoints (depth=3, width=4)")
logic.NestedWhileWithMultipleBreakPoints(3, 4)
testcheck.ok("Nested While With Multiple BreakPoints (3, 4)")
testcheck.section("For With Match Case In Loop Test (iterations=9)")
logic.ForWithMatchCaseInLoopTest(9)
testcheck.ok("For With Match Case In Loop Test (9)")
testcheck.section("Complex Logic With Elif Chains (a=3, b=5, c=7)")
logic.ComplexLogicWithElifChains(3, 5, 7)
testcheck.ok("Complex Logic With Elif Chains (3, 5, 7)")
testcheck.section("For Range With Step And Condition (n=12, step=2)")
logic.ForRangeWithStepAndCondition(12, 2)
testcheck.ok("For Range With Step And Condition (12, 2)")
testcheck.section("Match Case With Guard Conditions (value=1)")
logic.MatchCaseWithGuardConditions(1)
testcheck.ok("Match Case With Guard Conditions (1)")
testcheck.section("While With Multiple Match Cases (iterations=12)")
logic.WhileWithMultipleMatchCases(12)
testcheck.ok("While With Multiple Match Cases (12)")
testcheck.section("For While Mix With Break And Continue (n=5)")
logic.ForWhileMixWithBreakAndContinue(5)
testcheck.ok("For While Mix With Break And Continue (5)")
testcheck.section("Complex Case Matching With Ranges (start=0, end=35)")
logic.ComplexCaseMatchingWithRanges(0, 35)
testcheck.ok("Complex Case Matching With Ranges (0, 35)")
testcheck.section("While With Elif In Elif Chain (limit=7)")
logic.WhileWithElifInElifChain(7)
testcheck.ok("While With Elif In Elif Chain (7)")
testcheck.section("For With Case NoBreak Nested (inner_limit=4)")
logic.ForWithCaseNoBreakNested(4)
testcheck.ok("For With Case NoBreak Nested (4)")
testcheck.section("CLASS TESTS")
class_test.TestBasicDataClass()
testcheck.ok("TestBasicDataClass")
class_test.TestPoint3DClass()
testcheck.ok("TestPoint3DClass")
class_test.TestStudentClass()
testcheck.ok("TestStudentClass")
class_test.TestCounterClass()
testcheck.ok("TestCounterClass")
class_test.TestStackAllocation()
testcheck.ok("TestStackAllocation")
class_test.TestHeapAllocation()
testcheck.ok("TestHeapAllocation")
class_test.TestHeapObjectWithInit()
testcheck.ok("TestHeapObjectWithInit")
class_test.TestMultipleStackObjects()
testcheck.ok("TestMultipleStackObjects")
class_test.TestImplicitInitCall()
testcheck.ok("TestImplicitInitCall")
class_test.TestClassWithBitFields()
testcheck.ok("TestClassWithBitFields")
testcheck.section("ARRAY TESTS")
class_test.TestIntArray()
testcheck.ok("TestIntArray")
class_test.TestFloatArray()
testcheck.ok("TestFloatArray")
class_test.TestCharArray()
testcheck.ok("TestCharArray")
class_test.TestNestedArray()
testcheck.ok("TestNestedArray")
class_test.TestArrayWithStruct()
testcheck.ok("TestArrayWithStruct")
class_test.TestArrayPointer()
testcheck.ok("TestArrayPointer")
class_test.TestDynamicString()
testcheck.ok("TestDynamicString")
return testcheck.end()

View File

@@ -10,7 +10,7 @@ import string
import mpool
import t, c
pool: mpool.MPool | t.CPtr = None
pool: t.CPtr = None
test_passed: t.CInt = 0
test_failed: t.CInt = 0
@@ -616,7 +616,7 @@ def test_huffman_tree():
printf(" All 32 distance codes: 5 bits each\n")
printf("\n --- Dynamic Huffman tree from frequencies ---\n")
freqs: list[t.CInt, 256]
freqs: t.CArray[t.CInt, 257]
memset(freqs, 0, freqs.__sizeof__())
freqs['A'] = 50
freqs['B'] = 25
@@ -646,8 +646,8 @@ def test_huffman_tree():
printf(" Active codes: %d, max code lengthgth: %d\n", total_codes, max_length_found)
printf(" Code assignments:\n")
names: list[str, None] = ["A","B","C","D","E","F"] # 一个都是char* 的数组
syms: list[t.CInt, None] = ['A','B','C','D','E','F']
names: t.CArray[str, None] = ["A","B","C","D","E","F"] # 一个都是char* 的数组
syms: t.CArray[t.CInt, None] = ['A','B','C','D','E','F']
for i in range(6):
printf(" '%s' (freq=%3d): code=0x%04X, bits=%d\n",
names[i], freqs[syms[i]],
@@ -665,7 +665,7 @@ def test_huffman_tree():
a_bits, f_bits, "YES" if (a_bits <= f_bits) else "NO")
printf("\n --- Huffman encode/decode roundtrip ---\n")
freqs: list[t.CInt, 288]
freqs: t.CArray[t.CInt, 288]
memset(freqs, 0, freqs.__sizeof__())
freqs['H'] = 10
freqs['e'] = 8
@@ -686,7 +686,7 @@ def test_huffman_tree():
writer = zdef.zbit_writer()
symbols: list[t.CInt, 16]
symbols: t.CArray[t.CInt, 16]
symbols[0] = 'H'; symbols[1] = 'e'; symbols[2] = 'l'; symbols[3] = 'l'
symbols[4] = 'o'; symbols[5] = ' '; symbols[6] = 'W'; symbols[7] = 'o'
symbols[8] = 'r'; symbols[9] = 'l'; symbols[10] = 'd'; symbols[11] = '!'
@@ -716,7 +716,7 @@ def test_huffman_tree():
free(writer.buf)
printf("\n --- Overflow handling (many symbols, limited max_bits) ---\n")
freqs: list[t.CInt, 256]
freqs: t.CArray[t.CInt, 257]
for i in range(256):
freqs[i] = 1
freqs[256] = 1
@@ -731,7 +731,7 @@ def test_huffman_tree():
break
check("all code lengthgths <= 15 with 257 symbols", overflow_ok, "code lengthgth overflow")
bl_count: list[t.CInt, 16] = [0]
bl_count: t.CArray[t.CInt, 16] = [0]
for i in range(257):
if tree.codes[i].bits > 0:
bl_count[tree.codes[i].bits] += 1
@@ -769,7 +769,7 @@ def test_huffman_tree():
printf("\n --- Kraft inequality check ---\n")
freqs: list[t.CInt, 256]
freqs: t.CArray[t.CInt, 257]
memset(freqs, 0, freqs.__sizeof__())
freqs['X'] = 100
freqs['Y'] = 50