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 / om / codec / codec.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note codec.om: seeded Omega port of src/omega_codec.c, src/omega_canonical.c and src/omega_validate.c |
| 3 | note (aien-dev/omega-mv#726), with the parts of src/omega_core.c they call (effect payload decode and |
| 4 | note the four builders omega_graph_parse_text uses). Parity is on bytes and status codes against the C |
| 5 | note as the product builds it (gcc -std=gnu11 -O2, the Makefile CFLAGS, aarch64). See README.md. |
| 6 | note |
| 7 | note A graph is two arrays: W, the OMGG wire image it was decoded from (uchar, WCAP bytes), and X, |
| 8 | note an index of ulongs (XLEN). The C OmegaGraph (6,648,836 bytes) is never materialised: every |
| 9 | note OmegaObject field is a function of W and X, and sbyte below gives any byte of the C struct image |
| 10 | note (the C reads past an object's 1024-byte payload in format_text and in the cycle walk). |
| 11 | note X 0 object count |
| 12 | note X ob(j) + 0..13 cbuf offset, clen, kind, attr count, rel count, first rel offset, |
| 13 | note const count, payload_len, payload offset, has_id, id as 4 big-endian ulongs |
| 14 | note X ob(j) + 14..45 offset of attribute a's key bytes (klen is the byte before) |
| 15 | note X ob(j) + 46..77 offset of constraint c's record (kind, payload_len, payload) |
| 16 | note |
| 17 | note Exported functions (omega-bridge native call ABI v1: ulong scalars, fixed-length uchar/ulong |
| 18 | note arrays, long result): |
| 19 | note cdecode w n x omega_graph_deserialize_binary: 0, -1 as the C; -2 = needs a byte past WCAP |
| 20 | note cserial w x mx o omega_graph_serialize_binary: the length written, or -1 |
| 21 | note cvalid w x e omega_validate_graph: 0 or -1, message + NUL in e as the C's snprintf |
| 22 | note cvobject w x j e omega_validate_object of object j: 0 or -1, message as cvalid |
| 23 | note cformat w x cap t omega_graph_format_text: 0 or -1, t as the C leaves it |
| 24 | note cparse s n w x omega_graph_parse_text: 0 (-2: n > SCAP); the graph is left in w, x |
| 25 | note ccanon w x j cb omega_canonical_encode of object j with max_len 4096: length or -1 |
| 26 | note chexparse h o omega_parse_hex_semantic_id on the first 65 bytes of the C string |
| 27 | note chexid i o omega_hex_semantic_id: 64 hex digits and a NUL |
| 28 | note cidcmp a b omega_compare_semantic_id: -1, 0, 1 (glibc aarch64 memcmp gives the sign) |
| 29 | note cobjver k omega_canonical_object_version |
| 30 | note cchkhdr v k omega_canonical_check_header |
| 31 | |
| 32 | note Fixed sizes (written as numbers: the pinned omc refuses `const` in function mode, error 9): |
| 33 | note 2097152 W, the wire image (WCAP) 20544 X, the index: 64 + 80 * 256 (XLEN) |
| 34 | note 1049606 serialize output: 6 + 256 * (4 + 4096), the most omega_graph_serialize_binary writes |
| 35 | note 65536 format_text buffer (TCAP) 262144 parse_text input (SCAP) |
| 36 | note 256 error message / text line 4294967295 the 32-bit mask in SHA-256 |
| 37 | |
| 38 | note ---- small helpers ---- |
| 39 | |
| 40 | fn ob j ulong to ulong |
| 41 | ret add 64 mul j 80 |
| 42 | end |
| 43 | |
| 44 | fn be16 w view uchar 2097152 i ulong to ulong |
| 45 | ret or shl ulong get w i 8 ulong get w add i 1 |
| 46 | end |
| 47 | |
| 48 | fn be32 w view uchar 2097152 i ulong to ulong |
| 49 | v = be16 w i |
| 50 | ret or shl v 16 be16 w add i 2 |
| 51 | end |
| 52 | |
| 53 | fn be64 w view uchar 2097152 i ulong to ulong |
| 54 | v = be32 w i |
| 55 | ret or shl v 32 be32 w add i 4 |
| 56 | end |
| 57 | |
| 58 | fn cobjver k ulong to ulong |
| 59 | if eq k 8 |
| 60 | ret 2 |
| 61 | end |
| 62 | ret 1 |
| 63 | end |
| 64 | |
| 65 | fn cchkhdr v ulong k ulong to long |
| 66 | if and eq k 8 eq v 1 |
| 67 | ret -2 |
| 68 | end |
| 69 | if ne v cobjver k |
| 70 | ret -1 |
| 71 | end |
| 72 | ret 0 |
| 73 | end |
| 74 | |
| 75 | note ---- the C struct image (aarch64 LP64 offsets, measured with offsetof) ---- |
| 76 | note OmegaObject 25972 bytes: id 0, has_id 32, kind 36, attr_count 40, attributes 42 (578 each: |
| 77 | note key 64, value 512, val_len 576), rel_count 18538, relations 18540 (34 each), const_count |
| 78 | note 20716, constraints 20718 (132 each), payload_len 24944, payload 24948. Host order little-endian. |
| 79 | |
| 80 | note payload byte p (< 1024) of the object at X base b; 0 past payload_len (the decoder memsets) |
| 81 | fn plb w view uchar 2097152 x view ulong 20544 b ulong p ulong to ulong |
| 82 | if lt p get x add b 7 |
| 83 | ret ulong get w add get x add b 8 p |
| 84 | end |
| 85 | ret 0 |
| 86 | end |
| 87 | |
| 88 | fn sattr w view uchar 2097152 x view ulong 20544 b ulong q ulong to ulong |
| 89 | a = div q 578 |
| 90 | r = rem q 578 |
| 91 | if ge a get x add b 3 |
| 92 | ret 0 |
| 93 | end |
| 94 | o = get x add add b 14 a |
| 95 | kl = ulong get w sub o 1 |
| 96 | if lt r 64 |
| 97 | if lt r kl |
| 98 | ret ulong get w add o r |
| 99 | end |
| 100 | ret 0 |
| 101 | end |
| 102 | vl = be16 w add o kl |
| 103 | if lt r 576 |
| 104 | v = sub r 64 |
| 105 | if lt v vl |
| 106 | ret ulong get w add add o kl add 2 v |
| 107 | end |
| 108 | ret 0 |
| 109 | end |
| 110 | if eq r 576 |
| 111 | ret and vl 255 |
| 112 | end |
| 113 | ret shr vl 8 |
| 114 | end |
| 115 | |
| 116 | fn srel w view uchar 2097152 x view ulong 20544 b ulong q ulong to ulong |
| 117 | r = div q 34 |
| 118 | s = rem q 34 |
| 119 | if ge r get x add b 4 |
| 120 | ret 0 |
| 121 | end |
| 122 | o = add get x add b 5 mul r 34 |
| 123 | if eq s 0 |
| 124 | ret ulong get w add o 1 |
| 125 | end |
| 126 | if eq s 1 |
| 127 | ret ulong get w o |
| 128 | end |
| 129 | ret ulong get w add o s |
| 130 | end |
| 131 | |
| 132 | fn sconst w view uchar 2097152 x view ulong 20544 b ulong q ulong to ulong |
| 133 | c = div q 132 |
| 134 | s = rem q 132 |
| 135 | if ge c get x add b 6 |
| 136 | ret 0 |
| 137 | end |
| 138 | o = get x add add b 46 c |
| 139 | if lt s 4 |
| 140 | if eq s 0 |
| 141 | ret ulong get w add o 1 |
| 142 | end |
| 143 | if eq s 1 |
| 144 | ret ulong get w o |
| 145 | end |
| 146 | if eq s 2 |
| 147 | ret ulong get w add o 3 |
| 148 | end |
| 149 | ret ulong get w add o 2 |
| 150 | end |
| 151 | p = sub s 4 |
| 152 | if lt p be16 w add o 2 |
| 153 | ret ulong get w add add o 4 p |
| 154 | end |
| 155 | ret 0 |
| 156 | end |
| 157 | |
| 158 | note byte o of OmegaObject j as the C holds it; objects at or past the count are zero (memset, and the |
| 159 | note oracle's graph has zero bytes after it: see README "Reads past the object") |
| 160 | fn sbyte w view uchar 2097152 x view ulong 20544 j ulong o ulong to ulong |
| 161 | if ge j get x 0 |
| 162 | ret 0 |
| 163 | end |
| 164 | b = ob j |
| 165 | if lt o 32 |
| 166 | q = get x add add b 10 div o 8 |
| 167 | ret and shr q mul sub 7 rem o 8 8 255 |
| 168 | end |
| 169 | if eq o 32 |
| 170 | ret get x add b 9 |
| 171 | end |
| 172 | if eq o 36 |
| 173 | ret get x add b 2 |
| 174 | end |
| 175 | if eq o 40 |
| 176 | ret and get x add b 3 255 |
| 177 | end |
| 178 | if eq o 41 |
| 179 | ret shr get x add b 3 8 |
| 180 | end |
| 181 | if lt o 42 |
| 182 | ret 0 |
| 183 | end |
| 184 | if lt o 18538 |
| 185 | ret sattr w x b sub o 42 |
| 186 | end |
| 187 | if eq o 18538 |
| 188 | ret and get x add b 4 255 |
| 189 | end |
| 190 | if eq o 18539 |
| 191 | ret shr get x add b 4 8 |
| 192 | end |
| 193 | if lt o 20716 |
| 194 | ret srel w x b sub o 18540 |
| 195 | end |
| 196 | if eq o 20716 |
| 197 | ret and get x add b 6 255 |
| 198 | end |
| 199 | if eq o 20717 |
| 200 | ret shr get x add b 6 8 |
| 201 | end |
| 202 | if lt o 24942 |
| 203 | ret sconst w x b sub o 20718 |
| 204 | end |
| 205 | if lt o 24944 |
| 206 | ret 0 |
| 207 | end |
| 208 | if lt o 24948 |
| 209 | ret and shr get x add b 7 mul sub o 24944 8 255 |
| 210 | end |
| 211 | ret plb w x b sub o 24948 |
| 212 | end |
| 213 | |
| 214 | note payload byte p of object j, also past the 1024-byte payload (into the following objects) |
| 215 | fn pbyte w view uchar 2097152 x view ulong 20544 j ulong p ulong to ulong |
| 216 | if lt p 1024 |
| 217 | ret plb w x ob j p |
| 218 | end |
| 219 | g = add 24948 p |
| 220 | ret sbyte w x add j div g 25972 rem g 25972 |
| 221 | end |
| 222 | |
| 223 | note 8 payload bytes from p, big-endian (an id word) |
| 224 | fn pw64 w view uchar 2097152 x view ulong 20544 j ulong p ulong to ulong |
| 225 | v = ulong 0 |
| 226 | for i ulong 8 |
| 227 | v = or shl v 8 pbyte w x j add p i |
| 228 | end |
| 229 | ret v |
| 230 | end |
| 231 | |
| 232 | fn pu16 w view uchar 2097152 x view ulong 20544 b ulong p ulong to ulong |
| 233 | ret or plb w x b p shl plb w x b add p 1 8 |
| 234 | end |
| 235 | |
| 236 | fn pu32 w view uchar 2097152 x view ulong 20544 b ulong p ulong to ulong |
| 237 | v = pu16 w x b add p 2 |
| 238 | ret or shl v 16 pu16 w x b p |
| 239 | end |
| 240 | |
| 241 | note ---- SHA-256 (FIPS 180-4; from tools/zero-legacy/sha256.om, state in arrays) ---- |
| 242 | |
| 243 | fn shak k edit ulong 64 to void |
| 244 | put k 0 1116352408 |
| 245 | put k 1 1899447441 |
| 246 | put k 2 3049323471 |
| 247 | put k 3 3921009573 |
| 248 | put k 4 961987163 |
| 249 | put k 5 1508970993 |
| 250 | put k 6 2453635748 |
| 251 | put k 7 2870763221 |
| 252 | put k 8 3624381080 |
| 253 | put k 9 310598401 |
| 254 | put k 10 607225278 |
| 255 | put k 11 1426881987 |
| 256 | put k 12 1925078388 |
| 257 | put k 13 2162078206 |
| 258 | put k 14 2614888103 |
| 259 | put k 15 3248222580 |
| 260 | put k 16 3835390401 |
| 261 | put k 17 4022224774 |
| 262 | put k 18 264347078 |
| 263 | put k 19 604807628 |
| 264 | put k 20 770255983 |
| 265 | put k 21 1249150122 |
| 266 | put k 22 1555081692 |
| 267 | put k 23 1996064986 |
| 268 | put k 24 2554220882 |
| 269 | put k 25 2821834349 |
| 270 | put k 26 2952996808 |
| 271 | put k 27 3210313671 |
| 272 | put k 28 3336571891 |
| 273 | put k 29 3584528711 |
| 274 | put k 30 113926993 |
| 275 | put k 31 338241895 |
| 276 | put k 32 666307205 |
| 277 | put k 33 773529912 |
| 278 | put k 34 1294757372 |
| 279 | put k 35 1396182291 |
| 280 | put k 36 1695183700 |
| 281 | put k 37 1986661051 |
| 282 | put k 38 2177026350 |
| 283 | put k 39 2456956037 |
| 284 | put k 40 2730485921 |
| 285 | put k 41 2820302411 |
| 286 | put k 42 3259730800 |
| 287 | put k 43 3345764771 |
| 288 | put k 44 3516065817 |
| 289 | put k 45 3600352804 |
| 290 | put k 46 4094571909 |
| 291 | put k 47 275423344 |
| 292 | put k 48 430227734 |
| 293 | put k 49 506948616 |
| 294 | put k 50 659060556 |
| 295 | put k 51 883997877 |
| 296 | put k 52 958139571 |
| 297 | put k 53 1322822218 |
| 298 | put k 54 1537002063 |
| 299 | put k 55 1747873779 |
| 300 | put k 56 1955562222 |
| 301 | put k 57 2024104815 |
| 302 | put k 58 2227730452 |
| 303 | put k 59 2361852424 |
| 304 | put k 60 2428436474 |
| 305 | put k 61 2756734187 |
| 306 | put k 62 3204031479 |
| 307 | put k 63 3329325298 |
| 308 | end |
| 309 | |
| 310 | fn shainit h edit ulong 8 to void |
| 311 | put h 0 1779033703 |
| 312 | put h 1 3144134277 |
| 313 | put h 2 1013904242 |
| 314 | put h 3 2773480762 |
| 315 | put h 4 1359893119 |
| 316 | put h 5 2600822924 |
| 317 | put h 6 528734635 |
| 318 | put h 7 1541459225 |
| 319 | end |
| 320 | |
| 321 | fn rotr x ulong r ulong to ulong |
| 322 | ret and or shr x r shl x sub 32 r 4294967295 |
| 323 | end |
| 324 | |
| 325 | fn bsig0 x ulong to ulong |
| 326 | ret xor rotr x 2 xor rotr x 13 rotr x 22 |
| 327 | end |
| 328 | |
| 329 | fn bsig1 x ulong to ulong |
| 330 | ret xor rotr x 6 xor rotr x 11 rotr x 25 |
| 331 | end |
| 332 | |
| 333 | fn ssig0 x ulong to ulong |
| 334 | ret xor rotr x 7 xor rotr x 18 shr x 3 |
| 335 | end |
| 336 | |
| 337 | fn ssig1 x ulong to ulong |
| 338 | ret xor rotr x 17 xor rotr x 19 shr x 10 |
| 339 | end |
| 340 | |
| 341 | fn shach x ulong y ulong z ulong to ulong |
| 342 | ret xor and x y and and not x 4294967295 z |
| 343 | end |
| 344 | |
| 345 | fn shamaj x ulong y ulong z ulong to ulong |
| 346 | ret xor and x y xor and x z and y z |
| 347 | end |
| 348 | |
| 349 | fn shard st edit ulong 8 ki ulong wi ulong to void |
| 350 | a = get st 0 |
| 351 | e = get st 4 |
| 352 | t1 = add get st 7 bsig1 e |
| 353 | t1 = add t1 shach e get st 5 get st 6 |
| 354 | t1 = and add add t1 ki wi 4294967295 |
| 355 | t2 = and add bsig0 a shamaj a get st 1 get st 2 4294967295 |
| 356 | put st 7 get st 6 |
| 357 | put st 6 get st 5 |
| 358 | put st 5 e |
| 359 | put st 4 and add get st 3 t1 4294967295 |
| 360 | put st 3 get st 2 |
| 361 | put st 2 get st 1 |
| 362 | put st 1 a |
| 363 | put st 0 and add t1 t2 4294967295 |
| 364 | end |
| 365 | |
| 366 | fn shablk h edit ulong 8 m view uchar 64 k view ulong 64 to void |
| 367 | w = new ulong 64 0 |
| 368 | for i ulong 16 |
| 369 | o = mul i 4 |
| 370 | v = ulong get m o |
| 371 | v = or shl v 8 ulong get m add o 1 |
| 372 | v = or shl v 8 ulong get m add o 2 |
| 373 | v = or shl v 8 ulong get m add o 3 |
| 374 | put w i v |
| 375 | end |
| 376 | for j ulong 48 |
| 377 | i = add j 16 |
| 378 | s = add ssig1 get w sub i 2 get w sub i 7 |
| 379 | s = add s ssig0 get w sub i 15 |
| 380 | s = add s get w sub i 16 |
| 381 | put w i and s 4294967295 |
| 382 | end |
| 383 | st = new ulong 8 0 |
| 384 | for i ulong 8 |
| 385 | put st i get h i |
| 386 | end |
| 387 | for i ulong 64 |
| 388 | shard st get k i get w i |
| 389 | end |
| 390 | for i ulong 8 |
| 391 | put h i and add get h i get st i 4294967295 |
| 392 | end |
| 393 | end |
| 394 | |
| 395 | note pad block m (r message bytes already in it) and finish; shaget gives the digest as 4 big-endian ulongs |
| 396 | fn shafin h edit ulong 8 m edit uchar 64 k view ulong 64 r ulong n ulong to void |
| 397 | put m r 128 |
| 398 | for i ulong 64 |
| 399 | if gt i r |
| 400 | put m i 0 |
| 401 | end |
| 402 | end |
| 403 | if ge r 56 |
| 404 | shablk h m k |
| 405 | for i ulong 64 |
| 406 | put m i 0 |
| 407 | end |
| 408 | end |
| 409 | bits = mul n 8 |
| 410 | for i ulong 8 |
| 411 | sh = mul sub 7 i 8 |
| 412 | put m add 56 i uchar and shr bits sh 255 |
| 413 | end |
| 414 | shablk h m k |
| 415 | end |
| 416 | |
| 417 | fn shaget h view ulong 8 d edit ulong 4 to void |
| 418 | for i ulong 4 |
| 419 | put d i or shl get h mul i 2 32 get h add mul i 2 1 |
| 420 | end |
| 421 | end |
| 422 | |
| 423 | fn sha4k b view uchar 4096 n ulong d edit ulong 4 to void |
| 424 | k = new ulong 64 0 |
| 425 | shak k |
| 426 | h = new ulong 8 0 |
| 427 | shainit h |
| 428 | m = new uchar 64 0 |
| 429 | nb = div n 64 |
| 430 | for bi ulong nb |
| 431 | o = mul bi 64 |
| 432 | for i ulong 64 |
| 433 | put m i get b add o i |
| 434 | end |
| 435 | shablk h m k |
| 436 | end |
| 437 | tb = mul nb 64 |
| 438 | r = sub n tb |
| 439 | for i ulong r |
| 440 | put m i get b add tb i |
| 441 | end |
| 442 | shafin h m k r n |
| 443 | shaget h d |
| 444 | end |
| 445 | |
| 446 | note ---- decode (omega_graph_deserialize_binary) ---- |
| 447 | |
| 448 | note the C's check `cpos + k > clen` (-1), then the port's capacity: a byte at or past WCAP (-2) |
| 449 | fn cneed cp ulong k ulong cl ulong c2 ulong to long |
| 450 | if gt add cp k cl |
| 451 | ret -1 |
| 452 | end |
| 453 | if gt add cp k c2 |
| 454 | ret -2 |
| 455 | end |
| 456 | ret 0 |
| 457 | end |
| 458 | |
| 459 | fn cap2 cs ulong cl ulong to ulong |
| 460 | r = sub 2097152 cs |
| 461 | if lt cl r |
| 462 | ret cl |
| 463 | end |
| 464 | ret r |
| 465 | end |
| 466 | |
| 467 | fn dattrs w view uchar 2097152 x edit ulong 20544 b ulong cs ulong cl ulong to long |
| 468 | c2 = cap2 cs cl |
| 469 | cp = ulong 6 |
| 470 | r = cneed cp 2 cl c2 |
| 471 | if ne r 0 |
| 472 | ret r |
| 473 | end |
| 474 | na = be16 w add cs cp |
| 475 | cp = add cp 2 |
| 476 | if gt na 32 |
| 477 | ret -1 |
| 478 | end |
| 479 | put x add b 3 na |
| 480 | for a ulong na |
| 481 | r = cneed cp 1 cl c2 |
| 482 | if ne r 0 |
| 483 | ret r |
| 484 | end |
| 485 | kl = ulong get w add cs cp |
| 486 | cp = add cp 1 |
| 487 | if ge kl 64 |
| 488 | ret -1 |
| 489 | end |
| 490 | r = cneed cp add kl 2 cl c2 |
| 491 | if ne r 0 |
| 492 | ret r |
| 493 | end |
| 494 | put x add add b 14 a add cs cp |
| 495 | cp = add cp kl |
| 496 | vl = be16 w add cs cp |
| 497 | cp = add cp 2 |
| 498 | if gt vl 512 |
| 499 | ret -1 |
| 500 | end |
| 501 | r = cneed cp vl cl c2 |
| 502 | if ne r 0 |
| 503 | ret r |
| 504 | end |
| 505 | cp = add cp vl |
| 506 | end |
| 507 | ret long cp |
| 508 | end |
| 509 | |
| 510 | fn drels w view uchar 2097152 x edit ulong 20544 b ulong cs ulong cl ulong cp ulong to long |
| 511 | c2 = cap2 cs cl |
| 512 | r = cneed cp 2 cl c2 |
| 513 | if ne r 0 |
| 514 | ret r |
| 515 | end |
| 516 | nr = be16 w add cs cp |
| 517 | cp = add cp 2 |
| 518 | if gt nr 64 |
| 519 | ret -1 |
| 520 | end |
| 521 | put x add b 4 nr |
| 522 | put x add b 5 add cs cp |
| 523 | for i ulong nr |
| 524 | r = cneed cp 34 cl c2 |
| 525 | if ne r 0 |
| 526 | ret r |
| 527 | end |
| 528 | cp = add cp 34 |
| 529 | end |
| 530 | ret long cp |
| 531 | end |
| 532 | |
| 533 | fn dconsts w view uchar 2097152 x edit ulong 20544 b ulong cs ulong cl ulong cp ulong to long |
| 534 | c2 = cap2 cs cl |
| 535 | r = cneed cp 2 cl c2 |
| 536 | if ne r 0 |
| 537 | ret r |
| 538 | end |
| 539 | nc = be16 w add cs cp |
| 540 | cp = add cp 2 |
| 541 | if gt nc 32 |
| 542 | ret -1 |
| 543 | end |
| 544 | put x add b 6 nc |
| 545 | for c ulong nc |
| 546 | r = cneed cp 4 cl c2 |
| 547 | if ne r 0 |
| 548 | ret r |
| 549 | end |
| 550 | put x add add b 46 c add cs cp |
| 551 | pl = be16 w add add cs cp 2 |
| 552 | cp = add cp 4 |
| 553 | if gt pl 128 |
| 554 | ret -1 |
| 555 | end |
| 556 | r = cneed cp pl cl c2 |
| 557 | if ne r 0 |
| 558 | ret r |
| 559 | end |
| 560 | cp = add cp pl |
| 561 | end |
| 562 | ret long cp |
| 563 | end |
| 564 | |
| 565 | fn dpay w view uchar 2097152 x edit ulong 20544 b ulong cs ulong cl ulong cp ulong to long |
| 566 | c2 = cap2 cs cl |
| 567 | r = cneed cp 4 cl c2 |
| 568 | if ne r 0 |
| 569 | ret r |
| 570 | end |
| 571 | pl = be32 w add cs cp |
| 572 | cp = add cp 4 |
| 573 | if gt pl 1024 |
| 574 | ret -1 |
| 575 | end |
| 576 | r = cneed cp pl cl c2 |
| 577 | if ne r 0 |
| 578 | ret r |
| 579 | end |
| 580 | put x add b 7 pl |
| 581 | put x add b 8 add cs cp |
| 582 | ret long add cp pl |
| 583 | end |
| 584 | |
| 585 | note omega_effect_read of a KIND_EFFECT object (omega_core.c): 0 or OMEGA_EFFECT_ERR_* |
| 586 | fn effchk w view uchar 2097152 x view ulong 20544 b ulong to long |
| 587 | pl = get x add b 7 |
| 588 | if eq pl 176 |
| 589 | ret -3 |
| 590 | end |
| 591 | if ne pl 178 |
| 592 | ret -2 |
| 593 | end |
| 594 | res = or shl plb w x b 0 8 plb w x b 1 |
| 595 | if eq res 0 |
| 596 | ret -4 |
| 597 | end |
| 598 | prm = or shl plb w x b 48 8 plb w x b 49 |
| 599 | if gt prm 128 |
| 600 | ret -5 |
| 601 | end |
| 602 | for i ulong 128 |
| 603 | if ge i prm |
| 604 | if ne plb w x b add 50 i 0 |
| 605 | ret -6 |
| 606 | end |
| 607 | end |
| 608 | end |
| 609 | ret 0 |
| 610 | end |
| 611 | |
| 612 | note omega_compute_semantic_id: sha256 of the canonical encoding in a 4096-byte buffer; a longer |
| 613 | note encoding leaves has_id 0 and the id zero |
| 614 | fn semid w view uchar 2097152 x edit ulong 20544 j ulong to void |
| 615 | cb = new uchar 4096 0 |
| 616 | n = ccanon w view x j cb |
| 617 | if lt n 0 |
| 618 | ret |
| 619 | end |
| 620 | d = new ulong 4 0 |
| 621 | sha4k cb ulong n d |
| 622 | b = ob j |
| 623 | put x add b 9 1 |
| 624 | for i ulong 4 |
| 625 | put x add add b 10 i get d i |
| 626 | end |
| 627 | end |
| 628 | |
| 629 | fn dobj w view uchar 2097152 x edit ulong 20544 j ulong cs ulong cl ulong to long |
| 630 | b = ob j |
| 631 | put x 0 add j 1 |
| 632 | c2 = cap2 cs cl |
| 633 | if lt c2 6 |
| 634 | ret -2 |
| 635 | end |
| 636 | if or ne get w cs 79 ne get w add cs 1 77 |
| 637 | ret -1 |
| 638 | end |
| 639 | if or ne get w add cs 2 71 ne get w add cs 3 48 |
| 640 | ret -1 |
| 641 | end |
| 642 | k = ulong get w add cs 5 |
| 643 | if ne cchkhdr ulong get w add cs 4 k 0 |
| 644 | ret -1 |
| 645 | end |
| 646 | put x b cs |
| 647 | put x add b 1 cl |
| 648 | put x add b 2 k |
| 649 | r = dattrs w x b cs cl |
| 650 | if lt r 0 |
| 651 | ret r |
| 652 | end |
| 653 | r = drels w x b cs cl ulong r |
| 654 | if lt r 0 |
| 655 | ret r |
| 656 | end |
| 657 | r = dconsts w x b cs cl ulong r |
| 658 | if lt r 0 |
| 659 | ret r |
| 660 | end |
| 661 | r = dpay w x b cs cl ulong r |
| 662 | if lt r 0 |
| 663 | ret r |
| 664 | end |
| 665 | if eq k 8 |
| 666 | if ne effchk w view x b 0 |
| 667 | ret -1 |
| 668 | end |
| 669 | end |
| 670 | semid w x j |
| 671 | ret 0 |
| 672 | end |
| 673 | |
| 674 | fn cdecode w view uchar 2097152 n ulong x edit ulong 20544 to long |
| 675 | if lt n 6 |
| 676 | ret -1 |
| 677 | end |
| 678 | if or ne get w 0 79 ne get w 1 77 |
| 679 | ret -1 |
| 680 | end |
| 681 | if or ne get w 2 71 ne get w 3 71 |
| 682 | ret -1 |
| 683 | end |
| 684 | cnt = be16 w 4 |
| 685 | if gt cnt 256 |
| 686 | ret -1 |
| 687 | end |
| 688 | for i ulong 20544 |
| 689 | put x i 0 |
| 690 | end |
| 691 | pos = ulong 6 |
| 692 | for i ulong cnt |
| 693 | if gt add pos 4 n |
| 694 | ret -1 |
| 695 | end |
| 696 | if gt add pos 4 2097152 |
| 697 | ret -2 |
| 698 | end |
| 699 | cl = be32 w pos |
| 700 | pos = add pos 4 |
| 701 | if or gt add pos cl n lt cl 6 |
| 702 | ret -1 |
| 703 | end |
| 704 | r = dobj w x i pos cl |
| 705 | if ne r 0 |
| 706 | ret r |
| 707 | end |
| 708 | pos = add pos cl |
| 709 | end |
| 710 | ret 0 |
| 711 | end |
| 712 | |
| 713 | note ---- canonical encoding (omega_canonical_encode) ---- |
| 714 | |
| 715 | note strlen of attribute key at offset o, klen bytes stored (the C key ends at its first NUL) |
| 716 | fn ekl w view uchar 2097152 o ulong kl ulong to ulong |
| 717 | for i ulong kl |
| 718 | if eq get w add o i 0 |
| 719 | ret i |
| 720 | end |
| 721 | end |
| 722 | ret kl |
| 723 | end |
| 724 | |
| 725 | fn canlen w view uchar 2097152 x view ulong 20544 b ulong to ulong |
| 726 | n = ulong 8 |
| 727 | na = get x add b 3 |
| 728 | for a ulong na |
| 729 | o = get x add add b 14 a |
| 730 | kl = ulong get w sub o 1 |
| 731 | n = add n add add 3 ekl w o kl be16 w add o kl |
| 732 | end |
| 733 | n = add n add 4 mul 34 get x add b 4 |
| 734 | nc = get x add b 6 |
| 735 | for c ulong nc |
| 736 | o = get x add add b 46 c |
| 737 | n = add n add 4 be16 w add o 2 |
| 738 | end |
| 739 | ret add n add 4 get x add b 7 |
| 740 | end |
| 741 | |
| 742 | note strcmp sign of attribute keys i and j (unsigned bytes; a key ends at klen or its first NUL) |
| 743 | fn acmp w view uchar 2097152 x view ulong 20544 b ulong i ulong j ulong to long |
| 744 | oi = get x add add b 14 i |
| 745 | oj = get x add add b 14 j |
| 746 | ki = ulong get w sub oi 1 |
| 747 | kj = ulong get w sub oj 1 |
| 748 | for t ulong 65 |
| 749 | ci = ulong 0 |
| 750 | if lt t ki |
| 751 | ci = ulong get w add oi t |
| 752 | end |
| 753 | cj = ulong 0 |
| 754 | if lt t kj |
| 755 | cj = ulong get w add oj t |
| 756 | end |
| 757 | if lt ci cj |
| 758 | ret -1 |
| 759 | end |
| 760 | if gt ci cj |
| 761 | ret 1 |
| 762 | end |
| 763 | if eq ci 0 |
| 764 | ret 0 |
| 765 | end |
| 766 | end |
| 767 | ret 0 |
| 768 | end |
| 769 | |
| 770 | fn memcmpw w view uchar 2097152 a ulong c ulong n ulong to long |
| 771 | for i ulong n |
| 772 | p = ulong get w add a i |
| 773 | q = ulong get w add c i |
| 774 | if lt p q |
| 775 | ret -1 |
| 776 | end |
| 777 | if gt p q |
| 778 | ret 1 |
| 779 | end |
| 780 | end |
| 781 | ret 0 |
| 782 | end |
| 783 | |
| 784 | fn rcmp w view uchar 2097152 x view ulong 20544 b ulong i ulong j ulong to long |
| 785 | rb = get x add b 5 |
| 786 | oi = add rb mul i 34 |
| 787 | oj = add rb mul j 34 |
| 788 | ki = be16 w oi |
| 789 | kj = be16 w oj |
| 790 | if lt ki kj |
| 791 | ret -1 |
| 792 | end |
| 793 | if gt ki kj |
| 794 | ret 1 |
| 795 | end |
| 796 | ret memcmpw w add oi 2 add oj 2 32 |
| 797 | end |
| 798 | |
| 799 | fn ccmp w view uchar 2097152 x view ulong 20544 b ulong i ulong j ulong to long |
| 800 | oi = get x add add b 46 i |
| 801 | oj = get x add add b 46 j |
| 802 | ki = be16 w oi |
| 803 | kj = be16 w oj |
| 804 | if lt ki kj |
| 805 | ret -1 |
| 806 | end |
| 807 | if gt ki kj |
| 808 | ret 1 |
| 809 | end |
| 810 | li = be16 w add oi 2 |
| 811 | lj = be16 w add oj 2 |
| 812 | m = li |
| 813 | if lt lj li |
| 814 | m = lj |
| 815 | end |
| 816 | r = memcmpw w add oi 4 add oj 4 m |
| 817 | if ne r 0 |
| 818 | ret r |
| 819 | end |
| 820 | if lt li lj |
| 821 | ret -1 |
| 822 | end |
| 823 | if gt li lj |
| 824 | ret 1 |
| 825 | end |
| 826 | ret 0 |
| 827 | end |
| 828 | |
| 829 | note the C's insertion sorts (stable): kind 0 attributes (strcmp), 1 relations, 2 constraints |
| 830 | fn cmpk w view uchar 2097152 x view ulong 20544 b ulong t ulong i ulong j ulong to long |
| 831 | if eq t 0 |
| 832 | ret acmp w x b i j |
| 833 | end |
| 834 | if eq t 1 |
| 835 | ret rcmp w x b i j |
| 836 | end |
| 837 | ret ccmp w x b i j |
| 838 | end |
| 839 | |
| 840 | fn isort w view uchar 2097152 x view ulong 20544 b ulong t ulong ix edit ulong 64 n ulong to void |
| 841 | for i ulong n |
| 842 | put ix i i |
| 843 | end |
| 844 | for u ulong n |
| 845 | if gt u 0 |
| 846 | key = get ix u |
| 847 | j = sub long u 1 |
| 848 | while ge j 0 bound 64 |
| 849 | if le cmpk w x b t get ix j key 0 |
| 850 | break |
| 851 | end |
| 852 | put ix add j 1 get ix j |
| 853 | j = sub j 1 |
| 854 | end |
| 855 | put ix add j 1 key |
| 856 | end |
| 857 | end |
| 858 | end |
| 859 | |
| 860 | fn put16 cb edit uchar 4096 p ulong v ulong to ulong |
| 861 | put cb p uchar shr v 8 |
| 862 | put cb add p 1 uchar and v 255 |
| 863 | ret add p 2 |
| 864 | end |
| 865 | |
| 866 | note copy n wire bytes from o to cb at p; returns p + n |
| 867 | fn wcopy w view uchar 2097152 cb edit uchar 4096 p ulong o ulong n ulong to ulong |
| 868 | for t ulong n |
| 869 | put cb add p t get w add o t |
| 870 | end |
| 871 | ret add p n |
| 872 | end |
| 873 | |
| 874 | fn canone w view uchar 2097152 x view ulong 20544 b ulong cb edit uchar 4096 p ulong a ulong to ulong |
| 875 | o = get x add add b 14 a |
| 876 | kl = ulong get w sub o 1 |
| 877 | ek = ekl w o kl |
| 878 | put cb p uchar ek |
| 879 | p = wcopy w cb add p 1 o ek |
| 880 | vl = be16 w add o kl |
| 881 | p = put16 cb p vl |
| 882 | ret wcopy w cb p add add o kl 2 vl |
| 883 | end |
| 884 | |
| 885 | fn canattr w view uchar 2097152 x view ulong 20544 b ulong cb edit uchar 4096 p ulong to ulong |
| 886 | ix = new ulong 64 0 |
| 887 | na = get x add b 3 |
| 888 | isort w x b 0 ix na |
| 889 | p = put16 cb p na |
| 890 | for i ulong na |
| 891 | p = canone w x b cb p get ix i |
| 892 | end |
| 893 | ret p |
| 894 | end |
| 895 | |
| 896 | fn canrel w view uchar 2097152 x view ulong 20544 b ulong cb edit uchar 4096 p ulong to ulong |
| 897 | ix = new ulong 64 0 |
| 898 | nr = get x add b 4 |
| 899 | isort w x b 1 ix nr |
| 900 | p = put16 cb p nr |
| 901 | rb = get x add b 5 |
| 902 | for i ulong nr |
| 903 | p = wcopy w cb p add rb mul get ix i 34 34 |
| 904 | end |
| 905 | ret p |
| 906 | end |
| 907 | |
| 908 | fn cancon w view uchar 2097152 x view ulong 20544 b ulong cb edit uchar 4096 p ulong to ulong |
| 909 | ix = new ulong 64 0 |
| 910 | nc = get x add b 6 |
| 911 | isort w x b 2 ix nc |
| 912 | p = put16 cb p nc |
| 913 | for i ulong nc |
| 914 | o = get x add add b 46 get ix i |
| 915 | p = wcopy w cb p o add 4 be16 w add o 2 |
| 916 | end |
| 917 | ret p |
| 918 | end |
| 919 | |
| 920 | fn ccanon w view uchar 2097152 x view ulong 20544 j ulong cb edit uchar 4096 to long |
| 921 | b = ob j |
| 922 | n = canlen w x b |
| 923 | if gt n 4096 |
| 924 | ret -1 |
| 925 | end |
| 926 | k = get x add b 2 |
| 927 | put cb 0 79 |
| 928 | put cb 1 77 |
| 929 | put cb 2 71 |
| 930 | put cb 3 48 |
| 931 | put cb 4 uchar cobjver k |
| 932 | put cb 5 uchar k |
| 933 | p = canattr w x b cb 6 |
| 934 | p = canrel w x b cb p |
| 935 | p = cancon w x b cb p |
| 936 | pl = get x add b 7 |
| 937 | p = put16 cb p shr pl 16 |
| 938 | p = put16 cb p and pl 65535 |
| 939 | ret long wcopy w cb p get x add b 8 pl |
| 940 | end |
| 941 | |
| 942 | note ---- serialize (omega_graph_serialize_binary) ---- |
| 943 | |
| 944 | note one record: u32 big-endian length, then the canonical bytes; returns the new position |
| 945 | fn serone o edit uchar 1049606 pos ulong cb view uchar 4096 n ulong to ulong |
| 946 | for t ulong 4 |
| 947 | sh = mul sub 3 t 8 |
| 948 | put o add pos t uchar and shr n sh 255 |
| 949 | end |
| 950 | p = add pos 4 |
| 951 | for t ulong n |
| 952 | put o add p t get cb t |
| 953 | end |
| 954 | ret add p n |
| 955 | end |
| 956 | |
| 957 | fn cserial w view uchar 2097152 x view ulong 20544 mx ulong o edit uchar 1049606 to long |
| 958 | if gt 6 mx |
| 959 | ret -1 |
| 960 | end |
| 961 | put o 0 79 |
| 962 | put o 1 77 |
| 963 | put o 2 71 |
| 964 | put o 3 71 |
| 965 | cnt = get x 0 |
| 966 | put o 4 uchar shr cnt 8 |
| 967 | put o 5 uchar and cnt 255 |
| 968 | pos = ulong 6 |
| 969 | cb = new uchar 4096 0 |
| 970 | for i ulong cnt |
| 971 | n = ccanon w x i cb |
| 972 | if lt n 0 |
| 973 | ret -1 |
| 974 | end |
| 975 | L = ulong n |
| 976 | if gt add add pos 4 L mx |
| 977 | ret -1 |
| 978 | end |
| 979 | pos = serone o pos cb L |
| 980 | end |
| 981 | ret long pos |
| 982 | end |
| 983 | |
| 984 | note ---- message and line texts (each note quotes the bytes it writes) ---- |
| 985 | |
| 986 | note "Invalid semantic kind tag 0x" |
| 987 | fn mkind l edit uchar 256 p ulong to ulong |
| 988 | p = sput l p 2334106421097295433 8 |
| 989 | p = sput l p 7163384699739268467 8 |
| 990 | p = sput l p 7022273334698666784 8 |
| 991 | p = sput l p 2016419943 4 |
| 992 | ret p |
| 993 | end |
| 994 | |
| 995 | note "Empty attribute key at index " |
| 996 | fn mattr l edit uchar 256 p ulong to ulong |
| 997 | p = sput l p 8386019687157230917 8 |
| 998 | p = sput l p 2334400029372543604 8 |
| 999 | p = sput l p 7575182533742650731 8 |
| 1000 | p = sput l p 139458864238 5 |
| 1001 | ret p |
| 1002 | end |
| 1003 | |
| 1004 | note "Invalid relation kind 0x" |
| 1005 | fn mrelk l edit uchar 256 p ulong to ulong |
| 1006 | p = sput l p 2334106421097295433 8 |
| 1007 | p = sput l p 7957695015158572402 8 |
| 1008 | p = sput l p 8660457699154684704 8 |
| 1009 | ret p |
| 1010 | end |
| 1011 | |
| 1012 | note " at index " |
| 1013 | fn matidx l edit uchar 256 p ulong to ulong |
| 1014 | p = sput l p 7306085893296906528 8 |
| 1015 | p = sput l p 8312 2 |
| 1016 | ret p |
| 1017 | end |
| 1018 | |
| 1019 | note "Dangling relation target reference " |
| 1020 | fn mdang l edit uchar 256 p ulong to ulong |
| 1021 | p = sput l p 7453010347657421124 8 |
| 1022 | p = sput l p 8028075772543857184 8 |
| 1023 | p = sput l p 8387223622006349934 8 |
| 1024 | p = sput l p 7954890096655036960 8 |
| 1025 | p = sput l p 2123107 3 |
| 1026 | ret p |
| 1027 | end |
| 1028 | |
| 1029 | note "Invalid constraint kind 0x" |
| 1030 | fn mconk l edit uchar 256 p ulong to ulong |
| 1031 | p = sput l p 2334106421097295433 8 |
| 1032 | p = sput l p 7593476291201757027 8 |
| 1033 | p = sput l p 2334111905932670062 8 |
| 1034 | p = sput l p 30768 2 |
| 1035 | ret p |
| 1036 | end |
| 1037 | |
| 1038 | note "Type payload length too short (" |
| 1039 | fn mtshort l edit uchar 256 p ulong to ulong |
| 1040 | p = sput l p 8746395235773348180 8 |
| 1041 | p = sput l p 7954883203198709612 8 |
| 1042 | p = sput l p 2337209276179182695 8 |
| 1043 | p = sput l p 11294683576625267 7 |
| 1044 | ret p |
| 1045 | end |
| 1046 | |
| 1047 | note " bytes)" |
| 1048 | fn mbytes l edit uchar 256 p ulong to ulong |
| 1049 | p = sput l p 11667353628140064 7 |
| 1050 | ret p |
| 1051 | end |
| 1052 | |
| 1053 | note "Invalid type tag 0x" |
| 1054 | fn mtag l edit uchar 256 p ulong to ulong |
| 1055 | p = sput l p 2334106421097295433 8 |
| 1056 | p = sput l p 7449362941137156468 8 |
| 1057 | p = sput l p 7876640 3 |
| 1058 | ret p |
| 1059 | end |
| 1060 | |
| 1061 | note "Unsigned integer width " |
| 1062 | fn muint l edit uchar 256 p ulong to ulong |
| 1063 | p = sput l p 7234309766870429269 8 |
| 1064 | p = sput l p 8243108378414311712 8 |
| 1065 | p = sput l p 9122048364869408 7 |
| 1066 | ret p |
| 1067 | end |
| 1068 | |
| 1069 | note " out of bounds [1..256]" |
| 1070 | fn mob1 l edit uchar 256 p ulong to ulong |
| 1071 | p = sput l p 2334675642021670688 8 |
| 1072 | p = sput l p 6566375131893296994 8 |
| 1073 | p = sput l p 26236774937144881 7 |
| 1074 | ret p |
| 1075 | end |
| 1076 | |
| 1077 | note "Signed integer width " |
| 1078 | fn msint l edit uchar 256 p ulong to ulong |
| 1079 | p = sput l p 7575164960043919699 8 |
| 1080 | p = sput l p 8583986669620130926 8 |
| 1081 | p = sput l p 139191411817 5 |
| 1082 | ret p |
| 1083 | end |
| 1084 | |
| 1085 | note " out of bounds [2..256]" |
| 1086 | fn mob2 l edit uchar 256 p ulong to ulong |
| 1087 | p = sput l p 2334675642021670688 8 |
| 1088 | p = sput l p 6566375131893296994 8 |
| 1089 | p = sput l p 26236774937144882 7 |
| 1090 | ret p |
| 1091 | end |
| 1092 | |
| 1093 | note "FP32 width " |
| 1094 | fn mfp32 l edit uchar 256 p ulong to ulong |
| 1095 | p = sput l p 7235445256512294982 8 |
| 1096 | p = sput l p 2123892 3 |
| 1097 | ret p |
| 1098 | end |
| 1099 | |
| 1100 | note " is not 32" |
| 1101 | fn mnot32 l edit uchar 256 p ulong to ulong |
| 1102 | p = sput l p 2338616625293650208 8 |
| 1103 | p = sput l p 12851 2 |
| 1104 | ret p |
| 1105 | end |
| 1106 | |
| 1107 | note "Bitvector width " |
| 1108 | fn mbitv l edit uchar 256 p ulong to ulong |
| 1109 | p = sput l p 8031153322938624322 8 |
| 1110 | p = sput l p 2335244381406568562 8 |
| 1111 | ret p |
| 1112 | end |
| 1113 | |
| 1114 | note "Sequence length " |
| 1115 | fn mseql l edit uchar 256 p ulong to ulong |
| 1116 | p = sput l p 7305804402566194515 8 |
| 1117 | p = sput l p 2335244394374196256 8 |
| 1118 | ret p |
| 1119 | end |
| 1120 | |
| 1121 | note " exceeds 65535" |
| 1122 | fn mexc l edit uchar 256 p ulong to ulong |
| 1123 | p = sput l p 8314882298167715104 8 |
| 1124 | p = sput l p 58494052283936 6 |
| 1125 | ret p |
| 1126 | end |
| 1127 | |
| 1128 | note "Sequence element type unresolved or not KIND_TYPE" |
| 1129 | fn mseqe l edit uchar 256 p ulong to ulong |
| 1130 | p = sput l p 7305804402566194515 8 |
| 1131 | p = sput l p 8389754676365255968 8 |
| 1132 | p = sput l p 7959303536498013216 8 |
| 1133 | p = sput l p 7234318584538948978 8 |
| 1134 | p = sput l p 2338616625293586208 8 |
| 1135 | p = sput l p 5789751564106090827 8 |
| 1136 | p = sput l p 69 1 |
| 1137 | ret p |
| 1138 | end |
| 1139 | |
| 1140 | note "Value payload length too short (" |
| 1141 | fn mvshort l edit uchar 256 p ulong to ulong |
| 1142 | p = sput l p 7021147439204426070 8 |
| 1143 | p = sput l p 7308251910818983033 8 |
| 1144 | p = sput l p 8029764343165118318 8 |
| 1145 | p = sput l p 2891438995616068384 8 |
| 1146 | ret p |
| 1147 | end |
| 1148 | |
| 1149 | note "Value type_id unresolved or not KIND_TYPE" |
| 1150 | fn mvtype l edit uchar 256 p ulong to ulong |
| 1151 | p = sput l p 8751655596021539158 8 |
| 1152 | p = sput l p 7959303532083897712 8 |
| 1153 | p = sput l p 7234318584538948978 8 |
| 1154 | p = sput l p 2338616625293586208 8 |
| 1155 | p = sput l p 5789751564106090827 8 |
| 1156 | p = sput l p 69 1 |
| 1157 | ret p |
| 1158 | end |
| 1159 | |
| 1160 | note "Value byte length " |
| 1161 | fn mvlen1 l edit uchar 256 p ulong to ulong |
| 1162 | p = sput l p 8746589046440747350 8 |
| 1163 | p = sput l p 8387794212885652852 8 |
| 1164 | p = sput l p 8296 2 |
| 1165 | ret p |
| 1166 | end |
| 1167 | |
| 1168 | note " does not match declared type width " |
| 1169 | fn mvlen2 l edit uchar 256 p ulong to ulong |
| 1170 | p = sput l p 8029390865643299872 8 |
| 1171 | p = sput l p 2335225758293500020 8 |
| 1172 | p = sput l p 7234314139196417380 8 |
| 1173 | p = sput l p 7599578516261794848 8 |
| 1174 | p = sput l p 543716452 4 |
| 1175 | ret p |
| 1176 | end |
| 1177 | |
| 1178 | note " (expected " |
| 1179 | fn mvlen3 l edit uchar 256 p ulong to ulong |
| 1180 | p = sput l p 8386658464824633376 8 |
| 1181 | p = sput l p 2122853 3 |
| 1182 | ret p |
| 1183 | end |
| 1184 | |
| 1185 | note "Invalid opcode 0x" |
| 1186 | fn mopc l edit uchar 256 p ulong to ulong |
| 1187 | p = sput l p 2334106421097295433 8 |
| 1188 | p = sput l p 3467883195115204719 8 |
| 1189 | p = sput l p 120 1 |
| 1190 | ret p |
| 1191 | end |
| 1192 | |
| 1193 | note "Operation overflow policy not explicitly declared" |
| 1194 | fn movf l edit uchar 256 p ulong to ulong |
| 1195 | p = sput l p 8028075772644520015 8 |
| 1196 | p = sput l p 7811056383824961646 8 |
| 1197 | p = sput l p 7163375908187830127 8 |
| 1198 | p = sput l p 8675375941656911993 8 |
| 1199 | p = sput l p 8749496172062272624 8 |
| 1200 | p = sput l p 7310012263327687712 8 |
| 1201 | p = sput l p 100 1 |
| 1202 | ret p |
| 1203 | end |
| 1204 | |
| 1205 | note "Apply op_id unresolved or not KIND_OPERATION" |
| 1206 | fn mapop l edit uchar 256 p ulong to ulong |
| 1207 | p = sput l p 8101729960545251393 8 |
| 1208 | p = sput l p 7310026594509416799 8 |
| 1209 | p = sput l p 8007510524406034291 8 |
| 1210 | p = sput l p 5281350672479821938 8 |
| 1211 | p = sput l p 4706900771786933326 8 |
| 1212 | p = sput l p 1313818964 4 |
| 1213 | ret p |
| 1214 | end |
| 1215 | |
| 1216 | note "Apply operand " |
| 1217 | fn maparg l edit uchar 256 p ulong to ulong |
| 1218 | p = sput l p 8101729960545251393 8 |
| 1219 | p = sput l p 35615720698469 6 |
| 1220 | ret p |
| 1221 | end |
| 1222 | |
| 1223 | note " unresolved or invalid kind" |
| 1224 | fn maparg2 l edit uchar 256 p ulong to ulong |
| 1225 | p = sput l p 7813590758059832608 8 |
| 1226 | p = sput l p 7575180394847561078 8 |
| 1227 | p = sput l p 7719280165265700462 8 |
| 1228 | p = sput l p 6581865 3 |
| 1229 | ret p |
| 1230 | end |
| 1231 | |
| 1232 | note "Effect payload refused: " |
| 1233 | fn meff l edit uchar 256 p ulong to ulong |
| 1234 | p = sput l p 8079585701754463813 8 |
| 1235 | p = sput l p 8223683289222510945 8 |
| 1236 | p = sput l p 2322278944754460261 8 |
| 1237 | ret p |
| 1238 | end |
| 1239 | |
| 1240 | note " (" |
| 1241 | fn mparen l edit uchar 256 p ulong to ulong |
| 1242 | p = sput l p 10272 2 |
| 1243 | ret p |
| 1244 | end |
| 1245 | |
| 1246 | note "effect payload length is not 178 bytes" |
| 1247 | fn mefflen l edit uchar 256 p ulong to ulong |
| 1248 | p = sput l p 8079585701754463845 8 |
| 1249 | p = sput l p 7791337724994943329 8 |
| 1250 | p = sput l p 8316213819917954661 8 |
| 1251 | p = sput l p 4050760405305224736 8 |
| 1252 | p = sput l p 126879583003168 6 |
| 1253 | ret p |
| 1254 | end |
| 1255 | |
| 1256 | note "legacy v1 effect payload (32-bit generation) refused" |
| 1257 | fn meffv1 l edit uchar 256 p ulong to ulong |
| 1258 | p = sput l p 8511936763473126764 8 |
| 1259 | p = sput l p 8386658421572968497 8 |
| 1260 | p = sput l p 7233184988217307168 8 |
| 1261 | p = sput l p 8388343727209523232 8 |
| 1262 | p = sput l p 8386109761109976864 8 |
| 1263 | p = sput l p 7378429046976049001 8 |
| 1264 | p = sput l p 1684370293 4 |
| 1265 | ret p |
| 1266 | end |
| 1267 | |
| 1268 | note "effect resource class is 0 (invalid resource)" |
| 1269 | fn meffres l edit uchar 256 p ulong to ulong |
| 1270 | p = sput l p 8223700889830319717 8 |
| 1271 | p = sput l p 2334381325109130085 8 |
| 1272 | p = sput l p 8316213867145423971 8 |
| 1273 | p = sput l p 7022922066854686752 8 |
| 1274 | p = sput l p 8030874101375854956 8 |
| 1275 | p = sput l p 177794675317 5 |
| 1276 | ret p |
| 1277 | end |
| 1278 | |
| 1279 | note "effect param_len exceeds 128" |
| 1280 | fn meffprm l edit uchar 256 p ulong to ulong |
| 1281 | p = sput l p 8079585701754463845 8 |
| 1282 | p = sput l p 7954883473932644961 8 |
| 1283 | p = sput l p 8314882298167715104 8 |
| 1284 | p = sput l p 942813472 4 |
| 1285 | ret p |
| 1286 | end |
| 1287 | |
| 1288 | note "effect parameter padding is not zero" |
| 1289 | fn meffpad l edit uchar 256 p ulong to ulong |
| 1290 | p = sput l p 8079585701754463845 8 |
| 1291 | p = sput l p 8243122671947182689 8 |
| 1292 | p = sput l p 7453010313246502944 8 |
| 1293 | p = sput l p 2338616625293650208 8 |
| 1294 | p = sput l p 1869768058 4 |
| 1295 | ret p |
| 1296 | end |
| 1297 | |
| 1298 | note "unknown effect error" |
| 1299 | fn meffunk l edit uchar 256 p ulong to ulong |
| 1300 | p = sput l p 2336936577129475701 8 |
| 1301 | p = sput l p 7286952167337256549 8 |
| 1302 | p = sput l p 1919906418 4 |
| 1303 | ret p |
| 1304 | end |
| 1305 | |
| 1306 | note "Empty graph (0 objects)" |
| 1307 | fn mempty l edit uchar 256 p ulong to ulong |
| 1308 | p = sput l p 8243593348941638981 8 |
| 1309 | p = sput l p 8007453086365282401 8 |
| 1310 | p = sput l p 11667417766128226 7 |
| 1311 | ret p |
| 1312 | end |
| 1313 | |
| 1314 | note "Structural cycle detected involving " |
| 1315 | fn mcyc l edit uchar 256 p ulong to ulong |
| 1316 | p = sput l p 8247626263119950931 8 |
| 1317 | p = sput l p 7308325668320734305 8 |
| 1318 | p = sput l p 7310577382524806176 8 |
| 1319 | p = sput l p 8533317948409454692 8 |
| 1320 | p = sput l p 543649385 4 |
| 1321 | ret p |
| 1322 | end |
| 1323 | |
| 1324 | note "relation target at object index " |
| 1325 | fn mcycr l edit uchar 256 p ulong to ulong |
| 1326 | p = sput l p 7957695015158572402 8 |
| 1327 | p = sput l p 2338605601487156256 8 |
| 1328 | p = sput l p 7162247753406379105 8 |
| 1329 | p = sput l p 2339731488442490996 8 |
| 1330 | ret p |
| 1331 | end |
| 1332 | |
| 1333 | note "operand target at object index " |
| 1334 | fn mcyco l edit uchar 256 p ulong to ulong |
| 1335 | p = sput l p 2334111871694893167 8 |
| 1336 | p = sput l p 6998721799809818996 8 |
| 1337 | p = sput l p 8386658438686384244 8 |
| 1338 | p = sput l p 9139576126728480 7 |
| 1339 | ret p |
| 1340 | end |
| 1341 | |
| 1342 | note "// OMEGA NON-CANONICAL TEXTUAL FORM\n// Objects: " |
| 1343 | fn fhead1 l edit uchar 256 p ulong to ulong |
| 1344 | p = sput l p 4703804534154080047 8 |
| 1345 | p = sput l p 5638862070310981152 8 |
| 1346 | p = sput l p 6061928941626150479 8 |
| 1347 | p = sput l p 5053122625397872709 8 |
| 1348 | p = sput l p 5701609007333855823 8 |
| 1349 | p = sput l p 2322295501583903330 8 |
| 1350 | ret p |
| 1351 | end |
| 1352 | |
| 1353 | note "\n\n" |
| 1354 | fn fnl2 l edit uchar 256 p ulong to ulong |
| 1355 | p = sput l p 2570 2 |
| 1356 | ret p |
| 1357 | end |
| 1358 | |
| 1359 | note "; // id=" |
| 1360 | fn fidsuf l edit uchar 256 p ulong to ulong |
| 1361 | p = sput l p 4423776320936157243 8 |
| 1362 | ret p |
| 1363 | end |
| 1364 | |
| 1365 | note "type U" |
| 1366 | fn ftypu l edit uchar 256 p ulong to ulong |
| 1367 | p = sput l p 93597629184372 6 |
| 1368 | ret p |
| 1369 | end |
| 1370 | |
| 1371 | note " = UNSIGNED_INTEGER(" |
| 1372 | fn ftypu2 l edit uchar 256 p ulong to ulong |
| 1373 | p = sput l p 5136728445893492000 8 |
| 1374 | p = sput l p 4995703963698611534 8 |
| 1375 | p = sput l p 676480327 4 |
| 1376 | ret p |
| 1377 | end |
| 1378 | |
| 1379 | note ")" |
| 1380 | fn fparsc l edit uchar 256 p ulong to ulong |
| 1381 | p = sput l p 41 1 |
| 1382 | ret p |
| 1383 | end |
| 1384 | |
| 1385 | note "type Bool = BOOL" |
| 1386 | fn ftbool l edit uchar 256 p ulong to ulong |
| 1387 | p = sput l p 8029709367533140340 8 |
| 1388 | p = sput l p 5498700815469977708 8 |
| 1389 | ret p |
| 1390 | end |
| 1391 | |
| 1392 | note "type Tag" |
| 1393 | fn ftag l edit uchar 256 p ulong to ulong |
| 1394 | p = sput l p 7449327756765067636 8 |
| 1395 | ret p |
| 1396 | end |
| 1397 | |
| 1398 | note "val v_" |
| 1399 | fn fval l edit uchar 256 p ulong to ulong |
| 1400 | p = sput l p 104960954753398 6 |
| 1401 | ret p |
| 1402 | end |
| 1403 | |
| 1404 | note " = " |
| 1405 | fn feq l edit uchar 256 p ulong to ulong |
| 1406 | p = sput l p 2112800 3 |
| 1407 | ret p |
| 1408 | end |
| 1409 | |
| 1410 | note "op " |
| 1411 | fn fop l edit uchar 256 p ulong to ulong |
| 1412 | p = sput l p 2125935 3 |
| 1413 | ret p |
| 1414 | end |
| 1415 | |
| 1416 | note "[WRAP]" |
| 1417 | fn fwrap l edit uchar 256 p ulong to ulong |
| 1418 | p = sput l p 102599274682203 6 |
| 1419 | ret p |
| 1420 | end |
| 1421 | |
| 1422 | note "apply app_" |
| 1423 | fn fapply l edit uchar 256 p ulong to ulong |
| 1424 | p = sput l p 8097789310871302241 8 |
| 1425 | p = sput l p 24432 2 |
| 1426 | ret p |
| 1427 | end |
| 1428 | |
| 1429 | note "object kind=" |
| 1430 | fn fobj l edit uchar 256 p ulong to ulong |
| 1431 | p = sput l p 7719297731565085295 8 |
| 1432 | p = sput l p 1029992041 4 |
| 1433 | ret p |
| 1434 | end |
| 1435 | |
| 1436 | note ---- text building in a 256-byte line (messages and format_text lines) ---- |
| 1437 | |
| 1438 | note k (<= 8) bytes of the little-endian packed word v at p; returns p + k |
| 1439 | fn sput l edit uchar 256 p ulong v ulong k ulong to ulong |
| 1440 | for i ulong k |
| 1441 | put l add p i uchar and shr v mul i 8 255 |
| 1442 | end |
| 1443 | ret add p k |
| 1444 | end |
| 1445 | |
| 1446 | fn sdec l edit uchar 256 p ulong v ulong to ulong |
| 1447 | d = new uchar 20 0 |
| 1448 | n = ulong 0 |
| 1449 | while true bound 21 |
| 1450 | put d n uchar add rem v 10 48 |
| 1451 | n = add n 1 |
| 1452 | v = div v 10 |
| 1453 | if eq v 0 |
| 1454 | break |
| 1455 | end |
| 1456 | end |
| 1457 | for i ulong n |
| 1458 | put l add p i get d sub sub n 1 i |
| 1459 | end |
| 1460 | ret add p n |
| 1461 | end |
| 1462 | |
| 1463 | fn hexdig v ulong to ulong |
| 1464 | if lt v 10 |
| 1465 | ret add v 48 |
| 1466 | end |
| 1467 | ret add v 87 |
| 1468 | end |
| 1469 | |
| 1470 | note %0<m>x |
| 1471 | fn shex l edit uchar 256 p ulong v ulong m ulong to ulong |
| 1472 | n = ulong 1 |
| 1473 | while lt n 16 bound 16 |
| 1474 | if eq shr v mul n 4 0 |
| 1475 | break |
| 1476 | end |
| 1477 | n = add n 1 |
| 1478 | end |
| 1479 | if lt n m |
| 1480 | n = m |
| 1481 | end |
| 1482 | for i ulong n |
| 1483 | sh = mul sub sub n 1 i 4 |
| 1484 | put l add p i uchar hexdig and shr v sh 15 |
| 1485 | end |
| 1486 | ret add p n |
| 1487 | end |
| 1488 | |
| 1489 | note 64 hex digits of the id of the object at X base b (zero when it has none) |
| 1490 | fn sid l edit uchar 256 p ulong x view ulong 20544 b ulong to ulong |
| 1491 | for i ulong 4 |
| 1492 | v = get x add add b 10 i |
| 1493 | for t ulong 16 |
| 1494 | sh = mul sub 15 t 4 |
| 1495 | put l add p t uchar hexdig and shr v sh 15 |
| 1496 | end |
| 1497 | p = add p 16 |
| 1498 | end |
| 1499 | ret p |
| 1500 | end |
| 1501 | |
| 1502 | note 64 hex digits of 32 wire bytes at o |
| 1503 | fn swhex l edit uchar 256 p ulong w view uchar 2097152 o ulong to ulong |
| 1504 | for i ulong 32 |
| 1505 | c = ulong get w add o i |
| 1506 | put l p uchar hexdig shr c 4 |
| 1507 | put l add p 1 uchar hexdig and c 15 |
| 1508 | p = add p 2 |
| 1509 | end |
| 1510 | ret p |
| 1511 | end |
| 1512 | |
| 1513 | fn snul l edit uchar 256 p ulong to void |
| 1514 | put l p 0 |
| 1515 | end |
| 1516 | |
| 1517 | note ---- validate (omega_validate_object / omega_validate_graph) ---- |
| 1518 | |
| 1519 | note find_object_by_id: the first object with has_id whose id is t; -1 when none |
| 1520 | fn findid x view ulong 20544 t0 ulong t1 ulong t2 ulong t3 ulong to long |
| 1521 | n = get x 0 |
| 1522 | for j ulong n |
| 1523 | b = ob j |
| 1524 | if eq get x add b 9 1 |
| 1525 | if eq get x add b 10 t0 |
| 1526 | if eq get x add b 11 t1 |
| 1527 | if eq get x add b 12 t2 |
| 1528 | if eq get x add b 13 t3 |
| 1529 | ret long j |
| 1530 | end |
| 1531 | end |
| 1532 | end |
| 1533 | end |
| 1534 | end |
| 1535 | end |
| 1536 | ret -1 |
| 1537 | end |
| 1538 | |
| 1539 | note find by the id stored in the payload of object j at byte p (C reads it through the payload struct) |
| 1540 | fn findp w view uchar 2097152 x view ulong 20544 j ulong p ulong to long |
| 1541 | t0 = pw64 w x j p |
| 1542 | t1 = pw64 w x j add p 8 |
| 1543 | t2 = pw64 w x j add p 16 |
| 1544 | t3 = pw64 w x j add p 24 |
| 1545 | ret findid x t0 t1 t2 t3 |
| 1546 | end |
| 1547 | |
| 1548 | fn findw w view uchar 2097152 x view ulong 20544 o ulong to long |
| 1549 | t0 = be64 w o |
| 1550 | t1 = be64 w add o 8 |
| 1551 | t2 = be64 w add o 16 |
| 1552 | t3 = be64 w add o 24 |
| 1553 | ret findid x t0 t1 t2 t3 |
| 1554 | end |
| 1555 | |
| 1556 | note kind of the found object; 256 when not found (and/or evaluate both sides, so callers test f < 0 |
| 1557 | note and the kind in one condition) |
| 1558 | fn kindof x view ulong 20544 f long to ulong |
| 1559 | if lt f 0 |
| 1560 | ret 256 |
| 1561 | end |
| 1562 | ret get x add ob ulong f 2 |
| 1563 | end |
| 1564 | |
| 1565 | fn vfail e edit uchar 256 p ulong to long |
| 1566 | snul e p |
| 1567 | ret -1 |
| 1568 | end |
| 1569 | |
| 1570 | fn vattr w view uchar 2097152 x view ulong 20544 b ulong e edit uchar 256 to long |
| 1571 | na = get x add b 3 |
| 1572 | for i ulong na |
| 1573 | o = get x add add b 14 i |
| 1574 | if eq ekl w o ulong get w sub o 1 0 |
| 1575 | p = mattr e 0 |
| 1576 | ret vfail e sdec e p i |
| 1577 | end |
| 1578 | end |
| 1579 | ret 0 |
| 1580 | end |
| 1581 | |
| 1582 | fn vrels w view uchar 2097152 x view ulong 20544 b ulong e edit uchar 256 to long |
| 1583 | nr = get x add b 4 |
| 1584 | for i ulong nr |
| 1585 | o = add get x add b 5 mul i 34 |
| 1586 | k = be16 w o |
| 1587 | if or eq k 0 gt k 9 |
| 1588 | p = mrelk e 0 |
| 1589 | p = shex e p k 4 |
| 1590 | p = matidx e p |
| 1591 | ret vfail e sdec e p i |
| 1592 | end |
| 1593 | if lt findw w x add o 2 0 |
| 1594 | p = mdang e 0 |
| 1595 | ret vfail e swhex e p w add o 2 |
| 1596 | end |
| 1597 | end |
| 1598 | ret 0 |
| 1599 | end |
| 1600 | |
| 1601 | fn vcons w view uchar 2097152 x view ulong 20544 b ulong e edit uchar 256 to long |
| 1602 | nc = get x add b 6 |
| 1603 | for i ulong nc |
| 1604 | k = be16 w get x add add b 46 i |
| 1605 | if or eq k 0 gt k 9 |
| 1606 | p = mconk e 0 |
| 1607 | p = shex e p k 4 |
| 1608 | p = matidx e p |
| 1609 | ret vfail e sdec e p i |
| 1610 | end |
| 1611 | end |
| 1612 | ret 0 |
| 1613 | end |
| 1614 | |
| 1615 | note "<pre>%u<post>" for a width message: 0 unsigned, 1 signed, 2 bitvector, 3 fp32, 4 sequence length |
| 1616 | fn vwmsg e edit uchar 256 t ulong v ulong to long |
| 1617 | p = ulong 0 |
| 1618 | if eq t 0 |
| 1619 | p = muint e 0 |
| 1620 | end |
| 1621 | if eq t 1 |
| 1622 | p = msint e 0 |
| 1623 | end |
| 1624 | if eq t 2 |
| 1625 | p = mbitv e 0 |
| 1626 | end |
| 1627 | if eq t 3 |
| 1628 | p = mfp32 e 0 |
| 1629 | end |
| 1630 | if eq t 4 |
| 1631 | p = mseql e 0 |
| 1632 | end |
| 1633 | p = sdec e p v |
| 1634 | if eq t 1 |
| 1635 | p = mob2 e p |
| 1636 | end |
| 1637 | if eq t 3 |
| 1638 | p = mnot32 e p |
| 1639 | end |
| 1640 | if eq t 4 |
| 1641 | p = mexc e p |
| 1642 | end |
| 1643 | if or eq t 0 eq t 2 |
| 1644 | p = mob1 e p |
| 1645 | end |
| 1646 | ret vfail e p |
| 1647 | end |
| 1648 | |
| 1649 | fn vtype w view uchar 2097152 x view ulong 20544 j ulong e edit uchar 256 to long |
| 1650 | b = ob j |
| 1651 | pl = get x add b 7 |
| 1652 | if lt pl 44 |
| 1653 | p = mtshort e 0 |
| 1654 | p = sdec e p pl |
| 1655 | ret vfail e mbytes e p |
| 1656 | end |
| 1657 | tag = pu32 w x b 0 |
| 1658 | if or eq tag 0 gt tag 14 |
| 1659 | p = mtag e 0 |
| 1660 | ret vfail e shex e p tag 2 |
| 1661 | end |
| 1662 | wd = pu16 w x b 4 |
| 1663 | if and eq tag 3 or lt wd 1 gt wd 256 |
| 1664 | ret vwmsg e 0 wd |
| 1665 | end |
| 1666 | if and eq tag 4 or lt wd 2 gt wd 256 |
| 1667 | ret vwmsg e 1 wd |
| 1668 | end |
| 1669 | if and eq tag 14 ne wd 32 |
| 1670 | ret vwmsg e 3 wd |
| 1671 | end |
| 1672 | if and eq tag 5 or lt wd 1 gt wd 256 |
| 1673 | ret vwmsg e 2 wd |
| 1674 | end |
| 1675 | if eq tag 7 |
| 1676 | ln = pu32 w x b 8 |
| 1677 | if gt ln 65535 |
| 1678 | ret vwmsg e 4 ln |
| 1679 | end |
| 1680 | f = findp w x j 12 |
| 1681 | if or lt f 0 ne kindof x f 2 |
| 1682 | p = mseqe e 0 |
| 1683 | ret vfail e p |
| 1684 | end |
| 1685 | end |
| 1686 | ret 0 |
| 1687 | end |
| 1688 | |
| 1689 | fn vvalue w view uchar 2097152 x view ulong 20544 j ulong e edit uchar 256 to long |
| 1690 | b = ob j |
| 1691 | pl = get x add b 7 |
| 1692 | if lt pl 98 |
| 1693 | p = mvshort e 0 |
| 1694 | p = sdec e p pl |
| 1695 | ret vfail e mbytes e p |
| 1696 | end |
| 1697 | f = findp w x j 0 |
| 1698 | if or lt f 0 ne kindof x f 2 |
| 1699 | p = mvtype e 0 |
| 1700 | ret vfail e p |
| 1701 | end |
| 1702 | tb = ob ulong f |
| 1703 | tag = pu32 w x tb 0 |
| 1704 | if or or eq tag 3 eq tag 4 eq tag 5 |
| 1705 | wd = pu16 w x tb 4 |
| 1706 | ex = div add wd 7 8 |
| 1707 | bl = pu16 w x b 32 |
| 1708 | if ne bl ex |
| 1709 | p = mvlen1 e 0 |
| 1710 | p = sdec e p bl |
| 1711 | p = mvlen2 e p |
| 1712 | p = sdec e p wd |
| 1713 | p = mvlen3 e p |
| 1714 | p = sdec e p ex |
| 1715 | ret vfail e mbytes e p |
| 1716 | end |
| 1717 | end |
| 1718 | ret 0 |
| 1719 | end |
| 1720 | |
| 1721 | fn voper w view uchar 2097152 x view ulong 20544 j ulong e edit uchar 256 to long |
| 1722 | b = ob j |
| 1723 | pl = get x add b 7 |
| 1724 | if ge pl 204 |
| 1725 | opc = pu32 w x b 0 |
| 1726 | if or eq opc 0 gt opc 16 |
| 1727 | p = mopc e 0 |
| 1728 | ret vfail e shex e p opc 2 |
| 1729 | end |
| 1730 | ov = pu32 w x b 4 |
| 1731 | if or eq ov 0 gt ov 3 |
| 1732 | p = movf e 0 |
| 1733 | ret vfail e p |
| 1734 | end |
| 1735 | ret 0 |
| 1736 | end |
| 1737 | if lt pl 161 |
| 1738 | ret 0 |
| 1739 | end |
| 1740 | f = findp w x j 0 |
| 1741 | if or lt f 0 ne kindof x f 3 |
| 1742 | p = mapop e 0 |
| 1743 | ret vfail e p |
| 1744 | end |
| 1745 | n = plb w x b 32 |
| 1746 | for i ulong n |
| 1747 | f = findp w x j add 33 mul i 32 |
| 1748 | if lt f 0 |
| 1749 | p = maparg e 0 |
| 1750 | p = sdec e p i |
| 1751 | ret vfail e maparg2 e p |
| 1752 | end |
| 1753 | k = kindof x f |
| 1754 | if and ne k 1 ne k 3 |
| 1755 | p = maparg e 0 |
| 1756 | p = sdec e p i |
| 1757 | ret vfail e maparg2 e p |
| 1758 | end |
| 1759 | end |
| 1760 | ret 0 |
| 1761 | end |
| 1762 | |
| 1763 | fn veff w view uchar 2097152 x view ulong 20544 j ulong e edit uchar 256 to long |
| 1764 | b = ob j |
| 1765 | r = effchk w x b |
| 1766 | if eq r 0 |
| 1767 | ret 0 |
| 1768 | end |
| 1769 | p = meff e 0 |
| 1770 | if eq r -2 |
| 1771 | p = mefflen e p |
| 1772 | end |
| 1773 | if eq r -3 |
| 1774 | p = meffv1 e p |
| 1775 | end |
| 1776 | if eq r -4 |
| 1777 | p = meffres e p |
| 1778 | end |
| 1779 | if eq r -5 |
| 1780 | p = meffprm e p |
| 1781 | end |
| 1782 | if eq r -6 |
| 1783 | p = meffpad e p |
| 1784 | end |
| 1785 | p = mparen e p |
| 1786 | p = sdec e p get x add b 7 |
| 1787 | ret vfail e mbytes e p |
| 1788 | end |
| 1789 | |
| 1790 | fn vobj w view uchar 2097152 x view ulong 20544 j ulong e edit uchar 256 to long |
| 1791 | b = ob j |
| 1792 | k = get x add b 2 |
| 1793 | if or eq k 0 gt k 11 |
| 1794 | p = mkind e 0 |
| 1795 | ret vfail e shex e p k 2 |
| 1796 | end |
| 1797 | r = vattr w x b e |
| 1798 | if ne r 0 |
| 1799 | ret r |
| 1800 | end |
| 1801 | r = vrels w x b e |
| 1802 | if ne r 0 |
| 1803 | ret r |
| 1804 | end |
| 1805 | r = vcons w x b e |
| 1806 | if ne r 0 |
| 1807 | ret r |
| 1808 | end |
| 1809 | if eq k 2 |
| 1810 | ret vtype w x j e |
| 1811 | end |
| 1812 | if eq k 1 |
| 1813 | ret vvalue w x j e |
| 1814 | end |
| 1815 | if eq k 3 |
| 1816 | ret voper w x j e |
| 1817 | end |
| 1818 | if eq k 8 |
| 1819 | ret veff w x j e |
| 1820 | end |
| 1821 | ret 0 |
| 1822 | end |
| 1823 | |
| 1824 | note target of step a of the walk from object i into fr 1280..1283: phase 0 relation a, phase 1 |
| 1825 | note apply operand a (read through the 161-byte ApplyPayload view, past the payload when a > 29). |
| 1826 | note false when that phase has no step a. |
| 1827 | fn dtgt w view uchar 2097152 x view ulong 20544 i ulong ph ulong a ulong fr edit ulong 1284 to bool |
| 1828 | b = ob i |
| 1829 | if eq ph 0 |
| 1830 | if ge a get x add b 4 |
| 1831 | ret false |
| 1832 | end |
| 1833 | o = add add get x add b 5 mul a 34 2 |
| 1834 | for t ulong 4 |
| 1835 | put fr add 1280 t be64 w add o mul t 8 |
| 1836 | end |
| 1837 | ret true |
| 1838 | end |
| 1839 | if or ne get x add b 2 3 lt get x add b 7 161 |
| 1840 | ret false |
| 1841 | end |
| 1842 | if ge a plb w x b 32 |
| 1843 | ret false |
| 1844 | end |
| 1845 | p = add 33 mul a 32 |
| 1846 | for t ulong 4 |
| 1847 | put fr add 1280 t pw64 w x i add p mul t 8 |
| 1848 | end |
| 1849 | ret true |
| 1850 | end |
| 1851 | |
| 1852 | note the first j >= j0 whose id equals the target in fr 1280..1283; -1 when none |
| 1853 | fn dscan x view ulong 20544 fr view ulong 1284 j0 ulong to long |
| 1854 | n = get x 0 |
| 1855 | j = j0 |
| 1856 | while lt j n bound 257 |
| 1857 | b = ob j |
| 1858 | if eq get x add b 9 1 |
| 1859 | if eq get x add b 10 get fr 1280 |
| 1860 | if eq get x add b 11 get fr 1281 |
| 1861 | if eq get x add b 12 get fr 1282 |
| 1862 | if eq get x add b 13 get fr 1283 |
| 1863 | ret long j |
| 1864 | end |
| 1865 | end |
| 1866 | end |
| 1867 | end |
| 1868 | end |
| 1869 | j = add j 1 |
| 1870 | end |
| 1871 | ret -1 |
| 1872 | end |
| 1873 | |
| 1874 | note one step of check_cycle_dfs without recursion. fr: frames (object, phase, step, next j) at |
| 1875 | note 4 per depth, object states at 1024 + i (0 unvisited, 1 on the stack, 2 done), the target at |
| 1876 | note 1280. Returns the new depth, or -(1 + 2 * j + phase) for a cycle through object j. Matches |
| 1877 | note already done (state 2) are skipped inside one step, so the caller's loop runs at most |
| 1878 | note 512 + 256 * 321 steps. |
| 1879 | fn dstep w view uchar 2097152 x view ulong 20544 fr edit ulong 1284 sp ulong to long |
| 1880 | f = mul sub sp 1 4 |
| 1881 | i = get fr f |
| 1882 | ph = get fr add f 1 |
| 1883 | a = get fr add f 2 |
| 1884 | if not dtgt w x i ph a fr |
| 1885 | if eq ph 0 |
| 1886 | put fr add f 1 1 |
| 1887 | put fr add f 2 0 |
| 1888 | put fr add f 3 0 |
| 1889 | ret long sp |
| 1890 | end |
| 1891 | put fr add 1024 i 2 |
| 1892 | ret long sub sp 1 |
| 1893 | end |
| 1894 | r = dscan x fr get fr add f 3 |
| 1895 | while ge r 0 bound 257 |
| 1896 | if ne get fr add 1024 ulong r 2 |
| 1897 | break |
| 1898 | end |
| 1899 | r = dscan x fr add ulong r 1 |
| 1900 | end |
| 1901 | if lt r 0 |
| 1902 | put fr add f 2 add a 1 |
| 1903 | put fr add f 3 0 |
| 1904 | ret long sp |
| 1905 | end |
| 1906 | j = ulong r |
| 1907 | put fr add f 3 add j 1 |
| 1908 | s = get fr add 1024 j |
| 1909 | if eq s 0 |
| 1910 | put fr add 1024 j 1 |
| 1911 | g = mul sp 4 |
| 1912 | put fr g j |
| 1913 | put fr add g 1 0 |
| 1914 | put fr add g 2 0 |
| 1915 | put fr add g 3 0 |
| 1916 | ret long add sp 1 |
| 1917 | end |
| 1918 | ret neg long add add mul j 2 ph 1 |
| 1919 | end |
| 1920 | |
| 1921 | fn dfs w view uchar 2097152 x view ulong 20544 root ulong fr edit ulong 1284 e edit uchar 256 to long |
| 1922 | put fr add 1024 root 1 |
| 1923 | put fr 0 root |
| 1924 | put fr 1 0 |
| 1925 | put fr 2 0 |
| 1926 | put fr 3 0 |
| 1927 | sp = ulong 1 |
| 1928 | while gt sp 0 bound 999999 |
| 1929 | r = dstep w x fr sp |
| 1930 | if lt r 0 |
| 1931 | c = sub ulong neg r 1 |
| 1932 | p = mcyc e 0 |
| 1933 | if eq rem c 2 0 |
| 1934 | p = mcycr e p |
| 1935 | else |
| 1936 | p = mcyco e p |
| 1937 | end |
| 1938 | ret vfail e sdec e p div c 2 |
| 1939 | end |
| 1940 | sp = ulong r |
| 1941 | end |
| 1942 | ret 0 |
| 1943 | end |
| 1944 | |
| 1945 | note omega_validate_object for object j of the graph (the C also takes an object outside any graph; |
| 1946 | note here the object is always X's object j) |
| 1947 | fn cvobject w view uchar 2097152 x view ulong 20544 j ulong e edit uchar 256 to long |
| 1948 | ret vobj w x j e |
| 1949 | end |
| 1950 | |
| 1951 | fn cvalid w view uchar 2097152 x view ulong 20544 e edit uchar 256 to long |
| 1952 | n = get x 0 |
| 1953 | if eq n 0 |
| 1954 | p = mempty e 0 |
| 1955 | ret vfail e p |
| 1956 | end |
| 1957 | for i ulong n |
| 1958 | r = vobj w x i e |
| 1959 | if ne r 0 |
| 1960 | ret r |
| 1961 | end |
| 1962 | end |
| 1963 | fr = new ulong 1284 0 |
| 1964 | for i ulong n |
| 1965 | if eq get fr add 1024 i 0 |
| 1966 | r = dfs w x i fr e |
| 1967 | if ne r 0 |
| 1968 | ret r |
| 1969 | end |
| 1970 | end |
| 1971 | end |
| 1972 | ret 0 |
| 1973 | end |
| 1974 | |
| 1975 | note ---- format_text (omega_graph_format_text, NON-CANONICAL text) ---- |
| 1976 | |
| 1977 | fn fsuf l edit uchar 256 p ulong x view ulong 20544 b ulong to ulong |
| 1978 | p = fidsuf l p |
| 1979 | p = sid l p x b |
| 1980 | ret sput l p 10 1 |
| 1981 | end |
| 1982 | |
| 1983 | fn fopname l edit uchar 256 p ulong opc ulong to ulong |
| 1984 | if eq opc 3 |
| 1985 | ret sput l p 4473921 3 |
| 1986 | end |
| 1987 | if eq opc 4 |
| 1988 | ret sput l p 4347219 3 |
| 1989 | end |
| 1990 | ret sput l p 20559 2 |
| 1991 | end |
| 1992 | |
| 1993 | note one object line into l: its length, or -1 when the C writes nothing (an OPERATION payload |
| 1994 | note shorter than ApplyPayload leaves w as the previous line's length) |
| 1995 | fn fline w view uchar 2097152 x view ulong 20544 i ulong l edit uchar 256 to long |
| 1996 | b = ob i |
| 1997 | k = get x add b 2 |
| 1998 | p = ulong 0 |
| 1999 | if eq k 2 |
| 2000 | tag = pu32 w x b 0 |
| 2001 | if eq tag 3 |
| 2002 | wd = pu16 w x b 4 |
| 2003 | p = ftypu l 0 |
| 2004 | p = sdec l p wd |
| 2005 | p = ftypu2 l p |
| 2006 | p = sdec l p wd |
| 2007 | p = fparsc l p |
| 2008 | ret long fsuf l p x b |
| 2009 | end |
| 2010 | if eq tag 2 |
| 2011 | p = ftbool l 0 |
| 2012 | ret long fsuf l p x b |
| 2013 | end |
| 2014 | p = ftag l 0 |
| 2015 | p = sdec l p tag |
| 2016 | ret long fsuf l p x b |
| 2017 | end |
| 2018 | if eq k 1 |
| 2019 | bl = pu16 w x b 32 |
| 2020 | s = ulong 0 |
| 2021 | if gt bl 8 |
| 2022 | s = sub bl 8 |
| 2023 | end |
| 2024 | v = ulong 0 |
| 2025 | while lt s bl bound 9 |
| 2026 | v = or shl v 8 pbyte w x i add 34 s |
| 2027 | s = add s 1 |
| 2028 | end |
| 2029 | p = fval l 0 |
| 2030 | p = sdec l p i |
| 2031 | p = feq l p |
| 2032 | p = sdec l p v |
| 2033 | ret long fsuf l p x b |
| 2034 | end |
| 2035 | if eq k 3 |
| 2036 | pl = get x add b 7 |
| 2037 | if ge pl 204 |
| 2038 | opc = pu32 w x b 0 |
| 2039 | p = fop l 0 |
| 2040 | p = fopname l p opc |
| 2041 | p = feq l p |
| 2042 | p = fopname l p opc |
| 2043 | p = fwrap l p |
| 2044 | ret long fsuf l p x b |
| 2045 | end |
| 2046 | if ge pl 161 |
| 2047 | p = fapply l 0 |
| 2048 | p = sdec l p i |
| 2049 | ret long fsuf l p x b |
| 2050 | end |
| 2051 | ret -1 |
| 2052 | end |
| 2053 | p = fobj l 0 |
| 2054 | p = sdec l p k |
| 2055 | ret long fsuf l p x b |
| 2056 | end |
| 2057 | |
| 2058 | note snprintf(t + pos, cap - pos, line) then the C's check: -1 when the line did not fit |
| 2059 | fn femit t edit uchar 65536 cap ulong pos ulong l view uchar 256 n ulong to long |
| 2060 | room = sub cap pos |
| 2061 | m = n |
| 2062 | if ge n room |
| 2063 | m = sub room 1 |
| 2064 | end |
| 2065 | for i ulong m |
| 2066 | put t add pos i get l i |
| 2067 | end |
| 2068 | put t add pos m 0 |
| 2069 | if ge n room |
| 2070 | ret -1 |
| 2071 | end |
| 2072 | ret 0 |
| 2073 | end |
| 2074 | |
| 2075 | fn cformat w view uchar 2097152 x view ulong 20544 cap ulong t edit uchar 65536 to long |
| 2076 | if or eq cap 0 gt cap 65536 |
| 2077 | ret -1 |
| 2078 | end |
| 2079 | l = new uchar 256 0 |
| 2080 | cnt = get x 0 |
| 2081 | p = fhead1 l 0 |
| 2082 | p = sdec l p cnt |
| 2083 | p = fnl2 l p |
| 2084 | if lt femit t cap 0 l p 0 |
| 2085 | ret -1 |
| 2086 | end |
| 2087 | pos = p |
| 2088 | wv = p |
| 2089 | for i ulong cnt |
| 2090 | m = fline w x i l |
| 2091 | if ge m 0 |
| 2092 | wv = ulong m |
| 2093 | if lt femit t cap pos l wv 0 |
| 2094 | ret -1 |
| 2095 | end |
| 2096 | else |
| 2097 | if ge wv sub cap pos |
| 2098 | ret -1 |
| 2099 | end |
| 2100 | end |
| 2101 | pos = add pos wv |
| 2102 | end |
| 2103 | ret 0 |
| 2104 | end |
| 2105 | |
| 2106 | note ---- parse_text (omega_graph_parse_text) and the omega_core.c builders it calls ---- |
| 2107 | note sv: 0 u32 type, 1 val a, 2 val b, 3 op add, 4 op sub (object index + 1, 0 = NULL), |
| 2108 | note 5 object count, 6 wire write position; ids: 4 big-endian ulongs per object |
| 2109 | |
| 2110 | fn sch s view uchar 262144 sl ulong i ulong to ulong |
| 2111 | if lt i sl |
| 2112 | ret ulong get s i |
| 2113 | end |
| 2114 | ret 0 |
| 2115 | end |
| 2116 | |
| 2117 | note isspace in the C locale |
| 2118 | fn isspc c ulong to bool |
| 2119 | ret or eq c 32 and ge c 9 le c 13 |
| 2120 | end |
| 2121 | |
| 2122 | note the pattern bytes: 0 type, 1 val, 2 op, 3 apply, 4 UNSIGNED_INTEGER(32), 5 ADD, 6 SUB; length |
| 2123 | fn setpat pt edit uchar 24 c ulong to ulong |
| 2124 | l = new uchar 256 0 |
| 2125 | n = ulong 0 |
| 2126 | if eq c 0 |
| 2127 | n = sput l 0 1701869940 4 |
| 2128 | end |
| 2129 | if eq c 1 |
| 2130 | n = sput l 0 7102838 3 |
| 2131 | end |
| 2132 | if eq c 2 |
| 2133 | n = sput l 0 28783 2 |
| 2134 | end |
| 2135 | if eq c 3 |
| 2136 | n = sput l 0 521510350945 5 |
| 2137 | end |
| 2138 | if eq c 4 |
| 2139 | n = sput l 0 4919424236051975765 8 |
| 2140 | n = sput l n 5928222847595858271 8 |
| 2141 | n = sput l n 691155752 4 |
| 2142 | end |
| 2143 | if eq c 5 |
| 2144 | n = sput l 0 4473921 3 |
| 2145 | end |
| 2146 | if eq c 6 |
| 2147 | n = sput l 0 4347219 3 |
| 2148 | end |
| 2149 | for i ulong n |
| 2150 | put pt i get l i |
| 2151 | end |
| 2152 | ret n |
| 2153 | end |
| 2154 | |
| 2155 | note strncmp(s + i, pattern, n) == 0 (the string ends at sl) |
| 2156 | fn smat s view uchar 262144 sl ulong i ulong pt view uchar 24 n ulong to bool |
| 2157 | for t ulong n |
| 2158 | if ne sch s sl add i t ulong get pt t |
| 2159 | ret false |
| 2160 | end |
| 2161 | end |
| 2162 | ret true |
| 2163 | end |
| 2164 | |
| 2165 | note strstr(s + i, pattern) != NULL |
| 2166 | fn sfind s view uchar 262144 sl ulong i ulong pt view uchar 24 n ulong to bool |
| 2167 | while le add i n sl bound 999999 |
| 2168 | if smat s sl i pt n |
| 2169 | ret true |
| 2170 | end |
| 2171 | i = add i 1 |
| 2172 | end |
| 2173 | ret false |
| 2174 | end |
| 2175 | |
| 2176 | fn seol s view uchar 262144 sl ulong i ulong to ulong |
| 2177 | while lt i sl bound 999999 |
| 2178 | if eq get s i 10 |
| 2179 | ret i |
| 2180 | end |
| 2181 | i = add i 1 |
| 2182 | end |
| 2183 | ret i |
| 2184 | end |
| 2185 | |
| 2186 | fn digv c ulong to ulong |
| 2187 | if and ge c 48 le c 57 |
| 2188 | ret sub c 48 |
| 2189 | end |
| 2190 | if and ge c 97 le c 122 |
| 2191 | ret sub c 87 |
| 2192 | end |
| 2193 | if and ge c 65 le c 90 |
| 2194 | ret sub c 55 |
| 2195 | end |
| 2196 | ret 99 |
| 2197 | end |
| 2198 | |
| 2199 | note glibc 2.39 strtoul(s + i, NULL, 0) under _GNU_SOURCE is __isoc23_strtoul: 0b/0B is binary. |
| 2200 | note spref: skip spaces, sign and prefix; returns i | base << 40 | negative << 48 |
| 2201 | fn spref s view uchar 262144 sl ulong i ulong to ulong |
| 2202 | while isspc sch s sl i bound 999999 |
| 2203 | i = add i 1 |
| 2204 | end |
| 2205 | ng = ulong 0 |
| 2206 | c = sch s sl i |
| 2207 | if eq c 45 |
| 2208 | ng = 1 |
| 2209 | i = add i 1 |
| 2210 | else |
| 2211 | if eq c 43 |
| 2212 | i = add i 1 |
| 2213 | end |
| 2214 | end |
| 2215 | bs = ulong 10 |
| 2216 | if eq sch s sl i 48 |
| 2217 | c = sch s sl add i 1 |
| 2218 | if or eq c 120 eq c 88 |
| 2219 | bs = 16 |
| 2220 | i = add i 2 |
| 2221 | else |
| 2222 | if or eq c 98 eq c 66 |
| 2223 | bs = 2 |
| 2224 | i = add i 2 |
| 2225 | else |
| 2226 | bs = 8 |
| 2227 | end |
| 2228 | end |
| 2229 | end |
| 2230 | ret or i or shl bs 40 shl ng 48 |
| 2231 | end |
| 2232 | |
| 2233 | note the digits into r: r 0 the value, r 1 = 1 on overflow (glibc then returns ULONG_MAX whatever the sign) |
| 2234 | fn sdig s view uchar 262144 sl ulong i ulong bs ulong r edit ulong 2 to void |
| 2235 | cut = div 18446744073709551615 bs |
| 2236 | lim = rem 18446744073709551615 bs |
| 2237 | v = ulong 0 |
| 2238 | while lt digv sch s sl i bs bound 999999 |
| 2239 | d = digv sch s sl i |
| 2240 | if or gt v cut and eq v cut gt d lim |
| 2241 | put r 1 1 |
| 2242 | else |
| 2243 | v = add mul v bs d |
| 2244 | end |
| 2245 | i = add i 1 |
| 2246 | end |
| 2247 | put r 0 v |
| 2248 | end |
| 2249 | |
| 2250 | fn stoul s view uchar 262144 sl ulong i ulong to ulong |
| 2251 | q = spref s sl i |
| 2252 | r = new ulong 2 0 |
| 2253 | sdig s sl and q 1099511627775 and shr q 40 255 r |
| 2254 | if eq get r 1 1 |
| 2255 | ret 18446744073709551615 |
| 2256 | end |
| 2257 | if eq shr q 48 1 |
| 2258 | ret neg get r 0 |
| 2259 | end |
| 2260 | ret get r 0 |
| 2261 | end |
| 2262 | |
| 2263 | fn putid w edit uchar 2097152 o ulong ids view ulong 1024 k ulong to void |
| 2264 | for t ulong 32 |
| 2265 | q = get ids add mul k 4 div t 8 |
| 2266 | sh = mul sub 7 rem t 8 8 |
| 2267 | put w add o t uchar and shr q sh 255 |
| 2268 | end |
| 2269 | end |
| 2270 | |
| 2271 | note omega_graph_add_object + record header: the payload's wire offset (payload zeroed), 0 when full |
| 2272 | fn bstart w edit uchar 2097152 sv edit ulong 8 kind ulong pl ulong to ulong |
| 2273 | if ge get sv 5 256 |
| 2274 | ret 0 |
| 2275 | end |
| 2276 | o = get sv 6 |
| 2277 | cl = add 16 pl |
| 2278 | for t ulong 4 |
| 2279 | sh = mul sub 3 t 8 |
| 2280 | put w add o t uchar and shr cl sh 255 |
| 2281 | end |
| 2282 | put w add o 4 79 |
| 2283 | put w add o 5 77 |
| 2284 | put w add o 6 71 |
| 2285 | put w add o 7 48 |
| 2286 | put w add o 8 1 |
| 2287 | put w add o 9 uchar kind |
| 2288 | for t ulong 6 |
| 2289 | put w add add o 10 t 0 |
| 2290 | end |
| 2291 | put w add o 16 uchar shr pl 24 |
| 2292 | put w add o 17 uchar and shr pl 16 255 |
| 2293 | put w add o 18 uchar and shr pl 8 255 |
| 2294 | put w add o 19 uchar and pl 255 |
| 2295 | for t ulong pl |
| 2296 | put w add add o 20 t 0 |
| 2297 | end |
| 2298 | ret add o 20 |
| 2299 | end |
| 2300 | |
| 2301 | note omega_compute_semantic_id of the record just written: sha256 of its bytes after the length |
| 2302 | fn bfin w edit uchar 2097152 sv edit ulong 8 ids edit ulong 1024 to ulong |
| 2303 | o = get sv 6 |
| 2304 | cl = be32 view w o |
| 2305 | cb = new uchar 4096 0 |
| 2306 | for t ulong cl |
| 2307 | put cb t get w add add o 4 t |
| 2308 | end |
| 2309 | d = new ulong 4 0 |
| 2310 | sha4k cb cl d |
| 2311 | n = get sv 5 |
| 2312 | for t ulong 4 |
| 2313 | put ids add mul n 4 t get d t |
| 2314 | end |
| 2315 | put sv 5 add n 1 |
| 2316 | put sv 6 add add o 4 cl |
| 2317 | ret add n 1 |
| 2318 | end |
| 2319 | |
| 2320 | fn btype w edit uchar 2097152 sv edit ulong 8 ids edit ulong 1024 to ulong |
| 2321 | o = bstart w sv 2 44 |
| 2322 | if eq o 0 |
| 2323 | ret 0 |
| 2324 | end |
| 2325 | put w o 3 |
| 2326 | put w add o 4 32 |
| 2327 | ret bfin w sv ids |
| 2328 | end |
| 2329 | |
| 2330 | fn bval w edit uchar 2097152 sv edit ulong 8 ids edit ulong 1024 v ulong to ulong |
| 2331 | o = bstart w sv 1 98 |
| 2332 | if eq o 0 |
| 2333 | ret 0 |
| 2334 | end |
| 2335 | putid w o ids sub get sv 0 1 |
| 2336 | put w add o 32 4 |
| 2337 | for t ulong 4 |
| 2338 | sh = mul sub 3 t 8 |
| 2339 | put w add add o 34 t uchar and shr v sh 255 |
| 2340 | end |
| 2341 | ret bfin w sv ids |
| 2342 | end |
| 2343 | |
| 2344 | fn bop w edit uchar 2097152 sv edit ulong 8 ids edit ulong 1024 opc ulong to ulong |
| 2345 | o = bstart w sv 3 204 |
| 2346 | if eq o 0 |
| 2347 | ret 0 |
| 2348 | end |
| 2349 | k = sub get sv 0 1 |
| 2350 | put w o uchar opc |
| 2351 | put w add o 4 1 |
| 2352 | putid w add o 8 ids k |
| 2353 | put w add o 40 2 |
| 2354 | putid w add o 41 ids k |
| 2355 | putid w add o 73 ids k |
| 2356 | putid w add o 169 ids k |
| 2357 | ret bfin w sv ids |
| 2358 | end |
| 2359 | |
| 2360 | fn bapply w edit uchar 2097152 sv edit ulong 8 ids edit ulong 1024 op ulong to ulong |
| 2361 | o = bstart w sv 3 161 |
| 2362 | if eq o 0 |
| 2363 | ret 0 |
| 2364 | end |
| 2365 | putid w o ids sub op 1 |
| 2366 | put w add o 32 2 |
| 2367 | putid w add o 33 ids sub get sv 1 1 |
| 2368 | putid w add o 65 ids sub get sv 2 1 |
| 2369 | ret bfin w sv ids |
| 2370 | end |
| 2371 | |
| 2372 | note one line whose first word starts at i (after the C's whitespace skip) |
| 2373 | fn pline s view uchar 262144 sl ulong i ulong w edit uchar 2097152 sv edit ulong 8 ids edit ulong 1024 to void |
| 2374 | pt = new uchar 24 0 |
| 2375 | n = setpat pt 0 |
| 2376 | if smat s sl i pt n |
| 2377 | n = setpat pt 4 |
| 2378 | if sfind s sl i pt n |
| 2379 | put sv 0 btype w sv ids |
| 2380 | end |
| 2381 | ret |
| 2382 | end |
| 2383 | n = setpat pt 1 |
| 2384 | if smat s sl i pt n |
| 2385 | q = ulong 0 |
| 2386 | while lt add i q sl bound 999999 |
| 2387 | if eq get s add i q 61 |
| 2388 | break |
| 2389 | end |
| 2390 | q = add q 1 |
| 2391 | end |
| 2392 | if and lt add i q sl ne get sv 0 0 |
| 2393 | v = stoul s sl add add i q 1 |
| 2394 | if eq get sv 1 0 |
| 2395 | put sv 1 bval w sv ids v |
| 2396 | else |
| 2397 | if eq get sv 2 0 |
| 2398 | put sv 2 bval w sv ids v |
| 2399 | end |
| 2400 | end |
| 2401 | end |
| 2402 | ret |
| 2403 | end |
| 2404 | n = setpat pt 2 |
| 2405 | if smat s sl i pt n |
| 2406 | n = setpat pt 5 |
| 2407 | if and sfind s sl i pt n ne get sv 0 0 |
| 2408 | put sv 3 bop w sv ids 3 |
| 2409 | ret |
| 2410 | end |
| 2411 | n = setpat pt 6 |
| 2412 | if and sfind s sl i pt n ne get sv 0 0 |
| 2413 | put sv 4 bop w sv ids 4 |
| 2414 | end |
| 2415 | ret |
| 2416 | end |
| 2417 | n = setpat pt 3 |
| 2418 | if smat s sl i pt n |
| 2419 | ok = and ne get sv 1 0 ne get sv 2 0 |
| 2420 | if and ok ne get sv 3 0 |
| 2421 | r = bapply w sv ids get sv 3 |
| 2422 | ret |
| 2423 | end |
| 2424 | if and ok ne get sv 4 0 |
| 2425 | r = bapply w sv ids get sv 4 |
| 2426 | end |
| 2427 | end |
| 2428 | end |
| 2429 | |
| 2430 | fn cparse s view uchar 262144 n ulong w edit uchar 2097152 x edit ulong 20544 to long |
| 2431 | if gt n 262144 |
| 2432 | ret -2 |
| 2433 | end |
| 2434 | sl = n |
| 2435 | for i ulong n |
| 2436 | if eq get s i 0 |
| 2437 | sl = i |
| 2438 | break |
| 2439 | end |
| 2440 | end |
| 2441 | sv = new ulong 8 0 |
| 2442 | ids = new ulong 1024 0 |
| 2443 | put sv 6 6 |
| 2444 | p = ulong 0 |
| 2445 | while lt p sl bound 999999 |
| 2446 | while and lt p sl isspc sch s sl p bound 999999 |
| 2447 | p = add p 1 |
| 2448 | end |
| 2449 | if ge p sl |
| 2450 | break |
| 2451 | end |
| 2452 | if and eq get s p 47 eq sch s sl add p 1 47 |
| 2453 | p = seol s sl p |
| 2454 | continue |
| 2455 | end |
| 2456 | pline s sl p w sv ids |
| 2457 | p = seol s sl p |
| 2458 | end |
| 2459 | put w 0 79 |
| 2460 | put w 1 77 |
| 2461 | put w 2 71 |
| 2462 | put w 3 71 |
| 2463 | c = get sv 5 |
| 2464 | put w 4 uchar shr c 8 |
| 2465 | put w 5 uchar and c 255 |
| 2466 | r = cdecode view w get sv 6 x |
| 2467 | if ne r 0 |
| 2468 | trap 9 |
| 2469 | end |
| 2470 | ret 0 |
| 2471 | end |
| 2472 | |
| 2473 | note ---- ids as text (omega_canonical.c) ---- |
| 2474 | |
| 2475 | note strtol({c0, c1, 0}, &end, 16) consuming both characters: the byte value, or -1 |
| 2476 | fn hx2 c0 ulong c1 ulong to long |
| 2477 | i = ulong 0 |
| 2478 | if isspc c0 |
| 2479 | i = 1 |
| 2480 | end |
| 2481 | c = c0 |
| 2482 | if eq i 1 |
| 2483 | c = c1 |
| 2484 | end |
| 2485 | ng = false |
| 2486 | if and eq i 0 or eq c 45 eq c 43 |
| 2487 | ng = eq c 45 |
| 2488 | i = 1 |
| 2489 | c = c1 |
| 2490 | end |
| 2491 | if eq i 1 |
| 2492 | if gt digv c 15 |
| 2493 | ret -1 |
| 2494 | end |
| 2495 | v = long digv c |
| 2496 | if ng |
| 2497 | ret and neg v 255 |
| 2498 | end |
| 2499 | ret v |
| 2500 | end |
| 2501 | if or gt digv c0 15 gt digv c1 15 |
| 2502 | ret -1 |
| 2503 | end |
| 2504 | if and eq c0 48 or eq c1 120 eq c1 88 |
| 2505 | ret -1 |
| 2506 | end |
| 2507 | ret long or shl digv c0 4 digv c1 |
| 2508 | end |
| 2509 | |
| 2510 | fn chexparse h view uchar 65 o edit uchar 32 to long |
| 2511 | for i ulong 64 |
| 2512 | if eq get h i 0 |
| 2513 | ret -1 |
| 2514 | end |
| 2515 | end |
| 2516 | if ne get h 64 0 |
| 2517 | ret -1 |
| 2518 | end |
| 2519 | for i ulong 32 |
| 2520 | v = hx2 ulong get h mul i 2 ulong get h add mul i 2 1 |
| 2521 | if lt v 0 |
| 2522 | ret -1 |
| 2523 | end |
| 2524 | put o i uchar v |
| 2525 | end |
| 2526 | ret 0 |
| 2527 | end |
| 2528 | |
| 2529 | fn chexid a view uchar 32 o edit uchar 65 to void |
| 2530 | for i ulong 32 |
| 2531 | c = ulong get a i |
| 2532 | put o mul i 2 uchar hexdig shr c 4 |
| 2533 | put o add mul i 2 1 uchar hexdig and c 15 |
| 2534 | end |
| 2535 | put o 64 0 |
| 2536 | end |
| 2537 | |
| 2538 | fn cidcmp a view uchar 32 c view uchar 32 to long |
| 2539 | for i ulong 32 |
| 2540 | p = get a i |
| 2541 | q = get c i |
| 2542 | if lt p q |
| 2543 | ret -1 |
| 2544 | end |
| 2545 | if gt p q |
| 2546 | ret 1 |
| 2547 | end |
| 2548 | end |
| 2549 | ret 0 |
| 2550 | end |
| 2551 | |
| 2552 | note ==== parity harness: program mode only; everything above this line is the library ==== |
| 2553 | note usage: codec decode|text|hexid < PACK, or codec header. Writes the stream files into the current |
| 2554 | note directory in exactly the C oracle's line formats (see parity/run.sh). |
| 2555 | |
| 2556 | text tdec "decode.out" |
| 2557 | text tval "validate.out" |
| 2558 | text tser "serialize.out" |
| 2559 | text tfmt "format.out" |
| 2560 | text tpar "parse.out" |
| 2561 | text thex "hexid.out" |
| 2562 | text thdr "header.out" |
| 2563 | text tuse "usage: codec decode|text|hexid < PACK | codec header\n" |
| 2564 | text tbad "codec: cannot open an output file\n" |
| 2565 | |
| 2566 | global ib uchar 1048576 |
| 2567 | global ist ulong 2 |
| 2568 | global obuf uchar 4194304 |
| 2569 | global obn ulong 4 |
| 2570 | global ofd long 4 |
| 2571 | global arg uchar 64 |
| 2572 | |
| 2573 | fn inb to ulong |
| 2574 | p = get ist 0 |
| 2575 | if ge p get ist 1 |
| 2576 | r = read 0 ib 0 1048576 |
| 2577 | if le r 0 |
| 2578 | ret 256 |
| 2579 | end |
| 2580 | put ist 1 ulong r |
| 2581 | p = 0 |
| 2582 | end |
| 2583 | put ist 0 add p 1 |
| 2584 | ret ulong get ib p |
| 2585 | end |
| 2586 | |
| 2587 | note u32 little-endian record length; 2^32 at end of input |
| 2588 | fn rdlen to ulong |
| 2589 | c = inb |
| 2590 | if eq c 256 |
| 2591 | ret 4294967296 |
| 2592 | end |
| 2593 | v = c |
| 2594 | for i ulong 3 |
| 2595 | v = or v shl inb mul add i 1 8 |
| 2596 | end |
| 2597 | ret v |
| 2598 | end |
| 2599 | |
| 2600 | note n record bytes into a (the first 2097152; the rest is read and dropped). A `for` with a |
| 2601 | note counted value traps 4 past 1000000 passes, so long runs go in pieces of at most 4096. |
| 2602 | fn rdw a edit uchar 2097152 n ulong to void |
| 2603 | i = ulong 0 |
| 2604 | while lt i n bound 999999 |
| 2605 | m = sub n i |
| 2606 | if gt m 4096 |
| 2607 | m = 4096 |
| 2608 | end |
| 2609 | for t ulong m |
| 2610 | c = inb |
| 2611 | if lt add i t 2097152 |
| 2612 | put a add i t uchar c |
| 2613 | end |
| 2614 | end |
| 2615 | i = add i m |
| 2616 | end |
| 2617 | end |
| 2618 | |
| 2619 | fn rds a edit uchar 262144 n ulong to void |
| 2620 | i = ulong 0 |
| 2621 | while lt i n bound 999999 |
| 2622 | m = sub n i |
| 2623 | if gt m 4096 |
| 2624 | m = 4096 |
| 2625 | end |
| 2626 | for t ulong m |
| 2627 | c = inb |
| 2628 | if lt add i t 262144 |
| 2629 | put a add i t uchar c |
| 2630 | end |
| 2631 | end |
| 2632 | i = add i m |
| 2633 | end |
| 2634 | end |
| 2635 | |
| 2636 | fn ohexs f ulong o view uchar 1049606 n ulong to void |
| 2637 | i = ulong 0 |
| 2638 | while lt i n bound 999999 |
| 2639 | m = sub n i |
| 2640 | if gt m 4096 |
| 2641 | m = 4096 |
| 2642 | end |
| 2643 | for t ulong m |
| 2644 | ohexb f ulong get o add i t |
| 2645 | end |
| 2646 | i = add i m |
| 2647 | end |
| 2648 | end |
| 2649 | |
| 2650 | fn oflush f ulong to void |
| 2651 | n = get obn f |
| 2652 | if gt n 0 |
| 2653 | r = write int get ofd f obuf mul f 1048576 n |
| 2654 | end |
| 2655 | put obn f 0 |
| 2656 | end |
| 2657 | |
| 2658 | fn ob1 f ulong c ulong to void |
| 2659 | n = get obn f |
| 2660 | if ge n 1048576 |
| 2661 | oflush f |
| 2662 | n = 0 |
| 2663 | end |
| 2664 | put obuf add mul f 1048576 n uchar c |
| 2665 | put obn f add n 1 |
| 2666 | end |
| 2667 | |
| 2668 | fn odec f ulong v ulong to void |
| 2669 | d = new uchar 20 0 |
| 2670 | n = ulong 0 |
| 2671 | while true bound 21 |
| 2672 | put d n uchar add rem v 10 48 |
| 2673 | n = add n 1 |
| 2674 | v = div v 10 |
| 2675 | if eq v 0 |
| 2676 | break |
| 2677 | end |
| 2678 | end |
| 2679 | for i ulong n |
| 2680 | ob1 f ulong get d sub sub n 1 i |
| 2681 | end |
| 2682 | end |
| 2683 | |
| 2684 | fn osdec f ulong v long to void |
| 2685 | if lt v 0 |
| 2686 | ob1 f 45 |
| 2687 | odec f ulong neg v |
| 2688 | ret |
| 2689 | end |
| 2690 | odec f ulong v |
| 2691 | end |
| 2692 | |
| 2693 | fn ohexb f ulong c ulong to void |
| 2694 | ob1 f hexdig shr c 4 |
| 2695 | ob1 f hexdig and c 15 |
| 2696 | end |
| 2697 | |
| 2698 | fn ohexw f ulong v ulong to void |
| 2699 | for t ulong 16 |
| 2700 | sh = mul sub 15 t 4 |
| 2701 | ob1 f hexdig and shr v sh 15 |
| 2702 | end |
| 2703 | end |
| 2704 | |
| 2705 | fn oopen f ulong name view uchar 32 n ulong to bool |
| 2706 | fd = fopen name 0 n 577 420 |
| 2707 | if lt fd 0 |
| 2708 | ret false |
| 2709 | end |
| 2710 | put ofd f fd |
| 2711 | ret true |
| 2712 | end |
| 2713 | |
| 2714 | fn opn f ulong c ulong to bool |
| 2715 | nm = new uchar 32 0 |
| 2716 | if eq c 0 |
| 2717 | for i ulong len tdec |
| 2718 | put nm i get tdec i |
| 2719 | end |
| 2720 | ret oopen f nm len tdec |
| 2721 | end |
| 2722 | if eq c 1 |
| 2723 | for i ulong len tval |
| 2724 | put nm i get tval i |
| 2725 | end |
| 2726 | ret oopen f nm len tval |
| 2727 | end |
| 2728 | if eq c 2 |
| 2729 | for i ulong len tser |
| 2730 | put nm i get tser i |
| 2731 | end |
| 2732 | ret oopen f nm len tser |
| 2733 | end |
| 2734 | if eq c 3 |
| 2735 | for i ulong len tfmt |
| 2736 | put nm i get tfmt i |
| 2737 | end |
| 2738 | ret oopen f nm len tfmt |
| 2739 | end |
| 2740 | if eq c 4 |
| 2741 | for i ulong len tpar |
| 2742 | put nm i get tpar i |
| 2743 | end |
| 2744 | ret oopen f nm len tpar |
| 2745 | end |
| 2746 | if eq c 5 |
| 2747 | for i ulong len thex |
| 2748 | put nm i get thex i |
| 2749 | end |
| 2750 | ret oopen f nm len thex |
| 2751 | end |
| 2752 | for i ulong len thdr |
| 2753 | put nm i get thdr i |
| 2754 | end |
| 2755 | ret oopen f nm len thdr |
| 2756 | end |
| 2757 | |
| 2758 | fn shaout b view uchar 1049606 n ulong d edit ulong 4 to void |
| 2759 | k = new ulong 64 0 |
| 2760 | shak k |
| 2761 | h = new ulong 8 0 |
| 2762 | shainit h |
| 2763 | m = new uchar 64 0 |
| 2764 | nb = div n 64 |
| 2765 | for bi ulong nb |
| 2766 | o = mul bi 64 |
| 2767 | for i ulong 64 |
| 2768 | put m i get b add o i |
| 2769 | end |
| 2770 | shablk h m k |
| 2771 | end |
| 2772 | tb = mul nb 64 |
| 2773 | r = sub n tb |
| 2774 | for i ulong r |
| 2775 | put m i get b add tb i |
| 2776 | end |
| 2777 | shafin h m k r n |
| 2778 | shaget h d |
| 2779 | end |
| 2780 | |
| 2781 | note " <count> <has_id>:<id> ..." as the oracle's ids() |
| 2782 | fn oids f ulong x view ulong 20544 to void |
| 2783 | n = get x 0 |
| 2784 | ob1 f 32 |
| 2785 | odec f n |
| 2786 | for j ulong n |
| 2787 | b = ob j |
| 2788 | ob1 f 32 |
| 2789 | odec f get x add b 9 |
| 2790 | ob1 f 58 |
| 2791 | for t ulong 4 |
| 2792 | ohexw f get x add add b 10 t |
| 2793 | end |
| 2794 | end |
| 2795 | end |
| 2796 | |
| 2797 | fn gval w view uchar 2097152 x view ulong 20544 e edit uchar 256 f ulong k ulong to void |
| 2798 | r = cvalid w x e |
| 2799 | odec f k |
| 2800 | ob1 f 32 |
| 2801 | osdec f r |
| 2802 | if ne r 0 |
| 2803 | ob1 f 32 |
| 2804 | for i ulong 256 |
| 2805 | c = get e i |
| 2806 | if eq c 0 |
| 2807 | break |
| 2808 | end |
| 2809 | ob1 f ulong c |
| 2810 | end |
| 2811 | end |
| 2812 | ob1 f 10 |
| 2813 | end |
| 2814 | |
| 2815 | fn gser w view uchar 2097152 x view ulong 20544 o edit uchar 1049606 f ulong k ulong to void |
| 2816 | d = new ulong 4 0 |
| 2817 | r = cserial w x 1049606 o |
| 2818 | odec f k |
| 2819 | if ge r 0 |
| 2820 | ob1 f 32 |
| 2821 | ob1 f 48 |
| 2822 | ob1 f 32 |
| 2823 | n = ulong r |
| 2824 | odec f n |
| 2825 | ob1 f 32 |
| 2826 | ohexs f o n |
| 2827 | ob1 f 32 |
| 2828 | shaout o n d |
| 2829 | for i ulong 4 |
| 2830 | ohexw f get d i |
| 2831 | end |
| 2832 | else |
| 2833 | ob1 f 32 |
| 2834 | osdec f r |
| 2835 | end |
| 2836 | r = cserial w x 8192 o |
| 2837 | ob1 f 32 |
| 2838 | if ge r 0 |
| 2839 | ob1 f 48 |
| 2840 | ob1 f 32 |
| 2841 | odec f ulong r |
| 2842 | else |
| 2843 | osdec f r |
| 2844 | end |
| 2845 | ob1 f 10 |
| 2846 | end |
| 2847 | |
| 2848 | fn otxt f ulong t view uchar 65536 to void |
| 2849 | for i ulong 65536 |
| 2850 | c = get t i |
| 2851 | if eq c 0 |
| 2852 | ret |
| 2853 | end |
| 2854 | ohexb f ulong c |
| 2855 | end |
| 2856 | end |
| 2857 | |
| 2858 | fn gfmt w view uchar 2097152 x view ulong 20544 t edit uchar 65536 f ulong k ulong to void |
| 2859 | r = cformat w x 4096 t |
| 2860 | odec f k |
| 2861 | ob1 f 32 |
| 2862 | osdec f r |
| 2863 | ob1 f 32 |
| 2864 | otxt f t |
| 2865 | r = cformat w x 200 t |
| 2866 | ob1 f 32 |
| 2867 | osdec f r |
| 2868 | ob1 f 32 |
| 2869 | otxt f t |
| 2870 | ob1 f 10 |
| 2871 | end |
| 2872 | |
| 2873 | fn dodec to int |
| 2874 | w = new uchar 2097152 0 |
| 2875 | x = new ulong 20544 0 |
| 2876 | o = new uchar 1049606 0 |
| 2877 | t = new uchar 65536 0 |
| 2878 | e = new uchar 256 0 |
| 2879 | for f ulong 4 |
| 2880 | if not opn f f |
| 2881 | ret 2 |
| 2882 | end |
| 2883 | end |
| 2884 | k = ulong 0 |
| 2885 | while true bound 999999 |
| 2886 | n = rdlen |
| 2887 | if eq n 4294967296 |
| 2888 | break |
| 2889 | end |
| 2890 | rdw w n |
| 2891 | r = cdecode w n x |
| 2892 | odec 0 k |
| 2893 | ob1 0 32 |
| 2894 | osdec 0 r |
| 2895 | if eq r 0 |
| 2896 | oids 0 x |
| 2897 | gval w x e 1 k |
| 2898 | gser w x o 2 k |
| 2899 | gfmt w x t 3 k |
| 2900 | end |
| 2901 | ob1 0 10 |
| 2902 | k = add k 1 |
| 2903 | end |
| 2904 | for f ulong 4 |
| 2905 | oflush f |
| 2906 | end |
| 2907 | ret 0 |
| 2908 | end |
| 2909 | |
| 2910 | fn dotext to int |
| 2911 | s = new uchar 262144 0 |
| 2912 | w = new uchar 2097152 0 |
| 2913 | x = new ulong 20544 0 |
| 2914 | o = new uchar 1049606 0 |
| 2915 | t = new uchar 65536 0 |
| 2916 | e = new uchar 256 0 |
| 2917 | if not opn 0 4 |
| 2918 | ret 2 |
| 2919 | end |
| 2920 | k = ulong 0 |
| 2921 | while true bound 999999 |
| 2922 | n = rdlen |
| 2923 | if eq n 4294967296 |
| 2924 | break |
| 2925 | end |
| 2926 | rds s n |
| 2927 | r = cparse s n w x |
| 2928 | odec 0 k |
| 2929 | ob1 0 32 |
| 2930 | osdec 0 r |
| 2931 | oids 0 x |
| 2932 | ob1 0 10 |
| 2933 | gval w x e 0 k |
| 2934 | gser w x o 0 k |
| 2935 | gfmt w x t 0 k |
| 2936 | k = add k 1 |
| 2937 | end |
| 2938 | oflush 0 |
| 2939 | ret 0 |
| 2940 | end |
| 2941 | |
| 2942 | fn dohex to int |
| 2943 | h = new uchar 65 0 |
| 2944 | a = new uchar 32 0 |
| 2945 | c = new uchar 32 0 |
| 2946 | o = new uchar 32 0 |
| 2947 | hx = new uchar 65 0 |
| 2948 | a2 = new uchar 32 0 |
| 2949 | if not opn 0 5 |
| 2950 | ret 2 |
| 2951 | end |
| 2952 | k = ulong 0 |
| 2953 | while true bound 999999 |
| 2954 | n = rdlen |
| 2955 | if eq n 4294967296 |
| 2956 | break |
| 2957 | end |
| 2958 | if ne n 129 |
| 2959 | ret 3 |
| 2960 | end |
| 2961 | for i ulong 65 |
| 2962 | put h i uchar inb |
| 2963 | end |
| 2964 | for i ulong 32 |
| 2965 | put a i uchar inb |
| 2966 | end |
| 2967 | for i ulong 32 |
| 2968 | put c i uchar inb |
| 2969 | end |
| 2970 | for i ulong 32 |
| 2971 | put a2 i get a i |
| 2972 | end |
| 2973 | for i ulong 32 |
| 2974 | put o i 0 |
| 2975 | end |
| 2976 | r = chexparse h o |
| 2977 | odec 0 k |
| 2978 | ob1 0 32 |
| 2979 | osdec 0 r |
| 2980 | ob1 0 32 |
| 2981 | for i ulong 32 |
| 2982 | ohexb 0 ulong get o i |
| 2983 | end |
| 2984 | ob1 0 32 |
| 2985 | chexid a hx |
| 2986 | for i ulong 64 |
| 2987 | ob1 0 ulong get hx i |
| 2988 | end |
| 2989 | ob1 0 32 |
| 2990 | osdec 0 cidcmp a c |
| 2991 | ob1 0 32 |
| 2992 | osdec 0 cidcmp a a2 |
| 2993 | ob1 0 10 |
| 2994 | k = add k 1 |
| 2995 | end |
| 2996 | oflush 0 |
| 2997 | ret 0 |
| 2998 | end |
| 2999 | |
| 3000 | fn dohdr to int |
| 3001 | if not opn 0 6 |
| 3002 | ret 2 |
| 3003 | end |
| 3004 | for v ulong 256 |
| 3005 | for k ulong 256 |
| 3006 | odec 0 v |
| 3007 | ob1 0 32 |
| 3008 | odec 0 k |
| 3009 | ob1 0 32 |
| 3010 | odec 0 cobjver k |
| 3011 | ob1 0 32 |
| 3012 | osdec 0 cchkhdr v k |
| 3013 | ob1 0 10 |
| 3014 | end |
| 3015 | end |
| 3016 | oflush 0 |
| 3017 | ret 0 |
| 3018 | end |
| 3019 | |
| 3020 | fn main to int |
| 3021 | if lt argcnt 2 |
| 3022 | r = write 2 tuse 0 len tuse |
| 3023 | ret 2 |
| 3024 | end |
| 3025 | n = argread 1 arg 0 63 |
| 3026 | if lt n 4 |
| 3027 | r = write 2 tuse 0 len tuse |
| 3028 | ret 2 |
| 3029 | end |
| 3030 | c0 = get arg 0 |
| 3031 | c2 = get arg 2 |
| 3032 | rc = int 9 |
| 3033 | if eq c0 100 |
| 3034 | rc = dodec |
| 3035 | end |
| 3036 | if eq c0 116 |
| 3037 | rc = dotext |
| 3038 | end |
| 3039 | if and eq c0 104 eq c2 120 |
| 3040 | rc = dohex |
| 3041 | end |
| 3042 | if and eq c0 104 eq c2 97 |
| 3043 | rc = dohdr |
| 3044 | end |
| 3045 | if eq rc 9 |
| 3046 | r = write 2 tuse 0 len tuse |
| 3047 | ret 2 |
| 3048 | end |
| 3049 | if eq rc 2 |
| 3050 | r = write 2 tbad 0 len tbad |
| 3051 | end |
| 3052 | ret rc |
| 3053 | end |