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 / train / aien-train / native / omegese45 / mjr1.om
| 1 | note SPDX-License-Identifier: AGPL-3.0-only |
| 2 | note MJR1 receipt parser (aien-train #45, contract lane). Requires vocab.om before it. |
| 3 | note Layout and static rules follow aien-dev/aien-protocols-mv e705fdc9 |
| 4 | note crates/aien-microjob/src/lib.rs: RECEIPT_MAGIC L34, VERSION L36, RECEIPT_LEN L38, |
| 5 | note mod outcome L103-109, encode_receipt L857-883, decode_receipt L885-928; |
| 6 | note specs/microjob/SPEC.md section 5 (L162-206). Integers are big-endian. |
| 7 | note The signature (bytes 340..404 over [0,340)) is NOT verified here. |
| 8 | note Public API: fn ocmjr n ulong to long (ocrb[0,n)) -> outcome 1..5 | -reason; |
| 9 | note fn ocmjrf plen ulong to long (path ocpath[0,plen)) -> same; ocmv = outcome attempt generation. |
| 10 | note Every refusal maps to exit 43 MJR1_INVALID in callers. |
| 11 | const ocmlen ulong 404 |
| 12 | const ocmrlen long 1 |
| 13 | const ocmrmag long 2 |
| 14 | const ocmrver long 3 |
| 15 | const ocmrres long 4 |
| 16 | const ocmrout long 5 |
| 17 | const ocmratt long 6 |
| 18 | const ocmrsig long 7 |
| 19 | const ocmrzero long 8 |
| 20 | const ocmrdig long 9 |
| 21 | const ocmrvrd long 10 |
| 22 | const ocmrio long 11 |
| 23 | text ocmtx "length magic version reservedoutcome attempt signer zerohashoutput verdict io " |
| 24 | text ocmotx "completedrefused failed cancelleduncertain" |
| 25 | global ocrb uchar 512 |
| 26 | global ocpath uchar 4096 |
| 27 | global ocmv ulong 3 |
| 28 | |
| 29 | fn ocmz a ulong b ulong to bool |
| 30 | for i ulong sub b a |
| 31 | if ne get ocrb add a i 0 |
| 32 | ret false |
| 33 | end |
| 34 | end |
| 35 | ret true |
| 36 | end |
| 37 | |
| 38 | fn ocmu32 a ulong to ulong |
| 39 | v = ulong 0 |
| 40 | for i ulong 4 |
| 41 | v = add mul v 256 ulong get ocrb add a i |
| 42 | end |
| 43 | ret v |
| 44 | end |
| 45 | |
| 46 | fn ocmjr n ulong to long |
| 47 | if ne n ocmlen |
| 48 | ret ocerrset n ocmrlen |
| 49 | end |
| 50 | note magic "MJR1" |
| 51 | mg = true |
| 52 | if ne get ocrb 0 77 |
| 53 | mg = false |
| 54 | end |
| 55 | if ne get ocrb 1 74 |
| 56 | mg = false |
| 57 | end |
| 58 | if ne get ocrb 2 82 |
| 59 | mg = false |
| 60 | end |
| 61 | if ne get ocrb 3 49 |
| 62 | mg = false |
| 63 | end |
| 64 | if not mg |
| 65 | ret ocerrset 0 ocmrmag |
| 66 | end |
| 67 | if ne get ocrb 4 1 |
| 68 | ret ocerrset 4 ocmrver |
| 69 | end |
| 70 | if ne get ocrb 7 0 |
| 71 | ret ocerrset 7 ocmrres |
| 72 | end |
| 73 | if not ocmz 84 88 |
| 74 | ret ocerrset 84 ocmrres |
| 75 | end |
| 76 | if not ocmz 337 340 |
| 77 | ret ocerrset 337 ocmrres |
| 78 | end |
| 79 | oc = get ocrb 5 |
| 80 | if or lt oc 1 gt oc 5 |
| 81 | ret ocerrset 5 ocmrout |
| 82 | end |
| 83 | if eq get ocrb 6 0 |
| 84 | ret ocerrset 6 ocmratt |
| 85 | end |
| 86 | sg = get ocrb 304 |
| 87 | if and ne sg 2 ne sg 3 |
| 88 | ret ocerrset 304 ocmrsig |
| 89 | end |
| 90 | if ocmz 176 208 |
| 91 | ret ocerrset 176 ocmrzero |
| 92 | end |
| 93 | if ocmz 240 272 |
| 94 | ret ocerrset 240 ocmrzero |
| 95 | end |
| 96 | done = eq oc 1 |
| 97 | if eq done ocmz 144 176 |
| 98 | ret ocerrset 144 ocmrdig |
| 99 | end |
| 100 | if done |
| 101 | if ocmz 272 304 |
| 102 | ret ocerrset 272 ocmrvrd |
| 103 | end |
| 104 | end |
| 105 | put ocmv 0 ulong oc |
| 106 | put ocmv 1 ulong get ocrb 6 |
| 107 | put ocmv 2 ocmu32 72 |
| 108 | ret long oc |
| 109 | end |
| 110 | |
| 111 | note Read at most 512 bytes of the file named by ocpath[0,plen), then parse. |
| 112 | fn ocmjrf plen ulong to long |
| 113 | if or eq plen 0 gt plen 4096 |
| 114 | ret ocerrset 0 ocmrio |
| 115 | end |
| 116 | fd = fopen ocpath 0 plen 0 0 |
| 117 | if lt fd 0 |
| 118 | ret ocerrset 0 ocmrio |
| 119 | end |
| 120 | t = ulong 0 |
| 121 | fin = false |
| 122 | while and lt t 512 not fin bound 600 |
| 123 | r = read int fd ocrb t sub 512 t |
| 124 | if lt r 0 |
| 125 | c = fclose int fd |
| 126 | ret ocerrset t ocmrio |
| 127 | end |
| 128 | if eq r 0 |
| 129 | fin = true |
| 130 | end |
| 131 | t = add t ulong r |
| 132 | end |
| 133 | c = fclose int fd |
| 134 | ret ocmjr t |
| 135 | end |
| 136 | |
| 137 | fn ocmputrs r ulong to void |
| 138 | o = mul sub r 1 8 |
| 139 | for j ulong 8 |
| 140 | ch = get ocmtx add o j |
| 141 | if ne ch 32 |
| 142 | ocputc ch |
| 143 | end |
| 144 | end |
| 145 | end |
| 146 | |
| 147 | fn ocmputo oc ulong to void |
| 148 | o = mul sub oc 1 9 |
| 149 | for j ulong 9 |
| 150 | ch = get ocmotx add o j |
| 151 | if ne ch 32 |
| 152 | ocputc ch |
| 153 | end |
| 154 | end |
| 155 | end |
| 156 | |
| 157 | note Print ocrb[a,b) as lowercase hex. |
| 158 | fn ocmhex a ulong b ulong to void |
| 159 | for i ulong sub b a |
| 160 | v = get ocrb add a i |
| 161 | h = div v 16 |
| 162 | l = rem v 16 |
| 163 | if lt h 10 |
| 164 | ocputc add h 48 |
| 165 | else |
| 166 | ocputc add h 87 |
| 167 | end |
| 168 | if lt l 10 |
| 169 | ocputc add l 48 |
| 170 | else |
| 171 | ocputc add l 87 |
| 172 | end |
| 173 | end |
| 174 | end |