code wiki / _hdl_build / nx_cascade_gate.nx
nx_cascade_gate.nx source
↩ module page · 72 lines · 4668 B
1// nx_cascade_gate.nx -- GATE: the second-life cascade marketplace on a solar panel (30-year life). Tiers:
2// 0 Wealthy/DataCenter (8 yrs, pays $300) -> upgrades for efficiency, passes the panel down
3// 1 MiddleClass (10 yrs, pays $100, gov-subsidized transfer)
4// 2 Poor/Schools/NonProfit (12 yrs, free, gov + non-profit)
5// T1 FULL LIFE -- 8+10+12 = 30 years used = the panel's whole life.
6// T2 NO WASTE -- cascade utilization = 1000 permil vs 266 if scrapped after tier 0 (the waste avoided).
7// T3 PRICE DROPS -- $300 -> $100 -> $0: hardware gets cheaper / free down the cascade.
8// T4 ENERGY DECLINES -- per-year cost 3750c -> 1000c -> 0c: energy continually cheaper for those below, while the top upgrades.
9// T5 WIN-WIN-WIN -- 3 tiers served, top upgraded, zero scrap.
10// T6 NEVER-BRICK -- deterministic.
11// GREEN iff all. Sovereign nx_cc->nxasm. expect_exit: 0 license_tier: ORIGINAL
12import "nx_cascade.nx"
13import "nx_syscalls.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_cascade_gate: second-life CASCADE marketplace (solar panel; wealthy -> middle -> poor) ===\n" as *u8)
20 var pass: i64 = 0; var total: i64 = 0
21 let n: i64 = 3
22 let nm: *i64=sys_mmap(8*4) as *i64
23 let years: *i64=sys_mmap(8*4) as *i64
24 let price: *i64=sys_mmap(8*4) as *i64
25 nm[0]="Wealthy/DataCenter" as *u8 as i64; years[0]=8; price[0]=30000
26 nm[1]="MiddleClass" as *u8 as i64; years[1]=10; price[1]=10000
27 nm[2]="Poor/Schools/NonProfit" as *u8 as i64; years[2]=12; price[2]=0
28 let full: i64 = 30
29
30 // emit the cascade
31 w(" --- CASCADE (tier: years used / price / per-year cost) ---\n" as *u8)
32 var i: i64 = 0
33 while i < n {
34 w(" " as *u8); w(nm[i] as *u8); w(" " as *u8); wn(years[i]); w("yr $" as *u8); wn(price[i]/100); w(" " as *u8); wn(casc_annual_cost(price[i], years[i])); w("c/yr\n" as *u8)
35 i = i + 1
36 }
37
38 // T1 full life
39 let used: i64 = casc_total_years(years, n)
40 total=total+1; if used==30 { pass=pass+1; w(" [PASS] " as *u8) } else { w(" [FAIL] " as *u8) }
41 w("T1 full life used = " as *u8); wn(used); w(" years (8+10+12 = the whole 30-yr panel)\n" as *u8)
42
43 // T2 no waste
44 let util: i64 = casc_util_permil(used, full)
45 let scrap: i64 = casc_util_permil(years[0], full)
46 total=total+1; if util==1000 { if scrap==266 { pass=pass+1; w(" [PASS] " as *u8) } else { w(" [FAIL] " as *u8) } } else { w(" [FAIL] " as *u8) }
47 w("T2 utilization = " as *u8); wn(util); w(" permil (cascade) vs " as *u8); wn(scrap); w(" if scrapped after tier 0 (waste avoided)\n" as *u8)
48
49 // T3 price drops
50 total=total+1; if price[0]>price[1] { if price[1]>price[2] { pass=pass+1; w(" [PASS] " as *u8) } else { w(" [FAIL] " as *u8) } } else { w(" [FAIL] " as *u8) }
51 w("T3 price cascade: $300 -> $100 -> $0 (hardware cheaper/free down the tiers)\n" as *u8)
52
53 // T4 energy declines
54 let a0: i64 = casc_annual_cost(price[0], years[0])
55 let a1: i64 = casc_annual_cost(price[1], years[1])
56 let a2: i64 = casc_annual_cost(price[2], years[2])
57 total=total+1; if a0==3750 { if a1==1000 { if a2==0 { pass=pass+1; w(" [PASS] " as *u8) } else { w(" [FAIL] " as *u8) } } else { w(" [FAIL] " as *u8) } } else { w(" [FAIL] " as *u8) }
58 w("T4 per-year cost: " as *u8); wn(a0); w(" -> " as *u8); wn(a1); w(" -> " as *u8); wn(a2); w("c/yr (energy continually declines below; top upgrades)\n" as *u8)
59
60 // T5 win-win-win
61 total=total+1; if n==3 { if util > scrap { pass=pass+1; w(" [PASS] " as *u8) } else { w(" [FAIL] " as *u8) } } else { w(" [FAIL] " as *u8) }
62 w("T5 WIN-WIN-WIN: " as *u8); wn(n); w(" tiers served, top upgraded, zero scrap (gov-facilitated)\n" as *u8)
63
64 // T6 never-brick
65 let u2: i64 = casc_util_permil(casc_total_years(years, n), full)
66 total=total+1; if u2==util { pass=pass+1; w(" [PASS] " as *u8) } else { w(" [FAIL] " as *u8) }
67 w("T6 never-brick: deterministic (" as *u8); wn(u2); w("==" as *u8); wn(util); w(")\n" as *u8)
68
69 w("\n=== nx_cascade_gate " as *u8); wn(pass); w("/" as *u8); wn(total)
70 if pass == total { w(" GREEN (second-life cascade: full-life utilization, declining cost per tier, win-win-win across wealth tiers)\n" as *u8); sys_exit(0); return 0 }
71 w(" RED\n" as *u8); sys_exit(1); return 1
72}