nx_autofix_candidate3.nx source
↩ module page · 45 lines · 1890 B
1// nx_autofix_candidate3.nx -- second self-localizing candidate: SAME output contract as candidate2 but
2// the SEEDED BUG is in a DIFFERENT function (dbl() returns x instead of doubling). Running the same
3// nx_autofix_auto organ against candidate2 (bug in sgn) AND this file (bug in dbl) is the tooth that
4// proves localization is DISCOVERED from the per-function FNRES rows, not hardcoded. dbl is also not
5// in the fixer's few-shot examples, and its repair is arithmetic (not if-shaped) -- it probes whether
6// the maker generalizes past the template's pattern. license_tier: ORIGINAL
7import "nx_syscalls.nx"
8
9func cw(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
10func cn(v: i64) -> i64 {
11 var m: i64 = v
12 if m < 0 { cw("-" as *u8); m = 0 - m }
13 let t: *u8 = sys_mmap(24)
14 var k: i64 = 0
15 if m == 0 { t[0] = 48 as u8; k = 1 }
16 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
17 let o: *u8 = sys_mmap(24)
18 var i: i64 = 0
19 while i < k { o[i] = t[k - 1 - i]; i = i + 1 }
20 sys_write(1, o, k)
21 return 0
22}
23
24func max2(a: i64, b: i64) -> i64 { if a > b { return a } return b }
25func sgn(x: i64) -> i64 { if x > 0 { return 1 } if x < 0 { return 0 - 1 } return 0 }
26func dbl(x: i64) -> i64 { return x }
27
28func main() -> i64 {
29 var p: i64 = 0
30 var f1: i64 = 0
31 if max2(3, 5) == 5 { f1 = f1 + 1 }
32 if max2(7, 2) == 7 { f1 = f1 + 1 }
33 var f2: i64 = 0
34 if sgn(5) == 1 { f2 = f2 + 1 }
35 if sgn(0 - 3) == (0 - 1) { f2 = f2 + 1 }
36 var f3: i64 = 0
37 if dbl(6) == 12 { f3 = f3 + 1 }
38 if dbl(0 - 4) == (0 - 8) { f3 = f3 + 1 }
39 p = f1 + f2 + f3
40 cw("FNRES max2 " as *u8); cn(f1); cw(" 2\n" as *u8)
41 cw("FNRES sgn " as *u8); cn(f2); cw(" 2\n" as *u8)
42 cw("FNRES dbl " as *u8); cn(f3); cw(" 2\n" as *u8)
43 cw("CGR=" as *u8); cn(p); cw("\n" as *u8)
44 return 0
45}