code wiki / (root) / nx_quality_grade_self.nx

nx_quality_grade_self.nx source

↩ module page · 114 lines · 4157 B

1// nx_quality_grade_self.nx -- the grader, graded by itself. 2// 3// license_tier: ORIGINAL 4// 5// Reads runtime/nx_quality_grade.nx as bytes, lexes + parses via the 6// self-host front-end, runs all three Layer-0 graders, triangulates, 7// emits the verdict. This is the recursive self-assessment the user 8// asked for 2026-05-15: the grader must score well on its own rules 9// before we expand to Layer 1. 10// 11// expect_exit: 0 12 13// nx_safety_envelope: 14// intended_use: AUTO_APPLIED -- primitive-specific tuning queued 15// sil_target: SIL1 16// evidence: [bulk_applied_2026-05-16, see-file-comment-for-detail] 17// verdict: NOT_YET_EVALUATED 18 19import "nx_syscalls.nx" 20import "nx_runtime.nx" 21import "nx_types.nx" 22import "nx_tier.nx" 23import "nx_lex_kinds.nx" 24import "nx_ir.nx" 25import "nx_tokenizer.nx" 26import "nx_parse.nx" 27import "nx_quality_grade.nx" 28 29func main(argc: i64, argv: *i64) -> nx_int { 30 // Grade an ARBITRARY organ if a path is given (argv[1]); else self-grade the grader (default, expect_exit:0). 31 // NOTE 2026-07-04: the arbitrary-file path is GATED ON self-host parser robustness -- parse_module chokes on 32 // some real organs (e.g. module-level `func F() -> *u8 { return "lit" }` -> "call to undefined function: 33 // sys_write"), so a general "grade my organ" MCP tool needs the front-end to handle the FULL language first 34 // (the compiler-robustness arc). Until then this defaults to the proven self-grade; passing a path is 35 // best-effort + may fail-parse on unsupported constructs (honest: not yet the SOTA LLM-facing grader). 36 var path: *u8 = "runtime/nx_quality_grade.nx" as *u8 37 if argc >= 2 { path = argv[1] as *u8 } 38 let len_raw: *u8 = sys_mmap(16) 39 let len_p: *i64 = len_raw as *i64 40 let src: *u8 = sys_read_file(path, len_p) 41 if src == (0 as *u8) { 42 sys_write(2, "self-grade: cannot read source\n" as *u8, 31) 43 return 1 44 } 45 if len_p[0] == 0 { 46 sys_write(2, "self-grade: source is empty\n" as *u8, 28) 47 return 2 48 } 49 50 // Lex + parse. 256K tokens covers the grader source (~700 lines). 51 let toks: *Tok = lex_source(src, 262144) 52 if toks == (0 as *Tok) { 53 sys_write(2, "self-grade: lex failed\n" as *u8, 23) 54 return 3 55 } 56 57 let m: *Module = parse_module(toks, 0 as *Module) 58 if m == (0 as *Module) { 59 sys_write(2, "self-grade: parse failed\n" as *u8, 25) 60 return 4 61 } 62 if m.n_functions == 0 { 63 sys_write(2, "self-grade: zero functions parsed\n" as *u8, 34) 64 return 5 65 } 66 67 // Allocate three profiles + three cards. 68 let prof_sq_raw: *u8 = sys_mmap(128) 69 let prof_sq: *GradeProfile = prof_sq_raw as *GradeProfile 70 nx_grade_profile_sonarqube(prof_sq) 71 72 let prof_cl_raw: *u8 = sys_mmap(128) 73 let prof_cl: *GradeProfile = prof_cl_raw as *GradeProfile 74 nx_grade_profile_clippy(prof_cl) 75 76 let prof_el_raw: *u8 = sys_mmap(128) 77 let prof_el: *GradeProfile = prof_el_raw as *GradeProfile 78 nx_grade_profile_elm(prof_el) 79 80 let card_sq: *GradeCard = nx_grade_card_alloc() 81 nx_grade_card_init(card_sq) 82 nx_grade_card_scan(card_sq, m, prof_sq) 83 nx_grade_card_compute(card_sq, prof_sq) 84 85 let card_cl: *GradeCard = nx_grade_card_alloc() 86 nx_grade_card_init(card_cl) 87 nx_grade_card_scan(card_cl, m, prof_cl) 88 nx_grade_card_compute(card_cl, prof_cl) 89 90 let card_el: *GradeCard = nx_grade_card_alloc() 91 nx_grade_card_init(card_el) 92 nx_grade_card_scan(card_el, m, prof_el) 93 nx_grade_card_compute(card_el, prof_el) 94 95 // Triangulate. 96 let tri: *GradeTriangulation = nx_grade_triangulation_alloc() 97 nx_grade_triangulate(tri, card_sq, card_cl, card_el) 98 99 // Emit per-grader summaries + the triangulated verdict. 100 print("=== SONARQUBE ===" as *u8) 101 println("" as *u8) 102 nx_grade_card_emit(card_sq) 103 print("=== CLIPPY ===" as *u8) 104 println("" as *u8) 105 nx_grade_card_emit(card_cl) 106 print("=== ELM ===" as *u8) 107 println("" as *u8) 108 nx_grade_card_emit(card_el) 109 print("=== TRIANGULATED ===" as *u8) 110 println("" as *u8) 111 nx_grade_triangulation_emit(tri) 112 113 return 0 114}