nx_quality_grade_quad.nx source
↩ module page · 108 lines · 3776 B
1// nx_quality_grade_quad.nx -- four-grader polyangulation on the
2// grader itself. Adds NASA JPL Power of 10 as the 4th perspective,
3// closing the "safety-critical embedded" coverage gap from the
4// research audit 2026-05-15.
5//
6// license_tier: ORIGINAL
7//
8// expect_exit: 0
9
10// nx_safety_envelope:
11// intended_use: AUTO_APPLIED -- primitive-specific tuning queued
12// sil_target: SIL1
13// evidence: [bulk_applied_2026-05-16, see-file-comment-for-detail]
14// verdict: NOT_YET_EVALUATED
15
16import "nx_syscalls.nx"
17import "nx_runtime.nx"
18import "nx_types.nx"
19import "nx_tier.nx"
20import "nx_lex_kinds.nx"
21import "nx_ir.nx"
22import "nx_tokenizer.nx"
23import "nx_parse.nx"
24import "nx_quality_grade.nx"
25
26func main() -> nx_int {
27 let path: *u8 = "runtime/nx_quality_grade.nx" as *u8
28 let len_raw: *u8 = sys_mmap(16)
29 let len_p: *i64 = len_raw as *i64
30 let src: *u8 = sys_read_file(path, len_p)
31 if src == (0 as *u8) { return 1 }
32 if len_p[0] == 0 { return 2 }
33
34 let toks: *Tok = lex_source(src, 262144)
35 if toks == (0 as *Tok) { return 3 }
36 let m: *Module = parse_module(toks, 0 as *Module)
37 if m == (0 as *Module) { return 4 }
38 if m.n_functions == 0 { return 5 }
39
40 // Build all 4 profiles.
41 let prof_sq_raw: *u8 = sys_mmap(512)
42 let prof_sq: *GradeProfile = prof_sq_raw as *GradeProfile
43 nx_grade_profile_sonarqube(prof_sq)
44
45 let prof_cl_raw: *u8 = sys_mmap(512)
46 let prof_cl: *GradeProfile = prof_cl_raw as *GradeProfile
47 nx_grade_profile_clippy(prof_cl)
48
49 let prof_el_raw: *u8 = sys_mmap(512)
50 let prof_el: *GradeProfile = prof_el_raw as *GradeProfile
51 nx_grade_profile_elm(prof_el)
52
53 let prof_jpl_raw: *u8 = sys_mmap(512)
54 let prof_jpl: *GradeProfile = prof_jpl_raw as *GradeProfile
55 nx_grade_profile_jpl(prof_jpl)
56
57 // Scan + compute on all 4 cards.
58 let card_sq: *GradeCard = nx_grade_card_alloc()
59 nx_grade_card_init(card_sq)
60 nx_grade_card_scan(card_sq, m, prof_sq)
61 nx_grade_card_compute(card_sq, prof_sq)
62
63 let card_cl: *GradeCard = nx_grade_card_alloc()
64 nx_grade_card_init(card_cl)
65 nx_grade_card_scan(card_cl, m, prof_cl)
66 nx_grade_card_compute(card_cl, prof_cl)
67
68 let card_el: *GradeCard = nx_grade_card_alloc()
69 nx_grade_card_init(card_el)
70 nx_grade_card_scan(card_el, m, prof_el)
71 nx_grade_card_compute(card_el, prof_el)
72
73 let card_jpl: *GradeCard = nx_grade_card_alloc()
74 nx_grade_card_init(card_jpl)
75 nx_grade_card_scan(card_jpl, m, prof_jpl)
76 nx_grade_card_compute(card_jpl, prof_jpl)
77
78 // Polyangulate across all 4.
79 let tri: *GradeTriangulation = nx_grade_triangulation_alloc()
80 nx_grade_polyangulate(tri, card_sq, card_cl, card_el, card_jpl)
81
82 print("=== 4-grader polyangulation of nx_quality_grade.nx ===" as *u8)
83 println("" as *u8)
84 print("=== SONARQUBE ===" as *u8)
85 println("" as *u8)
86 nx_grade_card_emit(card_sq)
87 print("=== CLIPPY ===" as *u8)
88 println("" as *u8)
89 nx_grade_card_emit(card_cl)
90 print("=== ELM ===" as *u8)
91 println("" as *u8)
92 nx_grade_card_emit(card_el)
93 print("=== JPL/MISRA ===" as *u8)
94 println("" as *u8)
95 nx_grade_card_emit(card_jpl)
96 print("=== POLYANGULATED (4 graders) ===" as *u8)
97 println("" as *u8)
98 nx_grade_triangulation_emit(tri)
99
100 // Gate: substrate must polyangulate >= B across all 4 graders.
101 // 4-grader is genuinely stricter than 3-grader; adding JPL's
102 // safety-critical thresholds + the wider rule surface from
103 // Layer 2 means SOME categories may legitimately disagree.
104 // The 1 LOSE today is performance fan-out (nx_grade_triangulate
105 // at the boundary). Queued refactor moves to A.
106 if tri.final_grade < NX_GRADE_B { return 10 }
107 return 0
108}