code wiki / (root) / nx_gate.nx

nx_gate.nx source

↩ module page · 23 lines · 1122 B

1// nx_gate.nx -- canonical gate I/O. ONE definition of the gate stdout helpers (gw/gn/gwb), replacing the ~23 ad-hoc 2// copies scattered across runtime gates. Imports the CANONICAL syscall surface (nx_syscalls.nx), not the syscalls.nx 3// alias -- part of retiring alias-juggling. A gate imports this and writes results; it never re-rolls gw/gn again. 4// license_tier: ORIGINAL 5import "nx_syscalls.nx" 6 7// write a NUL-terminated string to stdout 8func gw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 9 10// write a signed decimal i64 to stdout 11func gn(v: i64) -> i64 { 12 if v==0 { sys_write(1,"0" as *u8,1); return 0 } 13 var m: i64=v 14 if m<0 { sys_write(1,"-" as *u8,1); m=0-m } 15 let t: *u8=sys_mmap(24); var k: i64=0 16 while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } 17 let o: *u8=sys_mmap(24); var w: i64=0; var q: i64=k-1 18 while q>=0 { o[w]=t[q]; w=w+1; q=q-1 } 19 sys_write(1,o,w); return 0 20} 21 22// write raw bytes buf[off..off+len) to stdout 23func gwb(buf: *u8, off: i64, len: i64) -> i64 { if len>0 { sys_write(1, ((buf as i64)+off) as *u8, len) } return 0 }