code wiki / _hdl_build / nx_store_seed.nx

nx_store_seed.nx source

↩ module page · 55 lines · 2274 B

1// nx_store_seed.nx -- THE generic "migrate any flat plane into a sovereign seg-store" CLI 2// (operator 2026-07-17: unify store-seed; the review found ~30 bespoke per-plane seeders and no generic). 3// nx_store_seed <store-prefix> <staging-file> -> migrate the flat file into the store, print row count 4// nx_store_seed <store-prefix> load -> dump the store as newline-joined rows (store-emitted view) 5// Store-law: the flat staging file is put-file staging; the seg-store is the SSOT. Reuses sts_seed/sts_load. 6// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 7import "nx_store_seed_lib.nx" 8import "nx_seg_store.nx" 9import "nx_syscalls.nx" 10 11const NSS_STDERR: i64 = 2 12const NSS_ARGC_MIN: i64 = 3 13const NSS_IDX_SRC: i64 = 2 14const NSS_L: i64 = 108 // 'l' of "load" 15const NSS_NL: i64 = 10 16const NSS_CAP: i64 = 1048576 17const NSS_SZCAP: i64 = 16 18const NSS_MSGCAP: i64 = 128 19const NSS_EXIT_USAGE: i64 = 2 20 21func nss_werr(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(NSS_STDERR, s, n); return 0 } 22 23func main(argc: i64, argv: *i64) -> i64 { 24 if argc < NSS_ARGC_MIN { 25 nss_werr("usage: nx_store_seed <store-prefix> <staging-file|load>\n" as *u8) 26 sys_exit(NSS_EXIT_USAGE) 27 return NSS_EXIT_USAGE 28 } 29 let prefix: *u8 = argv[1] as *u8 30 let arg2: *u8 = argv[NSS_IDX_SRC] as *u8 31 32 if arg2[0] == (NSS_L as u8) { 33 let out: *u8 = sys_mmap(NSS_CAP) 34 let n: i64 = sts_load(prefix, out, NSS_CAP) 35 if n <= 0 { nss_werr("store EMPTY / unseeded\n" as *u8); sys_exit(1); return 1 } 36 sys_write(1, out, n) 37 sys_exit(0) 38 return 0 39 } 40 41 let szp: *i64 = sys_mmap(NSS_SZCAP) as *i64 42 let buf: *u8 = ss_readall(arg2, szp) 43 if buf == (0 as *u8) { nss_werr("cannot read staging file\n" as *u8); sys_exit(1); return 1 } 44 let cnt: i64 = sts_seed(prefix, buf, szp[0]) 45 if cnt < 0 { nss_werr("seg-store commit error\n" as *u8); sys_exit(1); return 1 } 46 let msg: *u8 = sys_mmap(NSS_MSGCAP) 47 var o: i64 = ss_cat(msg, 0, "SEEDED " as *u8) 48 o = ss_cat(msg, o, prefix) 49 o = ss_cat(msg, o, " rows=" as *u8) 50 o = ss_catn(msg, o, cnt) 51 msg[o] = NSS_NL as u8; o = o + 1 52 sys_write(1, msg, o) 53 sys_exit(0) 54 return 0 55}