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 / native / prefetch / gate.om
| 1 | note SPDX-License-Identifier: AGPL-3.0-only |
| 2 | note Prefetch host qualification. Process helpers adapted from existing gate669 at1dffceae. |
| 3 | note No GPU. Exact exits plus exact verdict bytes; child deadlines30s; scratch exclusive. |
| 4 | text scratch "build/prefetch-native-gate" |
| 5 | text prefix "build/prefetch-native-gate/" |
| 6 | text names "unused\nnative/prefetch/classify.om\nnative/prefetch/review-fixtures.om\nnative/prefetch/review-nested.om\n/dev/null\n1\n0\nL\nJ\n2\n124\n137\n139\n-1\n01\n\nnative/prefetch/gate-child.om\n" |
| 7 | text input " < " |
| 8 | text output " > " |
| 9 | text errors " 2> " |
| 10 | text nl "\n" |
| 11 | text statusm "exit=" |
| 12 | text expect " expected=" |
| 13 | text signalm "INVALID child wait low-byte=" |
| 14 | text timeoutm "INVALID child deadline exceeded; sent SIGKILL; wait low-byte=" |
| 15 | text passed "AIEN-OBS prefetch_cases 53\nPREFETCH_NATIVE_GATE: PASS\n" |
| 16 | text failed "PREFETCH_NATIVE_GATE: FAIL; retain all scratch files and command output\n" |
| 17 | global pathbuf uchar 4096 |
| 18 | global plen ulong 1 |
| 19 | global serial ulong 1 |
| 20 | global argv uchar 4096 |
| 21 | global argc ulong 1 |
| 22 | global apos ulong 1 |
| 23 | global statbuf uchar 4 |
| 24 | global buf uchar 4096 |
| 25 | global other uchar 4096 |
| 26 | global digits uchar 32 |
| 27 | global cases ulong 1 |
| 28 | text caught "PREFETCH_CONTROL: CAUGHT\n" |
| 29 | text missed "PREFETCH_CONTROL: UNCAUGHT\n" |
| 30 | text invalid "PREFETCH_CONTROL: INVALID\n" |
| 31 | fn stop to void |
| 32 | r = write 2 failed 0 len failed |
| 33 | exit 99 |
| 34 | end |
| 35 | fn decimal v ulong to ulong |
| 36 | x = v |
| 37 | n = ulong 0 |
| 38 | while ge x 10 |
| 39 | put digits n uchar add 48 rem x 10 |
| 40 | x = div x 10 |
| 41 | n = add n 1 |
| 42 | end |
| 43 | put digits n uchar add 48 x |
| 44 | ret add n 1 |
| 45 | end |
| 46 | fn num v ulong to void |
| 47 | n = decimal v |
| 48 | for i ulong n |
| 49 | r = write 1 digits sub sub n i 1 1 |
| 50 | if ne r 1 |
| 51 | stop |
| 52 | end |
| 53 | end |
| 54 | end |
| 55 | fn setpath id ulong to void |
| 56 | if eq id 1 |
| 57 | n = argread 1 pathbuf 0 len pathbuf |
| 58 | if le n 0 |
| 59 | stop |
| 60 | end |
| 61 | put plen 0 ulong n |
| 62 | ret |
| 63 | end |
| 64 | if and ge id 100 lt id 356 |
| 65 | put pathbuf 0 uchar sub id 100 |
| 66 | put plen 0 1 |
| 67 | ret |
| 68 | end |
| 69 | if ge id 1000 |
| 70 | for i ulong len prefix |
| 71 | put pathbuf i get prefix i |
| 72 | end |
| 73 | n = decimal id |
| 74 | for i ulong n |
| 75 | put pathbuf add len prefix i get digits sub sub n i 1 |
| 76 | end |
| 77 | put plen 0 add len prefix n |
| 78 | ret |
| 79 | end |
| 80 | index = ulong 1 |
| 81 | p = ulong 0 |
| 82 | for i ulong len names |
| 83 | b = get names i |
| 84 | if eq b 10 |
| 85 | if eq index id |
| 86 | put plen 0 p |
| 87 | ret |
| 88 | end |
| 89 | index = add index 1 |
| 90 | else |
| 91 | if eq index id |
| 92 | put pathbuf p b |
| 93 | p = add p 1 |
| 94 | end |
| 95 | end |
| 96 | end |
| 97 | stop |
| 98 | end |
| 99 | fn showpath id ulong to void |
| 100 | setpath id |
| 101 | r = write 1 pathbuf 0 get plen 0 |
| 102 | if ne r long get plen 0 |
| 103 | stop |
| 104 | end |
| 105 | end |
| 106 | fn openfile id ulong flags int to int |
| 107 | setpath id |
| 108 | r = fopen pathbuf 0 get plen 0 flags 384 |
| 109 | if lt r 0 |
| 110 | stop |
| 111 | end |
| 112 | ret int r |
| 113 | end |
| 114 | fn fresh to ulong |
| 115 | n = add get serial 0 1 |
| 116 | if ge n 400000 |
| 117 | stop |
| 118 | end |
| 119 | put serial 0 n |
| 120 | ret add 1000 n |
| 121 | end |
| 122 | fn arg id ulong to void |
| 123 | setpath id |
| 124 | p = get apos 0 |
| 125 | n = get plen 0 |
| 126 | if gt add add p n 2 len argv |
| 127 | stop |
| 128 | end |
| 129 | put argv p uchar and n 255 |
| 130 | put argv add p 1 uchar shr n 8 |
| 131 | p = add p 2 |
| 132 | for i ulong n |
| 133 | put argv add p i get pathbuf i |
| 134 | end |
| 135 | put apos 0 add p n |
| 136 | put argc 0 add get argc 0 1 |
| 137 | end |
| 138 | fn command exe ulong to void |
| 139 | put argc 0 0 |
| 140 | put apos 0 2 |
| 141 | arg exe |
| 142 | showpath exe |
| 143 | end |
| 144 | fn argument id ulong to void |
| 145 | put digits 0 32 |
| 146 | r = write 1 digits 0 1 |
| 147 | showpath id |
| 148 | arg id |
| 149 | end |
| 150 | fn close fd int to void |
| 151 | if ne fclose fd 0 |
| 152 | stop |
| 153 | end |
| 154 | end |
| 155 | fn redirect source int dest int to void |
| 156 | if ne source dest |
| 157 | if ne dupfd source dest 0 long dest |
| 158 | stop |
| 159 | end |
| 160 | end |
| 161 | end |
| 162 | fn reap pid int to ulong |
| 163 | start = monons |
| 164 | if lt start 0 |
| 165 | stop |
| 166 | end |
| 167 | while true |
| 168 | r = waitpid pid statbuf 0 len statbuf 1 |
| 169 | if eq r long pid |
| 170 | if ne get statbuf 0 0 |
| 171 | r = write 1 signalm 0 len signalm |
| 172 | num ulong get statbuf 0 |
| 173 | r = write 1 nl 0 1 |
| 174 | stop |
| 175 | end |
| 176 | ret ulong get statbuf 1 |
| 177 | end |
| 178 | if lt r 0 |
| 179 | stop |
| 180 | end |
| 181 | now = monons |
| 182 | if or lt now start gt sub now start 30000000000 |
| 183 | r = killpid pid 9 |
| 184 | r = waitpid pid statbuf 0 len statbuf 0 |
| 185 | r = write 1 timeoutm 0 len timeoutm |
| 186 | num ulong get statbuf 0 |
| 187 | r = write 1 nl 0 1 |
| 188 | stop |
| 189 | end |
| 190 | if ne sleepns 1000000 0 |
| 191 | stop |
| 192 | end |
| 193 | end |
| 194 | exit 99 |
| 195 | end |
| 196 | fn run source ulong wanted ulong to ulong |
| 197 | outid = fresh |
| 198 | errid = add outid 500000 |
| 199 | r = write 1 input 0 len input |
| 200 | showpath source |
| 201 | r = write 1 output 0 len output |
| 202 | showpath outid |
| 203 | r = write 1 errors 0 len errors |
| 204 | showpath errid |
| 205 | r = write 1 nl 0 1 |
| 206 | rd = openfile source 524288 |
| 207 | wr = openfile outid 524481 |
| 208 | er = openfile errid 524481 |
| 209 | put argv 0 uchar get argc 0 |
| 210 | put argv 1 uchar shr get argc 0 8 |
| 211 | pid = fork |
| 212 | if lt pid 0 |
| 213 | stop |
| 214 | end |
| 215 | if eq pid 0 |
| 216 | redirect rd 0 |
| 217 | redirect wr 1 |
| 218 | redirect er 2 |
| 219 | r = execprog argv 0 get apos 0 |
| 220 | exit 98 |
| 221 | end |
| 222 | close rd |
| 223 | close wr |
| 224 | close er |
| 225 | actual = reap int pid |
| 226 | r = write 1 statusm 0 len statusm |
| 227 | num actual |
| 228 | r = write 1 expect 0 len expect |
| 229 | num wanted |
| 230 | r = write 1 nl 0 1 |
| 231 | if ne actual wanted |
| 232 | stop |
| 233 | end |
| 234 | ret outid |
| 235 | end |
| 236 | fn enable id ulong to void |
| 237 | fd = openfile id 524288 |
| 238 | r = read fd buf 0 4 |
| 239 | if ne r 4 |
| 240 | stop |
| 241 | end |
| 242 | if or ne get buf 0 127 ne get buf 1 69 |
| 243 | stop |
| 244 | end |
| 245 | if or ne get buf 2 76 ne get buf 3 70 |
| 246 | stop |
| 247 | end |
| 248 | if ne fchmod fd 448 0 |
| 249 | stop |
| 250 | end |
| 251 | close fd |
| 252 | end |
| 253 | fn empty id ulong to void |
| 254 | fd = openfile id 524288 |
| 255 | r = read fd buf 0 1 |
| 256 | close fd |
| 257 | if ne r 0 |
| 258 | stop |
| 259 | end |
| 260 | end |
| 261 | fn compile cc ulong src ulong wanted ulong to ulong |
| 262 | command cc |
| 263 | outid = run src wanted |
| 264 | if eq wanted 0 |
| 265 | enable outid |
| 266 | else |
| 267 | empty outid |
| 268 | end |
| 269 | ret outid |
| 270 | end |
| 271 | fn verdict id ulong want ulong to void |
| 272 | fd = openfile id 524288 |
| 273 | n = read fd buf 0 len buf |
| 274 | if lt n 0 |
| 275 | stop |
| 276 | end |
| 277 | extra = read fd other 0 1 |
| 278 | close fd |
| 279 | if ne extra 0 |
| 280 | stop |
| 281 | end |
| 282 | size = len invalid |
| 283 | if eq want 0 |
| 284 | size = len caught |
| 285 | end |
| 286 | if eq want 1 |
| 287 | size = len missed |
| 288 | end |
| 289 | if ne ulong n size |
| 290 | stop |
| 291 | end |
| 292 | for i ulong size |
| 293 | b = uchar 0 |
| 294 | if eq want 65 |
| 295 | b = get invalid i |
| 296 | end |
| 297 | if eq want 0 |
| 298 | b = get caught i |
| 299 | end |
| 300 | if eq want 1 |
| 301 | b = get missed i |
| 302 | end |
| 303 | if ne get buf i b |
| 304 | stop |
| 305 | end |
| 306 | end |
| 307 | put cases 0 add get cases 0 1 |
| 308 | end |
| 309 | fn make gen ulong mode ulong kind ulong to ulong |
| 310 | command gen |
| 311 | argument add mode 100 |
| 312 | argument kind |
| 313 | ret run 5 0 |
| 314 | end |
| 315 | fn check exe ulong code ulong log ulong json ulong want ulong to void |
| 316 | command exe |
| 317 | argument code |
| 318 | argument log |
| 319 | argument json |
| 320 | result = run 5 want |
| 321 | verdict result want |
| 322 | end |
| 323 | fn basics exe ulong gen ulong to void |
| 324 | for i ulong 21 |
| 325 | mode = add i 48 |
| 326 | if ge i 10 |
| 327 | mode = add sub i 10 65 |
| 328 | end |
| 329 | log = make gen mode 8 |
| 330 | json = make gen mode 9 |
| 331 | want = ulong 65 |
| 332 | code = ulong 6 |
| 333 | if lt i 3 |
| 334 | want = 0 |
| 335 | end |
| 336 | if eq i 3 |
| 337 | want = 1 |
| 338 | code = 7 |
| 339 | end |
| 340 | check exe code log json want |
| 341 | end |
| 342 | end |
| 343 | fn statuses exe ulong gen ulong to void |
| 344 | log = make gen 48 8 |
| 345 | json = make gen 48 9 |
| 346 | check exe 7 log json 65 |
| 347 | for i ulong 7 |
| 348 | code = add i 10 |
| 349 | check exe code log json 65 |
| 350 | end |
| 351 | log = make gen 51 8 |
| 352 | json = make gen 51 9 |
| 353 | check exe 6 log json 65 |
| 354 | end |
| 355 | fn slots exe ulong gen ulong to void |
| 356 | json = make gen 48 9 |
| 357 | otherj = make gen 49 9 |
| 358 | for i ulong 13 |
| 359 | log = make gen add i 76 8 |
| 360 | want = ulong 65 |
| 361 | if or eq i 4 eq i 5 |
| 362 | want = 0 |
| 363 | end |
| 364 | selected = json |
| 365 | if eq i 5 |
| 366 | selected = otherj |
| 367 | end |
| 368 | check exe 6 log selected want |
| 369 | end |
| 370 | end |
| 371 | fn nested exe ulong gen ulong mut ulong to void |
| 372 | log = make gen 48 8 |
| 373 | json = make gen 48 9 |
| 374 | for i ulong 10 |
| 375 | command mut |
| 376 | argument add i 148 |
| 377 | changed = run json 0 |
| 378 | check exe 6 log changed 65 |
| 379 | end |
| 380 | end |
| 381 | fn control to void |
| 382 | if ne argread 2 buf 0 1 1 |
| 383 | stop |
| 384 | end |
| 385 | m = get buf 0 |
| 386 | if or lt m 48 gt m 50 |
| 387 | stop |
| 388 | end |
| 389 | put buf 0 sub m 48 |
| 390 | id = fresh |
| 391 | fd = openfile id 524481 |
| 392 | if ne write fd buf 0 1 1 |
| 393 | stop |
| 394 | end |
| 395 | close fd |
| 396 | child = compile 1 17 0 |
| 397 | command child |
| 398 | result = run id 0 |
| 399 | stop |
| 400 | end |
| 401 | fn main to int |
| 402 | if or lt argcnt 2 gt argcnt 3 |
| 403 | ret 90 |
| 404 | end |
| 405 | if ne makedir scratch 0 len scratch 448 0 |
| 406 | ret 91 |
| 407 | end |
| 408 | if eq argcnt 3 |
| 409 | control |
| 410 | ret 99 |
| 411 | end |
| 412 | exe = compile 1 2 0 |
| 413 | gen = compile 1 3 0 |
| 414 | mut = compile 1 4 0 |
| 415 | basics exe gen |
| 416 | statuses exe gen |
| 417 | slots exe gen |
| 418 | nested exe gen mut |
| 419 | if ne get cases 0 53 |
| 420 | stop |
| 421 | end |
| 422 | r = write 1 passed 0 len passed |
| 423 | if ne r long len passed |
| 424 | ret 99 |
| 425 | end |
| 426 | ret 0 |
| 427 | end |