code wiki / _hdl_build / nx_eqdispatch_probe.nx

nx_eqdispatch_probe.nx source

↩ module page · 68 lines · 2315 B

1// nx_eqdispatch_probe.nx -- DECISIVE MINIMAL REPRO for debt 1785530065 (2232): 2// "nx_cc compiles == as >" in a multi-branch i64 equality dispatch returning STRING LITERALS. 3// 4// WHY THIS SHAPE: the reported subject (nx_mcu_ready.rdy_reason) is a 4-branch if-chain comparing an i64 5// against module consts and RETURNING a string literal from each arm. This probe isolates exactly that and 6// NOTHING else -- no imports beyond syscalls, no structs, no loops around the dispatch. 7// 8// THE DISCRIMINATOR: eq_pick(999) matches NO branch, so a correct compiler returns the fallthrough D. 9// If == is emitted as >, then 999 > 100 is TRUE and the FIRST arm wins. 10// CORRECT : D A B C D ==-as-> : A A A A A 11// The INT-ARM control separates "equality codegen broken" from "string-return dispatch broken". 12// 13// LOCAL RESULT 2026-08-01 (laptop nxc2 toolchain, elf 11207B): STRING-ARM=DABCD INT-ARM=41234 -- BOTH 14// CORRECT, i.e. the general claim is REFUTED under that compiler. This NAS copy exists to close the scope 15// gap, because the two toolchains have diverged before and a refutation on one proves nothing about the other. 16// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 17import "nx_syscalls.nx" 18 19const EQ_A: i64 = 100 20const EQ_B: i64 = 101 21const EQ_C: i64 = 102 22 23func eq_w(s: *u8) -> i64 { 24 var n: i64 = 0 25 while s[n] != (0 as u8) { n = n + 1 } 26 sys_write(1, s, n) 27 return 0 28} 29 30func eq_pick(v: i64) -> *u8 { 31 if v == EQ_A { return "A" as *u8 } 32 if v == EQ_B { return "B" as *u8 } 33 if v == EQ_C { return "C" as *u8 } 34 return "D" as *u8 35} 36 37func eq_pick_int(v: i64) -> i64 { 38 if v == EQ_A { return 1 } 39 if v == EQ_B { return 2 } 40 if v == EQ_C { return 3 } 41 return 4 42} 43 44func eq_wn(v: i64) -> i64 { 45 let b: *u8 = sys_mmap(32) 46 b[0] = ((v % 10) + 48) as u8 47 sys_write(1, b, 1) 48 return 0 49} 50 51func main(argc: i64, argv: *i64) -> i64 { 52 eq_w("STRING-ARM want=DABCD got=" as *u8) 53 eq_w(eq_pick(999)) 54 eq_w(eq_pick(100)) 55 eq_w(eq_pick(101)) 56 eq_w(eq_pick(102)) 57 eq_w(eq_pick(103)) 58 eq_w("\n" as *u8) 59 60 eq_w("INT-ARM want=41234 got=" as *u8) 61 eq_wn(eq_pick_int(999)) 62 eq_wn(eq_pick_int(100)) 63 eq_wn(eq_pick_int(101)) 64 eq_wn(eq_pick_int(102)) 65 eq_wn(eq_pick_int(103)) 66 eq_w("\n" as *u8) 67 return 0 68}