code wiki / _hdl_build / lmprobe_lm001.nx
lmprobe_lm001.nx source
↩ module page · 44 lines · 1818 B
1// lmprobe_lm001.nx -- LANDMINE PROBE for LM-001 "no &&/|| -- use flag idiom (go/scan vars)".
2// CONTRACT (the retirement oracle, same as lmprobe_lm002/004): exit 0 => ROOT-FIXED (short-circuit
3// && and || now parse AND evaluate correctly on all truth-table rows); non-zero OR build-failure =>
4// STILL LIVE (if the operators are unsupported the file FAILS TO BUILD, which IS the STILL-LIVE
5// verdict -- never inconclusive). Import-light so a compile failure is attributable to the operator.
6// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
7import "nx_syscalls.nx"
8import "nx_estr.nx"
9
10func andcase(a: i64, b: i64) -> i64 {
11 var r: i64 = 0
12 if a == 1 && b == 1 { r = 1 }
13 return r
14}
15func orcase(a: i64, b: i64) -> i64 {
16 var r: i64 = 0
17 if a == 1 || b == 1 { r = 1 }
18 return r
19}
20
21func main() -> i64 {
22 var bad: i64 = 0
23 if andcase(1,1) != 1 { bad = bad + 1 }
24 if andcase(1,0) != 0 { bad = bad + 1 }
25 if andcase(0,1) != 0 { bad = bad + 1 }
26 if andcase(0,0) != 0 { bad = bad + 1 }
27 if orcase(1,1) != 1 { bad = bad + 1 }
28 if orcase(1,0) != 1 { bad = bad + 1 }
29 if orcase(0,1) != 1 { bad = bad + 1 }
30 if orcase(0,0) != 0 { bad = bad + 1 }
31 var c: i64 = 0
32 if (1 == 1) && (2 == 2) && (3 == 3) { c = 1 }
33 if c != 1 { bad = bad + 1 }
34 // LM-001 also names `break` (the flag-idiom substitute). Prove it exits the loop early: sum 0..9
35 // but break at 5 -> 0+1+2+3+4 = 10.
36 var sum: i64 = 0
37 var i: i64 = 0
38 while i < 10 { if i == 5 { break } sum = sum + i; i = i + 1 }
39 if sum != 10 { bad = bad + 1 }
40 if bad != 0 { es_puts("LM-001 STILL-LIVE (&&/|| wrong)\n" as *u8); sys_exit(1); return 1 }
41 es_puts("LM-001 ROOT-FIXED (&& and || parse + evaluate correctly on the full truth table)\n" as *u8)
42 sys_exit(0)
43 return 0
44}