code wiki / (root) / nx_autofix_candidate4.nx

nx_autofix_candidate4.nx source

↩ module page · 51 lines · 2272 B

1// nx_autofix_candidate4.nx -- third self-localizing candidate, one rung HARDER: the seeded bug is 2// SEMANTIC and only PARTIALLY failing. absdiff() returns a-b, which passes absdiff(7,3)=4 and 3// absdiff(5,5)=0 but fails absdiff(3,7) with -4 -- so a fixer that only pattern-matches "function 4// broken -> rewrite from name" has less to go on, and the repair needs order-aware logic. To support 5// this, the output contract adds FNCASE rows for FAILING cases only: 6// FNCASE <fn> <in1> <in2> want <w> got <g> 7// The auto loop feeds those rows verbatim to the local maker = pure machine feedback (no Claude 8// authorship anywhere in the prompt content). FNRES + CGR stay as before. license_tier: ORIGINAL 9import "nx_syscalls.nx" 10 11func cw(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 12func cn(v: i64) -> i64 { 13 var m: i64 = v 14 if m < 0 { cw("-" as *u8); m = 0 - m } 15 let t: *u8 = sys_mmap(24) 16 var k: i64 = 0 17 if m == 0 { t[0] = 48 as u8; k = 1 } 18 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 19 let o: *u8 = sys_mmap(24) 20 var i: i64 = 0 21 while i < k { o[i] = t[k - 1 - i]; i = i + 1 } 22 sys_write(1, o, k) 23 return 0 24} 25func fncase(fn: *u8, a: i64, b: i64, want: i64, got: i64) -> i64 { 26 cw("FNCASE " as *u8); cw(fn); cw(" " as *u8); cn(a); cw(" " as *u8); cn(b) 27 cw(" want " as *u8); cn(want); cw(" got " as *u8); cn(got); cw("\n" as *u8) 28 return 0 29} 30 31func max2(a: i64, b: i64) -> i64 { if a > b { return a } return b } 32func absdiff(a: i64, b: i64) -> i64 { return a - b } 33 34func main() -> i64 { 35 var p: i64 = 0 36 var f1: i64 = 0 37 if max2(3, 5) == 5 { f1 = f1 + 1 } 38 if max2(7, 2) == 7 { f1 = f1 + 1 } 39 var f2: i64 = 0 40 let c1: i64 = absdiff(7, 3) 41 if c1 == 4 { f2 = f2 + 1 } else { fncase("absdiff" as *u8, 7, 3, 4, c1) } 42 let c2: i64 = absdiff(3, 7) 43 if c2 == 4 { f2 = f2 + 1 } else { fncase("absdiff" as *u8, 3, 7, 4, c2) } 44 let c3: i64 = absdiff(5, 5) 45 if c3 == 0 { f2 = f2 + 1 } else { fncase("absdiff" as *u8, 5, 5, 0, c3) } 46 p = f1 + f2 47 cw("FNRES max2 " as *u8); cn(f1); cw(" 2\n" as *u8) 48 cw("FNRES absdiff " as *u8); cn(f2); cw(" 3\n" as *u8) 49 cw("CGR=" as *u8); cn(p); cw("\n" as *u8) 50 return 0 51}