code wiki / _hdl_build / lmprobe_lm008.nx

lmprobe_lm008.nx source

↩ module page · 47 lines · 2108 B

1// lmprobe_lm008.nx -- LANDMINE PROBE for LM-008 "obj.field = imported_call(args) parser desync -- 2// bind call to temp (until T3 fixed)". SAME parser area as the seq715 fnptr-field-call bug. 3// CONTRACT: exit 0 => ROOT-FIXED (a struct-field STORE whose RHS is a function call assigns the 4// call RESULT correctly, and does not desync the token stream for the statements that follow); 5// non-zero OR build-failure => STILL LIVE. Import-light. 6// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 7import "nx_syscalls.nx" 8import "nx_estr.nx" 9 10struct Box { 11 a: i64, 12 b: i64, 13 c: i64, 14} 15const BOX_BYTES: i64 = 24 16 17func mk(x: i64) -> i64 { return x + 100 } 18func add2(x: i64, y: i64) -> i64 { return x + y } 19 20func main() -> i64 { 21 let s: *Box = sys_mmap(BOX_BYTES) as *Box 22 s.a = 7 23 // THE LANDMINE SHAPE: struct-field store whose RHS is a CALL. 24 s.b = mk(5) // want 105 25 s.c = add2(s.a, s.b) // want 7 + 105 = 112 -- also tests reading fields as call ARGS 26 // IMPORTED call as RHS (the landmine names `imported_call` specifically): es_atoi is imported 27 // from nx_estr. Store its result into a field. 28 s.a = es_atoi("42" as *u8) // want 42 (overwrites the earlier 7) 29 // token-stream desync canary: if the parser desynced on the call-RHS store, these following 30 // statements would misparse/miscompute. 31 var after: i64 = 0 32 after = s.a + s.b + s.c // 42 + 105 + 112 = 259 (s.a was overwritten to 42 by the imported call) 33 var bad: i64 = 0 34 if s.a != 42 { bad = bad + 1 } 35 if s.b != 105 { bad = bad + 1 } 36 if s.c != 112 { bad = bad + 1 } 37 if after != 259 { bad = bad + 1 } 38 if bad != 0 { 39 es_puts("LM-008 STILL-LIVE (obj.field = call(args) wrong: a=" as *u8); es_putn(s.a) 40 es_puts(" b=" as *u8); es_putn(s.b); es_puts(" c=" as *u8); es_putn(s.c) 41 es_puts(" after=" as *u8); es_putn(after); es_puts(")\n" as *u8) 42 sys_exit(1); return 1 43 } 44 es_puts("LM-008 ROOT-FIXED (struct-field store with a call RHS assigns correctly, no token desync)\n" as *u8) 45 sys_exit(0) 46 return 0 47}