code wiki / (root) / nx_parse.nx

nx_parse.nx

buildroot/runtime/nx_parse.nx

262144 B5705 linesdepth 4pulls 7 transitivereach 50 importersview sourcekind librarytopic parse
docsdependenciesstructsconstsfunctions

about

parse.nx -- NishiLang recursive-descent parser, in NishiLang. 2026-04-23: full monomorphization port landed; stdlib.nx's Option<T> / Result<T, E> now instantiate to distinct cached Types here the same way parse.c does. Port of parse.c's core: precedence expression parsing, function declarations, and the common statements (return, let, var, if, while). Struct / enum / const / match / pattern-matching are deferred to a second port turn so this file stays bounded. Produces IR using the emitter functions defined in ir.nx: for full compilation the driver (main.nx) passes the lex output here, then onto opt -> regalloc -> riscv.

dependencies 4 imports · 29 importers

nx_types.nx nx_quant.nx nx_lex_kinds.nx nx_ir.nx nx_parse.nx end2end_test.nx nx_compile_wat.nx nx_compile_x86.nx nx_dom_oracle_gate.nx nx_lang_struct.nx nx_main.nx nx_nxc.nx nx_quality_grade_daemon.nx nx_quality_grade_quad.nx nx_quality_grade_self.nx

diagram shows first 10 each side; +0 more imports, +19 more importers in the complete lists below.

imports: nx_types.nxnx_quant.nxnx_lex_kinds.nxnx_ir.nx

imported by: end2end_test.nxnx_compile_wat.nxnx_compile_x86.nxnx_dom_oracle_gate.nxnx_lang_struct.nxnx_main.nxnx_nxc.nxnx_quality_grade_daemon.nxnx_quality_grade_quad.nxnx_quality_grade_self.nxnx_quality_grade_septagon.nxnx_smoke_nxc_pipeline.nxnx_smoke_nxc_pipeline10.nxnx_smoke_nxc_pipeline11.nxnx_smoke_nxc_pipeline12.nxnx_smoke_nxc_pipeline13.nxnx_smoke_nxc_pipeline14.nxnx_smoke_nxc_pipeline15.nxnx_smoke_nxc_pipeline2.nxnx_smoke_nxc_pipeline3.nxnx_smoke_nxc_pipeline4.nxnx_smoke_nxc_pipeline5.nxnx_smoke_nxc_pipeline7.nxnx_smoke_nxc_pipeline8.nxnx_smoke_nxc_pipeline9.nxnx_smoke_nxc_tilde.nxnx_vcc_color_wat.nxnx_vcc_probe_wat.nxparse.nx

structs

365struct Local
391struct Parser
463struct EnumEntry
474struct StaticEntry
487struct StructEntry
496struct MConst

consts

116const NX_DIAG_MAX_ERRS: i64 = 20
378const LOCAL_BYTES: i64 = 96
389const NX_PARSE_LOCALS_CAP: i64 = 8192
472const ENUM_ENTRY_BYTES: i64 = 96
482const STATIC_ENTRY_BYTES: i64 = 88
494const STRUCT_ENTRY_BYTES: i64 = 80
512const MCONST_BYTES: i64 = 96
1238const NX_BOUNDS_CHECK_LIVE: i64 = 1
1241const NX_TRAP_BOUNDS: i64 = 71
1245const NX_RV64_SYS_WRITE: i64 = 64
1246const NX_RV64_SYS_EXIT_GROUP: i64 = 94
1357const NX_FNPTR_MAX_ARGS: i64 = 23

functions

