code wiki / (root) / nx_ccheck.nx

nx_ccheck.nx source

↩ module page · 48 lines · 2736 B

1// nx_ccheck.nx -- sovereign COMPILE-CHECK for the WRITING HUB. Operator 2026-07-01: "build into the nishi 2// ecosystem the required functionality." The Nishi shell / nx_sov_build_run can build+run any organ, but a 3// DAEMON (nx_writer_serve) would run+block -- so there was no way to just ASK "does this source compile?". 4// This is that tool: for each target it fork+execs nx_cc_sovereign on runtime/<name>.nx, DUPs the child's 5// stdout to a drained pipe (so the ~125k-line asm never floods), reaps the real EXIT code, and prints 6// CC-OK / CC-FAIL (compiler errors still hit stderr, visible). NO-ARG so nx_sov_build_run drives it directly. 7// license_tier: ORIGINAL module: nishi-core.tools.ccheck 8import "nx_syscalls.nx" 9const K_MAGIC_65536: i64 = 65536 10 11func cp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 12 13// compile-check runtime/<name>.nx; return 0 = OK, 1 = FAIL 14func cc_one(name: *u8) -> i64 { 15 let path: *u8 = sys_mmap(512); var o: i64=0 16 let pre: *u8 = "runtime/" as *u8; var i: i64=0; while pre[i]!=(0 as u8){ path[o]=pre[i]; o=o+1; i=i+1 } 17 i=0; while name[i]!=(0 as u8){ path[o]=name[i]; o=o+1; i=i+1 } 18 let suf: *u8 = ".nx" as *u8; i=0; while suf[i]!=(0 as u8){ path[o]=suf[i]; o=o+1; i=i+1 } 19 path[o]=0 as u8 20 let av: *i64 = sys_mmap(4*8) as *i64 21 av[0] = "_offc/nx_cc_sovereign.elf" as *u8 as i64 22 av[1] = path as i64 23 av[2] = 0 24 let pb: *i64 = sys_mmap(16); sys_pipe2(pb, 0) 25 let rfd: i64 = pb[0] & 0xFFFFFFFF 26 let wfd: i64 = (pb[0] >> 32) & 0xFFFFFFFF 27 let pid: i64 = sys_fork() 28 if pid==0 { sys_dup3(wfd, 1, 0); sys_close(rfd); sys_close(wfd); sys_execve("_offc/nx_cc_sovereign.elf" as *u8, av, 0 as *i64); sys_exit(127); return 0 } 29 sys_close(wfd) 30 let buf: *u8 = sys_mmap(K_MAGIC_65536); var go: i64=1 31 while go==1 { let k: i64=sys_read(rfd, buf, K_MAGIC_65536); if k<=0 { go=0 } } 32 sys_close(rfd) 33 let st: *i64 = sys_mmap(8); sys_wait4(pid, st, 0); let rc: i64 = wait_exit_code(st[0]) 34 cp(" CC " as *u8); cp(name) 35 if rc==0 { cp(" -> CC-OK\n" as *u8); return 0 } 36 cp(" -> CC-FAIL (nx_cc_sovereign exit != 0 -- see stderr above)\n" as *u8) 37 return 1 38} 39 40func main() -> i64 { 41 cp("=== nx_ccheck: writing-hub compile-check (asm suppressed; verifies the daemon nx_sov_build_run cannot) ===\n" as *u8) 42 var fail: i64 = 0 43 fail = fail + cc_one("nx_writehub_score" as *u8) 44 fail = fail + cc_one("nx_writehub_factlib" as *u8) 45 fail = fail + cc_one("nx_writer_serve" as *u8) 46 if fail==0 { cp("verdict=GREEN (all writing-hub sources compile)\n" as *u8); sys_exit(0); return 0 } 47 cp("verdict=RED (a source failed to compile -- fix before deploy)\n" as *u8); sys_exit(1); return 1 48}