cgen: #38a chained-dot TAGGED leaf — cursor read + widen store, value-chain + ptr-chain, both stages
A tagged leaf at the end of a dot chain (depth >= 2) fell to the
one-word scalar tail in FOUR walkers — the value-chain read spine,
the value-chain assign walker, the chained-*struct read branch, and
the chained-*struct assign branch — in BOTH stages, byte-identical,
gate-blind:
READ: one MOVQ pulled the TAG word only; is-tests passed by
tag-luck while as/match/let consumers read stale DX/CX/R8
as payload (ken x5c: o.r.min as size added entry-zero DX —
want 28 got 20; ken b8 same through a mid-chain *rep).
ASSIGN: one sized store landed the rhs ON the tag slot, payload
kept its old bytes (ken x5d: `o.r.min = 8: size` made the
following is-test false).
The single-dot arms were already correct — each fix is that arm
verbatim at the chained site:
read: the tagged cursor (AX=tag, DX=val0, R8=val2 before
CX=val1 — the base may live in CX/AX; >32B box leaves its
ADDRESS in AX, the #37 mem-read convention). wwstage rides
the existing cgloadtaggedfield helper; the *struct-base
branches stage AX into BX first (cursor targets AX).
assign: full slot rewrite via the shared widener
(cg_widen_tagged_store / cgwidentaggedstore, base BX/BP),
plain `=` only — compound on tagged stays loud (#133).
The nested-LITERAL half of the old #38 filing dissolved: the
canonical fill's tagged-field widen delegation (#23, 413aafa) already
covers any depth — x5c's literal init emits a correct tag at HEAD;
only the chained READ/ASSIGN halves were live (probe-proven, asm at
/tmp/pB).
Probes converge byte-id and runtime-correct: x5c/d/e (28), depth-2
(b3/b9), (void|str) 32B box + match readback (b5), *outer root (b7),
mid-chain *rep (b8), non-tagged control (f38a). 938 rows chained_*
pin all six shapes. Residuals filed, not folded (rule 11): the
INDEX-spine sibling xs[i].min payload read (task #58); tagged-field
GLOBALS stay loud at DATA emit (#129 A.2), so the walkers'
global arms are mirror-only today.
Task #38.
This commit is contained in:
123
cmd/w6c/cgen.c
123
cmd/w6c/cgen.c
@@ -5217,6 +5217,26 @@ cgexpr(Cg *c, Node *n, Local *locals)
|
||||
int store_op = fldstoreop(ft, fsz);
|
||||
int foff = (int)f->offset;
|
||||
if (n->op == TK_ASSIGN) {
|
||||
/* tagged leaf (#38a): eval the *struct
|
||||
* base into BX, then the shared widener
|
||||
* (it spills BX across its internal
|
||||
* cgexpr) — same base-then-widen order
|
||||
* as the single-dot via_ptr arm. The
|
||||
* scalar tail below stored ONE sized
|
||||
* word at the field offset: the rhs
|
||||
* landed in the TAG slot (ken b8:
|
||||
* `o.p.min = 8: size` left `is size`
|
||||
* false). */
|
||||
if (fu && fu->kind == TY_TAGGED) {
|
||||
cgexpr(c, n->lhs->lhs, locals);
|
||||
ins2(c, A_MOVQ, areg(D_AX),
|
||||
areg(D_BX));
|
||||
cg_widen_tagged_store(c,
|
||||
&locals, fu, n->rhs,
|
||||
D_BX, foff,
|
||||
(int)fu->size);
|
||||
break;
|
||||
}
|
||||
int c_isf32 = 0;
|
||||
if (fld_isfloat(ft, &c_isf32)) {
|
||||
/* f64/f32 chained-store: cgexpr rhs
|
||||
@@ -5501,6 +5521,39 @@ cgexpr(Cg *c, Node *n, Local *locals)
|
||||
int fsz = (int)(leaf_type
|
||||
? leaf_type->size : 8);
|
||||
int store_op = fldstoreop(leaf_type, fsz);
|
||||
/* tagged leaf (#38a): full slot rewrite via
|
||||
* the shared widener — the single-dot
|
||||
* tagged-field arm (after_dot_assign)
|
||||
* verbatim. The scalar tail below stored ONE
|
||||
* sized word at the field offset: the rhs
|
||||
* landed in the TAG slot and the payload
|
||||
* kept its old bytes (ken x5d:
|
||||
* `o.r.min = 8: size` left `is size`
|
||||
* false). Only plain `=` reaches this
|
||||
* walker (TK_ASSIGN gate above). */
|
||||
if (fu && fu->kind == TY_TAGGED) {
|
||||
int tsz = (int)fu->size;
|
||||
if (via_cx) {
|
||||
if (ptr_root)
|
||||
ins2(c, A_MOVQ,
|
||||
amem(D_BP, base_disp),
|
||||
areg(D_BX));
|
||||
else
|
||||
ins2(c, A_LEAQ,
|
||||
masym(c, cur->str),
|
||||
areg(D_BX));
|
||||
cg_widen_tagged_store(c,
|
||||
&locals, fu, n->rhs,
|
||||
D_BX, total_off, tsz);
|
||||
} else {
|
||||
cg_widen_tagged_store(c,
|
||||
&locals, fu, n->rhs,
|
||||
D_BP,
|
||||
base_disp + total_off,
|
||||
tsz);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (fu && (fu->kind == TY_STR
|
||||
|| fu->kind == TY_SLICE)) {
|
||||
/* str/slice: store ptr/len/cap. cgexpr
|
||||
@@ -10225,6 +10278,42 @@ cgexpr(Cg *c, Node *n, Local *locals)
|
||||
Type *fu = (leaf_type
|
||||
&& leaf_type->kind == TY_NAMED)
|
||||
? leaf_type->under : leaf_type;
|
||||
/* tagged leaf (#38a): load the box into
|
||||
* the tagged cursor (AX=tag, DX=val0,
|
||||
* R8=val2 before CX=val1 — base_reg may
|
||||
* be CX), the single-dot tagged-field arm
|
||||
* verbatim. Pre-#38a the fldloadop tail
|
||||
* pulled ONE word (the tag): is-tests
|
||||
* passed by tag-luck while as/match/let
|
||||
* consumers read stale payload registers
|
||||
* (ken x5c: o.r.min as size added DX).
|
||||
* >32B box: ADDRESS in AX (the #37
|
||||
* cg_tagged_memread convention). */
|
||||
if (fu && fu->kind == TY_TAGGED) {
|
||||
int fo = base_disp + total_off;
|
||||
if ((int)fu->size
|
||||
> TUPLE_GPCAP * 8) {
|
||||
ins2(c, A_LEAQ,
|
||||
amem(base_reg, fo),
|
||||
areg(D_AX));
|
||||
goto dot_done;
|
||||
}
|
||||
ins2(c, A_MOVQ,
|
||||
amem(base_reg, fo + 0),
|
||||
areg(D_AX));
|
||||
ins2(c, A_MOVQ,
|
||||
amem(base_reg, fo + 8),
|
||||
areg(D_DX));
|
||||
if (fu->size > 24)
|
||||
ins2(c, A_MOVQ,
|
||||
amem(base_reg, fo + 24),
|
||||
areg(D_R8));
|
||||
if (fu->size > 16)
|
||||
ins2(c, A_MOVQ,
|
||||
amem(base_reg, fo + 16),
|
||||
areg(D_CX));
|
||||
goto dot_done;
|
||||
}
|
||||
if (fu && fu->kind == TY_STR) {
|
||||
ins2(c, A_MOVQ,
|
||||
amem(base_reg,
|
||||
@@ -10729,6 +10818,40 @@ cgexpr(Cg *c, Node *n, Local *locals)
|
||||
Type *ft = f->type;
|
||||
Type *fu = (ft && ft->kind == TY_NAMED)
|
||||
? ft->under : ft;
|
||||
/* tagged leaf (#38a): AX holds the *struct
|
||||
* base and the tagged cursor targets AX
|
||||
* (tag) — stage the base in BX, then the
|
||||
* cursor load (AX=tag, DX=val0, R8=val2,
|
||||
* CX=val1; >32B → ADDRESS in AX, #37). The
|
||||
* fldloadop tail pulled ONE word (ken b8:
|
||||
* o.p.min read stale DX as payload). */
|
||||
if (fu && fu->kind == TY_TAGGED) {
|
||||
int fo = (int)f->offset;
|
||||
ins2(c, A_MOVQ, areg(D_AX),
|
||||
areg(D_BX));
|
||||
if ((int)fu->size
|
||||
> TUPLE_GPCAP * 8) {
|
||||
ins2(c, A_LEAQ,
|
||||
amem(D_BX, fo),
|
||||
areg(D_AX));
|
||||
goto dot_done;
|
||||
}
|
||||
ins2(c, A_MOVQ,
|
||||
amem(D_BX, fo + 0),
|
||||
areg(D_AX));
|
||||
ins2(c, A_MOVQ,
|
||||
amem(D_BX, fo + 8),
|
||||
areg(D_DX));
|
||||
if (fu->size > 24)
|
||||
ins2(c, A_MOVQ,
|
||||
amem(D_BX, fo + 24),
|
||||
areg(D_R8));
|
||||
if (fu->size > 16)
|
||||
ins2(c, A_MOVQ,
|
||||
amem(D_BX, fo + 16),
|
||||
areg(D_CX));
|
||||
goto dot_done;
|
||||
}
|
||||
/* str IS []u8 — same 3-word {ptr,len,cap} as a
|
||||
* slice field: load (ptr, len, cap) into
|
||||
* (AX, BX, CX). AX is the *struct base, so
|
||||
|
||||
Reference in New Issue
Block a user