code wiki / (root) / nx_template_instantiate.nx

nx_template_instantiate.nx

buildroot/runtime/nx_template_instantiate.nx

16880 B462 linesdepth 5pulls 6 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_template_instantiate.nx -- substrate-native template engine. For each registry entry that declares a "shape" field, read the corresponding template under specs/algo_shapes/<shape>/, substitute {{PLACEHOLDER}} tokens with values from the meta.json's "template_params" object, write the result to impl.nx + test.nx. This is the SELF-SUFFICIENCY dependency: new algorithms in a known shape need ONLY metadata (no body) -- substrate emits the impl. Recognized placeholder tokens (any name in {{UPPER_CASE}} is replaced from template_params). {{NX_MODULE}} is always replaced with the meta's "nx_module" value. genealogy_id: substrate_template_engine_2026_05_13 lineage_id: codegen_via_substitution license: public_domain

dependencies 5 imports · 0 importers

nx_syscalls.nx nx_runtime.nx nx_tier.nx nx_dirent.nx nx_fcntl.nx nx_template_instantiate.nx

imports: nx_syscalls.nxnx_runtime.nxnx_tier.nxnx_dirent.nxnx_fcntl.nx

imported by: nobody (leaf or entry point)

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

main nx_openat sys_write strlen sys_mmap nx_dirent_read nx_dirent_iter nx_dirent_name_len instantiate_shape_entry sys_mmap ↻ sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_close read_meta_field sys_mmap ↻ find_substr2 extract_params_slice strlen ↻ find_substr2 ↻ substitute_template sys_mmap ↻ strneq read_meta_field ↻ nx_open_wr nx_openat ↻ write_all2 sys_write ↻ sys_close ↻ sys_close ↻ print_i64 sys_mmap ↻ itoa sys_mmap ↻ sys_write ↻

structs

none

consts

30const NX_MAGIC_16384: i64 = 16384
32const STDOUT: i64 = 1
33const NX_TPL_PATH_BUF: nx_size = 512
34const NX_TPL_VAL_CAP: nx_size = 512
35const NX_TPL_BUF_CAP: nx_size = 16384

functions

39func write_str_to_fd(fd: i64, s: *u8) -> nx_int
calls 2: strlensys_write
45func write_all2(fd: i64, buf: *u8, n: nx_size) -> nx_size
called by 1: instantiate_shape_entry calls 1: sys_write
57func find_substr2(buf: *u8, start: nx_idx, n: nx_size, needle: *u8, nlen: nx_size) -> nx_idx
77func read_meta_field(buf: *u8, n: nx_size, key: *u8, out: *u8, out_cap: nx_size) -> nx_size
127func substitute_template(src: *u8, src_n: nx_size,
235func extract_params_slice(meta: *u8, meta_n: nx_size, out_start: *i64) -> nx_size
284func instantiate_shape_entry(entry_name: *u8) -> nx_int
412func main() -> i64