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/seed/omc/gate-ir.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 / seed / omc / gate-ir.sh` 654 lines ยท 21843 bytes Raw Blame History 1 #!/bin/sh 2 # Experimental scalar IR checkpoint; not the completed R6 gate. 3 # Requires C-built omegese/omega_emit/checker2 as comparison oracles only. 4 set -eu 5 cd "$(dirname "$0")/../.." 6 B=build/seed/ir 7 mkdir -p "$B" 8 fail() { printf 'FAIL %s\n' "$*"; exit 1; } 9 seed/rung4/om4.bin < seed/omc/omc.om > "$B/stage1" 10 chmod +x "$B/stage1" 11 "$B/stage1" < seed/omc/omc.om > "$B/stage2" 12 chmod +x "$B/stage2" 13 "$B/stage2" < seed/omc/omc.om > "$B/stage3" 14 cmp "$B/stage1" "$B/stage2" 15 cmp "$B/stage2" "$B/stage3" 16 echo "PASS fixpoint $(sha256sum "$B/stage3")" 17 n=0 18 for f in tests/one_layer/omegese/dev/*.omegese; do 19 id=$(basename "$f" .omegese) 20 build/omegese/omegese emit "$f" "$B/$id.json" 21 build/omega_emit/omega_emit emit "$B/$id.json" "$B/$id.oracle" 22 { printf 'ir\n'; cat "$f"; } > "$B/$id.input" 23 timeout 5 "$B/stage2" < "$B/$id.input" > "$B/$id.got" 24 cmp "$B/$id.oracle" "$B/$id.got" || fail "$id byte mismatch" 25 build/checker2/checker2 check "$B/$id.got" > "$B/$id.check" 26 grep -q '^checker2=ACCEPT ' "$B/$id.check" || fail "$id checker refusal" 27 echo "PASS $id identical; checker2 ACCEPT" 28 n=$((n+1)) 29 done 30 [ "$n" = 10 ] || fail "ran $n expected 10" 31 # Exercise the result comparison: change the arithmetic operation while preserving a valid program. 32 sed 's/ret mul a b/ret add a b/' tests/one_layer/omegese/dev/dev05.omegese > "$B/mut.om" 33 { printf 'ir\n'; cat "$B/mut.om"; } > "$B/mut.input" 34 timeout 5 "$B/stage2" < "$B/mut.input" > "$B/mut.ir" 35 if cmp -s "$B/mut.ir" "$B/dev05.oracle"; then fail 'mutant did not change IR'; fi 36 echo 'PASS mul-to-add mutant differs' 37 # IR mode must refuse what it cannot lower, never skip a declaration silently. 38 ir_refuse() { # name expected-error source 39 printf '%s\n' "$3" > "$B/$1.om" 40 set +e 41 timeout 5 "$B/stage2" < "$B/$1.om" > "$B/$1.out" 2> "$B/$1.err" 42 crc=$? 43 set -e 44 [ "$crc" = "$2" ] || fail "$1: exit $crc, wanted $2" 45 echo "PASS $1 refused $2" 46 } 47 ir_refuse struct_decl 9 'ir 48 struct S a uchar end 49 fn main to int 50 ret 0 51 end' 52 ir_refuse global_decl 9 'ir 53 global g uchar 4 54 fn main to int 55 ret 0 56 end' 57 ir_refuse text_decl 9 'ir 58 text t "x" 59 fn main to int 60 ret 0 61 end' 62 ir_refuse float_use 3 'ir 63 fn main to int 64 x = f64 1.0 65 ret 0 66 end' 67 ir_refuse continue_use 3 'ir 68 fn main to int 69 continue 70 end' 71 # Contract lines are not IR v1 statements: refuse with 30, never read them as a local (#791). 72 ir_refuse requires_line 30 'ir 73 fn f x uint to uint 74 requires lt x 10 75 ret x 76 end' 77 ir_refuse ensures_line 30 'ir 78 fn f x uint to uint 79 ensures lt x 10 80 ret x 81 end' 82 ir_refuse invariant_line 30 'ir 83 fn f x uint to uint 84 invariant lt x 10 85 ret x 86 end' 87 # Integer constants fold to the IR of their literal; float constants are still refused. 88 printf 'ir\nconst N uint 5\nfn f to uint\nret N\nend\n' > "$B/c1.om" 89 printf 'ir\nfn f to uint\nret uint 5\nend\n' > "$B/c2.om" 90 timeout 5 "$B/stage2" < "$B/c1.om" > "$B/c1.ir" 91 timeout 5 "$B/stage2" < "$B/c2.om" > "$B/c2.ir" 92 cmp -s "$B/c1.ir" "$B/c2.ir" || fail 'integer constant IR differs from its literal' 93 echo 'PASS integer constant folds to the literal IR' 94 # Constants in trap, bound and for positions fold to the same IR as literals. 95 ir_fold() { # name const-source literal-source 96 printf '%b\n' "$2" > "$B/$1c.om" 97 printf '%b\n' "$3" > "$B/$1l.om" 98 timeout 5 "$B/stage2" < "$B/$1c.om" > "$B/$1c.ir" 99 timeout 5 "$B/stage2" < "$B/$1l.om" > "$B/$1l.ir" 100 cmp -s "$B/$1c.ir" "$B/$1l.ir" || fail "$1 constant IR differs from its literal" 101 echo "PASS $1 constant folds to the literal IR" 102 } 103 ir_fold trap_const 'ir\nconst T uint 2\nfn f to uint\ntrap T\nend' 'ir\nfn f to uint\ntrap 2\nend' 104 ir_fold bound_const 'ir\nconst B ulong 3\nfn f to uint\nx = uint 0\nwhile lt x uint 2 bound B\nx = add x uint 1\nend\nret x\nend' 'ir\nfn f to uint\nx = uint 0\nwhile lt x uint 2 bound 3\nx = add x uint 1\nend\nret x\nend' 105 ir_fold for_const 'ir\nconst K ulong 4\nfn f to uint\nx = uint 0\nfor i ulong K\nx = add x uint 1\nend\nret x\nend' 'ir\nfn f to uint\nx = uint 0\nfor i ulong 4\nx = add x uint 1\nend\nret x\nend' 106 # for ... bound N: a constant N folds to its literal; an explicit bound `1000000` is the unbounded default. 107 ir_fold for_bound_const 'ir\nconst B ulong 3\nfn f a uint to uint\nx = uint 0\nfor i uint a bound B\nx = add x uint 1\nend\nret x\nend' 'ir\nfn f a uint to uint\nx = uint 0\nfor i uint a bound 3\nx = add x uint 1\nend\nret x\nend' 108 ir_fold for_bound_default 'ir\nfn f a uint to uint\nx = uint 0\nfor i uint a bound `1000000`\nx = add x uint 1\nend\nret x\nend' 'ir\nfn f a uint to uint\nx = uint 0\nfor i uint a\nx = add x uint 1\nend\nret x\nend' 109 ir_refuse for_bound_zero 8 'ir 110 fn f a uint to uint 111 for i uint a bound 0 112 end 113 ret a 114 end' 115 ir_refuse for_bound_over 8 'ir 116 fn f a uint to uint 117 for i uint 3 bound `9223372036854775808` 118 end 119 ret a 120 end' 121 # A number count with a bound gets the counter guard, which checker2 proves terminating. 122 printf 'ir\nfn f a uint to uint\ns = uint 0\nfor i uint 7 bound 5\ns = add s a\nend\nret s\nend\n' > "$B/forbn.om" 123 timeout 5 "$B/stage2" < "$B/forbn.om" > "$B/forbn.ir" 124 build/checker2/checker2 check "$B/forbn.ir" > "$B/forbn.check" 125 grep -q '^checker2=ACCEPT ' "$B/forbn.check" || fail 'for_num_bound checker refusal' 126 echo 'PASS for_num_bound guarded; checker2 ACCEPT' 127 # IR bound range = the C oracle's (omegese.c, 1..`1000000`) = the guard range checker2 proves 128 # (c2_check.c "loop bounds"): bound `1000000` is emitted and accepted, bound `1000001` is error 8. 129 printf 'fn f a uint to uint\nx = uint 0\nwhile lt x a bound `1000000`\nx = add x uint 1\nend\nret x\nend\n' > "$B/wbmax.omegese" 130 build/omegese/omegese emit "$B/wbmax.omegese" "$B/wbmax.json" > /dev/null 131 build/omega_emit/omega_emit emit "$B/wbmax.json" "$B/wbmax.oracle" > /dev/null 132 { printf 'ir\n'; cat "$B/wbmax.omegese"; } > "$B/wbmax.om" 133 timeout 5 "$B/stage2" < "$B/wbmax.om" > "$B/wbmax.ir" 134 cmp -s "$B/wbmax.oracle" "$B/wbmax.ir" || fail 'while_bound_max differs from the oracle' 135 build/checker2/checker2 check "$B/wbmax.ir" > "$B/wbmax.check" 136 grep -q '^checker2=ACCEPT ' "$B/wbmax.check" || fail 'while_bound_max checker refusal' 137 echo 'PASS while_bound_max identical; checker2 ACCEPT' 138 printf 'fn f a uint to uint\nx = uint 0\nwhile lt x a bound `1000001`\nx = add x uint 1\nend\nret x\nend\n' > "$B/wbover.omegese" 139 if build/omegese/omegese emit "$B/wbover.omegese" "$B/wbover.json" > /dev/null 2>&1; then fail 'oracle accepted while bound `1000001`'; fi 140 ir_refuse while_bound_over 8 'ir 141 fn f a uint to uint 142 x = uint 0 143 while lt x a bound `1000001` 144 x = add x uint 1 145 end 146 ret x 147 end' 148 printf 'ir\nfn f a uint to uint\nx = uint 0\nfor i uint a bound `1000000`\nx = add x uint 1\nend\nret x\nend\n' > "$B/fbmax.om" 149 timeout 5 "$B/stage2" < "$B/fbmax.om" > "$B/fbmax.ir" 150 build/checker2/checker2 check "$B/fbmax.ir" > "$B/fbmax.check" 151 grep -q '^checker2=ACCEPT ' "$B/fbmax.check" || fail 'for_bound_max checker refusal' 152 echo 'PASS for_bound_max guarded; checker2 ACCEPT' 153 ir_refuse for_bound_c2 8 'ir 154 fn f a uint to uint 155 x = uint 0 156 for i uint a bound `1000001` 157 x = add x uint 1 158 end 159 ret x 160 end' 161 # IR count range = the C oracle's (omegese.c for_line, 0..`1000000`), so an unguarded loop over a number never 162 # counts past what checker2 proves: count `1000000` is emitted identical to the oracle and accepted; `1000001` and a 163 # minus sign (-1, -0) are refused by both; an integer constant count is held to the same range (error 8). 164 printf 'fn f to ulong\ns = ulong 0\nfor i ulong `1000000`\ns = add s i\nend\nret s\nend\n' > "$B/fcmax.omegese" 165 build/omegese/omegese emit "$B/fcmax.omegese" "$B/fcmax.json" > /dev/null 166 build/omega_emit/omega_emit emit "$B/fcmax.json" "$B/fcmax.oracle" > /dev/null 167 { printf 'ir\n'; cat "$B/fcmax.omegese"; } > "$B/fcmax.om" 168 timeout 5 "$B/stage2" < "$B/fcmax.om" > "$B/fcmax.ir" 169 cmp -s "$B/fcmax.oracle" "$B/fcmax.ir" || fail 'for_count_max differs from the oracle' 170 build/checker2/checker2 check "$B/fcmax.ir" > "$B/fcmax.check" 171 grep -q '^checker2=ACCEPT ' "$B/fcmax.check" || fail 'for_count_max checker refusal' 172 echo 'PASS for_count_max identical; checker2 ACCEPT' 173 for v in `1000001` -1 -0; do 174 printf 'fn f to long\ns = long 0\nfor i long %s\ns = add s i\nend\nret s\nend\n' "$v" > "$B/fcbad.omegese" 175 if build/omegese/omegese emit "$B/fcbad.omegese" "$B/fcbad.json" > /dev/null 2>&1; then fail "oracle accepted for count $v"; fi 176 done 177 ir_refuse for_count_over 8 'ir 178 fn f to ulong 179 s = ulong 0 180 for i ulong `1000001` 181 s = add s i 182 end 183 ret s 184 end' 185 ir_refuse for_count_neg 8 'ir 186 fn f to long 187 s = long 0 188 for i long -1 189 s = add s i 190 end 191 ret s 192 end' 193 ir_refuse for_count_negzero 8 'ir 194 fn f to long 195 s = long 0 196 for i long -0 197 s = add s i 198 end 199 ret s 200 end' 201 ir_refuse for_count_const_over 8 'ir 202 const K ulong `1000001` 203 fn f to ulong 204 s = ulong 0 205 for i ulong K 206 s = add s i 207 end 208 ret s 209 end' 210 ir_refuse float_const 9 'ir 211 const H f64 0.1 212 fn f to f64 213 ret H 214 end' 215 ir_refuse call_self 3 'ir 216 fn f to uint 217 ret f 218 end' 219 ir_refuse call_forward 3 'ir 220 fn f to uint 221 ret g 222 end 223 fn g to uint 224 ret uint 1 225 end' 226 ir_refuse call_nonvoid_stmt 7 'ir 227 fn inc a uint to uint 228 ret add a uint 1 229 end 230 fn f to uint 231 inc uint 4 232 ret uint 2 233 end' 234 ir_refuse call_void_value 7 'ir 235 fn sink a uint to void 236 ret 237 end 238 fn f to uint 239 x = sink uint 1 240 ret uint 2 241 end' 242 ir_refuse call_arg_type 7 'ir 243 fn inc a uchar to uint 244 ret uint 1 245 end 246 fn f to uint 247 ret inc uint 4 248 end' 249 ir_refuse call_arg_local 7 'ir 250 fn inc a uchar to uint 251 ret uint 1 252 end 253 fn f to uint 254 x = uint 4 255 ret inc x 256 end' 257 ir_refuse call_result_type 7 'ir 258 fn inc a uint to uint 259 ret add a uint 1 260 end 261 fn f to uchar 262 ret inc uint 4 263 end' 264 ir_refuse break_outside 9 'ir 265 fn f to uint 266 break 267 end' 268 ir_refuse after_break 17 'ir 269 fn f to uint 270 while lt uint 1 uint 2 bound 3 271 break 272 ret uint 0 273 end 274 ret uint 0 275 end' 276 ir_refuse bin_type_local 7 'ir 277 fn f to uint 278 s = uint 1 279 i = ulong 2 280 x = add s i 281 ret uint 0 282 end' 283 ir_refuse bin_bool 7 'ir 284 fn f to uint 285 x = add bool true true 286 ret uint 0 287 end' 288 ir_refuse bin_shift_bool 7 'ir 289 fn f to ulong 290 ret shl ulong 1 true 291 end' 292 ir_refuse bin_result_type 7 'ir 293 fn f to uchar 294 ret add uint 1 uint 2 295 end' 296 ir_refuse cmp_assign_type 7 'ir 297 fn f to uint 298 x = uint 1 299 x = eq x x 300 ret x 301 end' 302 ir_refuse bool_result 7 'ir 303 fn f to uint 304 ret true 305 end' 306 ir_refuse neg_bool 7 'ir 307 fn f to uint 308 ret neg true 309 end' 310 ir_refuse cond_type 7 'ir 311 fn f to uint 312 x = uint 1 313 if x 314 ret 1 315 end 316 ret 0 317 end' 318 ir_refuse ret_type_local 7 'ir 319 fn f to uchar 320 x = uint 1 321 ret x 322 end' 323 ir_refuse neg_bool_local 7 'ir 324 fn f to uint 325 x = neg true 326 ret uint 0 327 end' 328 # Validation: every word of a line is read, names follow scope, and what IR v1 cannot lower is refused. 329 ir_refuse trailing_value 5 'ir 330 fn f a uint to uint 331 x = add a 1 7 332 ret x 333 end' 334 ir_refuse untyped_new 11 'ir 335 fn f a uint to uint 336 foo 1 a 0 1 337 ret a 338 end' 339 ir_refuse missing_operand 4 'ir 340 fn f a uint to uint 341 x = add a 342 ret x 343 end' 344 ir_refuse bare_neg 11 'ir 345 fn f to ulong 346 ret neg 5 347 end' 348 ir_refuse end_trailing 5 'ir 349 fn f a uint to uint 350 if eq a 0 351 ret 1 352 end a 353 ret a 354 end' 355 ir_refuse while_trailing 5 'ir 356 fn f to uint 357 x = uint 0 358 while lt x uint 3 x 359 x = add x uint 1 360 end 361 ret x 362 end' 363 ir_refuse ret_missing 4 'ir 364 fn f to uint 365 ret 366 end' 367 ir_refuse ret_void_value 5 'ir 368 fn f to void 369 ret uint 1 370 end' 371 ir_refuse keyword_name 16 'ir 372 fn f to uint 373 add = uint 1 374 ret uint 0 375 end' 376 ir_refuse stmt_number 16 'ir 377 fn f to uint 378 5 379 ret uint 0 380 end' 381 ir_refuse shadow_param_for 10 'ir 382 fn f n uint to uint 383 for n uint 3 384 end 385 ret n 386 end' 387 ir_refuse shadow_nested_for 10 'ir 388 fn f n uint to uint 389 s = uint 0 390 for i uint n 391 for i uint 2 392 s = add s i 393 end 394 end 395 ret s 396 end' 397 ir_refuse param_dup 10 'ir 398 fn f a uint a uint to uint 399 ret a 400 end' 401 ir_refuse param_fn_name 10 'ir 402 fn g to uint 403 ret uint 1 404 end 405 fn f g uint to uint 406 ret g 407 end' 408 ir_refuse param_self_name 10 'ir 409 fn f f uint to uint 410 ret f 411 end' 412 ir_refuse scope_if 3 'ir 413 fn f n uint to uint 414 if gt n 0 415 y = uint 3 416 end 417 ret y 418 end' 419 ir_refuse scope_else 3 'ir 420 fn f n uint to uint 421 if gt n 0 422 y = uint 3 423 ret y 424 else 425 ret y 426 end 427 ret n 428 end' 429 ir_refuse scope_for 3 'ir 430 fn f to uint 431 for i uint 3 432 end 433 ret i 434 end' 435 ir_refuse fallthrough 18 'ir 436 fn f a uint to uint 437 if eq a 0 438 ret 1 439 end 440 end' 441 ir_refuse float_param 9 'ir 442 fn f a f64 to f64 443 ret a 444 end' 445 ir_refuse float_ret 9 'ir 446 fn f a uint to f64 447 ret a 448 end' 449 ir_refuse else_twice 15 'ir 450 fn f a uint to uint 451 if eq a 0 452 ret 1 453 else 454 ret 2 455 else 456 ret 3 457 end 458 end' 459 ir_refuse else_outside 15 'ir 460 fn f to uint 461 else 462 ret uint 0 463 end' 464 ir_refuse eof_in_fn 15 'ir 465 fn f to uint 466 ret uint 0' 467 ir_refuse range_typed 8 'ir 468 fn f to uchar 469 ret 300 470 end' 471 ir_refuse range_bare 8 'ir 472 fn f a uchar to uchar 473 ret add a 300 474 end' 475 ir_refuse range_bare_left 8 'ir 476 fn f a uchar to uchar 477 ret sub 256 a 478 end' 479 ir_refuse range_negative 8 'ir 480 fn f to uint 481 ret uint -1 482 end' 483 # Locals, parameters and for counters are at most 8 bytes (13, as native); a word over 8 bytes is never a 484 ir_refuse cast_lit_range 8 'ir 485 fn f to uchar 486 ret uchar 256 487 end' 488 ir_refuse cast_opnd_range 8 'ir 489 fn f c uchar to ulong 490 ret ulong sub c 300 491 end' 492 ir_refuse cast_signed_range 8 'ir 493 fn f c byte to long 494 ret long sub c -129 495 end' 496 ir_refuse cast_bool_num 9 'ir 497 fn f c uchar to bool 498 ret bool c 499 end' 500 ir_refuse cast_num_bool 9 'ir 501 fn f b bool to ulong 502 ret ulong b 503 end' 504 ir_refuse cast_cmp_bool 9 'ir 505 fn f a uint b uint to ulong 506 ret ulong eq a b 507 end' 508 ir_refuse long_local 13 'ir 509 fn f n uint to uint 510 counterxy = add n uint 1 511 ret counterxy 512 end' 513 ir_refuse long_param 13 'ir 514 fn f counterxy uint to uint 515 ret counterxy 516 end' 517 ir_refuse long_for 13 'ir 518 fn f to uint 519 for counterxy uint 3 520 end 521 ret uint 0 522 end' 523 ir_refuse long_prefix_ref 3 'ir 524 fn f n uint to uint 525 counterx = add n uint 1 526 ret counterxy 527 end' 528 # Same IR from two spellings: a note after the path ended is skipped like any note. 529 ir_same() { # name source-a source-b 530 printf '%b\n' "$2" > "$B/$1a.om" 531 printf '%b\n' "$3" > "$B/$1b.om" 532 timeout 5 "$B/stage2" < "$B/$1a.om" > "$B/$1a.ir" 533 timeout 5 "$B/stage2" < "$B/$1b.om" > "$B/$1b.ir" 534 cmp -s "$B/$1a.ir" "$B/$1b.ir" || fail "$1 IR differs between the two spellings" 535 echo "PASS $1 same IR" 536 } 537 ir_same note_dead 'ir\nfn f to uint\nret uint 1\nnote after the path ended\nend' 'ir\nfn f to uint\nret uint 1\nend' 538 539 # Multi-function units with calls: byte-identical to the C oracle and checker2 ACCEPT. 540 ir_multi() { # name source 541 printf '%b\n' "$2" > "$B/$1.omegese" 542 build/omegese/omegese emit "$B/$1.omegese" "$B/$1.json" 543 build/omega_emit/omega_emit emit "$B/$1.json" "$B/$1.oracle" 544 { printf 'ir\n'; cat "$B/$1.omegese"; } > "$B/$1.input" 545 timeout 5 "$B/stage2" < "$B/$1.input" > "$B/$1.got" 546 cmp -s "$B/$1.oracle" "$B/$1.got" || fail "$1 multi-function IR differs" 547 build/checker2/checker2 check "$B/$1.got" > "$B/$1.check" 548 grep -q '^checker2=ACCEPT ' "$B/$1.check" || fail "$1 checker refusal" 549 echo "PASS $1 IR identical; checker2 ACCEPT" 550 } 551 ir_multi call_value 'fn inc a uint to uint\nret add a uint 1\nend\nfn f to uint\nret inc uint 4\nend' 552 ir_multi call_void 'fn sink a uint to void\nret\nend\nfn f to uint\nsink uint 1\nret uint 2\nend' 553 ir_multi call_zero 'fn z to uint\nret uint 1\nend\nfn f to uint\nret z\nend' 554 ir_multi call_two 'fn add2 a uint b uint to uint\nret add a b\nend\nfn f to uint\nret add2 uint 3 uint 4\nend' 555 ir_multi call_long 'fn increment_one a uint to uint\nret add a uint 1\nend\nfn f to uint\nret increment_one uint 4\nend' 556 ir_multi call_nested 'fn inc a uint to uint\nret add a uint 1\nend\nfn f to uint\nret inc inc uint 4\nend' 557 ir_multi call_expr 'fn inc a uint to uint\nret add a uint 1\nend\nfn f to uint\nret add inc uint 1 inc uint 2\nend' 558 ir_multi call_loop 'fn add1 a uint to uint\nret add a uint 1\nend\nfn f to uint\nx = uint 0\nwhile lt x uint 3 bound 8\nx = add1 x\nend\nret x\nend' 559 ir_multi call_six 'fn sum6 a uint b uint c uint d uint e uint f uint to uint\nret add add add add add a b c d e f\nend\nfn f to uint\nret sum6 uint 1 uint 2 uint 3 uint 4 uint 5 uint 6\nend' 560 ir_multi break_while 'fn f to uint\nx = uint 0\nwhile lt x uint 10 bound 100\nif eq x uint 3\nbreak\nend\nx = add x uint 1\nend\nret x\nend' 561 ir_multi break_for 'fn f to uint\ns = uint 0\nfor i ulong 10\nif eq i ulong 3\nbreak\nend\ns = add s uint i\nend\nret s\nend' 562 ir_multi break_nested 'fn f to uint\nx = uint 0\nwhile lt x uint 5 bound 20\ny = uint 0\nwhile lt y uint 5 bound 20\nif eq y uint 2\nbreak\nend\ny = add y uint 1\nend\nx = add x y\nend\nret x\nend' 563 ir_multi shift_mixed 'fn f to ulong\nret shl ulong 1 uint 3\nend' 564 ir_multi cmp_assign 'fn f to bool\nx = lt uint 1 uint 2\nx = eq uint 1 uint 1\nret x\nend' 565 ir_multi cast_ret 'fn f to uchar\nret uchar uint 1\nend' 566 ir_multi cast_wide 'fn f c uchar to ulong\nret ulong sub c 48\nend' 567 ir_multi cast_left 'fn f c uchar to ulong\nret ulong sub 255 c\nend' 568 ir_multi cast_u2s 'fn f c uchar to long\nret long sub c 48\nend' 569 ir_multi cast_s2s 'fn f c byte to long\nret long add c 1\nend' 570 ir_multi cast_s2u 'fn f c byte to ulong\nret ulong sub c 1\nend' 571 ir_multi cast_narrow 'fn f x ulong to uchar\nret uchar sub x 1\nend' 572 ir_multi cast_narrow_s 'fn f x long to byte\nret byte add x 1\nend' 573 ir_multi cast_same_ty 'fn f x uint to uint\nret uint add x 1\nend' 574 ir_multi cast_un 'fn f c uchar to ulong\nret ulong not c\nend' 575 ir_multi cast_call 'fn g a uchar to uchar\nret add a 1\nend\nfn f c uchar to ulong\nret ulong g c\nend' 576 ir_multi cast_assign 'fn f c uchar to ulong\nx = ulong sub c 48\nret x\nend' 577 ir_multi cast_nested 'fn f c uchar to ulong\nret ulong uint mul c 2\nend' 578 ir_multi cast_arg 'fn g a ulong to ulong\nret add a 1\nend\nfn f c uchar to ulong\nret g ulong sub c 48\nend' 579 ir_multi cast_lit_var 'fn f to uint\nx = uint 5\nret uint x\nend' 580 ir_multi cast_nest_var 'fn f x uint to uint\nret uint uint x\nend' 581 ir_multi cast_same_assign 'fn f x uint to uint\ny = uint x\nret y\nend' 582 ir_multi cast_same_param 'fn f x uint to uint\nret uint x\nend' 583 ir_multi cast_neg_lit 'fn f c byte to long\nret long sub c -128\nend' 584 ir_multi cast_ulong_max 'fn f to ulong\nret ulong `18446744073709551615`\nend' 585 ir_multi cast_cond 'fn f c uchar to uint\nif lt ulong c 10\nret 1\nend\nret 0\nend' 586 # A same-type cast of an integer or bool constant is the constant itself (the oracle's konst rule), not a mov. 587 ir_multi cast_same_konst 'fn f to uint\nret uint uint 5\nend' 588 ir_multi cast_same_bool 'fn f to bool\nret bool true\nend' 589 ir_multi cast_same_arg 'fn g a ulong to ulong\nret add a 1\nend\nfn f to ulong\nret g ulong ulong 7\nend' 590 ir_multi bool_and 'fn f a bool b bool to bool\nret and a b\nend' 591 ir_multi bool_or 'fn f a bool b bool to bool\nret or a b\nend' 592 ir_multi bool_xor 'fn f a bool b bool to bool\nret xor a b\nend' 593 ir_multi void_fall 'fn sink a uint to void\nend\nfn f to uint\nsink uint 1\nret uint 2\nend' 594 ir_multi for_reuse 'fn f to uint\ns = uint 0\nfor i uint 3\ns = add s i\nend\nfor i uint 2\ns = add s i\nend\nret s\nend' 595 ir_multi for_value 'fn f n uint to uint\ns = uint 0\nfor i uint n\ns = add s i\nend\nret s\nend' 596 ir_multi for_value_expr 'fn f n uchar to uint\ns = uint 0\nfor i uchar add n uchar 1\nif eq i uchar 3\nbreak\nend\ns = add s uint 1\nend\nret s\nend' 597 ir_multi scope_reuse 'fn f a uint to uint\nif gt a 1\ny = add a 1\nret y\nend\ny = add a 2\nret y\nend' 598 ir_multi call_long_prefix 'fn increment_one a uint to uint\nret add a uint 1\nend\nfn increment_two a uint to uint\nret add a uint 2\nend\nfn f to uint\nret increment_two uint 4\nend' 599 # A contract word followed by = is an assignment to a local of that name, as in the C oracle (only the clause form is error 30). 600 ir_multi ensures_assign 'fn f to ulong\nensures = ulong 1\nret ensures\nend' 601 ir_multi requires_assign 'fn f to ulong\nx = ulong 1\nrequires = add x x\nrequires = add requires x\nret requires\nend' 602 # Random two-function programs with a call: differential against the oracle. 603 rm -f "$B"/fz* 604 awk -v dir="$B" 'BEGIN{ 605 M = 65536; 606 split("add sub mul xor and or", O, " "); 607 split("eq ne lt le gt ge", C, " "); 608 for (p = 0; p < 30; p++) { 609 s = 1000 + p * 37; 610 s = (s * 25173 + 13849) % M; o1 = O[1 + (s % 6)]; 611 s = (s * 25173 + 13849) % M; o2 = O[1 + (s % 6)]; 612 s = (s * 25173 + 13849) % M; o3 = O[1 + (s % 6)]; 613 s = (s * 25173 + 13849) % M; cm = C[1 + (s % 6)]; 614 s = (s * 25173 + 13849) % M; n1 = 1 + (s % 9); 615 s = (s * 25173 + 13849) % M; n2 = 1 + (s % 9); 616 s = (s * 25173 + 13849) % M; n3 = 1 + (s % 9); 617 s = (s * 25173 + 13849) % M; n4 = 1 + (s % 9); 618 s = (s * 25173 + 13849) % M; o4 = O[1 + (s % 6)]; 619 s = (s * 25173 + 13849) % M; n5 = 1 + (s % 9); 620 f = sprintf("%s/fz%02d.omegese", dir, p); 621 print "fn h a ulong b ulong to ulong" > f; 622 print "x = " o1 " a b" > f; 623 print "y = " o2 " x " n1 > f; 624 print "if " cm " y " n2 > f; 625 print "y = " o3 " y " n3 > f; 626 print "end" > f; 627 print "ret y" > f; 628 print "end" > f; 629 print "fn f to ulong" > f; 630 print "p = ulong " n4 > f; 631 print "q = ulong " n4 > f; 632 print "r = h p q" > f; 633 print "z = " o4 " r " n5 > f; 634 print "ret z" > f; 635 print "end" > f; 636 close(f); 637 } 638 }' 639 fzn=0 640 for f in "$B"/fz*.omegese; do 641 fzn=$((fzn + 1)) 642 b=${f%.omegese} 643 build/omegese/omegese emit "$f" "$b.json" > /dev/null 644 build/omega_emit/omega_emit emit "$b.json" "$b.oracle" > /dev/null 645 { printf 'ir\n'; cat "$f"; } > "$b.input" 646 timeout 5 "$B/stage2" < "$b.input" > "$b.got" 647 cmp -s "$b.oracle" "$b.got" || fail "fuzz $b differs from the oracle" 648 build/checker2/checker2 check "$b.got" > "$b.check" 649 grep -q '^checker2=ACCEPT ' "$b.check" || fail "fuzz $b checker refusal" 650 done 651 [ "$fzn" = 30 ] || fail "fuzz ran $fzn of 30 programs" 652 echo "PASS 30 random two-function call units identical; checker2 ACCEPT" 653 echo 'SCALAR_IR_CHECKPOINT 10/10 + 31 refusals + 9 multi-call units + 3 break units + 2 for-value units + 1 shift unit + 4 bool units + 24 cast units + 2 contract-name units + 30 fuzz units + 1 guarded for-bound unit + 2 bound-range pairs (`1000000` accepted, `1000001` error 8) + 1 count-range set (`1000000` identical to the oracle; `1000001`, -1, -0, const `1000001` error 8); validation: 38 refusals + 1 same-IR pair + 4 scope/fallthrough/long-name units; structs IR spec-blocked' 654 echo 'RC=0'