code wiki / (root) / nx_research_pool.nx

nx_research_pool.nx source

↩ module page · 49 lines · 3226 B

1// nx_research_pool.nx -- GATE for the engine's folded-in R2+R3 (rf_slot_* semaphore + polite rf_fetch_bank). 2// The bounded-parallel + polite logic now lives IN nx_research_engine, so EVERY researcher inherits it (DRY); 3// this organ is the gate that PROVES it: resource-sized slots, O_EXCL exclusion, acquire/release, polite fetch. 4// (Was the R2/R3 prototype; superseded once the mechanism was folded into the engine.) 5// license_tier: ORIGINAL expect_exit: 0 6import "nx_research_engine.nx" 7const K_MAGIC_8388608: i64 = 8388608 8 9func gp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 10func gn(v: i64) -> i64 { let b: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0} 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 } 11 12func main() -> i64 { 13 let store: *TrustStore = rf_init() 14 if (store as i64) == 0 { gp("rp-gate: trust load failed\n" as *u8); return 1 } 15 let dir: *u8 = "knowledge/status/research_slots" as *u8 16 sys_mkdir(dir, 0x1ed) 17 let n: i64 = rf_nslots() 18 gp("=== nx_research_pool GATE -- engine R2+R3 (polite + bounded-parallel) ===\n" as *u8) 19 gp("free_mb=" as *u8); gn(rf_free_mb()); gp(" concurrency slots N=" as *u8); gn(n); gp("\n" as *u8) 20 var pass: i64 = 0; var total: i64 = 0 21 22 // T1: resource sizing sane (1..MAX) 23 var t1: i64 = 0; if n >= 1 { t1 = 1 } 24 total=total+1; if t1==1 { pass=pass+1; gp(" PASS T1 slots sized 1..MAX\n" as *u8) } else { gp(" FAIL T1\n" as *u8) } 25 26 // T2: O_EXCL exclusion -- a 2nd lock on the SAME slot must be DENIED (this is what bounds concurrency) 27 let p: *u8 = sys_mmap(512); rf_slotpath(dir, 0, p) 28 let a: i64 = rf_slot_lock(p) 29 let b: i64 = rf_slot_lock(p) 30 var t2: i64 = 0; if a >= 0 { if b < 0 { t2 = 1 } } 31 if a >= 0 { sys_close(a); rf_unlink(p) } 32 if b >= 0 { sys_close(b) } 33 total=total+1; if t2==1 { pass=pass+1; gp(" PASS T2 O_EXCL slot exclusion (2nd acquire denied)\n" as *u8) } else { gp(" FAIL T2\n" as *u8) } 34 35 // T3: acquire/release roundtrip through the semaphore 36 let idx: *i64 = sys_mmap(16) as *i64 37 let fd: i64 = rf_slot_acquire(dir, n, idx) 38 var t3: i64 = 0; if fd >= 0 { t3 = 1; rf_slot_release(dir, idx[0], fd) } 39 total=total+1; if t3==1 { pass=pass+1; gp(" PASS T3 acquire/release roundtrip (slot " as *u8); gn(idx[0]); gp(")\n" as *u8) } else { gp(" FAIL T3\n" as *u8) } 40 41 // T4: a real POLITE fetch through the now-bounded rf_fetch_bank (fresh name -> exercises the slot fetch path) 42 let cap: i64 = K_MAGIC_8388608; let out: *u8 = sys_mmap(cap) 43 let r: i64 = rf_fetch_bank("https://en.wikipedia.org/wiki/Bulkhead_(software)" as *u8, "rp_gate_r6b" as *u8, store, out, cap) 44 total=total+1; if r==1 { pass=pass+1; gp(" PASS T4 polite fetch through a slot -> banked\n" as *u8) } else { gp(" FAIL T4 fetch\n" as *u8) } 45 46 gp("---- nx_research_pool GATE: " as *u8); gn(pass); gp(" / " as *u8); gn(total); gp(" ----\n" as *u8) 47 if pass==total { gp("verdict=GREEN (engine R2+R3 polite + bounded-parallel fetch validated)\n" as *u8); return 0 } 48 gp("verdict=RED\n" as *u8); return 1 49}