nx_fieldtypeprobe.nx source
↩ module page · 40 lines · 1562 B
1// nx_fieldtypeprobe.nx -- MINIMAL REPRO for the type-check failure blocking the compiler build.
2// HYPOTHESIS: struct field TYPE lookup is misaligned, so an i64 field declared AFTER a pointer field
3// resolves to the POINTER's type. That would explain nx_compile_x86 failing with
4// "x86ctx_emit_condjump: arg 2 is a POINTER but the parameter is an INTEGER" when every caller and
5// every field involved is provably i64. Shape mirrors struct Instr: a *Type early, i64s after.
6// If this file FAILS to compile with a POINTER/INTEGER mismatch, the defect is field resolution.
7// If it COMPILES, the defect is elsewhere and Instr's width/other fields matter.
8// expect_exit: 0 license_tier: ORIGINAL
9import "nx_syscalls.nx"
10
11struct FtOther { pad: i64 }
12
13struct FtProbe {
14 a: i64,
15 b: i64,
16 ptr: *FtOther,
17 n: i64,
18 f0: i64,
19 f1: i64,
20 f2: i64,
21}
22
23func ft_take_int(x: i64, y: i64) -> i64 { return x + y }
24
25func ft_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
26func ft_puts(s: *u8) -> i64 { sys_write(1, s, ft_len(s)); return 0 }
27
28func main() -> i64 {
29 let raw: *u8 = sys_mmap(256)
30 let p: *FtProbe = raw as *FtProbe
31 p.a = 1
32 p.f1 = 41
33 p.f2 = 1
34 // The exact shape of the failing call: pass i64 fields that live AFTER a pointer field
35 // into i64 parameters.
36 let r: i64 = ft_take_int(p.f1, p.f2)
37 if r == 42 { ft_puts("FIELD-TYPE-OK: i64 fields after a pointer resolve correctly\n" as *u8) }
38 if r != 42 { ft_puts("FIELD-VALUE-WRONG\n" as *u8) }
39 return 0
40}