code wiki / _hdl_build / nx_builder_compose_test.nx
nx_builder_compose_test.nx source
↩ module page · 42 lines · 3404 B
1// nx_builder_compose_test.nx -- the Builder AUTHORS the build-cache's core flows by composition (not
2// Claude). PATH->HASH (the content-hash key) = [READ, SHA256]; PATH->BINARY (build) = [READ, COMPILE].
3// Each is found by the Builder's type-chain search + verified by the Engineer. An impossible target is
4// honestly un-authorable. Exit 0 on 6/6. license_tier: ORIGINAL
5
6import "nx_builder_compose.nx"
7import "nx_syscalls.nx"
8
9func bt_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
10func bt_num(v: i64) -> i64 { let bb: *u8 = sys_mmap(28); var m: i64=v; if m<0 {m=0-m;sys_write(1,"-" as *u8,1)}; let t: *u8 = sys_mmap(28); var k: i64=0; if m==0 {t[0]=48;k=1}; while m>0 {t[k]=48+(m%10); m=m/10; k=k+1}; var i: i64=0; while i<k {bb[i]=t[k-1-i]; i=i+1}; sys_write(1, bb, k); return 0 }
11
12func main() -> i64 {
13 bt_puts("=== BUILDER synthesizes code: author the build-cache flows by composition ===\n" as *u8)
14 // the Builder authors: content-hash key = PATH -> HASH
15 let s1: *i64 = sys_mmap(8*8) as *i64
16 let n1: i64 = bc_compose(BC_T_PATH, BC_T_HASH, s1, 6)
17 let v1: i64 = bc_valid(s1, n1, BC_T_PATH, BC_T_HASH)
18 // the Builder authors: build = PATH -> BINARY
19 let s2: *i64 = sys_mmap(8*8) as *i64
20 let n2: i64 = bc_compose(BC_T_PATH, BC_T_BINARY, s2, 6)
21 let v2: i64 = bc_valid(s2, n2, BC_T_PATH, BC_T_BINARY)
22 // an impossible target (no primitive yields it from a path)
23 let s3: *i64 = sys_mmap(8*8) as *i64
24 let n3: i64 = bc_compose(BC_T_HASH, BC_T_PATH, s3, 6) // HASH -> PATH: no primitive does this
25
26 bt_puts(" Builder authored PATH->HASH: len=" as *u8); bt_num(n1); bt_puts(" [" as *u8); var i: i64=0; while i<n1 { bt_num(s1[i]); if i<n1-1 { bt_puts("," as *u8) } i=i+1 } bt_puts("] (1=READ 2=SHA256) valid=" as *u8); bt_num(v1); bt_puts("\n" as *u8)
27 bt_puts(" Builder authored PATH->BINARY: len=" as *u8); bt_num(n2); bt_puts(" [" as *u8); i=0; while i<n2 { bt_num(s2[i]); if i<n2-1 { bt_puts("," as *u8) } i=i+1 } bt_puts("] (1=READ 3=COMPILE) valid=" as *u8); bt_num(v2); bt_puts("\n" as *u8)
28 bt_puts(" impossible HASH->PATH: len=" as *u8); bt_num(n3); bt_puts(" (-1=cannot author, honest)\n" as *u8)
29
30 let r: *i64 = sys_mmap(8*8) as *i64
31 r[0] = 0; if n1 == 2 { if s1[0] == BC_P_READ { if s1[1] == BC_P_SHA256 { r[0] = 1 } } } // authored [READ,SHA256]
32 r[1] = 0; if v1 == 1 { r[1] = 1 } // type-chains (Engineer-verified)
33 r[2] = 0; if n2 == 2 { if s2[0] == BC_P_READ { if s2[1] == BC_P_COMPILE { r[2] = 1 } } } // authored [READ,COMPILE]
34 r[3] = 0; if v2 == 1 { r[3] = 1 }
35 r[4] = 0; if n3 == 0 - 1 { r[4] = 1 } // honest: cannot author the impossible
36 r[5] = 0; if bc_valid(s1, 1, BC_T_PATH, BC_T_HASH) == 0 { r[5] = 1 } // a wrong/short chain is rejected
37 var pass: i64 = 0; i = 0
38 while i < 6 { pass = pass + r[i]; i = i + 1 }
39 bt_puts("----\n passed " as *u8); bt_num(pass); bt_puts("/6\n" as *u8)
40 if pass == 6 { bt_puts(" BUILDER BUILT IT: the Builder's search AUTHORED the build-cache flows by composing the team's primitives (READ->SHA256, READ->COMPILE) -- who wrote the code? the Builder did. Honest: composing KNOWN primitives; authoring a NEW primitive is still the LLM-gap.\n" as *u8); sys_exit(0); return 0 }
41 bt_puts(" FAIL\n" as *u8); sys_exit(1); return 1
42}