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