code wiki / (root) / nx_glsl_tok_lib.nx

nx_glsl_tok_lib.nx

buildroot/runtime/nx_glsl_tok_lib.nx

46704 B1013 linesdepth 2pulls 2 transitivereach 44 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_glsl_tok_lib.nx -- THE SHADER TOKEN RULER (gameengine S12c accept-rule instrument, 2026-09-05). WHY: the cast port's pre-declared accept rule says the IR-emitted GLSL must match the hand-written MVS/MFS at ZERO normalised-token distance before its WGSL twin is trusted. A byte diff cannot be that ruler (the hand shader has formatting freedom, comments, `.5` for `0.5`, `br/=nr` for `br=br/nr`) and a string-run ruler cannot either (it has no grammar). This lib is ONE tokenizer + ONE canonicaliser + ONE compound-assignment expander + ONE differ, composed in-process by nx_glsl_tokdiff (the program) and nx_glsl_tokdiff_gate (planted fixtures, both directions). NORMALISATIONS, each named: whitespace and comments dropped; numeric literals canonicalised (`.5`->`0.5`, `1.`->`1.0`, trailing f/F/u/U dropped); `x op= y` expanded to `x = x op y` for op in + - * / where x is an lvalue of the grammar ident ( '.' ident | '[' ... ']' )* -- any other shape is left literal and COUNTED (expand_refused=), never guessed. Everything else must match token for token: a renamed identifier, a moved parenthesis, a changed constant is a DIFF, and the first differing token is named with both spellings. Token = 3 words (start, len, kind); kinds 1 ident, 2 number, 3 operator/punct. Buffers are sized from the input (one token cannot be shorter than one byte, so 3*n words is a bound that cannot overflow -- no guessed cap). license_tier: ORIGINAL No hw writes (Rule 26).

dependencies 1 imports · 43 importers

nx_syscalls.nx nx_glsl_tok_lib.nx nx_craft_affine_fit_t342.nx nx_craft_body_affine_alpha_fit_t36 nx_craft_body_fit_t138.nx nx_craft_body_semantic_alpha_fit_t nx_craft_body_winding_alpha_fit_t3 nx_craft_canonical_fit_t135.nx nx_craft_eye_fit_t138.nx nx_craft_gait_fit_t139.nx nx_craft_garment_fit_t132.nx nx_craft_hair_attachment_fit_t263.

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

imports: nx_syscalls.nx

imported by: nx_craft_affine_fit_t342.nxnx_craft_body_affine_alpha_fit_t361.nxnx_craft_body_fit_t138.nxnx_craft_body_semantic_alpha_fit_t345.nxnx_craft_body_winding_alpha_fit_t365.nxnx_craft_canonical_fit_t135.nxnx_craft_eye_fit_t138.nxnx_craft_gait_fit_t139.nxnx_craft_garment_fit_t132.nxnx_craft_hair_attachment_fit_t263.nxnx_craft_hair_attachment_fit_t283.nxnx_craft_hair_probe_fit_t280.nxnx_craft_imported_fit_t262.nxnx_craft_inspection_alpha_fit_t342.nxnx_craft_inspection_canonical_fit_t142.nxnx_craft_inspection_distance_fit_t235.nxnx_craft_inspection_fit_t142.nxnx_craft_integrated_fit_t73.nxnx_craft_length_fit_t140.nxnx_craft_mip_fit_t241.nxnx_craft_motion_fit_t328.nxnx_craft_person_alpha_fit_t343.nxnx_craft_procedural_review_fit_candidate_t333.nxnx_craft_rig_comparison_fit_t332.nxnx_craft_rig_inspection_fit_t230.nxnx_craft_rig_observation_fit_t331.nxnx_craft_rigview_host_fit_t341.nxnx_craft_rigview_workbench_fit_t342.nxnx_craft_scene_light_alpha_fit_t364.nxnx_craft_skin_canonical_diag_t140.nxnx_craft_skin_canonical_fit_t140.nxnx_craft_skin_fit_t138.nxnx_craft_skin_wrap_fit_t261.nxnx_craft_static_fit_t338.nxnx_craft_toon_region_fit_t143.nxnx_craft_visitors_canonical_fit_t142.nxnx_craft_visitors_fit_t140.nxnx_craft_visitors_inspection_fit_t142.nxnx_craft_visitors_lit_fit_t181.nxnx_craft_visitors_material_fit_t181.nxnx_craft_visitors_owned_fit_t219.nxnx_glsl_tokdiff.nxnx_glsl_tokdiff_gate.nx

structs

none

consts

