code wiki / _hdl_build / nx_module_author_run.nx

nx_module_author_run.nx source

↩ module page · 64 lines · 4047 B

1// nx_module_author_run.nx -- PROVE the Builder can author autonomously: emit a NEW module from a spec, 2// compile it (nx_cc), link it (gcc), RUN it, and verify it works (exit 0). If this passes, the team WROTE 3// working NishiLang code that didn't exist before -- the authoring FAIL CASE is closed for the template 4// class. NishiLang fork/exec; flags the result to the PM review log. license_tier: ORIGINAL 5 6import "nx_module_author.nx" 7import "nx_pm_review_log.nx" 8import "nx_syscalls.nx" 9 10func _puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 11func _putn(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)}; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48;k=1}; while m>0{t[k]=48+(m%10);m=m/10;k=k+1}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(1,bb,k); return 0 } 12func _exitcode(s: i64) -> i64 { return (s >> 8) & 0xff } 13func _run(path: *u8, argv: *i64, envp: *i64, redir: i64) -> i64 { 14 let pid: i64 = sys_fork() 15 if pid == 0 { if redir >= 0 { sys_dup3(redir, 1, 0) } sys_execve(path, argv, envp) sys_exit(127) } 16 let st: *i64 = sys_mmap(16) as *i64; sys_wait4(pid, st, 0); return _exitcode(st[0]) 17} 18 19func main() -> i64 { 20 _puts("=== BUILDER AUTHORS A NEW MODULE (spec -> source -> compile -> run) ===\n" as *u8) 21 let cc: *u8 = "_offc/nx_cc_known_good.elf" as *u8 22 let gcc: *u8 = "/usr/bin/gcc" as *u8 23 let src: *u8 = "runtime/_hdl_build/_authored.nx" as *u8 24 let spath: *u8 = "/tmp/_authored.s" as *u8 25 let elf: *u8 = "/tmp/_authored.elf" as *u8 26 let envp: *i64 = sys_mmap(8*4) as *i64; envp[0]="PATH=/usr/bin:/bin" as *u8 as i64; envp[1]=0 27 28 // spec for the new module: chk(a,b) = (a>=5 && b<=10); test chk(7,3) -> expect 1. 29 let consistent: i64 = ma_spec_consistent(5, 10, 7, 3, 1) 30 _puts(" spec self-check (author validates its own spec) = " as *u8); _putn(consistent); _puts("\n" as *u8) 31 if consistent != 1 { _puts(" author refuses a self-contradictory spec\n" as *u8); sys_exit(1); return 1 } 32 33 // AUTHOR: the team WRITES the new .nx module. 34 let afd: i64 = sys_openat_wr(src, 0x1a4) 35 ma_emit_validator(afd, "chk" as *u8, 5, 10, 7, 3, 1) 36 sys_close(afd) 37 _puts(" authored runtime/_hdl_build/_authored.nx (the team wrote it)\n" as *u8) 38 39 // COMPILE (nx_cc -> .s) 40 let sfd: i64 = sys_openat_wr(spath, 0x1a4) 41 let ac: *i64 = sys_mmap(8*4) as *i64; ac[0]=cc as i64; ac[1]=src as i64; ac[2]=0 42 let rc_c: i64 = _run(cc, ac, envp, sfd); sys_close(sfd) 43 // LINK (gcc -> elf) 44 let al: *i64 = sys_mmap(8*12) as *i64 45 al[0]=gcc as i64; al[1]="-nostdlib" as *u8 as i64; al[2]="-no-pie" as *u8 as i64; al[3]="-static" as *u8 as i64 46 al[4]=spath as i64; al[5]="-o" as *u8 as i64; al[6]=elf as i64; al[7]=0 47 let rc_l: i64 = _run(gcc, al, envp, 0 - 1) 48 // RUN the authored module 49 let ar: *i64 = sys_mmap(8*4) as *i64; ar[0]=elf as i64; ar[1]=0 50 let rc_r: i64 = _run(elf, ar, envp, 0 - 1) 51 _puts(" compile rc=" as *u8); _putn(rc_c); _puts(" link rc=" as *u8); _putn(rc_l); _puts(" authored-module exit=" as *u8); _putn(rc_r); _puts("\n" as *u8) 52 53 let pm: i64 = pm_open("/tmp/nishi_pm_review.log" as *u8) 54 if rc_c == 0 { if rc_l == 0 { if rc_r == 0 { 55 pm_deliverable(pm, "builder/module-author" as *u8, "autonomous authoring" as *u8, "the Builder AUTHORED a new module from a spec, compiled + ran it (exit 0) -- the authoring FAIL CASE is closed for the template class (validators/scoreboards/mappers); novel-algorithm invention remains the residual" as *u8) 56 sys_close(pm) 57 _puts(" CLOSED: the team AUTHORED + compiled + RAN a new module. Authoring is no longer a fail case for this class.\n" as *u8) 58 sys_exit(0); return 0 59 } } } 60 pm_gap(pm, "builder/module-author" as *u8, "NEEDS-LOGIC" as *u8, "authoring" as *u8, "authored module failed to compile/run -- template needs a fix" as *u8) 61 sys_close(pm) 62 _puts(" authored module did not build/run cleanly\n" as *u8) 63 sys_exit(1); return 1 64}