Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/tools/gen/abstract/genabs.sh # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / tools / gen / abstract / genabs.sh` 214 lines ยท 12175 bytes Raw Blame History 1 # tools/gen/abstract/genabs.sh -- shell library of the GEN-3 extractor and verifier (aien-spark/omega#478). 2 # Sourced by tools/gen/abstract/extract and tools/gen/abstract/verify, so both run the same checks and write the 3 # same receipt bytes. Bash (as tools/exp445 uses), no Python. Deterministic: no clock, no randomness, C locale. 4 # 5 # ga_init binaries come from the build dir; corpus files from the root 6 # Every check calls the repo's own tools: omegese, omega_emit, x445, checker2, ola_runner (through gabs run). 7 export LC_ALL=C 8 GA_CORPUS=tests/one_layer/generalization/corpus 9 GA_HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 10 GA_PROPERTY_N=256 11 12 ga_init() { 13 GA_B="$1" GA_ROOT="$2" GA_W="$3" GA_ERR="" 14 GA_OMEGESE="$GA_B/omegese/omegese" GA_EMIT="$GA_B/omega_emit/omega_emit" GA_X445="$GA_B/omega_emit/x445" 15 GA_CHK="$GA_B/checker2/checker2" GA_RUNNER="$GA_B/one_layer/ola_runner" GA_GABS="$GA_B/gen_abstract/gabs" 16 GA_ORACLE="$GA_B/gen_abstract/oracle" GA_FAMSIG="${GEN_FAMSIG:-$GA_B/gen_abstract/famsig}" 17 local t 18 for t in "$GA_OMEGESE" "$GA_EMIT" "$GA_X445" "$GA_CHK" "$GA_RUNNER" "$GA_GABS" "$GA_ORACLE" "$GA_FAMSIG"; do 19 [ -x "$t" ] || { echo "genabs: missing tool $t (make omegese omega_emit checker2 ola gen-abstract)" >&2; return 2; } 20 done 21 mkdir -p "$GA_W/scratch" 22 } 23 ga_sha() { sha256sum "$1" | cut -c1-64; } 24 ga_shas() { printf '%s' "$1" | sha256sum | cut -c1-64; } 25 26 # Tool digests a receipt carries: the sources of the extractor, the verifier, the probe runner and the record 27 # validator (a change to any of them changes every receipt). 28 ga_tool_lines() { 29 local f 30 for f in extract verify probe genabs.sh gabs.c recheck.c; do printf 'tool tools/gen/abstract/%s %s\n' "$f" "$(ga_sha "$GA_HERE/$f")"; done 31 } 32 33 # ga_chain -- reader chain: omegese emit, omega_emit emit, checker2 check. 34 # Writes .json and .ir. On failure returns 1 with GA_ERR set. 35 ga_chain() { 36 local out 37 if ! out="$("$GA_OMEGESE" emit "$1" "$2.json" 2>&1)"; then GA_ERR="omegese emit refused: $(printf '%s' "$out" | head -n 1)"; return 1; fi 38 if ! out="$("$GA_EMIT" emit "$2.json" "$2.ir" 2>&1)"; then GA_ERR="omega_emit refused: $(printf '%s' "$out" | head -n 1)"; return 1; fi 39 if ! out="$("$GA_CHK" check "$2.ir" 2>&1)"; then GA_ERR="checker2 refused: $(printf '%s' "$out" | head -n 1)"; return 1; fi 40 case "$out" in checker2=ACCEPT*) ;; *) GA_ERR="checker2: $out"; return 1;; esac 41 return 0 42 } 43 44 # ga_fp -- canonical IR fingerprint (RECORD_SCHEMA.md section 6) on stdout. 45 ga_fp() { 46 "$GA_OMEGESE" emit "$1" "$2.fj" > /dev/null 2>&1 || { GA_ERR="omegese emit refused"; return 1; } 47 "$GA_GABS" canon "$2.fj" "$2.cj" > /dev/null 2>&1 || { GA_ERR="gabs canon failed"; return 1; } 48 "$GA_EMIT" emit "$2.cj" "$2.cir" > /dev/null 2>&1 || { GA_ERR="omega_emit refused the canonical program"; return 1; } 49 ga_sha "$2.cir" 50 } 51 52 # Omegese scalar type -> requirement spelling 53 ga_req() { 54 case "$1" in bool) echo bool;; uchar) echo u8;; ushort) echo u16;; uint) echo u32;; ulong) echo u64;; 55 byte) echo i8;; short) echo i16;; int) echo i32;; long) echo i64;; *) return 1;; esac 56 } 57 58 # ga_params -- sets GA_NAME, GA_PN[] (names), GA_PT[] (types; an array is "view uint 4"), GA_RET 59 # (Omegese), GA_REQP (params line value, requirement spelling), GA_FLATN (flattened scalar names), 60 # GA_FLATT (their requirement types), GA_FLATP (" name type" pairs for a wrapper fn line). 61 ga_params() { 62 local w=($1) i=2 t 63 GA_NAME="${w[1]}" GA_PN=() GA_PT=() GA_REQP="" GA_FLATN="" GA_FLATT="" GA_FLATP="" 64 while [ "$i" -lt "${#w[@]}" ] && [ "${w[$i]}" != to ]; do 65 GA_PN+=("${w[$i]}") 66 case "${w[$((i + 1))]}" in 67 view|edit|own) 68 GA_PT+=("${w[$((i + 1))]} ${w[$((i + 2))]} ${w[$((i + 3))]}") 69 t="$(ga_req "${w[$((i + 2))]}")" || return 1 70 GA_REQP+=" ${w[$((i + 1))]} $t ${w[$((i + 3))]}" 71 local j 72 for ((j = 0; j < ${w[$((i + 3))]}; j++)); do 73 GA_FLATN+=" ${w[$i]}_$j" GA_FLATT+=" $t" GA_FLATP+=" ${w[$i]}_$j ${w[$((i + 2))]}" 74 done 75 i=$((i + 4)) ;; 76 *) 77 GA_PT+=("${w[$((i + 1))]}") 78 t="$(ga_req "${w[$((i + 1))]}")" || return 1 79 GA_REQP+=" $t" GA_FLATN+=" ${w[$i]}" GA_FLATT+=" $t" GA_FLATP+=" ${w[$i]} ${w[$((i + 1))]}" 80 i=$((i + 2)) ;; 81 esac 82 done 83 GA_RET="${w[$((i + 1))]}" 84 } 85 86 # ga_wrappers
   -- the helper, then gw_call (the helper on flattened

87 # scalar arguments), gw_pre, gw_post (post with res = the helper's result) and gw_chk (true when pre is false,

88 # else post). Arrays are packed from their scalars and freed before each return.

89 ga_wrappers() {

90 ga_params "$(head -n 1 "$1")" || { GA_ERR="unknown type in the signature"; return 1; }

91 local pack="" free="" args="" i

92 for i in "${!GA_PN[@]}"; do

93 local tw=(${GA_PT[$i]}) n="${GA_PN[$i]}"

94 if [ "${#tw[@]}" = 3 ]; then

95 [ "${tw[0]}" != own ] || { GA_ERR="own array parameter (v1 checks view and edit only)"; return 1; }

96 pack+="$n = new ${tw[1]} ${tw[2]} 0"$'\n'

97 local j

98 for ((j = 0; j < tw[2]; j++)); do pack+="put $n $j ${n}_$j"$'\n'; done

99 free+="free $n"$'\n'

100 fi

101 args+=" $n"

102 done

103 {

104 cat "$1"

105 printf 'fn gw_call%s to %s\n%sgw_r = %s%s\n%sret gw_r\nend\n' "$GA_FLATP" "$GA_RET" "$pack" "$GA_NAME" "$args" "$free"

106 printf 'fn gw_pre%s to bool\n%sgw_r = bool false\nif %s\ngw_r = true\nend\n%sret gw_r\nend\n' "$GA_FLATP" "$pack" "$2" "$free"

107 printf 'fn gw_post%s to bool\n%sres = %s%s\ngw_r = bool false\nif %s\ngw_r = true\nend\n%sret gw_r\nend\n' "$GA_FLATP" "$pack" "$GA_NAME" "$args" "$3" "$free"

108 printf 'fn gw_chk%s to bool\nif gw_pre%s\nret gw_post%s\nend\nret true\nend\n' "$GA_FLATP" "$GA_FLATN" "$GA_FLATN"

109 } > "$4"

110 }

111

112 # ga_run