Files
sx/examples/0804-memory-xx-target-in-field-assign.sx
agra d8076b9333 lang: rename signed integer types sN -> iN
Surface rename of the signed integer family: s1..s64 become i1..i64
(u1..u64, usize, isize unchanged). 'string' keeps the s-prefix arm in
name classification; width parsing moves to the i-prefix arm next to
isize.

Internal TypeId tags follow the surface (.s8/.s16/.s32/.s64 ->
.i8/.i16/.i32/.i64), as do mono-key mangle fragments (ptr_i64,
tu_i64_bool) and all display/diagnostic formatting (i{d}).

Migrated in the same sweep: stdlib + examples + issue repros + FFI C
companions (shared symbol names like ffi_id_i64), expected
stdout/stderr/ir snapshots, specs.md, readme.md, CLAUDE.md/AGENTS.md,
implementation_plan.md, docs/, issue writeups. Vendored stb_image and
historical flow state left untouched.

zig build test: 426/426; examples suite: 595/595.
2026-06-12 09:31:53 +03:00

43 lines
1.2 KiB
Plaintext

// `xx` cast inside an RHS expression assigned to a struct field takes its
// target type from the field, not from the enclosing function's return type.
// Covers if-then-else RHS and binary-op RHS variants.
#import "modules/std.sx";
Foo :: struct {
pixel_w: i32;
dpi: f32;
last_perf: i64;
delta_time: f32;
}
FC :: struct { a: f32; b: f32; c: i32; d: i32; e: f32; f: f32; }
// If-then-else RHS in a function whose return type is not f32.
calc_bool :: (self: *Foo, wf: f32) -> bool {
self.dpi = if wf > 0.0 then xx self.pixel_w / wf else 1.0;
true
}
// Binary-op RHS in a struct-returning function. The xx casts must target f32,
// not the FC return-struct shape.
begin :: (self: *Foo, current: i64, freq: i64) -> FC {
if self.last_perf > 0 {
self.delta_time = xx (current - self.last_perf) / xx freq;
}
FC.{ a = 1.0, b = 2.0, c = 3, d = 4, e = 5.0, f = 6.0 }
}
main :: () -> void {
f : *Foo = xx libc_malloc(size_of(Foo));
f.pixel_w = 2880;
f.dpi = 0.0;
f.last_perf = 1000;
f.delta_time = 0.0;
_ := calc_bool(f, 1440.0);
print("dpi={}\n", f.dpi);
fc := begin(f, 1500, 1000);
print("delta={} fc.a={}\n", f.delta_time, fc.a);
}