Files
ww/test/lang/struct_composite_init_test.ww
Hojun-Cho 74cc35d488 test: migrate Fam4 static-init/DATA-emit value tests to @test (#30)
Continues the test-arch tower past Fam8-13. 11 module-level static-init
/ DATA-emit value drivers move from test/wcc/*_run.c into @test row-
tables under test/lang/; every classification empirically re-probed at
HEAD (refuting two stale worklist tags).

- value rows -> test/lang/*_test.ww (11 files)
- reject rows -> runww //ww:error carriers (3, dual-stage non-vacuous;
  947 const-divzero confirmed a both-stage compile-reject, not run-exit)
- 840_zeroinit, 944_array_zeroinit, 989_arrlit_tail_zero kept as byte-id
  .c pins (zero-over-dirtied-frame / DATAW-length is byte-id-blind to a
  runtime @test; #263), mutation-gated
- repoint two stale comment refs to deleted test names (719,
  989_structlocal_frame)

Migrated static-init @test ride the cs==ww T2 byte-id gate, preserving
DATA-emit byte-id. 2D global-struct array-field read (#137/#150)
confirmed cs==ww + correct at HEAD. Coverage parity verified row-by-row;
two-round reviewed. Floor ratchet follows.
2026-06-25 01:32:32 +09:00

67 lines
1.9 KiB
Plaintext

// struct_composite_init_test — module-level `let`/`def` composite-struct
// static-init, field read. Migrated from test/wcc/918_struct_composite_init_run.c
// (#129 Phase A.2). Pre-fix emit_lets/emit_defs skipped struct-typed decls
// (link: `undefined reference to main.NAME`) and a struct def read MOVSXD'd
// stack byte 0. Fix = emit_struct_data/emit_struct_lit_bytes walking the field
// list with per-field-offset zero-fill (rule 13). cstage build+run was T1;
// cs==ww .s byte-id rides T2 (test-lang-byteid).
//
// The float-field rows assert bit-exact (drew) via bits64. let_empty/norhs read
// 0 from the statically zero-filled DATA (a global, not a dirtied stack — no
// benign-zero trap; an under-emit would shorten the symbol, not pad zero). The
// 8B-struct row pins the !is_struct gate over the sz==8 scalar short-circuit.
package struct_composite_init_test;
type cfg_t = struct { a: i32, b: u64 };
type ft = struct { a: f64, b: u32 };
type s8 = struct { a: i32, b: i32 };
let CFG_L: cfg_t = cfg_t{a=1, b=2u64};
def CFG_D: cfg_t = cfg_t{a=1, b=2u64};
let F_L: ft = ft{a=1.5, b=99u32};
def F_D: ft = ft{a=1.5, b=99u32};
let Z: cfg_t = cfg_t{};
let X8: s8 = s8{a=7, b=42};
let CFG_NR: cfg_t;
fn bits64(v: f64) u64 = {
let x: f64 = v;
let p: *u64 = (&x): *u64;
return *p;
};
@test fn let_int_struct() void = {
assert(CFG_L.a == 1);
assert(CFG_L.b == 2u64);
};
@test fn def_int_struct() void = {
assert(CFG_D.a == 1);
assert(CFG_D.b == 2u64);
};
@test fn let_float_field() void = {
assert(bits64(F_L.a) == 0x3FF8000000000000u64);
assert(F_L.b == 99u32);
};
@test fn def_float_field() void = {
assert(bits64(F_D.a) == 0x3FF8000000000000u64);
assert(F_D.b == 99u32);
};
@test fn let_empty_struct() void = {
assert(Z.a == 0);
assert(Z.b == 0u64);
};
@test fn let_int_struct_8b() void = {
assert(X8.a == 7);
assert(X8.b == 42);
};
@test fn let_norhs_struct() void = {
assert(CFG_NR.a == 0);
};