18const GT_K_IDENT: i64 = 1
19const GT_K_NUM: i64 = 2
20const GT_K_OP: i64 = 3
21const GT_TW: i64 = 3
22const GT_R_TOKA: i64 = 0
23const GT_R_TOKB: i64 = 1
24const GT_R_EXPA: i64 = 2
25const GT_R_EXPB: i64 = 3
26const GT_R_FIRSTDIFF: i64 = 4
27const GT_R_VERDICT: i64 = 5
28const GT_R_REFUSED: i64 = 6
29const GT_R_SLOTS: i64 = 20
30const GT_V_IDENTICAL: i64 = 0
31const GT_V_DIFFERS: i64 = 1
32const GT_V_UNREADABLE: i64 = 2
33const GT_CANON_CAP: i64 = 512
34const GT_NUMBUF: i64 = 32
35const C_TAB: i64 = 9
36const C_NL: i64 = 10
37const C_CR: i64 = 13
38const C_SP: i64 = 32
39const C_BANG: i64 = 33
40const C_AMP: i64 = 38
41const C_LPAR: i64 = 40
42const C_RPAR: i64 = 41
43const C_STAR: i64 = 42
44const C_PLUS: i64 = 43
45const C_MINUS: i64 = 45
46const C_DOT: i64 = 46
47const C_SLASH: i64 = 47
48const C_0: i64 = 48
49const C_9: i64 = 57
50const C_LT: i64 = 60
51const C_EQ: i64 = 61
52const C_GT: i64 = 62
53const C_A: i64 = 65
54const C_E: i64 = 69
55const C_F: i64 = 70
56const C_U: i64 = 85
57const C_Z: i64 = 90
58const C_LBR: i64 = 91
59const C_RBR: i64 = 93
60const C_USCORE: i64 = 95
61const C_a: i64 = 97
62const C_e: i64 = 101
63const C_f: i64 = 102
64const C_u: i64 = 117
65const C_z: i64 = 122
66const C_BAR: i64 = 124
376const GN_KIND: i64 = 0
377const GN_TOK: i64 = 1
378const GN_A: i64 = 2
379const GN_B: i64 = 3
380const GN_C: i64 = 4
381const GN_NEXT: i64 = 5
382const GN_SLOTS: i64 = 6
383const GN_LEAF: i64 = 1
384const GN_BIN: i64 = 2
385const GN_UN: i64 = 3
386const GN_TERN: i64 = 4
387const GN_CALL: i64 = 5
388const GN_INDEX: i64 = 6
389const GN_SWZ: i64 = 7
390const GN_ASSIGN: i64 = 8
391const GN_INCDEC: i64 = 9
392const GP_POS: i64 = 0
393const GP_NTOK: i64 = 1
394const GP_OUT: i64 = 2
395const GP_ERR: i64 = 3
396const GP_NCOUNT: i64 = 4
397const GP_SRC: i64 = 5
398const GP_TOKS: i64 = 6
399const GP_NODES: i64 = 7
400const GP_OUTBUF: i64 = 8
401const GP_CAP: i64 = 9
402const GP_OVER: i64 = 10
403const GP_TMP: i64 = 11
404const GP_SLOTS: i64 = 12
405const GP_M_ASSIGN: i64 = 1
406const GP_M_TERN: i64 = 2
407const GP_M_BIN: i64 = 3
408const GP_M_UNARY: i64 = 4
409const GP_P_LOR: i64 = 1
410const GP_P_LAND: i64 = 2
411const GP_P_BOR: i64 = 3
412const GP_P_BXOR: i64 = 4
413const GP_P_BAND: i64 = 5
414const GP_P_EQ: i64 = 6
415const GP_P_REL: i64 = 7
416const GP_P_SHIFT: i64 = 8
417const GP_P_ADD: i64 = 9
418const GP_P_MUL: i64 = 10
419const GP_INV_NONE: i64 = 0
420const GP_INV_GE: i64 = 1
421const GP_INV_LE: i64 = 2
422const GP_INV_GT: i64 = 3
423const GP_INV_LT: i64 = 4
424const GP_INV_NE: i64 = 5
425const GP_INV_EQ: i64 = 6
426const C_QMARK: i64 = 63
427const C_COLON: i64 = 58
428const C_SEMI: i64 = 59
429const C_COMMA: i64 = 44
430const C_LBRACE: i64 = 123
431const C_RBRACE: i64 = 125
432const C_CARET: i64 = 94
433const C_PCT: i64 = 37
434const C_1: i64 = 49
437const GT_CANON_OUT_MULT: i64 = 8
438const GT_CANON_OUT_HEAD: i64 = 4096
440const GT_R_CANA: i64 = 7
441const GT_R_CANB: i64 = 8
442const GT_R_ERRA: i64 = 9
443const GT_R_ERRB: i64 = 10
444const GT_R_ERRLA: i64 = 11
445const GT_R_ERRLB: i64 = 12
446const GT_R_CAPTR_A: i64 = 13
447const GT_R_CALEN_A: i64 = 14
448const GT_R_CAPTR_B: i64 = 15
449const GT_R_CALEN_B: i64 = 16
450const GT_R_SRCA: i64 = 17
451const GT_R_SRCB: i64 = 18
452const GT_R_OVER: i64 = 19

functions

