wcc: str -> 24B {ptr,len,cap}, 3-reg ABI -- parity with []u8 (both stages)
A ww `str` becomes a 24-byte {ptr,len,cap} value, identical in layout to
[]u8 -- the enabling prerequisite for the Phase 2 `str == []u8` collapse.
Both stages, atomically:
- ty_str 16->24B; str value flows 3-reg AX/BX/CX (was 2-reg); str literals
emit cap (=len).
- str in a tagged union grows to a 32B slot, using the AX/DX/CX/R8 4th-word
path already used by 32B slice-variant unions -- str-variant is now
structurally identical.
- tuple (scalar,str) return: 4-reg AX/DX/CX/R8 + 32B receive, extending the
existing type-keyed return (no sret).
- str == []u8 for index and .ptr/.len/.cap, kind-gated where size-based
dispatch collided at 24B; cstage and wwstage mirror exactly.
- table-driven runtime coverage: test/wcc/928_str_abi_run.c.
Cannot be split (rule 10/11): a 24B str and a 16B str cannot coexist across
the two compiler stages without breaking byte-identity, so the size change
and every dependent ABI/codegen site land in one atomic commit, both stages.
Known follow-ups (zero corpus impact, tracked): str-literal global .cap
static-init; >16B struct by-value (pre-existing); tagged-union
match-scrutinee stage divergence (pre-existing).
This commit is contained in:
@@ -6535,7 +6535,20 @@ export fn typesinit(c: *tctx) void = {
|
||||
c.tyuintptr= prim(tykind.TY_UINTPTR, "uintptr", 8u64, 8u64);
|
||||
c.tyf32 = prim(tykind.TY_F32, "f32", 4u64, 4u64);
|
||||
c.tyf64 = prim(tykind.TY_F64, "f64", 8u64, 8u64);
|
||||
c.tystr = prim(tykind.TY_STR, "str", 16u64, 8u64); // sizelint-ok: SSoT for tystr (#64)
|
||||
// str IS []u8: { *u8, len, cap } — 24B, 3-reg ABI (#1/Phase 3).
|
||||
// Size sourced from a u8-slice's size (typeslice SSoT) so str and
|
||||
// []u8 can never drift; no second hardcoded 24. Mirrors cstage
|
||||
// type.c `type_slice(a, ty_u8)->size`.
|
||||
//
|
||||
// The slice tinfo MUST land in a local first: the inline form
|
||||
// `typeslice(c.tyu8).size` triggers a cgen bug — `call().field`
|
||||
// where the call returns a *pointer* emits no deref (it uses the
|
||||
// returned pointer AS the field value), so tystr.size would become
|
||||
// a heap address → runaway slot-size loops. Filed as task #6
|
||||
// (cstage cgen.c N_DOT base=N_CALL-returning-pointer + wwstage
|
||||
// cgdot mirror); retained here as a local until that lands.
|
||||
let u8slice: *tinfo = typeslice(c.tyu8);
|
||||
c.tystr = prim(tykind.TY_STR, "str", u8slice.size, 8u64);
|
||||
c.tyerr = prim(tykind.TY_ERR, "<err>", 0u64, 1u64);
|
||||
c.tynever = prim(tykind.TY_NEVER, "never", 0u64, 1u64);
|
||||
|
||||
@@ -7811,7 +7824,9 @@ fn primtypesize(nm: str) i64 = {
|
||||
if (streq(nm, "i32") || streq(nm, "u32") || streq(nm, "f32") || streq(nm, "rune")) { return 4i64; };
|
||||
if (streq(nm, "i64") || streq(nm, "u64") || streq(nm, "f64")) { return 8i64; };
|
||||
if (streq(nm, "int") || streq(nm, "uint") || streq(nm, "uintptr")) { return 8i64; };
|
||||
if (streq(nm, "str")) { return 16i64; }; // sizelint-ok: SSoT for ty_str primtype (#64)
|
||||
// str IS []u8: 24B, sourced from the slice header SSoT so str and
|
||||
// []u8 can never drift; no second hardcoded 24 (#1/Phase 3).
|
||||
if (streq(nm, "str")) { return tyslicesize(); };
|
||||
return -1i64;
|
||||
};
|
||||
|
||||
@@ -10794,8 +10809,11 @@ fn pushargsrev(c: *cgen, arg: *node, param: *node) i32 = {
|
||||
emitline(", AX\n");
|
||||
emitline("\tPUSHQ\tAX\n");
|
||||
} else { if (nodeisstr(c, arg)) {
|
||||
// slot 24: [+0]=tag,[+8]=ptr,[+16]=len. Push high→low
|
||||
// so pop drains tag first into arg-reg[0].
|
||||
// str IS []u8: slot 32 [+0]=tag,[+8]=ptr,[+16]=len,
|
||||
// [+24]=cap — same shape as the slice arm above. Push
|
||||
// cap, len, ptr, tag high→low so pop drains tag first
|
||||
// into arg-reg[0] (#1/Phase 3).
|
||||
emitline("\tPUSHQ\tCX\n");
|
||||
emitline("\tPUSHQ\tBX\n");
|
||||
emitline("\tPUSHQ\tAX\n");
|
||||
emitline("\tMOVQ\t$");
|
||||
@@ -11013,9 +11031,12 @@ fn pushargsrev(c: *cgen, arg: *node, param: *node) i32 = {
|
||||
return rest + 3;
|
||||
};
|
||||
if (nodeisstr(c, arg)) {
|
||||
// str IS []u8: cgexpr left (AX=ptr, BX=len, CX=cap). Push
|
||||
// the triple, same as the slice arm above (#1/Phase 3).
|
||||
emitline("\tPUSHQ\tCX\n");
|
||||
emitline("\tPUSHQ\tBX\n");
|
||||
emitline("\tPUSHQ\tAX\n");
|
||||
return rest + 2;
|
||||
return rest + 3;
|
||||
};
|
||||
// #21: CALL returning a tagged-union — the aistagged guard
|
||||
// above kept us out of the widening path. Push the tagged-
|
||||
@@ -12865,7 +12886,7 @@ fn cgloadtaggedfield(c: *cgen, basereg: str, foff: i32, slot_sz: i32) void = {
|
||||
// would need a reversed direction we don't currently emit).
|
||||
// - struct src (literal or ident): zero slot, write fields at +8+foff,
|
||||
// tag last.
|
||||
// - str src: tag@+0, ptr@+8, len@+16.
|
||||
// - str src: tag@+0, ptr@+8, len@+16, cap@+24 (str IS []u8, #1/Phase 3).
|
||||
// - scalar src: tag@+0, value@+8.
|
||||
fn cgwidentaggedstore(c: *cgen, dst: *tinfo, src: *node,
|
||||
basereg: str, slot_off: i32, slot_sz: i32) void = {
|
||||
@@ -13083,12 +13104,18 @@ fn cgwidentaggedstorebp(c: *cgen, dst: *tinfo, src: *node, slot_off: i32, slot_s
|
||||
emitoff((slot_off + 8 + fi.foff): i64);
|
||||
emitline("(BP)\n");
|
||||
} else { if (isstrtype(c, fi.tnode)) {
|
||||
// str IS []u8: 3-word field
|
||||
// (ptr,len,cap) from cgexpr's
|
||||
// AX/BX/CX (#1/Phase 3).
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff((slot_off + 8 + fi.foff): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tBX, ");
|
||||
emitoff((slot_off + 8 + fi.foff + 8): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitoff((slot_off + 8 + fi.foff + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
} else {
|
||||
let sop: str = fieldstoreop(c, fi);
|
||||
emitline("\t");
|
||||
@@ -13146,7 +13173,9 @@ fn cgwidentaggedstorebp(c: *cgen, dst: *tinfo, src: *node, slot_off: i32, slot_s
|
||||
return;
|
||||
};
|
||||
};
|
||||
// Str payload.
|
||||
// str IS []u8: AX=ptr, BX=len, CX=cap from cgexpr. Slot layout
|
||||
// tag@+0, ptr@+8, len@+16, cap@+24 — same 32B shape as the slice
|
||||
// payload below (#1/Phase 3).
|
||||
if (nodeisstr(c, src)) {
|
||||
cgexpr(c, src);
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
@@ -13155,6 +13184,9 @@ fn cgwidentaggedstorebp(c: *cgen, dst: *tinfo, src: *node, slot_off: i32, slot_s
|
||||
emitline("\tMOVQ\tBX, ");
|
||||
emitoff((slot_off + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitoff((slot_off + 24): i64);
|
||||
emitline("(BP)\n");
|
||||
let tag: i32 = taggedvariantindext(c, dt, src);
|
||||
if (tag < 0) { tag = 0; };
|
||||
emitline("\tMOVQ\t$");
|
||||
@@ -13382,11 +13414,15 @@ export fn dotchainresolve(c: *cgen, n: *node,
|
||||
for (ft != nil && ft.kind == tykind.TY_NAMED) { ft = ft.under; };
|
||||
if (ft == nil) { return false; };
|
||||
if (ft.kind == tykind.TY_STR) {
|
||||
// str IS []u8: .cap is the third header word, same as
|
||||
// the TY_SLICE leaf below — cstage treats str≡slice for
|
||||
// .ptr/.len/.cap (cmd/w6c/cgen.c:2478) (#1/Phase 3, #11).
|
||||
if (i != 1) { return false; };
|
||||
let pseudo: str = stk[0].str;
|
||||
let delta: i32 = -1;
|
||||
if (streq(pseudo, "ptr")) { delta = 0; }
|
||||
else { if (streq(pseudo, "len")) { delta = 8; }; };
|
||||
else { if (streq(pseudo, "len")) { delta = 8; }
|
||||
else { if (streq(pseudo, "cap")) { delta = 16; }; }; };
|
||||
if (delta < 0) { return false; };
|
||||
*outtotaloff = *outtotaloff + foff;
|
||||
*outslicedelta = delta;
|
||||
@@ -13699,6 +13735,44 @@ fn cgstructlitfill(c: *cgen, si: *structinfo, lit: *node,
|
||||
fi = nil;
|
||||
} else if (callwhole) {
|
||||
fi = nil;
|
||||
} else if (isstrtype(c, fi.tnode)) {
|
||||
// str IS []u8: 3-word field (ptr,len,cap).
|
||||
// cgexpr leaves AX/BX/CX; for non-BP modes
|
||||
// the dst base goes in DX to dodge BX=len /
|
||||
// CX=cap (the generic store reloads BX, which
|
||||
// would clobber len) (#1/Phase 3).
|
||||
cgexpr(c, fieldnode.lhs);
|
||||
if (mode == 0) {
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff((disp + fi.foff): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tBX, ");
|
||||
emitoff((disp + fi.foff + 8): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitoff((disp + fi.foff + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
} else {
|
||||
if (mode == 1) {
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff(srcoff: i64);
|
||||
emitline("(BP), DX\n");
|
||||
} else {
|
||||
emitline("\tLEAQ\t");
|
||||
emitsymname(c, srcname);
|
||||
emitline("(SB), DX\n");
|
||||
};
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitdispreg((disp + fi.foff): i64, "DX");
|
||||
emitline("\n");
|
||||
emitline("\tMOVQ\tBX, ");
|
||||
emitdispreg((disp + fi.foff + 8): i64, "DX");
|
||||
emitline("\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitdispreg((disp + fi.foff + 16): i64, "DX");
|
||||
emitline("\n");
|
||||
};
|
||||
fi = nil;
|
||||
} else {
|
||||
cgexpr(c, fieldnode.lhs);
|
||||
// For non-BP modes, cgexpr just clobbered
|
||||
@@ -13956,7 +14030,11 @@ fn cgtryprop(c: *cgen, n: *node) void = {
|
||||
};
|
||||
};
|
||||
if (succisstr) {
|
||||
// str IS []u8: success arrives DX=ptr, CX=len, R8=cap
|
||||
// (slot 32B). Move len out before cap overwrites CX
|
||||
// (#1/Phase 3).
|
||||
emitline("\tMOVQ\tCX, BX\n");
|
||||
emitline("\tMOVQ\tR8, CX\n");
|
||||
};
|
||||
emitline("\tMOVQ\tDX, AX\n");
|
||||
return;
|
||||
@@ -14012,7 +14090,11 @@ fn cgtryunw(c: *cgen, n: *node) void = {
|
||||
};
|
||||
};
|
||||
if (succisstr) {
|
||||
// str IS []u8: success arrives DX=ptr, CX=len, R8=cap
|
||||
// (slot 32B). Move len out before cap overwrites CX
|
||||
// (#1/Phase 3).
|
||||
emitline("\tMOVQ\tCX, BX\n");
|
||||
emitline("\tMOVQ\tR8, CX\n");
|
||||
};
|
||||
emitline("\tMOVQ\tDX, AX\n");
|
||||
return;
|
||||
@@ -14285,8 +14367,9 @@ fn cgcast(c: *cgen, n: *node) void = {
|
||||
};
|
||||
|
||||
fn cgstrlit(c: *cgen, n: *node) void = {
|
||||
// Result is the (ptr, len) pair: ptr in AX, len in BX. Call
|
||||
// sites that expect a str arg pick these up directly.
|
||||
// str IS []u8: the (ptr, len, cap) triple — ptr in AX, len in BX,
|
||||
// cap in CX. A static literal has no spare storage, so cap = len
|
||||
// (#1/Phase 3). Call sites that expect a str arg pick these up.
|
||||
let nstr: str = n.str;
|
||||
let lab: str = internstrlit(c, nstr);
|
||||
emitline("\tLEAQ\t");
|
||||
@@ -14295,6 +14378,9 @@ fn cgstrlit(c: *cgen, n: *node) void = {
|
||||
emitline("\tMOVQ\t$");
|
||||
emitint(nstr.len: i64);
|
||||
emitline(", BX\n");
|
||||
emitline("\tMOVQ\t$");
|
||||
emitint(nstr.len: i64);
|
||||
emitline(", CX\n");
|
||||
return;
|
||||
};
|
||||
|
||||
@@ -14330,9 +14416,14 @@ fn cgident(c: *cgen, n: *node) void = {
|
||||
emitoff(off: i64);
|
||||
emitline("(BP), AX\n");
|
||||
if (isstr) {
|
||||
// str IS []u8: load (ptr,len,cap) into AX/BX/CX,
|
||||
// identical to the slice arm below (#1/Phase 3).
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff((off + 8): i64);
|
||||
emitline("(BP), BX\n");
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff((off + 16): i64);
|
||||
emitline("(BP), CX\n");
|
||||
};
|
||||
if (issl) {
|
||||
emitline("\tMOVQ\t");
|
||||
@@ -14362,6 +14453,11 @@ fn cgident(c: *cgen, n: *node) void = {
|
||||
emitline("\tMOVQ\t$");
|
||||
emitint(bytes.len: i64);
|
||||
emitline(", BX\n");
|
||||
// str IS []u8: cap = len for a static def literal
|
||||
// (#1/Phase 3).
|
||||
emitline("\tMOVQ\t$");
|
||||
emitint(bytes.len: i64);
|
||||
emitline(", CX\n");
|
||||
return;
|
||||
};
|
||||
};
|
||||
@@ -14393,17 +14489,16 @@ fn cgident(c: *cgen, n: *node) void = {
|
||||
let isstr: bool = letvarisstr(c, nm);
|
||||
let issl: bool = letvarisslice(c, nm);
|
||||
if (isstr || issl) {
|
||||
// str IS []u8: both str and slice carry a third 8B
|
||||
// (cap); load it unconditionally. The address holder CX
|
||||
// is overwritten by the cap as the last step, after
|
||||
// ptr/len are already loaded (#1/Phase 3).
|
||||
emitline("\tLEAQ\t");
|
||||
emitsymname(c, nm);
|
||||
emitline("(SB), CX\n");
|
||||
emitline("\tMOVQ\t(CX), AX\n");
|
||||
emitline("\tMOVQ\t8(CX), BX\n");
|
||||
if (issl) {
|
||||
// Overwrites the address holder with the
|
||||
// cap as the last step — CX is no longer
|
||||
// needed once both ptr/len are loaded.
|
||||
emitline("\tMOVQ\t16(CX), CX\n");
|
||||
};
|
||||
emitline("\tMOVQ\t16(CX), CX\n");
|
||||
return;
|
||||
};
|
||||
// Float global: same LEAQ-indirect shape, since MOVSS/
|
||||
@@ -14457,6 +14552,12 @@ fn cgindex(c: *cgen, n: *node) void = {
|
||||
let idx: *node = n.rhs;
|
||||
let esz: i32 = 8;
|
||||
let signed_elem: bool = false;
|
||||
// #1/Phase 3: str=24B collides with slice=24B, so the str-element
|
||||
// branches below MUST gate on kind (mirroring cstage's elem_is_str),
|
||||
// not a bare `esz == primtypesize("str")` size check — otherwise a
|
||||
// []u8 element (also 24B) misfires into the str 2-word load and
|
||||
// diverges from cstage (#60 collision class; sentinel 754).
|
||||
let elemisstr: bool = false;
|
||||
let baselocal: *local = nil;
|
||||
// Global `[N]T` array or `*T` pointer used as an index base.
|
||||
// The local-ident lookup above misses it; we need LEAQ name(SB)
|
||||
@@ -14498,7 +14599,7 @@ fn cgindex(c: *cgen, n: *node) void = {
|
||||
// cgen.c:3517-18). esz-only — N_DOT-base signedness
|
||||
// stays unset, as before.
|
||||
let dt: *tinfo = n.type_: *tinfo;
|
||||
if (dt != nil) { esz = dt.size: i32; };
|
||||
if (dt != nil) { esz = dt.size: i32; elemisstr = typeisstr(dt); };
|
||||
} else { if (base.kind == nkind.N_INDEX) {
|
||||
// #60: chained `names[i][k]` — n.type_ is the checker-
|
||||
// stamped outer element tinfo (indexresult over the inner
|
||||
@@ -14547,6 +14648,7 @@ fn cgindex(c: *cgen, n: *node) void = {
|
||||
esz = elem_slot_sz;
|
||||
};
|
||||
};
|
||||
elemisstr = isstrtype(c, etn);
|
||||
};
|
||||
};
|
||||
cgexpr(c, idx);
|
||||
@@ -14582,7 +14684,7 @@ fn cgindex(c: *cgen, n: *node) void = {
|
||||
};
|
||||
// #43: str element-stride routes through primtypesize so the
|
||||
// 16-vs-24 dispatch tracks ty_str.size for #1.
|
||||
if (esz == primtypesize("str"): i32) {
|
||||
if (elemisstr) {
|
||||
emitline("\tMOVQ\t8(BX), CX\n");
|
||||
emitline("\tMOVQ\t(BX), AX\n");
|
||||
emitline("\tMOVQ\tCX, BX\n");
|
||||
@@ -14624,7 +14726,7 @@ fn cgindex(c: *cgen, n: *node) void = {
|
||||
// str element (16B today): load (ptr, len) into (AX, BX) so
|
||||
// the value flows through the str-rhs convention.
|
||||
// #43: route via primtypesize so the stride tracks #1.
|
||||
if (esz == primtypesize("str"): i32) {
|
||||
if (elemisstr) {
|
||||
emitline("\tMOVQ\t8(BX), CX\n");
|
||||
emitline("\tMOVQ\t(BX), AX\n");
|
||||
emitline("\tMOVQ\tCX, BX\n");
|
||||
@@ -14656,7 +14758,7 @@ fn cgindex(c: *cgen, n: *node) void = {
|
||||
};
|
||||
// #43: str element-stride routes through primtypesize so the
|
||||
// 16-vs-24 dispatch tracks ty_str.size for #1.
|
||||
if (esz == primtypesize("str"): i32) {
|
||||
if (elemisstr) {
|
||||
emitline("\tMOVQ\t8(AX), BX\n");
|
||||
emitline("\tMOVQ\t(AX), AX\n");
|
||||
return;
|
||||
@@ -15251,10 +15353,11 @@ fn cgdot(c: *cgen, n: *node) void = {
|
||||
};
|
||||
// Hare-style tuple positional access: `t.0`, `t.1`.
|
||||
// Walk the tuple element type list summing slotsize
|
||||
// (matches the (scalar, str) init layout which puts
|
||||
// the scalar in an 8B slot and the str in 16B). For
|
||||
// a str element, load both halves into (AX, BX) so
|
||||
// chains like `t.1.len` propagate correctly.
|
||||
// (matches the (scalar, str) init layout: scalar in an
|
||||
// 8B slot, str in 24B — str IS []u8, #1/Phase 3). For a
|
||||
// str element, load (ptr, len) into (AX, BX); the cap
|
||||
// stays in the slot (the 2-word str-field read, like
|
||||
// every other chained/dot str leaf read — task #14).
|
||||
if (lkind == nkind.N_TTUPLE) {
|
||||
let idx: i32 = fldnumidx(fld);
|
||||
if (idx >= 0) {
|
||||
@@ -15369,9 +15472,9 @@ fn cgdot(c: *cgen, n: *node) void = {
|
||||
let delta: i32 = -1;
|
||||
if (streq(fld, "ptr")) { delta = 0; };
|
||||
if (streq(fld, "len")) { delta = 8; };
|
||||
if (issl) {
|
||||
if (streq(fld, "cap")) { delta = 16; };
|
||||
};
|
||||
// str IS []u8: .cap is valid on a str global too,
|
||||
// not slice-only — mirrors cstage (#1/Phase 3, #11).
|
||||
if (streq(fld, "cap")) { delta = 16; };
|
||||
if (delta >= 0) {
|
||||
emitline("\tLEAQ\t");
|
||||
emitsymname(c, lhs.str);
|
||||
@@ -16227,7 +16330,9 @@ fn cgun(c: *cgen, n: *node) void = {
|
||||
let gdelta: i32 = -1;
|
||||
if (streq(fld, "ptr")) { gdelta = 0; };
|
||||
if (streq(fld, "len")) { gdelta = 8; };
|
||||
if (issl) { if (streq(fld, "cap")) { gdelta = 16; }; };
|
||||
// str IS []u8: &str.cap is valid too, not slice-only
|
||||
// — mirrors cstage (#1/Phase 3, #11).
|
||||
if (streq(fld, "cap")) { gdelta = 16; };
|
||||
if (gdelta >= 0) {
|
||||
emitline("\tLEAQ\t");
|
||||
emitsymname(c, basenm);
|
||||
@@ -16599,16 +16704,19 @@ fn cgalloc(c: *cgen, n: *node) void = {
|
||||
emitline("\n");
|
||||
fi = nil;
|
||||
} else { if (isstrtype(c, fi.tnode)) {
|
||||
// alloc(T{ fval = s }) for str field: cgexpr
|
||||
// leaves (AX=ptr, BX=len). Use CX for the heap
|
||||
// base so BX=len survives both stores. Mirrors
|
||||
// cmd/w6c/cgen.c:4184-4190.
|
||||
emitline("\tMOVQ\t(SP), CX\n");
|
||||
// str IS []u8: cgexpr leaves (AX=ptr,
|
||||
// BX=len, CX=cap). Route the heap base
|
||||
// through DX so all three survive — CX
|
||||
// holds cap, BX holds len (#1/Phase 3).
|
||||
emitline("\tMOVQ\t(SP), DX\n");
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitdispreg(fi.foff: i64, "CX");
|
||||
emitdispreg(fi.foff: i64, "DX");
|
||||
emitline("\n");
|
||||
emitline("\tMOVQ\tBX, ");
|
||||
emitdispreg((fi.foff + 8): i64, "CX");
|
||||
emitdispreg((fi.foff + 8): i64, "DX");
|
||||
emitline("\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitdispreg((fi.foff + 16): i64, "DX");
|
||||
emitline("\n");
|
||||
fi = nil;
|
||||
} else {
|
||||
@@ -17068,7 +17176,8 @@ fn cgcall(c: *cgen, n: *node) void = {
|
||||
popped += 1;
|
||||
} else {
|
||||
let extra: i32 = 0;
|
||||
if (nodeisstr(c, a)) { extra = 1; };
|
||||
// str IS []u8: 3-word arg, same as slice (#1/Phase 3).
|
||||
if (nodeisstr(c, a)) { extra = 2; };
|
||||
if (nodeisslice(c, a)) { extra = 2; };
|
||||
// #21: tagged-CALL arg was pushed AX/DX/CX/R8 high→low
|
||||
// by pushargsrev; size the per-arg pop to match so the
|
||||
@@ -17238,31 +17347,9 @@ fn cgcall(c: *cgen, n: *node) void = {
|
||||
emitint((stackslots * 8): i64);
|
||||
emitline(", SP\n");
|
||||
};
|
||||
// SysV returns 16-byte aggregates in (AX, DX). Our str
|
||||
// convention is (AX, BX), so shuffle for str-returning calls.
|
||||
// Route through fnretlookupmod: for N_DOT cross-module callees,
|
||||
// the bare-leaf fnretlookup's same-module-first walk (#4e) would
|
||||
// pick the caller-module's same-leaf fn — a str-returning
|
||||
// caller-side `slice` over a []u8-returning `mod.slice` then
|
||||
// emits a phantom MOVQ DX, BX after the cross-module CALL (#34).
|
||||
if (calleename.len > 0) {
|
||||
let cmod: str;
|
||||
cmod.ptr = nil; cmod.len = 0;
|
||||
if (callee != nil) {
|
||||
if (callee.kind == nkind.N_IDENT) { cmod = c.curmod; };
|
||||
if (callee.kind == nkind.N_DOT) {
|
||||
if (callee.lhs != nil) {
|
||||
if (callee.lhs.kind == nkind.N_IDENT) {
|
||||
cmod = callee.lhs.str;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
let rtyp: *node = fnretlookupmod(c, calleename, cmod);
|
||||
if (isstrtype(c, rtyp)) {
|
||||
emitline("\tMOVQ\tDX, BX\n");
|
||||
};
|
||||
};
|
||||
// str IS []u8: a str-returning callee leaves AX=ptr, BX=len,
|
||||
// CX=cap — same as a slice, so there is no receive-side shuffle
|
||||
// (#1/Phase 3).
|
||||
return;
|
||||
};
|
||||
|
||||
@@ -17361,17 +17448,21 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
emitline("\tX0, (BX)\n");
|
||||
return;
|
||||
};
|
||||
// Push order matches C cgen
|
||||
// (cmd/w6c/cgen.c:1033-1041): PUSHQ AX
|
||||
// (ptr) first, then PUSHQ BX (len) if
|
||||
// str, so the pop sequence is POP CX
|
||||
// (len) → POP AX (ptr) → MOVQ AX,
|
||||
// (BX) → MOVQ CX, 8(BX).
|
||||
// str IS []u8: PUSHQ AX (ptr) first, then
|
||||
// PUSHQ BX (len) + PUSHQ CX (cap) across the
|
||||
// pointer eval which clobbers BX/CX. Pop drains
|
||||
// cap (top) → 16(BX), then len, then ptr → 0(BX)
|
||||
// with len → 8(BX) (#1/Phase 3).
|
||||
emitline("\tPUSHQ\tAX\n");
|
||||
if (elemstr) { emitline("\tPUSHQ\tBX\n"); };
|
||||
if (elemstr) {
|
||||
emitline("\tPUSHQ\tBX\n");
|
||||
emitline("\tPUSHQ\tCX\n");
|
||||
};
|
||||
cgexpr(c, inner);
|
||||
emitline("\tMOVQ\tAX, BX\n");
|
||||
if (elemstr) {
|
||||
emitline("\tPOPQ\tCX\n");
|
||||
emitline("\tMOVQ\tCX, 16(BX)\n");
|
||||
emitline("\tPOPQ\tCX\n");
|
||||
emitline("\tPOPQ\tAX\n");
|
||||
emitline("\tMOVQ\tAX, (BX)\n");
|
||||
@@ -17625,10 +17716,19 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
};
|
||||
};
|
||||
cgexpr(c, n.rhs); // value → AX
|
||||
// #43: spill BX (str.len) before computing
|
||||
// the index so the post-index store can pop
|
||||
// it; the stride gate tracks ty_str.size.
|
||||
if (esz == primtypesize("str"): i32) { emitline("\tPUSHQ\tBX\n"); };
|
||||
// str IS []u8: spill cap (CX) + len (BX) before
|
||||
// computing the index so the post-index store can
|
||||
// pop all three. #1/Phase 3: str=24B collides with
|
||||
// slice=24B, so this MUST gate on kind (cstage's
|
||||
// elem_is_str, cmd/w6c/cgen.c:3576) — not a bare
|
||||
// `esz == primtypesize("str")` — or a []u8 element
|
||||
// (also 24B) misfires the str 3-word store and
|
||||
// diverges from cstage. Write-side mirror of the
|
||||
// cgindex read-path gate (#7/754).
|
||||
if (isstrtype(c, elemtn)) {
|
||||
emitline("\tPUSHQ\tCX\n");
|
||||
emitline("\tPUSHQ\tBX\n");
|
||||
};
|
||||
emitline("\tPUSHQ\tAX\n");
|
||||
cgexpr(c, idx); // idx → AX
|
||||
if (esz > 1) {
|
||||
@@ -17666,13 +17766,15 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
emitline("\tPOPQ\tAX\n"); // scaled idx
|
||||
emitline("\tADDQ\tAX, BX\n");
|
||||
emitline("\tPOPQ\tAX\n"); // value
|
||||
// #43: str-element write — pop the saved
|
||||
// .len and store both halves. Stride gate
|
||||
// routes through primtypesize for #1.
|
||||
if (esz == primtypesize("str"): i32) {
|
||||
// str IS []u8: pop the saved len + cap and store
|
||||
// all three words. Kind-gate, not size — see the
|
||||
// spill site above (#1/Phase 3, #7/754).
|
||||
if (isstrtype(c, elemtn)) {
|
||||
emitline("\tMOVQ\tAX, (BX)\n");
|
||||
emitline("\tPOPQ\tCX\n");
|
||||
emitline("\tMOVQ\tCX, 8(BX)\n");
|
||||
emitline("\tPOPQ\tCX\n");
|
||||
emitline("\tMOVQ\tCX, 16(BX)\n");
|
||||
return;
|
||||
};
|
||||
let isop: str = tnodestoreop(c, elemtn, esz);
|
||||
@@ -18099,20 +18201,24 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
emitline("\tMOVQ\tBX, AX\n");
|
||||
};
|
||||
};
|
||||
// str field via *struct: rhs left
|
||||
// (AX=ptr, BX=len). Use CX as the
|
||||
// address scratch so we don't clobber
|
||||
// the len half before storing it.
|
||||
// str IS []u8: rhs left (AX=ptr,
|
||||
// BX=len, CX=cap). CX holds cap, so
|
||||
// stage the struct addr in DX and
|
||||
// store all three words — identical
|
||||
// to the slice arm below (#1/Phase 3).
|
||||
if (n.op == tkind.TK_ASSIGN) {
|
||||
if (isstrtype(c, fi.tnode)) {
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff(lc.off: i64);
|
||||
emitline("(BP), CX\n");
|
||||
emitline("(BP), DX\n");
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitdispreg(fi.foff: i64, "CX");
|
||||
emitdispreg(fi.foff: i64, "DX");
|
||||
emitline("\n");
|
||||
emitline("\tMOVQ\tBX, ");
|
||||
emitdispreg((fi.foff + 8): i64, "CX");
|
||||
emitdispreg((fi.foff + 8): i64, "DX");
|
||||
emitline("\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitdispreg((fi.foff + 16): i64, "DX");
|
||||
emitline("\n");
|
||||
return;
|
||||
};
|
||||
@@ -18303,11 +18409,11 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
};};
|
||||
};
|
||||
cgexpr(c, n.rhs);
|
||||
// str field: cgexpr left (AX=ptr, BX=len);
|
||||
// store both halves at +0/+8. Without this,
|
||||
// `L.src = s` would only write the ptr and
|
||||
// `L.src.len` would carry whatever was on the
|
||||
// stack.
|
||||
// str IS []u8: cgexpr left (AX=ptr,
|
||||
// BX=len, CX=cap); store all three at
|
||||
// +0/+8/+16, identical to the slice
|
||||
// arm below. BP base, no scratch
|
||||
// reload needed (#1/Phase 3).
|
||||
if (isstrtype(c, fi.tnode)) {
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff((lc.off + fi.foff): i64);
|
||||
@@ -18315,6 +18421,9 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
emitline("\tMOVQ\tBX, ");
|
||||
emitoff((lc.off + fi.foff + 8): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitoff((lc.off + fi.foff + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
return;
|
||||
};
|
||||
// slice field direct: cgexpr left
|
||||
@@ -18562,14 +18671,22 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
if (n.op == tkind.TK_ASSIGN) {
|
||||
cgexpr(c, n.rhs);
|
||||
if (isstrtype(c, fi.tnode)) {
|
||||
// str IS []u8: cgexpr left
|
||||
// (AX=ptr, BX=len, CX=cap). CX
|
||||
// holds cap, so stage the base
|
||||
// addr in DX and store all three
|
||||
// words (#1/Phase 3).
|
||||
emitline("\tLEAQ\t");
|
||||
emitsymname(c, bn);
|
||||
emitline("(SB), CX\n");
|
||||
emitline("(SB), DX\n");
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitdispreg(fi.foff: i64, "CX");
|
||||
emitdispreg(fi.foff: i64, "DX");
|
||||
emitline("\n");
|
||||
emitline("\tMOVQ\tBX, ");
|
||||
emitdispreg((fi.foff + 8): i64, "CX");
|
||||
emitdispreg((fi.foff + 8): i64, "DX");
|
||||
emitline("\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitdispreg((fi.foff + 16): i64, "DX");
|
||||
emitline("\n");
|
||||
return;
|
||||
};
|
||||
@@ -18808,22 +18925,29 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
return;
|
||||
};
|
||||
if (typeisstr(leaftype)) {
|
||||
// str IS []u8: store ptr/len/cap. cgexpr leaves
|
||||
// CX=cap, so the viacx base goes in DX (not CX) to
|
||||
// avoid clobbering it — same as the single-dot str
|
||||
// field store (#1/Phase 3).
|
||||
cgexpr(c, n.rhs);
|
||||
if (viacx) {
|
||||
if (ptrroot) {
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff(rootoff: i64);
|
||||
emitline("(BP), CX\n");
|
||||
emitline("(BP), DX\n");
|
||||
} else {
|
||||
emitline("\tLEAQ\t");
|
||||
emitsymname(c, rootname);
|
||||
emitline("(SB), CX\n");
|
||||
emitline("(SB), DX\n");
|
||||
};
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitdispreg(totaloff: i64, "CX");
|
||||
emitdispreg(totaloff: i64, "DX");
|
||||
emitline("\n");
|
||||
emitline("\tMOVQ\tBX, ");
|
||||
emitdispreg((totaloff + 8): i64, "CX");
|
||||
emitdispreg((totaloff + 8): i64, "DX");
|
||||
emitline("\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitdispreg((totaloff + 16): i64, "DX");
|
||||
emitline("\n");
|
||||
} else {
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
@@ -18832,6 +18956,9 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
emitline("\tMOVQ\tBX, ");
|
||||
emitoff((rootoff + totaloff + 8): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitoff((rootoff + totaloff + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
};
|
||||
return;
|
||||
};
|
||||
@@ -19319,11 +19446,17 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
cgexpr(c, n.rhs);
|
||||
if (n.op == tkind.TK_ASSIGN) {
|
||||
if (letvarisstr(c, nm)) {
|
||||
// str IS []u8: stash cap in DI before LEAQ
|
||||
// overwrites CX, then store ptr/len/cap —
|
||||
// identical to the slice arm below
|
||||
// (#1/Phase 3).
|
||||
emitline("\tMOVQ\tCX, DI\n");
|
||||
emitline("\tLEAQ\t");
|
||||
emitsymname(c, nm);
|
||||
emitline("(SB), CX\n");
|
||||
emitline("\tMOVQ\tAX, (CX)\n");
|
||||
emitline("\tMOVQ\tBX, 8(CX)\n");
|
||||
emitline("\tMOVQ\tDI, 16(CX)\n");
|
||||
return;
|
||||
};
|
||||
if (letvarisslice(c, nm)) {
|
||||
@@ -19609,7 +19742,9 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
emitoff((off + 8): i64);
|
||||
emitline("(BP)\n");
|
||||
};
|
||||
if (lcsl) {
|
||||
// str IS []u8: store the cap word too, identical to
|
||||
// the slice store (#1/Phase 3).
|
||||
if (lcstr || lcsl) {
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitoff((off + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
@@ -19812,12 +19947,16 @@ fn cgreturn(c: *cgen, n: *node) void = {
|
||||
rundefers(c);
|
||||
let rhs: *node = n.lhs;
|
||||
if (rhs != nil) {
|
||||
// Tuple return `return a, b;`:
|
||||
// Tuple return `return a, b;`, word-indexed AX→DX→CX→R8 (the
|
||||
// SAME register sequence as the tagged-union return below; the
|
||||
// tuple just fills it positionally):
|
||||
// (scalar, scalar) — AX = v0, DX = v1.
|
||||
// (scalar, str) / (str, scalar) — AX = scalar elem,
|
||||
// DX = str.ptr, CX = str.len.
|
||||
// 24B convention mirrors the tagged-union return below; receive
|
||||
// sites destructure off the same regs regardless of position.
|
||||
// DX = str.ptr, CX = str.len, R8 = str.cap.
|
||||
// str IS []u8 (24B) → 32B tuple; cap rides R8, matching the
|
||||
// tagged-union return that already uses R8 for slot+24
|
||||
// (#1/Phase 3, task #5). Receive sites destructure off the
|
||||
// same regs regardless of position.
|
||||
if (rhs.kind == nkind.N_TUPLE) {
|
||||
let v: *node = rhs.list;
|
||||
if (v != nil) {
|
||||
@@ -19832,6 +19971,7 @@ fn cgreturn(c: *cgen, n: *node) void = {
|
||||
cgexpr(c, scaln);
|
||||
emitline("\tPUSHQ\tAX\n");
|
||||
cgexpr(c, strn);
|
||||
emitline("\tMOVQ\tCX, R8\n");
|
||||
emitline("\tMOVQ\tBX, CX\n");
|
||||
emitline("\tMOVQ\tAX, DX\n");
|
||||
emitline("\tPOPQ\tAX\n");
|
||||
@@ -19984,12 +20124,12 @@ fn cgreturn(c: *cgen, n: *node) void = {
|
||||
emitline("\tMOVQ\tBX, CX\n");
|
||||
emitline("\tMOVQ\tAX, DX\n");
|
||||
} else { if (nodeisstr(c, rhs)) {
|
||||
// str IS []u8: cgexpr leaves (AX=ptr, BX=len,
|
||||
// CX=cap). Same shuffle as the slice arm above —
|
||||
// DX=ptr, CX=len, R8=cap (#1/Phase 3).
|
||||
emitline("\tMOVQ\tCX, R8\n");
|
||||
emitline("\tMOVQ\tBX, CX\n");
|
||||
emitline("\tMOVQ\tAX, DX\n");
|
||||
// str fills DX,CX. Zero R8 if dst covers slot+24.
|
||||
if (rsz > 24) {
|
||||
emitline("\tMOVQ\t$0, R8\n");
|
||||
};
|
||||
} else {
|
||||
emitline("\tMOVQ\tAX, DX\n");
|
||||
// scalar fills DX only. Zero CX / R8 if dst
|
||||
@@ -20245,11 +20385,8 @@ fn cgreturn(c: *cgen, n: *node) void = {
|
||||
};
|
||||
emitline("\tMOVQ\t$0, AX\n");
|
||||
};
|
||||
// SysV: 16-byte aggregates (str, 2-tuple) return in (AX, DX).
|
||||
// cgexpr leaves str in (AX, BX); shuffle BX→DX.
|
||||
if (isstrtype(c, c.fnret)) {
|
||||
emitline("\tMOVQ\tBX, DX\n");
|
||||
};
|
||||
// str IS []u8: cgexpr leaves AX=ptr, BX=len, CX=cap — str now
|
||||
// returns exactly like a slice, no AX:DX shuffle (#1/Phase 3).
|
||||
emitline("\tMOVQ\tBP, SP\n");
|
||||
emitline("\tPOPQ\tBP\n");
|
||||
emitline("\tRET\n");
|
||||
@@ -20420,11 +20557,13 @@ fn cglet(c: *cgen, n: *node) void = {
|
||||
c.lastwasreturn = 0;
|
||||
return;
|
||||
};
|
||||
// 24B tuple init for `let t: (scalar, str) = call()` /
|
||||
// `let t: (str, scalar) = call()`. Per the AX:DX:CX return
|
||||
// convention: AX = scalar elem, DX = str.ptr, CX = str.len.
|
||||
// Layout is positional, so we route each register to the
|
||||
// slot dictated by element type, not by AX/DX position.
|
||||
// 32B tuple init for `let t: (scalar, str) = call()` /
|
||||
// `let t: (str, scalar) = call()`. Per the AX:DX:CX:R8 return
|
||||
// convention: AX = scalar elem, DX = str.ptr, CX = str.len,
|
||||
// R8 = str.cap. Layout is positional (str takes 24B at its
|
||||
// position), so we route each register to the slot dictated by
|
||||
// element type, not by AX/DX position. str IS []u8 (24B) → 32B
|
||||
// tuple (#1/Phase 3, task #5).
|
||||
if (n.lhs != nil) {
|
||||
if (n.lhs.kind == nkind.N_TTUPLE) {
|
||||
let p0: *node = n.lhs.list;
|
||||
@@ -20447,9 +20586,12 @@ fn cglet(c: *cgen, n: *node) void = {
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitoff((off + 8): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitline("\tMOVQ\tR8, ");
|
||||
emitoff((off + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff((off + 24): i64);
|
||||
emitline("(BP)\n");
|
||||
} else {
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff(off: i64);
|
||||
@@ -20460,6 +20602,9 @@ fn cglet(c: *cgen, n: *node) void = {
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitoff((off + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tR8, ");
|
||||
emitoff((off + 24): i64);
|
||||
emitline("(BP)\n");
|
||||
};
|
||||
c.lastwasreturn = 0;
|
||||
return;
|
||||
@@ -20750,15 +20895,19 @@ fn cglet(c: *cgen, n: *node) void = {
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff(off: i64);
|
||||
emitline("(BP)\n");
|
||||
// str init: cgexpr also leaves len in BX; store both.
|
||||
// str IS []u8: cgexpr leaves (ptr,len,cap) in AX/BX/CX; store
|
||||
// all three, same as the slice arm below (#1/Phase 3).
|
||||
// #60: gate by kind too — under #1's str=24 bump, sizeof(str)
|
||||
// and sizeof(slice) collide, so a bare `sz ==` check fires
|
||||
// both branches for one let. Mirrors cstage cgen.c:6439's
|
||||
// both branches for one let. Mirrors cstage cgen.c's
|
||||
// `type_isstr(lt) && sz == ty_str->size` shape.
|
||||
if (isstrtype(c, tn) && sz == primtypesize("str"): i32) {
|
||||
emitline("\tMOVQ\tBX, ");
|
||||
emitoff((off + 8): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitoff((off + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
};
|
||||
// slice init: ptr/len/cap in AX/BX/CX. Same kind+size gate as
|
||||
// the str arm — without the kind check this fires on a str let
|
||||
@@ -20919,11 +21068,12 @@ fn cgmassign(c: *cgen, n: *node) void = {
|
||||
// type is taken from its explicit annotation (l.lhs) when present
|
||||
// or inferred from the called fn's return-type tuple element.
|
||||
//
|
||||
// Per the AX:DX:CX return convention (mirrors C cgen nkind.N_MLET):
|
||||
// Per the AX:DX:CX:R8 return convention (mirrors C cgen nkind.N_MLET):
|
||||
// (scalar, scalar) — AX → l0, DX → l1.
|
||||
// (scalar, str) — AX → scalar slot, (DX, CX) → str slot
|
||||
// as (.ptr, .len). Position-agnostic — the
|
||||
// (scalar, str) — AX → scalar slot, (DX, CX, R8) → str slot
|
||||
// as (.ptr, .len, .cap). Position-agnostic — the
|
||||
// regs are routed by element type, not by AX/DX.
|
||||
// str IS []u8 (24B): cap rides R8 (#1/Phase 3, task #5).
|
||||
fn cgmlet(c: *cgen, n: *node) void = {
|
||||
let rhs: *node = n.rhs;
|
||||
if (rhs == nil) { return; };
|
||||
@@ -20992,16 +21142,21 @@ fn cgmlet(c: *cgen, n: *node) void = {
|
||||
let off0: i32 = localadd(c, l0.str, sz0, t0);
|
||||
let off1: i32 = localadd(c, l1.str, sz1, t1);
|
||||
if (s0_is_str) {
|
||||
// l0 str: ptr=DX, len=CX, cap=R8. l1 scalar = AX.
|
||||
emitline("\tMOVQ\tDX, ");
|
||||
emitoff(off0: i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitoff((off0 + 8): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tR8, ");
|
||||
emitoff((off0 + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff(off1: i64);
|
||||
emitline("(BP)\n");
|
||||
} else {
|
||||
// l0 scalar; l1 str: ptr=DX, len=CX, cap=R8.
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff(off0: i64);
|
||||
emitline("(BP)\n");
|
||||
@@ -21011,6 +21166,9 @@ fn cgmlet(c: *cgen, n: *node) void = {
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitoff((off1 + 8): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tR8, ");
|
||||
emitoff((off1 + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
};
|
||||
c.lastwasreturn = 0;
|
||||
return;
|
||||
@@ -21597,11 +21755,11 @@ fn cgfnparams(c: *cgen, params: *node) void = {
|
||||
stkcursor += 3;
|
||||
};};
|
||||
} else { if (isstrtype(c, p.lhs)) {
|
||||
if (idx + 2 <= 6) {
|
||||
// #60: route str-param slot width through the
|
||||
// primtypesize SSoT so #1's ty_str bump propagates
|
||||
// here (parent #43 covered the reg-fill site only
|
||||
// inside cgexpr).
|
||||
if (idx + 3 <= 6) {
|
||||
// str IS []u8: 3-word param (ptr,len,cap), same as
|
||||
// the slice arm above (#1/Phase 3). #60: route slot
|
||||
// width through the primtypesize SSoT so #1's ty_str
|
||||
// bump propagates here.
|
||||
let off: i32 = localadd(c, nm, primtypesize("str"): i32, p.lhs);
|
||||
emitline("\tMOVQ\t");
|
||||
emitline(argregname(idx));
|
||||
@@ -21615,11 +21773,14 @@ fn cgfnparams(c: *cgen, params: *node) void = {
|
||||
emitoff((off + 8): i64);
|
||||
emitline("(BP)\n");
|
||||
idx += 1;
|
||||
emitline("\tMOVQ\t");
|
||||
emitline(argregname(idx));
|
||||
emitline(", ");
|
||||
emitoff((off + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
idx += 1;
|
||||
} else { if (idx < 6) {
|
||||
// Partial-fit stitch — mirrors tagged at lines
|
||||
// 440-469. Only idx=5 hits this (nw=2,
|
||||
// regs_left=1): ptr lands in R9, len at
|
||||
// +16+stkcursor*8(BP).
|
||||
// Partial-fit stitch — mirrors the slice arm above.
|
||||
// #60: same SSoT routing as the regs-fit arm above.
|
||||
let off: i32 = localadd(c, nm, primtypesize("str"): i32, p.lhs);
|
||||
let regs_left: i32 = 6 - idx;
|
||||
@@ -21633,7 +21794,7 @@ fn cgfnparams(c: *cgen, params: *node) void = {
|
||||
idx += 1;
|
||||
w += 1;
|
||||
};
|
||||
for (w < 2) {
|
||||
for (w < 3) {
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff((16 + stkcursor*8): i64);
|
||||
emitline("(BP), AX\n");
|
||||
@@ -21645,7 +21806,7 @@ fn cgfnparams(c: *cgen, params: *node) void = {
|
||||
};
|
||||
} else {
|
||||
localaddstack(c, nm, p.lhs, 16 + stkcursor*8);
|
||||
stkcursor += 2;
|
||||
stkcursor += 3;
|
||||
};};
|
||||
} else { let stsz: i32 = structparamsize(c, p.lhs);
|
||||
if (stsz > 0) {
|
||||
|
||||
@@ -222,11 +222,11 @@ fn cgfnparams(c: *cgen, params: *node) void = {
|
||||
stkcursor += 3;
|
||||
};};
|
||||
} else { if (isstrtype(c, p.lhs)) {
|
||||
if (idx + 2 <= 6) {
|
||||
// #60: route str-param slot width through the
|
||||
// primtypesize SSoT so #1's ty_str bump propagates
|
||||
// here (parent #43 covered the reg-fill site only
|
||||
// inside cgexpr).
|
||||
if (idx + 3 <= 6) {
|
||||
// str IS []u8: 3-word param (ptr,len,cap), same as
|
||||
// the slice arm above (#1/Phase 3). #60: route slot
|
||||
// width through the primtypesize SSoT so #1's ty_str
|
||||
// bump propagates here.
|
||||
let off: i32 = localadd(c, nm, primtypesize("str"): i32, p.lhs);
|
||||
emitline("\tMOVQ\t");
|
||||
emitline(argregname(idx));
|
||||
@@ -240,11 +240,14 @@ fn cgfnparams(c: *cgen, params: *node) void = {
|
||||
emitoff((off + 8): i64);
|
||||
emitline("(BP)\n");
|
||||
idx += 1;
|
||||
emitline("\tMOVQ\t");
|
||||
emitline(argregname(idx));
|
||||
emitline(", ");
|
||||
emitoff((off + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
idx += 1;
|
||||
} else { if (idx < 6) {
|
||||
// Partial-fit stitch — mirrors tagged at lines
|
||||
// 440-469. Only idx=5 hits this (nw=2,
|
||||
// regs_left=1): ptr lands in R9, len at
|
||||
// +16+stkcursor*8(BP).
|
||||
// Partial-fit stitch — mirrors the slice arm above.
|
||||
// #60: same SSoT routing as the regs-fit arm above.
|
||||
let off: i32 = localadd(c, nm, primtypesize("str"): i32, p.lhs);
|
||||
let regs_left: i32 = 6 - idx;
|
||||
@@ -258,7 +261,7 @@ fn cgfnparams(c: *cgen, params: *node) void = {
|
||||
idx += 1;
|
||||
w += 1;
|
||||
};
|
||||
for (w < 2) {
|
||||
for (w < 3) {
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff((16 + stkcursor*8): i64);
|
||||
emitline("(BP), AX\n");
|
||||
@@ -270,7 +273,7 @@ fn cgfnparams(c: *cgen, params: *node) void = {
|
||||
};
|
||||
} else {
|
||||
localaddstack(c, nm, p.lhs, 16 + stkcursor*8);
|
||||
stkcursor += 2;
|
||||
stkcursor += 3;
|
||||
};};
|
||||
} else { let stsz: i32 = structparamsize(c, p.lhs);
|
||||
if (stsz > 0) {
|
||||
|
||||
@@ -185,7 +185,11 @@ fn cgtryprop(c: *cgen, n: *node) void = {
|
||||
};
|
||||
};
|
||||
if (succisstr) {
|
||||
// str IS []u8: success arrives DX=ptr, CX=len, R8=cap
|
||||
// (slot 32B). Move len out before cap overwrites CX
|
||||
// (#1/Phase 3).
|
||||
emitline("\tMOVQ\tCX, BX\n");
|
||||
emitline("\tMOVQ\tR8, CX\n");
|
||||
};
|
||||
emitline("\tMOVQ\tDX, AX\n");
|
||||
return;
|
||||
@@ -241,7 +245,11 @@ fn cgtryunw(c: *cgen, n: *node) void = {
|
||||
};
|
||||
};
|
||||
if (succisstr) {
|
||||
// str IS []u8: success arrives DX=ptr, CX=len, R8=cap
|
||||
// (slot 32B). Move len out before cap overwrites CX
|
||||
// (#1/Phase 3).
|
||||
emitline("\tMOVQ\tCX, BX\n");
|
||||
emitline("\tMOVQ\tR8, CX\n");
|
||||
};
|
||||
emitline("\tMOVQ\tDX, AX\n");
|
||||
return;
|
||||
@@ -514,8 +522,9 @@ fn cgcast(c: *cgen, n: *node) void = {
|
||||
};
|
||||
|
||||
fn cgstrlit(c: *cgen, n: *node) void = {
|
||||
// Result is the (ptr, len) pair: ptr in AX, len in BX. Call
|
||||
// sites that expect a str arg pick these up directly.
|
||||
// str IS []u8: the (ptr, len, cap) triple — ptr in AX, len in BX,
|
||||
// cap in CX. A static literal has no spare storage, so cap = len
|
||||
// (#1/Phase 3). Call sites that expect a str arg pick these up.
|
||||
let nstr: str = n.str;
|
||||
let lab: str = internstrlit(c, nstr);
|
||||
emitline("\tLEAQ\t");
|
||||
@@ -524,6 +533,9 @@ fn cgstrlit(c: *cgen, n: *node) void = {
|
||||
emitline("\tMOVQ\t$");
|
||||
emitint(nstr.len: i64);
|
||||
emitline(", BX\n");
|
||||
emitline("\tMOVQ\t$");
|
||||
emitint(nstr.len: i64);
|
||||
emitline(", CX\n");
|
||||
return;
|
||||
};
|
||||
|
||||
@@ -559,9 +571,14 @@ fn cgident(c: *cgen, n: *node) void = {
|
||||
emitoff(off: i64);
|
||||
emitline("(BP), AX\n");
|
||||
if (isstr) {
|
||||
// str IS []u8: load (ptr,len,cap) into AX/BX/CX,
|
||||
// identical to the slice arm below (#1/Phase 3).
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff((off + 8): i64);
|
||||
emitline("(BP), BX\n");
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff((off + 16): i64);
|
||||
emitline("(BP), CX\n");
|
||||
};
|
||||
if (issl) {
|
||||
emitline("\tMOVQ\t");
|
||||
@@ -591,6 +608,11 @@ fn cgident(c: *cgen, n: *node) void = {
|
||||
emitline("\tMOVQ\t$");
|
||||
emitint(bytes.len: i64);
|
||||
emitline(", BX\n");
|
||||
// str IS []u8: cap = len for a static def literal
|
||||
// (#1/Phase 3).
|
||||
emitline("\tMOVQ\t$");
|
||||
emitint(bytes.len: i64);
|
||||
emitline(", CX\n");
|
||||
return;
|
||||
};
|
||||
};
|
||||
@@ -622,17 +644,16 @@ fn cgident(c: *cgen, n: *node) void = {
|
||||
let isstr: bool = letvarisstr(c, nm);
|
||||
let issl: bool = letvarisslice(c, nm);
|
||||
if (isstr || issl) {
|
||||
// str IS []u8: both str and slice carry a third 8B
|
||||
// (cap); load it unconditionally. The address holder CX
|
||||
// is overwritten by the cap as the last step, after
|
||||
// ptr/len are already loaded (#1/Phase 3).
|
||||
emitline("\tLEAQ\t");
|
||||
emitsymname(c, nm);
|
||||
emitline("(SB), CX\n");
|
||||
emitline("\tMOVQ\t(CX), AX\n");
|
||||
emitline("\tMOVQ\t8(CX), BX\n");
|
||||
if (issl) {
|
||||
// Overwrites the address holder with the
|
||||
// cap as the last step — CX is no longer
|
||||
// needed once both ptr/len are loaded.
|
||||
emitline("\tMOVQ\t16(CX), CX\n");
|
||||
};
|
||||
emitline("\tMOVQ\t16(CX), CX\n");
|
||||
return;
|
||||
};
|
||||
// Float global: same LEAQ-indirect shape, since MOVSS/
|
||||
@@ -686,6 +707,12 @@ fn cgindex(c: *cgen, n: *node) void = {
|
||||
let idx: *node = n.rhs;
|
||||
let esz: i32 = 8;
|
||||
let signed_elem: bool = false;
|
||||
// #1/Phase 3: str=24B collides with slice=24B, so the str-element
|
||||
// branches below MUST gate on kind (mirroring cstage's elem_is_str),
|
||||
// not a bare `esz == primtypesize("str")` size check — otherwise a
|
||||
// []u8 element (also 24B) misfires into the str 2-word load and
|
||||
// diverges from cstage (#60 collision class; sentinel 754).
|
||||
let elemisstr: bool = false;
|
||||
let baselocal: *local = nil;
|
||||
// Global `[N]T` array or `*T` pointer used as an index base.
|
||||
// The local-ident lookup above misses it; we need LEAQ name(SB)
|
||||
@@ -727,7 +754,7 @@ fn cgindex(c: *cgen, n: *node) void = {
|
||||
// cgen.c:3517-18). esz-only — N_DOT-base signedness
|
||||
// stays unset, as before.
|
||||
let dt: *tinfo = n.type_: *tinfo;
|
||||
if (dt != nil) { esz = dt.size: i32; };
|
||||
if (dt != nil) { esz = dt.size: i32; elemisstr = typeisstr(dt); };
|
||||
} else { if (base.kind == nkind.N_INDEX) {
|
||||
// #60: chained `names[i][k]` — n.type_ is the checker-
|
||||
// stamped outer element tinfo (indexresult over the inner
|
||||
@@ -776,6 +803,7 @@ fn cgindex(c: *cgen, n: *node) void = {
|
||||
esz = elem_slot_sz;
|
||||
};
|
||||
};
|
||||
elemisstr = isstrtype(c, etn);
|
||||
};
|
||||
};
|
||||
cgexpr(c, idx);
|
||||
@@ -811,7 +839,7 @@ fn cgindex(c: *cgen, n: *node) void = {
|
||||
};
|
||||
// #43: str element-stride routes through primtypesize so the
|
||||
// 16-vs-24 dispatch tracks ty_str.size for #1.
|
||||
if (esz == primtypesize("str"): i32) {
|
||||
if (elemisstr) {
|
||||
emitline("\tMOVQ\t8(BX), CX\n");
|
||||
emitline("\tMOVQ\t(BX), AX\n");
|
||||
emitline("\tMOVQ\tCX, BX\n");
|
||||
@@ -853,7 +881,7 @@ fn cgindex(c: *cgen, n: *node) void = {
|
||||
// str element (16B today): load (ptr, len) into (AX, BX) so
|
||||
// the value flows through the str-rhs convention.
|
||||
// #43: route via primtypesize so the stride tracks #1.
|
||||
if (esz == primtypesize("str"): i32) {
|
||||
if (elemisstr) {
|
||||
emitline("\tMOVQ\t8(BX), CX\n");
|
||||
emitline("\tMOVQ\t(BX), AX\n");
|
||||
emitline("\tMOVQ\tCX, BX\n");
|
||||
@@ -885,7 +913,7 @@ fn cgindex(c: *cgen, n: *node) void = {
|
||||
};
|
||||
// #43: str element-stride routes through primtypesize so the
|
||||
// 16-vs-24 dispatch tracks ty_str.size for #1.
|
||||
if (esz == primtypesize("str"): i32) {
|
||||
if (elemisstr) {
|
||||
emitline("\tMOVQ\t8(AX), BX\n");
|
||||
emitline("\tMOVQ\t(AX), AX\n");
|
||||
return;
|
||||
@@ -1480,10 +1508,11 @@ fn cgdot(c: *cgen, n: *node) void = {
|
||||
};
|
||||
// Hare-style tuple positional access: `t.0`, `t.1`.
|
||||
// Walk the tuple element type list summing slotsize
|
||||
// (matches the (scalar, str) init layout which puts
|
||||
// the scalar in an 8B slot and the str in 16B). For
|
||||
// a str element, load both halves into (AX, BX) so
|
||||
// chains like `t.1.len` propagate correctly.
|
||||
// (matches the (scalar, str) init layout: scalar in an
|
||||
// 8B slot, str in 24B — str IS []u8, #1/Phase 3). For a
|
||||
// str element, load (ptr, len) into (AX, BX); the cap
|
||||
// stays in the slot (the 2-word str-field read, like
|
||||
// every other chained/dot str leaf read — task #14).
|
||||
if (lkind == nkind.N_TTUPLE) {
|
||||
let idx: i32 = fldnumidx(fld);
|
||||
if (idx >= 0) {
|
||||
@@ -1598,9 +1627,9 @@ fn cgdot(c: *cgen, n: *node) void = {
|
||||
let delta: i32 = -1;
|
||||
if (streq(fld, "ptr")) { delta = 0; };
|
||||
if (streq(fld, "len")) { delta = 8; };
|
||||
if (issl) {
|
||||
if (streq(fld, "cap")) { delta = 16; };
|
||||
};
|
||||
// str IS []u8: .cap is valid on a str global too,
|
||||
// not slice-only — mirrors cstage (#1/Phase 3, #11).
|
||||
if (streq(fld, "cap")) { delta = 16; };
|
||||
if (delta >= 0) {
|
||||
emitline("\tLEAQ\t");
|
||||
emitsymname(c, lhs.str);
|
||||
@@ -2456,7 +2485,9 @@ fn cgun(c: *cgen, n: *node) void = {
|
||||
let gdelta: i32 = -1;
|
||||
if (streq(fld, "ptr")) { gdelta = 0; };
|
||||
if (streq(fld, "len")) { gdelta = 8; };
|
||||
if (issl) { if (streq(fld, "cap")) { gdelta = 16; }; };
|
||||
// str IS []u8: &str.cap is valid too, not slice-only
|
||||
// — mirrors cstage (#1/Phase 3, #11).
|
||||
if (streq(fld, "cap")) { gdelta = 16; };
|
||||
if (gdelta >= 0) {
|
||||
emitline("\tLEAQ\t");
|
||||
emitsymname(c, basenm);
|
||||
@@ -2828,16 +2859,19 @@ fn cgalloc(c: *cgen, n: *node) void = {
|
||||
emitline("\n");
|
||||
fi = nil;
|
||||
} else { if (isstrtype(c, fi.tnode)) {
|
||||
// alloc(T{ fval = s }) for str field: cgexpr
|
||||
// leaves (AX=ptr, BX=len). Use CX for the heap
|
||||
// base so BX=len survives both stores. Mirrors
|
||||
// cmd/w6c/cgen.c:4184-4190.
|
||||
emitline("\tMOVQ\t(SP), CX\n");
|
||||
// str IS []u8: cgexpr leaves (AX=ptr,
|
||||
// BX=len, CX=cap). Route the heap base
|
||||
// through DX so all three survive — CX
|
||||
// holds cap, BX holds len (#1/Phase 3).
|
||||
emitline("\tMOVQ\t(SP), DX\n");
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitdispreg(fi.foff: i64, "CX");
|
||||
emitdispreg(fi.foff: i64, "DX");
|
||||
emitline("\n");
|
||||
emitline("\tMOVQ\tBX, ");
|
||||
emitdispreg((fi.foff + 8): i64, "CX");
|
||||
emitdispreg((fi.foff + 8): i64, "DX");
|
||||
emitline("\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitdispreg((fi.foff + 16): i64, "DX");
|
||||
emitline("\n");
|
||||
fi = nil;
|
||||
} else {
|
||||
@@ -3297,7 +3331,8 @@ fn cgcall(c: *cgen, n: *node) void = {
|
||||
popped += 1;
|
||||
} else {
|
||||
let extra: i32 = 0;
|
||||
if (nodeisstr(c, a)) { extra = 1; };
|
||||
// str IS []u8: 3-word arg, same as slice (#1/Phase 3).
|
||||
if (nodeisstr(c, a)) { extra = 2; };
|
||||
if (nodeisslice(c, a)) { extra = 2; };
|
||||
// #21: tagged-CALL arg was pushed AX/DX/CX/R8 high→low
|
||||
// by pushargsrev; size the per-arg pop to match so the
|
||||
@@ -3467,31 +3502,9 @@ fn cgcall(c: *cgen, n: *node) void = {
|
||||
emitint((stackslots * 8): i64);
|
||||
emitline(", SP\n");
|
||||
};
|
||||
// SysV returns 16-byte aggregates in (AX, DX). Our str
|
||||
// convention is (AX, BX), so shuffle for str-returning calls.
|
||||
// Route through fnretlookupmod: for N_DOT cross-module callees,
|
||||
// the bare-leaf fnretlookup's same-module-first walk (#4e) would
|
||||
// pick the caller-module's same-leaf fn — a str-returning
|
||||
// caller-side `slice` over a []u8-returning `mod.slice` then
|
||||
// emits a phantom MOVQ DX, BX after the cross-module CALL (#34).
|
||||
if (calleename.len > 0) {
|
||||
let cmod: str;
|
||||
cmod.ptr = nil; cmod.len = 0;
|
||||
if (callee != nil) {
|
||||
if (callee.kind == nkind.N_IDENT) { cmod = c.curmod; };
|
||||
if (callee.kind == nkind.N_DOT) {
|
||||
if (callee.lhs != nil) {
|
||||
if (callee.lhs.kind == nkind.N_IDENT) {
|
||||
cmod = callee.lhs.str;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
let rtyp: *node = fnretlookupmod(c, calleename, cmod);
|
||||
if (isstrtype(c, rtyp)) {
|
||||
emitline("\tMOVQ\tDX, BX\n");
|
||||
};
|
||||
};
|
||||
// str IS []u8: a str-returning callee leaves AX=ptr, BX=len,
|
||||
// CX=cap — same as a slice, so there is no receive-side shuffle
|
||||
// (#1/Phase 3).
|
||||
return;
|
||||
};
|
||||
|
||||
@@ -3590,17 +3603,21 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
emitline("\tX0, (BX)\n");
|
||||
return;
|
||||
};
|
||||
// Push order matches C cgen
|
||||
// (cmd/w6c/cgen.c:1033-1041): PUSHQ AX
|
||||
// (ptr) first, then PUSHQ BX (len) if
|
||||
// str, so the pop sequence is POP CX
|
||||
// (len) → POP AX (ptr) → MOVQ AX,
|
||||
// (BX) → MOVQ CX, 8(BX).
|
||||
// str IS []u8: PUSHQ AX (ptr) first, then
|
||||
// PUSHQ BX (len) + PUSHQ CX (cap) across the
|
||||
// pointer eval which clobbers BX/CX. Pop drains
|
||||
// cap (top) → 16(BX), then len, then ptr → 0(BX)
|
||||
// with len → 8(BX) (#1/Phase 3).
|
||||
emitline("\tPUSHQ\tAX\n");
|
||||
if (elemstr) { emitline("\tPUSHQ\tBX\n"); };
|
||||
if (elemstr) {
|
||||
emitline("\tPUSHQ\tBX\n");
|
||||
emitline("\tPUSHQ\tCX\n");
|
||||
};
|
||||
cgexpr(c, inner);
|
||||
emitline("\tMOVQ\tAX, BX\n");
|
||||
if (elemstr) {
|
||||
emitline("\tPOPQ\tCX\n");
|
||||
emitline("\tMOVQ\tCX, 16(BX)\n");
|
||||
emitline("\tPOPQ\tCX\n");
|
||||
emitline("\tPOPQ\tAX\n");
|
||||
emitline("\tMOVQ\tAX, (BX)\n");
|
||||
@@ -3854,10 +3871,19 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
};
|
||||
};
|
||||
cgexpr(c, n.rhs); // value → AX
|
||||
// #43: spill BX (str.len) before computing
|
||||
// the index so the post-index store can pop
|
||||
// it; the stride gate tracks ty_str.size.
|
||||
if (esz == primtypesize("str"): i32) { emitline("\tPUSHQ\tBX\n"); };
|
||||
// str IS []u8: spill cap (CX) + len (BX) before
|
||||
// computing the index so the post-index store can
|
||||
// pop all three. #1/Phase 3: str=24B collides with
|
||||
// slice=24B, so this MUST gate on kind (cstage's
|
||||
// elem_is_str, cmd/w6c/cgen.c:3576) — not a bare
|
||||
// `esz == primtypesize("str")` — or a []u8 element
|
||||
// (also 24B) misfires the str 3-word store and
|
||||
// diverges from cstage. Write-side mirror of the
|
||||
// cgindex read-path gate (#7/754).
|
||||
if (isstrtype(c, elemtn)) {
|
||||
emitline("\tPUSHQ\tCX\n");
|
||||
emitline("\tPUSHQ\tBX\n");
|
||||
};
|
||||
emitline("\tPUSHQ\tAX\n");
|
||||
cgexpr(c, idx); // idx → AX
|
||||
if (esz > 1) {
|
||||
@@ -3895,13 +3921,15 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
emitline("\tPOPQ\tAX\n"); // scaled idx
|
||||
emitline("\tADDQ\tAX, BX\n");
|
||||
emitline("\tPOPQ\tAX\n"); // value
|
||||
// #43: str-element write — pop the saved
|
||||
// .len and store both halves. Stride gate
|
||||
// routes through primtypesize for #1.
|
||||
if (esz == primtypesize("str"): i32) {
|
||||
// str IS []u8: pop the saved len + cap and store
|
||||
// all three words. Kind-gate, not size — see the
|
||||
// spill site above (#1/Phase 3, #7/754).
|
||||
if (isstrtype(c, elemtn)) {
|
||||
emitline("\tMOVQ\tAX, (BX)\n");
|
||||
emitline("\tPOPQ\tCX\n");
|
||||
emitline("\tMOVQ\tCX, 8(BX)\n");
|
||||
emitline("\tPOPQ\tCX\n");
|
||||
emitline("\tMOVQ\tCX, 16(BX)\n");
|
||||
return;
|
||||
};
|
||||
let isop: str = tnodestoreop(c, elemtn, esz);
|
||||
@@ -4328,20 +4356,24 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
emitline("\tMOVQ\tBX, AX\n");
|
||||
};
|
||||
};
|
||||
// str field via *struct: rhs left
|
||||
// (AX=ptr, BX=len). Use CX as the
|
||||
// address scratch so we don't clobber
|
||||
// the len half before storing it.
|
||||
// str IS []u8: rhs left (AX=ptr,
|
||||
// BX=len, CX=cap). CX holds cap, so
|
||||
// stage the struct addr in DX and
|
||||
// store all three words — identical
|
||||
// to the slice arm below (#1/Phase 3).
|
||||
if (n.op == tkind.TK_ASSIGN) {
|
||||
if (isstrtype(c, fi.tnode)) {
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff(lc.off: i64);
|
||||
emitline("(BP), CX\n");
|
||||
emitline("(BP), DX\n");
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitdispreg(fi.foff: i64, "CX");
|
||||
emitdispreg(fi.foff: i64, "DX");
|
||||
emitline("\n");
|
||||
emitline("\tMOVQ\tBX, ");
|
||||
emitdispreg((fi.foff + 8): i64, "CX");
|
||||
emitdispreg((fi.foff + 8): i64, "DX");
|
||||
emitline("\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitdispreg((fi.foff + 16): i64, "DX");
|
||||
emitline("\n");
|
||||
return;
|
||||
};
|
||||
@@ -4532,11 +4564,11 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
};};
|
||||
};
|
||||
cgexpr(c, n.rhs);
|
||||
// str field: cgexpr left (AX=ptr, BX=len);
|
||||
// store both halves at +0/+8. Without this,
|
||||
// `L.src = s` would only write the ptr and
|
||||
// `L.src.len` would carry whatever was on the
|
||||
// stack.
|
||||
// str IS []u8: cgexpr left (AX=ptr,
|
||||
// BX=len, CX=cap); store all three at
|
||||
// +0/+8/+16, identical to the slice
|
||||
// arm below. BP base, no scratch
|
||||
// reload needed (#1/Phase 3).
|
||||
if (isstrtype(c, fi.tnode)) {
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff((lc.off + fi.foff): i64);
|
||||
@@ -4544,6 +4576,9 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
emitline("\tMOVQ\tBX, ");
|
||||
emitoff((lc.off + fi.foff + 8): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitoff((lc.off + fi.foff + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
return;
|
||||
};
|
||||
// slice field direct: cgexpr left
|
||||
@@ -4791,14 +4826,22 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
if (n.op == tkind.TK_ASSIGN) {
|
||||
cgexpr(c, n.rhs);
|
||||
if (isstrtype(c, fi.tnode)) {
|
||||
// str IS []u8: cgexpr left
|
||||
// (AX=ptr, BX=len, CX=cap). CX
|
||||
// holds cap, so stage the base
|
||||
// addr in DX and store all three
|
||||
// words (#1/Phase 3).
|
||||
emitline("\tLEAQ\t");
|
||||
emitsymname(c, bn);
|
||||
emitline("(SB), CX\n");
|
||||
emitline("(SB), DX\n");
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitdispreg(fi.foff: i64, "CX");
|
||||
emitdispreg(fi.foff: i64, "DX");
|
||||
emitline("\n");
|
||||
emitline("\tMOVQ\tBX, ");
|
||||
emitdispreg((fi.foff + 8): i64, "CX");
|
||||
emitdispreg((fi.foff + 8): i64, "DX");
|
||||
emitline("\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitdispreg((fi.foff + 16): i64, "DX");
|
||||
emitline("\n");
|
||||
return;
|
||||
};
|
||||
@@ -5037,22 +5080,29 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
return;
|
||||
};
|
||||
if (typeisstr(leaftype)) {
|
||||
// str IS []u8: store ptr/len/cap. cgexpr leaves
|
||||
// CX=cap, so the viacx base goes in DX (not CX) to
|
||||
// avoid clobbering it — same as the single-dot str
|
||||
// field store (#1/Phase 3).
|
||||
cgexpr(c, n.rhs);
|
||||
if (viacx) {
|
||||
if (ptrroot) {
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff(rootoff: i64);
|
||||
emitline("(BP), CX\n");
|
||||
emitline("(BP), DX\n");
|
||||
} else {
|
||||
emitline("\tLEAQ\t");
|
||||
emitsymname(c, rootname);
|
||||
emitline("(SB), CX\n");
|
||||
emitline("(SB), DX\n");
|
||||
};
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitdispreg(totaloff: i64, "CX");
|
||||
emitdispreg(totaloff: i64, "DX");
|
||||
emitline("\n");
|
||||
emitline("\tMOVQ\tBX, ");
|
||||
emitdispreg((totaloff + 8): i64, "CX");
|
||||
emitdispreg((totaloff + 8): i64, "DX");
|
||||
emitline("\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitdispreg((totaloff + 16): i64, "DX");
|
||||
emitline("\n");
|
||||
} else {
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
@@ -5061,6 +5111,9 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
emitline("\tMOVQ\tBX, ");
|
||||
emitoff((rootoff + totaloff + 8): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitoff((rootoff + totaloff + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
};
|
||||
return;
|
||||
};
|
||||
@@ -5548,11 +5601,17 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
cgexpr(c, n.rhs);
|
||||
if (n.op == tkind.TK_ASSIGN) {
|
||||
if (letvarisstr(c, nm)) {
|
||||
// str IS []u8: stash cap in DI before LEAQ
|
||||
// overwrites CX, then store ptr/len/cap —
|
||||
// identical to the slice arm below
|
||||
// (#1/Phase 3).
|
||||
emitline("\tMOVQ\tCX, DI\n");
|
||||
emitline("\tLEAQ\t");
|
||||
emitsymname(c, nm);
|
||||
emitline("(SB), CX\n");
|
||||
emitline("\tMOVQ\tAX, (CX)\n");
|
||||
emitline("\tMOVQ\tBX, 8(CX)\n");
|
||||
emitline("\tMOVQ\tDI, 16(CX)\n");
|
||||
return;
|
||||
};
|
||||
if (letvarisslice(c, nm)) {
|
||||
@@ -5838,7 +5897,9 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
emitoff((off + 8): i64);
|
||||
emitline("(BP)\n");
|
||||
};
|
||||
if (lcsl) {
|
||||
// str IS []u8: store the cap word too, identical to
|
||||
// the slice store (#1/Phase 3).
|
||||
if (lcstr || lcsl) {
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitoff((off + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
|
||||
@@ -111,12 +111,16 @@ fn cgreturn(c: *cgen, n: *node) void = {
|
||||
rundefers(c);
|
||||
let rhs: *node = n.lhs;
|
||||
if (rhs != nil) {
|
||||
// Tuple return `return a, b;`:
|
||||
// Tuple return `return a, b;`, word-indexed AX→DX→CX→R8 (the
|
||||
// SAME register sequence as the tagged-union return below; the
|
||||
// tuple just fills it positionally):
|
||||
// (scalar, scalar) — AX = v0, DX = v1.
|
||||
// (scalar, str) / (str, scalar) — AX = scalar elem,
|
||||
// DX = str.ptr, CX = str.len.
|
||||
// 24B convention mirrors the tagged-union return below; receive
|
||||
// sites destructure off the same regs regardless of position.
|
||||
// DX = str.ptr, CX = str.len, R8 = str.cap.
|
||||
// str IS []u8 (24B) → 32B tuple; cap rides R8, matching the
|
||||
// tagged-union return that already uses R8 for slot+24
|
||||
// (#1/Phase 3, task #5). Receive sites destructure off the
|
||||
// same regs regardless of position.
|
||||
if (rhs.kind == nkind.N_TUPLE) {
|
||||
let v: *node = rhs.list;
|
||||
if (v != nil) {
|
||||
@@ -131,6 +135,7 @@ fn cgreturn(c: *cgen, n: *node) void = {
|
||||
cgexpr(c, scaln);
|
||||
emitline("\tPUSHQ\tAX\n");
|
||||
cgexpr(c, strn);
|
||||
emitline("\tMOVQ\tCX, R8\n");
|
||||
emitline("\tMOVQ\tBX, CX\n");
|
||||
emitline("\tMOVQ\tAX, DX\n");
|
||||
emitline("\tPOPQ\tAX\n");
|
||||
@@ -283,12 +288,12 @@ fn cgreturn(c: *cgen, n: *node) void = {
|
||||
emitline("\tMOVQ\tBX, CX\n");
|
||||
emitline("\tMOVQ\tAX, DX\n");
|
||||
} else { if (nodeisstr(c, rhs)) {
|
||||
// str IS []u8: cgexpr leaves (AX=ptr, BX=len,
|
||||
// CX=cap). Same shuffle as the slice arm above —
|
||||
// DX=ptr, CX=len, R8=cap (#1/Phase 3).
|
||||
emitline("\tMOVQ\tCX, R8\n");
|
||||
emitline("\tMOVQ\tBX, CX\n");
|
||||
emitline("\tMOVQ\tAX, DX\n");
|
||||
// str fills DX,CX. Zero R8 if dst covers slot+24.
|
||||
if (rsz > 24) {
|
||||
emitline("\tMOVQ\t$0, R8\n");
|
||||
};
|
||||
} else {
|
||||
emitline("\tMOVQ\tAX, DX\n");
|
||||
// scalar fills DX only. Zero CX / R8 if dst
|
||||
@@ -544,11 +549,8 @@ fn cgreturn(c: *cgen, n: *node) void = {
|
||||
};
|
||||
emitline("\tMOVQ\t$0, AX\n");
|
||||
};
|
||||
// SysV: 16-byte aggregates (str, 2-tuple) return in (AX, DX).
|
||||
// cgexpr leaves str in (AX, BX); shuffle BX→DX.
|
||||
if (isstrtype(c, c.fnret)) {
|
||||
emitline("\tMOVQ\tBX, DX\n");
|
||||
};
|
||||
// str IS []u8: cgexpr leaves AX=ptr, BX=len, CX=cap — str now
|
||||
// returns exactly like a slice, no AX:DX shuffle (#1/Phase 3).
|
||||
emitline("\tMOVQ\tBP, SP\n");
|
||||
emitline("\tPOPQ\tBP\n");
|
||||
emitline("\tRET\n");
|
||||
@@ -719,11 +721,13 @@ fn cglet(c: *cgen, n: *node) void = {
|
||||
c.lastwasreturn = 0;
|
||||
return;
|
||||
};
|
||||
// 24B tuple init for `let t: (scalar, str) = call()` /
|
||||
// `let t: (str, scalar) = call()`. Per the AX:DX:CX return
|
||||
// convention: AX = scalar elem, DX = str.ptr, CX = str.len.
|
||||
// Layout is positional, so we route each register to the
|
||||
// slot dictated by element type, not by AX/DX position.
|
||||
// 32B tuple init for `let t: (scalar, str) = call()` /
|
||||
// `let t: (str, scalar) = call()`. Per the AX:DX:CX:R8 return
|
||||
// convention: AX = scalar elem, DX = str.ptr, CX = str.len,
|
||||
// R8 = str.cap. Layout is positional (str takes 24B at its
|
||||
// position), so we route each register to the slot dictated by
|
||||
// element type, not by AX/DX position. str IS []u8 (24B) → 32B
|
||||
// tuple (#1/Phase 3, task #5).
|
||||
if (n.lhs != nil) {
|
||||
if (n.lhs.kind == nkind.N_TTUPLE) {
|
||||
let p0: *node = n.lhs.list;
|
||||
@@ -746,9 +750,12 @@ fn cglet(c: *cgen, n: *node) void = {
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitoff((off + 8): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitline("\tMOVQ\tR8, ");
|
||||
emitoff((off + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff((off + 24): i64);
|
||||
emitline("(BP)\n");
|
||||
} else {
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff(off: i64);
|
||||
@@ -759,6 +766,9 @@ fn cglet(c: *cgen, n: *node) void = {
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitoff((off + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tR8, ");
|
||||
emitoff((off + 24): i64);
|
||||
emitline("(BP)\n");
|
||||
};
|
||||
c.lastwasreturn = 0;
|
||||
return;
|
||||
@@ -1049,15 +1059,19 @@ fn cglet(c: *cgen, n: *node) void = {
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff(off: i64);
|
||||
emitline("(BP)\n");
|
||||
// str init: cgexpr also leaves len in BX; store both.
|
||||
// str IS []u8: cgexpr leaves (ptr,len,cap) in AX/BX/CX; store
|
||||
// all three, same as the slice arm below (#1/Phase 3).
|
||||
// #60: gate by kind too — under #1's str=24 bump, sizeof(str)
|
||||
// and sizeof(slice) collide, so a bare `sz ==` check fires
|
||||
// both branches for one let. Mirrors cstage cgen.c:6439's
|
||||
// both branches for one let. Mirrors cstage cgen.c's
|
||||
// `type_isstr(lt) && sz == ty_str->size` shape.
|
||||
if (isstrtype(c, tn) && sz == primtypesize("str"): i32) {
|
||||
emitline("\tMOVQ\tBX, ");
|
||||
emitoff((off + 8): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitoff((off + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
};
|
||||
// slice init: ptr/len/cap in AX/BX/CX. Same kind+size gate as
|
||||
// the str arm — without the kind check this fires on a str let
|
||||
@@ -1218,11 +1232,12 @@ fn cgmassign(c: *cgen, n: *node) void = {
|
||||
// type is taken from its explicit annotation (l.lhs) when present
|
||||
// or inferred from the called fn's return-type tuple element.
|
||||
//
|
||||
// Per the AX:DX:CX return convention (mirrors C cgen nkind.N_MLET):
|
||||
// Per the AX:DX:CX:R8 return convention (mirrors C cgen nkind.N_MLET):
|
||||
// (scalar, scalar) — AX → l0, DX → l1.
|
||||
// (scalar, str) — AX → scalar slot, (DX, CX) → str slot
|
||||
// as (.ptr, .len). Position-agnostic — the
|
||||
// (scalar, str) — AX → scalar slot, (DX, CX, R8) → str slot
|
||||
// as (.ptr, .len, .cap). Position-agnostic — the
|
||||
// regs are routed by element type, not by AX/DX.
|
||||
// str IS []u8 (24B): cap rides R8 (#1/Phase 3, task #5).
|
||||
fn cgmlet(c: *cgen, n: *node) void = {
|
||||
let rhs: *node = n.rhs;
|
||||
if (rhs == nil) { return; };
|
||||
@@ -1291,16 +1306,21 @@ fn cgmlet(c: *cgen, n: *node) void = {
|
||||
let off0: i32 = localadd(c, l0.str, sz0, t0);
|
||||
let off1: i32 = localadd(c, l1.str, sz1, t1);
|
||||
if (s0_is_str) {
|
||||
// l0 str: ptr=DX, len=CX, cap=R8. l1 scalar = AX.
|
||||
emitline("\tMOVQ\tDX, ");
|
||||
emitoff(off0: i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitoff((off0 + 8): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tR8, ");
|
||||
emitoff((off0 + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff(off1: i64);
|
||||
emitline("(BP)\n");
|
||||
} else {
|
||||
// l0 scalar; l1 str: ptr=DX, len=CX, cap=R8.
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff(off0: i64);
|
||||
emitline("(BP)\n");
|
||||
@@ -1310,6 +1330,9 @@ fn cgmlet(c: *cgen, n: *node) void = {
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitoff((off1 + 8): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tR8, ");
|
||||
emitoff((off1 + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
};
|
||||
c.lastwasreturn = 0;
|
||||
return;
|
||||
|
||||
@@ -249,8 +249,11 @@ fn pushargsrev(c: *cgen, arg: *node, param: *node) i32 = {
|
||||
emitline(", AX\n");
|
||||
emitline("\tPUSHQ\tAX\n");
|
||||
} else { if (nodeisstr(c, arg)) {
|
||||
// slot 24: [+0]=tag,[+8]=ptr,[+16]=len. Push high→low
|
||||
// so pop drains tag first into arg-reg[0].
|
||||
// str IS []u8: slot 32 [+0]=tag,[+8]=ptr,[+16]=len,
|
||||
// [+24]=cap — same shape as the slice arm above. Push
|
||||
// cap, len, ptr, tag high→low so pop drains tag first
|
||||
// into arg-reg[0] (#1/Phase 3).
|
||||
emitline("\tPUSHQ\tCX\n");
|
||||
emitline("\tPUSHQ\tBX\n");
|
||||
emitline("\tPUSHQ\tAX\n");
|
||||
emitline("\tMOVQ\t$");
|
||||
@@ -468,9 +471,12 @@ fn pushargsrev(c: *cgen, arg: *node, param: *node) i32 = {
|
||||
return rest + 3;
|
||||
};
|
||||
if (nodeisstr(c, arg)) {
|
||||
// str IS []u8: cgexpr left (AX=ptr, BX=len, CX=cap). Push
|
||||
// the triple, same as the slice arm above (#1/Phase 3).
|
||||
emitline("\tPUSHQ\tCX\n");
|
||||
emitline("\tPUSHQ\tBX\n");
|
||||
emitline("\tPUSHQ\tAX\n");
|
||||
return rest + 2;
|
||||
return rest + 3;
|
||||
};
|
||||
// #21: CALL returning a tagged-union — the aistagged guard
|
||||
// above kept us out of the widening path. Push the tagged-
|
||||
@@ -2320,7 +2326,7 @@ fn cgloadtaggedfield(c: *cgen, basereg: str, foff: i32, slot_sz: i32) void = {
|
||||
// would need a reversed direction we don't currently emit).
|
||||
// - struct src (literal or ident): zero slot, write fields at +8+foff,
|
||||
// tag last.
|
||||
// - str src: tag@+0, ptr@+8, len@+16.
|
||||
// - str src: tag@+0, ptr@+8, len@+16, cap@+24 (str IS []u8, #1/Phase 3).
|
||||
// - scalar src: tag@+0, value@+8.
|
||||
fn cgwidentaggedstore(c: *cgen, dst: *tinfo, src: *node,
|
||||
basereg: str, slot_off: i32, slot_sz: i32) void = {
|
||||
@@ -2538,12 +2544,18 @@ fn cgwidentaggedstorebp(c: *cgen, dst: *tinfo, src: *node, slot_off: i32, slot_s
|
||||
emitoff((slot_off + 8 + fi.foff): i64);
|
||||
emitline("(BP)\n");
|
||||
} else { if (isstrtype(c, fi.tnode)) {
|
||||
// str IS []u8: 3-word field
|
||||
// (ptr,len,cap) from cgexpr's
|
||||
// AX/BX/CX (#1/Phase 3).
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff((slot_off + 8 + fi.foff): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tBX, ");
|
||||
emitoff((slot_off + 8 + fi.foff + 8): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitoff((slot_off + 8 + fi.foff + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
} else {
|
||||
let sop: str = fieldstoreop(c, fi);
|
||||
emitline("\t");
|
||||
@@ -2601,7 +2613,9 @@ fn cgwidentaggedstorebp(c: *cgen, dst: *tinfo, src: *node, slot_off: i32, slot_s
|
||||
return;
|
||||
};
|
||||
};
|
||||
// Str payload.
|
||||
// str IS []u8: AX=ptr, BX=len, CX=cap from cgexpr. Slot layout
|
||||
// tag@+0, ptr@+8, len@+16, cap@+24 — same 32B shape as the slice
|
||||
// payload below (#1/Phase 3).
|
||||
if (nodeisstr(c, src)) {
|
||||
cgexpr(c, src);
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
@@ -2610,6 +2624,9 @@ fn cgwidentaggedstorebp(c: *cgen, dst: *tinfo, src: *node, slot_off: i32, slot_s
|
||||
emitline("\tMOVQ\tBX, ");
|
||||
emitoff((slot_off + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitoff((slot_off + 24): i64);
|
||||
emitline("(BP)\n");
|
||||
let tag: i32 = taggedvariantindext(c, dt, src);
|
||||
if (tag < 0) { tag = 0; };
|
||||
emitline("\tMOVQ\t$");
|
||||
@@ -2837,11 +2854,15 @@ export fn dotchainresolve(c: *cgen, n: *node,
|
||||
for (ft != nil && ft.kind == tykind.TY_NAMED) { ft = ft.under; };
|
||||
if (ft == nil) { return false; };
|
||||
if (ft.kind == tykind.TY_STR) {
|
||||
// str IS []u8: .cap is the third header word, same as
|
||||
// the TY_SLICE leaf below — cstage treats str≡slice for
|
||||
// .ptr/.len/.cap (cmd/w6c/cgen.c:2478) (#1/Phase 3, #11).
|
||||
if (i != 1) { return false; };
|
||||
let pseudo: str = stk[0].str;
|
||||
let delta: i32 = -1;
|
||||
if (streq(pseudo, "ptr")) { delta = 0; }
|
||||
else { if (streq(pseudo, "len")) { delta = 8; }; };
|
||||
else { if (streq(pseudo, "len")) { delta = 8; }
|
||||
else { if (streq(pseudo, "cap")) { delta = 16; }; }; };
|
||||
if (delta < 0) { return false; };
|
||||
*outtotaloff = *outtotaloff + foff;
|
||||
*outslicedelta = delta;
|
||||
@@ -3154,6 +3175,44 @@ fn cgstructlitfill(c: *cgen, si: *structinfo, lit: *node,
|
||||
fi = nil;
|
||||
} else if (callwhole) {
|
||||
fi = nil;
|
||||
} else if (isstrtype(c, fi.tnode)) {
|
||||
// str IS []u8: 3-word field (ptr,len,cap).
|
||||
// cgexpr leaves AX/BX/CX; for non-BP modes
|
||||
// the dst base goes in DX to dodge BX=len /
|
||||
// CX=cap (the generic store reloads BX, which
|
||||
// would clobber len) (#1/Phase 3).
|
||||
cgexpr(c, fieldnode.lhs);
|
||||
if (mode == 0) {
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff((disp + fi.foff): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tBX, ");
|
||||
emitoff((disp + fi.foff + 8): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitoff((disp + fi.foff + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
} else {
|
||||
if (mode == 1) {
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff(srcoff: i64);
|
||||
emitline("(BP), DX\n");
|
||||
} else {
|
||||
emitline("\tLEAQ\t");
|
||||
emitsymname(c, srcname);
|
||||
emitline("(SB), DX\n");
|
||||
};
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitdispreg((disp + fi.foff): i64, "DX");
|
||||
emitline("\n");
|
||||
emitline("\tMOVQ\tBX, ");
|
||||
emitdispreg((disp + fi.foff + 8): i64, "DX");
|
||||
emitline("\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitdispreg((disp + fi.foff + 16): i64, "DX");
|
||||
emitline("\n");
|
||||
};
|
||||
fi = nil;
|
||||
} else {
|
||||
cgexpr(c, fieldnode.lhs);
|
||||
// For non-BP modes, cgexpr just clobbered
|
||||
|
||||
@@ -714,7 +714,9 @@ fn primtypesize(nm: str) i64 = {
|
||||
if (streq(nm, "i32") || streq(nm, "u32") || streq(nm, "f32") || streq(nm, "rune")) { return 4i64; };
|
||||
if (streq(nm, "i64") || streq(nm, "u64") || streq(nm, "f64")) { return 8i64; };
|
||||
if (streq(nm, "int") || streq(nm, "uint") || streq(nm, "uintptr")) { return 8i64; };
|
||||
if (streq(nm, "str")) { return 16i64; }; // sizelint-ok: SSoT for ty_str primtype (#64)
|
||||
// str IS []u8: 24B, sourced from the slice header SSoT so str and
|
||||
// []u8 can never drift; no second hardcoded 24 (#1/Phase 3).
|
||||
if (streq(nm, "str")) { return tyslicesize(); };
|
||||
return -1i64;
|
||||
};
|
||||
|
||||
|
||||
@@ -6535,7 +6535,20 @@ export fn typesinit(c: *tctx) void = {
|
||||
c.tyuintptr= prim(tykind.TY_UINTPTR, "uintptr", 8u64, 8u64);
|
||||
c.tyf32 = prim(tykind.TY_F32, "f32", 4u64, 4u64);
|
||||
c.tyf64 = prim(tykind.TY_F64, "f64", 8u64, 8u64);
|
||||
c.tystr = prim(tykind.TY_STR, "str", 16u64, 8u64); // sizelint-ok: SSoT for tystr (#64)
|
||||
// str IS []u8: { *u8, len, cap } — 24B, 3-reg ABI (#1/Phase 3).
|
||||
// Size sourced from a u8-slice's size (typeslice SSoT) so str and
|
||||
// []u8 can never drift; no second hardcoded 24. Mirrors cstage
|
||||
// type.c `type_slice(a, ty_u8)->size`.
|
||||
//
|
||||
// The slice tinfo MUST land in a local first: the inline form
|
||||
// `typeslice(c.tyu8).size` triggers a cgen bug — `call().field`
|
||||
// where the call returns a *pointer* emits no deref (it uses the
|
||||
// returned pointer AS the field value), so tystr.size would become
|
||||
// a heap address → runaway slot-size loops. Filed as task #6
|
||||
// (cstage cgen.c N_DOT base=N_CALL-returning-pointer + wwstage
|
||||
// cgdot mirror); retained here as a local until that lands.
|
||||
let u8slice: *tinfo = typeslice(c.tyu8);
|
||||
c.tystr = prim(tykind.TY_STR, "str", u8slice.size, 8u64);
|
||||
c.tyerr = prim(tykind.TY_ERR, "<err>", 0u64, 1u64);
|
||||
c.tynever = prim(tykind.TY_NEVER, "never", 0u64, 1u64);
|
||||
|
||||
@@ -7811,7 +7824,9 @@ fn primtypesize(nm: str) i64 = {
|
||||
if (streq(nm, "i32") || streq(nm, "u32") || streq(nm, "f32") || streq(nm, "rune")) { return 4i64; };
|
||||
if (streq(nm, "i64") || streq(nm, "u64") || streq(nm, "f64")) { return 8i64; };
|
||||
if (streq(nm, "int") || streq(nm, "uint") || streq(nm, "uintptr")) { return 8i64; };
|
||||
if (streq(nm, "str")) { return 16i64; }; // sizelint-ok: SSoT for ty_str primtype (#64)
|
||||
// str IS []u8: 24B, sourced from the slice header SSoT so str and
|
||||
// []u8 can never drift; no second hardcoded 24 (#1/Phase 3).
|
||||
if (streq(nm, "str")) { return tyslicesize(); };
|
||||
return -1i64;
|
||||
};
|
||||
|
||||
@@ -10794,8 +10809,11 @@ fn pushargsrev(c: *cgen, arg: *node, param: *node) i32 = {
|
||||
emitline(", AX\n");
|
||||
emitline("\tPUSHQ\tAX\n");
|
||||
} else { if (nodeisstr(c, arg)) {
|
||||
// slot 24: [+0]=tag,[+8]=ptr,[+16]=len. Push high→low
|
||||
// so pop drains tag first into arg-reg[0].
|
||||
// str IS []u8: slot 32 [+0]=tag,[+8]=ptr,[+16]=len,
|
||||
// [+24]=cap — same shape as the slice arm above. Push
|
||||
// cap, len, ptr, tag high→low so pop drains tag first
|
||||
// into arg-reg[0] (#1/Phase 3).
|
||||
emitline("\tPUSHQ\tCX\n");
|
||||
emitline("\tPUSHQ\tBX\n");
|
||||
emitline("\tPUSHQ\tAX\n");
|
||||
emitline("\tMOVQ\t$");
|
||||
@@ -11013,9 +11031,12 @@ fn pushargsrev(c: *cgen, arg: *node, param: *node) i32 = {
|
||||
return rest + 3;
|
||||
};
|
||||
if (nodeisstr(c, arg)) {
|
||||
// str IS []u8: cgexpr left (AX=ptr, BX=len, CX=cap). Push
|
||||
// the triple, same as the slice arm above (#1/Phase 3).
|
||||
emitline("\tPUSHQ\tCX\n");
|
||||
emitline("\tPUSHQ\tBX\n");
|
||||
emitline("\tPUSHQ\tAX\n");
|
||||
return rest + 2;
|
||||
return rest + 3;
|
||||
};
|
||||
// #21: CALL returning a tagged-union — the aistagged guard
|
||||
// above kept us out of the widening path. Push the tagged-
|
||||
@@ -12865,7 +12886,7 @@ fn cgloadtaggedfield(c: *cgen, basereg: str, foff: i32, slot_sz: i32) void = {
|
||||
// would need a reversed direction we don't currently emit).
|
||||
// - struct src (literal or ident): zero slot, write fields at +8+foff,
|
||||
// tag last.
|
||||
// - str src: tag@+0, ptr@+8, len@+16.
|
||||
// - str src: tag@+0, ptr@+8, len@+16, cap@+24 (str IS []u8, #1/Phase 3).
|
||||
// - scalar src: tag@+0, value@+8.
|
||||
fn cgwidentaggedstore(c: *cgen, dst: *tinfo, src: *node,
|
||||
basereg: str, slot_off: i32, slot_sz: i32) void = {
|
||||
@@ -13083,12 +13104,18 @@ fn cgwidentaggedstorebp(c: *cgen, dst: *tinfo, src: *node, slot_off: i32, slot_s
|
||||
emitoff((slot_off + 8 + fi.foff): i64);
|
||||
emitline("(BP)\n");
|
||||
} else { if (isstrtype(c, fi.tnode)) {
|
||||
// str IS []u8: 3-word field
|
||||
// (ptr,len,cap) from cgexpr's
|
||||
// AX/BX/CX (#1/Phase 3).
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff((slot_off + 8 + fi.foff): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tBX, ");
|
||||
emitoff((slot_off + 8 + fi.foff + 8): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitoff((slot_off + 8 + fi.foff + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
} else {
|
||||
let sop: str = fieldstoreop(c, fi);
|
||||
emitline("\t");
|
||||
@@ -13146,7 +13173,9 @@ fn cgwidentaggedstorebp(c: *cgen, dst: *tinfo, src: *node, slot_off: i32, slot_s
|
||||
return;
|
||||
};
|
||||
};
|
||||
// Str payload.
|
||||
// str IS []u8: AX=ptr, BX=len, CX=cap from cgexpr. Slot layout
|
||||
// tag@+0, ptr@+8, len@+16, cap@+24 — same 32B shape as the slice
|
||||
// payload below (#1/Phase 3).
|
||||
if (nodeisstr(c, src)) {
|
||||
cgexpr(c, src);
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
@@ -13155,6 +13184,9 @@ fn cgwidentaggedstorebp(c: *cgen, dst: *tinfo, src: *node, slot_off: i32, slot_s
|
||||
emitline("\tMOVQ\tBX, ");
|
||||
emitoff((slot_off + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitoff((slot_off + 24): i64);
|
||||
emitline("(BP)\n");
|
||||
let tag: i32 = taggedvariantindext(c, dt, src);
|
||||
if (tag < 0) { tag = 0; };
|
||||
emitline("\tMOVQ\t$");
|
||||
@@ -13382,11 +13414,15 @@ export fn dotchainresolve(c: *cgen, n: *node,
|
||||
for (ft != nil && ft.kind == tykind.TY_NAMED) { ft = ft.under; };
|
||||
if (ft == nil) { return false; };
|
||||
if (ft.kind == tykind.TY_STR) {
|
||||
// str IS []u8: .cap is the third header word, same as
|
||||
// the TY_SLICE leaf below — cstage treats str≡slice for
|
||||
// .ptr/.len/.cap (cmd/w6c/cgen.c:2478) (#1/Phase 3, #11).
|
||||
if (i != 1) { return false; };
|
||||
let pseudo: str = stk[0].str;
|
||||
let delta: i32 = -1;
|
||||
if (streq(pseudo, "ptr")) { delta = 0; }
|
||||
else { if (streq(pseudo, "len")) { delta = 8; }; };
|
||||
else { if (streq(pseudo, "len")) { delta = 8; }
|
||||
else { if (streq(pseudo, "cap")) { delta = 16; }; }; };
|
||||
if (delta < 0) { return false; };
|
||||
*outtotaloff = *outtotaloff + foff;
|
||||
*outslicedelta = delta;
|
||||
@@ -13699,6 +13735,44 @@ fn cgstructlitfill(c: *cgen, si: *structinfo, lit: *node,
|
||||
fi = nil;
|
||||
} else if (callwhole) {
|
||||
fi = nil;
|
||||
} else if (isstrtype(c, fi.tnode)) {
|
||||
// str IS []u8: 3-word field (ptr,len,cap).
|
||||
// cgexpr leaves AX/BX/CX; for non-BP modes
|
||||
// the dst base goes in DX to dodge BX=len /
|
||||
// CX=cap (the generic store reloads BX, which
|
||||
// would clobber len) (#1/Phase 3).
|
||||
cgexpr(c, fieldnode.lhs);
|
||||
if (mode == 0) {
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff((disp + fi.foff): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tBX, ");
|
||||
emitoff((disp + fi.foff + 8): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitoff((disp + fi.foff + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
} else {
|
||||
if (mode == 1) {
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff(srcoff: i64);
|
||||
emitline("(BP), DX\n");
|
||||
} else {
|
||||
emitline("\tLEAQ\t");
|
||||
emitsymname(c, srcname);
|
||||
emitline("(SB), DX\n");
|
||||
};
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitdispreg((disp + fi.foff): i64, "DX");
|
||||
emitline("\n");
|
||||
emitline("\tMOVQ\tBX, ");
|
||||
emitdispreg((disp + fi.foff + 8): i64, "DX");
|
||||
emitline("\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitdispreg((disp + fi.foff + 16): i64, "DX");
|
||||
emitline("\n");
|
||||
};
|
||||
fi = nil;
|
||||
} else {
|
||||
cgexpr(c, fieldnode.lhs);
|
||||
// For non-BP modes, cgexpr just clobbered
|
||||
@@ -13956,7 +14030,11 @@ fn cgtryprop(c: *cgen, n: *node) void = {
|
||||
};
|
||||
};
|
||||
if (succisstr) {
|
||||
// str IS []u8: success arrives DX=ptr, CX=len, R8=cap
|
||||
// (slot 32B). Move len out before cap overwrites CX
|
||||
// (#1/Phase 3).
|
||||
emitline("\tMOVQ\tCX, BX\n");
|
||||
emitline("\tMOVQ\tR8, CX\n");
|
||||
};
|
||||
emitline("\tMOVQ\tDX, AX\n");
|
||||
return;
|
||||
@@ -14012,7 +14090,11 @@ fn cgtryunw(c: *cgen, n: *node) void = {
|
||||
};
|
||||
};
|
||||
if (succisstr) {
|
||||
// str IS []u8: success arrives DX=ptr, CX=len, R8=cap
|
||||
// (slot 32B). Move len out before cap overwrites CX
|
||||
// (#1/Phase 3).
|
||||
emitline("\tMOVQ\tCX, BX\n");
|
||||
emitline("\tMOVQ\tR8, CX\n");
|
||||
};
|
||||
emitline("\tMOVQ\tDX, AX\n");
|
||||
return;
|
||||
@@ -14285,8 +14367,9 @@ fn cgcast(c: *cgen, n: *node) void = {
|
||||
};
|
||||
|
||||
fn cgstrlit(c: *cgen, n: *node) void = {
|
||||
// Result is the (ptr, len) pair: ptr in AX, len in BX. Call
|
||||
// sites that expect a str arg pick these up directly.
|
||||
// str IS []u8: the (ptr, len, cap) triple — ptr in AX, len in BX,
|
||||
// cap in CX. A static literal has no spare storage, so cap = len
|
||||
// (#1/Phase 3). Call sites that expect a str arg pick these up.
|
||||
let nstr: str = n.str;
|
||||
let lab: str = internstrlit(c, nstr);
|
||||
emitline("\tLEAQ\t");
|
||||
@@ -14295,6 +14378,9 @@ fn cgstrlit(c: *cgen, n: *node) void = {
|
||||
emitline("\tMOVQ\t$");
|
||||
emitint(nstr.len: i64);
|
||||
emitline(", BX\n");
|
||||
emitline("\tMOVQ\t$");
|
||||
emitint(nstr.len: i64);
|
||||
emitline(", CX\n");
|
||||
return;
|
||||
};
|
||||
|
||||
@@ -14330,9 +14416,14 @@ fn cgident(c: *cgen, n: *node) void = {
|
||||
emitoff(off: i64);
|
||||
emitline("(BP), AX\n");
|
||||
if (isstr) {
|
||||
// str IS []u8: load (ptr,len,cap) into AX/BX/CX,
|
||||
// identical to the slice arm below (#1/Phase 3).
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff((off + 8): i64);
|
||||
emitline("(BP), BX\n");
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff((off + 16): i64);
|
||||
emitline("(BP), CX\n");
|
||||
};
|
||||
if (issl) {
|
||||
emitline("\tMOVQ\t");
|
||||
@@ -14362,6 +14453,11 @@ fn cgident(c: *cgen, n: *node) void = {
|
||||
emitline("\tMOVQ\t$");
|
||||
emitint(bytes.len: i64);
|
||||
emitline(", BX\n");
|
||||
// str IS []u8: cap = len for a static def literal
|
||||
// (#1/Phase 3).
|
||||
emitline("\tMOVQ\t$");
|
||||
emitint(bytes.len: i64);
|
||||
emitline(", CX\n");
|
||||
return;
|
||||
};
|
||||
};
|
||||
@@ -14393,17 +14489,16 @@ fn cgident(c: *cgen, n: *node) void = {
|
||||
let isstr: bool = letvarisstr(c, nm);
|
||||
let issl: bool = letvarisslice(c, nm);
|
||||
if (isstr || issl) {
|
||||
// str IS []u8: both str and slice carry a third 8B
|
||||
// (cap); load it unconditionally. The address holder CX
|
||||
// is overwritten by the cap as the last step, after
|
||||
// ptr/len are already loaded (#1/Phase 3).
|
||||
emitline("\tLEAQ\t");
|
||||
emitsymname(c, nm);
|
||||
emitline("(SB), CX\n");
|
||||
emitline("\tMOVQ\t(CX), AX\n");
|
||||
emitline("\tMOVQ\t8(CX), BX\n");
|
||||
if (issl) {
|
||||
// Overwrites the address holder with the
|
||||
// cap as the last step — CX is no longer
|
||||
// needed once both ptr/len are loaded.
|
||||
emitline("\tMOVQ\t16(CX), CX\n");
|
||||
};
|
||||
emitline("\tMOVQ\t16(CX), CX\n");
|
||||
return;
|
||||
};
|
||||
// Float global: same LEAQ-indirect shape, since MOVSS/
|
||||
@@ -14457,6 +14552,12 @@ fn cgindex(c: *cgen, n: *node) void = {
|
||||
let idx: *node = n.rhs;
|
||||
let esz: i32 = 8;
|
||||
let signed_elem: bool = false;
|
||||
// #1/Phase 3: str=24B collides with slice=24B, so the str-element
|
||||
// branches below MUST gate on kind (mirroring cstage's elem_is_str),
|
||||
// not a bare `esz == primtypesize("str")` size check — otherwise a
|
||||
// []u8 element (also 24B) misfires into the str 2-word load and
|
||||
// diverges from cstage (#60 collision class; sentinel 754).
|
||||
let elemisstr: bool = false;
|
||||
let baselocal: *local = nil;
|
||||
// Global `[N]T` array or `*T` pointer used as an index base.
|
||||
// The local-ident lookup above misses it; we need LEAQ name(SB)
|
||||
@@ -14498,7 +14599,7 @@ fn cgindex(c: *cgen, n: *node) void = {
|
||||
// cgen.c:3517-18). esz-only — N_DOT-base signedness
|
||||
// stays unset, as before.
|
||||
let dt: *tinfo = n.type_: *tinfo;
|
||||
if (dt != nil) { esz = dt.size: i32; };
|
||||
if (dt != nil) { esz = dt.size: i32; elemisstr = typeisstr(dt); };
|
||||
} else { if (base.kind == nkind.N_INDEX) {
|
||||
// #60: chained `names[i][k]` — n.type_ is the checker-
|
||||
// stamped outer element tinfo (indexresult over the inner
|
||||
@@ -14547,6 +14648,7 @@ fn cgindex(c: *cgen, n: *node) void = {
|
||||
esz = elem_slot_sz;
|
||||
};
|
||||
};
|
||||
elemisstr = isstrtype(c, etn);
|
||||
};
|
||||
};
|
||||
cgexpr(c, idx);
|
||||
@@ -14582,7 +14684,7 @@ fn cgindex(c: *cgen, n: *node) void = {
|
||||
};
|
||||
// #43: str element-stride routes through primtypesize so the
|
||||
// 16-vs-24 dispatch tracks ty_str.size for #1.
|
||||
if (esz == primtypesize("str"): i32) {
|
||||
if (elemisstr) {
|
||||
emitline("\tMOVQ\t8(BX), CX\n");
|
||||
emitline("\tMOVQ\t(BX), AX\n");
|
||||
emitline("\tMOVQ\tCX, BX\n");
|
||||
@@ -14624,7 +14726,7 @@ fn cgindex(c: *cgen, n: *node) void = {
|
||||
// str element (16B today): load (ptr, len) into (AX, BX) so
|
||||
// the value flows through the str-rhs convention.
|
||||
// #43: route via primtypesize so the stride tracks #1.
|
||||
if (esz == primtypesize("str"): i32) {
|
||||
if (elemisstr) {
|
||||
emitline("\tMOVQ\t8(BX), CX\n");
|
||||
emitline("\tMOVQ\t(BX), AX\n");
|
||||
emitline("\tMOVQ\tCX, BX\n");
|
||||
@@ -14656,7 +14758,7 @@ fn cgindex(c: *cgen, n: *node) void = {
|
||||
};
|
||||
// #43: str element-stride routes through primtypesize so the
|
||||
// 16-vs-24 dispatch tracks ty_str.size for #1.
|
||||
if (esz == primtypesize("str"): i32) {
|
||||
if (elemisstr) {
|
||||
emitline("\tMOVQ\t8(AX), BX\n");
|
||||
emitline("\tMOVQ\t(AX), AX\n");
|
||||
return;
|
||||
@@ -15251,10 +15353,11 @@ fn cgdot(c: *cgen, n: *node) void = {
|
||||
};
|
||||
// Hare-style tuple positional access: `t.0`, `t.1`.
|
||||
// Walk the tuple element type list summing slotsize
|
||||
// (matches the (scalar, str) init layout which puts
|
||||
// the scalar in an 8B slot and the str in 16B). For
|
||||
// a str element, load both halves into (AX, BX) so
|
||||
// chains like `t.1.len` propagate correctly.
|
||||
// (matches the (scalar, str) init layout: scalar in an
|
||||
// 8B slot, str in 24B — str IS []u8, #1/Phase 3). For a
|
||||
// str element, load (ptr, len) into (AX, BX); the cap
|
||||
// stays in the slot (the 2-word str-field read, like
|
||||
// every other chained/dot str leaf read — task #14).
|
||||
if (lkind == nkind.N_TTUPLE) {
|
||||
let idx: i32 = fldnumidx(fld);
|
||||
if (idx >= 0) {
|
||||
@@ -15369,9 +15472,9 @@ fn cgdot(c: *cgen, n: *node) void = {
|
||||
let delta: i32 = -1;
|
||||
if (streq(fld, "ptr")) { delta = 0; };
|
||||
if (streq(fld, "len")) { delta = 8; };
|
||||
if (issl) {
|
||||
if (streq(fld, "cap")) { delta = 16; };
|
||||
};
|
||||
// str IS []u8: .cap is valid on a str global too,
|
||||
// not slice-only — mirrors cstage (#1/Phase 3, #11).
|
||||
if (streq(fld, "cap")) { delta = 16; };
|
||||
if (delta >= 0) {
|
||||
emitline("\tLEAQ\t");
|
||||
emitsymname(c, lhs.str);
|
||||
@@ -16227,7 +16330,9 @@ fn cgun(c: *cgen, n: *node) void = {
|
||||
let gdelta: i32 = -1;
|
||||
if (streq(fld, "ptr")) { gdelta = 0; };
|
||||
if (streq(fld, "len")) { gdelta = 8; };
|
||||
if (issl) { if (streq(fld, "cap")) { gdelta = 16; }; };
|
||||
// str IS []u8: &str.cap is valid too, not slice-only
|
||||
// — mirrors cstage (#1/Phase 3, #11).
|
||||
if (streq(fld, "cap")) { gdelta = 16; };
|
||||
if (gdelta >= 0) {
|
||||
emitline("\tLEAQ\t");
|
||||
emitsymname(c, basenm);
|
||||
@@ -16599,16 +16704,19 @@ fn cgalloc(c: *cgen, n: *node) void = {
|
||||
emitline("\n");
|
||||
fi = nil;
|
||||
} else { if (isstrtype(c, fi.tnode)) {
|
||||
// alloc(T{ fval = s }) for str field: cgexpr
|
||||
// leaves (AX=ptr, BX=len). Use CX for the heap
|
||||
// base so BX=len survives both stores. Mirrors
|
||||
// cmd/w6c/cgen.c:4184-4190.
|
||||
emitline("\tMOVQ\t(SP), CX\n");
|
||||
// str IS []u8: cgexpr leaves (AX=ptr,
|
||||
// BX=len, CX=cap). Route the heap base
|
||||
// through DX so all three survive — CX
|
||||
// holds cap, BX holds len (#1/Phase 3).
|
||||
emitline("\tMOVQ\t(SP), DX\n");
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitdispreg(fi.foff: i64, "CX");
|
||||
emitdispreg(fi.foff: i64, "DX");
|
||||
emitline("\n");
|
||||
emitline("\tMOVQ\tBX, ");
|
||||
emitdispreg((fi.foff + 8): i64, "CX");
|
||||
emitdispreg((fi.foff + 8): i64, "DX");
|
||||
emitline("\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitdispreg((fi.foff + 16): i64, "DX");
|
||||
emitline("\n");
|
||||
fi = nil;
|
||||
} else {
|
||||
@@ -17068,7 +17176,8 @@ fn cgcall(c: *cgen, n: *node) void = {
|
||||
popped += 1;
|
||||
} else {
|
||||
let extra: i32 = 0;
|
||||
if (nodeisstr(c, a)) { extra = 1; };
|
||||
// str IS []u8: 3-word arg, same as slice (#1/Phase 3).
|
||||
if (nodeisstr(c, a)) { extra = 2; };
|
||||
if (nodeisslice(c, a)) { extra = 2; };
|
||||
// #21: tagged-CALL arg was pushed AX/DX/CX/R8 high→low
|
||||
// by pushargsrev; size the per-arg pop to match so the
|
||||
@@ -17238,31 +17347,9 @@ fn cgcall(c: *cgen, n: *node) void = {
|
||||
emitint((stackslots * 8): i64);
|
||||
emitline(", SP\n");
|
||||
};
|
||||
// SysV returns 16-byte aggregates in (AX, DX). Our str
|
||||
// convention is (AX, BX), so shuffle for str-returning calls.
|
||||
// Route through fnretlookupmod: for N_DOT cross-module callees,
|
||||
// the bare-leaf fnretlookup's same-module-first walk (#4e) would
|
||||
// pick the caller-module's same-leaf fn — a str-returning
|
||||
// caller-side `slice` over a []u8-returning `mod.slice` then
|
||||
// emits a phantom MOVQ DX, BX after the cross-module CALL (#34).
|
||||
if (calleename.len > 0) {
|
||||
let cmod: str;
|
||||
cmod.ptr = nil; cmod.len = 0;
|
||||
if (callee != nil) {
|
||||
if (callee.kind == nkind.N_IDENT) { cmod = c.curmod; };
|
||||
if (callee.kind == nkind.N_DOT) {
|
||||
if (callee.lhs != nil) {
|
||||
if (callee.lhs.kind == nkind.N_IDENT) {
|
||||
cmod = callee.lhs.str;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
let rtyp: *node = fnretlookupmod(c, calleename, cmod);
|
||||
if (isstrtype(c, rtyp)) {
|
||||
emitline("\tMOVQ\tDX, BX\n");
|
||||
};
|
||||
};
|
||||
// str IS []u8: a str-returning callee leaves AX=ptr, BX=len,
|
||||
// CX=cap — same as a slice, so there is no receive-side shuffle
|
||||
// (#1/Phase 3).
|
||||
return;
|
||||
};
|
||||
|
||||
@@ -17361,17 +17448,21 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
emitline("\tX0, (BX)\n");
|
||||
return;
|
||||
};
|
||||
// Push order matches C cgen
|
||||
// (cmd/w6c/cgen.c:1033-1041): PUSHQ AX
|
||||
// (ptr) first, then PUSHQ BX (len) if
|
||||
// str, so the pop sequence is POP CX
|
||||
// (len) → POP AX (ptr) → MOVQ AX,
|
||||
// (BX) → MOVQ CX, 8(BX).
|
||||
// str IS []u8: PUSHQ AX (ptr) first, then
|
||||
// PUSHQ BX (len) + PUSHQ CX (cap) across the
|
||||
// pointer eval which clobbers BX/CX. Pop drains
|
||||
// cap (top) → 16(BX), then len, then ptr → 0(BX)
|
||||
// with len → 8(BX) (#1/Phase 3).
|
||||
emitline("\tPUSHQ\tAX\n");
|
||||
if (elemstr) { emitline("\tPUSHQ\tBX\n"); };
|
||||
if (elemstr) {
|
||||
emitline("\tPUSHQ\tBX\n");
|
||||
emitline("\tPUSHQ\tCX\n");
|
||||
};
|
||||
cgexpr(c, inner);
|
||||
emitline("\tMOVQ\tAX, BX\n");
|
||||
if (elemstr) {
|
||||
emitline("\tPOPQ\tCX\n");
|
||||
emitline("\tMOVQ\tCX, 16(BX)\n");
|
||||
emitline("\tPOPQ\tCX\n");
|
||||
emitline("\tPOPQ\tAX\n");
|
||||
emitline("\tMOVQ\tAX, (BX)\n");
|
||||
@@ -17625,10 +17716,19 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
};
|
||||
};
|
||||
cgexpr(c, n.rhs); // value → AX
|
||||
// #43: spill BX (str.len) before computing
|
||||
// the index so the post-index store can pop
|
||||
// it; the stride gate tracks ty_str.size.
|
||||
if (esz == primtypesize("str"): i32) { emitline("\tPUSHQ\tBX\n"); };
|
||||
// str IS []u8: spill cap (CX) + len (BX) before
|
||||
// computing the index so the post-index store can
|
||||
// pop all three. #1/Phase 3: str=24B collides with
|
||||
// slice=24B, so this MUST gate on kind (cstage's
|
||||
// elem_is_str, cmd/w6c/cgen.c:3576) — not a bare
|
||||
// `esz == primtypesize("str")` — or a []u8 element
|
||||
// (also 24B) misfires the str 3-word store and
|
||||
// diverges from cstage. Write-side mirror of the
|
||||
// cgindex read-path gate (#7/754).
|
||||
if (isstrtype(c, elemtn)) {
|
||||
emitline("\tPUSHQ\tCX\n");
|
||||
emitline("\tPUSHQ\tBX\n");
|
||||
};
|
||||
emitline("\tPUSHQ\tAX\n");
|
||||
cgexpr(c, idx); // idx → AX
|
||||
if (esz > 1) {
|
||||
@@ -17666,13 +17766,15 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
emitline("\tPOPQ\tAX\n"); // scaled idx
|
||||
emitline("\tADDQ\tAX, BX\n");
|
||||
emitline("\tPOPQ\tAX\n"); // value
|
||||
// #43: str-element write — pop the saved
|
||||
// .len and store both halves. Stride gate
|
||||
// routes through primtypesize for #1.
|
||||
if (esz == primtypesize("str"): i32) {
|
||||
// str IS []u8: pop the saved len + cap and store
|
||||
// all three words. Kind-gate, not size — see the
|
||||
// spill site above (#1/Phase 3, #7/754).
|
||||
if (isstrtype(c, elemtn)) {
|
||||
emitline("\tMOVQ\tAX, (BX)\n");
|
||||
emitline("\tPOPQ\tCX\n");
|
||||
emitline("\tMOVQ\tCX, 8(BX)\n");
|
||||
emitline("\tPOPQ\tCX\n");
|
||||
emitline("\tMOVQ\tCX, 16(BX)\n");
|
||||
return;
|
||||
};
|
||||
let isop: str = tnodestoreop(c, elemtn, esz);
|
||||
@@ -18099,20 +18201,24 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
emitline("\tMOVQ\tBX, AX\n");
|
||||
};
|
||||
};
|
||||
// str field via *struct: rhs left
|
||||
// (AX=ptr, BX=len). Use CX as the
|
||||
// address scratch so we don't clobber
|
||||
// the len half before storing it.
|
||||
// str IS []u8: rhs left (AX=ptr,
|
||||
// BX=len, CX=cap). CX holds cap, so
|
||||
// stage the struct addr in DX and
|
||||
// store all three words — identical
|
||||
// to the slice arm below (#1/Phase 3).
|
||||
if (n.op == tkind.TK_ASSIGN) {
|
||||
if (isstrtype(c, fi.tnode)) {
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff(lc.off: i64);
|
||||
emitline("(BP), CX\n");
|
||||
emitline("(BP), DX\n");
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitdispreg(fi.foff: i64, "CX");
|
||||
emitdispreg(fi.foff: i64, "DX");
|
||||
emitline("\n");
|
||||
emitline("\tMOVQ\tBX, ");
|
||||
emitdispreg((fi.foff + 8): i64, "CX");
|
||||
emitdispreg((fi.foff + 8): i64, "DX");
|
||||
emitline("\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitdispreg((fi.foff + 16): i64, "DX");
|
||||
emitline("\n");
|
||||
return;
|
||||
};
|
||||
@@ -18303,11 +18409,11 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
};};
|
||||
};
|
||||
cgexpr(c, n.rhs);
|
||||
// str field: cgexpr left (AX=ptr, BX=len);
|
||||
// store both halves at +0/+8. Without this,
|
||||
// `L.src = s` would only write the ptr and
|
||||
// `L.src.len` would carry whatever was on the
|
||||
// stack.
|
||||
// str IS []u8: cgexpr left (AX=ptr,
|
||||
// BX=len, CX=cap); store all three at
|
||||
// +0/+8/+16, identical to the slice
|
||||
// arm below. BP base, no scratch
|
||||
// reload needed (#1/Phase 3).
|
||||
if (isstrtype(c, fi.tnode)) {
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff((lc.off + fi.foff): i64);
|
||||
@@ -18315,6 +18421,9 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
emitline("\tMOVQ\tBX, ");
|
||||
emitoff((lc.off + fi.foff + 8): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitoff((lc.off + fi.foff + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
return;
|
||||
};
|
||||
// slice field direct: cgexpr left
|
||||
@@ -18562,14 +18671,22 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
if (n.op == tkind.TK_ASSIGN) {
|
||||
cgexpr(c, n.rhs);
|
||||
if (isstrtype(c, fi.tnode)) {
|
||||
// str IS []u8: cgexpr left
|
||||
// (AX=ptr, BX=len, CX=cap). CX
|
||||
// holds cap, so stage the base
|
||||
// addr in DX and store all three
|
||||
// words (#1/Phase 3).
|
||||
emitline("\tLEAQ\t");
|
||||
emitsymname(c, bn);
|
||||
emitline("(SB), CX\n");
|
||||
emitline("(SB), DX\n");
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitdispreg(fi.foff: i64, "CX");
|
||||
emitdispreg(fi.foff: i64, "DX");
|
||||
emitline("\n");
|
||||
emitline("\tMOVQ\tBX, ");
|
||||
emitdispreg((fi.foff + 8): i64, "CX");
|
||||
emitdispreg((fi.foff + 8): i64, "DX");
|
||||
emitline("\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitdispreg((fi.foff + 16): i64, "DX");
|
||||
emitline("\n");
|
||||
return;
|
||||
};
|
||||
@@ -18808,22 +18925,29 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
return;
|
||||
};
|
||||
if (typeisstr(leaftype)) {
|
||||
// str IS []u8: store ptr/len/cap. cgexpr leaves
|
||||
// CX=cap, so the viacx base goes in DX (not CX) to
|
||||
// avoid clobbering it — same as the single-dot str
|
||||
// field store (#1/Phase 3).
|
||||
cgexpr(c, n.rhs);
|
||||
if (viacx) {
|
||||
if (ptrroot) {
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff(rootoff: i64);
|
||||
emitline("(BP), CX\n");
|
||||
emitline("(BP), DX\n");
|
||||
} else {
|
||||
emitline("\tLEAQ\t");
|
||||
emitsymname(c, rootname);
|
||||
emitline("(SB), CX\n");
|
||||
emitline("(SB), DX\n");
|
||||
};
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitdispreg(totaloff: i64, "CX");
|
||||
emitdispreg(totaloff: i64, "DX");
|
||||
emitline("\n");
|
||||
emitline("\tMOVQ\tBX, ");
|
||||
emitdispreg((totaloff + 8): i64, "CX");
|
||||
emitdispreg((totaloff + 8): i64, "DX");
|
||||
emitline("\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitdispreg((totaloff + 16): i64, "DX");
|
||||
emitline("\n");
|
||||
} else {
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
@@ -18832,6 +18956,9 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
emitline("\tMOVQ\tBX, ");
|
||||
emitoff((rootoff + totaloff + 8): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitoff((rootoff + totaloff + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
};
|
||||
return;
|
||||
};
|
||||
@@ -19319,11 +19446,17 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
cgexpr(c, n.rhs);
|
||||
if (n.op == tkind.TK_ASSIGN) {
|
||||
if (letvarisstr(c, nm)) {
|
||||
// str IS []u8: stash cap in DI before LEAQ
|
||||
// overwrites CX, then store ptr/len/cap —
|
||||
// identical to the slice arm below
|
||||
// (#1/Phase 3).
|
||||
emitline("\tMOVQ\tCX, DI\n");
|
||||
emitline("\tLEAQ\t");
|
||||
emitsymname(c, nm);
|
||||
emitline("(SB), CX\n");
|
||||
emitline("\tMOVQ\tAX, (CX)\n");
|
||||
emitline("\tMOVQ\tBX, 8(CX)\n");
|
||||
emitline("\tMOVQ\tDI, 16(CX)\n");
|
||||
return;
|
||||
};
|
||||
if (letvarisslice(c, nm)) {
|
||||
@@ -19609,7 +19742,9 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
emitoff((off + 8): i64);
|
||||
emitline("(BP)\n");
|
||||
};
|
||||
if (lcsl) {
|
||||
// str IS []u8: store the cap word too, identical to
|
||||
// the slice store (#1/Phase 3).
|
||||
if (lcstr || lcsl) {
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitoff((off + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
@@ -19812,12 +19947,16 @@ fn cgreturn(c: *cgen, n: *node) void = {
|
||||
rundefers(c);
|
||||
let rhs: *node = n.lhs;
|
||||
if (rhs != nil) {
|
||||
// Tuple return `return a, b;`:
|
||||
// Tuple return `return a, b;`, word-indexed AX→DX→CX→R8 (the
|
||||
// SAME register sequence as the tagged-union return below; the
|
||||
// tuple just fills it positionally):
|
||||
// (scalar, scalar) — AX = v0, DX = v1.
|
||||
// (scalar, str) / (str, scalar) — AX = scalar elem,
|
||||
// DX = str.ptr, CX = str.len.
|
||||
// 24B convention mirrors the tagged-union return below; receive
|
||||
// sites destructure off the same regs regardless of position.
|
||||
// DX = str.ptr, CX = str.len, R8 = str.cap.
|
||||
// str IS []u8 (24B) → 32B tuple; cap rides R8, matching the
|
||||
// tagged-union return that already uses R8 for slot+24
|
||||
// (#1/Phase 3, task #5). Receive sites destructure off the
|
||||
// same regs regardless of position.
|
||||
if (rhs.kind == nkind.N_TUPLE) {
|
||||
let v: *node = rhs.list;
|
||||
if (v != nil) {
|
||||
@@ -19832,6 +19971,7 @@ fn cgreturn(c: *cgen, n: *node) void = {
|
||||
cgexpr(c, scaln);
|
||||
emitline("\tPUSHQ\tAX\n");
|
||||
cgexpr(c, strn);
|
||||
emitline("\tMOVQ\tCX, R8\n");
|
||||
emitline("\tMOVQ\tBX, CX\n");
|
||||
emitline("\tMOVQ\tAX, DX\n");
|
||||
emitline("\tPOPQ\tAX\n");
|
||||
@@ -19984,12 +20124,12 @@ fn cgreturn(c: *cgen, n: *node) void = {
|
||||
emitline("\tMOVQ\tBX, CX\n");
|
||||
emitline("\tMOVQ\tAX, DX\n");
|
||||
} else { if (nodeisstr(c, rhs)) {
|
||||
// str IS []u8: cgexpr leaves (AX=ptr, BX=len,
|
||||
// CX=cap). Same shuffle as the slice arm above —
|
||||
// DX=ptr, CX=len, R8=cap (#1/Phase 3).
|
||||
emitline("\tMOVQ\tCX, R8\n");
|
||||
emitline("\tMOVQ\tBX, CX\n");
|
||||
emitline("\tMOVQ\tAX, DX\n");
|
||||
// str fills DX,CX. Zero R8 if dst covers slot+24.
|
||||
if (rsz > 24) {
|
||||
emitline("\tMOVQ\t$0, R8\n");
|
||||
};
|
||||
} else {
|
||||
emitline("\tMOVQ\tAX, DX\n");
|
||||
// scalar fills DX only. Zero CX / R8 if dst
|
||||
@@ -20245,11 +20385,8 @@ fn cgreturn(c: *cgen, n: *node) void = {
|
||||
};
|
||||
emitline("\tMOVQ\t$0, AX\n");
|
||||
};
|
||||
// SysV: 16-byte aggregates (str, 2-tuple) return in (AX, DX).
|
||||
// cgexpr leaves str in (AX, BX); shuffle BX→DX.
|
||||
if (isstrtype(c, c.fnret)) {
|
||||
emitline("\tMOVQ\tBX, DX\n");
|
||||
};
|
||||
// str IS []u8: cgexpr leaves AX=ptr, BX=len, CX=cap — str now
|
||||
// returns exactly like a slice, no AX:DX shuffle (#1/Phase 3).
|
||||
emitline("\tMOVQ\tBP, SP\n");
|
||||
emitline("\tPOPQ\tBP\n");
|
||||
emitline("\tRET\n");
|
||||
@@ -20420,11 +20557,13 @@ fn cglet(c: *cgen, n: *node) void = {
|
||||
c.lastwasreturn = 0;
|
||||
return;
|
||||
};
|
||||
// 24B tuple init for `let t: (scalar, str) = call()` /
|
||||
// `let t: (str, scalar) = call()`. Per the AX:DX:CX return
|
||||
// convention: AX = scalar elem, DX = str.ptr, CX = str.len.
|
||||
// Layout is positional, so we route each register to the
|
||||
// slot dictated by element type, not by AX/DX position.
|
||||
// 32B tuple init for `let t: (scalar, str) = call()` /
|
||||
// `let t: (str, scalar) = call()`. Per the AX:DX:CX:R8 return
|
||||
// convention: AX = scalar elem, DX = str.ptr, CX = str.len,
|
||||
// R8 = str.cap. Layout is positional (str takes 24B at its
|
||||
// position), so we route each register to the slot dictated by
|
||||
// element type, not by AX/DX position. str IS []u8 (24B) → 32B
|
||||
// tuple (#1/Phase 3, task #5).
|
||||
if (n.lhs != nil) {
|
||||
if (n.lhs.kind == nkind.N_TTUPLE) {
|
||||
let p0: *node = n.lhs.list;
|
||||
@@ -20447,9 +20586,12 @@ fn cglet(c: *cgen, n: *node) void = {
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitoff((off + 8): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitline("\tMOVQ\tR8, ");
|
||||
emitoff((off + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff((off + 24): i64);
|
||||
emitline("(BP)\n");
|
||||
} else {
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff(off: i64);
|
||||
@@ -20460,6 +20602,9 @@ fn cglet(c: *cgen, n: *node) void = {
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitoff((off + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tR8, ");
|
||||
emitoff((off + 24): i64);
|
||||
emitline("(BP)\n");
|
||||
};
|
||||
c.lastwasreturn = 0;
|
||||
return;
|
||||
@@ -20750,15 +20895,19 @@ fn cglet(c: *cgen, n: *node) void = {
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff(off: i64);
|
||||
emitline("(BP)\n");
|
||||
// str init: cgexpr also leaves len in BX; store both.
|
||||
// str IS []u8: cgexpr leaves (ptr,len,cap) in AX/BX/CX; store
|
||||
// all three, same as the slice arm below (#1/Phase 3).
|
||||
// #60: gate by kind too — under #1's str=24 bump, sizeof(str)
|
||||
// and sizeof(slice) collide, so a bare `sz ==` check fires
|
||||
// both branches for one let. Mirrors cstage cgen.c:6439's
|
||||
// both branches for one let. Mirrors cstage cgen.c's
|
||||
// `type_isstr(lt) && sz == ty_str->size` shape.
|
||||
if (isstrtype(c, tn) && sz == primtypesize("str"): i32) {
|
||||
emitline("\tMOVQ\tBX, ");
|
||||
emitoff((off + 8): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitoff((off + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
};
|
||||
// slice init: ptr/len/cap in AX/BX/CX. Same kind+size gate as
|
||||
// the str arm — without the kind check this fires on a str let
|
||||
@@ -20919,11 +21068,12 @@ fn cgmassign(c: *cgen, n: *node) void = {
|
||||
// type is taken from its explicit annotation (l.lhs) when present
|
||||
// or inferred from the called fn's return-type tuple element.
|
||||
//
|
||||
// Per the AX:DX:CX return convention (mirrors C cgen nkind.N_MLET):
|
||||
// Per the AX:DX:CX:R8 return convention (mirrors C cgen nkind.N_MLET):
|
||||
// (scalar, scalar) — AX → l0, DX → l1.
|
||||
// (scalar, str) — AX → scalar slot, (DX, CX) → str slot
|
||||
// as (.ptr, .len). Position-agnostic — the
|
||||
// (scalar, str) — AX → scalar slot, (DX, CX, R8) → str slot
|
||||
// as (.ptr, .len, .cap). Position-agnostic — the
|
||||
// regs are routed by element type, not by AX/DX.
|
||||
// str IS []u8 (24B): cap rides R8 (#1/Phase 3, task #5).
|
||||
fn cgmlet(c: *cgen, n: *node) void = {
|
||||
let rhs: *node = n.rhs;
|
||||
if (rhs == nil) { return; };
|
||||
@@ -20992,16 +21142,21 @@ fn cgmlet(c: *cgen, n: *node) void = {
|
||||
let off0: i32 = localadd(c, l0.str, sz0, t0);
|
||||
let off1: i32 = localadd(c, l1.str, sz1, t1);
|
||||
if (s0_is_str) {
|
||||
// l0 str: ptr=DX, len=CX, cap=R8. l1 scalar = AX.
|
||||
emitline("\tMOVQ\tDX, ");
|
||||
emitoff(off0: i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitoff((off0 + 8): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tR8, ");
|
||||
emitoff((off0 + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff(off1: i64);
|
||||
emitline("(BP)\n");
|
||||
} else {
|
||||
// l0 scalar; l1 str: ptr=DX, len=CX, cap=R8.
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff(off0: i64);
|
||||
emitline("(BP)\n");
|
||||
@@ -21011,6 +21166,9 @@ fn cgmlet(c: *cgen, n: *node) void = {
|
||||
emitline("\tMOVQ\tCX, ");
|
||||
emitoff((off1 + 8): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tR8, ");
|
||||
emitoff((off1 + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
};
|
||||
c.lastwasreturn = 0;
|
||||
return;
|
||||
@@ -21597,11 +21755,11 @@ fn cgfnparams(c: *cgen, params: *node) void = {
|
||||
stkcursor += 3;
|
||||
};};
|
||||
} else { if (isstrtype(c, p.lhs)) {
|
||||
if (idx + 2 <= 6) {
|
||||
// #60: route str-param slot width through the
|
||||
// primtypesize SSoT so #1's ty_str bump propagates
|
||||
// here (parent #43 covered the reg-fill site only
|
||||
// inside cgexpr).
|
||||
if (idx + 3 <= 6) {
|
||||
// str IS []u8: 3-word param (ptr,len,cap), same as
|
||||
// the slice arm above (#1/Phase 3). #60: route slot
|
||||
// width through the primtypesize SSoT so #1's ty_str
|
||||
// bump propagates here.
|
||||
let off: i32 = localadd(c, nm, primtypesize("str"): i32, p.lhs);
|
||||
emitline("\tMOVQ\t");
|
||||
emitline(argregname(idx));
|
||||
@@ -21615,11 +21773,14 @@ fn cgfnparams(c: *cgen, params: *node) void = {
|
||||
emitoff((off + 8): i64);
|
||||
emitline("(BP)\n");
|
||||
idx += 1;
|
||||
emitline("\tMOVQ\t");
|
||||
emitline(argregname(idx));
|
||||
emitline(", ");
|
||||
emitoff((off + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
idx += 1;
|
||||
} else { if (idx < 6) {
|
||||
// Partial-fit stitch — mirrors tagged at lines
|
||||
// 440-469. Only idx=5 hits this (nw=2,
|
||||
// regs_left=1): ptr lands in R9, len at
|
||||
// +16+stkcursor*8(BP).
|
||||
// Partial-fit stitch — mirrors the slice arm above.
|
||||
// #60: same SSoT routing as the regs-fit arm above.
|
||||
let off: i32 = localadd(c, nm, primtypesize("str"): i32, p.lhs);
|
||||
let regs_left: i32 = 6 - idx;
|
||||
@@ -21633,7 +21794,7 @@ fn cgfnparams(c: *cgen, params: *node) void = {
|
||||
idx += 1;
|
||||
w += 1;
|
||||
};
|
||||
for (w < 2) {
|
||||
for (w < 3) {
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff((16 + stkcursor*8): i64);
|
||||
emitline("(BP), AX\n");
|
||||
@@ -21645,7 +21806,7 @@ fn cgfnparams(c: *cgen, params: *node) void = {
|
||||
};
|
||||
} else {
|
||||
localaddstack(c, nm, p.lhs, 16 + stkcursor*8);
|
||||
stkcursor += 2;
|
||||
stkcursor += 3;
|
||||
};};
|
||||
} else { let stsz: i32 = structparamsize(c, p.lhs);
|
||||
if (stsz > 0) {
|
||||
|
||||
@@ -3365,7 +3365,7 @@ export fn main() i32 = {
|
||||
// (#42). Each call folds to an N_INTLIT at check time; cgen
|
||||
// materialises the literal as a plain `MOVQ $N, AX`. Mirrors
|
||||
// cstage cmd/wcc/check.c:907-960 byte-for-byte on this corpus.
|
||||
if (size(str) != 16) { return 23; };
|
||||
if (size(str) != 24) { return 23; }; // str IS []u8: {ptr,len,cap} 24B (#1/Phase 3)
|
||||
if (size(i64) != 8) { return 24; };
|
||||
if (size(i32) != 4) { return 25; };
|
||||
if (align(i64) != 8) { return 26; };
|
||||
|
||||
@@ -185,7 +185,7 @@ export fn main() i32 = {
|
||||
// (#42). Each call folds to an N_INTLIT at check time; cgen
|
||||
// materialises the literal as a plain `MOVQ $N, AX`. Mirrors
|
||||
// cstage cmd/wcc/check.c:907-960 byte-for-byte on this corpus.
|
||||
if (size(str) != 16) { return 23; };
|
||||
if (size(str) != 24) { return 23; }; // str IS []u8: {ptr,len,cap} 24B (#1/Phase 3)
|
||||
if (size(i64) != 8) { return 24; };
|
||||
if (size(i32) != 4) { return 25; };
|
||||
if (align(i64) != 8) { return 26; };
|
||||
|
||||
Reference in New Issue
Block a user