code wiki / _hdl_build / nx_gen_conf_lib.nx

nx_gen_conf_lib.nx source

↩ module page · 56 lines · 2445 B

1// nx_gen_conf_lib.nx -- the gen lane's ONE conf reader (2026-08-30): the two-path read (daemon cwd first, then the 2// nishihost tree -- the gen daemon runs from /volume1/ai/gen, so a bare knowledge/ path resolves there) plus the 3// integer-row parser that skips '#' and ';' comment lines. Extracted because the identical two-path idiom already 4// existed in go_default_steps and gw_chat_budget_s and a THIRD copy was about to be typed for gen_hires.conf and 5// gen_prompt_weight.conf (rule 15: three copies is the extraction trigger). Those two incumbents are deliberately 6// NOT migrated in the same change -- a refactor of a live daemon's config path travels on its own proof. 7// license_tier: ORIGINAL 8import "nx_syscalls.nx" 9 10const GC_CH_HASH: i64 = 35 11const GC_CH_SEMI: i64 = 59 12const GC_CH_NL: i64 = 10 13const GC_CH_D0: i64 = 48 14const GC_CH_D9: i64 = 57 15const GC_B10: i64 = 10 16 17// read rel, then abs. szp[0] = bytes read (0 when neither exists). returns the buffer as i64 (0 when absent). 18func gc_read2(rel: *u8, abs: *u8, szp: *i64) -> i64 { 19 szp[0] = 0 20 var b: *u8 = sys_read_file(rel, szp) 21 if szp[0] <= 0 { szp[0] = 0; b = sys_read_file(abs, szp) } 22 if szp[0] <= 0 { szp[0] = 0; return 0 } 23 return b as i64 24} 25// parse up to `want` unsigned integers from a conf body in order of appearance, skipping comment lines (a line whose 26// first byte is '#' or ';'). returns how many landed in out[0..]. 27func gc_ints(b: *u8, n: i64, out: *i64, want: i64) -> i64 { 28 var i: i64 = 0 29 var k: i64 = 0 30 var linestart: i64 = 1 31 var skip: i64 = 0 32 while i < n { 33 let c: i64 = b[i] & 0xff 34 if linestart == 1 { skip = 0; if c == GC_CH_HASH { skip = 1 } if c == GC_CH_SEMI { skip = 1 } linestart = 0 } 35 var isd: i64 = 0 36 if c >= GC_CH_D0 { if c <= GC_CH_D9 { isd = 1 } } 37 if skip == 1 { isd = 0 } 38 if isd == 1 { 39 var v: i64 = 0 40 var ind: i64 = 1 41 while ind == 1 { 42 if i >= n { ind = 0 } else { 43 let d: i64 = b[i] & 0xff 44 var dd: i64 = 0 45 if d >= GC_CH_D0 { if d <= GC_CH_D9 { dd = 1 } } 46 if dd == 1 { v = v*GC_B10 + (d - GC_CH_D0); i = i + 1 } else { ind = 0 } 47 } 48 } 49 if k < want { out[k] = v; k = k + 1 } 50 } else { 51 if c == GC_CH_NL { linestart = 1 } 52 i = i + 1 53 } 54 } 55 return k 56}