将 .py 和 .pyi 后缀名改为了 .vp 和 .vpi 后缀名

This commit is contained in:
2026-07-30 16:34:50 +08:00
parent 32af3f93fa
commit d227bee139
74 changed files with 42 additions and 25 deletions

45
Test/App/closure_test.vp Normal file
View File

@@ -0,0 +1,45 @@
import stdio
import t, c
# ============================================================
# 闭包 + nonlocal/global 测试
# ============================================================
# 全局变量
g_count: int = 0
# global 关键字测试:修改全局变量
def test_global() -> int:
global g_count
g_count = g_count + 1
return g_count
# nonlocal 关键字测试:嵌套函数修改外层局部变量
def make_counter() -> t.CPtr:
count: int = 0
# 内部函数(闭包)捕获 count
def counter() -> int:
nonlocal count
count = count + 1
return count
return counter
def closure_test() -> int:
# global 测试
stdio.printf("global: %d\n", test_global())
stdio.printf("global: %d\n", test_global())
stdio.printf("global: %d\n", test_global())
# nonlocal/闭包测试
f: t.CPtr = make_counter()
stdio.printf("closure: %d\n", f())
stdio.printf("closure: %d\n", f())
stdio.printf("closure: %d\n", f())
return 0