code wiki / _hdl_build / nx_self_model_lint.nx

nx_self_model_lint.nx source

↩ module page · 48 lines · 2423 B

1// nx_self_model_lint.nx -- the LIBRARIAN's validator for the self-model registry, so a bug like a cap 2// assigned to a non-existent layer (lay >= ECO_NLAYERS -> silently uncounted + unprinted) is CAUGHT by the 3// team, not discovered by hand (operator: "things like this should be addressed by the nishi team... the 4// librarian is gathering all this information... with you checking to see if their functionality s class 5// exceeds yours and if not building towards that"). This capability EXCEEDS manual editing: hand-registration 6// just produced a 9-cap silent miscount; this lint makes that class of bug impossible to ship. license_tier: ORIGINAL 7 8import "nx_syscalls.nx" 9 10const SML_OK: i64 = 0 11const SML_BAD_LAYER: i64 = 1 // lay[i] outside [0, nlayers) -> the INVISIBLE-cap bug (uncounted/unprinted) 12const SML_BAD_STATUS: i64 = 2 // st[i] not in {PLANNED=0, INFLIGHT=1, PROVEN=2} 13const SML_DUP_INDEX: i64 = 3 // two caps share an index 14 15// a capability is VISIBLE/countable iff its layer is a real layer the display loop iterates. 16func sml_layer_valid(layer: i64, nlayers: i64) -> i64 { if layer < 0 { return 0 } if layer >= nlayers { return 0 } return 1 } 17func sml_status_valid(status: i64) -> i64 { if status < 0 { return 0 } if status > 2 { return 0 } return 1 } 18 19// validate one cap entry -> an SML_* code. 20func sml_check_cap(layer: i64, status: i64, nlayers: i64) -> i64 { 21 if sml_layer_valid(layer, nlayers) == 0 { return SML_BAD_LAYER } 22 if sml_status_valid(status) == 0 { return SML_BAD_STATUS } 23 return SML_OK 24} 25 26// the SILENT-UNDERCOUNT detector: how many caps would be invisible (layer out of range) over the whole array. 27func sml_count_invisible(lays: *i64, n: i64, nlayers: i64) -> i64 { 28 var c: i64 = 0; var i: i64 = 0 29 while i < n { if sml_layer_valid(lays[i], nlayers) == 0 { c = c + 1 } i = i + 1 } 30 return c 31} 32 33// the registry is CLEAN iff zero caps are invisible AND every status is valid. 34func sml_registry_clean(lays: *i64, sts: *i64, n: i64, nlayers: i64) -> i64 { 35 var i: i64 = 0 36 while i < n { 37 if sml_check_cap(lays[i], sts[i], nlayers) != SML_OK { return 0 } 38 i = i + 1 39 } 40 return 1 41} 42 43func sml_code_label(c: i64) -> *u8 { 44 if c == SML_BAD_LAYER { return "BAD-LAYER(invisible)" as *u8 } 45 if c == SML_BAD_STATUS { return "BAD-STATUS" as *u8 } 46 if c == SML_DUP_INDEX { return "DUP-INDEX" as *u8 } 47 return "OK" as *u8 48}