Files
Viper_RegressionTesting/FormatStringTest/App/main.vp
T
TermiNexus aa5a7e7250 chore(syntax): Test 仓 R1 + R12 迁移
R1:T | t.CPtr -> T*(40 文件 / 1121 处;含多级 **、强转位 (T*)(x)、下标内 list[AST*]);引号前向引用 'Rect' | t.CPtr 26 处按例外保留,T | t.CPtr | t.State 25 处因 T* 后不能接 | 保持原联合写法。

R12:i = 0 + while i < N: + 尾 i += 1 -> or i in range(N):(10 文件 / 42 处;含 <= -> range(EXPR + 1)、带注解初始化 i: int = 0、尾 i = i + 1)。余 20 处经守卫判定不可安全改写(复合条件 1、尾部非自增 8、体内重绑定/continue 5、while-else 2、循环后仍被读取 2、找不到初始化 2)。
2026-10-05 21:18:37 +08:00

55 lines
1.7 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from stdint import *
import t, c
import ctraits
import stdio
import testcheck
# ============================================================
# FormatStringTest - 格式化字符串回归测试
# ============================================================
export 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 编译时类型判断测试
# &s 取的是局部变量 s(str = i8*)的地址,结果是 i8**(char**);
# 与 INTPTR(= int*,见 includes/stdint.vp)层数与基座都不同,
# 且指针隐式转换已收紧(层数必须相同)⇒ 注解按实际类型写 str*(= i8**)。
ptr_var: str* = &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()