code wiki / (root) / nx_nir.nx

nx_nir.nx

buildroot/runtime/nx_nir.nx

5812 B164 linesdepth 6pulls 7 transitivereach 10 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_nir.nx -- NishiLang IR builder, in pure NishiLang. THIRD CONCRETE STEP of the nxc2 self-hosting trajectory. Consumes the AST produced by nx_nparse and emits IR instructions (mirroring a subset of nxc2/ir.h's Opcode enum). Minimum viable opcodes: NX_IR_CONST_I64 (value in operand 0) NX_IR_RETURN (value-id in operand 0) NX_IR_ADD/SUB/MUL (operand 0 + 1 -> result) SSA value-ids are dense integers (0, 1, 2, ...). Each NxInstr's result_id is its own slot index. Operands reference earlier slots.

dependencies 3 imports · 10 importers

syscalls.nx nx_nlex.nx nx_nparse.nx nx_nir.nx _a2a_selfhost_binop.nx _a2a_selfhost_let.nx _selfhost_compile_42.nx _selfhost_compile_binop.nx _selfhost_compile_if.nx _selfhost_compile_if_false.nx _selfhost_compile_let.nx nx_nir_test.nx nx_nx86.nx nx_nx86_test.nx

imports: syscalls.nxnx_nlex.nxnx_nparse.nx

imported by: _a2a_selfhost_binop.nx_a2a_selfhost_let.nx_selfhost_compile_42.nx_selfhost_compile_binop.nx_selfhost_compile_if.nx_selfhost_compile_if_false.nx_selfhost_compile_let.nxnx_nir_test.nxnx_nx86.nxnx_nx86_test.nx

structs

30struct NxInstr
37struct NxIrFunc

consts

20const NX_IR_CONST_I64: i64 = 1
21const NX_IR_RETURN: i64 = 2
22const NX_IR_ADD: i64 = 3
23const NX_IR_SUB: i64 = 4
24const NX_IR_MUL: i64 = 5
25const NX_IR_STORE_LOCAL: i64 = 6 // op0 = slot index, op1 = value-id
26const NX_IR_LOAD_LOCAL: i64 = 7 // op0 = slot index, result = loaded value
27const NX_IR_BR_IF_ZERO: i64 = 8 // op0 = value-id, op1 = label-id (jump if value is 0)
28const NX_IR_LABEL: i64 = 9 // op0 = label-id (placeholder, emits .Lid:)

functions

48func nx_nir_func_new(cap: i64) -> *NxIrFunc
called by 1: nx_nir_lower_func
62func nx_nir_new_label(f: *NxIrFunc) -> i64
called by 1: nx_nir_lower_stmt
68func nx_nir_instr_at(f: *NxIrFunc, i: i64) -> *NxInstr
72func nx_nir_emit(f: *NxIrFunc, opcode: i64, op0: i64, op1: i64) -> i64
86func nx_nir_lower_expr(f: *NxIrFunc, parser: *NxNParser, ast_idx: i64) -> i64
107func nx_nir_lower_stmt(f: *NxIrFunc, parser: *NxNParser, ast_idx: i64) -> i64
142func nx_nir_lower_block(f: *NxIrFunc, parser: *NxNParser, ast_idx: i64) -> i64
153func nx_nir_lower_func(parser: *NxNParser, func_ast_idx: i64, cap: i64) -> *NxIrFunc