code wiki / _hdl_build / nx_g_pn_lite_lib.nx

nx_g_pn_lite_lib.nx source

↩ module page · 22 lines · 1479 B

1// nx_g_pn_lite_lib.nx -- single-responsibility g_pn LITE variant (no negative-number branch). 2// NX-ITOA-NEGATIVE-FREE-BY-DESIGN -- read by nx_itoaclone, which otherwise flags every emitter lacking a 3// sign branch. The omission HERE is the entire point of the file: nx_g_pn_lib is the superset WITH the 4// branch, this is the deliberate subset, and a superset self-check already refuses one for the other. 5// ★★WHETHER A MISSING NEGATIVE BRANCH IS A DEFECT OR THE DESIGN IS A CONTRACT QUESTION, AND NO SCANNER 6// CAN ANSWER IT -- so the intent is DECLARED here in the source where it is checkable, exactly as 7// organ_kind.conf declares an organ's kind rather than letting a name-suffix classifier guess. 8// ⚠DO NOT "fix" this by adding a sign branch: that collapses the subset/superset pair this file exists 9// to express, and the census would lose the distinction it is now able to report. 10// This is the SUBSET body that nx_g_pn_lib's superset self-check refuses; files carrying it delegate HERE 11// (behavior-identical for their non-negative usage - the ONLY difference is negatives, which gate counts never are). 12// license_tier: ORIGINAL 13import "nx_syscalls.nx" 14func g_pn(v: i64) -> i64 { 15 let b: *u8 = sys_mmap(28); var x: i64 = v 16 if x == 0 { b[0]=48; sys_write(1,b,1); return 0 } 17 var d: i64=0; var y: i64=x 18 while y>0 { d=d+1; y=y/10 } 19 var i: i64=d-1; y=x 20 while i>=0 { b[i]=(48+(y%10)) as u8; y=y/10; i=i-1 } 21 sys_write(1,b,d); return 0 22}