code wiki / _hdl_build / nx_ale_grade_nondet_stub.nx
nx_ale_grade_nondet_stub.nx source
↩ module page · 45 lines · 2152 B
1// nx_ale_grade_nondet_stub.nx -- the TAMPER fixture for ALE-R1a: a NON-DETERMINISTIC grader.
2// It IGNORES (reference, artifact) and emits a CLOCK-DERIVED, time-varying milli-score
3// instead of a pure function of the two files. The diff-lane gate _ale_grade_gate runs THIS
4// twice on the same inputs; because the score changes between runs, the gate REJECTS it (the
5// determinism check BITES). This is the negative control proving the real grader's determinism
6// contract is enforced, not assumed. NEVER on the runtime path; fixture only. Lives in
7// runtime/_hdl_build/ so `import "nx_syscalls.nx"` resolves (the import walker reaches runtime/);
8// the fixture DATA (.txt) lives under knowledge/specs/ale_grade_examples/. Same I/O surface as
9// nx_ale_grade: argv[1]=ref, argv[2]=art; writes the milli-score (decimal + newline) to the
10// scratch path in argv[3] (or stdout if absent). license_tier: ORIGINAL
11import "nx_syscalls.nx"
12
13func ng_wn(fd: i64, v: i64) -> i64 {
14 let bb: *u8 = sys_mmap(28)
15 var m: i64 = v
16 if m < 0 { m = 0 - m }
17 let t: *u8 = sys_mmap(28)
18 var k: i64 = 0
19 if m == 0 { t[0] = 48; k = 1 }
20 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
21 var i: i64 = 0
22 while i < k { bb[i] = t[k - 1 - i]; i = i + 1 }
23 sys_write(fd, bb, k)
24 sys_write(fd, "\n" as *u8, 1)
25 return 0
26}
27
28func main(argc: i64, argv: *i64) -> i64 {
29 // NON-DETERMINISTIC by construction: score derived from the MICROSECOND clock, so two
30 // runs on the same (ref, art) emit DIFFERENT scores (us resolution makes a same-bucket
31 // collision between two sequential process spawns astronomically unlikely). Clamp into
32 // [0,1000] so the value is still a *valid-looking* score -- the only thing wrong is that
33 // it is not a pure function of the inputs (exactly what the gate's determinism check bites).
34 let us: i64 = sys_now_us()
35 var s: i64 = us % 1000
36 if s < 0 { s = 0 - s }
37 if argc >= 4 {
38 let out: i64 = sys_openat_wr(argv[3] as *u8, 0x1a4)
39 if out >= 0 { ng_wn(out, s); sys_close(out) }
40 } else {
41 ng_wn(1, s)
42 }
43 sys_exit(0)
44 return 0
45}