code wiki / _hdl_build / nx_eg.nx

nx_eg.nx

buildroot/runtime/_hdl_build/nx_eg.nx

67591 B720 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tooltopic eg
docsdependenciesstructsconstsfunctions

about

nx_eg.nx -- EMITTER-OF-EMITTERS GENERALIZED (X-AUT-006e-GEN, the daemon-class rung). nx_eoe.nx proved the keystone on a BOUNDED shape: it pretty-prints `depth` NESTED COUNTING loops from a single integer -- the SHAPE is baked, only a COUNT is data-driven. THIS organ removes the ceiling: it is the parser's full DUAL -- a GENERIC recursive tree->source pretty-printer that reads a STRUCTURAL-SKELETON-as-DATA table (a flat *i64 node array, same flat-record discipline as nx_http_router's NX_ROUTE_F_*) and emits the matching NishiLang construct for each typed node kind: SEQ / FUNC / DECL / ASSIGN / WHILE / IF / RETURN / STMT_CALL / EMIT. The control-flow STRUCTURE (which loops, which branches, which calls, in what nesting) is now entirely DATA -- so an emitter whose control flow is ABSENT from every prior emitter (a socket bind/listen/`while accept`/fork/flat-if dispatch daemon) can be ORGAN-pretty-printed from its spec, never hand-written. nx_cc then turns that source into machine code (control-flow synthesis DELEGATED to the compiler the team owns). THE MECHANISM SEEDED (one-time, declared, exactly like the EOE keystone in nx_eoe.nx:3-9): ONLY this generic recursive pretty-printer. The BODY of any specific emitter is pretty-printed FROM ITS SPEC TABLE, never hand-written. Dialect rails the walker enforces by construction: flat-ifs only (LM-002 -- an IF node holds ONE comparison and a then-seq; there is NO else node, compound guards become a SEQUENCE of flat IFs), no &&/|| in emitted conditions (LM-001 -- a condition is a verbatim ARG string the spec author keeps single-comparison), and any fragment the typed kinds do not model (a struct-cast, a mask-after-shift port byte) rides an NK_EMIT verbatim-line node (the escape hatch, LM-005-safe). USAGE (driven by an in-organ spec selector, no hand-written emitter body): nx_eg <which> <outbase> -> writes runtime/_hdl_build/<outbase>.nx by WALKING spec <which> which = 0 -> the EOE-equivalent spec (PROOF-1 regression: re-author nx_eoe's depth-2 output shape) which = 1 -> the DAEMON spec (PROOF-2: socket/bind/listen/accept/fork/flat-if -> /health 200) which = 1 tamper>0 -> same daemon spec with one F_ARG0_PTR field flipped (NO-FAKE-GREEN: output MUST differ -> KAT RED, proving the control flow + literals are spec-synthesized) Sovereign (nx_cc/nxasm, no gcc/.sh). Additive: nx_eoe.nx untouched. license_tier: ORIGINAL

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_eg.nx

imports: nx_syscalls.nx

imported by: nobody (leaf or entry point)

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

main eg_p sys_write eg_atoi sys_mmap eg_cat eg_build_spec0 eg_n eg_s eg_emit_node eg_emit_node ↻ eg_cat ↻ eg_indent eg_cat ↻ eg_build_spec1 eg_n ↻ eg_s ↻ sys_mmap ↻ eg_cat ↻ eg_build_spec2 eg_n ↻ eg_s ↻ sys_mmap ↻ sys_openat_append eg_cat ↻ sys_openat_wr sys_write ↻ sys_close

structs

none

consts

29const NK_MAGIC_262144: i64 = 262144
34const NK_FIELDS: i64 = 7
35const F_KIND: i64 = 0
36const F_ARG0: i64 = 1 // *u8 string fragment (name / cond / lhs / callee / verbatim line)
37const F_ARG1: i64 = 2 // *u8 string fragment (type / rhs / arglist)
38const F_ARG2: i64 = 3 // *u8 string fragment (init expr)
39const F_CHILD0: i64 = 4 // node index (body-seq / then-seq) or -1
40const F_CHILD1: i64 = 5 // node index (reserved) or -1
41const F_SIB: i64 = 6 // next sibling node index or -1 (SEQ child-list link)
44const NK_SEQ: i64 = 0 // CHILD0 = first child; siblings chained via F_SIB
45const NK_DECL: i64 = 1 // ARG0 keyword(let/var), ARG1 "name: type", ARG2 init-expr -> "<kw> <name: type> = <init>"
46const NK_ASSIGN: i64 = 2 // ARG0 lhs, ARG1 rhs -> "<lhs> = <rhs>"
47const NK_WHILE: i64 = 3 // ARG0 cond, CHILD0 body-seq -> "while <cond> {\n<body>\n}"
48const NK_IF: i64 = 4 // ARG0 cond, CHILD0 then-seq (FLAT, no else) -> "if <cond> {\n<then>\n}"
49const NK_IF_INLINE: i64 = 5 // ARG0 cond, ARG1 single-stmt -> "if <cond> { <stmt> }" (one-line flat-if)
50const NK_RETURN: i64 = 6 // ARG0 expr -> "return <expr>"
51const NK_STMT_CALL: i64 = 7 // ARG0 = a bare statement line (call / expr-stmt) emitted verbatim + newline
52const NK_EMIT: i64 = 8 // ARG0 = a verbatim source line (escape hatch for fragments the kinds don't model)
53const NK_FUNC: i64 = 9 // ARG0 = full signature head "name(params) -> ret", CHILD0 body-seq

functions

56func eg_atoi(s: *u8) -> i64 { var n: i64 = 0; var i: i64 = 0; while s[i] != (0 as u8) { if s[i] >= (48 as u8) { if s[i] <= (57 as u8) { n = n * 10 + ((s[i] as i64) - 48) } } i = i + 1 } return n }
called by 1: main
57func eg_cat(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { dst[off+i] = s[i]; i = i + 1 } return off + i }
58func eg_p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
called by 1: main calls 1: sys_write
61func eg_indent(buf: *u8, off: i64, indent: i64) -> i64
called by 1: eg_emit_node calls 1: eg_cat
72func eg_emit_node(buf: *u8, off: i64, spec: *i64, idx: i64, indent: i64) -> i64
168func eg_n(spec: *i64, idx: i64, kind: i64, c0: i64, sib: i64) -> i64
179func eg_s(spec: *i64, idx: i64, slot: i64, val: i64) -> i64
190func eg_build_spec0(spec: *i64) -> i64
called by 1: main calls 2: eg_neg_s
223func eg_build_spec1(spec: *i64, tamper: i64) -> i64
called by 1: main calls 4: eg_neg_ssys_mmapeg_cat
336func eg_build_spec2(spec: *i64, tamper: i64) -> i64
660func main(argc: i64, argv: *i64) -> i64