wcc: 2D array [N][M]T static-init + double-index read (#156, A.3 capstone)
Close A.3's deferred shape-14 (nested array). (a) emit_array_lit_bytes gains a TY_ARRAY-element arm (mechanical clone of the TY_STRUCT-element arm — recurses; esz=etype->size, rule-13; ...-nested loud-reject). (b) double-index read tbl[i][j]: when the indexed element is TY_ARRAY, leave the sub-array ADDRESS in AX instead of dereferencing (sister of #135's N_DOT-base fix, on the N_INDEX path) — new elemisarrayc/tinfoisarray helpers, both stages. Storage + read = one 2D-end-to-end concern (A.2/A.3 storage+LOAD precedent). Unblocks strconv fold-4's powers_of_ten[596][2]u64 (direct double-index access). Bootstrap-NEUTRAL (new arms gate on TY_ARRAY-element; 1D consumers byte-identical, 990-997 green). Test 919 +2D rows + 3D + ...-nested-reject. Deferred siblings: #155 (sub-array bind / whole- aggregate copy), #160 (global-struct-field index base).
This commit is contained in:
@@ -1567,6 +1567,51 @@ fn emitarraylitbytes(c: *cgen, arrt: *tinfo, rhs: *node,
|
||||
return true;
|
||||
};
|
||||
|
||||
// #129 A.3 capstone (PREREQ-1, #156): nested-array element [M]T
|
||||
// inside [N][M]T. Mirror of the TY_STRUCT-element arm above and of
|
||||
// the TY_ARRAY-field-in-struct arm in emitstructlitbytes — recurse
|
||||
// into emitarraylitbytes per element; recursion bottoms out at
|
||||
// scalar (int/float) elements. esz = au.sub.size gives the per-
|
||||
// element stride (rule 13). The `...` repeat marker with nested-
|
||||
// array elements is rejected loud (rule 7): no consumer needs it
|
||||
// (powers_of_ten is fully enumerated).
|
||||
if (eu != nil && eu.kind == tykind.TY_ARRAY) {
|
||||
let idx: i32 = 0;
|
||||
let e: *node = rhs.list;
|
||||
for (e != nil && idx < alen) {
|
||||
if (e.kind == nkind.N_FIELD) {
|
||||
if (streq(e.str, "...")) {
|
||||
let m: str = "emitarraylitbytes: '...' repeat with nested-array elements unsupported (#129 A.3, rule 7)\n";
|
||||
os.write(2, m.ptr, m.len: u64);
|
||||
os.exit(1);
|
||||
};
|
||||
};
|
||||
let ev: *node = e;
|
||||
for (ev != nil && ev.kind == nkind.N_CAST) { ev = ev.lhs; };
|
||||
if (ev == nil) { return false; };
|
||||
if (ev.kind != nkind.N_ARRLIT) { return false; };
|
||||
if (!emitarraylitbytes(c, au.sub, ev, 0)) { return false; };
|
||||
idx += 1;
|
||||
e = e.next;
|
||||
};
|
||||
if (emit_phase == 0) { return true; };
|
||||
idx = 0;
|
||||
e = rhs.list;
|
||||
for (e != nil && idx < alen) {
|
||||
let ev: *node = e;
|
||||
for (ev != nil && ev.kind == nkind.N_CAST) { ev = ev.lhs; };
|
||||
emitarraylitbytes(c, au.sub, ev, 1);
|
||||
idx += 1;
|
||||
e = e.next;
|
||||
};
|
||||
for (idx < alen) {
|
||||
let bb: i32 = 0;
|
||||
for (bb < esz) { emitdatawbyte(0u8); bb += 1; };
|
||||
idx += 1;
|
||||
};
|
||||
return true;
|
||||
};
|
||||
|
||||
if (typeisfloat(au.sub)) {
|
||||
let isf32: bool = typeisf32(au.sub);
|
||||
// Validate.
|
||||
|
||||
Reference in New Issue
Block a user