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

This commit is contained in:
2026-06-25 14:49:46 +08:00
parent 19f2787db0
commit d88d11b646
827 changed files with 32617 additions and 18316 deletions

View File

@@ -0,0 +1,128 @@
from stdint import *
import t, c
import stdio
import vrandom
import testcheck
# ============================================================
# VRandomTest - 硬件随机数生成 + 标准分布函数测试
# ============================================================
def main() -> t.CInt:
testcheck.begin("VRandomTest: Hardware RNG + Distributions")
# --- Test 1: RDRAND basic ---
testcheck.section("Test 1: RDRAND basic")
r32: t.CUInt32T = vrandom.rdrand32()
r64: t.CUInt64T = vrandom.rdrand64()
stdio.printf(" rdrand32() = 0x%08x\n", r32)
stdio.printf(" rdrand64() = 0x%016llx\n", r64)
testcheck.ok("RDRAND basic")
# --- Test 2: randint ---
testcheck.section("Test 2: randint(1, 100)")
for _ in range(5):
v: t.CInt = vrandom.randint(1, 100)
stdio.printf(" randint(1,100) = %d\n", v)
testcheck.ok("randint range check")
# --- Test 3: randrange ---
testcheck.section("Test 3: randrange(0, 100, 5)")
for _ in range(5):
v = vrandom.randrange(0, 100, 5)
stdio.printf(" randrange(0,100,5) = %d\n", v)
testcheck.ok("randrange step check")
# --- Test 4: getrandbits ---
testcheck.section("Test 4: getrandbits(8)")
for _ in range(3):
b: t.CUInt64T = vrandom.getrandbits(8)
stdio.printf(" getrandbits(8) = 0x%02llx\n", b)
testcheck.ok("getrandbits width check")
# --- Test 5: random() [0,1) ---
testcheck.section("Test 5: random()")
for _ in range(3):
f: t.CDouble = vrandom.random()
stdio.printf(" random() = %f\n", f)
testcheck.ok("random() in [0,1)")
# --- Test 6: uniform ---
testcheck.section("Test 6: uniform(10.0, 20.0)")
for _ in range(3):
f = vrandom.uniform(10.0, 20.0)
stdio.printf(" uniform(10,20) = %f\n", f)
testcheck.ok("uniform range check")
# --- Test 7: gauss ---
testcheck.section("Test 7: gauss(0.0, 1.0)")
for _ in range(3):
f = vrandom.gauss(0.0, 1.0)
stdio.printf(" gauss(0,1) = %f\n", f)
testcheck.ok("gauss distribution")
# --- Test 8: normalvariate ---
testcheck.section("Test 8: normalvariate(100.0, 15.0)")
for _ in range(3):
f = vrandom.normalvariate(100.0, 15.0)
stdio.printf(" normalvariate(100,15) = %f\n", f)
testcheck.ok("normalvariate distribution")
# --- Test 9: expovariate ---
testcheck.section("Test 9: expovariate(0.5)")
for _ in range(3):
f = vrandom.expovariate(0.5)
stdio.printf(" expovariate(0.5) = %f\n", f)
testcheck.ok("expovariate distribution")
# --- Test 10: gammavariate ---
testcheck.section("Test 10: gammavariate(2.0, 1.0)")
for _ in range(3):
f = vrandom.gammavariate(2.0, 1.0)
stdio.printf(" gammavariate(2,1) = %f\n", f)
testcheck.ok("gammavariate distribution")
# --- Test 11: betavariate ---
testcheck.section("Test 11: betavariate(2.0, 5.0)")
for _ in range(3):
f = vrandom.betavariate(2.0, 5.0)
stdio.printf(" betavariate(2,5) = %f\n", f)
testcheck.ok("betavariate distribution")
# --- Test 12: triangular ---
testcheck.section("Test 12: triangular(0.0, 10.0, 5.0)")
for _ in range(3):
f = vrandom.triangular(0.0, 10.0, 5.0)
stdio.printf(" triangular(0,10,5) = %f\n", f)
testcheck.ok("triangular distribution")
# --- Test 13: lognormvariate ---
testcheck.section("Test 13: lognormvariate(0.0, 1.0)")
for _ in range(3):
f = vrandom.lognormvariate(0.0, 1.0)
stdio.printf(" lognormvariate(0,1) = %f\n", f)
testcheck.ok("lognormvariate distribution")
# --- Test 14: paretovariate ---
testcheck.section("Test 14: paretovariate(1.0)")
for _ in range(3):
f = vrandom.paretovariate(1.0)
stdio.printf(" paretovariate(1) = %f\n", f)
testcheck.ok("paretovariate distribution")
# --- Test 15: weibullvariate ---
testcheck.section("Test 15: weibullvariate(1.0, 1.5)")
for _ in range(3):
f = vrandom.weibullvariate(1.0, 1.5)
stdio.printf(" weibullvariate(1,1.5) = %f\n", f)
testcheck.ok("weibullvariate distribution")
# --- Test 16: vonmisesvariate ---
testcheck.section("Test 16: vonmisesvariate(0.0, 1.0)")
for _ in range(3):
f = vrandom.vonmisesvariate(0.0, 1.0)
stdio.printf(" vonmisesvariate(0,1) = %f\n", f)
testcheck.ok("vonmisesvariate distribution")
return testcheck.end()

