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 / evidence / ECOSYSTEM663 / final-unit.om
| 1 | note M20 metadata-v1. Integer metadata only; no allocator or numeric execution. |
| 2 | note ED: schema,dtype,rank,elements,offset,slot,generation,reserved,shape8,stride8. |
| 3 | note ES: live,retired,slot,generation,dtype,elements,reserved,reserved. |
| 4 | note ES is the caller-owned allocator snapshot. It is not untrusted wire input. |
| 5 | global ED ulong 24 |
| 6 | global ES ulong 8 |
| 7 | |
| 8 | fn emshape to int |
| 9 | rank = get ED 2 |
| 10 | if gt rank 8 |
| 11 | ret -2 |
| 12 | end |
| 13 | n = ulong 1 |
| 14 | for d ulong rank |
| 15 | size = get ED add 8 d |
| 16 | if eq size 0 |
| 17 | ret -3 |
| 18 | end |
| 19 | if gt size div 1073741824 n |
| 20 | ret -8 |
| 21 | end |
| 22 | n = mul n size |
| 23 | end |
| 24 | if ne get ED 3 n |
| 25 | ret -3 |
| 26 | end |
| 27 | ret 0 |
| 28 | end |
| 29 | |
| 30 | fn emlive slot ulong gen ulong to int |
| 31 | if gt slot 4294967295 |
| 32 | ret -5 |
| 33 | end |
| 34 | if or ne get ES 0 1 ne get ES 1 0 |
| 35 | ret -5 |
| 36 | end |
| 37 | if or eq gen 0 ne slot get ES 2 |
| 38 | ret -5 |
| 39 | end |
| 40 | if ne gen get ES 3 |
| 41 | ret -5 |
| 42 | end |
| 43 | ret 0 |
| 44 | end |
| 45 | |
| 46 | fn embounds to int |
| 47 | size = get ES 5 |
| 48 | offset = get ED 4 |
| 49 | if or eq size 0 gt size 1073741824 |
| 50 | ret -8 |
| 51 | end |
| 52 | if ge offset size |
| 53 | ret -6 |
| 54 | end |
| 55 | note Compare against remaining extent before multiplication, never overflow. |
| 56 | room = sub sub size 1 offset |
| 57 | for d ulong get ED 2 |
| 58 | count = sub get ED add 8 d 1 |
| 59 | stride = get ED add 16 d |
| 60 | if ne stride 0 |
| 61 | if gt count div room stride |
| 62 | ret -6 |
| 63 | end |
| 64 | room = sub room mul count stride |
| 65 | end |
| 66 | end |
| 67 | ret 0 |
| 68 | end |
| 69 | |
| 70 | fn emcheck to int |
| 71 | if or ne get ED 0 1 ne get ED 7 0 |
| 72 | ret -1 |
| 73 | end |
| 74 | if or ne get ES 6 0 ne get ES 7 0 |
| 75 | ret -1 |
| 76 | end |
| 77 | dtype = get ED 1 |
| 78 | if or lt dtype 1 gt dtype 3 |
| 79 | ret -4 |
| 80 | end |
| 81 | status = emshape |
| 82 | if ne status 0 |
| 83 | ret status |
| 84 | end |
| 85 | status = emlive get ED 5 get ED 6 |
| 86 | if ne status 0 |
| 87 | ret status |
| 88 | end |
| 89 | if ne dtype get ES 4 |
| 90 | ret -4 |
| 91 | end |
| 92 | ret embounds |
| 93 | end |
| 94 | |
| 95 | fn emrelease slot ulong gen ulong to int |
| 96 | status = emlive slot gen |
| 97 | if ne status 0 |
| 98 | ret status |
| 99 | end |
| 100 | note A maximal generation is retired, never wrapped into a valid old handle. |
| 101 | if eq gen 18446744073709551615 |
| 102 | put ES 1 1 |
| 103 | else |
| 104 | put ES 3 add gen 1 |
| 105 | end |
| 106 | put ES 0 0 |
| 107 | ret 0 |
| 108 | end |
| 109 | note Native checks plus independent element-by-element view bounds oracle. |
| 110 | global EC ulong 1 |
| 111 | global Digits uchar 20 |
| 112 | text Pass "M20_METADATA_V1_PASS checks=" |
| 113 | text Fail "M20_METADATA_V1_FAIL check=" |
| 114 | text NL "\n" |
| 115 | |
| 116 | fn number n ulong to void |
| 117 | if eq n 0 |
| 118 | put Digits 0 48 |
| 119 | w = write 1 Digits 0 1 |
| 120 | if ne w 1 |
| 121 | exit 90 |
| 122 | end |
| 123 | ret |
| 124 | end |
| 125 | pos = ulong 20 |
| 126 | while gt n 0 bound 20 |
| 127 | pos = sub pos 1 |
| 128 | put Digits pos uchar add 48 rem n 10 |
| 129 | n = div n 10 |
| 130 | end |
| 131 | w = write 1 Digits pos sub 20 pos |
| 132 | if ne w long sub 20 pos |
| 133 | exit 90 |
| 134 | end |
| 135 | end |
| 136 | |
| 137 | fn check got int want int to void |
| 138 | put EC 0 add get EC 0 1 |
| 139 | if ne got want |
| 140 | w = write 1 Fail 0 len Fail |
| 141 | number get EC 0 |
| 142 | w = write 1 NL 0 1 |
| 143 | if ne w 1 |
| 144 | exit 90 |
| 145 | end |
| 146 | exit 1 |
| 147 | end |
| 148 | end |
| 149 | |
| 150 | fn fixture to void |
| 151 | for i ulong 24 |
| 152 | put ED i 0 |
| 153 | end |
| 154 | for i ulong 8 |
| 155 | put ES i 0 |
| 156 | end |
| 157 | put ED 0 1 |
| 158 | put ED 1 1 |
| 159 | put ED 2 2 |
| 160 | put ED 3 6 |
| 161 | put ED 5 4 |
| 162 | put ED 6 17 |
| 163 | put ED 8 2 |
| 164 | put ED 9 3 |
| 165 | put ED 16 3 |
| 166 | put ED 17 1 |
| 167 | put ES 0 1 |
| 168 | put ES 2 4 |
| 169 | put ES 3 17 |
| 170 | put ES 4 1 |
| 171 | put ES 5 6 |
| 172 | end |
| 173 | |
| 174 | fn direct to void |
| 175 | fixture |
| 176 | check emcheck 0 |
| 177 | put ED 0 2 |
| 178 | check emcheck -1 |
| 179 | fixture |
| 180 | put ED 7 1 |
| 181 | check emcheck -1 |
| 182 | fixture |
| 183 | put ES 6 1 |
| 184 | check emcheck -1 |
| 185 | fixture |
| 186 | put ES 7 1 |
| 187 | check emcheck -1 |
| 188 | fixture |
| 189 | put ED 1 0 |
| 190 | check emcheck -4 |
| 191 | put ED 1 4 |
| 192 | check emcheck -4 |
| 193 | fixture |
| 194 | put ES 4 2 |
| 195 | check emcheck -4 |
| 196 | put ED 1 2 |
| 197 | check emcheck 0 |
| 198 | put ED 1 3 |
| 199 | put ES 4 3 |
| 200 | check emcheck 0 |
| 201 | fixture |
| 202 | put ED 2 9 |
| 203 | check emcheck -2 |
| 204 | fixture |
| 205 | put ED 8 0 |
| 206 | check emcheck -3 |
| 207 | fixture |
| 208 | put ED 3 7 |
| 209 | check emcheck -3 |
| 210 | fixture |
| 211 | put ED 8 1073741824 |
| 212 | check emcheck -8 |
| 213 | fixture |
| 214 | put ED 8 18446744073709551615 |
| 215 | check emcheck -8 |
| 216 | fixture |
| 217 | put ES 5 0 |
| 218 | check emcheck -8 |
| 219 | put ES 5 1073741825 |
| 220 | check emcheck -8 |
| 221 | fixture |
| 222 | put ED 4 6 |
| 223 | check emcheck -6 |
| 224 | fixture |
| 225 | put ED 4 18446744073709551615 |
| 226 | check emcheck -6 |
| 227 | fixture |
| 228 | put ED 16 18446744073709551615 |
| 229 | check emcheck -6 |
| 230 | fixture |
| 231 | put ED 8 1 |
| 232 | put ED 3 3 |
| 233 | put ED 16 18446744073709551615 |
| 234 | check emcheck 0 |
| 235 | fixture |
| 236 | put ED 16 0 |
| 237 | check emcheck 0 |
| 238 | fixture |
| 239 | put ED 16 1 |
| 240 | put ED 17 2 |
| 241 | check emcheck 0 |
| 242 | put ES 5 5 |
| 243 | check emcheck -6 |
| 244 | fixture |
| 245 | put ED 2 0 |
| 246 | put ED 3 1 |
| 247 | put ED 4 5 |
| 248 | check emcheck 0 |
| 249 | put ED 4 6 |
| 250 | check emcheck -6 |
| 251 | fixture |
| 252 | put ED 2 8 |
| 253 | put ED 3 1 |
| 254 | for i ulong 8 |
| 255 | put ED add 8 i 1 |
| 256 | put ED add 16 i 18446744073709551615 |
| 257 | end |
| 258 | check emcheck 0 |
| 259 | fixture |
| 260 | put ED 2 1 |
| 261 | put ED 8 1073741824 |
| 262 | put ED 3 1073741824 |
| 263 | put ED 16 0 |
| 264 | put ES 5 1 |
| 265 | check emcheck 0 |
| 266 | put ED 16 1 |
| 267 | put ES 5 1073741824 |
| 268 | check emcheck 0 |
| 269 | put ED 4 1 |
| 270 | check emcheck -6 |
| 271 | end |
| 272 | |
| 273 | fn lifetime to void |
| 274 | fixture |
| 275 | check emlive 4 17 0 |
| 276 | put ED 5 0 |
| 277 | put ES 2 0 |
| 278 | check emcheck 0 |
| 279 | put ED 5 4294967295 |
| 280 | put ES 2 4294967295 |
| 281 | check emcheck 0 |
| 282 | put ED 5 4294967296 |
| 283 | put ES 2 4294967296 |
| 284 | check emcheck -5 |
| 285 | fixture |
| 286 | check emlive 5 17 -5 |
| 287 | check emlive 4 0 -5 |
| 288 | check emlive 4 16 -5 |
| 289 | check emrelease 4 16 -5 |
| 290 | check emlive 4 17 0 |
| 291 | check emrelease 4 17 0 |
| 292 | check int get ES 0 0 |
| 293 | check int get ES 3 18 |
| 294 | check emcheck -5 |
| 295 | check emrelease 4 17 -5 |
| 296 | put ES 0 1 |
| 297 | check emcheck -5 |
| 298 | put ED 6 18 |
| 299 | check emcheck 0 |
| 300 | check emlive 4 17 -5 |
| 301 | fixture |
| 302 | put ES 1 1 |
| 303 | check emcheck -5 |
| 304 | fixture |
| 305 | put ES 0 2 |
| 306 | check emcheck -5 |
| 307 | fixture |
| 308 | put ES 1 2 |
| 309 | check emcheck -5 |
| 310 | fixture |
| 311 | put ES 3 18446744073709551615 |
| 312 | put ED 6 18446744073709551615 |
| 313 | check emcheck 0 |
| 314 | check emrelease 4 18446744073709551615 0 |
| 315 | check int get ES 0 0 |
| 316 | check int get ES 1 1 |
| 317 | check emlive 4 18446744073709551615 -5 |
| 318 | put ES 0 1 |
| 319 | check emcheck -5 |
| 320 | if ne get ES 3 18446744073709551615 |
| 321 | check 1 0 |
| 322 | end |
| 323 | fixture |
| 324 | check emcheck 0 |
| 325 | end |
| 326 | |
| 327 | note Independent oracle visits every element; it never uses maximal extent. |
| 328 | fn oracle a ulong b ulong s ulong t ulong off ulong cap ulong to int |
| 329 | for i ulong a |
| 330 | for j ulong b |
| 331 | index = add off add mul i s mul j t |
| 332 | if ge index cap |
| 333 | ret -6 |
| 334 | end |
| 335 | end |
| 336 | end |
| 337 | ret 0 |
| 338 | end |
| 339 | |
| 340 | fn enumerate to void |
| 341 | fixture |
| 342 | for ai ulong 3 |
| 343 | a = add ai 1 |
| 344 | put ED 8 a |
| 345 | for bi ulong 3 |
| 346 | b = add bi 1 |
| 347 | put ED 9 b |
| 348 | put ED 3 mul a b |
| 349 | for s ulong 5 |
| 350 | put ED 16 s |
| 351 | for t ulong 5 |
| 352 | put ED 17 t |
| 353 | for off ulong 4 |
| 354 | put ED 4 off |
| 355 | for ci ulong 16 |
| 356 | cap = add ci 1 |
| 357 | put ES 5 cap |
| 358 | want = oracle a b s t off cap |
| 359 | check emcheck want |
| 360 | end |
| 361 | end |
| 362 | end |
| 363 | end |
| 364 | end |
| 365 | end |
| 366 | end |
| 367 | |
| 368 | fn main to int |
| 369 | direct |
| 370 | lifetime |
| 371 | enumerate |
| 372 | w = write 1 Pass 0 len Pass |
| 373 | number get EC 0 |
| 374 | w = write 1 NL 0 1 |
| 375 | if ne w 1 |
| 376 | ret 90 |
| 377 | end |
| 378 | ret 0 |
| 379 | end |