68func gt_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
69func gt_fputs(fd: i64, s: *u8) -> i64 { sys_write(fd, s, gt_slen(s)); return 0 }
70func gt_fputn(fd: i64, v: i64) -> i64
83func gt_isalpha(c: i64) -> i64
called by 1: gt_tokenize
89func gt_isdigit(c: i64) -> i64 { if c >= C_0 { if c <= C_9 { return 1 } } return 0 }
called by 1: gt_tokenize
90func gt_isspace(c: i64) -> i64
called by 1: gt_tokenize
98func gt_op2(a: i64, b: i64) -> i64
called by 1: gt_tokenize
119func gt_tokenize(src: *u8, n: i64, toks: *i64) -> i64
186func gt_canon(src: *u8, toks: *i64, t: i64, out: *u8, cap: i64) -> i64
212func gt_is_compound(src: *u8, toks: *i64, t: i64) -> i64
called by 2: gt_expandgp_parse
224func gt_tok_is(src: *u8, toks: *i64, t: i64, ch: i64) -> i64
called by 1: gt_lvalue_start
232func gt_lvalue_start(src: *u8, toks: *i64, last: i64) -> i64
called by 1: gt_expand calls 1: gt_tok_is
262func gt_expand(src: *u8, toks: *i64, k: i64, xt: *i64, box: *i64) -> i64
287func gt_diff(a: *u8, na: i64, b: *u8, nb: i64, r: *i64) -> i64
325func gt_put_expanded_tok(fd: i64, src: *u8, n: i64, i: i64) -> i64
338func gt_report(fd: i64, a: *u8, na: i64, b: *u8, nb: i64, r: *i64) -> i64
454func gp_tk(ps: *i64, t: i64, w: i64) -> i64 { let tk: *i64 = ps[GP_TOKS] as *i64; return tk[t * GT_TW + w] }
455func gp_byte(ps: *i64, t: i64, i: i64) -> i64 { let s: *u8 = ps[GP_SRC] as *u8; return s[gp_tk(ps, t, 0) + i] as i64 }
456func gp_kind(ps: *i64, t: i64) -> i64
461func gp_is1(ps: *i64, t: i64, ch: i64) -> i64
467func gp_is2(ps: *i64, t: i64, a: i64, b: i64) -> i64
called by 1: gp_parse calls 3: gp_kindgp_tkgp_byte
474func gp_isword(ps: *i64, t: i64, w: *u8) -> i64
called by 1: gp_stmt calls 4: gp_kindgp_tkgt_slengp_byte
482func gp_fail(ps: *i64, t: i64) -> i64 { if ps[GP_ERR] < 0 { ps[GP_ERR] = t } return 0 }
483func gp_n(ps: *i64, id: i64, w: i64) -> i64 { let nd: *i64 = ps[GP_NODES] as *i64; return nd[id * GN_SLOTS + w] }
called by 1: gp_print
484func gp_nset(ps: *i64, id: i64, w: i64, v: i64) -> i64 { let nd: *i64 = ps[GP_NODES] as *i64; nd[id * GN_SLOTS + w] = v; return 0 }
called by 2: gp_nodegp_parse
485func gp_node(ps: *i64, kind: i64, tok: i64, a: i64, b: i64, c: i64) -> i64
called by 2: gp_parsegp_stmt calls 1: gp_nset
491func gp_putc(ps: *i64, ch: i64) -> i64
498func gp_emit_c(ps: *i64, ch: i64) -> i64 { gp_putc(ps, ch); gp_putc(ps, C_SP); return 0 }
499func gp_emit_s(ps: *i64, s: *u8) -> i64
called by 1: gp_stmt calls 1: gp_putc
506func gp_emit_tok(ps: *i64, t: i64) -> i64
514func gp_take(ps: *i64) -> i64 { ps[GP_POS] = ps[GP_POS] + 1; return 0 }
516func gp_expect(ps: *i64, ch: i64) -> i64
522func gp_binprec(ps: *i64, t: i64) -> i64
called by 1: gp_parse calls 3: gp_kindgp_tkgp_byte
554func gp_parse(ps: *i64, mode: i64, minp: i64) -> i64
668func gp_inv(ps: *i64, t: i64) -> i64
called by 1: gp_print calls 3: gp_kindgp_tkgp_byte
684func gp_emit_inv(ps: *i64, inv: i64) -> i64
called by 1: gp_print calls 1: gp_putc
695func gp_print(ps: *i64, id: i64) -> i64
744func gp_stmt(ps: *i64, wrap: i64) -> i64
889func gp_toplevel(ps: *i64) -> i64
907func gt_canon_text(src: *u8, n: i64, out: *u8, cap: i64, box: *i64) -> i64
933func gt_diff_canon(a: *u8, na: i64, b: *u8, nb: i64, r: *i64) -> i64
966func gt_slice_prefix(r: *i64) -> i64
called by 1: gt_report_canon
982func gt_report_canon(fd: i64, r: *i64) -> i64