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 / core / cortex / tests / pageunit / gen.om
| 1 | note gen.om: deterministic inputs and the two helpers of the pageunit gate (tests/pageunit/run.sh), |
| 2 | note so the runner itself only invokes programs and compares bytes and exit codes. Argument 1 selects: |
| 3 | note m 900000 bytes: 7500 copies of the 120-byte line GLINE (quotes, backslashes, a tab, UTF-8) |
| 4 | note w 999999 bytes: 7999 lines of 124 quotes, then 124 quotes with no newline (every byte escaped) |
| 5 | note b 1000000 bytes of a, no newline: one line longer than a record, split by enc |
| 6 | note g 300000 bytes of q, no newline |
| 7 | note k, j, l 8000, 8001 and 10000 lines of x (8000 was the most the old enc accepted) |
| 8 | note x, y 50000 and 200000 lines "line N" (the old pinned omc refused units past 8192 texts); the |
| 9 | note unit of y is over the alarm threshold, so it is also the alarm's end-to-end control |
| 10 | note c, d ok, byte 1 or byte 127, newline: enc must exit 4 |
| 11 | note u stdin to stdout, streamed, with the first lowercase letter after the first quote changed to |
| 12 | note upper case: one byte inside the first text record of an enc unit (the mutant control) |
| 13 | note a alarm: stdin is the omc-use record of a unit compiled in usage mode (`usage` as its first |
| 14 | note line). Prints "arena=A top=T full=F alarm-at=ALARMAT" and exits 8 when F is 1 or T (the |
| 15 | note 8-byte words the unit put in the compiler's arena) is ALARMAT or more; exit 0 below it. The |
| 16 | note threshold is a stated number, not a share of A: 80 percent of the 16777216-word arena that |
| 17 | note compilers before omega-mv's run-time pools had (that arena was fixed; the later one grows, so a |
| 18 | note share of it says nothing) |
| 19 | note exit 0 ok, 2 usage, read error or no record, 6 write error, 7 mode u found no letter to change, |
| 20 | note 8 alarm. Every input is read in 65536-byte blocks and output leaves through one 1048576-byte |
| 21 | note buffer; no size limit of its own. |
| 22 | global gb uchar 1048576 |
| 23 | global gn ulong 1 |
| 24 | global gi uchar 65536 |
| 25 | global av ulong 8 |
| 26 | text GLINE "He said \"ok\"\tthen C:\\tmp\\x; café naïve 中文 Ελλάδα € 🙂 the quick brown fox jumps over the lazy dog, agai\n" |
| 27 | text KARENA "arena=" |
| 28 | text KTOP "top=" |
| 29 | text KFULL "full=" |
| 30 | text AARENA "arena=" |
| 31 | text ATOP " top=" |
| 32 | text AFULL " full=" |
| 33 | text AUSED " alarm-at=" |
| 34 | const ALARMAT ulong 13421773 |
| 35 | fn gflush to void |
| 36 | n = get gn 0 |
| 37 | o = ulong 0 |
| 38 | while lt o n bound 1048577 |
| 39 | k = write 1 gb o sub n o |
| 40 | if le k 0 |
| 41 | exit 6 |
| 42 | end |
| 43 | o = add o ulong k |
| 44 | end |
| 45 | put gn 0 0 |
| 46 | end |
| 47 | fn gput c uchar to void |
| 48 | p = get gn 0 |
| 49 | put gb p c |
| 50 | p = add p 1 |
| 51 | put gn 0 p |
| 52 | if eq p 1048576 |
| 53 | gflush |
| 54 | end |
| 55 | end |
| 56 | fn gdec v ulong to void |
| 57 | d = new uchar 20 0 |
| 58 | k = ulong 0 |
| 59 | x = v |
| 60 | while gt x 0 bound 20 |
| 61 | put d k uchar add rem x 10 48 |
| 62 | x = div x 10 |
| 63 | k = add k 1 |
| 64 | end |
| 65 | if eq k 0 |
| 66 | gput uchar 48 |
| 67 | end |
| 68 | while gt k 0 bound 20 |
| 69 | k = sub k 1 |
| 70 | gput get d k |
| 71 | end |
| 72 | end |
| 73 | fn gtimes c uchar k ulong to void |
| 74 | i = ulong 0 |
| 75 | while lt i k bound 9223372036854775807 |
| 76 | gput c |
| 77 | i = add i 1 |
| 78 | end |
| 79 | end |
| 80 | fn gtext a view uchar * to void |
| 81 | n = len a |
| 82 | i = ulong 0 |
| 83 | while lt i n bound 4097 |
| 84 | gput get a i |
| 85 | i = add i 1 |
| 86 | end |
| 87 | end |
| 88 | fn gxlines k ulong to void |
| 89 | i = ulong 0 |
| 90 | while lt i k bound 9223372036854775807 |
| 91 | gput uchar 120 |
| 92 | gput uchar 10 |
| 93 | i = add i 1 |
| 94 | end |
| 95 | end |
| 96 | fn gnlines k ulong to void |
| 97 | i = ulong 0 |
| 98 | while lt i k bound 9223372036854775807 |
| 99 | gput uchar 108 |
| 100 | gput uchar 105 |
| 101 | gput uchar 110 |
| 102 | gput uchar 101 |
| 103 | gput uchar 32 |
| 104 | gdec i |
| 105 | gput uchar 10 |
| 106 | i = add i 1 |
| 107 | end |
| 108 | end |
| 109 | fn gmutate to int |
| 110 | note st 0 before the first quote, 1 after it, 2 done |
| 111 | st = ulong 0 |
| 112 | go = ulong 1 |
| 113 | while eq go 1 bound 9223372036854775807 |
| 114 | r = read 0 gi 0 65536 |
| 115 | if lt r 0 |
| 116 | ret 2 |
| 117 | end |
| 118 | if eq r 0 |
| 119 | go = ulong 0 |
| 120 | else |
| 121 | n = ulong r |
| 122 | i = ulong 0 |
| 123 | while lt i n bound 65536 |
| 124 | c = get gi i |
| 125 | if eq st 1 |
| 126 | if ge c 97 |
| 127 | if le c 122 |
| 128 | c = uchar sub c 32 |
| 129 | st = ulong 2 |
| 130 | end |
| 131 | end |
| 132 | end |
| 133 | if eq st 0 |
| 134 | if eq c 34 |
| 135 | st = ulong 1 |
| 136 | end |
| 137 | end |
| 138 | gput c |
| 139 | i = add i 1 |
| 140 | end |
| 141 | end |
| 142 | end |
| 143 | gflush |
| 144 | if ne st 2 |
| 145 | ret 7 |
| 146 | end |
| 147 | ret 0 |
| 148 | end |
| 149 | fn kstep k view uchar * pos ulong c uchar to ulong |
| 150 | note the next match position of key k after byte c, given the current one |
| 151 | if eq c get k pos |
| 152 | ret add pos 1 |
| 153 | end |
| 154 | if eq c get k 0 |
| 155 | ret 1 |
| 156 | end |
| 157 | ret 0 |
| 158 | end |
| 159 | fn galarm to int |
| 160 | note av: 0 arena, 1 top, 2 full, 3 digit target (0 none, 1 arena, 2 top, 3 full), 4..6 key |
| 161 | note positions, 7 keys seen (bit 1 arena, 2 top) |
| 162 | go = ulong 1 |
| 163 | while eq go 1 bound 9223372036854775807 |
| 164 | r = read 0 gi 0 65536 |
| 165 | if lt r 0 |
| 166 | ret 2 |
| 167 | end |
| 168 | if eq r 0 |
| 169 | go = ulong 0 |
| 170 | else |
| 171 | n = ulong r |
| 172 | i = ulong 0 |
| 173 | while lt i n bound 65536 |
| 174 | c = get gi i |
| 175 | t = get av 3 |
| 176 | if ne t 0 |
| 177 | if ge c 48 |
| 178 | if le c 57 |
| 179 | v = get av sub t 1 |
| 180 | put av sub t 1 add mul v 10 ulong sub c 48 |
| 181 | end |
| 182 | end |
| 183 | if lt c 48 |
| 184 | put av 3 0 |
| 185 | end |
| 186 | if gt c 57 |
| 187 | put av 3 0 |
| 188 | end |
| 189 | end |
| 190 | pa = kstep KARENA get av 4 c |
| 191 | pt = kstep KTOP get av 5 c |
| 192 | pf = kstep KFULL get av 6 c |
| 193 | if eq pa len KARENA |
| 194 | put av 0 0 |
| 195 | put av 3 1 |
| 196 | put av 7 or get av 7 1 |
| 197 | pa = ulong 0 |
| 198 | end |
| 199 | if eq pt len KTOP |
| 200 | put av 1 0 |
| 201 | put av 3 2 |
| 202 | put av 7 or get av 7 2 |
| 203 | pt = ulong 0 |
| 204 | end |
| 205 | if eq pf len KFULL |
| 206 | put av 2 0 |
| 207 | put av 3 3 |
| 208 | pf = ulong 0 |
| 209 | end |
| 210 | put av 4 pa |
| 211 | put av 5 pt |
| 212 | put av 6 pf |
| 213 | i = add i 1 |
| 214 | end |
| 215 | end |
| 216 | end |
| 217 | if ne get av 7 3 |
| 218 | ret 2 |
| 219 | end |
| 220 | a = get av 0 |
| 221 | if eq a 0 |
| 222 | ret 2 |
| 223 | end |
| 224 | t = get av 1 |
| 225 | f = get av 2 |
| 226 | gtext AARENA |
| 227 | gdec a |
| 228 | gtext ATOP |
| 229 | gdec t |
| 230 | gtext AFULL |
| 231 | gdec f |
| 232 | gtext AUSED |
| 233 | gdec ALARMAT |
| 234 | gput uchar 10 |
| 235 | gflush |
| 236 | if eq f 1 |
| 237 | ret 8 |
| 238 | end |
| 239 | if ge t ALARMAT |
| 240 | ret 8 |
| 241 | end |
| 242 | ret 0 |
| 243 | end |
| 244 | fn main to int |
| 245 | if ne argcnt 2 |
| 246 | ret 2 |
| 247 | end |
| 248 | m = new uchar 8 0 |
| 249 | k = argread 1 m 0 8 |
| 250 | if lt k 1 |
| 251 | ret 2 |
| 252 | end |
| 253 | c = get m 0 |
| 254 | if eq c 117 |
| 255 | ret gmutate |
| 256 | end |
| 257 | if eq c 97 |
| 258 | ret galarm |
| 259 | end |
| 260 | if eq c 109 |
| 261 | i = ulong 0 |
| 262 | while lt i 7500 bound 7500 |
| 263 | gtext GLINE |
| 264 | i = add i 1 |
| 265 | end |
| 266 | gflush |
| 267 | ret 0 |
| 268 | end |
| 269 | if eq c 119 |
| 270 | j = ulong 0 |
| 271 | while lt j 7999 bound 7999 |
| 272 | gtimes uchar 34 124 |
| 273 | gput uchar 10 |
| 274 | j = add j 1 |
| 275 | end |
| 276 | gtimes uchar 34 124 |
| 277 | gflush |
| 278 | ret 0 |
| 279 | end |
| 280 | if eq c 98 |
| 281 | gtimes uchar 97 1000000 |
| 282 | gflush |
| 283 | ret 0 |
| 284 | end |
| 285 | if eq c 103 |
| 286 | gtimes uchar 113 300000 |
| 287 | gflush |
| 288 | ret 0 |
| 289 | end |
| 290 | if eq c 107 |
| 291 | gxlines 8000 |
| 292 | gflush |
| 293 | ret 0 |
| 294 | end |
| 295 | if eq c 106 |
| 296 | gxlines 8001 |
| 297 | gflush |
| 298 | ret 0 |
| 299 | end |
| 300 | if eq c 108 |
| 301 | gxlines 10000 |
| 302 | gflush |
| 303 | ret 0 |
| 304 | end |
| 305 | if eq c 120 |
| 306 | gnlines 50000 |
| 307 | gflush |
| 308 | ret 0 |
| 309 | end |
| 310 | if eq c 121 |
| 311 | gnlines 200000 |
| 312 | gflush |
| 313 | ret 0 |
| 314 | end |
| 315 | if eq c 99 |
| 316 | gput uchar 111 |
| 317 | gput uchar 107 |
| 318 | gput uchar 1 |
| 319 | gput uchar 10 |
| 320 | gflush |
| 321 | ret 0 |
| 322 | end |
| 323 | if eq c 100 |
| 324 | gput uchar 111 |
| 325 | gput uchar 107 |
| 326 | gput uchar 127 |
| 327 | gput uchar 10 |
| 328 | gflush |
| 329 | ret 0 |
| 330 | end |
| 331 | ret 2 |
| 332 | end |