Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/train/aien-train/tests/omegese45/contract/main.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / train / aien-train / tests / omegese45 / contract / main.om` 361 lines ยท 5591 bytes Raw Blame History 1 note SPDX-License-Identifier: AGPL-3.0-only 2 note Contract driver (aien-train #45). Build: 3 note cat native/omegese45/vocab.om native/omegese45/msg.om native/omegese45/mjr1.om \ 4 note tests/omegese45/contract/main.om | omc > oe45c 5 note stdin = one mode letter, LF, payload. Modes (see docs/omegese45/CONTRACT.md): 6 note V VALID | exit 40 INVALID 7 note N LF MASK <41 x 0|1> LF FINAL <0|1> 8 note B LF LF BIND_OK | 40 INVALID | 41 BIND_MISMATCH | 42 BIND_BOUND 9 note L LOWER | 40 | 41 BIND_MISMATCH notjob 10 note E IDS ... | exit 40 INVALID 11 note D | exit 40 INVALID 12 note T the vocab table, byte-identical to vocab.tsv 13 note J MJR1 14 note | exit 43 MJR1_INVALID 15 note Exit 2: usage (bad mode, malformed payload, output failure). 16 global ocxin uchar 16384 17 global ocxn ulong 1 18 text ocxva "VALID " 19 text ocxiv "INVALID " 20 text ocxmk "MASK " 21 text ocxfi "FINAL " 22 text ocxbo "BIND_OK\n" 23 text ocxbm "BIND_MISMATCH " 24 text ocxbb "BIND_BOUND\n" 25 text ocxlo "LOWER" 26 text ocxid "IDS" 27 text ocxmj "MJR1 " 28 text ocxmi "MJR1_INVALID " 29 text ocxkl "?GARPM" 30 31 note End of the line that starts at s (index of LF or the input length). 32 fn ocxeol s ulong to ulong 33 n = get ocxn 0 34 e = s 35 while and lt e n ne get ocxin e 10 bound 20000 36 e = add e 1 37 end 38 ret e 39 end 40 41 note Copy ocxin[a,b) into ocin; return the length (capped at the ocin size). 42 fn ocxcopy a ulong b ulong to ulong 43 c = sub b a 44 if gt c 4096 45 c = 4096 46 end 47 for i ulong c 48 put ocin i get ocxin add a i 49 end 50 ret sub b a 51 end 52 53 note Parse space-separated decimal numbers in ocxin[a,b) into ocids; -1 when malformed. 54 fn ocxnums a ulong b ulong to long 55 k = ulong 0 56 v = ulong 0 57 nd = ulong 0 58 for i ulong add sub b a 1 59 p = add a i 60 sep = true 61 if lt p b 62 if ne get ocxin p 32 63 sep = false 64 end 65 end 66 if sep 67 if eq nd 0 68 if or lt p b gt k 0 69 ret -1 70 end 71 else 72 if ge k 256 73 ret -1 74 end 75 put ocids k v 76 k = add k 1 77 v = 0 78 nd = 0 79 end 80 else 81 c = get ocxin p 82 if or lt c 48 gt c 57 83 ret -1 84 end 85 if ge nd 6 86 ret -1 87 end 88 v = add mul v 10 ulong sub c 48 89 nd = add nd 1 90 end 91 end 92 ret long k 93 end 94 95 fn ocxinv r long to void 96 w = write 1 ocxiv 0 len ocxiv 97 ocputn get ocerr 0 98 ocputc 32 99 ocputrs get ocerr 1 100 ocputc 10 101 end 102 103 fn ocxkind c uchar to ulong 104 for i ulong 5 105 if eq c get ocxkl add i 1 106 ret add i 1 107 end 108 end 109 ret 0 110 end 111 112 fn ocxmode_v to int 113 e = ocxeol 2 114 if ne e get ocxn 0 115 if ne add e 1 get ocxn 0 116 note a second line inside the payload is a control byte 117 e = get ocxn 0 118 end 119 end 120 n = ocxcopy 2 e 121 r = ocvline n 0 122 if lt r 0 123 ocxinv r 124 ret 40 125 end 126 w = write 1 ocxva 0 len ocxva 127 ocputc get ocxkl ulong r 128 ocputc 10 129 ret 0 130 end 131 132 fn ocxmode_e to int 133 e = ocxeol 2 134 if ne e get ocxn 0 135 if ne add e 1 get ocxn 0 136 e = get ocxn 0 137 end 138 end 139 n = ocxcopy 2 e 140 r = ocenc n 141 if lt r 0 142 ocxinv r 143 ret 40 144 end 145 w = write 1 ocxid 0 len ocxid 146 for i ulong ulong r 147 ocputc 32 148 ocputn get ocids i 149 end 150 ocputc 10 151 ret 0 152 end 153 154 fn ocxmode_d to int 155 e = ocxeol 2 156 k = ocxnums 2 e 157 if lt k 0 158 ret 2 159 end 160 r = ocdec ulong k 161 if lt r 0 162 ocxinv r 163 ret 40 164 end 165 w = write 1 ocout 0 ulong r 166 if ne w r 167 exit 2 168 end 169 ocputc 10 170 ret 0 171 end 172 173 fn ocxmode_n to int 174 e1 = ocxeol 2 175 if ne e1 3 176 ret 2 177 end 178 kd = ocxkind get ocxin 2 179 if eq kd 0 180 ret 2 181 end 182 e2 = ocxeol add e1 1 183 k = ocxnums add e1 1 e2 184 if lt k 0 185 ret 2 186 end 187 st = ocstart kd 188 for i ulong ulong k 189 id = get ocids i 190 if ge id ocv 191 ret 2 192 end 193 st = ocstep st id 194 end 195 c = ocmask st 196 w = write 1 ocxmk 0 len ocxmk 197 for id ulong ocv 198 ocputc add 48 get ocmk id 199 end 200 ocputc 10 201 w = write 1 ocxfi 0 len ocxfi 202 if ocfinal st 203 ocputc 49 204 else 205 ocputc 48 206 end 207 ocputc 10 208 ret 0 209 end 210 211 fn ocxmode_b to int 212 e1 = ocxeol 2 213 n = ocxcopy 2 e1 214 r = ocsetgl n 215 if lt r 0 216 ocxinv r 217 ret 40 218 end 219 e2 = ocxeol add e1 1 220 k = ocxnums add e1 1 e2 221 if ne k 1 222 ret 2 223 end 224 job = get ocids 0 225 e3 = ocxeol add e2 1 226 n = ocxcopy add e2 1 e3 227 r = ocbindl n job 228 if lt r 0 229 ocxinv r 230 ret 40 231 end 232 if eq r 41 233 w = write 1 ocxbm 0 len ocxbm 234 ocputrs get ocerr 1 235 ocputc 10 236 ret 41 237 end 238 if eq r 42 239 w = write 1 ocxbb 0 len ocxbb 240 ret 42 241 end 242 w = write 1 ocxbo 0 len ocxbo 243 ret 0 244 end 245 246 fn ocxmode_l to int 247 e = ocxeol 2 248 n = ocxcopy 2 e 249 r = oclowerl n 250 if lt r 0 251 ocxinv r 252 ret 40 253 end 254 if eq r 41 255 w = write 1 ocxbm 0 len ocxbm 256 ocputrs get ocerr 1 257 ocputc 10 258 ret 41 259 end 260 w = write 1 ocxlo 0 len ocxlo 261 for i ulong 4 262 ocputc 32 263 ocputn get oclv i 264 end 265 ocputc 10 266 ret 0 267 end 268 269 fn ocxmode_t to int 270 ocvinit 271 w = write 1 ocvtsv 0 len ocvtsv 272 if ne w long len ocvtsv 273 exit 2 274 end 275 ret 0 276 end 277 278 fn ocxmode_j to int 279 e = ocxeol 2 280 pl = sub e 2 281 if gt pl 4096 282 ret 2 283 end 284 for i ulong pl 285 put ocpath i get ocxin add 2 i 286 end 287 r = ocmjrf pl 288 if lt r 0 289 w = write 1 ocxmi 0 len ocxmi 290 ocputn get ocerr 0 291 ocputc 32 292 ocmputrs get ocerr 1 293 ocputc 10 294 ret 43 295 end 296 w = write 1 ocxmj 0 len ocxmj 297 ocmputo get ocmv 0 298 ocputc 32 299 ocputn get ocmv 1 300 ocputc 32 301 ocputn get ocmv 2 302 ocputc 32 303 ocmhex 8 40 304 ocputc 32 305 ocmhex 40 56 306 ocputc 32 307 ocmhex 144 176 308 ocputc 10 309 ret 0 310 end 311 312 fn main to int 313 t = ulong 0 314 fin = false 315 while and lt t 16384 not fin bound 20000 316 r = read 0 ocxin t sub 16384 t 317 if le r 0 318 fin = true 319 else 320 t = add t ulong r 321 end 322 end 323 put ocxn 0 t 324 if lt t 1 325 ret 2 326 end 327 if gt t 1 328 if ne get ocxin 1 10 329 ret 2 330 end 331 end 332 md = get ocxin 0 333 if eq md 84 334 ret ocxmode_t 335 end 336 if lt t 2 337 ret 2 338 end 339 if eq md 86 340 ret ocxmode_v 341 end 342 if eq md 78 343 ret ocxmode_n 344 end 345 if eq md 66 346 ret ocxmode_b 347 end 348 if eq md 76 349 ret ocxmode_l 350 end 351 if eq md 69 352 ret ocxmode_e 353 end 354 if eq md 68 355 ret ocxmode_d 356 end 357 if eq md 74 358 ret ocxmode_j 359 end 360 ret 2 361 end