cgen + memio: cgoutarena → memio.dynamic, grow → dynamicgrow (β-3)
Phase 0 last β-shape site. Two concerns in one commit because the refactor surfaced the rename: - selfhost/cmd/wcc/cgen.ww cgout buffer (cgoutbuf/cap/len + arena + cgout_grow + CGOUT_INIT_CAP) → memio.state + io.stream behind a one-shot lazy-init guard. cgout_enable drops its *arena param; memio.reset in cgout_flush keeps the buffer sticky across fns so the arena's amortisation survives — re-init per fn would abandon the buffer and re-grow from 0 via the 8→…→65536 ladder for every function (no io.close path → no os.free). - lib/memio/memio.ww private fn grow → dynamicgrow. Symmetric with dynamicwrite / dynamicclose; required because cstage bundles all imported modules into a flat TU and resolves private fns by unqualified name, so the new `import memio;` in wcc's bundle collided with selfhost/cmd/wcc/mem.ww's arena `grow`. Module-aware private-fn scoping in cstage is task #9. @test fn dynamicgrow in memiotest.ww (same package as memio.ww) renamed to dynamicgrowcases to free the name; new suffix mirrors the file's existing fixedwritecases / borrowedreadcases convention. Lazy-init guard cgoutinit. memio.dynamic runs once on first cgout_enable; subsequent enables just set cgoutmode. Mirrors lib/log/log.ww:124 ensureinit. Without it, ~14 mmap syscalls per fn and ~100 MiB+ cumulative leak on a typical bootstrap. io.write bare discard in emitbytes mirrors lib/log/log.ww:169 — memio.dynamicwrite never returns io.closed (memio.ww:166). Verified 132/132 incl. 995_self_rebuild byte-identity.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
// Houses the top-level emission glue:
|
||||
// - cgfnparams: parameter spilling per SysV
|
||||
// - cgfn: fn body emit (TEXT/SUBQ patched after body), prologue
|
||||
// deferred via cgen.ww's cgoutbuf so the frame size
|
||||
// deferred via cgen.ww's cgoutstate so the frame size
|
||||
// reflects every emit-time localadd (#15/#26c)
|
||||
// - cgfile: file-level entry (the exported driver)
|
||||
//
|
||||
@@ -350,7 +350,7 @@ fn cgfn(c: *cgen, fn_: *node) void = {
|
||||
// through *(@sretarg) and returns @sretarg in RAX.
|
||||
let sret_callee: bool = sretretsize(c, c.fnret) > 0;
|
||||
|
||||
// Capture the body into cgoutbuf while c.frame grows under
|
||||
// Capture the body into cgoutstate while c.frame grows under
|
||||
// emit-time localadd calls (#15/#26c — wwstage dropped its
|
||||
// scanlocals pre-pass to align DOWN with cstage's first-use
|
||||
// pattern). The prologue (TEXT label, PUSHQ/MOVQ/SUBQ) emits
|
||||
@@ -358,7 +358,7 @@ fn cgfn(c: *cgen, fn_: *node) void = {
|
||||
// localadd. Mirrors cstage cmd/w6c/cgen.c cgfn which builds
|
||||
// `subsp`/`text` Progs up front and patches their `from.offset`
|
||||
// at the end via txt_emit.
|
||||
cgout_enable(c.a);
|
||||
cgout_enable();
|
||||
|
||||
if (sret_callee) {
|
||||
let saoff: i32 = localadd(c, "@sretarg", 8, nil);
|
||||
|
||||
Reference in New Issue
Block a user