code wiki / _hdl_build / nx_capability_shape.nx

nx_capability_shape.nx source

↩ module page · 44 lines · 2862 B

1// nx_capability_shape.nx -- grade an organ on the "PERFECT OBJECT" axes (operator: "climb logically into perfect 2// objects that arent too big or small but like linux tools exist perfectly in their spaces"). The existing 3// lineage system grades biological seed-to-feed + sovereignty-evolution; NEITHER grades capability SIZING. This 4// does: per organ, measure FUNCTION COUNT (proxy for single-responsibility / right-size) + REUSE (how many .nx 5// import it = a shared building block) and grade TOO_SMALL (trivial -> merge/inline #15/#22) / PERFECT (one 6// cohesive capability, ~3-30 funcs) / TOO_BIG (likely >1 responsibility -> split #9). Tunable heuristic, not a 7// law -- a Linux tool `true` is tiny + `grep` is bigger; the grade is a PROMPT to review, not an auto-edit. 8// Composes the sovereign grep (oc_grep) for reuse. READ-ONLY (never-brick). license_tier: ORIGINAL 9import "nx_organ_callers.nx" // oc_grep, oc_read 10import "nx_syscalls.nx" 11 12const CS_TOO_SMALL: i64 = 0 13const CS_PERFECT: i64 = 1 14const CS_TOO_BIG: i64 = 2 15const CS_MIN_FUNCS: i64 = 3 // < this = trivial = merge/inline candidate 16const CS_MAX_FUNCS: i64 = 30 // > this = likely multiple responsibilities = split candidate 17 18func cs_isident(c: i64) -> i64 { if c>=97 { if c<=122 { return 1 } } if c>=65 { if c<=90 { return 1 } } if c>=48 { if c<=57 { return 1 } } if c==95 { return 1 } return 0 } 19// count `func ` definitions (word-boundaried on the left) in buf[0..n) = the organ's responsibility surface. 20func cs_funccount(buf: *u8, n: i64) -> i64 { 21 var c: i64=0; var i: i64=0 22 while i+5 <= n { 23 var hit: i64=0 24 if buf[i]==(102 as u8) { if buf[i+1]==(117 as u8) { if buf[i+2]==(110 as u8) { if buf[i+3]==(99 as u8) { if buf[i+4]==(32 as u8) { hit=1 } } } } } 25 if hit==1 { var ok: i64=1; if i>0 { if cs_isident(buf[i-1] as i64)==1 { ok=0 } } if ok==1 { c=c+1 } } 26 i=i+1 27 } 28 return c 29} 30// read an organ + count its functions (-1 if unreadable). munmap'd (no leak). 31func cs_funcs(path: *u8) -> i64 { 32 let buf: *u8=sys_mmap(4194304); let n: i64=oc_read(path, buf, 4194304) 33 if n<=0 { sys_munmap(buf, 4194304); return 0-1 } 34 let c: i64=cs_funccount(buf, n) 35 sys_munmap(buf, 4194304) 36 return c 37} 38// the PERFECT-OBJECT sizing grade by function count. 39func cs_grade(funcs: i64) -> i64 { if funcs < CS_MIN_FUNCS { return CS_TOO_SMALL } if funcs > CS_MAX_FUNCS { return CS_TOO_BIG } return CS_PERFECT } 40func cs_grade_name(g: i64) -> *u8 { if g==0 { return "TOO_SMALL(merge/inline)" as *u8 } if g==2 { return "TOO_BIG(split)" as *u8 } return "PERFECT" as *u8 } 41// REUSE: how many .nx files import `organ` (pass needle = `import "nx_organ.nx`). High = a reusable building block. 42func cs_reuse(import_needle: *u8, hits: *u8, hitoff: *i64) -> i64 { 43 return oc_grep("runtime\x00" as *u8, import_needle, 262144, hits, hitoff, 4096) 44}