code wiki / (root) / nx_autofix_candidate2.nx

nx_autofix_candidate2.nx source

↩ module page · 47 lines · 1996 B

1// nx_autofix_candidate2.nx -- richer "code under repair" for the SELF-LOCALIZING fix loop 2// (nx_autofix_auto). Unlike candidate 1 (one function, aggregate score only), this one grades EACH 3// function and emits per-function FNRES rows -- so the loop can DISCOVER which function is broken 4// instead of being told. SEEDED BUG: sgn() ignores its input (returns 0) -> FNRES sgn 1 3. 5// sgn is deliberately NOT one of the fixer's few-shot examples (min2/abs1) -- a green fix here is the 6// model's own completion, not a template lookup. Output: FNRES <name> <passed> <total> per function, 7// then the aggregate CGR=<total-passed> the existing graders parse. license_tier: ORIGINAL 8import "nx_syscalls.nx" 9 10func cw(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 11func cn(v: i64) -> i64 { 12 var m: i64 = v 13 if m < 0 { cw("-" as *u8); m = 0 - m } 14 let t: *u8 = sys_mmap(24) 15 var k: i64 = 0 16 if m == 0 { t[0] = 48 as u8; k = 1 } 17 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 18 let o: *u8 = sys_mmap(24) 19 var i: i64 = 0 20 while i < k { o[i] = t[k - 1 - i]; i = i + 1 } 21 sys_write(1, o, k) 22 return 0 23} 24 25func max2(a: i64, b: i64) -> i64 { if a > b { return a } return b } 26func min2(a: i64, b: i64) -> i64 { if a < b { return a } return b } 27func sgn(x: i64) -> i64 { return 0 } 28 29func main() -> i64 { 30 var p: i64 = 0 31 var f1: i64 = 0 32 if max2(3, 5) == 5 { f1 = f1 + 1 } 33 if max2(7, 2) == 7 { f1 = f1 + 1 } 34 var f2: i64 = 0 35 if min2(3, 5) == 3 { f2 = f2 + 1 } 36 if min2(7, 2) == 2 { f2 = f2 + 1 } 37 var f3: i64 = 0 38 if sgn(5) == 1 { f3 = f3 + 1 } 39 if sgn(0 - 3) == (0 - 1) { f3 = f3 + 1 } 40 if sgn(0) == 0 { f3 = f3 + 1 } 41 p = f1 + f2 + f3 42 cw("FNRES max2 " as *u8); cn(f1); cw(" 2\n" as *u8) 43 cw("FNRES min2 " as *u8); cn(f2); cw(" 2\n" as *u8) 44 cw("FNRES sgn " as *u8); cn(f3); cw(" 3\n" as *u8) 45 cw("CGR=" as *u8); cn(p); cw("\n" as *u8) 46 return 0 47}