code wiki / _hdl_build / nx_gate_emit_lib.nx

nx_gate_emit_lib.nx source

↩ module page · 16 lines · 975 B

1// nx_gate_emit_lib.nx -- shared gate-emit helpers (g_puts / g_pn / g_check) for the nofloat (+ other) gate 2// clusters, extracted from the byte-identical copies funcmine surfaced (g_pn x78, rule 15). Verbatim bodies 3// -> behaviour-preserving by construction (compile-clean = identical machine code). license_tier: ORIGINAL 4import "nx_syscalls.nx" 5func g_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 6func g_pn(v: i64) -> i64 { 7 let b: *u8 = sys_mmap(28); var x: i64 = v 8 if x < 0 { b[0]=45; sys_write(1,b,1); x = 0 - x } 9 if x == 0 { b[0]=48; sys_write(1,b,1); return 0 } 10 var d: i64=0; var y: i64=x 11 while y>0 { d=d+1; y=y/10 } 12 var i: i64=d-1; y=x 13 while i>=0 { b[i]=(48+(y%10)) as u8; y=y/10; i=i-1 } 14 sys_write(1,b,d); return 0 15} 16func g_check(name: *u8, cond: i64) -> i64 { if cond==1 { g_puts(" PASS " as *u8) } else { g_puts(" FAIL " as *u8) } g_puts(name); g_puts("\n" as *u8); return cond }