nx_gramdec_lib.nx
buildroot/runtime/nx_gramdec_lib.nx
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
imports: nx_nofloat_serve_core.nx
imported by: nx_autofix_auto.nxnx_gramdec_gate.nx
structs
| none |
consts
| 19 | const GD_MAGIC_88172645463325252: i64 = 88172645463325252 |
| 22 | const GD_MASK_LOGIT: i64 = 0 - 1099511627776 |
| 23 | const GD_MAX_TRIES: i64 = 256 |
| 24 | const GD_WORD_CAP: i64 = 48 |
| 25 | const GD_TOKTXT_CAP: i64 = 1024 |
| 28 | const GD_NEG_ALLOW_ELSEIF: i64 = 0 |
| 29 | const GD_NEG_MASK_OFF: i64 = 0 |
| 31 | const GD_DENY_HELPERS: *u8 = " abs min max pow sqrt fabs floor ceil " |
| 32 | const GD_KEYWORDS: *u8 = " if while return let var else func as " |
| 35 | const GDI_PHASE: i64 = 0 |
| 36 | const GDI_LIT: i64 = 1 |
| 37 | const GDI_BRACE: i64 = 2 |
| 38 | const GDI_PAREN: i64 = 3 |
| 39 | const GDI_WLEN: i64 = 4 |
| 40 | const GDI_LASTSIG: i64 = 5 |
| 41 | const GDI_PMINUS: i64 = 6 |
| 42 | const GDI_PELSE: i64 = 7 |
| 43 | const GDI_PARROW: i64 = 8 |
| 44 | const GDI_LASTIDENT: i64 = 9 |
| 45 | const GDI_PREWORD: i64 = 10 |
| 46 | const GDI_N: i64 = 11 |
functions
| 55 | func 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 |
| 57 | func gd_mem() -> i64 |
| 66 | func gd_reset() -> i64 |
| 72 | func gd_isid(c: i64) -> i64 called by 1: gd_step |
| 79 | func gd_isdig(c: i64) -> i64 { if c >= 48 { if c <= 57 { return 1 } } return 0 } called by 1: gd_step |
| 80 | func gd_isws(c: i64) -> i64 called by 1: gd_step |
| 88 | func gd_word_in(list: *u8) -> i64 called by 1: gd_word_end |
| 112 | func gd_word_end() -> i64 |
| 139 | func gd_step(c: i64) -> i64 |
| 257 | func gd_feed(s: *u8, n: i64) -> i64 |
| 281 | func gd_accepting() -> i64 |
| 287 | func gd_validate(s: *u8, n: i64) -> i64 |
| 299 | func gdx_tok_text(tok: i64, tb: *u8) -> i64 called by 1: gdx_pick calls 4: tk_decode_offnx_gguf_meta_read_string_lennx_gguf_meta_read_string_ptrtd_piece_decode |
| 306 | func gdx_argmax() -> i64 called by 1: gdx_pick |
| 319 | func gdx_pick(np: *i64) -> i64 called by 1: gdx_generate calls 8: head_argmax_cached_i32nsv_next_tokengdx_tok_textgd_feedhead_logits_cached_i32gdx_argmax+2 |
| 377 | func gdx_generate(gp: *i64) -> i64 called by 3: lf_genlf_gen_tgg_gen calls 9: tk_bpe_encodesys_now_msgd_resetdequant_rownsv_steprmsnorm_gamma_row_q24+3 |