code wiki / _hdl_build / nx_bom_hb.nx

nx_bom_hb.nx source

↩ module page · 39 lines · 1735 B

1// nx_bom.nx -- LIB: component library + supply-chain BILL OF MATERIALS, as a digital twin of real procurement. 2// A parts library carries REAL data per part (mfr part number, unit price in CENTS, available stock). A design maps 3// each component instance to a library part; the BOM aggregates by part -> quantity + extended cost, sums an EXACT 4// integer total (no float rounding -> what you'd really pay), and flags supply-chain SHORTFALLS (required qty > 5// stock = can't source). Composes the schematic's component list (schematic -> ... -> BOM). Data-driven: adding a 6// part = a library row. never-brick #26: pure arithmetic, bounded, deterministic. license_tier: ORIGINAL 7import "nx_syscalls.nx" 8 9// quantity of a given library part used across the design's component instances. 10func bom_qty(comp_part: *i64, ncomp: i64, part: i64) -> i64 { 11 var c: i64 = 0 12 var i: i64 = 0 13 while i < ncomp { if comp_part[i] == part { c = c + 1 } i = i + 1 } 14 return c 15} 16 17// EXACT total BOM cost in cents = sum over parts of qty * unit_price_cents. 18func bom_total_cents(comp_part: *i64, ncomp: i64, lib_price: *i64, nlib: i64) -> i64 { 19 var total: i64 = 0 20 var p: i64 = 0 21 while p < nlib { 22 let qty: i64 = bom_qty(comp_part, ncomp, p) 23 total = total + qty * lib_price[p] 24 p = p + 1 25 } 26 return total 27} 28 29// supply-chain shortfalls: number of parts whose required qty EXCEEDS available stock (0 = fully sourceable). 30func bom_shortfalls(comp_part: *i64, ncomp: i64, lib_stock: *i64, nlib: i64) -> i64 { 31 var sf: i64 = 0 32 var p: i64 = 0 33 while p < nlib { 34 let qty: i64 = bom_qty(comp_part, ncomp, p) 35 if qty > lib_stock[p] { sf = sf + 1 } 36 p = p + 1 37 } 38 return sf 39}