test: migrate defdim len/cap family to test/lang @test, retire C twins (fold-2)
Continue fold-2: migrate drew's Family 2 (def-dimensioned array len/cap/slice resolution) from bespoke build+run C twins to test/lang @test, retiring each twin in the same commit. Runtime coverage MOVES from $(TESTS) to test-lang (T1 runs+asserts via `ww test`) + test-lang-byteid (T2 keeps cs==ww .s byte-id); coverage is preserved, the $(TESTS) headline drops 3 (425->422). All asserts are primitive int comparisons (no fmt/strconv in the assert path); the defcap rows poison cap != len and assert both words so a dropped cap word FAILS. 989_defdim_field_run.c -> defdim_field_test.ww (`.len` field-read on a def-dim [MAX]T resolves from the type table: local/let-global/def cgdot arms + sum) 989_defdim_slice_run.c -> defdim_slice_test.ww (slicing a def-dim [MAX]T resolves len AND cap from the type table: default-hi + cgbasecap, local+global) 989_defdim_argslice_run.c -> defdim_argslice_test.ww (def-dim slice passed as a call arg resolves default-hi len in the N_SLICE arg-push arms; litctrl pins the N_INTLIT path) Bump LANGBYTEID_EXPECTED_MIN 31->34 to ratchet the new corpus floor.
This commit is contained in:
35
test/lang/defdim_argslice_test.ww
Normal file
35
test/lang/defdim_argslice_test.ww
Normal file
@@ -0,0 +1,35 @@
|
||||
// defdim_argslice_test — passing a slice of a `def`-dimensioned array
|
||||
// (`take(buf[1:])` on `[MAX]T`) as a call argument must resolve the default-hi
|
||||
// length from the type table, the N_SLICE arg-push member of the def-dim
|
||||
// family, migrated from test/wcc/989_defdim_argslice_run.c (#56 c4). pushargsrev's
|
||||
// N_SLICE default-hi arms (local / global) only handled an N_INTLIT dim, so a
|
||||
// plain `[MAX]u8` base emitted nothing and the pushed slice header's len word
|
||||
// was left stale -- the callee read garbage (ww 135 local / 255 global). The
|
||||
// fix reads alen from the stamped array tinfo (rule-13) in both arg-push arms.
|
||||
// `take` returns s.len, so the asserted 4 IS the pushed-header length contract;
|
||||
// the litctrl row pins the N_INTLIT path so the new else-arm can't perturb it.
|
||||
// T2 (test-lang-byteid) keeps the cs==ww net the .c twin's run-compare gave.
|
||||
|
||||
package defdim_argslice_test;
|
||||
|
||||
def MAX: i32 = 5;
|
||||
let g: [MAX]u8 = [1, 2, 3, 4, 5];
|
||||
|
||||
fn take(s: []u8) i32 = { return s.len: i32; };
|
||||
|
||||
@test fn local_argslice() void = {
|
||||
// local def-dim base: take(buf[1:]) sees len 5-1 = 4.
|
||||
let buf: [MAX]u8 = [1, 2, 3, 4, 5];
|
||||
assert(take(buf[1:]) == 4);
|
||||
};
|
||||
|
||||
@test fn global_argslice() void = {
|
||||
// global def-dim base: take(g[1:]) sees len 4.
|
||||
assert(take(g[1:]) == 4);
|
||||
};
|
||||
|
||||
@test fn litctrl_argslice() void = {
|
||||
// literal-dim control: the N_INTLIT arm stays correct (no regress).
|
||||
let buf: [5]u8 = [1, 2, 3, 4, 5];
|
||||
assert(take(buf[1:]) == 4);
|
||||
};
|
||||
37
test/lang/defdim_field_test.ww
Normal file
37
test/lang/defdim_field_test.ww
Normal file
@@ -0,0 +1,37 @@
|
||||
// defdim_field_test — `.len` field-read on an array whose dimension is a
|
||||
// `def` constant (`[MAX]T`) must resolve the length from the type table, the
|
||||
// cgdot sibling of the #21 cgslice fix, migrated from
|
||||
// test/wcc/989_defdim_field_run.c (#56). A `def MAX` dim arrives as a
|
||||
// non-literal node; wwstage's cgdot `.len` arms (local / let-global / def) +
|
||||
// letemitsize only handled an N_INTLIT dim, so `.len` folded to MOVQ $0 (ww
|
||||
// returned 0 where cstage reads the resolved bu->alen). The fix reads alen from
|
||||
// the stamped array tinfo (rule-13) in each arm. cstage was always correct; T2
|
||||
// (test-lang-byteid) keeps the cs==ww net the .c twin's run-compare provided.
|
||||
|
||||
package defdim_field_test;
|
||||
|
||||
def MAX: i32 = 5;
|
||||
let g: [MAX]u8 = [1, 2, 3, 4, 5];
|
||||
def A: [MAX]u8 = [1, 2, 3, 4, 5];
|
||||
|
||||
@test fn local_len() void = {
|
||||
// local [MAX]u8 — the cgdot local arm; pre-fix ww folded to 0.
|
||||
let buf: [MAX]u8 = [1, 2, 3, 4, 5];
|
||||
assert(buf.len: i32 == 5);
|
||||
};
|
||||
|
||||
@test fn global_len() void = {
|
||||
// let-global [MAX]u8 — the cgdot let-global arm.
|
||||
assert(g.len: i32 == 5);
|
||||
};
|
||||
|
||||
@test fn defarr_len() void = {
|
||||
// def [MAX]u8 constant — the cgdot def arm.
|
||||
assert(A.len: i32 == 5);
|
||||
};
|
||||
|
||||
@test fn sum_len() void = {
|
||||
// all three arms in one fn (the .c `sum` row): 5 + 5 + 5 = 15.
|
||||
let buf: [MAX]u8 = [1, 2, 3, 4, 5];
|
||||
assert((buf.len + g.len + A.len): i32 == 15);
|
||||
};
|
||||
47
test/lang/defdim_slice_test.ww
Normal file
47
test/lang/defdim_slice_test.ww
Normal file
@@ -0,0 +1,47 @@
|
||||
// defdim_slice_test — slicing an array whose dimension is a `def` constant
|
||||
// (`[MAX]T`) must resolve the length AND the capacity from the type table, not
|
||||
// the AST dimension node, migrated from test/wcc/989_defdim_slice_run.c (#21).
|
||||
// A `def MAX` dim arrives as a non-literal node; wwstage's cgslice default-hi
|
||||
// fell to MOVQ $0 (len 0 -> underflow, exit 255) and cgbasecap returned false
|
||||
// (cap fell back to len). The fix reads alen from the stamped array tinfo
|
||||
// (rule-13) in both the local and global arms of both helpers. cstage reads the
|
||||
// resolved bu->alen and was always correct; the defcap rows poison cap != len
|
||||
// so a stage that drops the cap word FAILS. T2 keeps the cs==ww net.
|
||||
//
|
||||
// Two def constants (MAX4/MAX6) and two globals (g4/g6) since one package
|
||||
// cannot redeclare `def MAX`; the def-dim path is exercised regardless of name.
|
||||
|
||||
package defdim_slice_test;
|
||||
|
||||
def MAX4: i32 = 4;
|
||||
def MAX6: i32 = 6;
|
||||
let g4: [MAX4]u8 = [10, 20, 30, 40];
|
||||
let g6: [MAX6]u8 = [1, 2, 3, 4, 5, 6];
|
||||
|
||||
@test fn deflen_local() void = {
|
||||
// local default-hi: cgslice reads N=4 from tinfo; buf[1:].len = 4-1 = 3.
|
||||
let buf: [MAX4]u8 = [10, 20, 30, 40];
|
||||
let s: []u8 = buf[1:];
|
||||
assert(s.len: i32 == 3);
|
||||
};
|
||||
|
||||
@test fn deflen_global() void = {
|
||||
// global default-hi: g4[1:].len = 4-1 = 3.
|
||||
let s: []u8 = g4[1:];
|
||||
assert(s.len: i32 == 3);
|
||||
};
|
||||
|
||||
@test fn defcap_local() void = {
|
||||
// cgbasecap local: buf[2:4] over [6]u8 -> len 2, cap = 6-2 = 4 (cap != len).
|
||||
let buf: [MAX6]u8 = [1, 2, 3, 4, 5, 6];
|
||||
let s: []u8 = buf[2:4];
|
||||
assert(s.len: i32 == 2);
|
||||
assert(s.cap: i32 == 4);
|
||||
};
|
||||
|
||||
@test fn defcap_global() void = {
|
||||
// cgbasecap global: g6[2:4] -> len 2, cap = 6-2 = 4.
|
||||
let s: []u8 = g6[2:4];
|
||||
assert(s.len: i32 == 2);
|
||||
assert(s.cap: i32 == 4);
|
||||
};
|
||||
Reference in New Issue
Block a user