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
omega-mv / src / searchtrace / st_core.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note Pure seeded OM-2 core logic backing src/searchtrace/ (st_holdout.c, |
| 3 | note st_corpus.c): lowercase hex encode/decode, constant-time byte compare, |
| 4 | note label/name validation, task-prefix line counter, big-endian commitment |
| 5 | note header encoder, canonical u64/i64 decimal parsers, and record byte checks. |
| 6 | om2 |
| 7 | |
| 8 | fn st_hex_nibble v ulong to uchar |
| 9 | if lt v 10 |
| 10 | ret uchar add 48 v |
| 11 | end |
| 12 | ret uchar add 87 v |
| 13 | end |
| 14 | |
| 15 | export fn st_om_hex_lower src view uchar * n ulong dst edit uchar * to void |
| 16 | for i ulong n bound 9223372036854775807 |
| 17 | b = ulong get src i |
| 18 | put dst mul i 2 st_hex_nibble shr b 4 |
| 19 | put dst add mul i 2 1 st_hex_nibble and b 15 |
| 20 | end |
| 21 | end |
| 22 | |
| 23 | export fn st_om_ct_equal a view uchar * b view uchar * n ulong to ulong |
| 24 | acc = ulong 0 |
| 25 | for i ulong n bound 9223372036854775807 |
| 26 | acc = or acc xor ulong get a i ulong get b i |
| 27 | end |
| 28 | if eq acc 0 |
| 29 | ret 1 |
| 30 | end |
| 31 | ret 0 |
| 32 | end |
| 33 | |
| 34 | export fn st_om_label_ok s view uchar * n ulong lim ulong to ulong |
| 35 | if or lt n 1 gt n lim |
| 36 | ret 0 |
| 37 | end |
| 38 | for i ulong n bound 9223372036854775807 |
| 39 | c = ulong get s i |
| 40 | ok = ulong 0 |
| 41 | if and ge c 97 le c 122 |
| 42 | ok = 1 |
| 43 | end |
| 44 | if and ge c 65 le c 90 |
| 45 | ok = 1 |
| 46 | end |
| 47 | if and ge c 48 le c 57 |
| 48 | ok = 1 |
| 49 | end |
| 50 | if or eq c 46 or eq c 95 eq c 45 |
| 51 | ok = 1 |
| 52 | end |
| 53 | if eq ok 0 |
| 54 | ret 0 |
| 55 | end |
| 56 | end |
| 57 | ret 1 |
| 58 | end |
| 59 | |
| 60 | fn st_is_task_prefix t view uchar * slen ulong pos ulong to ulong |
| 61 | if lt sub slen pos 5 |
| 62 | ret 0 |
| 63 | end |
| 64 | if ne ulong get t pos 116 |
| 65 | ret 0 |
| 66 | end |
| 67 | if ne ulong get t add pos 1 97 |
| 68 | ret 0 |
| 69 | end |
| 70 | if ne ulong get t add pos 2 115 |
| 71 | ret 0 |
| 72 | end |
| 73 | if ne ulong get t add pos 3 107 |
| 74 | ret 0 |
| 75 | end |
| 76 | if ne ulong get t add pos 4 32 |
| 77 | ret 0 |
| 78 | end |
| 79 | ret 1 |
| 80 | end |
| 81 | |
| 82 | export fn st_om_count_tasks t view uchar * slen ulong to ulong |
| 83 | n = ulong 0 |
| 84 | i = ulong 0 |
| 85 | while lt i slen bound 9223372036854775807 |
| 86 | if eq st_is_task_prefix t slen i 1 |
| 87 | if lt n 4294967295 |
| 88 | n = add n 1 |
| 89 | end |
| 90 | end |
| 91 | while lt i slen bound 9223372036854775807 |
| 92 | c = ulong get t i |
| 93 | i = add i 1 |
| 94 | if eq c 10 |
| 95 | break |
| 96 | end |
| 97 | end |
| 98 | end |
| 99 | ret n |
| 100 | end |
| 101 | |
| 102 | export fn st_om_put_be64_be32 dst edit uchar 12 l ulong count ulong to void |
| 103 | for i ulong 8 |
| 104 | put dst i uchar and shr l sub 56 mul i 8 255 |
| 105 | end |
| 106 | for i ulong 4 |
| 107 | put dst add 8 i uchar and shr count sub 24 mul i 8 255 |
| 108 | end |
| 109 | end |
| 110 | |
| 111 | export fn st_om_parse_hex32 v view uchar * n ulong dst edit uchar 32 to long |
| 112 | if ne n 64 |
| 113 | ret 1 |
| 114 | end |
| 115 | for i ulong 64 |
| 116 | ch = ulong get v i |
| 117 | x = ulong 99 |
| 118 | if and ge ch 48 le ch 57 |
| 119 | x = sub ch 48 |
| 120 | else |
| 121 | if and ge ch 97 le ch 102 |
| 122 | x = add sub ch 97 10 |
| 123 | else |
| 124 | if and ge ch 65 le ch 70 |
| 125 | ret 2 |
| 126 | end |
| 127 | ret 3 |
| 128 | end |
| 129 | end |
| 130 | idx = div i 2 |
| 131 | if eq and i 1 1 |
| 132 | prev = ulong get dst idx |
| 133 | put dst idx uchar or prev x |
| 134 | else |
| 135 | put dst idx uchar shl x 4 |
| 136 | end |
| 137 | end |
| 138 | ret 0 |
| 139 | end |
| 140 | |
| 141 | export fn st_om_parse_dec v view uchar * n ulong max_v ulong dst edit ulong 1 to long |
| 142 | if or eq n 0 gt n 20 |
| 143 | ret 1 |
| 144 | end |
| 145 | if and gt n 1 eq ulong get v 0 48 |
| 146 | ret 1 |
| 147 | end |
| 148 | x = ulong 0 |
| 149 | for i ulong n bound 9223372036854775807 |
| 150 | c = ulong get v i |
| 151 | if or lt c 48 gt c 57 |
| 152 | ret 2 |
| 153 | end |
| 154 | d = sub c 48 |
| 155 | if gt x div sub max_v d 10 |
| 156 | ret 3 |
| 157 | end |
| 158 | x = add mul x 10 d |
| 159 | end |
| 160 | put dst 0 x |
| 161 | ret 0 |
| 162 | end |
| 163 | |
| 164 | export fn st_om_parse_i64 s view uchar * n ulong dst edit ulong 1 to ulong |
| 165 | if eq n 0 |
| 166 | ret 0 |
| 167 | end |
| 168 | is_neg = ulong 0 |
| 169 | off = ulong 0 |
| 170 | if eq ulong get s 0 45 |
| 171 | is_neg = 1 |
| 172 | off = 1 |
| 173 | end |
| 174 | rem_n = sub n off |
| 175 | if or eq rem_n 0 gt rem_n 20 |
| 176 | ret 0 |
| 177 | end |
| 178 | if and gt rem_n 1 eq ulong get s off 48 |
| 179 | ret 0 |
| 180 | end |
| 181 | v = ulong 0 |
| 182 | for i ulong rem_n |
| 183 | c = ulong get s add off i |
| 184 | if or lt c 48 gt c 57 |
| 185 | ret 0 |
| 186 | end |
| 187 | d = sub c 48 |
| 188 | if gt v div sub 2147483648 d 10 |
| 189 | ret 0 |
| 190 | end |
| 191 | v = add mul v 10 d |
| 192 | end |
| 193 | if gt v 2147483648 |
| 194 | ret 0 |
| 195 | end |
| 196 | if and eq is_neg 1 eq v 0 |
| 197 | ret 0 |
| 198 | end |
| 199 | if eq is_neg 1 |
| 200 | put dst 0 sub 0 v |
| 201 | else |
| 202 | put dst 0 v |
| 203 | end |
| 204 | ret 1 |
| 205 | end |
| 206 | |
| 207 | export fn st_om_check_rec_bytes rec view uchar * slen ulong to long |
| 208 | if gt slen 1024 |
| 209 | ret 1 |
| 210 | end |
| 211 | for i ulong slen |
| 212 | c = ulong get rec i |
| 213 | if eq c 0 |
| 214 | ret 2 |
| 215 | end |
| 216 | end |
| 217 | for i ulong slen |
| 218 | c = ulong get rec i |
| 219 | if eq c 13 |
| 220 | ret 3 |
| 221 | end |
| 222 | end |
| 223 | ret 0 |
| 224 | end |