code wiki / (root) / nx_parse.nx

nx_parse.nx

buildroot/runtime/nx_parse.nx

262144 B5077 linesdepth 4pulls 10 transitivereach 212 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 7 imports · 59 importers

nx_types.nx nx_quant.nx nx_f64.nx nx_f64_div.nx nx_lex_kinds.nx nx_ir.nx nx_linemap.nx nx_parse.nx end2end_test.nx nx_cap_detect_ir_gate_t278.nx nx_compile_wat.nx nx_compile_wat_call_operands_t143. nx_compile_wat_scalararm.nx nx_compile_x86.nx nx_dom_oracle_gate.nx nx_lang_struct.nx nx_lsp.nx nx_main.nx

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

imports: nx_types.nxnx_quant.nxnx_f64.nxnx_f64_div.nxnx_lex_kinds.nxnx_ir.nxnx_linemap.nx

imported by: end2end_test.nxnx_cap_detect_ir_gate_t278.nxnx_compile_wat.nxnx_compile_wat_call_operands_t143.nxnx_compile_wat_scalararm.nxnx_compile_x86.nxnx_dom_oracle_gate.nxnx_lang_struct.nxnx_lsp.nxnx_main.nxnx_nxc.nxnx_quality_grade_daemon.nxnx_quality_grade_quad.nxnx_quality_grade_self.nxnx_quality_grade_septagon.nxnx_rv64_atomic_gate.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_type_layout_gate.nxnx_vcc_color_wat.nxnx_vcc_probe_wat.nxnx_wgsl.nxnx_wgsl_authored_t55.nxnx_wgsl_before_front_t217.nxnx_wgsl_canonical_skin_t140.nxnx_wgsl_cast_control_t181.nxnx_wgsl_cast_lbs_t181.nxnx_wgsl_cast_material_t181.nxnx_wgsl_cloud_transport_t155.nxnx_wgsl_cumulus_release_t161.nxnx_wgsl_cumulus_t156.nxnx_wgsl_depth_candidate_t192.nxnx_wgsl_eye_t138.nxnx_wgsl_face_mask_t163.nxnx_wgsl_front_candidate_t217.nxnx_wgsl_inspection_t165.nxnx_wgsl_sand_baseline_t137.nxnx_wgsl_sand_private_t137.nxnx_wgsl_scene_light_candidate_t364.nxnx_wgsl_skin_t138.nxnx_wgsl_sky_light_t154.nxnx_wgsl_sky_private_20260910.nxnx_wgsl_sky_review_t154.nxnx_wgsl_static_t335.nxnx_wgsl_world_depth_t195.nxparse.nx

structs

495struct Local
580struct Parser
652struct EnumEntry
663struct StaticEntry
676struct StructEntry
685struct MConst

consts

98const NX_GENERIC_MAX_ARGS: i64 = 8
103const NX_PARSE_MAX_PARAMS: i64 = 24
154const NX_DIAG_MAX_ERRS: i64 = 20
540const LOCAL_BYTES: i64 = 128
551const NX_PARSE_LOCALS_CAP: i64 = 8192
559const NX_PARSE_STRUCTS_CAP: i64 = 1024
560const NX_PARSE_STATICS_CAP: i64 = 512
561const NX_PARSE_ENUMS_CAP: i64 = 256
562const NX_PARSE_MCONSTS_CAP: i64 = 8192
573const NX_PARSE_GLOBALS_SLACK: i64 = 256
578const NX_PARSE_FN_SLACK: i64 = 64
661const ENUM_ENTRY_BYTES: i64 = 96
671const STATIC_ENTRY_BYTES: i64 = 88
683const STRUCT_ENTRY_BYTES: i64 = 80
701const MCONST_BYTES: i64 = 96
1515const NX_BOUNDS_CHECK_LIVE: i64 = 1
1518const NX_TRAP_BOUNDS: i64 = 71
1522const NX_RV64_SYS_WRITE: i64 = 64
1523const NX_RV64_SYS_EXIT_GROUP: i64 = 94
1745const NX_TRAP_OVERFLOW: i64 = 72
1770const SEND_NAME_W: i64 = 64
1771const SEND_MAX: i64 = 256
1772const SEND_CALLEE_LEN: i64 = 14 // strlen("nx_pool_submit"), the one callee this check keys on
2334const OWN_NONE: i64 = 0
2335const OWN_LIVE: i64 = 1
2336const OWN_MOVED: i64 = 2
2337const OWN_RELEASED: i64 = 3
2520const NX_FNPTR_MAX_ARGS: i64 = 23

