Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/seed/json/tests/big.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 / seed / json / tests / big.om` 284 lines ยท 5350 bytes Raw Blame History 1 note seed/json/tests/big.om: test driver for inputs above the old 983040-byte bound (json/growing). Program 2 note mode, composed after json.om, jsonw.om and jsonf.om under one `om2` line by tests/gate-json.sh. 3 note Usage: big MODE [A] < input 4 note p [SLIM] parse with size limit SLIM (default jsmaxn); prints "OK tokens" 5 note r [CAP] parse, then write every token again through js_wtok into an output array of CAP bytes 6 note (default `2098192`); prints the JSON text, no newline 7 note n [CAP] the whole input is one number lexeme, written by js_wnumb into CAP bytes 8 note s [CAP] the whole input is the raw UTF-8 bytes of one string, written by js_wsbuf into CAP bytes 9 note f the whole input is one number lexeme: "F status bits text", status js_f64st, bits the f64 10 note in hex, text from js_wf64 11 note A refusal prints one line: js_init "INIT -code", js_parse "ERR code pos", the writer "WERR code". 12 note Exit 0 after printing; 90 a read or write error, 92 usage, 93 more input than the `4194304`-byte array. 13 note The input is read to its end, never a prefix: a full array is followed by a one-byte probe read. 14 note Stack: the input is a local of main (`4194304` bytes, the omc limit of 4 MiB of local arrays per 15 note function); the tape (`1048576` bytes) and the output (`2098192` bytes) are locals of the functions it 16 note calls; their combined live arrays remain below the 8 MiB program stack. 17 18 note ======== output ======== 19 20 note bg_w: write all of b[o .. o + n); every pass writes at least one byte or exits, so passes <= n 21 fn bg_w b view uchar * o ulong n ulong to void 22 q = ulong 0 23 while lt q n bound `9223372036854775807` 24 k = write 1 b add o q sub n q 25 if le k 0 26 exit 90 27 end 28 q = add q ulong k 29 end 30 end 31 32 fn bg_c c uchar to void 33 b = new uchar 1 0 34 put b 0 c 35 bg_w b 0 1 36 end 37 38 fn bg_dec v ulong to void 39 b = new uchar 20 0 40 k = ulong 20 41 x = v 42 for i ulong 20 43 k = sub k 1 44 put b k uchar add rem x 10 48 45 x = div x 10 46 if eq x 0 47 break 48 end 49 end 50 bg_w b k sub 20 k 51 end 52 53 fn bg_hexd v ulong to uchar 54 if lt v 10 55 ret uchar add v 48 56 end 57 ret uchar add v 87 58 end 59 60 fn bg_hex16 v ulong to void 61 h = new uchar 16 0 62 for i ulong 16 63 put h i bg_hexd and shr v mul sub 15 i 4 15 64 end 65 bg_w h 0 16 66 end 67 68 fn bg_werr c ulong to void 69 bg_c 87 70 bg_c 69 71 bg_c 82 72 bg_c 82 73 bg_c 32 74 bg_dec c 75 bg_c 10 76 end 77 78 fn bg_err c ulong p ulong to void 79 bg_c 69 80 bg_c 82 81 bg_c 82 82 bg_c 32 83 bg_dec c 84 bg_c 32 85 bg_dec p 86 bg_c 10 87 end 88 89 note ======== input and arguments ======== 90 91 note bg_read: all of stdin into src. Exit 90 on a read error, 93 when one more byte follows a full array. 92 note Every pass reads at least one byte or leaves, so passes <= len src. 93 fn bg_read src edit uchar * to ulong 94 p = ulong 0 95 while lt p len src bound `9223372036854775807` 96 k = read 0 src p sub len src p 97 if lt k 0 98 exit 90 99 end 100 if eq k 0 101 ret p 102 end 103 p = add p ulong k 104 end 105 x = new uchar 1 0 106 k = read 0 x 0 1 107 if lt k 0 108 exit 90 109 end 110 if gt k 0 111 exit 93 112 end 113 ret p 114 end 115 116 fn bg_arg i ulong d ulong to ulong 117 b = new uchar 32 0 118 if le argcnt long i 119 ret d 120 end 121 k = argread i b 0 32 122 if or le k 0 gt k 20 123 exit 92 124 end 125 v = ulong 0 126 for j ulong ulong k 127 c = get b j 128 if or lt c 48 gt c 57 129 exit 92 130 end 131 if gt v `1844674407370955160` 132 exit 92 133 end 134 v = add mul v 10 ulong sub c 48 135 end 136 ret v 137 end 138 139 fn bg_mode to uchar 140 b = new uchar 2 0 141 if lt argcnt 2 142 exit 92 143 end 144 k = argread 1 b 0 2 145 if ne k 1 146 exit 92 147 end 148 ret get b 0 149 end 150 151 note ======== modes ======== 152 153 fn bg_done ob edit uchar * to void 154 r = js_wdone ob 155 if lt r 0 156 bg_werr ulong neg r 157 ret 158 end 159 bg_w ob jswh ulong r 160 end 161 162 note bg_rw2: every token of the tape through js_wtok; one token per pass, so passes <= js_ntok tape 163 fn bg_rw2 src view uchar * tape view uint * ob edit uchar * to void 164 r = js_winit ob 165 if lt r 0 166 bg_werr ulong neg r 167 ret 168 end 169 t = ulong 0 170 while lt t js_ntok tape bound `9223372036854775807` 171 js_wtok ob src js_type tape t js_off tape t 172 t = add t 1 173 end 174 bg_done ob 175 end 176 177 fn bg_rw src view uchar * tape view uint * cap ulong to void 178 ob = new uchar `2098192` 0 179 bg_rw2 src tape part ob 0 cap 180 end 181 182 fn bg_parse src view uchar * m uchar sl ulong cap ulong to void 183 tape = new uint 262144 0 184 r = js_init tape sl 512 185 if lt r 0 186 bg_c 73 187 bg_c 78 188 bg_c 73 189 bg_c 84 190 bg_c 32 191 bg_c 45 192 bg_dec ulong neg r 193 bg_c 10 194 ret 195 end 196 r2 = js_parse src tape len src 197 if lt r2 0 198 bg_err js_err tape js_epos tape 199 ret 200 end 201 if eq m 112 202 bg_c 79 203 bg_c 75 204 bg_c 32 205 bg_dec ulong r2 206 bg_c 10 207 ret 208 end 209 bg_rw src tape cap 210 end 211 212 fn bg_wr2 src view uchar * m uchar ob edit uchar * to void 213 r = js_winit ob 214 if lt r 0 215 bg_werr ulong neg r 216 ret 217 end 218 if eq m 110 219 js_wnumb ob src 0 len src 220 else 221 js_wsbuf ob src 0 len src 222 end 223 bg_done ob 224 end 225 226 fn bg_wr src view uchar * m uchar cap ulong to void 227 ob = new uchar `2098192` 0 228 bg_wr2 src m part ob 0 cap 229 end 230 231 fn bg_f src view uchar * to void 232 fs = new long jsfs 0 233 ob = new uchar 2048 0 234 x = js_f64 src 0 fs 235 bg_c 70 236 bg_c 32 237 bg_dec js_f64st fs 238 bg_c 32 239 bg_hex16 bitcast ulong x 240 bg_c 32 241 r = js_winit ob 242 if lt r 0 243 exit 92 244 end 245 js_wf64 ob x fs 246 r2 = js_wdone ob 247 if lt r2 0 248 bg_werr ulong neg r2 249 ret 250 end 251 bg_w ob jswh ulong r2 252 bg_c 10 253 end 254 255 fn main to int 256 src = new uchar `4194304` 0 257 m = bg_mode 258 a = bg_arg 2 `2098192` 259 sl = bg_arg 2 jsmaxn 260 n = bg_read src 261 if eq m 112 262 bg_parse part src 0 n m sl `2098192` 263 ret 0 264 end 265 if eq m 114 266 if gt a `2098192` 267 exit 92 268 end 269 bg_parse part src 0 n m jsmaxn a 270 ret 0 271 end 272 if or eq m 110 eq m 115 273 if gt a `2098192` 274 exit 92 275 end 276 bg_wr part src 0 n m a 277 ret 0 278 end 279 if eq m 102 280 bg_f part src 0 n 281 ret 0 282 end 283 exit 92 284 end