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

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

@@ -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