修复了大量存在的问题,增加了假鸭子类型等等机制
This commit is contained in:
52
Test/FormatStringTest/App/main.py
Normal file
52
Test/FormatStringTest/App/main.py
Normal file
@@ -0,0 +1,52 @@
|
||||
from stdint import *
|
||||
import t, c
|
||||
import ctraits
|
||||
import stdio
|
||||
import testcheck
|
||||
|
||||
|
||||
# ============================================================
|
||||
# FormatStringTest - 格式化字符串回归测试
|
||||
# ============================================================
|
||||
@t.CExport
|
||||
def main() -> int:
|
||||
testcheck.begin("FormatStringTest: Format String Regression")
|
||||
|
||||
b: str = "hello world"
|
||||
for i in b:
|
||||
stdio.printf("%c\n", i)
|
||||
b += 1
|
||||
print(b-11)
|
||||
|
||||
l: t.CArray[u64] = [0, 43, 2, 3, 4]
|
||||
l[0] = 1000
|
||||
for i in l:
|
||||
stdio.printf("%llu\n", i)
|
||||
|
||||
print("Value: ", f"0x{ULONGLONG(0x11)}")
|
||||
print("ULL Hex: ", f"0x{ULONGLONG(0x11):016X}")
|
||||
print("LL Hex: ", f"{LONGLONG(0x11):016X}")
|
||||
print("ULL Dec: ", f"{ULONGLONG(42):d}")
|
||||
print("LL Dec: ", f"{LONGLONG(42):d}")
|
||||
print("Hex: ", f"{0x11:016X}")
|
||||
print("Dec: ", f"{42:d}")
|
||||
print("Float: ", f"{3.14159:.2f}")
|
||||
|
||||
# f-string 赋值测试(验证不再直接 printf,而是生成字符串)
|
||||
s: str = f"Value=0x{ULONGLONG(42)}, Hex=0x{ULONGLONG(0x11):016X}"
|
||||
print("Assigned: ", s)
|
||||
|
||||
# ctraits.isptr 编译时类型判断测试
|
||||
ptr_var: INTPTR = c.Addr(s)
|
||||
val_var: int = 42
|
||||
if c.CIf(ctraits.isptr(ptr_var)):
|
||||
print("ptr_var is pointer")
|
||||
if c.CIf(not ctraits.isptr(val_var)):
|
||||
print("val_var is not pointer")
|
||||
|
||||
testcheck.section("placeholder")
|
||||
testcheck.ok("testcheck framework ready")
|
||||
testcheck.info("placeholder test")
|
||||
|
||||
return testcheck.end()
|
||||
|
||||
1
Test/FormatStringTest/output/9dbecd0942a39782.deps.json
Normal file
1
Test/FormatStringTest/output/9dbecd0942a39782.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"ctraits": "42ced27d9e76aef5", "stdint": "49bd8cba55979f76", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "main": "cdff0d7b58fc935b"}
|
||||
1
Test/FormatStringTest/output/cdff0d7b58fc935b.deps.json
Normal file
1
Test/FormatStringTest/output/cdff0d7b58fc935b.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"ctraits": "42ced27d9e76aef5", "stdint": "49bd8cba55979f76", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782"}
|
||||
29
Test/FormatStringTest/project.json
Normal file
29
Test/FormatStringTest/project.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/TermiNexus/TransPyC/main/schemas/project-schema.json",
|
||||
"name": "FormatStringTest",
|
||||
"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": "FormatStringTest.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
|
||||
}
|
||||
}
|
||||
11
Test/FormatStringTest/temp/42ced27d9e76aef5.pyi
Normal file
11
Test/FormatStringTest/temp/42ced27d9e76aef5.pyi
Normal file
@@ -0,0 +1,11 @@
|
||||
"""
|
||||
Auto-generated Python stub file from ctraits.py
|
||||
Module: ctraits
|
||||
"""
|
||||
|
||||
import c
|
||||
|
||||
|
||||
import t
|
||||
|
||||
def isptr(x: t.CType) -> bool: pass
|
||||
75
Test/FormatStringTest/temp/49bd8cba55979f76.pyi
Normal file
75
Test/FormatStringTest/temp/49bd8cba55979f76.pyi
Normal 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
|
||||
28
Test/FormatStringTest/temp/73edbcf76e32d00b.pyi
Normal file
28
Test/FormatStringTest/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/FormatStringTest/temp/9dbecd0942a39782.pyi
Normal file
25
Test/FormatStringTest/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
|
||||
5
Test/FormatStringTest/temp/_sha1_map.txt
Normal file
5
Test/FormatStringTest/temp/_sha1_map.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
42ced27d9e76aef5:includes/ctraits.pyi
|
||||
49bd8cba55979f76:includes/stdint.py
|
||||
73edbcf76e32d00b:includes/stdio.py
|
||||
9dbecd0942a39782:includes/testcheck.py
|
||||
cdff0d7b58fc935b:main.py
|
||||
14
Test/FormatStringTest/temp/cdff0d7b58fc935b.pyi
Normal file
14
Test/FormatStringTest/temp/cdff0d7b58fc935b.pyi
Normal file
@@ -0,0 +1,14 @@
|
||||
"""
|
||||
Auto-generated Python stub file from main.py
|
||||
Module: main
|
||||
"""
|
||||
|
||||
|
||||
from stdint import *
|
||||
import t, c
|
||||
import ctraits
|
||||
import stdio
|
||||
import testcheck
|
||||
|
||||
@t.CExport
|
||||
def main() -> int: pass
|
||||
Reference in New Issue
Block a user