code wiki / (root) / nx_quality_grade_daemon.nx

nx_quality_grade_daemon.nx source

↩ module page · 105 lines · 3381 B

1// nx_quality_grade_daemon.nx -- grade nx_daemon_bench.nx (another 2// substrate file) and verify it clears A. Demonstrates the grader 3// works on substrate code beyond the grader itself. 4// 5// license_tier: ORIGINAL 6// 7// expect_exit: 0 8 9// nx_safety_envelope: 10// intended_use: AUTO_APPLIED -- primitive-specific tuning queued 11// sil_target: SIL1 12// evidence: [bulk_applied_2026-05-16, see-file-comment-for-detail] 13// verdict: NOT_YET_EVALUATED 14 15import "nx_syscalls.nx" 16import "nx_runtime.nx" 17import "nx_types.nx" 18import "nx_tier.nx" 19import "nx_lex_kinds.nx" 20import "nx_ir.nx" 21import "nx_tokenizer.nx" 22import "nx_parse.nx" 23import "nx_quality_grade.nx" 24 25func main() -> nx_int { 26 let path: *u8 = "runtime/nx_daemon_bench.nx" as *u8 27 let len_raw: *u8 = sys_mmap(16) 28 let len_p: *i64 = len_raw as *i64 29 let src: *u8 = sys_read_file(path, len_p) 30 if src == (0 as *u8) { 31 sys_write(2, "grade_daemon: cannot read source\n" as *u8, 33) 32 return 1 33 } 34 if len_p[0] == 0 { 35 sys_write(2, "grade_daemon: source is empty\n" as *u8, 30) 36 return 2 37 } 38 39 let toks: *Tok = lex_source(src, 262144) 40 if toks == (0 as *Tok) { 41 sys_write(2, "grade_daemon: lex failed\n" as *u8, 25) 42 return 3 43 } 44 45 let m: *Module = parse_module(toks, 0 as *Module) 46 if m == (0 as *Module) { 47 sys_write(2, "grade_daemon: parse failed\n" as *u8, 27) 48 return 4 49 } 50 if m.n_functions == 0 { 51 sys_write(2, "grade_daemon: zero functions\n" as *u8, 29) 52 return 5 53 } 54 55 let prof_sq_raw: *u8 = sys_mmap(256) 56 let prof_sq: *GradeProfile = prof_sq_raw as *GradeProfile 57 nx_grade_profile_sonarqube(prof_sq) 58 59 let prof_cl_raw: *u8 = sys_mmap(256) 60 let prof_cl: *GradeProfile = prof_cl_raw as *GradeProfile 61 nx_grade_profile_clippy(prof_cl) 62 63 let prof_el_raw: *u8 = sys_mmap(256) 64 let prof_el: *GradeProfile = prof_el_raw as *GradeProfile 65 nx_grade_profile_elm(prof_el) 66 67 let card_sq: *GradeCard = nx_grade_card_alloc() 68 nx_grade_card_init(card_sq) 69 nx_grade_card_scan(card_sq, m, prof_sq) 70 nx_grade_card_compute(card_sq, prof_sq) 71 72 let card_cl: *GradeCard = nx_grade_card_alloc() 73 nx_grade_card_init(card_cl) 74 nx_grade_card_scan(card_cl, m, prof_cl) 75 nx_grade_card_compute(card_cl, prof_cl) 76 77 let card_el: *GradeCard = nx_grade_card_alloc() 78 nx_grade_card_init(card_el) 79 nx_grade_card_scan(card_el, m, prof_el) 80 nx_grade_card_compute(card_el, prof_el) 81 82 let tri: *GradeTriangulation = nx_grade_triangulation_alloc() 83 nx_grade_triangulate(tri, card_sq, card_cl, card_el) 84 85 print("=== nx_daemon_bench.nx, graded ===" as *u8) 86 println("" as *u8) 87 print("=== SONARQUBE ===" as *u8) 88 println("" as *u8) 89 nx_grade_card_emit(card_sq) 90 print("=== CLIPPY ===" as *u8) 91 println("" as *u8) 92 nx_grade_card_emit(card_cl) 93 print("=== ELM ===" as *u8) 94 println("" as *u8) 95 nx_grade_card_emit(card_el) 96 print("=== TRIANGULATED ===" as *u8) 97 println("" as *u8) 98 nx_grade_triangulation_emit(tri) 99 100 // Substrate-wide acceptance gate: daemon source must triangulate 101 // at A or S. If the daemon ever drops below A, this smoke fails 102 // and forces a fix before merge. Cardinal: self-aware substrate. 103 if tri.final_grade < NX_GRADE_A { return 10 } 104 return 0 105}