code wiki / (root) / nx_gramdec_lib.nx

nx_gramdec_lib.nx

buildroot/runtime/nx_gramdec_lib.nx

17095 B460 linesdepth 10pulls 21 transitivereach 2 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_gramdec_lib.nx -- NB10 GRAMMAR-CONSTRAINED DECODE (neuro-symbolic builder lane, 2026-07-20). Makes the small maker STRUCTURALLY UNABLE to emit ungrammatical NishiLang candidates: a token is sampled, its decoded bytes are run through a NishiLang function-fragment prefix automaton, and a rejected token is LOGIT-MASKED and re-sampled (renormalized constrained decode). EOS is masked until the function is brace-complete (the model cannot stop mid-function); once complete, decode stops (accept-state). Greedy steps that the grammar accepts ride the UNCHANGED head_argmax hero path -- the mask only engages on a rejection, so an already-grammatical generation is BIT-EXACT with nsv_generate over its prefix. HONEST SCOPE (v1): a regular+counter APPROXIMATION of NishiLang for SELF-CONTAINED integer functions (the v1 judge's declared scope) -- brace/paren balance, `else` only as `} else {` (kills the else-if build-break class), NO calls in the body (ident '(' reject + known-helper denylist: kills abs()/min() undefined-fn breaks), unary minus on an identifier rejected while negative literals stay legal, charset fence. Grammar-valid != correct: the fresh compile+run grader and nx_symjudge property sweep still judge EVERY candidate (the union stays sound; the mask only shrinks the candidate space). Fail-closed: a mask deadlock stops generation (honest MISS), never lets an ungrammatical token through. license_tier: ORIGINAL No hw writes (Rule 26).

dependencies 1 imports · 2 importers

nx_nofloat_serve_core.nx nx_gramdec_lib.nx nx_autofix_auto.nx nx_gramdec_gate.nx

imports: nx_nofloat_serve_core.nx

imported by: nx_autofix_auto.nxnx_gramdec_gate.nx

structs

none

consts

19const GD_MAGIC_88172645463325252: i64 = 88172645463325252
22const GD_MASK_LOGIT: i64 = 0 - 1099511627776
23const GD_MAX_TRIES: i64 = 256
24const GD_WORD_CAP: i64 = 48
25const GD_TOKTXT_CAP: i64 = 1024
28const GD_NEG_ALLOW_ELSEIF: i64 = 0
29const GD_NEG_MASK_OFF: i64 = 0
31const GD_DENY_HELPERS: *u8 = " abs min max pow sqrt fabs floor ceil "
32const GD_KEYWORDS: *u8 = " if while return let var else func as "
35const GDI_PHASE: i64 = 0
36const GDI_LIT: i64 = 1
37const GDI_BRACE: i64 = 2
38const GDI_PAREN: i64 = 3
39const GDI_WLEN: i64 = 4
40const GDI_LASTSIG: i64 = 5
41const GDI_PMINUS: i64 = 6
42const GDI_PELSE: i64 = 7
43const GDI_PARROW: i64 = 8
44const GDI_LASTIDENT: i64 = 9
45const GDI_PREWORD: i64 = 10
46const GDI_N: i64 = 11

functions

55func gd_w(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: gdx_pick
57func gd_mem() -> i64
66func gd_reset() -> i64
called by 2: gd_validategdx_generate calls 1: gd_mem
72func gd_isid(c: i64) -> i64
called by 1: gd_step
79func gd_isdig(c: i64) -> i64 { if c >= 48 { if c <= 57 { return 1 } } return 0 }
called by 1: gd_step
80func gd_isws(c: i64) -> i64
called by 1: gd_step
88func gd_word_in(list: *u8) -> i64
called by 1: gd_word_end
112func gd_word_end() -> i64
called by 1: gd_step calls 1: gd_word_in
139func gd_step(c: i64) -> i64
257func gd_feed(s: *u8, n: i64) -> i64
called by 1: gdx_pick calls 2: gd_memgd_step
281func gd_accepting() -> i64
called by 2: gd_validategdx_generate calls 1: gd_mem
287func gd_validate(s: *u8, n: i64) -> i64
299func gdx_tok_text(tok: i64, tb: *u8) -> i64
306func gdx_argmax() -> i64
called by 1: gdx_pick
319func gdx_pick(np: *i64) -> i64
377func gdx_generate(gp: *i64) -> i64