Files
ww/test/lang/struct_composite_init_test.ww
Hojun-Cho 83f5956df2 test: banner purge + WHY-only comment sweep (rule 8)
Every section banner dies (103 -> 0) across test/lang, the observer
suites, the C carriers, and the five comment-heavy corpus fixtures;
banner provenance (#N cites, carrier numbers, repair-cluster labels)
folded into headers or adjacent WHY comments. Narration deleted; row
provenance, ref cites, divergence pins, and layout contracts kept
(fwd-ref decl-order guards and bootstrap-gate corpus rationale
restored where the sweep over-cut). Comment-only proven: all 3742
wwbuild workdir .s byte-identical before/after; test-commit and
test-byteid (161 lang + 1399 data, 0 pinned-divergent) green.
2026-08-08 21:40:23 +09:00

67 lines
1.9 KiB
Plaintext

// 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);
};