This commit is contained in:
2026-06-16 16:09:42 +08:00
commit bffb0cb6b7
644 changed files with 86620 additions and 0 deletions

99
Test/LoopTest/App/main.py Normal file
View File

@@ -0,0 +1,99 @@
import t
import stdio
def test_for_loop():
stdio.printf("--- Test 1: for loop ---\n")
sum_val: t.CInt = 0
for i in range(10):
sum_val += i
# 0+1+2+...+9 = 45
if sum_val == 45:
stdio.printf("PASS: for loop sum (0..9 = %d)\n", sum_val)
else:
stdio.printf("FAIL: for loop sum (%d, expect 45)\n", sum_val)
def test_while_loop():
stdio.printf("--- Test 2: while loop ---\n")
n: t.CInt = 100
count: t.CInt = 0
while n > 1:
if n % 2 == 0:
n = n // 2
else:
n = 3 * n + 1
count += 1
# Collatz conjecture: 100 -> 50 -> 25 -> 76 -> ... -> 1, takes 25 steps
stdio.printf("PASS: while loop Collatz(100) steps=%d\n", count)
def test_nested_loop():
stdio.printf("--- Test 3: nested loop ---\n")
count: t.CInt = 0
for i in range(5):
for j in range(5):
if i < j:
count += 1
# 上三角: 4+3+2+1 = 10
if count == 10:
stdio.printf("PASS: nested loop (count=%d)\n", count)
else:
stdio.printf("FAIL: nested loop (count=%d, expect 10)\n", count)
def test_break():
stdio.printf("--- Test 4: break ---\n")
found: t.CInt = -1
for i in range(100):
if i * i > 50:
found = i
break
# 7*7=49<=50, 8*8=64>50
if found == 8:
stdio.printf("PASS: break (found=%d)\n", found)
else:
stdio.printf("FAIL: break (found=%d, expect 8)\n", found)
def test_continue():
stdio.printf("--- Test 5: continue ---\n")
sum_val: t.CInt = 0
for i in range(20):
if i % 3 == 0:
continue
sum_val += i
# 跳过 0,3,6,9,12,15,18, 剩余和 = sum(0..19) - sum(0,3,6,9,12,15,18) = 190 - 63 = 127
if sum_val == 127:
stdio.printf("PASS: continue (sum=%d)\n", sum_val)
else:
stdio.printf("FAIL: continue (sum=%d, expect 127)\n", sum_val)
def test_range_step():
stdio.printf("--- Test 6: range with step ---\n")
sum_val: t.CInt = 0
for i in range(0, 20, 3):
sum_val += i
# 0+3+6+9+12+15+18 = 63
if sum_val == 63:
stdio.printf("PASS: range step (sum=%d)\n", sum_val)
else:
stdio.printf("FAIL: range step (sum=%d, expect 63)\n", sum_val)
def test_loop_u64():
stdio.printf("--- Test 7: loop with u64 counter ---\n")
total: t.CUInt64T = 0
for i in range(100):
total += t.CUInt64T(i)
# 0+1+2+...+99 = 4950
if total == 4950:
stdio.printf("PASS: u64 loop (total=%lu)\n", total)
else:
stdio.printf("FAIL: u64 loop (total=%lu, expect 4950)\n", total)
def main() -> t.CInt:
stdio.printf("=== LoopTest: 循环与控制流基准测试 ===\n\n")
test_for_loop()
test_while_loop()
test_nested_loop()
test_break()
test_continue()
test_range_step()
test_loop_u64()
stdio.printf("\n=== LoopTest Complete ===\n")
return 0

View File

@@ -0,0 +1 @@
{"stdio": "73edbcf76e32d00b"}

View File

@@ -0,0 +1,29 @@
{
"$schema": "https://raw.githubusercontent.com/TermiNexus/TransPyC/main/schemas/project-schema.json",
"name": "LoopTest",
"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": ["-Wl,--allow-multiple-definition", "-Wl,--unresolved-symbols=ignore-in-object-files", "-lmsvcrt", "-lucrt", "-lpthread", "-lmingwex", "-lkernel32", "-luser32", "-latomic"],
"output": "LoopTest.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
}
}

View File

@@ -0,0 +1,26 @@
"""
Auto-generated Python stub file from main.py
Module: main
"""
import c
import t
import stdio
def test_for_loop() -> t.CInt: pass
def test_while_loop() -> t.CInt: pass
def test_nested_loop() -> t.CInt: pass
def test_break() -> t.CInt: pass
def test_continue() -> t.CInt: pass
def test_range_step() -> t.CInt: pass
def test_loop_u64() -> t.CInt: pass
def main() -> t.CInt: pass

View File

@@ -0,0 +1,28 @@
"""
Auto-generated Python stub file from stdio.py
Module: stdio
"""
import t, c
def printf(fmt: t.CChar | t.CConst | t.CPtr, *args) -> t.CInt | t.CExtern | t.CExport: pass
def fprintf(stream: t.CVoid | t.CPtr, fmt: t.CChar | t.CConst | t.CPtr, *args) -> t.CInt | t.CExtern | t.CExport: pass
def sprintf(buf: t.CChar | t.CPtr, fmt: t.CChar | t.CConst | t.CPtr, *args) -> t.CInt | t.CExtern | t.CExport: pass
def snprintf(buf: t.CChar | t.CPtr, size: t.CSizeT, fmt: t.CChar | t.CConst | t.CPtr, *args) -> t.CInt | t.CExtern | t.CExport: pass
def puts(s: t.CChar | t.CConst | t.CPtr) -> t.CInt | t.CExtern | t.CExport: pass
def fputs(s: t.CChar | t.CConst | t.CPtr, stream: t.CVoid | t.CPtr) -> t.CInt | t.CExtern | t.CExport: pass
def fgets(buf: t.CChar | t.CPtr, size: t.CInt, stream: t.CVoid | t.CPtr) -> t.CChar | t.CPtr | t.CExtern | t.CExport: pass
def fflush(stream: t.CVoid | t.CPtr) -> t.CInt | t.CExtern | t.CExport: pass
stdin: t.CExtern | t.CVoid | t.CPtr
stdout: t.CExtern | t.CVoid | t.CPtr
stderr: t.CExtern | t.CVoid | t.CPtr

View File

@@ -0,0 +1,2 @@
4b6b35e3922a169f:main.py
73edbcf76e32d00b:includes/stdio.py