From 9eb037ee8fe6e2fd3fefa3a3c4e1c471a0a51521 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Thu, 8 Oct 2026 18:21:13 +0800 Subject: [PATCH] =?UTF-8?q?test(new):=20NewTest=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E2=80=9Cstack=20=E7=94=9F=E5=91=BD=E6=9C=9F=E7=BC=BA=E7=9C=81?= =?UTF-8?q?=3Dslife=E2=80=9D=E5=AF=B9=E7=85=A7=E7=94=A8=E4=BE=8B=EF=BC=9BR?= =?UTF-8?q?EADME=20=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增 (3) `new stack Point(7,8)`(不写 slife)与 (1) 显式 slife 等价,专门验证缺省规则;文件头补上完整缺省表:省略来源→heap,省略生命期→stack 为 slife、heap/memgr 为 hlife。 --- NewTest/App/main.vp | 16 ++++++++++++---- README.md | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/NewTest/App/main.vp b/NewTest/App/main.vp index d7ee35c..785c4e5 100644 --- a/NewTest/App/main.vp +++ b/NewTest/App/main.vp @@ -13,7 +13,11 @@ import memhub # heap → call i8* @malloc(i64 sizeof) + bitcast 到 T* # memgr → call i8* @.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)——要验证时打开其中一条: diff --git a/README.md b/README.md index b485095..61830e6 100644 --- a/README.md +++ b/README.md @@ -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` 都支持):