code wiki / _hdl_build / nx_assembly_gate.nx
nx_assembly_gate.nx source
↩ module page · 103 lines · 6632 B
1// nx_assembly_gate.nx -- GATE: a whole-PRODUCT digital twin -- a REFRIGERATOR, modeled as an assembly tree from the
2// real supply chain, with the nx_bom PCB control board composed in as a subsystem.
3// T1 EFF COUNTS -- the assembly multiplies correctly (2 doors -> effective count 2).
4// T2 ROLLED COST -- exact total bill of materials = 14005 cents ($140.05), summed over the whole tree.
5// T3 ROLLED MASS -- exact total mass = 46950 g (46.95 kg).
6// T4 PART COUNT -- 9 real parts.
7// T5 SOURCEABLE -- all parts in stock -> 0 shortfalls; dropping door stock to 1 (need 2) -> a real shortfall (liar-kill).
8// T6 COMPOSE PCB -- the control board cost = the nx_bom PCB twin (the PCB is a SUBSYSTEM of the fridge).
9// GREEN iff all. Sovereign nx_cc->nxasm. The same engine scales to a car (a bigger tree). expect_exit: 0 license_tier: ORIGINAL
10import "nx_assembly.nx"
11import "nx_bom.nx"
12import "nx_syscalls.nx"
13import "nx_gate_verdict.nx"
14
15func w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
16func wn(v: i64) -> i64 { var m: i64=v; if m<0{w("-" as *u8);m=0-m} let t:*u8=sys_mmap(24); 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; let o:*u8=sys_mmap(24); while i<k{o[i]=t[k-1-i];i=i+1} sys_write(1,o,k); return 0 }
17
18func main() -> i64 {
19 w("=== nx_assembly_gate: whole-product DIGITAL TWIN -- a REFRIGERATOR from the real supply chain ===\n" as *u8)
20 var pass: i64 = 0; var total: i64 = 0
21
22 // control board cost = the nx_bom PCB twin (MCU + 2 resistors + 1 cap)
23 let cb_price: *i64=sys_mmap(8*4) as *i64; cb_price[0]=200; cb_price[1]=1; cb_price[2]=3
24 let cb_comp: *i64=sys_mmap(8*8) as *i64; cb_comp[0]=0; cb_comp[1]=1; cb_comp[2]=1; cb_comp[3]=2
25 let cb_cost: i64 = bom_total_cents(cb_comp, 4, cb_price, 3) // 200 + 1 + 1 + 3 = 205
26
27 let n: i64 = 11
28 let nm: *i64=sys_mmap(8*16) as *i64
29 let parent: *i64=sys_mmap(8*16) as *i64
30 let qty: *i64=sys_mmap(8*16) as *i64
31 let leaf: *i64=sys_mmap(8*16) as *i64
32 let cost: *i64=sys_mmap(8*16) as *i64
33 let mass: *i64=sys_mmap(8*16) as *i64
34 let stock: *i64=sys_mmap(8*16) as *i64
35
36 nm[0]="Refrigerator" as *u8 as i64; parent[0]=0-1; qty[0]=1; leaf[0]=0; cost[0]=0; mass[0]=0; stock[0]=999999
37 nm[1]="RefrigerationSystem" as *u8 as i64; parent[1]=0; qty[1]=1; leaf[1]=0; cost[1]=0; mass[1]=0; stock[1]=999999
38 nm[2]="Compressor" as *u8 as i64; parent[2]=1; qty[2]=1; leaf[2]=1; cost[2]=4500; mass[2]=8000; stock[2]=100
39 nm[3]="CondenserCoil" as *u8 as i64; parent[3]=1; qty[3]=1; leaf[3]=1; cost[3]=1200; mass[3]=1500; stock[3]=100
40 nm[4]="Evaporator" as *u8 as i64; parent[4]=1; qty[4]=1; leaf[4]=1; cost[4]=1000; mass[4]=1200; stock[4]=100
41 nm[5]="Refrigerant-R600a" as *u8 as i64; parent[5]=1; qty[5]=1; leaf[5]=1; cost[5]=300; mass[5]=50; stock[5]=100
42 nm[6]="Cabinet" as *u8 as i64; parent[6]=0; qty[6]=1; leaf[6]=0; cost[6]=0; mass[6]=0; stock[6]=999999
43 nm[7]="SteelShell" as *u8 as i64; parent[7]=6; qty[7]=1; leaf[7]=1; cost[7]=3000; mass[7]=25000; stock[7]=100
44 nm[8]="InsulationFoam" as *u8 as i64; parent[8]=6; qty[8]=1; leaf[8]=1; cost[8]=800; mass[8]=3000; stock[8]=100
45 nm[9]="Door" as *u8 as i64; parent[9]=6; qty[9]=2; leaf[9]=1; cost[9]=1500; mass[9]=4000; stock[9]=100
46 nm[10]="ControlBoard(PCB)" as *u8 as i64; parent[10]=0; qty[10]=1; leaf[10]=1; cost[10]=cb_cost; mass[10]=200; stock[10]=100
47
48 let eff: *i64=sys_mmap(8*16) as *i64
49 asm_eff_count(parent, qty, n, eff)
50
51 // emit the BOM tree
52 w(" --- PRODUCT BOM (effective qty x unit cost) ---\n" as *u8)
53 var i: i64 = 0
54 while i < n {
55 if leaf[i] == 1 {
56 w(" " as *u8); w(nm[i] as *u8); w(" x" as *u8); wn(eff[i]); w(" @" as *u8); wn(cost[i]); w("c = " as *u8); wn(eff[i]*cost[i]); w("c\n" as *u8)
57 }
58 i = i + 1
59 }
60 let tcost: i64 = asm_total(eff, cost, leaf, n)
61 let tmass: i64 = asm_total(eff, mass, leaf, n)
62 let tparts: i64 = asm_part_count(eff, leaf, n)
63 w(" TOTAL cost=" as *u8); wn(tcost); w("c mass=" as *u8); wn(tmass); w("g parts=" as *u8); wn(tparts); w("\n" as *u8)
64
65 // T1 eff counts
66 total=total+1; if eff[9]==2 { if eff[2]==1 { pass=pass+1; w(" [PASS] " as *u8) } else { w(" [FAIL] " as *u8) } } else { w(" [FAIL] " as *u8) }
67 w("T1 eff counts: door=" as *u8); wn(eff[9]); w(" compressor=" as *u8); wn(eff[2]); w("\n" as *u8)
68
69 // T2 rolled cost
70 total=total+1; if tcost==14005 { pass=pass+1; w(" [PASS] " as *u8) } else { w(" [FAIL] " as *u8) }
71 w("T2 rolled cost: " as *u8); wn(tcost); w(" cents ($140.05, exact tree sum)\n" as *u8)
72
73 // T3 rolled mass
74 total=total+1; if tmass==46950 { pass=pass+1; w(" [PASS] " as *u8) } else { w(" [FAIL] " as *u8) }
75 w("T3 rolled mass: " as *u8); wn(tmass); w(" g (46.95 kg)\n" as *u8)
76
77 // T4 part count
78 total=total+1; if tparts==9 { pass=pass+1; w(" [PASS] " as *u8) } else { w(" [FAIL] " as *u8) }
79 w("T4 part count: " as *u8); wn(tparts); w(" real parts\n" as *u8)
80
81 // T5 sourceable + liar-kill
82 let sf0: i64 = asm_shortfalls(eff, stock, leaf, n)
83 stock[9] = 1
84 let sf1: i64 = asm_shortfalls(eff, stock, leaf, n)
85 stock[9] = 100
86 total=total+1; if sf0==0 { if sf1>0 { pass=pass+1; w(" [PASS] " as *u8) } else { w(" [FAIL] " as *u8) } } else { w(" [FAIL] " as *u8) }
87 w("T5 sourceable: shortfalls=" as *u8); wn(sf0); w(" ; with door stock=1 (need 2) -> " as *u8); wn(sf1); w(" (real supply risk)\n" as *u8)
88
89 // T6 compose the PCB twin
90 total=total+1; if cb_cost==205 { pass=pass+1; w(" [PASS] " as *u8) } else { w(" [FAIL] " as *u8) }
91 w("T6 compose PCB: control board cost=" as *u8); wn(cb_cost); w("c from the nx_bom PCB twin (a subsystem of the fridge)\n" as *u8)
92
93 w("\n=== nx_assembly_gate " as *u8); wn(pass); w("/" as *u8); wn(total)
94 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
95 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
96 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
97 let ctr__dry: *i64 = gv_ctr()
98 ctr__dry[0] = pass
99 ctr__dry[1] = total
100 let rc__dry: i64 = gv_verdict("ASSEMBLY-GATE" as *u8, ctr__dry, "whole-product digital twin: hierarchical real supply-chain rollup, exact cost/mass/parts, composes the PCB twin; scales to a car)" as *u8)
101 sys_exit(rc__dry)
102 return rc__dry
103}