code wiki / _hdl_build / nx_fpga_census_store.nx

nx_fpga_census_store.nx source

↩ module page · 53 lines · 2461 B

1// nx_fpga_census_store.nx -- LIB: the FPGA-BOOT-SIM capability census in the SOVEREIGN seg-store 2// (knowledge/store/fpgacen-*, via nx_seg_store). Operator: "use the nishi ecosystem" -- the FPGA-sim rungs were 3// tracked only in Claude memory; this puts the capability ladder into the ecosystem's OWN sovereign storage + 4// census machinery (the nx_reader_census / nx_brand_census pattern). NO TSV. 5// Record schema (keys under prefix fpgacen-), TAB-separated VALUE fields (tabs are the value encoding inside the 6// content-addressed store blob, NOT a .tsv file): 7// fc:ids -> index: TAB-separated list of cell ids (the walk order) 8// fc:<id> -> id <tab> rung <tab> capability <tab> best_in_class <tab> status <tab> gate <tab> exceed_angle 9// license_tier: ORIGINAL 10import "nx_seg_store.nx" 11import "nx_syscalls.nx" 12 13const FC_PREFIX: *u8 = "knowledge/store/fpgacen-" 14 15func fc_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 16// latest record for key: 1=found (ptr/len set), 0=tombstoned, -1=absent. 17func fc_get(key: *u8, ptrout: *i64, lenout: *i64) -> i64 { return ss_get(FC_PREFIX, key, ptrout, lenout) } 18// next segment id for a commit = 1 + current segment count. 19func fc_seg_next_p(prefix: *u8) -> i64 { 20 let segs: *i64 = sys_mmap(8 * 260) as *i64 21 let nseg: i64 = ss_manifest(prefix, segs) 22 if nseg < 0 { return 1 } 23 return 1 + nseg 24} 25// extract the f-th (0-based) TAB field of rec[0..rlen) into out (NUL-terminated); returns field length. 26func fc_field(rec: *u8, rlen: i64, f: i64, out: *u8) -> i64 { 27 var cur: i64 = 0; var i: i64 = 0; var o: i64 = 0 28 while cur < f { 29 if i >= rlen { out[0] = 0 as u8; return 0 } 30 if rec[i] == (9 as u8) { cur = cur + 1 } 31 i = i + 1 32 } 33 var go: i64 = 1 34 while go == 1 { 35 if i >= rlen { go = 0 } else { 36 if rec[i] == (9 as u8) { go = 0 } else { out[o] = rec[i]; o = o + 1; i = i + 1 } 37 } 38 } 39 out[o] = 0 as u8 40 return o 41} 42// 1 if the store's current value for key byte-equals val[0..vlen). Drives idempotent skip + post-commit verify. 43func fc_streq_store(key: *u8, val: *u8, vlen: i64) -> i64 { 44 let pq: *i64 = sys_mmap(16) as *i64 45 let lq: *i64 = sys_mmap(16) as *i64 46 if fc_get(key, pq, lq) != 1 { return 0 } 47 let b: *u8 = pq[0] as *u8 48 let n: i64 = lq[0] 49 if n != vlen { return 0 } 50 var i: i64 = 0 51 while i < n { if b[i] != val[i] { return 0 } i = i + 1 } 52 return 1 53}