selfhost/cmd/w6a+w6l: rt.malloc/amalloc β grow → alloc([], n)! (β-2)

Phase 0 second β-batch. 6 alloc sites across 3 β grow loops:
 - selfhost/cmd/w6a/obj.ww:100,108  buf bufinit/bufgrow (amalloc)
 - selfhost/cmd/w6a/asm.ww:26,63    asm_ emitbyte/emitdatabyte text+data (rt.malloc)
 - selfhost/cmd/w6l/obj.ww:113,135  lnk emittext/emitdata text+data (rt.malloc)

Same β shape as d9f0972: `*u8 = (rt.malloc|amalloc)(_, n): *u8`
→ `[]u8 = alloc([], n)!`, inner copy bounded by the manual length
counter (b.n / textlen / datalen) unchanged, struct field stays
*u8, writeback via .ptr. Bear-trap N/A (slice .len = 0 never read).

w6a/asm.ww `import rt;` (line 15) is now dead — deferred to a
post-Phase-0 import-hygiene sweep, mirrors 368b85e.

Verified 132/132 + 995_self_rebuild byte-identity.
This commit is contained in:
2026-05-21 09:38:40 +09:00
parent d9f097250b
commit f07a032104
5 changed files with 24 additions and 22 deletions

View File

@@ -1760,10 +1760,10 @@ export fn emitbyte(a: *asm_, b: u8) void = {
let nc: u64 = a.textcap;
if (nc == 0u64) { nc = 4096u64; };
nc = nc * 2u64;
let nb: *u8 = rt.malloc(nc): *u8;
let nb: []u8 = alloc([], nc)!;
let i: u64 = 0u64;
for (i < a.textlen) { nb[i] = a.text[i]; i += 1u64; };
a.text = nb;
a.text = nb.ptr;
a.textcap = nc;
};
a.text[a.textlen] = b;
@@ -1797,10 +1797,10 @@ export fn emitdatabyte(a: *asm_, b: u8) void = {
let nc: u64 = a.datacap;
if (nc == 0u64) { nc = 256u64; };
nc = nc * 2u64;
let nb: *u8 = rt.malloc(nc): *u8;
let nb: []u8 = alloc([], nc)!;
let i: u64 = 0u64;
for (i < a.datalen) { nb[i] = a.data[i]; i += 1u64; };
a.data = nb;
a.data = nb.ptr;
a.datacap = nc;
};
a.data[a.datalen] = b;
@@ -2687,17 +2687,18 @@ fn bufinit(b: *buf, a: *arena) void = {
b.a = a;
b.cap = 256u64;
b.n = 0u64;
b.p = amalloc(a, b.cap): *u8;
let np: []u8 = alloc([], b.cap)!;
b.p = np.ptr;
};
fn bufgrow(b: *buf, need: u64) void = {
if (b.n + need <= b.cap) { return; };
let nc: u64 = b.cap;
for (nc < b.n + need) { nc = nc * 2u64; };
let np: *u8 = amalloc(b.a, nc): *u8;
let np: []u8 = alloc([], nc)!;
let i: u64 = 0u64;
for (i < b.n) { np[i] = b.p[i]; i += 1u64; };
b.p = np;
b.p = np.ptr;
b.cap = nc;
};