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