io.empty (discard+EOF stream, ref/hare/io/empty.ha:4-17) — needed by getopt's two-pass printusage width measurement. Diverges from Hare's `const empty: *stream`: a `let _empty_vt` + `fn empty()` that wires the fn-ptr slots per call, because const-init of a vtable struct with fn-ptr fields is blocked (#118, ruled accept). Co-discovered while making empty() byte-identical across stages: three wwstage-only cgen fixes (cstage was already correct; wwstage aligned down): - #129 sretretsize: consult the same-module pointer-alias before structlookup's any-module struct fallback (io.stream = *vtable was mis-sized as memio's 56B struct -> spurious sret save). - #129 callsretsize: swap curmod to the callee's module before sret-size classification (cross-module callee context). - #130 cgassign global-struct tagged-union field store: add the missing arm (was a 1-word store) mirroring cstage cgen.c:4893-4912. The three are inseparable from io.empty here — splitting them out leaves a divergent-asm intermediate (993/995 red), so they ride one commit per the one-class gate-repair carve-out (#133-expanded precedent). Regenerates the embedded combined.ww; 989_lib_byteid pins bufio + fmt graduated to M_ID. (cgenexpr.ww fix-3 inline comment cites the #129 cluster; narrow to #130 on next touch to avoid a regen for a comment.)
This commit is contained in:
@@ -9891,6 +9891,23 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
return;
|
||||
};};
|
||||
};
|
||||
// #129: tagged-union field on global struct. LEAQ
|
||||
// base(SB) into BX then the shared widener handles
|
||||
// every rhs shape. Mirrors cstage cgen.c:4902
|
||||
// is_global arm. Without this the generic TK_ASSIGN
|
||||
// below truncates to 1 word, silently dropping tag
|
||||
// and payload.
|
||||
if (n.op == tkind.TK_ASSIGN
|
||||
&& istaggedtype(c, fi.tnode)) {
|
||||
let fsz: i32 = slotsize(c, fi.tnode);
|
||||
emitline("\tLEAQ\t");
|
||||
emitsymname(c, bn);
|
||||
emitline("(SB), BX\n");
|
||||
cgwidentaggedstore(c,
|
||||
fi.tnode.type_: *tinfo,
|
||||
n.rhs, "BX", fi.foff, fsz);
|
||||
return;
|
||||
};
|
||||
if (n.op == tkind.TK_ASSIGN) {
|
||||
cgexpr(c, n.rhs);
|
||||
if (isstrtype(c, fi.tnode)) {
|
||||
|
||||
@@ -1880,6 +1880,16 @@ export fn sretretsize(c: *cgen, t: *node) i32 = {
|
||||
// Primitives / aliased-to-primitives are never sret.
|
||||
if (aliasprimsize(c, r.str) > 0) { return 0; };
|
||||
if (streq(r.str, "str")) { return 0; };
|
||||
// #129: same-module alias wins over any-module struct hit. Without
|
||||
// this, `type stream = *vtable` (io) loses to memio.stream (56B
|
||||
// struct) via structlookup's any-module fallback → spurious sret.
|
||||
// Mirrors cstage cg_sret_retsize, which sees TY_PTR, not a name.
|
||||
if (c != nil) {
|
||||
let al: *node = aliassamemod(c, r.str);
|
||||
if (al != nil) {
|
||||
return sretretsize(c, al);
|
||||
};
|
||||
};
|
||||
let si: *structinfo = structlookup(c, r.str);
|
||||
if (si == nil) {
|
||||
if (c != nil) {
|
||||
@@ -1922,7 +1932,15 @@ export fn callsretsize(c: *cgen, n: *node) i32 = {
|
||||
};
|
||||
if (cn.len == 0) { return 0; };
|
||||
let rtyp: *node = fnretlookupmod(c, cn, cmod);
|
||||
return sretretsize(c, rtyp);
|
||||
// #129: sretretsize must see the CALLEE's module context so
|
||||
// aliassamemod resolves aliases from the callee's module (not the
|
||||
// caller's). Mirrors cstage operating on resolved Type* objects
|
||||
// (type_chase_named never has this confusion). Swap + restore.
|
||||
let savedmod: str = c.curmod;
|
||||
if (cmod.len > 0) { c.curmod = cmod; };
|
||||
let r: i32 = sretretsize(c, rtyp);
|
||||
c.curmod = savedmod;
|
||||
return r;
|
||||
};
|
||||
|
||||
fn structlookup(c: *cgen, name: str) *structinfo = {
|
||||
|
||||
Reference in New Issue
Block a user