nx_diagram.nx
buildroot/runtime/nx_diagram.nx
about
nx_diagram.nx -- substrate-native diagram primitive.
First-class diagrams in NishiLang. Data model + 4 output emitters
from a single in-memory representation.
Why this exists (per user 2026-05-13):
"can we add mermaid like capabilities to nishi lang"
The substrate should NOT depend on external renderers (Mermaid.live,
Graphviz CLI, etc.). Per Wolfram-IP-free + sovereign-substrate
doctrine: ship our own. Mermaid stays as a COMPATIBILITY output
for tools that already render it; ASCII is the sovereign default
(terminal-renderable, zero external dep).
API:
nx_diagram_new(max_nodes, max_edges) -> *Diagram
nx_diagram_add_node(d, label, summary) -> i64 (returns node index)
nx_diagram_add_edge(d, from_idx, to_idx, label)
nx_diagram_emit_mermaid(d) -> writes graph TD to stdout
nx_diagram_emit_ascii(d) -> terminal-friendly layered render
nx_diagram_emit_dot(d) -> Graphviz DOT (interop)
nx_diagram_emit_json(d) -> machine-readable JSONL
Plain-English: a substrate primitive that lets any NishiLang program
build a diagram in memory then export it in any of 4 formats. The
ASCII format runs in any terminal, so the substrate can VISUALIZE
itself without needing a graphical tool.
genealogy_id: mermaid_2015_js_lib + graphviz_dot_1991 + ascii_art
+ plain_text_diagram_lineage
lineage_id: in_memory_diagram + multi_format_emit
axioms: NX_AX_REL_TRANSITIVITY (edges define a relation;
diagram emit preserves source structure)
dependencies 4 imports · 3 importers
imports: nx_syscalls.nxnx_runtime.nxnx_axioms.nxnx_tier.nx
imported by: nx_diagram_test.nxnx_substrate_diagram.nxnx_substrate_diagram_ascii.nx
structs
| 48 | struct DiagramNode |
| 53 | struct DiagramEdge |
| 59 | struct Diagram |
consts
| 46 | const NX_DIAG_MAX_LABEL: nx_size = 96 |
| 70 | const NX_DIAG_NODE_BYTES: i64 = 16 |
| 71 | const NX_DIAG_EDGE_BYTES: i64 = 24 |
functions
| 75 | func nx_diagram_new(max_nodes: nx_idx, max_edges: nx_idx) -> *Diagram |
| 87 | func nx_diagram_node_at(d: *Diagram, i: nx_idx) -> *DiagramNode |
| 91 | func nx_diagram_edge_at(d: *Diagram, i: nx_idx) -> *DiagramEdge |
| 97 | func nx_diagram_add_node(d: *Diagram, label: *u8, summary: *u8) -> nx_idx |
| 107 | func nx_diagram_add_edge(d: *Diagram, from_idx: nx_idx, to_idx: nx_idx, |
| 121 | func nx_diagram_emit_mermaid(d: *Diagram) -> i64 |
| 162 | func nx_diagram_emit_dot(d: *Diagram) -> i64 |
| 204 | func nx_diagram_emit_json(d: *Diagram) -> i64 |
| 242 | func nx_diagram_emit_ascii(d: *Diagram) -> i64 |