functions

66func tok_at(toks: *Tok, i: i64) -> *Tok
76func tr(c: i64) -> i64
112func parse_die(msg: *u8, msg_len: i64) -> i64
157func nx_diag_note_error() -> i64
171func nx_diag_puts(s: *u8) -> i64
180func nx_diag_why_undefined() -> i64
188func nx_diag_set_source(p: *u8, n: i64) -> i64
197func nx_diag_caret(line: i64, col: i64) -> i64
240func nx_diag_show_line(line: i64) -> i64
278func nx_dym_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
282func nx_dym_dist(a: *u8, la: i64, b: *u8, lb: i64, budget: i64) -> i64
326func nx_dym_suggest_fn(m: *Module, name: *u8, nlen: i64) -> i64
called by 1: parse_primary_call calls 1: nx_dym_dist
357func nx_put_dec_err(n: i64) -> i64
387func nx_diag_set_linemap(lm: *LineMap) -> i64
called by 2: mainlsp_child_analyze calls 1: lm_set_active
413func nx_diag_loc(line: i64) -> i64
439func nx_diag_at(line: i64) -> i64
449func nx_diag_organ_at(line: i64) -> i64
455func nx_put_tok_text_err(t: *Tok) -> i64
called by 1: nx_diag_token_window calls 1: tok_text_ptr
479func nx_diag_token_window(P: *Parser, tidx: i64) -> i64
719func sb_star_starts_store(P: *Parser) -> i64
called by 1: at_stmt_boundary calls 1: tok_at
744func peek_kind(P: *Parser) -> i64
771func at_stmt_boundary(P: *Parser) -> i64
818func peek_at(P: *Parser, k: i64) -> *Tok
calls 1: tok_at
829func advance_tok(P: *Parser) -> *Tok
836func check_kind(P: *Parser, k: i64) -> i64
calls 1: peek_kind
840func match_kind(P: *Parser, k: i64) -> i64
864func ty_name_eq(a: *u8, a_len: i64, b: *u8, b_len: i64) -> i64
883func clone_type_substituting(t: *Type, param_name: *u8,
913func ty_mangle_suffix(arg: *Type, out: *u8, off: i64, cap: i64) -> i64
982func lookup_struct(P: *Parser, name: *u8) -> *Type;
983func register_struct(P: *Parser, name: *u8, name_len: i64,
987func lookup_enum_type(P: *Parser, name: *u8) -> *Type;
called by 1: parse_type
998func instantiate_generic_n(P: *Parser, tmpl: *Type,
1057func parse_type(P: *Parser) -> *Type
1232func parser_loc_at(P: *Parser, i: i64) -> *Local
1238func copy_name_into_local(L: *Local, src: *u8) -> i64
called by 1: add_local
1252func local_name_eq(L: *Local, name: *u8) -> i64
1272func nx_dym_suggest_ident(P: *Parser, name: *u8, nlen: i64) -> i64
1326func find_local(P: *Parser, name: *u8) -> *Local
1339func local_in_block(P: *Parser, name: *u8) -> i64
1349func add_local(P: *Parser, name: *u8, value_id: i64, is_alloca: i64,
1406func parse_logical_or(P: *Parser) -> i64;
called by 1: parse_expr
1407func parse_unary_core(P: *Parser) -> i64;
1408func parse_primary(P: *Parser) -> i64;
called by 1: parse_unary_core
1409func parse_primary_ident(P: *Parser, t: *Tok) -> i64;
called by 1: parse_primary
1410func parse_primary_qualified_variant(P: *Parser, name: *u8) -> i64;
called by 1: parse_primary_ident
1411func parse_primary_intrinsic(P: *Parser, name: *u8) -> i64;
called by 1: parse_primary_ident
1412func parse_primary_call(P: *Parser, name: *u8) -> i64;
called by 1: parse_primary_ident
1413func parse_primary_local_or_const(P: *Parser, name: *u8) -> i64;
called by 1: parse_primary_ident
1414func parse_stmt_list(P: *Parser) -> i64;
1415func parse_stmt(P: *Parser) -> i64;
1416func parse_stmt_return(P: *Parser) -> i64;
1417func parse_stmt_let(P: *Parser) -> i64;
1418func parse_stmt_var(P: *Parser) -> i64;
1419func parse_stmt_if(P: *Parser) -> i64;
1420func parse_stmt_while(P: *Parser) -> i64;
1421func parse_stmt_for(P: *Parser) -> i64;
1422func parse_stmt_break(P: *Parser) -> i64;
1423func parse_stmt_continue(P: *Parser) -> i64;
1424func parse_stmt_match(P: *Parser) -> i64;
1425func parse_stmt_star(P: *Parser) -> i64;
1426func parse_stmt_ident(P: *Parser) -> i64;
1427func parse_stmt_ident_assign(P: *Parser) -> i64;
1428func parse_stmt_ident_subscript(P: *Parser) -> i64;
1429func parse_stmt_ident_dot(P: *Parser) -> i64;
1430func parse_stmt_expr_fallback(P: *Parser) -> i64;
1431func parse_module_const(P: *Parser) -> i64;
1432func lookup_mconst(P: *Parser, name: *u8, out: *i64) -> i64;
1433func lookup_mconst_f64(P: *Parser, name: *u8, out: *i64) -> i64;
1434func const_eval_f64_addsub(P: *Parser, depth: i64) -> i64;
1435func const_eval_f64_unary(P: *Parser, depth: i64) -> i64;
1436func lookup_mconst_string(P: *Parser, name: *u8,
1438func mconst_name_eq(mc: *MConst, name: *u8) -> i64;
1439func mconst_at(P: *Parser, i: i64) -> *MConst;
1442func const_eval_expr(P: *Parser, depth: i64) -> i64;
1443func const_eval_bor(P: *Parser, depth: i64) -> i64;
1444func const_eval_bxor(P: *Parser, depth: i64) -> i64;
1445func const_eval_band(P: *Parser, depth: i64) -> i64;
1446func const_eval_shift(P: *Parser, depth: i64) -> i64;
1447func const_eval_addsub(P: *Parser, depth: i64) -> i64;
1448func const_eval_muldiv(P: *Parser, depth: i64) -> i64;
1449func const_eval_unary(P: *Parser, depth: i64) -> i64;
1450func const_eval_primary(P: *Parser, depth: i64) -> i64;
1451func mconst_at(P: *Parser, i: i64) -> *MConst;
1452func copy_name_into_mconst(mc: *MConst, src: *u8) -> i64;
1453func parse_struct_decl(P: *Parser) -> i64;
1454func parse_static_decl(P: *Parser) -> i64;
1455func parse_module_enum(P: *Parser) -> i64;
1456func inject_statics(P: *Parser) -> i64;
1457func enum_entry_at(P: *Parser, i: i64) -> *EnumEntry;
1458func lookup_enum(P: *Parser, name: *u8) -> *EnumEntry;
1460func struct_entry_at(P: *Parser, i: i64) -> *StructEntry;
1462func parse_expr(P: *Parser) -> i64
1502func safe_const_i64(P: *Parser, val: i64, tag: *u8) -> i64
1538func emit_bounds_trap(P: *Parser) -> i64
1568func emit_trap_syscalls(P: *Parser, msg_v: i64, mlen: i64, code: i64) -> i64
1603func emit_bounds_check_v(P: *Parser, idx: i64, len_v: i64) -> i64
1623func emit_bounds_check(P: *Parser, idx: i64, nelem: i64) -> i64
1664func nx_ptrprov_set(v: i64) -> i64 { g_ptrprov_live = v; return 0 }
called by 1: main
1667func nx_ptrprov_reset_fn() -> i64
1680func pp_idx_check(P: *Parser, idx: i64, nelem: i64, ln: i64) -> i64
1706func bck_ptr_provenance_live() -> i64 { return g_ptrprov_live }
1748func nx_chkarith_set(v: i64) -> i64 { g_chkarith_live = v; return 0 }
called by 1: main
1773func nx_sendcheck_set(v: i64) -> i64 { g_sendcheck_live = v; return 0 }
called by 1: main
1774func sync_send_mark(name: *u8, len: i64) -> i64
1784func sync_send_is_marked(name: *u8, len: i64) -> i64
called by 1: sync_send_check
1797func sync_send_check(P: *Parser, name: *u8, nlen: i64, args: *i64, n_args: i64, ln: i64, cl: i64) -> i64
1824func chk_add_overflow_live() -> i64 { return g_chkarith_live }
1832func emit_overflow_trap(P: *Parser) -> i64
1855func chk_branch_on_overflow(P: *Parser, cond: i64) -> i64
1867func chk_add_overflow(P: *Parser, a: i64, b: i64, r: i64) -> i64
1877func chk_sub_overflow(P: *Parser, a: i64, b: i64, r: i64) -> i64
1888func chk_i64_min() -> i64
1901func chk_mul_overflow(P: *Parser, a: i64, b: i64, r: i64) -> i64
1931func chk_arith_applies(P: *Parser, op: i64, left: i64, right: i64, rty: *Type) -> i64
calls 1: nx_value_type
1948func chk_arith_inject(P: *Parser, op: i64, left: i64, right: i64, r: i64) -> i64
1957func chk_const_add_overflows(a: i64, b: i64) -> i64
1962func chk_const_sub_overflows(a: i64, b: i64) -> i64
1967func chk_const_mul_overflows(a: i64, b: i64) -> i64
1982func chk_const_overflow_refuse(P: *Parser, op: i64, left: i64, right: i64, op_tok: *Tok) -> i64
2041func nx_optenforce_set(v: i64) -> i64 { g_optenforce_live = v; return 0 }
called by 1: main
2044func opt_enforce_unwrap_live() -> i64 { return g_optenforce_live }
2058func oe_reset_fn() -> i64 { g_oe_base_val = 0 - 1; g_oe_base_unchk = 0; g_oe_term = 0; return 0 }
2067func oe_value_nonnull(P: *Parser, v: i64) -> i64
2127func oe_callee_is(fn: *Function, name: *u8, len: i64) -> i64
2143func oe_bind_local(P: *Parser, L: *Local, v: i64) -> i64
2152func oe_refuse(name: *u8, line: i64, col: i64) -> i64
2176func oe_local_is_static(P: *Parser, L: *Local) -> i64
2184func oe_check_local_deref(P: *Parser, L: *Local, tok: *Tok) -> i64
2195func oe_handshake_set(P: *Parser, L: *Local, v: i64, tok: *Tok) -> i64
2209func oe_chain_check(P: *Parser, v: i64) -> i64
2223func oe_probe_null_test(P: *Parser) -> i64
2340func nx_ownership_set(v: i64) -> i64 { g_ownership_live = v; return 0 }
called by 1: main
2349func own_check_live() -> i64 { return g_ownership_live }
2355func own_value_is_alloc(P: *Parser, v: i64) -> i64
2382func own_bind_local(P: *Parser, L: *Local, v: i64) -> i64
2398func own_mark(P: *Parser, L: *Local, st: i64, ln: i64) -> i64
2421func own_refuse(name: *u8, line: i64, col: i64, st: i64, from_line: i64) -> i64
2460func own_check_use(P: *Parser, L: *Local, tok: *Tok) -> i64
2474func own_mark_named(P: *Parser, tok: *Tok, st: i64) -> i64
2487func own_move_arg(P: *Parser, tok: *Tok) -> i64
2529func parse_field_of_struct(P: *Parser, stty: *Type, ftok: *Tok, fname: *u8, flen: i64) -> *StructField
2556func parse_field_chain(P: *Parser, base: i64, base_ty: *Type) -> i64
2778func parse_primary(P: *Parser) -> i64
3034func parse_primary_ident(P: *Parser, t: *Tok) -> i64
3052func parse_primary_qualified_variant(P: *Parser, name: *u8) -> i64
3135func parse_layout_query_kind(name: *u8) -> i64
called by 1: parse_primary_intrinsic calls 1: streq_n
3144func parse_layout_query_value(P: *Parser, layout_query: i64) -> i64
3175func parse_primary_intrinsic(P: *Parser, name: *u8) -> i64
4218func parse_primary_call(P: *Parser, name: *u8) -> i64
4528func mc_name_eq(a: *u8, b: *u8) -> i64
4538func mconst_declared_later(P: *Parser, name: *u8) -> i64
4562func parse_primary_local_or_const(P: *Parser, name: *u8) -> i64
4844func parse_unary(P: *Parser) -> i64
4888func parse_unary_core(P: *Parser) -> i64
5059func fp_op_for_int(op: i64) -> i64
5067func has_fp_operand(P: *Parser, v: i64) -> i64
5078func nx_value_type(P: *Parser, v: i6