code wiki / _hdl_build / nx_pattern_emit_netcompose_demo.nx
nx_pattern_emit_netcompose_demo.nx source
↩ module page · 58 lines · 4294 B
1// nx_pattern_emit_netcompose_demo.nx -- DEMO/GATE: the Builder runs the NETLIST_COMPOSE emitter on a spec (k=2) and
2// it AUTHORS a working K-way fabric-fold core composing the team-owned fab_append (shape 24, no Claude logic).
3// T1 author succeeds for a valid spec (k=2) and REFUSES a bad spec (k=1).
4// T2 the AUTHORED module is real compose code: contains _compose + exactly k=2 'fab_append(' calls.
5// T3 determinism: re-authoring -> byte-identical module.
6// (Building nc_authored_test via the runner then proves the AUTHORED module COMPILES + PASSES = the autonomy credit.)
7// expect_exit: 0 license_tier: ORIGINAL
8import "nx_pattern_emit_netcompose.nx"
9import "nx_syscalls.nx"
10const K_MAGIC_65536: i64 = 65536
11const K_MAGIC_16384: i64 = 16384
12
13func dw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
14func dn(v: i64) -> i64 { let b: *u8=sys_mmap(28); var m: i64=v; if m<0{sys_write(1,"-" as *u8,1);m=0-m} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 }
15func read_all(path: *u8, lenbox: *i64) -> i64 {
16 let fd: i64=sys_openat_rd(path); if fd<0 { lenbox[0]=0; return 0 }
17 let buf: *u8=sys_mmap(K_MAGIC_65536); var off: i64=0; var go: i64=1
18 while go==1 { let r: i64=sys_read(fd, ((buf as i64)+off) as *u8, K_MAGIC_16384); if r<=0 { go=0 } else { off=off+r } }
19 sys_close(fd); lenbox[0]=off; return buf as i64
20}
21func count_sub(hay: *u8, hlen: i64, needle: *u8, nlen: i64) -> i64 {
22 var cnt: i64=0; var i: i64=0
23 while i+nlen<=hlen { var j: i64=0; var eq: i64=1; while j<nlen { if hay[i+j]!=needle[j] { eq=0; j=nlen } else { j=j+1 } } if eq==1 { cnt=cnt+1 } i=i+1 }
24 return cnt
25}
26
27func main() -> i64 {
28 dw("=== nx_pattern_emit_netcompose_demo: the Builder AUTHORS a NETLIST_COMPOSE module from a spec (shape 24) ===\n" as *u8)
29 var pass: i64=0; var total: i64=0
30 let mp: *u8="runtime/_hdl_build/nc_authored.nx" as *u8
31 let tp: *u8="runtime/_hdl_build/nc_authored_test.nx" as *u8
32 let spec: *i64=sys_mmap(64) as *i64; spec[0]=2
33 let ok: i64=pe_nc_author("nc_authored" as *u8, mp, tp, spec)
34 let badspec: *i64=sys_mmap(64) as *i64; badspec[0]=1
35 let bad: i64=pe_nc_author("nc_bad" as *u8, "runtime/_hdl_build/nc_bad.nx" as *u8, "runtime/_hdl_build/nc_bad_test.nx" as *u8, badspec)
36
37 total=total+1; if ok==1 { if bad==0 { pass=pass+1; dw(" [PASS] " as *u8) } else { dw(" [FAIL] " as *u8) } } else { dw(" [FAIL] " as *u8) }
38 dw("T1 AUTHOR+RAIL: valid spec authored=" as *u8); dn(ok); dw(", bad spec (k=1) refused=" as *u8); dn(1-bad); dw("\n" as *u8)
39
40 let lb: *i64=sys_mmap(16) as *i64; let buf: *i64=read_all(mp, lb)
41 let b: *u8=buf as *u8; let blen: i64=lb[0]
42 let n_comp: i64=count_sub(b, blen, "_compose(NPI" as *u8, 12)
43 let n_app: i64=count_sub(b, blen, "fab_append(" as *u8, 11)
44 total=total+1; if n_comp>=1 { if n_app==2 { pass=pass+1; dw(" [PASS] " as *u8) } else { dw(" [FAIL] " as *u8) } } else { dw(" [FAIL] " as *u8) }
45 dw("T2 AUTHORED REAL COMPOSE: module=" as *u8); dn(blen); dw("B, _compose=" as *u8); dn(n_comp); dw(", fab_append calls x" as *u8); dn(n_app); dw(" (=k=2)\n" as *u8)
46
47 pe_nc_author("nc_authored" as *u8, "runtime/_hdl_build/nc_authored2.nx" as *u8, "runtime/_hdl_build/nc_authored2_test.nx" as *u8, spec)
48 let lb2: *i64=sys_mmap(16) as *i64; let buf2: *i64=read_all("runtime/_hdl_build/nc_authored2.nx" as *u8, lb2)
49 let b2: *u8=buf2 as *u8; var d: i64=0; if lb2[0]!=blen { d=1 }
50 var i: i64=0; while i<blen { if b[i]!=b2[i] { d=d+1 } i=i+1 }
51 total=total+1; if d==0 { pass=pass+1; dw(" [PASS] " as *u8) } else { dw(" [FAIL] " as *u8) }
52 dw("T3 DETERMINISM: re-authoring -> byte-identical module (diffs=" as *u8); dn(d); dw(")\n" as *u8)
53
54 dw("\n AUTONOMY CREDIT: shape 24 NETLIST_COMPOSE is now TEAM-AUTHORABLE -- the Builder folds K sub-fabrics via fab_append, no Claude.\n" as *u8)
55 dw("EMIT-NETCOMPOSE-DEMO verdict=" as *u8)
56 if pass==total { dw("GREEN passes=" as *u8); dn(pass); dw("/" as *u8); dn(total); dw(" END\n" as *u8); sys_exit(0); return 0 }
57 dw("RED passes=" as *u8); dn(pass); dw("/" as *u8); dn(total); dw(" END\n" as *u8); sys_exit(1); return 1
58}