test(new): NewTest 增加“stack 生命期缺省=slife”对照用例;README 同步

新增 (3) `new stack Point(7,8)`(不写 slife)与 (1) 显式 slife 等价,专门验证缺省规则;文件头补上完整缺省表:省略来源→heap,省略生命期→stack 为 slife、heap/memgr 为 hlife。
This commit is contained in:
TermiNexus committed 2026-10-08 18:21:13 +08:00
1 parent 12c96d3039
commit 9eb037ee8f
2 files changed
+13 -5

No files matched your search

+12 -4
View File
@@ -13,7 +13,11 @@ import memhub
# heap → call i8* @malloc(i64 sizeof) + bitcast 到 T*
# memgr → call i8* @<Mgr>.alloc(i64 sizeof) + bitcast 到 T*
# 本工程做冒烟验证:能编译、能跑出正确字段值。
# 描述符顺序无关;省略来源 = heap(D3),省略生命期由来源决定。
# 描述符顺序无关;**缺省规则**(D3 / §3.2):
# 省略来源 → heap
# 省略生命期 → 由**来源**决定:stack → slife(帧生命期),heap / memgr → hlife
# 于是:`new stack Point(7,8)` ≡ `new stack slife Point(7,8)`(stack 默认 slife)
# `new Point(3,4)` ≡ `new heap hlife Point(3,4)`(完全省略即堆 + 自由生命期)
# =============================================================================
@@ -34,11 +38,15 @@ def main() -> CInt | CExport:
p2: Point* = new heap Point(3, 4)
stdio.printf("heap : %d %d\n", p2.x, p2.y)
# (3) memgr(x):从 memhub 管理器取存储(管理器构造方式见 Test/MemhubTest)
# (3) stack + **生命期缺省** → slife(与 (1) 显式写 slife 等价,专门验证缺省规则)
p3: Point* = new stack Point(7, 8)
stdio.printf("stack默认slife: %d %d\n", p3.x, p3.y)
# (4) memgr(x):从 memhub 管理器取存储(管理器构造方式见 Test/MemhubTest)
arena: bytes = stdlib.malloc(65536)
m: memhub.MemBuddy = memhub.MemBuddy(arena, 65536)
p3: Point* = new memgr(m) hlife Point(5, 6)
stdio.printf("memgr: %d %d\n", p3.x, p3.y)
p4: Point* = new memgr(m) hlife Point(5, 6)
stdio.printf("memgr: %d %d\n", p4.x, p4.y)
stdlib.free(arena)
# 非法组合(应报 LifetimeError)——要验证时打开其中一条:
+1 -1
View File
@@ -130,7 +130,7 @@
| EscapeOkTest | 仓库根 `EscapeOkTest/` | 编译通过并输出 `Hi/hello/AB/x/aa/loop`(值拷贝/静态/帧内使用等豁免不得误报) |
| EscapeMethodTest | 仓库根 `EscapeMethodTest/` | **编译失败**:方法 / `__init__` / 嵌套函数交出栈地址 → `LifetimeError`(三用例互斥,一次开一条) |
| EscapeXmodTest | 仓库根 `EscapeXmodTest/` | **编译失败**:跨模块摘要(`.vpi` 落盘 `# esc=`)路径 → `LifetimeError` |
| NewTest | [Test/NewTest/](NewTest/App/main.vp) | 编译通过并输出 `stack` / `heap` 的字段值(`memgr(x)` 段待确认管理器构造 API) |
| NewTest | [Test/NewTest/](NewTest/App/main.vp) | 编译通过并输出 4 行:`stack`(显式 slife) / `heap` / `stack默认slife`(验证**缺省规则**:省略生命期时 stack→slife、heap/memgr→hlife)/ `memgr` |
单独运行(`regression_test.py` 与 `SequentialRegressionTest.py` 都支持):