View File

@@ -0,0 +1 @@
{"vipermath": "3f7c5e78d8652535", "stdint": "49bd8cba55979f76", "vrandom": "62cc01c2bb770ca3", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "main": "e24a7f4a875f4518"}

View File

@@ -0,0 +1 @@
{"vipermath": "3f7c5e78d8652535", "stdint": "49bd8cba55979f76", "vrandom": "62cc01c2bb770ca3", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "main": "e24a7f4a875f4518"}

View File

@@ -0,0 +1 @@
{"vipermath": "3f7c5e78d8652535", "stdint": "49bd8cba55979f76", "vrandom": "62cc01c2bb770ca3", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "main": "e24a7f4a875f4518"}

View File

@@ -0,0 +1 @@
{"vipermath": "3f7c5e78d8652535", "stdint": "49bd8cba55979f76", "vrandom": "62cc01c2bb770ca3", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782"}

View File

@@ -0,0 +1,29 @@
{
"$schema": "https://raw.githubusercontent.com/TermiNexus/TransPyC/main/schemas/project-schema.json",
"name": "VRandomTest",
"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": "VRandomTest.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,128 @@
"""
Auto-generated Python stub file from vipermath.py
Module: vipermath
"""
import t, c
U_M_PI: t.CDefine = 3.14159265358979323846
U_M_E: t.CDefine = 2.71828182845904523536
U_M_PI_2: t.CDefine = 1.57079632679489661923
U_M_PI_4: t.CDefine = 0.78539816339744830962
U_M_1_PI: t.CDefine = 0.31830988618379067154
U_M_2_PI: t.CDefine = 0.63661977236758134308
U_M_LN2: t.CDefine = 0.69314718055994530942
U_M_LN10: t.CDefine = 2.30258509299404568402
U_M_2_SQRT_PI: t.CDefine = 1.77245385090551602730
def radians(degrees: t.CDouble) -> t.CDouble: pass
def degrees(radians: t.CDouble) -> t.CDouble: pass
def sin(x: t.CDouble) -> t.CDouble: pass
def cos(x: t.CDouble) -> t.CDouble: pass
def tan(x: t.CDouble) -> t.CDouble: pass
def asin(x: t.CDouble) -> t.CDouble: pass
def acos(x: t.CDouble) -> t.CDouble: pass
def _atan_core(x: t.CDouble) -> t.CDouble: pass
def atan(x: t.CDouble) -> t.CDouble: pass
def atan2(y: t.CDouble, x: t.CDouble) -> t.CDouble: pass
def sinh(x: t.CDouble) -> t.CDouble: pass
def cosh(x: t.CDouble) -> t.CDouble: pass
def tanh(x: t.CDouble) -> t.CDouble: pass
def exp(x: t.CDouble) -> t.CDouble: pass
def log(x: t.CDouble) -> t.CDouble: pass
def sqrt(x: t.CDouble) -> t.CDouble: pass
def abs(x: t.CInt) -> t.CInt: pass
def fabs(x: t.CDouble) -> t.CDouble: pass
def labs(x: t.CLong) -> t.CLong: pass
def factorial(n: t.CInt) -> t.CDouble: pass
def combination(n: t.CInt, k: t.CInt) -> t.CDouble: pass
def permutation(n: t.CInt, k: t.CInt) -> t.CDouble: pass
def pow(x: t.CDouble, y: t.CDouble) -> t.CDouble: pass
def powf(x: t.CDouble, y: t.CDouble) -> t.CDouble: pass
def cbrt(x: t.CDouble) -> t.CDouble: pass
def hypot(x: t.CDouble, y: t.CDouble) -> t.CDouble: pass
def floor(x: t.CDouble) -> t.CDouble: pass
def ceil(x: t.CDouble) -> t.CDouble: pass
def round(x: t.CDouble) -> t.CDouble: pass
def trunc(x: t.CDouble) -> t.CDouble: pass
def fmod(x: t.CDouble, y: t.CDouble) -> t.CDouble: pass
def fmodf(x: float, y: float) -> float: pass
def modf(x: t.CDouble, iptr: t.CDouble | t.CPtr) -> t.CDouble: pass
def log10(x: t.CDouble) -> t.CDouble: pass
def log2(x: t.CDouble) -> t.CDouble: pass
def exp2(x: t.CDouble) -> t.CDouble: pass
def expm1(x: t.CDouble) -> t.CDouble: pass
def log1p(x: t.CDouble) -> t.CDouble: pass
def asinh(x: t.CDouble) -> t.CDouble: pass
def acosh(x: t.CDouble) -> t.CDouble: pass
def atanh(x: t.CDouble) -> t.CDouble: pass
def gamma(x: t.CDouble) -> t.CDouble: pass
def erf(x: t.CDouble) -> t.CDouble: pass
def erfc(x: t.CDouble) -> t.CDouble: pass
def sqrtf(x: t.CFloat) -> t.CFloat: pass
def sinf(x: t.CFloat) -> t.CFloat: pass
def cosf(x: t.CFloat) -> t.CFloat: pass
def tanf(x: t.CFloat) -> t.CFloat: pass
def fabsf(x: t.CFloat) -> t.CFloat: pass
def floorf(x: t.CFloat) -> t.CFloat: pass
def ceilf(x: t.CFloat) -> t.CFloat: pass
class _U(t.CUnion):
d: t.CDouble
u: t.CUInt64T
def isnan(x: t.CDouble) -> t.CStatic | t.CInt: pass
def isinf(x: t.CDouble) -> t.CStatic | t.CInt: pass

View File

@@ -0,0 +1,75 @@
"""
Auto-generated Python stub file from stdint.py
Module: stdint
"""
import c
import t
INT: t.CTypedef = t.CInt
INTPTR: t.CTypedef = t.CInt | t.CPtr
BOOL: t.CTypedef = t.CInt
UINT: t.CTypedef = t.CUnsignedInt
UINTPTR: t.CTypedef = UINT | t.CPtr
BYTE: t.CTypedef = t.CUnsignedChar
BYTEPTR: t.CTypedef = BYTE | t.CPtr
WORD: t.CTypedef = t.CUInt16T
DWORD: t.CTypedef = t.CUInt32T
QWORD: t.CTypedef = t.CUInt64T
TCHAR: t.CTypedef = t.CChar
CHARLIST: t.CTypedef = str | t.CPtr
VOID: t.CTypedef = t.CVoid
SHORT: t.CTypedef = t.CShort
SHORTPTR: t.CTypedef = t.CShort | t.CPtr
USHORT: t.CTypedef = t.CUnsignedShort
USHORTPTR: t.CTypedef = t.CUnsignedShort | t.CPtr
LONGLONG: t.CTypedef = t.CLong | t.CLong
ULONGLONG: t.CTypedef = t.CUnsignedLong | t.CLong
LONG: t.CTypedef = t.CLong
ULONG: t.CTypedef = t.CUnsignedLong
WCHAR: t.CTypedef = WORD
WCHARPTR: t.CTypedef = WORD | t.CPtr
CHARPTR: t.CTypedef = t.CChar | t.CPtr
FSIZE_t: t.CTypedef = DWORD
LBA_t: t.CTypedef = DWORD
UINTPTR: t.CTypedef = t.CUnsignedInt | t.CPtr
VOIDPTR: t.CTypedef = t.CVoid | t.CPtr
FLOAT: t.CTypedef = t.CFloat
DOUBLE: t.CTypedef = t.CDouble
FLOAT8: t.CTypedef = t.CFloat8T
FLOAT16: t.CTypedef = t.CFloat16T
FLOAT32: t.CTypedef = t.CFloat32T
FLOAT64: t.CTypedef = t.CFloat64T
FLOAT128: t.CTypedef = t.CFloat128T
INT8: t.CTypedef = t.CInt8T
INT16: t.CTypedef = t.CInt16T
INT32: t.CTypedef = t.CInt32T
INT64: t.CTypedef = t.CInt64T
UINT8: t.CTypedef = t.CUInt8T
UINT16: t.CTypedef = t.CUInt16T
UINT32: t.CTypedef = t.CUInt32T
UINT64: t.CTypedef = t.CUInt64T
INT8PTR: t.CTypedef = t.CInt8T | t.CPtr
INT16PTR: t.CTypedef = t.CInt16T | t.CPtr
INT32PTR: t.CTypedef = t.CInt32T | t.CPtr
INT64PTR: t.CTypedef = t.CInt64T | t.CPtr
UINT8PTR: t.CTypedef = t.CUInt8T | t.CPtr
UINT16PTR: t.CTypedef = t.CUInt16T | t.CPtr
UINT32PTR: t.CTypedef = t.CUInt32T | t.CPtr
UINT64PTR: t.CTypedef = t.CUInt64T | t.CPtr
CHAR8: t.CTypedef = t.CChar8T
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
i8: t.CTypedef = t.CInt8T
i16: t.CTypedef = t.CInt16T
i32: t.CTypedef = t.CInt32T
i64: t.CTypedef = t.CInt64T
u8: t.CTypedef = t.CUInt8T
u16: t.CTypedef = t.CUInt16T
u32: t.CTypedef = t.CUInt32T
u64: t.CTypedef = t.CUInt64T

View File

@@ -0,0 +1,77 @@
"""
Auto-generated Python stub file from vrandom.py
Module: vrandom
"""
import t, c
import vipermath
RDRAND_RETRY_LIMIT: t.CDefine = 10
RDSEED_RETRY_LIMIT: t.CDefine = 100
def rdrand16() -> t.CUInt16T: pass
def rdrand32() -> t.CUInt32T: pass
def rdrand64() -> t.CUInt64T: pass
def rdseed16() -> t.CUInt16T: pass
def rdseed32() -> t.CUInt32T: pass
def rdseed64() -> t.CUInt64T: pass
def rdrand16_step(p: t.CUInt16T | t.CPtr) -> t.CInt: pass
def rdrand32_step(p: t.CUInt32T | t.CPtr) -> t.CInt: pass
def rdrand64_step(p: t.CUInt64T | t.CPtr) -> t.CInt: pass
def rdseed16_step(p: t.CUInt16T | t.CPtr) -> t.CInt: pass
def rdseed32_step(p: t.CUInt32T | t.CPtr) -> t.CInt: pass
def rdseed64_step(p: t.CUInt64T | t.CPtr) -> t.CInt: pass
def random_u16() -> t.CUInt16T: pass
def random_u32() -> t.CUInt32T: pass
def random_u64() -> t.CUInt64T: pass
def seed_u16() -> t.CUInt16T: pass
def seed_u32() -> t.CUInt32T: pass
def seed_u64() -> t.CUInt64T: pass
def randint(a: t.CInt, b: t.CInt) -> t.CInt: pass
def randrange(start: t.CInt, stop: t.CInt, step: t.CInt) -> t.CInt: pass
def getrandbits(k: t.CInt) -> t.CUInt64T: pass
def random() -> t.CDouble: pass
def uniform(a: t.CDouble, b: t.CDouble) -> t.CDouble: pass
def triangular(low: t.CDouble, high: t.CDouble, mode: t.CDouble) -> t.CDouble: pass
def betavariate(alpha: t.CDouble, beta: t.CDouble) -> t.CDouble: pass
def expovariate(lambd: t.CDouble) -> t.CDouble: pass
def gammavariate(alpha: t.CDouble, beta: t.CDouble) -> t.CDouble: pass
def gauss(mu: t.CDouble, sigma: t.CDouble) -> t.CDouble: pass
def normalvariate(mu: t.CDouble, sigma: t.CDouble) -> t.CDouble: pass
def lognormvariate(mu: t.CDouble, sigma: t.CDouble) -> t.CDouble: pass
def vonmisesvariate(mu: t.CDouble, kappa: t.CDouble) -> t.CDouble: pass
def paretovariate(alpha: t.CDouble) -> t.CDouble: pass
def weibullvariate(alpha: t.CDouble, beta: t.CDouble) -> t.CDouble: 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,25 @@
"""
Auto-generated Python stub file from testcheck.py
Module: testcheck
"""
import t, c
import stdio
_pass_count: t.CExtern | t.CInt
_fail_count: t.CExtern | t.CInt
def begin(name: str) -> t.CInt: pass
def section(name: str) -> t.CInt: pass
def ok(msg: str) -> t.CInt: pass
def fail(msg: str) -> t.CInt: pass
def check(cond: t.CInt, ok_msg: str, fail_msg: str) -> t.CInt: pass
def info(msg: str) -> t.CInt: pass
def end() -> t.CInt: pass

View File

@@ -0,0 +1,6 @@
3f7c5e78d8652535:includes/vipermath.py
49bd8cba55979f76:includes/stdint.py
62cc01c2bb770ca3:includes/vrandom.py
73edbcf76e32d00b:includes/stdio.py
9dbecd0942a39782:includes/testcheck.py
e24a7f4a875f4518:main.py

View File

@@ -0,0 +1,13 @@
"""
Auto-generated Python stub file from main.py
Module: main
"""
from stdint import *
import t, c
import stdio
import vrandom
import testcheck
def main() -> t.CInt: pass