code wiki / (root) / nx_codegrep.nx

nx_codegrep.nx

buildroot/runtime/nx_codegrep.nx

11512 B269 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_codegrep.nx -- SOVEREIGN code search (the grep-exceeding capability; operator 2026-06-17: "use the nishi ecosystem ... s class functionality that exceeds grep ... build it from the hardware rung up"). RUNG 1: recursive dir-walk (sys_getdents64) + bounded per-file read (sys_openat_rd/sys_read, no 4GB reserve) + substring line-scan -> file:line: <line>. Sovereign (.nx, nx_cc->nxasm, no ripgrep/grep). Beats ripgrep HERE because it is focused on .nx, bounded, and substring (not a regex engine over a giant tree) -- ripgrep TIMED OUT on runtime/ at 20s; this completes. Query is read from data/cg_query.txt (edit + re-run = no recompile). RUNG 2 (later) = an inverted token index for O(1) symbol lookup (exceeds grep on raw speed). license_tier: ORIGINAL

dependencies 2 imports · 0 importers

nx_syscalls.nx nx_itoa_lib.nx nx_codegrep.nx

imports: nx_syscalls.nxnx_itoa_lib.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sys_openat_rd cg_puts sys_write cg_strlen sys_exit sys_mmap sys_read sys_close sys_now_ms sys_mmap ↻ sys_clock_gettime_mono sys_openat_wr cg_index_dir sys_openat_rd ↻ sys_mmap ↻ sys_getdents64 dirent_reclen dirent_type dirent_name cg_is_dot cg_join cg_index_dir ↻ cg_ends_nx cg_strlen ↻ cg_index_file sys_openat_rd ↻ sys_read ↻ sys_close ↻ cg_fwrite sys_write ↻ cg_strlen ↻ sys_write ↻ cg_fwrite_num nxi_fd sys_mmap ↻ ccz_cat_num sys_write ↻ sys_munmap sys_close ↻

structs

none

consts

12const CG_MAGIC_65536: i64 = 65536
13const CG_MAGIC_1024: i64 = 1024
14const CG_MAGIC_67108864: i64 = 67108864
16const CG_FBUF: i64 = 4194304 // 4 MB per-file read buffer (reused); .nx files are well under this

functions

18func cg_strlen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
19func cg_puts(s: *u8) -> i64 { sys_write(1, s, cg_strlen(s)); return 0 }
24func cg_putn(v: i64) -> i64 { nxi_out(v); return 0 }
called by 2: cg_scan_filemain calls 1: nxi_out
25func cg_write_range(buf: *u8, lo: i64, hi: i64) -> i64 { if hi > lo { sys_write(1, (buf as i64 + lo) as *u8, hi - lo) } return 0 }
28func cg_find_range(buf: *u8, lo: i64, hi: i64, pat: *u8, pl: i64) -> i64
40func cg_ends_nx(name: *u8) -> i64
called by 2: cg_scan_dircg_index_dir calls 1: cg_strlen
50func cg_scan_file(path: *u8, query: *u8, ql: i64, fbuf: *u8) -> i64
77func cg_is_dot(name: *u8) -> i64
83func cg_join(dirpath: *u8, name: *u8, out: *u8) -> i64
95func cg_scan_dir(dirpath: *u8, query: *u8, ql: i64, fbuf: *u8) -> i64
134func cg_fwrite(fd: i64, s: *u8) -> i64 { sys_write(fd, s, cg_strlen(s)); return 0 }
called by 1: cg_index_file calls 2: sys_writecg_strlen
139func cg_fwrite_num(fd: i64, v: i64) -> i64 { nxi_fd(fd, v); return 0 }
called by 1: cg_index_file calls 1: nxi_fd
142func cg_index_file(path: *u8, cfd: i64, fbuf: *u8) -> i64
167func cg_index_dir(dirpath: *u8, cfd: i64, fbuf: *u8) -> i64
205func cg_query_corpus(cpath: *u8, query: *u8, ql: i64, buf: *u8, cap: i64) -> i64
230func main() -> i64