修复了大量存在的问题,增加了假鸭子类型等等机制
This commit is contained in:
20
TODO
20
TODO
@@ -1,7 +1,23 @@
|
||||
更复杂的 泛型
|
||||
函数装饰器
|
||||
main 收集
|
||||
main 收集(和 导入模块的自动执行)
|
||||
元类型
|
||||
@p.set
|
||||
函数的描述符用装饰器而不是返回值
|
||||
崩溃/返回作用域 回调
|
||||
崩溃/返回作用域 回调
|
||||
假鸭子
|
||||
# f-string 自动 snprintf
|
||||
__doc__
|
||||
自动索引
|
||||
testcheck默认中文
|
||||
|
||||
vdebug 工具和 vsdt 工具
|
||||
多态 ops 允许单个函数拥有装饰器(可修改,走函数指针)
|
||||
协程关键字支持
|
||||
with出入多态
|
||||
哈希表
|
||||
内联快速迭代器
|
||||
出栈调用函数
|
||||
构造函数隐式参数
|
||||
小数组直接栈上创建+ i in [xxx]
|
||||
字符串索引
|
||||
|
||||
12
Test/BuddyTest/App/main.py
Normal file
12
Test/BuddyTest/App/main.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from stdint import *
|
||||
import w32.win32console
|
||||
import t, c
|
||||
from t import CInt, CExport
|
||||
import mbuddytest
|
||||
|
||||
|
||||
def main() -> CInt | CExport:
|
||||
w32.win32console.SetConsoleCP(65001)
|
||||
w32.win32console.SetConsoleOutputCP(65001)
|
||||
|
||||
return mbuddytest.mbuddy_main()
|
||||
535
Test/BuddyTest/App/mbuddytest.py
Normal file
535
Test/BuddyTest/App/mbuddytest.py
Normal file
@@ -0,0 +1,535 @@
|
||||
import t, c
|
||||
from t import CInt, CPtr, CChar, CUInt8T, CUInt32T, CUInt64T, CSizeT
|
||||
import viperlib
|
||||
import viperio
|
||||
import stdlib
|
||||
import mbuddy
|
||||
import string
|
||||
import testcheck
|
||||
import w32.win32process
|
||||
import w32.win32sync
|
||||
import w32.win32base
|
||||
|
||||
|
||||
# 线程函数: 在共享 MBuddy 上执行 alloc/free (测试 spinlock 线程安全)
|
||||
def _thread_alloc_free(param: t.CVoid | t.CPtr) -> t.CUInt32T:
|
||||
bd: mbuddy.MBuddy | t.CPtr = (mbuddy.MBuddy | t.CPtr)(param)
|
||||
i: CInt
|
||||
for i in range(100):
|
||||
p: bytes = bd.alloc(32)
|
||||
if p != None:
|
||||
p_c: CUInt8T | CPtr = CPtr(p)
|
||||
p_c[0] = CUInt8T(i & 0xFF)
|
||||
bd.free(p)
|
||||
return 0
|
||||
|
||||
|
||||
def mbuddy_main() -> CInt:
|
||||
buf: bytes = stdlib.malloc(256)
|
||||
|
||||
testcheck.begin("BuddyTest: 伙伴系统内存分配器测试")
|
||||
|
||||
# === 基础 alloc/free 测试 ===
|
||||
testcheck.section("基础 alloc/free")
|
||||
arena: bytes = stdlib.malloc(65536)
|
||||
bd: mbuddy.MBuddy | CPtr = mbuddy.MBuddy(arena, 65536)
|
||||
|
||||
viperlib.snprintf(buf, 256, "stats=%lu, free_count=%lu", bd.stats(), bd.free_count())
|
||||
testcheck.info(buf)
|
||||
|
||||
p1: bytes = bd.alloc(16)
|
||||
p2: bytes = bd.alloc(64)
|
||||
p3: bytes = bd.alloc(256)
|
||||
testcheck.check(p1 != None and p2 != None and p3 != None,
|
||||
"3 allocs OK", "alloc FAILED")
|
||||
|
||||
# 写入数据验证指针可用
|
||||
p_c: CUInt8T | CPtr = CPtr(p1)
|
||||
p_c[0] = CUInt8T(0xAB)
|
||||
p_c[1] = CUInt8T(0xCD)
|
||||
viperlib.snprintf(buf, 256, "p1[0]=0x%x p1[1]=0x%x", p_c[0], p_c[1])
|
||||
testcheck.info(buf)
|
||||
testcheck.check(p_c[0] == CUInt8T(0xAB) and p_c[1] == CUInt8T(0xCD),
|
||||
"write/read OK", "write/read FAILED")
|
||||
|
||||
bd.free(p1)
|
||||
bd.free(p2)
|
||||
bd.free(p3)
|
||||
testcheck.ok("3 frees OK")
|
||||
|
||||
# 释放后验证合并: free_count 应回到 1 (单个大块)
|
||||
testcheck.check(bd.free_count() == 1,
|
||||
"coalesce: free_count=1 OK", "coalesce: free_count != 1")
|
||||
|
||||
# 合并后应能分配大块
|
||||
big: bytes = bd.alloc(16000)
|
||||
testcheck.check(big != None, "big alloc OK", "big alloc FAILED")
|
||||
bd.free(big)
|
||||
|
||||
stdlib.free(arena)
|
||||
|
||||
# === calloc 测试 (验证清零) ===
|
||||
testcheck.section("calloc 清零")
|
||||
arena2: bytes = stdlib.malloc(4096)
|
||||
bd2: mbuddy.MBuddy | CPtr = mbuddy.MBuddy(arena2, 4096)
|
||||
|
||||
dirty: bytes = bd2.alloc(64)
|
||||
d_c: CUInt8T | CPtr = CPtr(dirty)
|
||||
i: CInt
|
||||
for i in range(64):
|
||||
d_c[i] = CUInt8T(0xFF)
|
||||
bd2.free(dirty)
|
||||
|
||||
cl: bytes = bd2.calloc(8, 8)
|
||||
if cl != None:
|
||||
cl_c: CUInt8T | CPtr = CPtr(cl)
|
||||
all_zero: CInt = 1
|
||||
j: CInt
|
||||
for j in range(64):
|
||||
if cl_c[j] != 0:
|
||||
all_zero = 0
|
||||
break
|
||||
testcheck.check(all_zero == 1, "calloc zeroed OK", "calloc NOT zeroed")
|
||||
bd2.free(cl)
|
||||
else:
|
||||
testcheck.fail("calloc FAILED")
|
||||
|
||||
stdlib.free(arena2)
|
||||
|
||||
# === realloc 扩展测试 ===
|
||||
testcheck.section("realloc 扩展")
|
||||
arena3: bytes = stdlib.malloc(4096)
|
||||
bd3: mbuddy.MBuddy | CPtr = mbuddy.MBuddy(arena3, 4096)
|
||||
|
||||
rp: bytes = bd3.alloc(32)
|
||||
rp_c: CUInt8T | CPtr = CPtr(rp)
|
||||
k: CInt
|
||||
for k in range(32):
|
||||
rp_c[k] = CUInt8T(k + 1)
|
||||
|
||||
rp2: bytes = bd3.realloc(rp, 128)
|
||||
if rp2 != None:
|
||||
rp2_c: CUInt8T | CPtr = CPtr(rp2)
|
||||
ok: CInt = 1
|
||||
m: CInt
|
||||
for m in range(32):
|
||||
if rp2_c[m] != CUInt8T(m + 1):
|
||||
ok = 0
|
||||
break
|
||||
testcheck.check(ok == 1, "realloc grow data preserved OK", "realloc grow data LOST")
|
||||
bd3.free(rp2)
|
||||
else:
|
||||
testcheck.fail("realloc grow FAILED")
|
||||
|
||||
stdlib.free(arena3)
|
||||
|
||||
# === 原地收缩测试 (验证无泄漏) ===
|
||||
testcheck.section("原地收缩 (realloc shrink)")
|
||||
arena_shrink: bytes = stdlib.malloc(4096)
|
||||
bds: mbuddy.MBuddy | CPtr = mbuddy.MBuddy(arena_shrink, 4096)
|
||||
|
||||
sp: bytes = bds.alloc(256)
|
||||
testcheck.check(sp != None, "alloc 256 OK", "alloc 256 FAILED")
|
||||
|
||||
fc_before: CSizeT = bds.free_count()
|
||||
# realloc 到更小尺寸: 256+8=264 -> order 4 (512); 32+8=40 -> order 1 (64)
|
||||
# new_order(1) <= old_order(4), 应原地返回同一指针
|
||||
sp2: bytes = bds.realloc(sp, 32)
|
||||
fc_after: CSizeT = bds.free_count()
|
||||
|
||||
testcheck.check(sp2 == sp, "shrink same ptr OK", "shrink ptr changed")
|
||||
testcheck.check(fc_after == fc_before, "shrink no leak OK", "shrink LEAKED blocks")
|
||||
|
||||
# 验证数据仍可读写
|
||||
sp_c: CUInt8T | CPtr = CPtr(sp2)
|
||||
sp_c[0] = CUInt8T(0x42)
|
||||
testcheck.check(sp_c[0] == CUInt8T(0x42), "shrink data OK", "shrink data FAILED")
|
||||
|
||||
bds.free(sp2)
|
||||
testcheck.check(bds.free_count() == 1, "shrink+free coalesce OK", "shrink+free coalesce FAILED")
|
||||
|
||||
stdlib.free(arena_shrink)
|
||||
|
||||
# === 边界情况测试 ===
|
||||
testcheck.section("边界情况")
|
||||
arena4: bytes = stdlib.malloc(4096)
|
||||
bd4: mbuddy.MBuddy | CPtr = mbuddy.MBuddy(arena4, 4096)
|
||||
|
||||
# alloc(0) 应返回 None
|
||||
z: bytes = bd4.alloc(0)
|
||||
testcheck.check(z == None, "alloc(0)=None OK", "alloc(0) should be None")
|
||||
|
||||
# free(None) 应安全
|
||||
bd4.free(None)
|
||||
testcheck.ok("free(None) safe")
|
||||
|
||||
# realloc(None, size) 等价于 alloc
|
||||
rn: bytes = bd4.realloc(None, 32)
|
||||
testcheck.check(rn != None, "realloc(None)=alloc OK", "realloc(None) FAILED")
|
||||
bd4.free(rn)
|
||||
|
||||
# realloc(ptr, 0) 等价于 free
|
||||
rz: bytes = bd4.alloc(32)
|
||||
rz2: bytes = bd4.realloc(rz, 0)
|
||||
testcheck.check(rz2 == None, "realloc(ptr,0)=free OK", "realloc(ptr,0) should be None")
|
||||
|
||||
stdlib.free(arena4)
|
||||
|
||||
# === 非法指针防护测试 ===
|
||||
testcheck.section("非法指针防护")
|
||||
arena5: bytes = stdlib.malloc(4096)
|
||||
bd5: mbuddy.MBuddy | CPtr = mbuddy.MBuddy(arena5, 4096)
|
||||
|
||||
valid: bytes = bd5.alloc(32)
|
||||
testcheck.check(valid != None, "alloc for illegal test OK", "alloc FAILED")
|
||||
|
||||
# 1. free 随机地址 (地址 1)
|
||||
bd5.free(t.CVoid(t.CUInt64T(1), t.CPtr))
|
||||
testcheck.ok("free(addr=1) ignored")
|
||||
|
||||
# 2. free NULL
|
||||
bd5.free(None)
|
||||
testcheck.ok("free(NULL) ignored")
|
||||
|
||||
# 3. free 越界指针 (arena 之前)
|
||||
bd5.free(t.CVoid(t.CUInt64T(arena5), t.CPtr))
|
||||
testcheck.ok("free(before arena) ignored")
|
||||
|
||||
# 4. free 越界指针 (arena 之后)
|
||||
bd5.free(t.CVoid(t.CUInt64T(arena5) + 99999, t.CPtr))
|
||||
testcheck.ok("free(after arena) ignored")
|
||||
|
||||
# 5. free 未对齐指针 (arena + 1, 在 mem 区域内但不对齐)
|
||||
bd5.free(t.CVoid(t.CUInt64T(bd5.mem) + 1, t.CPtr))
|
||||
testcheck.ok("free(misaligned) ignored")
|
||||
|
||||
# 6. 验证合法 free 仍正常工作 (释放后应能再次分配)
|
||||
bd5.free(valid)
|
||||
retry5: bytes = bd5.alloc(32)
|
||||
testcheck.check(retry5 != None, "valid free still works OK", "valid free BROKEN")
|
||||
if retry5 != None:
|
||||
bd5.free(retry5)
|
||||
|
||||
# 7. realloc 非法指针应返回 None
|
||||
r_illegal: bytes = bd5.realloc(t.CVoid(t.CUInt64T(1), t.CPtr), 64)
|
||||
testcheck.check(r_illegal == None, "realloc(illegal)=None OK", "realloc(illegal) should be None")
|
||||
|
||||
stdlib.free(arena5)
|
||||
|
||||
# === OOM 内存耗尽测试 ===
|
||||
testcheck.section("OOM 内存耗尽")
|
||||
arena6: bytes = stdlib.malloc(4096)
|
||||
bd6: mbuddy.MBuddy | CPtr = mbuddy.MBuddy(arena6, 4096)
|
||||
|
||||
# 持续分配直到失败
|
||||
alloc_count: CInt = 0
|
||||
ptrs_arr: bytes = stdlib.malloc(8 * 256) # 存储指针的数组
|
||||
ptrs: CUInt64T | CPtr = CPtr(ptrs_arr)
|
||||
|
||||
while alloc_count < 256:
|
||||
p: bytes = bd6.alloc(32)
|
||||
if p == None:
|
||||
break
|
||||
ptrs[alloc_count] = t.CUInt64T(p)
|
||||
alloc_count += 1
|
||||
|
||||
viperlib.snprintf(buf, 256, "allocated %d blocks before OOM", alloc_count)
|
||||
testcheck.info(buf)
|
||||
testcheck.check(alloc_count > 0, "OOM: got some allocs OK", "OOM: no allocs at all")
|
||||
|
||||
# 尝试再分配应失败
|
||||
oom_p: bytes = bd6.alloc(32)
|
||||
testcheck.check(oom_p == None, "OOM: alloc fails OK", "OOM: alloc should fail")
|
||||
|
||||
# 释放一个块后应能再次分配
|
||||
if alloc_count > 0:
|
||||
first_ptr: bytes = t.CVoid(ptrs[0], t.CPtr)
|
||||
bd6.free(first_ptr)
|
||||
retry: bytes = bd6.alloc(32)
|
||||
testcheck.check(retry != None, "OOM: free+alloc OK", "OOM: free+alloc FAILED")
|
||||
if retry != None:
|
||||
bd6.free(retry)
|
||||
|
||||
# 释放所有块
|
||||
idx: CInt = 1
|
||||
while idx < alloc_count:
|
||||
cur_p: bytes = t.CVoid(ptrs[idx], t.CPtr)
|
||||
bd6.free(cur_p)
|
||||
idx += 1
|
||||
|
||||
# 全部释放后应能合并回单个大块
|
||||
testcheck.check(bd6.free_count() == 1,
|
||||
"OOM: full coalesce OK", "OOM: free_count != 1 after full free")
|
||||
|
||||
stdlib.free(ptrs_arr)
|
||||
stdlib.free(arena6)
|
||||
|
||||
# === 空闲链表状态测试 ===
|
||||
testcheck.section("空闲链表状态")
|
||||
arena7: bytes = stdlib.malloc(4096)
|
||||
bd7: mbuddy.MBuddy | CPtr = mbuddy.MBuddy(arena7, 4096)
|
||||
|
||||
# 初始: 1 个大块
|
||||
testcheck.check(bd7.free_count() == 1, "init: 1 free block OK", "init: free_count != 1")
|
||||
|
||||
# 分配后: 空闲块数应增加 (分裂产生多个小块)
|
||||
a1: bytes = bd7.alloc(32)
|
||||
fc1: CSizeT = bd7.free_count()
|
||||
viperlib.snprintf(buf, 256, "after alloc(32): free_count=%lu", fc1)
|
||||
testcheck.info(buf)
|
||||
testcheck.check(fc1 > 1, "after alloc: split OK", "after alloc: no split")
|
||||
|
||||
# 再分配
|
||||
a2: bytes = bd7.alloc(32)
|
||||
fc2: CSizeT = bd7.free_count()
|
||||
testcheck.check(fc2 >= 1, "after 2nd alloc: free >= 1 OK", "after 2nd alloc: free < 1")
|
||||
|
||||
# 释放 a1: 空闲块数应增加
|
||||
bd7.free(a1)
|
||||
fc3: CSizeT = bd7.free_count()
|
||||
testcheck.check(fc3 > fc2, "after free a1: free increased OK", "after free a1: free not increased")
|
||||
|
||||
# 释放 a2: 应合并, 空闲块数回到 1
|
||||
bd7.free(a2)
|
||||
testcheck.check(bd7.free_count() == 1,
|
||||
"after free all: coalesced to 1 OK", "after free all: free_count != 1")
|
||||
|
||||
stdlib.free(arena7)
|
||||
|
||||
# === with 上下文管理器测试 ===
|
||||
testcheck.section("with 上下文管理器")
|
||||
arena8: bytes = stdlib.malloc(4096)
|
||||
with mbuddy.MBuddy(arena8, 4096) as wbd:
|
||||
wp1: bytes = wbd.alloc(32)
|
||||
wp2: bytes = wbd.alloc(64)
|
||||
testcheck.check(wp1 != None and wp2 != None,
|
||||
"with: allocs OK", "with: allocs FAILED")
|
||||
# 退出 with 块时 __exit__ 自动 reset
|
||||
|
||||
# 退出后重新进入,验证 reset 生效
|
||||
with mbuddy.MBuddy(arena8, 4096) as wbd2:
|
||||
wp3: bytes = wbd2.alloc(1024)
|
||||
testcheck.check(wp3 != None, "with: reset+realloc OK", "with: reset+realloc FAILED")
|
||||
|
||||
stdlib.free(arena8)
|
||||
|
||||
# === 双重 free 检测测试 ===
|
||||
testcheck.section("双重 free 检测")
|
||||
arena_df: bytes = stdlib.malloc(4096)
|
||||
bd_df: mbuddy.MBuddy | CPtr = mbuddy.MBuddy(arena_df, 4096)
|
||||
|
||||
df: bytes = bd_df.alloc(64)
|
||||
testcheck.check(df != None, "df: alloc OK", "df: alloc FAILED")
|
||||
|
||||
# 第一次 free
|
||||
bd_df.free(df)
|
||||
fc_df1: CSizeT = bd_df.free_count()
|
||||
testcheck.ok("first free OK")
|
||||
|
||||
# 第二次 free (双重 free) — 应被静默拒绝
|
||||
bd_df.free(df)
|
||||
fc_df2: CSizeT = bd_df.free_count()
|
||||
testcheck.check(fc_df2 == fc_df1, "double free rejected OK", "double free CORRUPTED state")
|
||||
|
||||
# 验证分配器仍正常工作
|
||||
df2: bytes = bd_df.alloc(64)
|
||||
testcheck.check(df2 != None, "df: alloc after double-free OK", "df: alloc after double-free FAILED")
|
||||
if df2 != None:
|
||||
bd_df.free(df2)
|
||||
|
||||
stdlib.free(arena_df)
|
||||
|
||||
# === 自检功能测试 ===
|
||||
testcheck.section("自检功能")
|
||||
arena_sc: bytes = stdlib.malloc(4096)
|
||||
bd_sc: mbuddy.MBuddy | CPtr = mbuddy.MBuddy(arena_sc, 4096)
|
||||
|
||||
# 初始状态自检
|
||||
testcheck.check(bd_sc.self_check() == 0, "self_check init OK", "self_check init FAILED")
|
||||
|
||||
# 分配后自检
|
||||
sc_p1: bytes = bd_sc.alloc(32)
|
||||
sc_p2: bytes = bd_sc.alloc(128)
|
||||
testcheck.check(bd_sc.self_check() == 0, "self_check after alloc OK", "self_check after alloc FAILED")
|
||||
|
||||
# 部分释放后自检
|
||||
bd_sc.free(sc_p1)
|
||||
testcheck.check(bd_sc.self_check() == 0, "self_check after partial free OK", "self_check after partial free FAILED")
|
||||
|
||||
# 全部释放后自检 (应合并回单个大块)
|
||||
bd_sc.free(sc_p2)
|
||||
testcheck.check(bd_sc.self_check() == 0, "self_check after full free OK", "self_check after full free FAILED")
|
||||
|
||||
# 双重 free 后自检 (验证状态未损坏)
|
||||
sc_p3: bytes = bd_sc.alloc(64)
|
||||
bd_sc.free(sc_p3)
|
||||
bd_sc.free(sc_p3) # 双重 free,应被拒绝
|
||||
testcheck.check(bd_sc.self_check() == 0, "self_check after double-free OK", "self_check after double-free CORRUPTED")
|
||||
|
||||
stdlib.free(arena_sc)
|
||||
|
||||
# === 并发多线程测试 (spinlock) ===
|
||||
testcheck.section("并发多线程 (spinlock)")
|
||||
arena_mt: bytes = stdlib.malloc(65536)
|
||||
bd_mt: mbuddy.MBuddy | CPtr = mbuddy.MBuddy(arena_mt, 65536)
|
||||
|
||||
NUM_THREADS: CInt = 4
|
||||
handles_arr: bytes = stdlib.malloc(8 * 4)
|
||||
handles: CUInt64T | CPtr = CPtr(handles_arr)
|
||||
tid: CUInt32T = 0
|
||||
|
||||
# 创建 4 个线程并发 alloc/free
|
||||
t_idx: CInt
|
||||
for t_idx in range(NUM_THREADS):
|
||||
h: bytes = w32.win32process.CreateThread(None, 0, _thread_alloc_free, t.CVoid(t.CUInt64T(bd_mt), t.CPtr), 0, c.Addr(tid))
|
||||
handles[t_idx] = CUInt64T(h)
|
||||
|
||||
# 等待所有线程完成
|
||||
for t_idx in range(NUM_THREADS):
|
||||
h: bytes = t.CVoid(handles[t_idx], t.CPtr)
|
||||
w32.win32sync.WaitForSingleObject(h, w32.win32base.INFINITE)
|
||||
w32.win32base.CloseHandle(h)
|
||||
|
||||
# 验证分配器状态: 自检通过,所有块已合并
|
||||
testcheck.check(bd_mt.self_check() == 0, "mt: self_check OK", "mt: self_check FAILED")
|
||||
testcheck.check(bd_mt.free_count() == 1, "mt: free_count=1 OK", "mt: free_count != 1 (leaked)")
|
||||
|
||||
viperlib.snprintf(buf, 256, "mt: free_count=%lu", bd_mt.free_count())
|
||||
testcheck.info(buf)
|
||||
|
||||
stdlib.free(handles_arr)
|
||||
stdlib.free(arena_mt)
|
||||
|
||||
# === 极端边界测试 ===
|
||||
testcheck.section("极端边界")
|
||||
|
||||
# 1. 分配尺寸恰巧是块边界
|
||||
arena_ex: bytes = stdlib.malloc(4096)
|
||||
bd_ex: mbuddy.MBuddy | CPtr = mbuddy.MBuddy(arena_ex, 4096)
|
||||
|
||||
# 24 + 8 = 32 = MIN_BLOCK, 恰好填满 order 0 块
|
||||
exact_fit: bytes = bd_ex.alloc(24)
|
||||
testcheck.check(exact_fit != None, "exact fit order 0 OK", "exact fit order 0 FAILED")
|
||||
|
||||
# 25 + 8 = 33 > 32, 需要 order 1 (64 字节)
|
||||
over_fit: bytes = bd_ex.alloc(25)
|
||||
testcheck.check(over_fit != None, "over by 1 byte OK", "over by 1 byte FAILED")
|
||||
|
||||
bd_ex.free(exact_fit)
|
||||
bd_ex.free(over_fit)
|
||||
testcheck.check(bd_ex.free_count() == 1, "boundary: coalesce OK", "boundary: coalesce FAILED")
|
||||
|
||||
# 2. 单次分配接近 arena 上限
|
||||
max_usable: CSizeT = bd_ex.mem_size - 8
|
||||
viperlib.snprintf(buf, 256, "mem_size=%lu, max_usable=%lu", bd_ex.mem_size, max_usable)
|
||||
testcheck.info(buf)
|
||||
|
||||
# 恰好用完整个 arena
|
||||
exact_max: bytes = bd_ex.alloc(max_usable)
|
||||
testcheck.check(exact_max != None, "exact max alloc OK", "exact max alloc FAILED")
|
||||
testcheck.check(bd_ex.free_count() == 0, "max alloc: arena full OK", "max alloc: arena not full")
|
||||
|
||||
bd_ex.free(exact_max)
|
||||
testcheck.check(bd_ex.free_count() == 1, "max free: coalesce OK", "max free: coalesce FAILED")
|
||||
|
||||
# 再次分配同样大小 — 验证合并后可再次使用
|
||||
exact_max2: bytes = bd_ex.alloc(max_usable)
|
||||
testcheck.check(exact_max2 != None, "exact max re-alloc OK", "exact max re-alloc FAILED")
|
||||
bd_ex.free(exact_max2)
|
||||
|
||||
# 3. 分配超过 arena 上限 — 应失败
|
||||
over_max: bytes = bd_ex.alloc(bd_ex.mem_size)
|
||||
testcheck.check(over_max == None, "over max: fails OK", "over max: should fail")
|
||||
|
||||
over_max2: bytes = bd_ex.alloc(max_usable + 1)
|
||||
testcheck.check(over_max2 == None, "max+1: fails OK", "max+1: should fail")
|
||||
|
||||
stdlib.free(arena_ex)
|
||||
|
||||
# 4. Arena 太小 (仅够 free_lists 开销, 264 字节)
|
||||
arena_tiny: bytes = stdlib.malloc(264)
|
||||
bd_tiny: mbuddy.MBuddy | CPtr = mbuddy.MBuddy(arena_tiny, 264)
|
||||
testcheck.check(bd_tiny.stats() == 0, "tiny arena: stats=0 OK", "tiny arena: stats != 0")
|
||||
tiny_p: bytes = bd_tiny.alloc(32)
|
||||
testcheck.check(tiny_p == None, "tiny arena: alloc fails OK", "tiny arena: should fail")
|
||||
stdlib.free(arena_tiny)
|
||||
|
||||
# 5. Arena 刚好够一个最小块 (264 + 32 = 296)
|
||||
arena_one: bytes = stdlib.malloc(296)
|
||||
bd_one: mbuddy.MBuddy | CPtr = mbuddy.MBuddy(arena_one, 296)
|
||||
testcheck.check(bd_one.stats() == 32, "one block: stats=32 OK", "one block: stats != 32")
|
||||
|
||||
one_p: bytes = bd_one.alloc(24)
|
||||
testcheck.check(one_p != None, "one block: alloc OK", "one block: alloc FAILED")
|
||||
|
||||
one_p2: bytes = bd_one.alloc(24)
|
||||
testcheck.check(one_p2 == None, "one block: OOM OK", "one block: should be OOM")
|
||||
|
||||
bd_one.free(one_p)
|
||||
testcheck.check(bd_one.free_count() == 1, "one block: free OK", "one block: free FAILED")
|
||||
stdlib.free(arena_one)
|
||||
|
||||
# 6. 2 的幂 arena vs 非 2 的幂 arena
|
||||
arena_pow2: bytes = stdlib.malloc(512)
|
||||
bd_pow2: mbuddy.MBuddy | CPtr = mbuddy.MBuddy(arena_pow2, 512)
|
||||
# 512 - 264 = 248, largest_pow2(248) = 128
|
||||
testcheck.check(bd_pow2.stats() == 128, "pow2 arena: stats=128 OK", "pow2 arena: stats != 128")
|
||||
stdlib.free(arena_pow2)
|
||||
|
||||
arena_non2: bytes = stdlib.malloc(500)
|
||||
bd_non2: mbuddy.MBuddy | CPtr = mbuddy.MBuddy(arena_non2, 500)
|
||||
# 500 - 264 = 236, largest_pow2(236) = 128
|
||||
testcheck.check(bd_non2.stats() == 128, "non-pow2 arena: stats=128 OK", "non-pow2 arena: stats != 128")
|
||||
stdlib.free(arena_non2)
|
||||
|
||||
# 7. 压力测试: 反复 alloc/free 同一尺寸 1000 次
|
||||
arena_stress: bytes = stdlib.malloc(4096)
|
||||
bd_stress: mbuddy.MBuddy | CPtr = mbuddy.MBuddy(arena_stress, 4096)
|
||||
|
||||
s: CInt
|
||||
for s in range(1000):
|
||||
sp: bytes = bd_stress.alloc(64)
|
||||
if sp != None:
|
||||
sp_c: CUInt8T | CPtr = CPtr(sp)
|
||||
sp_c[0] = CUInt8T(s & 0xFF)
|
||||
bd_stress.free(sp)
|
||||
|
||||
testcheck.check(bd_stress.self_check() == 0, "stress: self_check OK", "stress: self_check FAILED")
|
||||
testcheck.check(bd_stress.free_count() == 1, "stress: free_count=1 OK", "stress: leaked")
|
||||
stdlib.free(arena_stress)
|
||||
|
||||
# 8. 分配全部最小块然后全部释放
|
||||
arena_fill: bytes = stdlib.malloc(4096)
|
||||
bd_fill: mbuddy.MBuddy | CPtr = mbuddy.MBuddy(arena_fill, 4096)
|
||||
|
||||
fill_count: CInt = 0
|
||||
fill_ptrs_arr: bytes = stdlib.malloc(8 * 256)
|
||||
fill_ptrs: CUInt64T | CPtr = CPtr(fill_ptrs_arr)
|
||||
|
||||
fc: CInt
|
||||
for fc in range(256):
|
||||
fp: bytes = bd_fill.alloc(24)
|
||||
if fp == None:
|
||||
break
|
||||
fill_ptrs[fill_count] = t.CUInt64T(fp)
|
||||
fill_count += 1
|
||||
|
||||
viperlib.snprintf(buf, 256, "fill: %d min blocks allocated", fill_count)
|
||||
testcheck.info(buf)
|
||||
testcheck.check(fill_count > 0, "fill: got blocks OK", "fill: no blocks")
|
||||
testcheck.check(bd_fill.self_check() == 0, "fill: self_check OK", "fill: self_check FAILED")
|
||||
|
||||
# 全部释放
|
||||
fi: CInt
|
||||
for fi in range(fill_count):
|
||||
fp2: bytes = t.CVoid(fill_ptrs[fi], t.CPtr)
|
||||
bd_fill.free(fp2)
|
||||
|
||||
testcheck.check(bd_fill.free_count() == 1, "fill: all freed OK", "fill: leaked after free all")
|
||||
testcheck.check(bd_fill.self_check() == 0, "fill: self_check after free OK", "fill: self_check FAILED")
|
||||
|
||||
stdlib.free(fill_ptrs_arr)
|
||||
stdlib.free(arena_fill)
|
||||
|
||||
stdlib.free(buf)
|
||||
return testcheck.end()
|
||||
1
Test/BuddyTest/output/067c78e9f121dce3.deps.json
Normal file
1
Test/BuddyTest/output/067c78e9f121dce3.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"w32.win32process": "067c78e9f121dce3", "win32process": "067c78e9f121dce3", "atom": "271ea3decb810db2", "w32.win32sync": "29813d57621099a9", "win32sync": "29813d57621099a9", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "main": "5e430ae5bf7af3a2", "stdlib": "6c2029b306556c00", "viperlib": "70b580331b822117", "stdarg": "71e0a3ffcb3ebfad", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "mbuddytest": "c53a157505aa8081", "viperio": "c9f4be41ca1cc2b4", "mbuddy": "e1937873ebfba8c3", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1"}
|
||||
1
Test/BuddyTest/output/271ea3decb810db2.deps.json
Normal file
1
Test/BuddyTest/output/271ea3decb810db2.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"w32.win32process": "067c78e9f121dce3", "win32process": "067c78e9f121dce3", "atom": "271ea3decb810db2", "w32.win32sync": "29813d57621099a9", "win32sync": "29813d57621099a9", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "main": "5e430ae5bf7af3a2", "stdlib": "6c2029b306556c00", "viperlib": "70b580331b822117", "stdarg": "71e0a3ffcb3ebfad", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "mbuddytest": "c53a157505aa8081", "viperio": "c9f4be41ca1cc2b4", "mbuddy": "e1937873ebfba8c3"}
|
||||
1
Test/BuddyTest/output/29813d57621099a9.deps.json
Normal file
1
Test/BuddyTest/output/29813d57621099a9.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"w32.win32process": "067c78e9f121dce3", "win32process": "067c78e9f121dce3", "atom": "271ea3decb810db2", "w32.win32sync": "29813d57621099a9", "win32sync": "29813d57621099a9", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "main": "5e430ae5bf7af3a2", "stdlib": "6c2029b306556c00", "viperlib": "70b580331b822117", "stdarg": "71e0a3ffcb3ebfad", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "mbuddytest": "c53a157505aa8081", "viperio": "c9f4be41ca1cc2b4", "mbuddy": "e1937873ebfba8c3", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1"}
|
||||
1
Test/BuddyTest/output/5a6a2137958c28c5.deps.json
Normal file
1
Test/BuddyTest/output/5a6a2137958c28c5.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"w32.win32process": "067c78e9f121dce3", "win32process": "067c78e9f121dce3", "atom": "271ea3decb810db2", "w32.win32sync": "29813d57621099a9", "win32sync": "29813d57621099a9", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "main": "5e430ae5bf7af3a2", "stdlib": "6c2029b306556c00", "viperlib": "70b580331b822117", "stdarg": "71e0a3ffcb3ebfad", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "mbuddytest": "c53a157505aa8081", "viperio": "c9f4be41ca1cc2b4", "mbuddy": "e1937873ebfba8c3"}
|
||||
1
Test/BuddyTest/output/5e430ae5bf7af3a2.deps.json
Normal file
1
Test/BuddyTest/output/5e430ae5bf7af3a2.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"w32.win32process": "067c78e9f121dce3", "win32process": "067c78e9f121dce3", "atom": "271ea3decb810db2", "w32.win32sync": "29813d57621099a9", "win32sync": "29813d57621099a9", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "stdlib": "6c2029b306556c00", "viperlib": "70b580331b822117", "stdarg": "71e0a3ffcb3ebfad", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "mbuddytest": "c53a157505aa8081", "viperio": "c9f4be41ca1cc2b4", "mbuddy": "e1937873ebfba8c3"}
|
||||
1
Test/BuddyTest/output/70b580331b822117.deps.json
Normal file
1
Test/BuddyTest/output/70b580331b822117.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"w32.win32process": "067c78e9f121dce3", "win32process": "067c78e9f121dce3", "atom": "271ea3decb810db2", "w32.win32sync": "29813d57621099a9", "win32sync": "29813d57621099a9", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "main": "5e430ae5bf7af3a2", "stdlib": "6c2029b306556c00", "viperlib": "70b580331b822117", "stdarg": "71e0a3ffcb3ebfad", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "mbuddytest": "c53a157505aa8081", "viperio": "c9f4be41ca1cc2b4", "mbuddy": "e1937873ebfba8c3"}
|
||||
1
Test/BuddyTest/output/72e2d5ccb7cedcf1.deps.json
Normal file
1
Test/BuddyTest/output/72e2d5ccb7cedcf1.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"w32.win32process": "067c78e9f121dce3", "win32process": "067c78e9f121dce3", "atom": "271ea3decb810db2", "w32.win32sync": "29813d57621099a9", "win32sync": "29813d57621099a9", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "main": "5e430ae5bf7af3a2", "stdlib": "6c2029b306556c00", "viperlib": "70b580331b822117", "stdarg": "71e0a3ffcb3ebfad", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "mbuddytest": "c53a157505aa8081", "viperio": "c9f4be41ca1cc2b4", "mbuddy": "e1937873ebfba8c3", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1"}
|
||||
1
Test/BuddyTest/output/9dbecd0942a39782.deps.json
Normal file
1
Test/BuddyTest/output/9dbecd0942a39782.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"w32.win32process": "067c78e9f121dce3", "win32process": "067c78e9f121dce3", "atom": "271ea3decb810db2", "w32.win32sync": "29813d57621099a9", "win32sync": "29813d57621099a9", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "main": "5e430ae5bf7af3a2", "stdlib": "6c2029b306556c00", "viperlib": "70b580331b822117", "stdarg": "71e0a3ffcb3ebfad", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "mbuddytest": "c53a157505aa8081", "viperio": "c9f4be41ca1cc2b4", "mbuddy": "e1937873ebfba8c3"}
|
||||
1
Test/BuddyTest/output/abf9ce3160c9279e.deps.json
Normal file
1
Test/BuddyTest/output/abf9ce3160c9279e.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"w32.win32process": "067c78e9f121dce3", "win32process": "067c78e9f121dce3", "atom": "271ea3decb810db2", "w32.win32sync": "29813d57621099a9", "win32sync": "29813d57621099a9", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "main": "5e430ae5bf7af3a2", "stdlib": "6c2029b306556c00", "viperlib": "70b580331b822117", "stdarg": "71e0a3ffcb3ebfad", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "mbuddytest": "c53a157505aa8081", "viperio": "c9f4be41ca1cc2b4", "mbuddy": "e1937873ebfba8c3", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e"}
|
||||
1
Test/BuddyTest/output/b5f1dc665c52a1bd.deps.json
Normal file
1
Test/BuddyTest/output/b5f1dc665c52a1bd.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"w32.win32process": "067c78e9f121dce3", "win32process": "067c78e9f121dce3", "atom": "271ea3decb810db2", "w32.win32sync": "29813d57621099a9", "win32sync": "29813d57621099a9", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "main": "5e430ae5bf7af3a2", "stdlib": "6c2029b306556c00", "viperlib": "70b580331b822117", "stdarg": "71e0a3ffcb3ebfad", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "mbuddytest": "c53a157505aa8081", "viperio": "c9f4be41ca1cc2b4", "mbuddy": "e1937873ebfba8c3"}
|
||||
1
Test/BuddyTest/output/bbdf3bbd4c3bc28c.deps.json
Normal file
1
Test/BuddyTest/output/bbdf3bbd4c3bc28c.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"w32.win32process": "067c78e9f121dce3", "win32process": "067c78e9f121dce3", "atom": "271ea3decb810db2", "w32.win32sync": "29813d57621099a9", "win32sync": "29813d57621099a9", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "main": "5e430ae5bf7af3a2", "stdlib": "6c2029b306556c00", "viperlib": "70b580331b822117", "stdarg": "71e0a3ffcb3ebfad", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "mbuddytest": "c53a157505aa8081", "viperio": "c9f4be41ca1cc2b4", "mbuddy": "e1937873ebfba8c3"}
|
||||
1
Test/BuddyTest/output/c53a157505aa8081.deps.json
Normal file
1
Test/BuddyTest/output/c53a157505aa8081.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"w32.win32process": "067c78e9f121dce3", "win32process": "067c78e9f121dce3", "atom": "271ea3decb810db2", "w32.win32sync": "29813d57621099a9", "win32sync": "29813d57621099a9", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "main": "5e430ae5bf7af3a2", "stdlib": "6c2029b306556c00", "viperlib": "70b580331b822117", "stdarg": "71e0a3ffcb3ebfad", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "viperio": "c9f4be41ca1cc2b4", "mbuddy": "e1937873ebfba8c3"}
|
||||
1
Test/BuddyTest/output/c9f4be41ca1cc2b4.deps.json
Normal file
1
Test/BuddyTest/output/c9f4be41ca1cc2b4.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"w32.win32process": "067c78e9f121dce3", "win32process": "067c78e9f121dce3", "atom": "271ea3decb810db2", "w32.win32sync": "29813d57621099a9", "win32sync": "29813d57621099a9", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "main": "5e430ae5bf7af3a2", "stdlib": "6c2029b306556c00", "viperlib": "70b580331b822117", "stdarg": "71e0a3ffcb3ebfad", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "mbuddytest": "c53a157505aa8081", "viperio": "c9f4be41ca1cc2b4", "mbuddy": "e1937873ebfba8c3"}
|
||||
1
Test/BuddyTest/output/e1937873ebfba8c3.deps.json
Normal file
1
Test/BuddyTest/output/e1937873ebfba8c3.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"w32.win32process": "067c78e9f121dce3", "win32process": "067c78e9f121dce3", "atom": "271ea3decb810db2", "w32.win32sync": "29813d57621099a9", "win32sync": "29813d57621099a9", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "main": "5e430ae5bf7af3a2", "stdlib": "6c2029b306556c00", "viperlib": "70b580331b822117", "stdarg": "71e0a3ffcb3ebfad", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "mbuddytest": "c53a157505aa8081", "viperio": "c9f4be41ca1cc2b4", "mbuddy": "e1937873ebfba8c3"}
|
||||
1
Test/BuddyTest/output/fa3691e66b426950.deps.json
Normal file
1
Test/BuddyTest/output/fa3691e66b426950.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"w32.win32process": "067c78e9f121dce3", "win32process": "067c78e9f121dce3", "atom": "271ea3decb810db2", "w32.win32sync": "29813d57621099a9", "win32sync": "29813d57621099a9", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "main": "5e430ae5bf7af3a2", "stdlib": "6c2029b306556c00", "viperlib": "70b580331b822117", "stdarg": "71e0a3ffcb3ebfad", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "mbuddytest": "c53a157505aa8081", "viperio": "c9f4be41ca1cc2b4", "mbuddy": "e1937873ebfba8c3", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950"}
|
||||
29
Test/BuddyTest/project.json
Normal file
29
Test/BuddyTest/project.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/TermiNexus/TransPyC/main/schemas/project-schema.json",
|
||||
"name": "BuddyTest",
|
||||
"version": "1.0.0",
|
||||
"source_dir": "./App",
|
||||
"temp_dir": "./temp",
|
||||
"output_dir": "./output",
|
||||
"compiler": {
|
||||
"cmd": "llc",
|
||||
"flags": ["-filetype=obj", "-relocation-model=pic"]
|
||||
},
|
||||
"linker": {
|
||||
"cmd": "clang++",
|
||||
"flags": ["-lmsvcrt", "-lucrt", "-lpthread", "-lmingwex", "-lkernel32", "-Wl,--allow-multiple-definition"],
|
||||
"output": "BuddyTest.exe"
|
||||
},
|
||||
"includes": [
|
||||
"./includes"
|
||||
],
|
||||
"target": {
|
||||
"triple": "x86_64-pc-windows-gnu",
|
||||
"datalayout": "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
|
||||
},
|
||||
"options": {
|
||||
"slice_level": 3,
|
||||
"target": "llvm",
|
||||
"strict_mode": true
|
||||
}
|
||||
}
|
||||
26
Test/BuddyTest/temp/271ea3decb810db2.pyi
Normal file
26
Test/BuddyTest/temp/271ea3decb810db2.pyi
Normal file
@@ -0,0 +1,26 @@
|
||||
"""
|
||||
Auto-generated Python stub file from atom.py
|
||||
Module: atom
|
||||
"""
|
||||
|
||||
|
||||
import t, c
|
||||
|
||||
ATOMIC_RELAXED: t.CDefine = 0
|
||||
ATOMIC_CONSUME: t.CDefine = 1
|
||||
ATOMIC_ACQUIRE: t.CDefine = 2
|
||||
ATOMIC_RELEASE: t.CDefine = 3
|
||||
ATOMIC_ACQ_REL: t.CDefine = 4
|
||||
ATOMIC_SEQ_CST: t.CDefine = 5
|
||||
|
||||
def __atomic_test_and_set(ptr: t.CUInt64T | t.CPtr, order: t.CInt) -> t.CBool: pass
|
||||
|
||||
def __atomic_clear(ptr: t.CUInt64T | t.CPtr, order: t.CInt) -> t.CVoid: pass
|
||||
|
||||
def __atomic_thread_fence(order: t.CInt) -> t.CVoid: pass
|
||||
|
||||
def __atomic_signal_fence(order: t.CInt) -> t.CVoid: pass
|
||||
|
||||
def __atomic_always_lock_free(size: t.CSizeT, ptr: t.CVoid | t.CPtr) -> t.CBool: pass
|
||||
|
||||
def __atomic_is_lock_free(size: t.CSizeT, ptr: t.CVoid | t.CPtr) -> t.CBool: pass
|
||||
@@ -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
|
||||
13
Test/BuddyTest/temp/5e430ae5bf7af3a2.pyi
Normal file
13
Test/BuddyTest/temp/5e430ae5bf7af3a2.pyi
Normal file
@@ -0,0 +1,13 @@
|
||||
"""
|
||||
Auto-generated Python stub file from main.py
|
||||
Module: main
|
||||
"""
|
||||
|
||||
|
||||
from stdint import *
|
||||
import w32.win32console
|
||||
import t, c
|
||||
from t import CInt, CExport
|
||||
import mbuddytest
|
||||
|
||||
def main() -> CInt | CExport: pass
|
||||
20
Test/BuddyTest/temp/71e0a3ffcb3ebfad.pyi
Normal file
20
Test/BuddyTest/temp/71e0a3ffcb3ebfad.pyi
Normal file
@@ -0,0 +1,20 @@
|
||||
"""
|
||||
Auto-generated Python stub file from stdarg.py
|
||||
Module: stdarg
|
||||
"""
|
||||
|
||||
import c
|
||||
|
||||
|
||||
import t
|
||||
|
||||
def va_start(args: t.CPtr, last_arg: t.CPtr) -> t.State: pass
|
||||
|
||||
def va_arg(args: t.CPtr, type: t.CPtr) -> t.CPtr | t.State: pass
|
||||
|
||||
def va_end(args: t.CPtr) -> t.State | t.State: pass
|
||||
|
||||
|
||||
va_list: t.CTypedef = t.CUnsignedChar | t.CPtr
|
||||
|
||||
def arg(type: t.CType) -> t.State: pass
|
||||
28
Test/BuddyTest/temp/73edbcf76e32d00b.pyi
Normal file
28
Test/BuddyTest/temp/73edbcf76e32d00b.pyi
Normal 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
|
||||
25
Test/BuddyTest/temp/9dbecd0942a39782.pyi
Normal file
25
Test/BuddyTest/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
|
||||
16
Test/BuddyTest/temp/_sha1_map.txt
Normal file
16
Test/BuddyTest/temp/_sha1_map.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
067c78e9f121dce3:includes/w32\win32process.py
|
||||
271ea3decb810db2:includes/atom.py
|
||||
29813d57621099a9:includes/w32\win32sync.py
|
||||
49bd8cba55979f76:includes/stdint.py
|
||||
5a6a2137958c28c5:includes/w32\win32base.py
|
||||
5e430ae5bf7af3a2:main.py
|
||||
6c2029b306556c00:includes/stdlib.py
|
||||
70b580331b822117:includes/viperlib.py
|
||||
71e0a3ffcb3ebfad:includes/stdarg.py
|
||||
73edbcf76e32d00b:includes/stdio.py
|
||||
9dbecd0942a39782:includes/testcheck.py
|
||||
b5f1dc665c52a1bd:includes/string.py
|
||||
bbdf3bbd4c3bc28c:includes/w32\win32console.py
|
||||
c53a157505aa8081:mbuddytest.py
|
||||
c9f4be41ca1cc2b4:includes/viperio.py
|
||||
e1937873ebfba8c3:includes/mbuddy.py
|
||||
0
Test/BuddyTest/temp/_shared_sym.json
Normal file
0
Test/BuddyTest/temp/_shared_sym.json
Normal file
@@ -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
|
||||
21
Test/BuddyTest/temp/c53a157505aa8081.pyi
Normal file
21
Test/BuddyTest/temp/c53a157505aa8081.pyi
Normal file
@@ -0,0 +1,21 @@
|
||||
"""
|
||||
Auto-generated Python stub file from mbuddytest.py
|
||||
Module: mbuddytest
|
||||
"""
|
||||
|
||||
|
||||
import t, c
|
||||
from t import CInt, CPtr, CChar, CUInt8T, CUInt32T, CUInt64T, CSizeT
|
||||
import viperlib
|
||||
import viperio
|
||||
import stdlib
|
||||
import mbuddy
|
||||
import string
|
||||
import testcheck
|
||||
import w32.win32process
|
||||
import w32.win32sync
|
||||
import w32.win32base
|
||||
|
||||
def _thread_alloc_free(param: t.CVoid | t.CPtr) -> t.CUInt32T: pass
|
||||
|
||||
def mbuddy_main() -> CInt: pass
|
||||
48
Test/BuddyTest/temp/e1937873ebfba8c3.pyi
Normal file
48
Test/BuddyTest/temp/e1937873ebfba8c3.pyi
Normal file
@@ -0,0 +1,48 @@
|
||||
"""
|
||||
Auto-generated Python stub file from mbuddy.py
|
||||
Module: mbuddy
|
||||
"""
|
||||
|
||||
|
||||
import t, c
|
||||
from stdint import *
|
||||
import string
|
||||
import atom
|
||||
|
||||
MBUDDY_MIN_BLOCK: t.CDefine = 32 # 最小块大小 (字节),需 >= 16 以容纳链表指针
|
||||
MBUDDY_MAX_ORDERS: t.CDefine = 32 # 最大阶数数量
|
||||
MBUDDY_HEADER_SIZE: t.CDefine = 8 # 块头大小 (存储阶数)
|
||||
|
||||
def _largest_pow2_le(val: t.CSizeT) -> t.CSizeT: pass
|
||||
|
||||
def _block_size_at_order(order: t.CInt) -> t.CSizeT: pass
|
||||
|
||||
|
||||
class MBuddy:
|
||||
mem: t.CVoid | t.CPtr
|
||||
mem_size: t.CSizeT
|
||||
max_order: t.CInt
|
||||
free_lists: t.CUInt64T | t.CPtr
|
||||
lock_val: t.CVolatile | t.CInt
|
||||
def __init__(self: MBuddy, arena: t.CVoid | t.CPtr, arena_size: t.CSizeT) -> t.CInt: pass
|
||||
def __enter__(self: MBuddy) -> 'MBuddy' | t.CPtr: pass
|
||||
def __exit__(self: MBuddy) -> t.CInt: pass
|
||||
def reset(self: MBuddy) -> t.CInt: pass
|
||||
def _fl_push(self: MBuddy, order: t.CInt, block: t.CVoid | t.CPtr) -> t.CInt: pass
|
||||
def _fl_pop(self: MBuddy, order: t.CInt) -> t.CVoid | t.CPtr: pass
|
||||
def _fl_find_and_remove(self: MBuddy, order: t.CInt, target: t.CVoid | t.CPtr) -> t.CInt: pass
|
||||
def _buddy_of(self: MBuddy, block: t.CVoid | t.CPtr, order: t.CInt) -> t.CVoid | t.CPtr: pass
|
||||
def _order_for_size(self: MBuddy, size: t.CSizeT) -> t.CInt: pass
|
||||
def _split_to_order(self: MBuddy, to_order: t.CInt) -> t.CVoid | t.CPtr: pass
|
||||
def _coalesce(self: MBuddy, block: t.CVoid | t.CPtr, order: t.CInt) -> t.CInt: pass
|
||||
def _is_valid_ptr(self: MBuddy, ptr: t.CVoid | t.CPtr) -> t.CInt: pass
|
||||
def _fl_count(self: MBuddy, order: t.CInt) -> t.CSizeT: pass
|
||||
def _lock(self: MBuddy) -> t.CInt: pass
|
||||
def _unlock(self: MBuddy) -> t.CInt: pass
|
||||
def alloc(self: MBuddy, size: t.CSizeT) -> t.CVoid | t.CPtr: pass
|
||||
def free(self: MBuddy, ptr: t.CVoid | t.CPtr) -> t.CInt: pass
|
||||
def calloc(self: MBuddy, count: t.CSizeT, size: t.CSizeT) -> t.CVoid | t.CPtr: pass
|
||||
def realloc(self: MBuddy, ptr: t.CVoid | t.CPtr, new_size: t.CSizeT) -> t.CVoid | t.CPtr: pass
|
||||
def stats(self: MBuddy) -> t.CSizeT: pass
|
||||
def free_count(self: MBuddy) -> t.CSizeT: pass
|
||||
def self_check(self: MBuddy) -> t.CInt: pass
|
||||
@@ -2,21 +2,7 @@ import t
|
||||
from stdint import *
|
||||
from stdio import printf
|
||||
from stdlib import malloc
|
||||
|
||||
# ============================================================
|
||||
# 测试计数器
|
||||
# ============================================================
|
||||
_pass_count: t.CInt = 0
|
||||
_fail_count: t.CInt = 0
|
||||
|
||||
def check(name: t.CChar | t.CPtr, condition: bool):
|
||||
global _pass_count, _fail_count
|
||||
if condition:
|
||||
_pass_count += 1
|
||||
printf(" [PASS] %s\n", name)
|
||||
else:
|
||||
_fail_count += 1
|
||||
printf(" [FAIL] %s\n", name)
|
||||
import testcheck
|
||||
|
||||
|
||||
# ============================================================
|
||||
@@ -43,14 +29,13 @@ class Rect:
|
||||
|
||||
|
||||
def test_property_getter():
|
||||
printf("\n+-- @property getter --+\n")
|
||||
testcheck.section("@property getter")
|
||||
r1: Rect = Rect(3, 4)
|
||||
check("area == 12", r1.area == 12)
|
||||
check("not square", not r1.is_square)
|
||||
testcheck.check(r1.area == 12, "area == 12", "area expect 12")
|
||||
testcheck.check(not r1.is_square, "not square", "should not be square")
|
||||
r2: Rect = Rect(5, 5)
|
||||
check("square area == 25", r2.area == 25)
|
||||
check("is_square", r2.is_square)
|
||||
printf("+--------------------------------------------+\n")
|
||||
testcheck.check(r2.area == 25, "square area == 25", "square area expect 25")
|
||||
testcheck.check(r2.is_square, "is_square", "should be square")
|
||||
|
||||
|
||||
# ============================================================
|
||||
@@ -79,13 +64,12 @@ class Temperature:
|
||||
|
||||
|
||||
def test_property_setter():
|
||||
printf("\n+-- @property.setter --+\n")
|
||||
testcheck.section("@property.setter")
|
||||
tmp1: Temperature = Temperature(0.0)
|
||||
check("0C == 32F", tmp1.fahrenheit > 31.9 and tmp1.fahrenheit < 32.1)
|
||||
testcheck.check(tmp1.fahrenheit > 31.9 and tmp1.fahrenheit < 32.1, "0C == 32F", "0C expect 32F")
|
||||
tmp1.celsius = 100.0
|
||||
check("100C == 212F", tmp1.fahrenheit > 211.9 and tmp1.fahrenheit < 212.1)
|
||||
check("celsius == 100", tmp1.celsius > 99.9 and tmp1.celsius < 100.1)
|
||||
printf("+--------------------------------------------+\n")
|
||||
testcheck.check(tmp1.fahrenheit > 211.9 and tmp1.fahrenheit < 212.1, "100C == 212F", "100C expect 212F")
|
||||
testcheck.check(tmp1.celsius > 99.9 and tmp1.celsius < 100.1, "celsius == 100", "celsius expect 100")
|
||||
|
||||
|
||||
# ============================================================
|
||||
@@ -110,12 +94,11 @@ class Counter:
|
||||
|
||||
|
||||
def test_property_getter_redef():
|
||||
printf("\n+-- @property.getter redef --+\n")
|
||||
testcheck.section("@property.getter redef")
|
||||
cnt: Counter = Counter()
|
||||
check("init == 0", cnt.value == 0)
|
||||
testcheck.check(cnt.value == 0, "init == 0", "init expect 0")
|
||||
cnt.value = 42
|
||||
check("set == 42", cnt.value == 42)
|
||||
printf("+--------------------------------------------+\n")
|
||||
testcheck.check(cnt.value == 42, "set == 42", "set expect 42")
|
||||
|
||||
|
||||
# ============================================================
|
||||
@@ -150,14 +133,13 @@ class Config:
|
||||
|
||||
|
||||
def test_property_deleter():
|
||||
printf("\n+-- @property.deleter --+\n")
|
||||
testcheck.section("@property.deleter")
|
||||
cfg: Config = Config(99)
|
||||
check("init == 99", cfg.value == 99)
|
||||
check("not deleted", not cfg.is_deleted())
|
||||
testcheck.check(cfg.value == 99, "init == 99", "init expect 99")
|
||||
testcheck.check(not cfg.is_deleted(), "not deleted", "should not be deleted")
|
||||
del cfg.value
|
||||
check("after del == 0", cfg.value == 0)
|
||||
check("is_deleted", cfg.is_deleted())
|
||||
printf("+--------------------------------------------+\n")
|
||||
testcheck.check(cfg.value == 0, "after del == 0", "after del expect 0")
|
||||
testcheck.check(cfg.is_deleted(), "is_deleted", "should be deleted")
|
||||
|
||||
|
||||
# ============================================================
|
||||
@@ -174,11 +156,10 @@ class MathUtils:
|
||||
|
||||
|
||||
def test_staticmethod():
|
||||
printf("\n+-- @staticmethod --+\n")
|
||||
testcheck.section("@staticmethod")
|
||||
# 通过类名调用
|
||||
check("MathUtils.add(3,4)==7", MathUtils.add(3, 4) == 7)
|
||||
check("MathUtils.max(5,10)==10", MathUtils.max_val(5, 10) == 10)
|
||||
printf("+--------------------------------------------+\n")
|
||||
testcheck.check(MathUtils.add(3, 4) == 7, "MathUtils.add(3,4)==7", "MathUtils.add(3,4) expect 7")
|
||||
testcheck.check(MathUtils.max_val(5, 10) == 10, "MathUtils.max(5,10)==10", "MathUtils.max(5,10) expect 10")
|
||||
|
||||
|
||||
# ============================================================
|
||||
@@ -208,18 +189,17 @@ class Point:
|
||||
|
||||
|
||||
def test_classmethod():
|
||||
printf("\n+-- @classmethod --+\n")
|
||||
testcheck.section("@classmethod")
|
||||
# 通过类名调用
|
||||
p1: Point = Point.origin()
|
||||
check("origin.x ~= 0", p1.x > -0.01 and p1.x < 0.01)
|
||||
check("origin.y ~= 0", p1.y > -0.01 and p1.y < 0.01)
|
||||
check("origin.dist ~= 0", p1.dist_sq() < 0.01)
|
||||
testcheck.check(p1.x > -0.01 and p1.x < 0.01, "origin.x ~= 0", "origin.x expect ~0")
|
||||
testcheck.check(p1.y > -0.01 and p1.y < 0.01, "origin.y ~= 0", "origin.y expect ~0")
|
||||
testcheck.check(p1.dist_sq() < 0.01, "origin.dist ~= 0", "origin.dist expect ~0")
|
||||
|
||||
p2: Point = Point.from_int(3, 4)
|
||||
check("from_int(3,4).x ~= 3", p2.x > 2.99 and p2.x < 3.01)
|
||||
check("from_int(3,4).y ~= 4", p2.y > 3.99 and p2.y < 4.01)
|
||||
check("dist_sq ~= 25", p2.dist_sq() > 24.99 and p2.dist_sq() < 25.01)
|
||||
printf("+--------------------------------------------+\n")
|
||||
testcheck.check(p2.x > 2.99 and p2.x < 3.01, "from_int(3,4).x ~= 3", "from_int(3,4).x expect ~3")
|
||||
testcheck.check(p2.y > 3.99 and p2.y < 4.01, "from_int(3,4).y ~= 4", "from_int(3,4).y expect ~4")
|
||||
testcheck.check(p2.dist_sq() > 24.99 and p2.dist_sq() < 25.01, "dist_sq ~= 25", "dist_sq expect ~25")
|
||||
|
||||
|
||||
# ============================================================
|
||||
@@ -256,27 +236,26 @@ class Circle:
|
||||
|
||||
|
||||
def test_combined():
|
||||
printf("\n+-- Combined @property + @staticmethod + @classmethod --+\n")
|
||||
testcheck.section("Combined @property + @staticmethod + @classmethod")
|
||||
# 先测试直接构造
|
||||
cr0: Circle = Circle(1.0)
|
||||
check("direct radius ~= 1", cr0.radius > 0.99 and cr0.radius < 1.01)
|
||||
check("direct area ~= pi", cr0.area > 3.14 and cr0.area < 3.15)
|
||||
testcheck.check(cr0.radius > 0.99 and cr0.radius < 1.01, "direct radius ~= 1", "direct radius expect ~1")
|
||||
testcheck.check(cr0.area > 3.14 and cr0.area < 3.15, "direct area ~= pi", "direct area expect ~pi")
|
||||
cr0.radius = 2.0
|
||||
check("direct radius 2.0", cr0.radius > 1.99 and cr0.radius < 2.01)
|
||||
check("direct area ~= 4pi", cr0.area > 12.56 and cr0.area < 12.58)
|
||||
testcheck.check(cr0.radius > 1.99 and cr0.radius < 2.01, "direct radius 2.0", "direct radius expect 2.0")
|
||||
testcheck.check(cr0.area > 12.56 and cr0.area < 12.58, "direct area ~= 4pi", "direct area expect ~4pi")
|
||||
# 测试 classmethod
|
||||
cr1: Circle = Circle.unit()
|
||||
check("unit radius ~= 1", cr1.radius > 0.99 and cr1.radius < 1.01)
|
||||
check("is_unit(1.0)", Circle.is_unit(1.0))
|
||||
check("not is_unit(2.0)", not Circle.is_unit(2.0))
|
||||
printf("+--------------------------------------------+\n")
|
||||
testcheck.check(cr1.radius > 0.99 and cr1.radius < 1.01, "unit radius ~= 1", "unit radius expect ~1")
|
||||
testcheck.check(Circle.is_unit(1.0), "is_unit(1.0)", "is_unit(1.0) should be true")
|
||||
testcheck.check(not Circle.is_unit(2.0), "not is_unit(2.0)", "is_unit(2.0) should be false")
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 主函数
|
||||
# ============================================================
|
||||
def main() -> t.CInt | t.CExport:
|
||||
printf("=== Builtin Decorator Test ===\n")
|
||||
testcheck.begin("Builtin Decorator Test")
|
||||
|
||||
test_property_getter()
|
||||
test_property_setter()
|
||||
@@ -286,5 +265,4 @@ def main() -> t.CInt | t.CExport:
|
||||
test_classmethod()
|
||||
test_combined()
|
||||
|
||||
printf("\n=== Results: %d passed, %d failed ===\n", _pass_count, _fail_count)
|
||||
return 0
|
||||
return testcheck.end()
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
{"stdint": "49bd8cba55979f76", "stdlib": "6c2029b306556c00", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "main": "e3ac223bdaf94a0c"}
|
||||
@@ -1 +0,0 @@
|
||||
{"stdint": "56cdd754a8a09347", "stdlib": "6c2029b306556c00", "stdio": "73edbcf76e32d00b"}
|
||||
@@ -0,0 +1 @@
|
||||
{"stdint": "49bd8cba55979f76", "stdlib": "6c2029b306556c00", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782"}
|
||||
@@ -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/BuiltinDecoratorTest/temp/9dbecd0942a39782.pyi
Normal file
25
Test/BuiltinDecoratorTest/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,4 +1,5 @@
|
||||
56cdd754a8a09347:includes/stdint.py
|
||||
49bd8cba55979f76:includes/stdint.py
|
||||
6c2029b306556c00:includes/stdlib.py
|
||||
73edbcf76e32d00b:includes/stdio.py
|
||||
b6069b01d8c9cc04:main.py
|
||||
9dbecd0942a39782:includes/testcheck.py
|
||||
e3ac223bdaf94a0c:main.py
|
||||
|
||||
@@ -10,12 +10,7 @@ import t
|
||||
from stdint import *
|
||||
from stdio import printf
|
||||
from stdlib import malloc
|
||||
|
||||
_pass_count: t.CExtern | t.CInt
|
||||
_fail_count: t.CExtern | t.CInt
|
||||
|
||||
def check(name: t.CChar | t.CPtr, condition: bool) -> t.CInt: pass
|
||||
|
||||
import testcheck
|
||||
|
||||
class Rect:
|
||||
width: t.CInt
|
||||
@@ -2,61 +2,48 @@ import t, c
|
||||
from t import CInt, CLong, CDouble, CPtr, CSizeT
|
||||
from stdio import printf
|
||||
import cpython
|
||||
|
||||
|
||||
_pass_count: CInt = 0
|
||||
_fail_count: CInt = 0
|
||||
|
||||
def check(name: t.CChar | CPtr, condition: bool):
|
||||
global _pass_count, _fail_count
|
||||
if condition:
|
||||
_pass_count += 1
|
||||
printf(" [PASS] %s\n", name)
|
||||
else:
|
||||
_fail_count += 1
|
||||
printf(" [FAIL] %s\n", name)
|
||||
import testcheck
|
||||
|
||||
|
||||
def test_init_finalize():
|
||||
printf("\n+-- Py_Initialize / Py_Finalize --+\n")
|
||||
testcheck.section("Py_Initialize / Py_Finalize")
|
||||
cpython.Py_Initialize()
|
||||
check("Py_Initialize succeeded", cpython.Py_IsInitialized() != 0)
|
||||
testcheck.check(cpython.Py_IsInitialized() != 0, "Py_Initialize succeeded", "Py_Initialize succeeded")
|
||||
cpython.Py_Finalize()
|
||||
check("Py_Finalize succeeded", cpython.Py_IsInitialized() == 0)
|
||||
printf("+--------------------------------------------+\n")
|
||||
testcheck.check(cpython.Py_IsInitialized() == 0, "Py_Finalize succeeded", "Py_Finalize succeeded")
|
||||
|
||||
|
||||
def test_long_operations():
|
||||
printf("\n+-- PyLong operations --+\n")
|
||||
testcheck.section("PyLong operations")
|
||||
cpython.Py_Initialize()
|
||||
|
||||
# 创建整数
|
||||
py_num: cpython.PyObject | CPtr = cpython.PyLong_FromLong(12345)
|
||||
check("PyLong_FromLong != NULL", py_num != 0)
|
||||
testcheck.check(py_num != 0, "PyLong_FromLong != NULL", "PyLong_FromLong != NULL")
|
||||
|
||||
# 整数转字符串
|
||||
py_str: cpython.PyObject | CPtr = cpython.PyObject_Str(py_num)
|
||||
check("PyObject_Str != NULL", py_str != 0)
|
||||
py_str: cpython.PyObject | CPtr = cpython.PyObject_str(py_num)
|
||||
testcheck.check(py_str != 0, "PyObject_Str != NULL", "PyObject_Str != NULL")
|
||||
|
||||
# 获取 C 字符串
|
||||
c_str: t.CChar | CPtr = cpython.PyUnicode_AsUTF8(py_str)
|
||||
check("PyUnicode_AsUTF8 != NULL", c_str != 0)
|
||||
testcheck.check(c_str != 0, "PyUnicode_AsUTF8 != NULL", "PyUnicode_AsUTF8 != NULL")
|
||||
printf(" PyLong_FromLong(12345) -> str = %s\n", c_str)
|
||||
|
||||
# 读取回来
|
||||
val: CLong = cpython.PyLong_AsLong(py_num)
|
||||
check("PyLong_AsLong == 12345", val == 12345)
|
||||
testcheck.check(val == 12345, "PyLong_AsLong == 12345", "PyLong_AsLong == 12345")
|
||||
|
||||
# 负数
|
||||
py_neg: cpython.PyObject | CPtr = cpython.PyLong_FromLong(-999)
|
||||
neg_val: CLong = cpython.PyLong_AsLong(py_neg)
|
||||
check("PyLong_FromLong(-999) == -999", neg_val == -999)
|
||||
testcheck.check(neg_val == -999, "PyLong_FromLong(-999) == -999", "PyLong_FromLong(-999) == -999")
|
||||
|
||||
# 浮点数转整数
|
||||
py_dbl: cpython.PyObject | CPtr = cpython.PyFloat_FromDouble(3.14159)
|
||||
check("PyFloat_FromDouble != NULL", py_dbl != 0)
|
||||
testcheck.check(py_dbl != 0, "PyFloat_FromDouble != NULL", "PyFloat_FromDouble != NULL")
|
||||
dbl_val: CDouble = cpython.PyFloat_AsDouble(py_dbl)
|
||||
check("PyFloat_AsDouble ~= 3.14", dbl_val > 3.14 and dbl_val < 3.15)
|
||||
testcheck.check(dbl_val > 3.14 and dbl_val < 3.15, "PyFloat_AsDouble ~= 3.14", "PyFloat_AsDouble ~= 3.14")
|
||||
|
||||
# 清理
|
||||
cpython.Py_DecRef(py_dbl)
|
||||
@@ -65,31 +52,30 @@ def test_long_operations():
|
||||
cpython.Py_DecRef(py_num)
|
||||
|
||||
cpython.Py_Finalize()
|
||||
printf("+--------------------------------------------+\n")
|
||||
|
||||
|
||||
def test_string_operations():
|
||||
printf("\n+-- PyUnicode operations --+\n")
|
||||
testcheck.section("PyUnicode operations")
|
||||
cpython.Py_Initialize()
|
||||
|
||||
# 从 C 字符串创建
|
||||
py_s1: cpython.PyObject | CPtr = cpython.PyUnicode_FromString("Hello, Viper!")
|
||||
check("PyUnicode_FromString != NULL", py_s1 != 0)
|
||||
testcheck.check(py_s1 != 0, "PyUnicode_FromString != NULL", "PyUnicode_FromString != NULL")
|
||||
|
||||
# 获取 UTF8
|
||||
utf8: t.CChar | CPtr = cpython.PyUnicode_AsUTF8(py_s1)
|
||||
check("AsUTF8 != NULL", utf8 != 0)
|
||||
testcheck.check(utf8 != 0, "AsUTF8 != NULL", "AsUTF8 != NULL")
|
||||
printf(" PyUnicode_FromString -> %s\n", utf8)
|
||||
|
||||
# 字符串长度
|
||||
length: CLong = cpython.PyUnicode_GetLength(py_s1)
|
||||
check("GetLength == 13", length == 13)
|
||||
testcheck.check(length == 13, "GetLength == 13", "GetLength == 13")
|
||||
|
||||
# 字符串拼接
|
||||
py_s2: cpython.PyObject | CPtr = cpython.PyUnicode_FromString(" World")
|
||||
py_concat: cpython.PyObject | CPtr = cpython.PyUnicode_Concat(py_s1, py_s2)
|
||||
concat_utf8: t.CChar | CPtr = cpython.PyUnicode_AsUTF8(py_concat)
|
||||
check("Concat != NULL", py_concat != 0)
|
||||
testcheck.check(py_concat != 0, "Concat != NULL", "Concat != NULL")
|
||||
printf(" Concat -> %s\n", concat_utf8)
|
||||
|
||||
# 清理
|
||||
@@ -98,16 +84,15 @@ def test_string_operations():
|
||||
cpython.Py_DecRef(py_s1)
|
||||
|
||||
cpython.Py_Finalize()
|
||||
printf("+--------------------------------------------+\n")
|
||||
|
||||
|
||||
def test_list_operations():
|
||||
printf("\n+-- PyList operations --+\n")
|
||||
testcheck.section("PyList operations")
|
||||
cpython.Py_Initialize()
|
||||
|
||||
# 创建列表
|
||||
py_list: cpython.PyObject | CPtr = cpython.PyList_New(0)
|
||||
check("PyList_New != NULL", py_list != 0)
|
||||
testcheck.check(py_list != 0, "PyList_New != NULL", "PyList_New != NULL")
|
||||
|
||||
# Append 元素
|
||||
py_i1: cpython.PyObject | CPtr = cpython.PyLong_FromLong(10)
|
||||
@@ -119,16 +104,16 @@ def test_list_operations():
|
||||
|
||||
# 检查大小
|
||||
list_size: CSizeT = cpython.PyList_Size(py_list)
|
||||
check("PyList_Size == 3", list_size == 3)
|
||||
testcheck.check(list_size == 3, "PyList_Size == 3", "PyList_Size == 3")
|
||||
|
||||
# 获取元素
|
||||
item0: cpython.PyObject | CPtr = cpython.PyList_GetItem(py_list, 0)
|
||||
val0: CLong = cpython.PyLong_AsLong(item0)
|
||||
check("list[0] == 10", val0 == 10)
|
||||
testcheck.check(val0 == 10, "list[0] == 10", "list[0] == 10")
|
||||
|
||||
item2: cpython.PyObject | CPtr = cpython.PyList_GetItem(py_list, 2)
|
||||
val2: CLong = cpython.PyLong_AsLong(item2)
|
||||
check("list[2] == 30", val2 == 30)
|
||||
testcheck.check(val2 == 30, "list[2] == 30", "list[2] == 30")
|
||||
|
||||
# 清理
|
||||
cpython.Py_DecRef(py_i3)
|
||||
@@ -137,16 +122,15 @@ def test_list_operations():
|
||||
cpython.Py_DecRef(py_list)
|
||||
|
||||
cpython.Py_Finalize()
|
||||
printf("+--------------------------------------------+\n")
|
||||
|
||||
|
||||
def test_dict_operations():
|
||||
printf("\n+-- PyDict operations --+\n")
|
||||
testcheck.section("PyDict operations")
|
||||
cpython.Py_Initialize()
|
||||
|
||||
# 创建字典
|
||||
py_dict: cpython.PyObject | CPtr = cpython.PyDict_New()
|
||||
check("PyDict_New != NULL", py_dict != 0)
|
||||
testcheck.check(py_dict != 0, "PyDict_New != NULL", "PyDict_New != NULL")
|
||||
|
||||
# 设置键值对
|
||||
py_key1: cpython.PyObject | CPtr = cpython.PyUnicode_FromString("name")
|
||||
@@ -159,20 +143,20 @@ def test_dict_operations():
|
||||
|
||||
# 检查大小
|
||||
dict_size: CSizeT = cpython.PyDict_Size(py_dict)
|
||||
check("PyDict_Size == 2", dict_size == 2)
|
||||
testcheck.check(dict_size == 2, "PyDict_Size == 2", "PyDict_Size == 2")
|
||||
|
||||
# 获取值
|
||||
got_val: cpython.PyObject | CPtr = cpython.PyDict_GetItem(py_dict, py_key1)
|
||||
check("GetItem(name) != NULL", got_val != 0)
|
||||
testcheck.check(got_val != 0, "GetItem(name) != NULL", "GetItem(name) != NULL")
|
||||
got_str: t.CChar | CPtr = cpython.PyUnicode_AsUTF8(got_val)
|
||||
check("name == Viper", got_str != 0)
|
||||
testcheck.check(got_str != 0, "name == Viper", "name == Viper")
|
||||
printf(" dict['name'] = %s\n", got_str)
|
||||
|
||||
# 使用 GetItemString
|
||||
got_ver: cpython.PyObject | CPtr = cpython.PyDict_GetItemString(py_dict, "version")
|
||||
check("GetItemString(version) != NULL", got_ver != 0)
|
||||
testcheck.check(got_ver != 0, "GetItemString(version) != NULL", "GetItemString(version) != NULL")
|
||||
ver_val: CLong = cpython.PyLong_AsLong(got_ver)
|
||||
check("version == 1", ver_val == 1)
|
||||
testcheck.check(ver_val == 1, "version == 1", "version == 1")
|
||||
|
||||
# 清理
|
||||
cpython.Py_DecRef(py_val2)
|
||||
@@ -182,79 +166,76 @@ def test_dict_operations():
|
||||
cpython.Py_DecRef(py_dict)
|
||||
|
||||
cpython.Py_Finalize()
|
||||
printf("+--------------------------------------------+\n")
|
||||
|
||||
|
||||
def test_pyrun_string():
|
||||
printf("\n+-- PyRun_SimpleString --+\n")
|
||||
testcheck.section("PyRun_SimpleString")
|
||||
cpython.Py_Initialize()
|
||||
|
||||
# 执行简单 Python 代码
|
||||
rc: CInt = cpython.PyRun_SimpleString("print('Hello from embedded Python!')")
|
||||
check("PyRun_SimpleString == 0", rc == 0)
|
||||
testcheck.check(rc == 0, "PyRun_SimpleString == 0", "PyRun_SimpleString == 0")
|
||||
|
||||
# 执行赋值
|
||||
rc2: CInt = cpython.PyRun_SimpleString("x = 6 * 7")
|
||||
check("PyRun_SimpleString(assign) == 0", rc2 == 0)
|
||||
testcheck.check(rc2 == 0, "PyRun_SimpleString(assign) == 0", "PyRun_SimpleString(assign) == 0")
|
||||
|
||||
# 读取结果
|
||||
rc3: CInt = cpython.PyRun_SimpleString("print(f'The answer is {x}')")
|
||||
check("PyRun_SimpleString(print) == 0", rc3 == 0)
|
||||
testcheck.check(rc3 == 0, "PyRun_SimpleString(print) == 0", "PyRun_SimpleString(print) == 0")
|
||||
|
||||
cpython.Py_Finalize()
|
||||
printf("+--------------------------------------------+\n")
|
||||
|
||||
|
||||
def test_import_module():
|
||||
printf("\n+-- PyImport_ImportModule --+\n")
|
||||
testcheck.section("PyImport_ImportModule")
|
||||
cpython.Py_Initialize()
|
||||
|
||||
# 导入 math 模块
|
||||
math_mod: cpython.PyObject | CPtr = cpython.PyImport_ImportModule("math")
|
||||
check("import math != NULL", math_mod != 0)
|
||||
testcheck.check(math_mod != 0, "import math != NULL", "import math != NULL")
|
||||
|
||||
if math_mod != 0:
|
||||
# 获取 math.pi
|
||||
pi_val: cpython.PyObject | CPtr = cpython.PyObject_GetAttrString(math_mod, "pi")
|
||||
check("math.pi != NULL", pi_val != 0)
|
||||
testcheck.check(pi_val != 0, "math.pi != NULL", "math.pi != NULL")
|
||||
if pi_val != 0:
|
||||
pi_dbl: CDouble = cpython.PyFloat_AsDouble(pi_val)
|
||||
check("math.pi ~= 3.14", pi_dbl > 3.14 and pi_dbl < 3.15)
|
||||
testcheck.check(pi_dbl > 3.14 and pi_dbl < 3.15, "math.pi ~= 3.14", "math.pi ~= 3.14")
|
||||
printf(" math.pi = %f\n", pi_dbl)
|
||||
cpython.Py_DecRef(pi_val)
|
||||
|
||||
# 获取 math.sqrt 函数
|
||||
sqrt_func: cpython.PyObject | CPtr = cpython.PyObject_GetAttrString(math_mod, "sqrt")
|
||||
check("math.sqrt != NULL", sqrt_func != 0)
|
||||
testcheck.check(sqrt_func != 0, "math.sqrt != NULL", "math.sqrt != NULL")
|
||||
if sqrt_func != 0:
|
||||
cpython.Py_DecRef(sqrt_func)
|
||||
|
||||
cpython.Py_DecRef(math_mod)
|
||||
|
||||
cpython.Py_Finalize()
|
||||
printf("+--------------------------------------------+\n")
|
||||
|
||||
|
||||
def test_operator_overload():
|
||||
printf("\n+-- Operator Overload (PyLongObj / PyFloatObj / PyUnicodeObj / PyListObj / PyDictObj) --+\n")
|
||||
testcheck.section("Operator Overload (PyLongObj / PyFloatObj / PyUnicodeObj / PyListObj / PyDictObj)")
|
||||
cpython.Py_Initialize()
|
||||
|
||||
# --- PyLongObj: from_long, to_long, +, -, *, - (neg) ---
|
||||
a: cpython.PyLongObj | CPtr = cpython.PyLongObj.from_long(10)
|
||||
b: cpython.PyLongObj | CPtr = cpython.PyLongObj.from_long(3)
|
||||
check("PyLongObj.from_long != NULL", a != 0 and b != 0)
|
||||
testcheck.check(a != 0 and b != 0, "PyLongObj.from_long != NULL", "PyLongObj.from_long != NULL")
|
||||
|
||||
add_r: cpython.PyLongObj | CPtr = a + b
|
||||
check("PyLongObj 10 + 3 == 13", add_r.to_long() == 13)
|
||||
testcheck.check(add_r.to_long() == 13, "PyLongObj 10 + 3 == 13", "PyLongObj 10 + 3 == 13")
|
||||
|
||||
sub_r: cpython.PyLongObj | CPtr = a - b
|
||||
check("PyLongObj 10 - 3 == 7", sub_r.to_long() == 7)
|
||||
testcheck.check(sub_r.to_long() == 7, "PyLongObj 10 - 3 == 7", "PyLongObj 10 - 3 == 7")
|
||||
|
||||
mul_r: cpython.PyLongObj | CPtr = a * b
|
||||
check("PyLongObj 10 * 3 == 30", mul_r.to_long() == 30)
|
||||
testcheck.check(mul_r.to_long() == 30, "PyLongObj 10 * 3 == 30", "PyLongObj 10 * 3 == 30")
|
||||
|
||||
neg_r: cpython.PyLongObj | CPtr = -b
|
||||
check("PyLongObj -3 == -3", neg_r.to_long() == -3)
|
||||
testcheck.check(neg_r.to_long() == -3, "PyLongObj -3 == -3", "PyLongObj -3 == -3")
|
||||
|
||||
mul_r.dec_ref()
|
||||
sub_r.dec_ref()
|
||||
@@ -266,22 +247,22 @@ def test_operator_overload():
|
||||
# --- PyFloatObj: from_double, to_double, +, -, *, /, - (neg) ---
|
||||
fa: cpython.PyFloatObj | CPtr = cpython.PyFloatObj.from_double(10.0)
|
||||
fb: cpython.PyFloatObj | CPtr = cpython.PyFloatObj.from_double(4.0)
|
||||
check("PyFloatObj.from_double != NULL", fa != 0 and fb != 0)
|
||||
testcheck.check(fa != 0 and fb != 0, "PyFloatObj.from_double != NULL", "PyFloatObj.from_double != NULL")
|
||||
|
||||
fadd: cpython.PyFloatObj | CPtr = fa + fb
|
||||
check("PyFloatObj 10.0 + 4.0 == 14.0", fadd.to_double() == 14.0)
|
||||
testcheck.check(fadd.to_double() == 14.0, "PyFloatObj 10.0 + 4.0 == 14.0", "PyFloatObj 10.0 + 4.0 == 14.0")
|
||||
|
||||
fsub: cpython.PyFloatObj | CPtr = fa - fb
|
||||
check("PyFloatObj 10.0 - 4.0 == 6.0", fsub.to_double() == 6.0)
|
||||
testcheck.check(fsub.to_double() == 6.0, "PyFloatObj 10.0 - 4.0 == 6.0", "PyFloatObj 10.0 - 4.0 == 6.0")
|
||||
|
||||
fmul: cpython.PyFloatObj | CPtr = fa * fb
|
||||
check("PyFloatObj 10.0 * 4.0 == 40.0", fmul.to_double() == 40.0)
|
||||
testcheck.check(fmul.to_double() == 40.0, "PyFloatObj 10.0 * 4.0 == 40.0", "PyFloatObj 10.0 * 4.0 == 40.0")
|
||||
|
||||
fdiv: cpython.PyFloatObj | CPtr = fa / fb
|
||||
check("PyFloatObj 10.0 / 4.0 == 2.5", fdiv.to_double() == 2.5)
|
||||
testcheck.check(fdiv.to_double() == 2.5, "PyFloatObj 10.0 / 4.0 == 2.5", "PyFloatObj 10.0 / 4.0 == 2.5")
|
||||
|
||||
fneg: cpython.PyFloatObj | CPtr = -fb
|
||||
check("PyFloatObj -4.0 == -4.0", fneg.to_double() == -4.0)
|
||||
testcheck.check(fneg.to_double() == -4.0, "PyFloatObj -4.0 == -4.0", "PyFloatObj -4.0 == -4.0")
|
||||
|
||||
fadd.dec_ref()
|
||||
fsub.dec_ref()
|
||||
@@ -294,16 +275,16 @@ def test_operator_overload():
|
||||
# --- PyUnicodeObj: from_string, as_utf8, len, + (concat) ---
|
||||
sa: cpython.PyUnicodeObj | CPtr = cpython.PyUnicodeObj.from_string("Hello")
|
||||
sb: cpython.PyUnicodeObj | CPtr = cpython.PyUnicodeObj.from_string(" World")
|
||||
check("PyUnicodeObj.from_string != NULL", sa != 0 and sb != 0)
|
||||
testcheck.check(sa != 0 and sb != 0, "PyUnicodeObj.from_string != NULL", "PyUnicodeObj.from_string != NULL")
|
||||
|
||||
sc: cpython.PyUnicodeObj | CPtr = sa + sb
|
||||
sc_utf8: t.CChar | CPtr = sc.as_utf8()
|
||||
check("PyUnicodeObj concat != NULL", sc_utf8 != 0)
|
||||
testcheck.check(sc_utf8 != 0, "PyUnicodeObj concat != NULL", "PyUnicodeObj concat != NULL")
|
||||
if sc_utf8 != 0:
|
||||
printf(" PyUnicodeObj 'Hello' + ' World' = %s\n", sc_utf8)
|
||||
|
||||
sa_len: t.CPtrDiffT = len(sa)
|
||||
check("PyUnicodeObj len('Hello') == 5", sa_len == 5)
|
||||
testcheck.check(sa_len == 5, "PyUnicodeObj len('Hello') == 5", "PyUnicodeObj len('Hello') == 5")
|
||||
|
||||
sc.dec_ref()
|
||||
sb.dec_ref()
|
||||
@@ -311,7 +292,7 @@ def test_operator_overload():
|
||||
|
||||
# --- PyListObj: new, append, len, [], []= ---
|
||||
lst: cpython.PyListObj | CPtr = cpython.PyListObj.new()
|
||||
check("PyListObj.new != NULL", lst != 0)
|
||||
testcheck.check(lst != 0, "PyListObj.new != NULL", "PyListObj.new != NULL")
|
||||
if lst != 0:
|
||||
e1: cpython.PyObject | CPtr = cpython.PyLong_FromLong(100)
|
||||
e2: cpython.PyObject | CPtr = cpython.PyLong_FromLong(200)
|
||||
@@ -319,16 +300,16 @@ def test_operator_overload():
|
||||
lst.append(e1)
|
||||
lst.append(e2)
|
||||
lst.append(e3)
|
||||
check("PyListObj len == 3", len(lst) == 3)
|
||||
testcheck.check(len(lst) == 3, "PyListObj len == 3", "PyListObj len == 3")
|
||||
|
||||
item0: cpython.PyObject | CPtr = lst[t.CSizeT(0)]
|
||||
check("PyListObj lst[0] == 100", cpython.PyLong_AsLong(item0) == 100)
|
||||
testcheck.check(cpython.PyLong_AsLong(item0) == 100, "PyListObj lst[0] == 100", "PyListObj lst[0] == 100")
|
||||
|
||||
# __setitem__
|
||||
e4: cpython.PyObject | CPtr = cpython.PyLong_FromLong(999)
|
||||
lst[t.CSizeT(1)] = e4
|
||||
item1: cpython.PyObject | CPtr = lst[t.CSizeT(1)]
|
||||
check("PyListObj lst[1] = 999", cpython.PyLong_AsLong(item1) == 999)
|
||||
testcheck.check(cpython.PyLong_AsLong(item1) == 999, "PyListObj lst[1] = 999", "PyListObj lst[1] = 999")
|
||||
|
||||
cpython.Py_DecRef(e4)
|
||||
cpython.Py_DecRef(e3)
|
||||
@@ -338,34 +319,33 @@ def test_operator_overload():
|
||||
|
||||
# --- PyDictObj: new, [], []=, len, set_string, get_string ---
|
||||
dct: cpython.PyDictObj | CPtr = cpython.PyDictObj.new()
|
||||
check("PyDictObj.new != NULL", dct != 0)
|
||||
testcheck.check(dct != 0, "PyDictObj.new != NULL", "PyDictObj.new != NULL")
|
||||
if dct != 0:
|
||||
dk1: cpython.PyObject | CPtr = cpython.PyUnicode_FromString("lang")
|
||||
dv1: cpython.PyObject | CPtr = cpython.PyUnicode_FromString("Viper")
|
||||
dct[dk1] = dv1
|
||||
check("PyDictObj len == 1", len(dct) == 1)
|
||||
testcheck.check(len(dct) == 1, "PyDictObj len == 1", "PyDictObj len == 1")
|
||||
|
||||
got_lang: cpython.PyObject | CPtr = dct[dk1]
|
||||
got_str: t.CChar | CPtr = cpython.PyUnicode_AsUTF8(got_lang)
|
||||
check("PyDictObj dct['lang'] == Viper", got_str != 0)
|
||||
testcheck.check(got_str != 0, "PyDictObj dct['lang'] == Viper", "PyDictObj dct['lang'] == Viper")
|
||||
if got_str != 0:
|
||||
printf(" PyDictObj dct['lang'] = %s\n", got_str)
|
||||
|
||||
# get_string / set_string
|
||||
dct.set_string("ver", cpython.PyLong_FromLong(3))
|
||||
got_ver: cpython.PyObject | CPtr = dct.get_string("ver")
|
||||
check("PyDictObj get_string('ver') == 3", got_ver != 0 and cpython.PyLong_AsLong(got_ver) == 3)
|
||||
testcheck.check(got_ver != 0 and cpython.PyLong_AsLong(got_ver) == 3, "PyDictObj get_string('ver') == 3", "PyDictObj get_string('ver') == 3")
|
||||
|
||||
cpython.Py_DecRef(dv1)
|
||||
cpython.Py_DecRef(dk1)
|
||||
dct.dec_ref()
|
||||
|
||||
cpython.Py_Finalize()
|
||||
printf("+--------------------------------------------+\n")
|
||||
|
||||
|
||||
def main() -> CInt | t.CExport:
|
||||
printf("=== CPython Integration Test ===\n")
|
||||
testcheck.begin("CPython Integration Test")
|
||||
|
||||
test_init_finalize()
|
||||
test_long_operations()
|
||||
@@ -376,5 +356,4 @@ def main() -> CInt | t.CExport:
|
||||
test_import_module()
|
||||
test_operator_overload()
|
||||
|
||||
printf("\n=== Results: %d passed, %d failed ===\n", _pass_count, _fail_count)
|
||||
return 0
|
||||
return testcheck.end()
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
{"stdio": "73edbcf76e32d00b", "cpython": "7c5d5ec59c5fb0a8"}
|
||||
@@ -1 +1 @@
|
||||
{"main": "0cd580d62a3de4f8", "stdio": "73edbcf76e32d00b"}
|
||||
{"main": "3c8ecda6b848f011", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782"}
|
||||
@@ -8,11 +8,7 @@ import t, c
|
||||
from t import CInt, CLong, CDouble, CPtr, CSizeT
|
||||
from stdio import printf
|
||||
import cpython
|
||||
|
||||
_pass_count: t.CExtern | CInt
|
||||
_fail_count: t.CExtern | CInt
|
||||
|
||||
def check(name: t.CChar | CPtr, condition: bool) -> t.CInt: pass
|
||||
import testcheck
|
||||
|
||||
def test_init_finalize() -> t.CInt: pass
|
||||
|
||||
25
Test/CPythonTest/temp/9dbecd0942a39782.pyi
Normal file
25
Test/CPythonTest/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,3 +1,4 @@
|
||||
0cd580d62a3de4f8:main.py
|
||||
3c8ecda6b848f011:main.py
|
||||
73edbcf76e32d00b:includes/stdio.py
|
||||
7c5d5ec59c5fb0a8:cpython.py
|
||||
9dbecd0942a39782:includes/testcheck.py
|
||||
|
||||
0
Test/CPythonTest/temp/_shared_sym.json
Normal file
0
Test/CPythonTest/temp/_shared_sym.json
Normal file
Binary file not shown.
@@ -1,5 +1,6 @@
|
||||
import t
|
||||
import stdio
|
||||
import testcheck
|
||||
|
||||
# ============================================================
|
||||
# Test 1: global 在嵌套函数中
|
||||
@@ -14,20 +15,17 @@ def outer_modify_global():
|
||||
inner_modify()
|
||||
|
||||
def test_global_in_nested():
|
||||
stdio.printf("--- Test 1: global in nested function ---\n")
|
||||
testcheck.section("Test 1: global in nested function")
|
||||
global g_val
|
||||
g_val = 100
|
||||
outer_modify_global()
|
||||
if g_val == 150:
|
||||
stdio.printf("PASS: global nested (g_val=%d)\n", g_val)
|
||||
else:
|
||||
stdio.printf("FAIL: global nested (g_val=%d, expect 150)\n", g_val)
|
||||
testcheck.check(g_val == 150, "global nested (g_val == 150)", "global nested (expect 150)")
|
||||
|
||||
# ============================================================
|
||||
# Test 2: nonlocal 在多层嵌套中
|
||||
# ============================================================
|
||||
def test_nonlocal_multi_level():
|
||||
stdio.printf("--- Test 2: nonlocal multi-level ---\n")
|
||||
testcheck.section("Test 2: nonlocal multi-level")
|
||||
x: t.CInt = 1
|
||||
def level1():
|
||||
nonlocal x
|
||||
@@ -41,10 +39,7 @@ def test_nonlocal_multi_level():
|
||||
level3()
|
||||
level2()
|
||||
level1()
|
||||
if x == 1111:
|
||||
stdio.printf("PASS: nonlocal multi (x=%d)\n", x)
|
||||
else:
|
||||
stdio.printf("FAIL: nonlocal multi (x=%d, expect 1111)\n", x)
|
||||
testcheck.check(x == 1111, "nonlocal multi (x == 1111)", "nonlocal multi (expect 1111)")
|
||||
|
||||
# ============================================================
|
||||
# Test 3: global 和 nonlocal 混合
|
||||
@@ -52,7 +47,7 @@ def test_nonlocal_multi_level():
|
||||
g_mixed: t.CInt = 0
|
||||
|
||||
def test_global_nonlocal_mixed():
|
||||
stdio.printf("--- Test 3: global + nonlocal mixed ---\n")
|
||||
testcheck.section("Test 3: global + nonlocal mixed")
|
||||
global g_mixed
|
||||
g_mixed = 0
|
||||
local_var: t.CInt = 0
|
||||
@@ -63,59 +58,47 @@ def test_global_nonlocal_mixed():
|
||||
local_var += 20
|
||||
modify_both()
|
||||
modify_both()
|
||||
if g_mixed == 20 and local_var == 40:
|
||||
stdio.printf("PASS: mixed (global=%d local=%d)\n", g_mixed, local_var)
|
||||
else:
|
||||
stdio.printf("FAIL: mixed (global=%d local=%d, expect 20 40)\n", g_mixed, local_var)
|
||||
testcheck.check(g_mixed == 20 and local_var == 40, "mixed (global==20 local==40)", "mixed (expect global=20 local=40)")
|
||||
|
||||
# ============================================================
|
||||
# Test 4: lambda 捕获多个变量
|
||||
# ============================================================
|
||||
def test_lambda_multi_capture():
|
||||
stdio.printf("--- Test 4: lambda multi-capture ---\n")
|
||||
testcheck.section("Test 4: lambda multi-capture")
|
||||
a: t.CInt = 10
|
||||
b: t.CInt = 20
|
||||
f = lambda: a + b
|
||||
r: t.CInt = f()
|
||||
if r == 30:
|
||||
stdio.printf("PASS: lambda multi-capture (a+b=%d)\n", r)
|
||||
else:
|
||||
stdio.printf("FAIL: lambda multi-capture (a+b=%d, expect 30)\n", r)
|
||||
testcheck.check(r == 30, "lambda multi-capture (a+b == 30)", "lambda multi-capture (expect 30)")
|
||||
|
||||
# ============================================================
|
||||
# Test 5: lambda 带参数 + 捕获
|
||||
# ============================================================
|
||||
def test_lambda_arg_capture():
|
||||
stdio.printf("--- Test 5: lambda arg + capture ---\n")
|
||||
testcheck.section("Test 5: lambda arg + capture")
|
||||
base: t.CInt = 100
|
||||
add = lambda x: base + x
|
||||
r: t.CInt = add(42)
|
||||
if r == 142:
|
||||
stdio.printf("PASS: lambda arg+capture (100+42=%d)\n", r)
|
||||
else:
|
||||
stdio.printf("FAIL: lambda arg+capture (result=%d, expect 142)\n", r)
|
||||
testcheck.check(r == 142, "lambda arg+capture (100+42 == 142)", "lambda arg+capture (expect 142)")
|
||||
|
||||
# ============================================================
|
||||
# Test 6: 嵌套函数返回值
|
||||
# ============================================================
|
||||
def test_nested_return():
|
||||
stdio.printf("--- Test 6: nested function return ---\n")
|
||||
testcheck.section("Test 6: nested function return")
|
||||
x: t.CInt = 5
|
||||
def double_x() -> t.CInt:
|
||||
nonlocal x
|
||||
x = x * 2
|
||||
return x
|
||||
r: t.CInt = double_x()
|
||||
if r == 10 and x == 10:
|
||||
stdio.printf("PASS: nested return (r=%d x=%d)\n", r, x)
|
||||
else:
|
||||
stdio.printf("FAIL: nested return (r=%d x=%d, expect 10 10)\n", r, x)
|
||||
testcheck.check(r == 10 and x == 10, "nested return (r==10 x==10)", "nested return (expect r=10 x=10)")
|
||||
|
||||
# ============================================================
|
||||
# Test 7: nonlocal 与循环变量
|
||||
# ============================================================
|
||||
def test_nonlocal_loop():
|
||||
stdio.printf("--- Test 7: nonlocal with loop ---\n")
|
||||
testcheck.section("Test 7: nonlocal with loop")
|
||||
total: t.CInt = 0
|
||||
def accumulate(n: t.CInt):
|
||||
nonlocal total
|
||||
@@ -124,34 +107,28 @@ def test_nonlocal_loop():
|
||||
accumulate(5)
|
||||
accumulate(5)
|
||||
# 0+1+2+3+4 = 10, twice = 20
|
||||
if total == 20:
|
||||
stdio.printf("PASS: nonlocal loop (total=%d)\n", total)
|
||||
else:
|
||||
stdio.printf("FAIL: nonlocal loop (total=%d, expect 20)\n", total)
|
||||
testcheck.check(total == 20, "nonlocal loop (total == 20)", "nonlocal loop (expect 20)")
|
||||
|
||||
# ============================================================
|
||||
# Test 8: global 数组操作
|
||||
# ============================================================
|
||||
g_arr: list[t.CInt, 4] = [0]
|
||||
g_arr: t.CArray[t.CInt, 4] = [0]
|
||||
|
||||
def test_global_array():
|
||||
stdio.printf("--- Test 8: global array ---\n")
|
||||
testcheck.section("Test 8: global array")
|
||||
global g_arr
|
||||
g_arr[0] = 10
|
||||
g_arr[1] = 20
|
||||
g_arr[2] = 30
|
||||
g_arr[3] = 40
|
||||
total: t.CInt = g_arr[0] + g_arr[1] + g_arr[2] + g_arr[3]
|
||||
if total == 100:
|
||||
stdio.printf("PASS: global array (total=%d)\n", total)
|
||||
else:
|
||||
stdio.printf("FAIL: global array (total=%d, expect 100)\n", total)
|
||||
testcheck.check(total == 100, "global array (total == 100)", "global array (expect 100)")
|
||||
|
||||
# ============================================================
|
||||
# Test 9: 嵌套函数条件调用
|
||||
# ============================================================
|
||||
def test_nested_conditional():
|
||||
stdio.printf("--- Test 9: nested conditional call ---\n")
|
||||
testcheck.section("Test 9: nested conditional call")
|
||||
result: t.CInt = 0
|
||||
def set_result(val: t.CInt):
|
||||
nonlocal result
|
||||
@@ -160,26 +137,20 @@ def test_nested_conditional():
|
||||
set_result(42)
|
||||
else:
|
||||
set_result(99)
|
||||
if result == 42:
|
||||
stdio.printf("PASS: nested conditional (result=%d)\n", result)
|
||||
else:
|
||||
stdio.printf("FAIL: nested conditional (result=%d, expect 42)\n", result)
|
||||
testcheck.check(result == 42, "nested conditional (result == 42)", "nested conditional (expect 42)")
|
||||
|
||||
# ============================================================
|
||||
# Test 10: lambda 链式调用
|
||||
# ============================================================
|
||||
def test_lambda_chain():
|
||||
stdio.printf("--- Test 10: lambda chain ---\n")
|
||||
testcheck.section("Test 10: lambda chain")
|
||||
f1 = lambda: 10
|
||||
f2 = lambda: 20
|
||||
r: t.CInt = f1() + f2()
|
||||
if r == 30:
|
||||
stdio.printf("PASS: lambda chain (10+20=%d)\n", r)
|
||||
else:
|
||||
stdio.printf("FAIL: lambda chain (result=%d, expect 30)\n", r)
|
||||
testcheck.check(r == 30, "lambda chain (10+20 == 30)", "lambda chain (expect 30)")
|
||||
|
||||
def main() -> t.CInt:
|
||||
stdio.printf("=== ClosureAdvancedTest: 高级闭包测试 ===\n\n")
|
||||
testcheck.begin("ClosureAdvancedTest: 高级闭包测试")
|
||||
test_global_in_nested()
|
||||
test_nonlocal_multi_level()
|
||||
test_global_nonlocal_mixed()
|
||||
@@ -190,5 +161,4 @@ def main() -> t.CInt:
|
||||
test_global_array()
|
||||
test_nested_conditional()
|
||||
test_lambda_chain()
|
||||
stdio.printf("\n=== ClosureAdvancedTest Complete ===\n")
|
||||
return 0
|
||||
return testcheck.end()
|
||||
|
||||
1
Test/ClosureTest/output/52e6b51da061882f.deps.json
Normal file
1
Test/ClosureTest/output/52e6b51da061882f.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782"}
|
||||
@@ -1 +0,0 @@
|
||||
{"stdio": "73edbcf76e32d00b"}
|
||||
1
Test/ClosureTest/output/9dbecd0942a39782.deps.json
Normal file
1
Test/ClosureTest/output/9dbecd0942a39782.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"main": "52e6b51da061882f", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782"}
|
||||
@@ -8,6 +8,7 @@ import c
|
||||
|
||||
import t
|
||||
import stdio
|
||||
import testcheck
|
||||
|
||||
g_val: t.CExtern | t.CInt
|
||||
|
||||
@@ -31,7 +32,7 @@ def test_nested_return() -> t.CInt: pass
|
||||
def test_nonlocal_loop() -> t.CInt: pass
|
||||
|
||||
|
||||
g_arr: t.CExtern | list[t.CInt, 4]
|
||||
g_arr: t.CExtern | t.CArray[t.CInt, 4]
|
||||
|
||||
def test_global_array() -> t.CInt: pass
|
||||
|
||||
25
Test/ClosureTest/temp/9dbecd0942a39782.pyi
Normal file
25
Test/ClosureTest/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,2 +1,3 @@
|
||||
52e6b51da061882f:main.py
|
||||
73edbcf76e32d00b:includes/stdio.py
|
||||
7dbf085f7e3e8944:main.py
|
||||
9dbecd0942a39782:includes/testcheck.py
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import t
|
||||
import stdio
|
||||
import testcheck
|
||||
|
||||
# ============================================================
|
||||
# Test 1: nonlocal 在条件分支中修改
|
||||
# ============================================================
|
||||
def test_nonlocal_conditional():
|
||||
stdio.printf("--- Test 1: nonlocal in conditional branches ---\n")
|
||||
testcheck.section("Test 1: nonlocal in conditional branches")
|
||||
x: t.CInt = 0
|
||||
def modify(flag: t.CInt):
|
||||
nonlocal x
|
||||
@@ -16,16 +17,13 @@ def test_nonlocal_conditional():
|
||||
modify(1)
|
||||
modify(0)
|
||||
modify(1)
|
||||
if x == 120:
|
||||
stdio.printf("PASS: nonlocal conditional (x=%d)\n", x)
|
||||
else:
|
||||
stdio.printf("FAIL: nonlocal conditional (x=%d, expect 120)\n", x)
|
||||
testcheck.check(x == 120, "nonlocal conditional (x == 120)", "nonlocal conditional (expect 120)")
|
||||
|
||||
# ============================================================
|
||||
# Test 2: 多个nonlocal变量同时修改
|
||||
# ============================================================
|
||||
def test_nonlocal_multi_var():
|
||||
stdio.printf("--- Test 2: multiple nonlocal variables ---\n")
|
||||
testcheck.section("Test 2: multiple nonlocal variables")
|
||||
a: t.CInt = 1
|
||||
b: t.CInt = 2
|
||||
c_val: t.CInt = 3
|
||||
@@ -36,10 +34,7 @@ def test_nonlocal_multi_var():
|
||||
b = c_val
|
||||
c_val = tmp
|
||||
swap_add()
|
||||
if a == 2 and b == 3 and c_val == 1:
|
||||
stdio.printf("PASS: multi nonlocal (a=%d b=%d c=%d)\n", a, b, c_val)
|
||||
else:
|
||||
stdio.printf("FAIL: multi nonlocal (a=%d b=%d c=%d, expect 2 3 1)\n", a, b, c_val)
|
||||
testcheck.check(a == 2 and b == 3 and c_val == 1, "multi nonlocal (a==2 b==3 c==1)", "multi nonlocal (expect 2 3 1)")
|
||||
|
||||
# ============================================================
|
||||
# Test 3: global 在多个函数中交叉修改
|
||||
@@ -55,55 +50,46 @@ def add_global(n: t.CInt):
|
||||
g_counter += n
|
||||
|
||||
def test_global_cross_functions():
|
||||
stdio.printf("--- Test 3: global cross-function modification ---\n")
|
||||
testcheck.section("Test 3: global cross-function modification")
|
||||
global g_counter
|
||||
g_counter = 0
|
||||
inc_global()
|
||||
inc_global()
|
||||
add_global(10)
|
||||
inc_global()
|
||||
if g_counter == 13:
|
||||
stdio.printf("PASS: global cross (g_counter=%d)\n", g_counter)
|
||||
else:
|
||||
stdio.printf("FAIL: global cross (g_counter=%d, expect 13)\n", g_counter)
|
||||
testcheck.check(g_counter == 13, "global cross (g_counter == 13)", "global cross (expect 13)")
|
||||
|
||||
# ============================================================
|
||||
# Test 4: 嵌套函数修改外层局部变量(引用捕获)
|
||||
# ============================================================
|
||||
def test_nested_ref_capture():
|
||||
stdio.printf("--- Test 4: nested function ref capture ---\n")
|
||||
arr: list[t.CInt, 4] = [0]
|
||||
testcheck.section("Test 4: nested function ref capture")
|
||||
arr: t.CArray[t.CInt, 4] = [0]
|
||||
def fill():
|
||||
nonlocal arr
|
||||
for i in range(4):
|
||||
arr[i] = (i + 1) * 10
|
||||
fill()
|
||||
total: t.CInt = arr[0] + arr[1] + arr[2] + arr[3]
|
||||
if total == 100:
|
||||
stdio.printf("PASS: ref capture (total=%d)\n", total)
|
||||
else:
|
||||
stdio.printf("FAIL: ref capture (total=%d, expect 100)\n", total)
|
||||
testcheck.check(total == 100, "ref capture (total == 100)", "ref capture (expect 100)")
|
||||
|
||||
# ============================================================
|
||||
# Test 5: lambda捕获后修改原变量
|
||||
# ============================================================
|
||||
def test_lambda_capture_then_modify():
|
||||
stdio.printf("--- Test 5: lambda capture then modify ---\n")
|
||||
testcheck.section("Test 5: lambda capture then modify")
|
||||
x: t.CInt = 10
|
||||
f = lambda: x
|
||||
r1: t.CInt = f()
|
||||
x = 20
|
||||
r2: t.CInt = f()
|
||||
if r1 == 10 and r2 == 10:
|
||||
stdio.printf("PASS: lambda value capture (before=%d after=%d)\n", r1, r2)
|
||||
else:
|
||||
stdio.printf("FAIL: lambda value capture (before=%d after=%d, expect 10 10)\n", r1, r2)
|
||||
testcheck.check(r1 == 10 and r2 == 10, "lambda value capture (before==10 after==10)", "lambda value capture (expect 10 10)")
|
||||
|
||||
# ============================================================
|
||||
# Test 6: 嵌套函数中nonlocal与循环结合
|
||||
# ============================================================
|
||||
def test_nonlocal_loop_accumulate():
|
||||
stdio.printf("--- Test 6: nonlocal with loop accumulate ---\n")
|
||||
testcheck.section("Test 6: nonlocal with loop accumulate")
|
||||
sum_val: t.CInt = 0
|
||||
count: t.CInt = 0
|
||||
def add_numbers(n: t.CInt):
|
||||
@@ -113,16 +99,13 @@ def test_nonlocal_loop_accumulate():
|
||||
count += 1
|
||||
add_numbers(5) # 1+2+3+4+5=15
|
||||
add_numbers(3) # 1+2+3=6
|
||||
if sum_val == 21 and count == 8:
|
||||
stdio.printf("PASS: loop accumulate (sum=%d count=%d)\n", sum_val, count)
|
||||
else:
|
||||
stdio.printf("FAIL: loop accumulate (sum=%d count=%d, expect 21 8)\n", sum_val, count)
|
||||
testcheck.check(sum_val == 21 and count == 8, "loop accumulate (sum==21 count==8)", "loop accumulate (expect 21 8)")
|
||||
|
||||
# ============================================================
|
||||
# Test 7: 三层嵌套中每层修改不同变量
|
||||
# ============================================================
|
||||
def test_deep_nested_vars():
|
||||
stdio.printf("--- Test 7: deep nested different vars ---\n")
|
||||
testcheck.section("Test 7: deep nested different vars")
|
||||
a: t.CInt = 0
|
||||
b: t.CInt = 0
|
||||
c_val: t.CInt = 0
|
||||
@@ -139,10 +122,7 @@ def test_deep_nested_vars():
|
||||
level2()
|
||||
level1()
|
||||
level1()
|
||||
if a == 2 and b == 20 and c_val == 200:
|
||||
stdio.printf("PASS: deep nested (a=%d b=%d c=%d)\n", a, b, c_val)
|
||||
else:
|
||||
stdio.printf("FAIL: deep nested (a=%d b=%d c=%d, expect 2 20 200)\n", a, b, c_val)
|
||||
testcheck.check(a == 2 and b == 20 and c_val == 200, "deep nested (a==2 b==20 c==200)", "deep nested (expect 2 20 200)")
|
||||
|
||||
# ============================================================
|
||||
# Test 8: global + nonlocal 在同一嵌套函数中
|
||||
@@ -150,7 +130,7 @@ def test_deep_nested_vars():
|
||||
g_state: t.CInt = 0
|
||||
|
||||
def test_global_nonlocal_same_func():
|
||||
stdio.printf("--- Test 8: global+nonlocal in same nested func ---\n")
|
||||
testcheck.section("Test 8: global+nonlocal in same nested func")
|
||||
global g_state
|
||||
g_state = 0
|
||||
local_state: t.CInt = 0
|
||||
@@ -161,30 +141,24 @@ def test_global_nonlocal_same_func():
|
||||
g_state += 1
|
||||
local_state += 2
|
||||
worker(5)
|
||||
if g_state == 5 and local_state == 10:
|
||||
stdio.printf("PASS: global+nonlocal same (g=%d l=%d)\n", g_state, local_state)
|
||||
else:
|
||||
stdio.printf("FAIL: global+nonlocal same (g=%d l=%d, expect 5 10)\n", g_state, local_state)
|
||||
testcheck.check(g_state == 5 and local_state == 10, "global+nonlocal same (g==5 l==10)", "global+nonlocal same (expect 5 10)")
|
||||
|
||||
# ============================================================
|
||||
# Test 9: lambda带默认参数与捕获
|
||||
# ============================================================
|
||||
def test_lambda_default_and_capture():
|
||||
stdio.printf("--- Test 9: lambda with arg and capture ---\n")
|
||||
testcheck.section("Test 9: lambda with arg and capture")
|
||||
base: t.CInt = 100
|
||||
multiply = lambda x: base * x
|
||||
r1: t.CInt = multiply(3)
|
||||
r2: t.CInt = multiply(5)
|
||||
if r1 == 300 and r2 == 500:
|
||||
stdio.printf("PASS: lambda arg+capture (100*3=%d 100*5=%d)\n", r1, r2)
|
||||
else:
|
||||
stdio.printf("FAIL: lambda arg+capture (100*3=%d 100*5=%d, expect 300 500)\n", r1, r2)
|
||||
testcheck.check(r1 == 300 and r2 == 500, "lambda arg+capture (100*3==300 100*5==500)", "lambda arg+capture (expect 300 500)")
|
||||
|
||||
# ============================================================
|
||||
# Test 10: 嵌套函数多次调用累积
|
||||
# ============================================================
|
||||
def test_nested_accumulate():
|
||||
stdio.printf("--- Test 10: nested function accumulate ---\n")
|
||||
testcheck.section("Test 10: nested function accumulate")
|
||||
total: t.CInt = 0
|
||||
def add_val(n: t.CInt):
|
||||
nonlocal total
|
||||
@@ -192,16 +166,13 @@ def test_nested_accumulate():
|
||||
add_val(10)
|
||||
add_val(20)
|
||||
add_val(30)
|
||||
if total == 60:
|
||||
stdio.printf("PASS: nested accumulate (total=%d)\n", total)
|
||||
else:
|
||||
stdio.printf("FAIL: nested accumulate (total=%d, expect 60)\n", total)
|
||||
testcheck.check(total == 60, "nested accumulate (total == 60)", "nested accumulate (expect 60)")
|
||||
|
||||
# ============================================================
|
||||
# Test 11: nonlocal在while循环中
|
||||
# ============================================================
|
||||
def test_nonlocal_while():
|
||||
stdio.printf("--- Test 11: nonlocal in while loop ---\n")
|
||||
testcheck.section("Test 11: nonlocal in while loop")
|
||||
result: t.CInt = 0
|
||||
def countdown(n: t.CInt):
|
||||
nonlocal result
|
||||
@@ -210,10 +181,7 @@ def test_nonlocal_while():
|
||||
result += i
|
||||
i -= 1
|
||||
countdown(5) # 5+4+3+2+1=15
|
||||
if result == 15:
|
||||
stdio.printf("PASS: nonlocal while (result=%d)\n", result)
|
||||
else:
|
||||
stdio.printf("FAIL: nonlocal while (result=%d, expect 15)\n", result)
|
||||
testcheck.check(result == 15, "nonlocal while (result == 15)", "nonlocal while (expect 15)")
|
||||
|
||||
# ============================================================
|
||||
# Test 12: 嵌套函数修改结构体字段
|
||||
@@ -223,7 +191,7 @@ class Point:
|
||||
y: t.CInt
|
||||
|
||||
def test_nested_modify_struct():
|
||||
stdio.printf("--- Test 12: nested modify struct ---\n")
|
||||
testcheck.section("Test 12: nested modify struct")
|
||||
p: Point = Point()
|
||||
p.x = 0
|
||||
p.y = 0
|
||||
@@ -233,13 +201,10 @@ def test_nested_modify_struct():
|
||||
p.y += dy
|
||||
translate(10, 20)
|
||||
translate(5, 15)
|
||||
if p.x == 15 and p.y == 35:
|
||||
stdio.printf("PASS: nested struct (x=%d y=%d)\n", p.x, p.y)
|
||||
else:
|
||||
stdio.printf("FAIL: nested struct (x=%d y=%d, expect 15 35)\n", p.x, p.y)
|
||||
testcheck.check(p.x == 15 and p.y == 35, "nested struct (x==15 y==35)", "nested struct (expect 15 35)")
|
||||
|
||||
def main() -> t.CInt:
|
||||
stdio.printf("=== ClosureTest2: Advanced Closure/Lambda/Global/Nonlocal ===\n\n")
|
||||
testcheck.begin("ClosureTest2: Advanced Closure/Lambda/Global/Nonlocal")
|
||||
test_nonlocal_conditional()
|
||||
test_nonlocal_multi_var()
|
||||
test_global_cross_functions()
|
||||
@@ -252,5 +217,4 @@ def main() -> t.CInt:
|
||||
test_nested_accumulate()
|
||||
test_nonlocal_while()
|
||||
test_nested_modify_struct()
|
||||
stdio.printf("\n=== ClosureTest2 Complete ===\n")
|
||||
return 0
|
||||
return testcheck.end()
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
{"stdio": "73edbcf76e32d00b"}
|
||||
1
Test/ClosureTest2/output/440f18f9dce85a95.deps.json
Normal file
1
Test/ClosureTest2/output/440f18f9dce85a95.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782"}
|
||||
1
Test/ClosureTest2/output/9dbecd0942a39782.deps.json
Normal file
1
Test/ClosureTest2/output/9dbecd0942a39782.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"main": "440f18f9dce85a95", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782"}
|
||||
@@ -8,6 +8,7 @@ import c
|
||||
|
||||
import t
|
||||
import stdio
|
||||
import testcheck
|
||||
|
||||
def test_nonlocal_conditional() -> t.CInt: pass
|
||||
|
||||
25
Test/ClosureTest2/temp/9dbecd0942a39782.pyi
Normal file
25
Test/ClosureTest2/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,2 +1,3 @@
|
||||
052c7f96b9eefa2c:main.py
|
||||
440f18f9dce85a95:main.py
|
||||
73edbcf76e32d00b:includes/stdio.py
|
||||
9dbecd0942a39782:includes/testcheck.py
|
||||
|
||||
77
Test/DecoratorMarkerTest/App/main.py
Normal file
77
Test/DecoratorMarkerTest/App/main.py
Normal file
@@ -0,0 +1,77 @@
|
||||
import t
|
||||
from stdio import printf
|
||||
import testcheck
|
||||
|
||||
|
||||
# 装饰器形式:@t.CStruct 等同于 class Point(t.CStruct):
|
||||
@t.CStruct
|
||||
class Point:
|
||||
x: t.CInt
|
||||
y: t.CInt
|
||||
|
||||
|
||||
# 装饰器形式:@t.CEnum 等同于 class Color(t.CEnum):
|
||||
@t.CEnum
|
||||
class Color:
|
||||
RED = 1
|
||||
GREEN = 2
|
||||
BLUE = 3
|
||||
|
||||
|
||||
# 装饰器形式:@t.CUnion 等同于 class Data(t.CUnion):
|
||||
@t.CUnion
|
||||
class Data:
|
||||
i: t.CInt
|
||||
f: t.CFloat
|
||||
|
||||
|
||||
# 装饰器形式:@t.CExport 等同于 def test() -> t.CInt | t.CExport:
|
||||
@t.CExport
|
||||
def test() -> t.CInt:
|
||||
printf("test_export called\n")
|
||||
return 42
|
||||
|
||||
|
||||
# 装饰器形式:@t.CStatic 等同于 def static_func() -> t.CInt | t.CStatic:
|
||||
@t.CStatic
|
||||
def static_func() -> t.CInt:
|
||||
return 100
|
||||
|
||||
|
||||
# 混合形式:装饰器 + 注解
|
||||
@t.CStatic
|
||||
def mixed_func() -> t.CInt | t.CExport:
|
||||
return 200
|
||||
|
||||
|
||||
def main() -> t.CInt:
|
||||
testcheck.begin("DecoratorMarkerTest: 装饰器标记测试")
|
||||
|
||||
p: Point = Point()
|
||||
p.x = 10
|
||||
p.y = 20
|
||||
printf("Point: (%d, %d)\n", p.x, p.y)
|
||||
testcheck.check(p.x == 10 and p.y == 20, "Point (10, 20)", "Point expect (10, 20)")
|
||||
|
||||
c: t.CInt = Color.GREEN
|
||||
printf("Color: %d\n", c)
|
||||
testcheck.check(c == 2, "Color.GREEN == 2", "Color.GREEN expect 2")
|
||||
|
||||
d: Data = Data()
|
||||
d.i = 65
|
||||
printf("Data.i: %d\n", d.i)
|
||||
testcheck.check(d.i == 65, "Data.i == 65", "Data.i expect 65")
|
||||
|
||||
ret: t.CInt = test()
|
||||
printf("test() returned: %d\n", ret)
|
||||
testcheck.check(ret == 42, "test() returned 42", "test() expect 42")
|
||||
|
||||
s: t.CInt = static_func()
|
||||
printf("static_func() returned: %d\n", s)
|
||||
testcheck.check(s == 100, "static_func() returned 100", "static_func() expect 100")
|
||||
|
||||
m: t.CInt = mixed_func()
|
||||
printf("mixed_func() returned: %d\n", m)
|
||||
testcheck.check(m == 200, "mixed_func() returned 200", "mixed_func() expect 200")
|
||||
|
||||
return testcheck.end()
|
||||
@@ -0,0 +1 @@
|
||||
{"stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "main": "b1122357fee8fd68"}
|
||||
@@ -0,0 +1 @@
|
||||
{"stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782"}
|
||||
29
Test/DecoratorMarkerTest/project.json
Normal file
29
Test/DecoratorMarkerTest/project.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/TermiNexus/TransPyC/main/schemas/project-schema.json",
|
||||
"name": "DecoratorMarkerTest",
|
||||
"version": "1.0.0",
|
||||
"source_dir": "./App",
|
||||
"temp_dir": "./temp",
|
||||
"output_dir": "./output",
|
||||
"compiler": {
|
||||
"cmd": "llc",
|
||||
"flags": ["-filetype=obj", "-relocation-model=pic"]
|
||||
},
|
||||
"linker": {
|
||||
"cmd": "clang++",
|
||||
"flags": ["-lmsvcrt", "-lucrt", "-lpthread", "-lmingwex", "-lkernel32", "-Wl,--allow-multiple-definition"],
|
||||
"output": "DecoratorMarkerTest.exe"
|
||||
},
|
||||
"includes": [
|
||||
"../../includes"
|
||||
],
|
||||
"target": {
|
||||
"triple": "x86_64-pc-windows-gnu",
|
||||
"datalayout": "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
|
||||
},
|
||||
"options": {
|
||||
"slice_level": 3,
|
||||
"target": "llvm",
|
||||
"strict_mode": true
|
||||
}
|
||||
}
|
||||
28
Test/DecoratorMarkerTest/temp/73edbcf76e32d00b.pyi
Normal file
28
Test/DecoratorMarkerTest/temp/73edbcf76e32d00b.pyi
Normal 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
|
||||
25
Test/DecoratorMarkerTest/temp/9dbecd0942a39782.pyi
Normal file
25
Test/DecoratorMarkerTest/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
|
||||
3
Test/DecoratorMarkerTest/temp/_sha1_map.txt
Normal file
3
Test/DecoratorMarkerTest/temp/_sha1_map.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
73edbcf76e32d00b:includes/stdio.py
|
||||
9dbecd0942a39782:includes/testcheck.py
|
||||
b1122357fee8fd68:main.py
|
||||
36
Test/DecoratorMarkerTest/temp/b1122357fee8fd68.pyi
Normal file
36
Test/DecoratorMarkerTest/temp/b1122357fee8fd68.pyi
Normal file
@@ -0,0 +1,36 @@
|
||||
"""
|
||||
Auto-generated Python stub file from main.py
|
||||
Module: main
|
||||
"""
|
||||
|
||||
import c
|
||||
|
||||
|
||||
import t
|
||||
from stdio import printf
|
||||
import testcheck
|
||||
|
||||
@t.CStruct
|
||||
class Point:
|
||||
x: t.CInt
|
||||
y: t.CInt
|
||||
@t.CEnum
|
||||
class Color:
|
||||
RED = 1
|
||||
GREEN = 2
|
||||
BLUE = 3
|
||||
@t.CUnion
|
||||
class Data:
|
||||
i: t.CInt
|
||||
f: t.CFloat
|
||||
|
||||
@t.CExport
|
||||
def test() -> t.CInt: pass
|
||||
|
||||
@t.CStatic
|
||||
def static_func() -> t.CInt: pass
|
||||
|
||||
@t.CStatic
|
||||
def mixed_func() -> t.CInt | t.CExport: pass
|
||||
|
||||
def main() -> t.CInt: pass
|
||||
@@ -1,5 +1,6 @@
|
||||
import t
|
||||
from stdio import printf
|
||||
import testcheck
|
||||
|
||||
# ============================================================
|
||||
# 自定义装饰器处理函数
|
||||
@@ -226,65 +227,72 @@ def fib(n: t.CInt) -> t.CInt | t.CExport:
|
||||
# ============================================================
|
||||
|
||||
def main() -> t.CInt | t.CExport:
|
||||
printf("=== Decorator Test v4 ===\n\n")
|
||||
testcheck.begin("Decorator Test v4")
|
||||
|
||||
# 测试 1:单个 @log
|
||||
printf("--- Test 1: single @log ---\n")
|
||||
testcheck.section("Test 1: single @log")
|
||||
r1: t.CInt = add(3, 4)
|
||||
printf("add(3,4) = %d\n\n", r1)
|
||||
printf("add(3,4) = %d\n", r1)
|
||||
testcheck.check(r1 == 7, "add(3,4) = 7", "add(3,4) expect 7")
|
||||
|
||||
# 测试 2:链式 @log @trace
|
||||
printf("--- Test 2: chained @log @trace ---\n")
|
||||
testcheck.section("Test 2: chained @log @trace")
|
||||
r2: t.CInt = multiply(5, 6)
|
||||
printf("multiply(5,6) = %d\n\n", r2)
|
||||
printf("multiply(5,6) = %d\n", r2)
|
||||
testcheck.check(r2 == 30, "multiply(5,6) = 30", "multiply(5,6) expect 30")
|
||||
|
||||
# 测试 3:void 返回
|
||||
printf("--- Test 3: @log on void function ---\n")
|
||||
testcheck.section("Test 3: @log on void function")
|
||||
greet("Viper")
|
||||
printf("\n")
|
||||
testcheck.ok("@log on void function greet")
|
||||
|
||||
# 测试 4:无参数
|
||||
printf("--- Test 4: @log on no-arg function ---\n")
|
||||
testcheck.section("Test 4: @log on no-arg function")
|
||||
r4: t.CInt = get_value()
|
||||
printf("get_value() = %d\n\n", r4)
|
||||
printf("get_value() = %d\n", r4)
|
||||
testcheck.check(r4 == 42, "get_value() = 42", "get_value() expect 42")
|
||||
|
||||
# 测试 5:@timing
|
||||
printf("--- Test 5: @timing ---\n")
|
||||
testcheck.section("Test 5: @timing")
|
||||
r5: t.CInt = compute(7)
|
||||
printf("compute(7) = %d\n\n", r5)
|
||||
printf("compute(7) = %d\n", r5)
|
||||
testcheck.check(r5 == 50, "compute(7) = 50", "compute(7) expect 50")
|
||||
|
||||
# 测试 6:@repeat(3) — 流程劫持,循环 3 次
|
||||
printf("--- Test 6: @repeat(3) flow hijack ---\n")
|
||||
testcheck.section("Test 6: @repeat(3) flow hijack")
|
||||
echo("hello")
|
||||
printf("\n")
|
||||
testcheck.ok("@repeat(3) flow hijack echo")
|
||||
|
||||
# 测试 7:链式 @timing @log
|
||||
printf("--- Test 7: chained @timing @log ---\n")
|
||||
testcheck.section("Test 7: chained @timing @log")
|
||||
r7: t.CInt = power(2, 10)
|
||||
printf("power(2,10) = %d\n\n", r7)
|
||||
printf("power(2,10) = %d\n", r7)
|
||||
testcheck.check(r7 == 1024, "power(2,10) = 1024", "power(2,10) expect 1024")
|
||||
|
||||
# 测试 8:@skip — 跳过原函数调用
|
||||
printf("--- Test 8: @skip flow hijack ---\n")
|
||||
testcheck.section("Test 8: @skip flow hijack")
|
||||
r8: t.CInt = dangerous()
|
||||
printf("dangerous() = %d (should be 0, skipped)\n\n", r8)
|
||||
printf("dangerous() = %d (should be 0, skipped)\n", r8)
|
||||
testcheck.check(r8 == 0, "dangerous() skipped = 0", "dangerous() expect 0")
|
||||
|
||||
# 测试 9:@repeat(3) 有返回值
|
||||
printf("--- Test 9: @repeat(3) with return value ---\n")
|
||||
testcheck.section("Test 9: @repeat(3) with return value")
|
||||
r9: t.CInt = accumulate(5)
|
||||
printf("accumulate(5) = %d (last iteration result)\n\n", r9)
|
||||
printf("accumulate(5) = %d (last iteration result)\n", r9)
|
||||
testcheck.check(r9 == 50, "accumulate(5) = 50", "accumulate(5) expect 50")
|
||||
|
||||
# 测试 10:递归装饰保护 — @count_calls
|
||||
printf("--- Test 10: recursive decoration protection ---\n")
|
||||
testcheck.section("Test 10: recursive decoration protection")
|
||||
_call_count = 0
|
||||
r10: t.CInt = factorial(5)
|
||||
printf("factorial(5) = %d (should be 120)\n", r10)
|
||||
printf(" decorator call count = %d (should be 1, not 5)\n\n", _call_count)
|
||||
printf(" decorator call count = %d (should be 1, not 5)\n", _call_count)
|
||||
testcheck.check(r10 == 120 and _call_count == 1, "factorial(5)=120, calls=1", "factorial(5) expect 120, calls=1")
|
||||
|
||||
# 测试 11:@log 递归保护 — fib
|
||||
printf("--- Test 11: @log on recursive fib ---\n")
|
||||
testcheck.section("Test 11: @log on recursive fib")
|
||||
r11: t.CInt = fib(6)
|
||||
printf("fib(6) = %d (should be 8)\n", r11)
|
||||
printf(" (should see only 1 LOG enter/exit pair)\n\n")
|
||||
testcheck.check(r11 == 8, "fib(6) = 8", "fib(6) expect 8")
|
||||
|
||||
printf("=== All decorator tests done ===\n")
|
||||
return 0
|
||||
return testcheck.end()
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
{"stdio": "73edbcf76e32d00b"}
|
||||
1
Test/DecoratorTest/output/814e6b31adfc6256.deps.json
Normal file
1
Test/DecoratorTest/output/814e6b31adfc6256.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782"}
|
||||
1
Test/DecoratorTest/output/9dbecd0942a39782.deps.json
Normal file
1
Test/DecoratorTest/output/9dbecd0942a39782.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"stdio": "73edbcf76e32d00b", "main": "814e6b31adfc6256", "testcheck": "9dbecd0942a39782"}
|
||||
@@ -8,6 +8,7 @@ import c
|
||||
|
||||
import t
|
||||
from stdio import printf
|
||||
import testcheck
|
||||
|
||||
def log(ctx: t.CVoid | t.CPtr, func_name: str, phase: t.CInt, args_ptr: t.CVoid | t.CPtr, ret_ptr: t.CVoid | t.CPtr, decor_args_ptr: t.CVoid | t.CPtr) -> t.CInt | t.CExport: pass
|
||||
|
||||
25
Test/DecoratorTest/temp/9dbecd0942a39782.pyi
Normal file
25
Test/DecoratorTest/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,2 +1,3 @@
|
||||
577f9e1aa32b17f8:main.py
|
||||
73edbcf76e32d00b:includes/stdio.py
|
||||
814e6b31adfc6256:main.py
|
||||
9dbecd0942a39782:includes/testcheck.py
|
||||
|
||||
230
Test/DictTest/App/main.py
Normal file
230
Test/DictTest/App/main.py
Normal file
@@ -0,0 +1,230 @@
|
||||
from stdint import *
|
||||
import w32.win32console
|
||||
import t, c
|
||||
from t import CInt, CExport
|
||||
import stdio
|
||||
import stdlib
|
||||
import string
|
||||
import mbuddy
|
||||
import mpool
|
||||
import testcheck
|
||||
|
||||
|
||||
def main() -> CInt | CExport:
|
||||
w32.win32console.SetConsoleCP(65001)
|
||||
w32.win32console.SetConsoleOutputCP(65001)
|
||||
|
||||
testcheck.begin("DictTest: 万能 dict (Variant 存储) 测试")
|
||||
|
||||
# 分配内存竞技场
|
||||
arena: bytes = stdlib.malloc(65536)
|
||||
bd: mbuddy.MBuddy | t.CPtr = mbuddy.MBuddy(arena, 65536)
|
||||
|
||||
# === Test 1: dict set_int / c.Deref 基本操作 ===
|
||||
testcheck.section("Test 1: dict set_int / c.Deref 基本操作")
|
||||
d: dict = dict(bd)
|
||||
d.set_int("alpha", 10)
|
||||
d.set_int("beta", 20)
|
||||
d.set_int("gamma", 30)
|
||||
n: t.CSizeT = len(d)
|
||||
stdio.printf("len=%lu\n", n)
|
||||
testcheck.check(n == 3, "dict len OK (3)", "dict len FAILED")
|
||||
|
||||
p1: t.CPtr = d["alpha"]
|
||||
stdio.printf("p1=%p\n", p1)
|
||||
p2: t.CPtr = d["beta"]
|
||||
stdio.printf("p2=%p\n", p2)
|
||||
p3: t.CPtr = d["gamma"]
|
||||
stdio.printf("p3=%p\n", p3)
|
||||
v1: int = c.Deref(p1)
|
||||
stdio.printf("v1=%d\n", v1)
|
||||
v2: int = c.Deref(p2)
|
||||
v3: int = c.Deref(p3)
|
||||
stdio.printf("alpha=%d beta=%d gamma=%d\n", v1, v2, v3)
|
||||
testcheck.check(v1 == 10, "dict[alpha]==10 OK", "dict[alpha] FAILED")
|
||||
testcheck.check(v2 == 20, "dict[beta]==20 OK", "dict[beta] FAILED")
|
||||
testcheck.check(v3 == 30, "dict[gamma]==30 OK", "dict[gamma] FAILED")
|
||||
|
||||
# === Test 2: 更新已有键 ===
|
||||
testcheck.section("Test 2: 更新已有键")
|
||||
d.set_int("beta", 99)
|
||||
p2b: t.CPtr = d["beta"]
|
||||
v2b: int = c.Deref(p2b)
|
||||
stdio.printf("beta(updated)=%d\n", v2b)
|
||||
testcheck.check(v2b == 99, "dict update OK", "dict update FAILED")
|
||||
testcheck.check(len(d) == 3, "dict len still 3 OK", "dict len changed FAILED")
|
||||
|
||||
# === Test 3: get with default ===
|
||||
testcheck.section("Test 3: get with default")
|
||||
gv: t.CPtr = d.get("missing", None)
|
||||
testcheck.check(gv == None, "dict get missing OK (None)", "dict get missing FAILED")
|
||||
|
||||
gp: t.CPtr = d.get("alpha", None)
|
||||
ga: int = c.Deref(gp)
|
||||
stdio.printf("get(alpha)=%d\n", ga)
|
||||
testcheck.check(ga == 10, "dict get existing OK", "dict get existing FAILED")
|
||||
|
||||
# === Test 4: contains ===
|
||||
testcheck.section("Test 4: contains")
|
||||
has_alpha: t.CInt = d.contains("alpha")
|
||||
has_missing: t.CInt = d.contains("missing")
|
||||
stdio.printf("contains(alpha)=%d contains(missing)=%d\n", has_alpha, has_missing)
|
||||
testcheck.check(has_alpha == 1, "contains alpha OK", "contains alpha FAILED")
|
||||
testcheck.check(has_missing == 0, "not contains missing OK", "contains missing FAILED")
|
||||
|
||||
# === Test 5: 迭代器 ===
|
||||
testcheck.section("Test 5: 迭代器 for key in dict")
|
||||
iter_count: int = 0
|
||||
for key in d:
|
||||
kp: t.CPtr = d[key]
|
||||
val: int = c.Deref(kp)
|
||||
stdio.printf("dict[%s]=%d\n", key, val)
|
||||
iter_count += 1
|
||||
testcheck.check(iter_count == 3, "dict iter OK (3)", "dict iter FAILED")
|
||||
|
||||
# === Test 6: dict set_str 字符串值 ===
|
||||
testcheck.section("Test 6: dict set_str 字符串值")
|
||||
d2: dict = dict(bd)
|
||||
d2.set_str("name", "Alice")
|
||||
d2.set_str("city", "Beijing")
|
||||
d2.set_str("lang", "TransPyC")
|
||||
n2: t.CSizeT = len(d2)
|
||||
stdio.printf("d2 len=%lu\n", n2)
|
||||
testcheck.check(n2 == 3, "dict set_str len OK (3)", "dict set_str len FAILED")
|
||||
|
||||
name_p: t.CPtr = d2["name"]
|
||||
city_p: t.CPtr = d2["city"]
|
||||
lang_p: t.CPtr = d2["lang"]
|
||||
name: str = name_p
|
||||
city: str = city_p
|
||||
lang: str = lang_p
|
||||
stdio.printf("name=%s city=%s lang=%s\n", name, city, lang)
|
||||
testcheck.check(string.strcmp(name, "Alice") == 0, "dict str name OK", "dict str name FAILED")
|
||||
testcheck.check(string.strcmp(city, "Beijing") == 0, "dict str city OK", "dict str city FAILED")
|
||||
testcheck.check(string.strcmp(lang, "TransPyC") == 0, "dict str lang OK", "dict str lang FAILED")
|
||||
|
||||
# === Test 7: dict[str] 迭代 ===
|
||||
testcheck.section("Test 7: dict 迭代 (str values)")
|
||||
str_iter_count: int = 0
|
||||
for k in d2:
|
||||
svp: t.CPtr = d2[k]
|
||||
sv: str = svp
|
||||
stdio.printf("d2[%s]=%s\n", k, sv)
|
||||
str_iter_count += 1
|
||||
testcheck.check(str_iter_count == 3, "dict str iter OK (3)", "dict str iter FAILED")
|
||||
|
||||
# === Test 8: 扩容测试 ===
|
||||
testcheck.section("Test 8: 扩容测试 (>8 个元素)")
|
||||
d3: dict = dict(bd)
|
||||
i: int = 0
|
||||
while i < 20:
|
||||
key_buf: str = stdlib.malloc(16)
|
||||
stdio.sprintf(key_buf, "key%d", i)
|
||||
d3.set_int(key_buf, i * 100)
|
||||
i += 1
|
||||
n3: t.CSizeT = len(d3)
|
||||
stdio.printf("d3 len=%lu (after 20 inserts)\n", n3)
|
||||
testcheck.check(n3 == 20, "dict expand OK (20)", "dict expand FAILED")
|
||||
|
||||
# 验证几个值
|
||||
k5: str = stdlib.malloc(16)
|
||||
stdio.sprintf(k5, "key5")
|
||||
p5: t.CPtr = d3[k5]
|
||||
v5: int = c.Deref(p5)
|
||||
stdio.printf("d3[key5]=%d\n", v5)
|
||||
testcheck.check(v5 == 500, "dict expand key5 OK", "dict expand key5 FAILED")
|
||||
|
||||
k15: str = stdlib.malloc(16)
|
||||
stdio.sprintf(k15, "key15")
|
||||
p15: t.CPtr = d3[k15]
|
||||
v15: int = c.Deref(p15)
|
||||
stdio.printf("d3[key15]=%d\n", v15)
|
||||
testcheck.check(v15 == 1500, "dict expand key15 OK", "dict expand key15 FAILED")
|
||||
|
||||
# === Test 9: JSON dumps ===
|
||||
testcheck.section("Test 9: JSON dumps")
|
||||
pool_mem: bytes = stdlib.malloc(65536)
|
||||
pool: mpool.MPool = mpool.MPool(pool_mem, 65536, 0)
|
||||
|
||||
jd: dict = dict(bd)
|
||||
jd.set_int("x", 100)
|
||||
jd.set_int("y", 200)
|
||||
jd.set_int("z", 300)
|
||||
|
||||
json_str: str = jd.dumps(pool)
|
||||
stdio.printf("JSON dumps: %s\n", json_str)
|
||||
testcheck.check(json_str != None, "dumps OK", "dumps FAILED (null)")
|
||||
|
||||
# === Test 10: JSON loads ===
|
||||
testcheck.section("Test 10: JSON loads")
|
||||
jd2: dict = dict(bd)
|
||||
jd2.loads(pool, "{\"x\":1,\"y\":2,\"z\":3}")
|
||||
xp: t.CPtr = jd2["x"]
|
||||
yp: t.CPtr = jd2["y"]
|
||||
zp: t.CPtr = jd2["z"]
|
||||
xv: int = c.Deref(xp)
|
||||
yv: int = c.Deref(yp)
|
||||
zv: int = c.Deref(zp)
|
||||
stdio.printf("loads: x=%d y=%d z=%d\n", xv, yv, zv)
|
||||
testcheck.check(xv == 1, "loads x OK", "loads x FAILED")
|
||||
testcheck.check(yv == 2, "loads y OK", "loads y FAILED")
|
||||
testcheck.check(zv == 3, "loads z OK", "loads z FAILED")
|
||||
|
||||
# === Test 11: JSON dumps (str values) ===
|
||||
testcheck.section("Test 11: JSON dumps (str values)")
|
||||
jd3: dict = dict(bd)
|
||||
jd3.set_str("name", "Alice")
|
||||
jd3.set_str("city", "Beijing")
|
||||
|
||||
json_str2: str = jd3.dumps(pool)
|
||||
stdio.printf("JSON dumps (str): %s\n", json_str2)
|
||||
testcheck.check(json_str2 != None, "dumps str OK", "dumps str FAILED (null)")
|
||||
|
||||
# === Test 12: JSON round-trip ===
|
||||
testcheck.section("Test 12: JSON round-trip")
|
||||
rt: dict = dict(bd)
|
||||
rt.set_int("a", 1)
|
||||
rt.set_int("b", 2)
|
||||
rt_str: str = rt.dumps(pool)
|
||||
stdio.printf("round-trip dump: %s\n", rt_str)
|
||||
rt2: dict = dict(bd)
|
||||
rt2.loads(pool, rt_str)
|
||||
rta_p: t.CPtr = rt2["a"]
|
||||
rtb_p: t.CPtr = rt2["b"]
|
||||
rta: int = c.Deref(rta_p)
|
||||
rtb: int = c.Deref(rtb_p)
|
||||
stdio.printf("round-trip: a=%d b=%d\n", rta, rtb)
|
||||
testcheck.check(rta == 1, "round-trip a OK", "round-trip a FAILED")
|
||||
testcheck.check(rtb == 2, "round-trip b OK", "round-trip b FAILED")
|
||||
|
||||
# === Test 13: 嵌套 dict ===
|
||||
testcheck.section("Test 13: 嵌套 dict")
|
||||
outer: dict = dict(bd)
|
||||
inner: dict = dict(bd)
|
||||
inner.set_int("a", 1)
|
||||
inner.set_int("b", 2)
|
||||
outer.set_dict("sub", inner)
|
||||
|
||||
sub_p: t.CPtr = outer["sub"]
|
||||
sub: dict = sub_p
|
||||
sa_p: t.CPtr = sub["a"]
|
||||
sb_p: t.CPtr = sub["b"]
|
||||
sa: int = c.Deref(sa_p)
|
||||
sb: int = c.Deref(sb_p)
|
||||
stdio.printf("nested: sub.a=%d sub.b=%d\n", sa, sb)
|
||||
testcheck.check(sa == 1, "nested sub.a OK", "nested sub.a FAILED")
|
||||
testcheck.check(sb == 2, "nested sub.b OK", "nested sub.b FAILED")
|
||||
|
||||
# === Test 14: get_vtype 类型标签 ===
|
||||
testcheck.section("Test 14: get_vtype 类型标签")
|
||||
vt1: t.CInt = d.get_vtype("alpha")
|
||||
vt2: t.CInt = d2.get_vtype("name")
|
||||
vt3: t.CInt = outer.get_vtype("sub")
|
||||
stdio.printf("vtype(alpha)=%d vtype(name)=%d vtype(sub)=%d\n", vt1, vt2, vt3)
|
||||
testcheck.check(vt1 == 1, "vtype int OK", "vtype int FAILED")
|
||||
testcheck.check(vt2 == 4, "vtype str OK", "vtype str FAILED")
|
||||
testcheck.check(vt3 == 5, "vtype dict OK", "vtype dict FAILED")
|
||||
|
||||
stdlib.free(pool_mem)
|
||||
stdlib.free(arena)
|
||||
return testcheck.end()
|
||||
1
Test/DictTest/output/067c78e9f121dce3.deps.json
Normal file
1
Test/DictTest/output/067c78e9f121dce3.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"mpool": "0991af0d22263577", "mbuddy": "0eaa586c42dcd931", "atom": "271ea3decb810db2", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "stdlib": "6c2029b306556c00", "stdio": "73edbcf76e32d00b", "json.__init__": "8ee3170049c70333", "__init__": "8ee3170049c70333", "json": "8ee3170049c70333", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "json.__parser": "bd2e7db1744476fe", "__parser": "bd2e7db1744476fe", "viperio": "c9f4be41ca1cc2b4", "json.__writer": "eaf7a981f0ef5b22", "__writer": "eaf7a981f0ef5b22", "_dict": "f1e15ccf054b1e89", "main": "fced53b138f67cf5", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "w32.win32process": "067c78e9f121dce3", "win32process": "067c78e9f121dce3"}
|
||||
1
Test/DictTest/output/06f53cc594b4ac6c.deps.json
Normal file
1
Test/DictTest/output/06f53cc594b4ac6c.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"mpool": "0991af0d22263577", "mbuddy": "0eaa586c42dcd931", "atom": "271ea3decb810db2", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "stdlib": "6c2029b306556c00", "stdio": "73edbcf76e32d00b", "json.__init__": "8ee3170049c70333", "__init__": "8ee3170049c70333", "json": "8ee3170049c70333", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "json.__parser": "bd2e7db1744476fe", "__parser": "bd2e7db1744476fe", "viperio": "c9f4be41ca1cc2b4", "json.__writer": "eaf7a981f0ef5b22", "__writer": "eaf7a981f0ef5b22", "_dict": "f1e15ccf054b1e89", "main": "fced53b138f67cf5", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "w32.win32process": "067c78e9f121dce3", "win32process": "067c78e9f121dce3", "w32.win32sync": "06f53cc594b4ac6c", "win32sync": "06f53cc594b4ac6c"}
|
||||
1
Test/DictTest/output/0991af0d22263577.deps.json
Normal file
1
Test/DictTest/output/0991af0d22263577.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"mpool": "0991af0d22263577", "mbuddy": "0eaa586c42dcd931", "atom": "271ea3decb810db2", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "stdlib": "6c2029b306556c00", "stdio": "73edbcf76e32d00b", "json.__init__": "8ee3170049c70333", "__init__": "8ee3170049c70333", "json": "8ee3170049c70333", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "json.__parser": "bd2e7db1744476fe", "__parser": "bd2e7db1744476fe", "viperio": "c9f4be41ca1cc2b4", "json.__writer": "eaf7a981f0ef5b22", "__writer": "eaf7a981f0ef5b22", "_dict": "f1e15ccf054b1e89", "main": "fced53b138f67cf5"}
|
||||
1
Test/DictTest/output/0eaa586c42dcd931.deps.json
Normal file
1
Test/DictTest/output/0eaa586c42dcd931.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"mpool": "0991af0d22263577", "mbuddy": "0eaa586c42dcd931", "atom": "271ea3decb810db2", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "stdlib": "6c2029b306556c00", "stdio": "73edbcf76e32d00b", "json.__init__": "8ee3170049c70333", "__init__": "8ee3170049c70333", "json": "8ee3170049c70333", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "json.__parser": "bd2e7db1744476fe", "__parser": "bd2e7db1744476fe", "viperio": "c9f4be41ca1cc2b4", "json.__writer": "eaf7a981f0ef5b22", "__writer": "eaf7a981f0ef5b22", "_dict": "f1e15ccf054b1e89", "main": "fced53b138f67cf5"}
|
||||
1
Test/DictTest/output/271ea3decb810db2.deps.json
Normal file
1
Test/DictTest/output/271ea3decb810db2.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"mpool": "0991af0d22263577", "mbuddy": "0eaa586c42dcd931", "atom": "271ea3decb810db2", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "stdlib": "6c2029b306556c00", "stdio": "73edbcf76e32d00b", "json.__init__": "8ee3170049c70333", "__init__": "8ee3170049c70333", "json": "8ee3170049c70333", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "json.__parser": "bd2e7db1744476fe", "__parser": "bd2e7db1744476fe", "viperio": "c9f4be41ca1cc2b4", "json.__writer": "eaf7a981f0ef5b22", "__writer": "eaf7a981f0ef5b22", "_dict": "f1e15ccf054b1e89", "main": "fced53b138f67cf5"}
|
||||
1
Test/DictTest/output/5a6a2137958c28c5.deps.json
Normal file
1
Test/DictTest/output/5a6a2137958c28c5.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"mpool": "0991af0d22263577", "mbuddy": "0eaa586c42dcd931", "atom": "271ea3decb810db2", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "stdlib": "6c2029b306556c00", "stdio": "73edbcf76e32d00b", "json.__init__": "8ee3170049c70333", "__init__": "8ee3170049c70333", "json": "8ee3170049c70333", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "json.__parser": "bd2e7db1744476fe", "__parser": "bd2e7db1744476fe", "viperio": "c9f4be41ca1cc2b4", "json.__writer": "eaf7a981f0ef5b22", "__writer": "eaf7a981f0ef5b22", "_dict": "f1e15ccf054b1e89", "main": "fced53b138f67cf5"}
|
||||
1
Test/DictTest/output/72e2d5ccb7cedcf1.deps.json
Normal file
1
Test/DictTest/output/72e2d5ccb7cedcf1.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"mpool": "0991af0d22263577", "mbuddy": "0eaa586c42dcd931", "atom": "271ea3decb810db2", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "stdlib": "6c2029b306556c00", "stdio": "73edbcf76e32d00b", "json.__init__": "8ee3170049c70333", "__init__": "8ee3170049c70333", "json": "8ee3170049c70333", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "json.__parser": "bd2e7db1744476fe", "__parser": "bd2e7db1744476fe", "viperio": "c9f4be41ca1cc2b4", "json.__writer": "eaf7a981f0ef5b22", "__writer": "eaf7a981f0ef5b22", "_dict": "f1e15ccf054b1e89", "main": "fced53b138f67cf5", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1"}
|
||||
1
Test/DictTest/output/8ee3170049c70333.deps.json
Normal file
1
Test/DictTest/output/8ee3170049c70333.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"mpool": "0991af0d22263577", "mbuddy": "0eaa586c42dcd931", "atom": "271ea3decb810db2", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "stdlib": "6c2029b306556c00", "stdio": "73edbcf76e32d00b", "json.__init__": "8ee3170049c70333", "__init__": "8ee3170049c70333", "json": "8ee3170049c70333", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "json.__parser": "bd2e7db1744476fe", "__parser": "bd2e7db1744476fe", "viperio": "c9f4be41ca1cc2b4", "json.__writer": "eaf7a981f0ef5b22", "__writer": "eaf7a981f0ef5b22", "_dict": "f1e15ccf054b1e89", "main": "fced53b138f67cf5"}
|
||||
1
Test/DictTest/output/9dbecd0942a39782.deps.json
Normal file
1
Test/DictTest/output/9dbecd0942a39782.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"mpool": "0991af0d22263577", "mbuddy": "0eaa586c42dcd931", "atom": "271ea3decb810db2", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "stdlib": "6c2029b306556c00", "stdio": "73edbcf76e32d00b", "json.__init__": "8ee3170049c70333", "__init__": "8ee3170049c70333", "json": "8ee3170049c70333", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "json.__parser": "bd2e7db1744476fe", "__parser": "bd2e7db1744476fe", "viperio": "c9f4be41ca1cc2b4", "json.__writer": "eaf7a981f0ef5b22", "__writer": "eaf7a981f0ef5b22", "_dict": "f1e15ccf054b1e89", "main": "fced53b138f67cf5"}
|
||||
1
Test/DictTest/output/abf9ce3160c9279e.deps.json
Normal file
1
Test/DictTest/output/abf9ce3160c9279e.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"mpool": "0991af0d22263577", "mbuddy": "0eaa586c42dcd931", "atom": "271ea3decb810db2", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "stdlib": "6c2029b306556c00", "stdio": "73edbcf76e32d00b", "json.__init__": "8ee3170049c70333", "__init__": "8ee3170049c70333", "json": "8ee3170049c70333", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "json.__parser": "bd2e7db1744476fe", "__parser": "bd2e7db1744476fe", "viperio": "c9f4be41ca1cc2b4", "json.__writer": "eaf7a981f0ef5b22", "__writer": "eaf7a981f0ef5b22", "_dict": "f1e15ccf054b1e89", "main": "fced53b138f67cf5", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e"}
|
||||
1
Test/DictTest/output/b5f1dc665c52a1bd.deps.json
Normal file
1
Test/DictTest/output/b5f1dc665c52a1bd.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"mpool": "0991af0d22263577", "mbuddy": "0eaa586c42dcd931", "atom": "271ea3decb810db2", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "stdlib": "6c2029b306556c00", "stdio": "73edbcf76e32d00b", "json.__init__": "8ee3170049c70333", "__init__": "8ee3170049c70333", "json": "8ee3170049c70333", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "json.__parser": "bd2e7db1744476fe", "__parser": "bd2e7db1744476fe", "viperio": "c9f4be41ca1cc2b4", "json.__writer": "eaf7a981f0ef5b22", "__writer": "eaf7a981f0ef5b22", "_dict": "f1e15ccf054b1e89", "main": "fced53b138f67cf5"}
|
||||
1
Test/DictTest/output/bbdf3bbd4c3bc28c.deps.json
Normal file
1
Test/DictTest/output/bbdf3bbd4c3bc28c.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"mpool": "0991af0d22263577", "mbuddy": "0eaa586c42dcd931", "atom": "271ea3decb810db2", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "stdlib": "6c2029b306556c00", "stdio": "73edbcf76e32d00b", "json.__init__": "8ee3170049c70333", "__init__": "8ee3170049c70333", "json": "8ee3170049c70333", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "json.__parser": "bd2e7db1744476fe", "__parser": "bd2e7db1744476fe", "viperio": "c9f4be41ca1cc2b4", "json.__writer": "eaf7a981f0ef5b22", "__writer": "eaf7a981f0ef5b22", "_dict": "f1e15ccf054b1e89", "main": "fced53b138f67cf5"}
|
||||
1
Test/DictTest/output/bd2e7db1744476fe.deps.json
Normal file
1
Test/DictTest/output/bd2e7db1744476fe.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"mpool": "0991af0d22263577", "mbuddy": "0eaa586c42dcd931", "atom": "271ea3decb810db2", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "stdlib": "6c2029b306556c00", "stdio": "73edbcf76e32d00b", "json.__init__": "8ee3170049c70333", "__init__": "8ee3170049c70333", "json": "8ee3170049c70333", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "json.__parser": "bd2e7db1744476fe", "__parser": "bd2e7db1744476fe", "viperio": "c9f4be41ca1cc2b4", "json.__writer": "eaf7a981f0ef5b22", "__writer": "eaf7a981f0ef5b22", "_dict": "f1e15ccf054b1e89", "main": "fced53b138f67cf5"}
|
||||
1
Test/DictTest/output/c9f4be41ca1cc2b4.deps.json
Normal file
1
Test/DictTest/output/c9f4be41ca1cc2b4.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"mpool": "0991af0d22263577", "mbuddy": "0eaa586c42dcd931", "atom": "271ea3decb810db2", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "stdlib": "6c2029b306556c00", "stdio": "73edbcf76e32d00b", "json.__init__": "8ee3170049c70333", "__init__": "8ee3170049c70333", "json": "8ee3170049c70333", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "json.__parser": "bd2e7db1744476fe", "__parser": "bd2e7db1744476fe", "viperio": "c9f4be41ca1cc2b4", "json.__writer": "eaf7a981f0ef5b22", "__writer": "eaf7a981f0ef5b22", "_dict": "f1e15ccf054b1e89", "main": "fced53b138f67cf5"}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user