code wiki / (root) / nx_import.nx

nx_import.nx

buildroot/runtime/nx_import.nx

21896 B644 linesdepth 2pulls 2 transitivereach 6 importersview sourcekind librarytopic import
docsdependenciesstructsconstsfunctions

about

import.nx -- sovereign import preprocessor (replaces main.c logic). Responsibility: given a root source path, return a single null- terminated buffer containing every imported file's text spliced inline, recursively, with each file visited at most once. Output is exactly what parse_module consumes. Subsystem boundary: - syscalls.nx : file I/O (sys_read_file) - str helpers : cstr_len / cstr_eq / u8_copy (below; no external dep) - import.nx : path ops + import expansion (this file) - nxc.nx : CLI driver that owns argv and calls expand_imports Invariants (enforced, not hoped): I1 Each canonicalised absolute path is expanded at most once -- the `seen` path table dedupes. Repeat imports emit nothing. I2 Canonicalisation is pure textual (.. pops, . drops, forward-slashes unified). No realpath(3). Identical output on Windows and Linux/NishiOS. I3 Import syntax: exactly `import "relative.nx"` at start-of- line after optional whitespace. Nothing else parses as an import; a substring match mid-line passes through. I4 Buffer overruns fail loudly (negative return). Never silently truncate -- correctness over convenience. I5 Fixed capacity: MAX_IMPORTS distinct imports per tree; paths up to IMPORT_PATH_LEN; output buffer sized by caller. A build that needs more raises one constant in one place. Complexity: O(N * F) where N is total source bytes across all files and F is average imports-per-file. One read per file.

dependencies 1 imports · 6 importers

nx_syscalls.nx nx_import.nx nx_compile_wat.nx nx_compile_x86.nx nx_dom_oracle_gate.nx nx_nxc.nx nx_vcc_color_wat.nx nx_vcc_probe_wat.nx

imports: nx_syscalls.nx

imported by: nx_compile_wat.nxnx_compile_x86.nxnx_dom_oracle_gate.nxnx_nxc.nxnx_vcc_color_wat.nxnx_vcc_probe_wat.nx

structs

277struct ExpandCtx

consts

45const MAX_IMPORTS: i64 = 256
46const IMPORT_PATH_LEN: i64 = 1024
49const ERR_IMPORTS_FULL: i64 = -1
50const ERR_READ_FAILED: i64 = -2
51const ERR_OUT_OVERFLOW: i64 = -3
52const ERR_BAD_IMPORT: i64 = -4

functions

56func cstr_len(s: *u8) -> i64
62func cstr_eq(a: *u8, b: *u8) -> i64
called by 1: import_already
73func u8_copy(dst: *u8, src: *u8, n: i64) -> i64
80func ptr_at(p: *u8, delta: i64) -> *u8
90func import_already(paths: *u8, n: i64, path: *u8) -> i64
called by 1: expand_imports_inner calls 2: ptr_atcstr_eq
100func import_add(paths: *u8, n: i64, path: *u8) -> i64
114func path_dir(path: *u8, out: *u8) -> i64
131func join_path(dir: *u8, name: *u8, out: *u8) -> i64
163func is_sep(b: i64) -> i64
called by 1: canonicalise_path
173func canonicalise_path(path: *u8, out: *u8, scratch: *u8) -> i64
259func starts_with_import(src: *u8, p: i64) -> i64
293func expand_ctx_new(out: *u8, out_cap: i64) -> *ExpandCtx
called by 6: mainmainmainmainmainmain calls 1: sys_mmap
313func out_push(ctx: *ExpandCtx, b: i64) -> i64
323func out_append(ctx: *ExpandCtx, src: *u8, n: i64) -> i64
calls 2: u8_copyptr_at
339func is_func_main_line(src: *u8, p: i64) -> i64
366func skip_func_main(src: *u8, p: i64) -> i64
414func expand_imports_inner(ctx: *ExpandCtx, path: *u8, is_root: i64) -> i64;
427func file_exists(path: *u8) -> i64
called by 1: try_subroot calls 2: sys_openat_rdsys_close
434func try_subroot(dir: *u8, subroot: *u8, ipath: *u8,
462func try_resolve_import(dir: *u8, ipath: *u8, out: *u8) -> i64
539func expand_imports(ctx: *ExpandCtx, path: *u8) -> i64
543func expand_imports_inner(ctx: *ExpandCtx, path: *u8, is_root: i64) -> i64