60func tok_at(toks: *Tok, i: i64) -> *Tok
70func tr(c: i64) -> i64
85func parse_die(msg: *u8, msg_len: i64) -> i64
119func nx_diag_note_error() -> i64
131func nx_diag_set_source(p: *u8, n: i64) -> i64
called by 1: main
140func nx_diag_caret(line: i64, col: i64) -> i64
183func nx_diag_show_line(line: i64) -> i64
221func nx_dym_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
225func nx_dym_dist(a: *u8, la: i64, b: *u8, lb: i64, budget: i64) -> i64
269func nx_dym_suggest_fn(m: *Module, name: *u8, nlen: i64) -> i64
called by 1: parse_primary_call calls 1: nx_dym_dist
303func nx_put_dec_err(n: i64) -> i64
325func nx_put_tok_text_err(t: *Tok) -> i64
349func nx_diag_token_window(P: *Parser, tidx: i64) -> i64
516func peek_kind(P: *Parser) -> i64
543func at_stmt_boundary(P: *Parser) -> i64
601func peek_at(P: *Parser, k: i64) -> *Tok
604func advance_tok(P: *Parser) -> *Tok
609func check_kind(P: *Parser, k: i64) -> i64
calls 1: peek_kind
613func match_kind(P: *Parser, k: i64) -> i64
637func ty_name_eq(a: *u8, a_len: i64, b: *u8, b_len: i64) -> i64
656func clone_type_substituting(t: *Type, param_name: *u8,
686func ty_mangle_suffix(arg: *Type, out: *u8, off: i64, cap: i64) -> i64
755func lookup_struct(P: *Parser, name: *u8) -> *Type;
756func register_struct(P: *Parser, name: *u8, name_len: i64,
768func instantiate_generic_n(P: *Parser, tmpl: *Type,
827func parse_type(P: *Parser) -> *Type
969func parser_loc_at(P: *Parser, i: i64) -> *Local
975func copy_name_into_local(L: *Local, src: *u8) -> i64
called by 1: add_local
989func local_name_eq(L: *Local, name: *u8) -> i64
1009func nx_dym_suggest_ident(P: *Parser, name: *u8, nlen: i64) -> i64
1066func find_local(P: *Parser, name: *u8) -> *Local
1079func local_in_block(P: *Parser, name: *u8) -> i64
1089func add_local(P: *Parser, name: *u8, value_id: i64, is_alloca: i64,
1132func parse_logical_or(P: *Parser) -> i64;
called by 1: parse_expr
1133func parse_unary_core(P: *Parser) -> i64;
1134func parse_primary(P: *Parser) -> i64;
called by 1: parse_unary_core
1135func parse_primary_ident(P: *Parser, t: *Tok) -> i64;
called by 1: parse_primary
1136func parse_primary_qualified_variant(P: *Parser, name: *u8) -> i64;
called by 1: parse_primary_ident
1137func parse_primary_intrinsic(P: *Parser, name: *u8) -> i64;
called by 1: parse_primary_ident
1138func parse_primary_call(P: *Parser, name: *u8) -> i64;
called by 1: parse_primary_ident
1139func parse_primary_local_or_const(P: *Parser, name: *u8) -> i64;
called by 1: parse_primary_ident
1140func parse_stmt_list(P: *Parser) -> i64;
1141func parse_stmt(P: *Parser) -> i64;
1142func parse_stmt_return(P: *Parser) -> i64;
called by 1: parse_stmt
1143func parse_stmt_let(P: *Parser) -> i64;
called by 1: parse_stmt
1144func parse_stmt_var(P: *Parser) -> i64;
called by 1: parse_stmt
1145func parse_stmt_if(P: *Parser) -> i64;
1146func parse_stmt_while(P: *Parser) -> i64;
called by 1: parse_stmt
1147func parse_stmt_for(P: *Parser) -> i64;
called by 1: parse_stmt
1148func parse_stmt_break(P: *Parser) -> i64;
called by 1: parse_stmt
1149func parse_stmt_continue(P: *Parser) -> i64;
called by 1: parse_stmt
1150func parse_stmt_match(P: *Parser) -> i64;
called by 1: parse_stmt
1151func parse_stmt_star(P: *Parser) -> i64;
called by 1: parse_stmt
1152func parse_stmt_ident(P: *Parser) -> i64;
called by 1: parse_stmt
1153func parse_stmt_ident_assign(P: *Parser) -> i64;
called by 1: parse_stmt_ident
1154func parse_stmt_ident_subscript(P: *Parser) -> i64;
called by 1: parse_stmt_ident
1155func parse_stmt_ident_dot(P: *Parser) -> i64;
called by 1: parse_stmt_ident
1156func parse_stmt_expr_fallback(P: *Parser) -> i64;
1157func parse_module_const(P: *Parser) -> i64;
called by 1: parse_module
1158func lookup_mconst(P: *Parser, name: *u8, out: *i64) -> i64;
1159func lookup_mconst_string(P: *Parser, name: *u8,
1161func mconst_name_eq(mc: *MConst, name: *u8) -> i64;
1162func mconst_at(P: *Parser, i: i64) -> *MConst;
1165func const_eval_expr(P: *Parser, depth: i64) -> i64;
1166func const_eval_bor(P: *Parser, depth: i64) -> i64;
1167func const_eval_bxor(P: *Parser, depth: i64) -> i64;
1168func const_eval_band(P: *Parser, depth: i64) -> i64;
1169func const_eval_shift(P: *Parser, depth: i64) -> i64;
1170func const_eval_addsub(P: *Parser, depth: i64) -> i64;
1171func const_eval_muldiv(P: *Parser, depth: i64) -> i64;
1172func const_eval_unary(P: *Parser, depth: i64) -> i64;
1173func const_eval_primary(P: *Parser, depth: i64) -> i64;
1174func mconst_at(P: *Parser, i: i64) -> *MConst;
1175func copy_name_into_mconst(mc: *MConst, src: *u8) -> i64;
1176func parse_struct_decl(P: *Parser) -> i64;
called by 1: parse_module
1177func parse_static_decl(P: *Parser) -> i64;
called by 1: parse_module
1178func parse_module_enum(P: *Parser) -> i64;
called by 1: parse_module
1179func inject_statics(P: *Parser) -> i64;
called by 1: parse_function
1180func enum_entry_at(P: *Parser, i: i64) -> *EnumEntry;
1181func lookup_enum(P: *Parser, name: *u8) -> *EnumEntry;
1183func struct_entry_at(P: *Parser, i: i64) -> *StructEntry;
1185func parse_expr(P: *Parser) -> i64
1225func safe_const_i64(P: *Parser, val: i64, tag: *u8) -> i64
1261func emit_bounds_trap(P: *Parser) -> i64
1316func emit_bounds_check_v(P: *Parser, idx: i64, len_v: i64) -> i64
1336func emit_bounds_check(P: *Parser, idx: i64, nelem: i64) -> i64
1358func parse_field_chain(P: *Parser, base: i64, base_ty: *Type) -> i64
1560func parse_primary(P: *Parser) -> i64
1777func parse_primary_ident(P: *Parser, t: *Tok) -> i64
1795func parse_primary_qualified_variant(P: *Parser, name: *u8) -> i64
1847func parse_primary_intrinsic(P: *Parser, name: *u8) -> i64
2784func parse_primary_call(P: *Parser, name: *u8) -> i64
3018func mc_name_eq(a: *u8, b: *u8) -> i64
3028func mconst_declared_later(P: *Parser, name: *u8) -> i64
3052func parse_primary_local_or_const(P: *Parser, name: *u8) -> i64
3299func parse_unary(P: *Parser) -> i64
3325func parse_unary_core(P: *Parser) -> i64
3482func fp_op_for_int(op: i64) -> i64
3490func has_fp_operand(P: *Parser, v: i64) -> i64
called by 1: emit_typed_binop
3501func nx_value_type(P: *Parser, v: i64) -> *Type
3515func nx_value_is_const(P: *Parser, v: i64) -> i64
3524func int_binop_result_type(P: *Parser, left: i64, right: i64) -> *Type
3573func fp_result_type(P: *Parser, left: i64, right: i64) -> *Type
3582func emit_typed_binop(P: *Parser, op: i64, left: i64, right: i64) -> i64
3595func parse_multiplicative(P: *Parser) -> i64
3616func parse_additive(P: *Parser) -> i64
3636func parse_shift(P: *Parser) -> i64
3663func parse_comparison(P: *Parser) -> i64
3681func parse_equality(P: *Parser) -> i64
3698func parse_bitand(P: *Parser) -> i64
3709func parse_bitxor(P: *Parser) -> i64
3720func parse_bitor(P: *Parser) -> i64
3731func parse_logical_and(P: *Parser) -> i64
3742func parse_logical_or(P: *Parser) -> i64
3770func parse_stmt(P: *Parser) -> i64
3808func nx_require_ident_name(P: *Parser, name_tok: *Tok) -> i64
3820func parse_stmt_return(P: *Parser) -> i64
3833func parse_stmt_let(P: *Parser) -> i64
3881func parse_stmt_var(P: *Parser) -> i64
3917func parse_stmt_if(P: *Parser) -> i64
3956func parse_stmt_while(P: *Parser) -> i64
3980func parse_stmt_for(P: *Parser) -> i64
4038func parse_stmt_break(P: *Parser) -> i64
4047func parse_stmt_continue(P: *Parser) -> i64
4056func parse_stmt_match(P: *Parser) -> i64
4266func parse_stmt_star(P: *Parser) -> i64
4303func parse_stmt_ident(P: *Parser) -> i64
4312func parse_stmt_ident_assign(P: *Parser) -> i64
4371func parse_stmt_ident_subscript(P: *Parser) -> i64
4537func parse_stmt_ident_dot(P: *Parser) -> i64
4699func parse_stmt_expr_fallback(P: *Parser) -> i64
4711func parse_stmt_list(P: *Parser) -> i64
4741func nx_dupdef_name_eq(t: *Tok, name: *u8, name_len: i64) -> i64
called by 1: nx_find_first_def_line calls 1: tok_text_ptr
4775func nx_find_first_def_line(P: *Parser, name: *u8, name_len: i64) -> i64
4831func parse_function(P: *Parser) -> i64
5096func resolve_primitive_type(name: *u8) -> *Type
5126func prepass_register_aliases(P: *Parser) -> i64
5185func prepass_register_structs(P: *Parser) -> i64
5279func prepass_count_params(P: *Parser) -> i64
5317func prepass_register_funcs(P: *Parser) -> i64
5424func parse_module(toks: *Tok, m: *Module) -> *Module
5607func parse_module_enum(P: *Parser) -> i64