From 9a2b09e606b183456d2ebff16a1043a18a34058d Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Thu, 8 Oct 2026 21:04:57 +0800 Subject: [PATCH] =?UTF-8?q?test(new):=20NewTest=20=E5=A2=9E=E6=B3=9B?= =?UTF-8?q?=E5=9E=8B=E7=B1=BB=20+=20new=20=E6=8F=8F=E8=BF=B0=E7=AC=A6?= =?UTF-8?q?=E5=8F=96=E5=AD=98=E5=82=A8=E7=9A=84=E5=86=92=E7=83=9F=E7=94=A8?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增 class Box[T] 与 new memgr(m2) hlife Box[int](7),覆盖「泛型下标 callee 先特化」与「描述符存储被构造复用」两个前提件,预期多打印一行 generic-in-pool: 7。 --- NewTest/App/main.vp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/NewTest/App/main.vp b/NewTest/App/main.vp index 00cbf41..2b8ecd8 100644 --- a/NewTest/App/main.vp +++ b/NewTest/App/main.vp @@ -24,6 +24,11 @@ novirtual class Point: y: int +# §7.2/M4 前提件冒烟:泛型类的 callee 是下标形式(Box[int]),`new` 必须先特化再取存储 +class Box[T]: + v: T + + export def main() -> int: w32.win32console.SetConsoleCP(65001) w32.win32console.SetConsoleOutputCP(65001) @@ -47,6 +52,15 @@ export def main() -> int: stdio.printf("memgr: %d %d\n", p4.x, p4.y) stdlib.free(arena) + # (5) §7.2/M4 前提件:**泛型类**的存储也走 `new` 描述符(`Box[int]` 先特化,再复用描述符存储)。 + # 这是把 list/dict/hashtable 从"类内 __new__ 从池取本体"迁到"调用点 new memgr(pool) …"的前提: + # _translate_generic_ctor_call 之前只会 _alloca_at_entry(栈),会忽略描述符存储。 + arena2: bytes = stdlib.malloc(65536) + m2: memhub.MemBuddy = memhub.MemBuddy(arena2, 65536) + b: Box[int]* = new memgr(m2) hlife Box[int](7) + stdio.printf("generic-in-pool: %d\n", b.v) + stdlib.free(arena2) + # 非法组合(应报 LifetimeError)——要验证时打开其中一条: # 1) 语义矛盾:bad: Point* = new stack hlife Point(7, 8) # 2) 多来源 :new stack heap Point(7, 8) → 解析期报错