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/ng/src/front.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 / ng / src / front.om` 13194 lines · 257117 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note front.om: the ng front end (Hive NG D1b; functions fe_, globals f_), a unit of seed/ng/ng.units after 3 note ir.om, so it is OM-2 code (om2 reserved words such as at, big, ops are not names here). fe_check takes 4 note an Omega unit in f_inp (main.om mode @ng front-check) and gives exactly the refusal (stderr line and 5 note exit code) and the om2 diag/check records that omc gives, but it writes no program: it is the lexer, 6 note parser and language checks of omc.om @`943d9555` (seed/omc/omc.om) with all machine code taken out. 7 note Made by seed/ng/front/rename.om (rename.map: fe_/f_ names), hand edits that carry an "omc.om ... 8 note @`943d9555` line N" note, and seed/ng/front/prune.om (prune.txt); since then edited here directly. 9 note Gated by seed/ng/front/gate-front.om against the pinned omc. Not reproduced (D6): error 12 (register 10 note pool), 14 for trap sites, 24 (branch range). Units it does not take exit 64: x86/EFI targets (D8), 11 note IR v1 units (first line ir). Runtime pools lower to descriptor-naming checked ops. An om2 fmt unit gets every 12 note refusal of omc (fmtprep, then the rest checked 13 note as OM-2) and no formatted output. 14 note Notes kept from omc.om still name the AArch64 code omc emits at each check (B.HS trap 3 and so on): 15 note those are the run-time checks and trap codes the ΩIR emission (IR.md v0.1 s7 chk.* ops, s13) must produce. 16 note Value slots (fe_alloc, kind 1 values) are omc's pool numbering without its limit; they are the values 17 note ΩIR builders replace. No heap (decision 24): every input-sized table is a region of the arena of ir.om (ar_m, 18 note no-caps 2026-11-11), the rest are fixed global pools of language or format size. 19 20 note ---- input, output, token ---- 21 global f_inlen ulong 1 22 global f_irmode ulong 1 23 global f_cur ulong 1 24 global f_line ulong 1 25 global f_tk ulong 1 26 global f_tw ulong 1 27 global f_tl ulong 1 28 global f_ts ulong 1 29 global f_tbig ulong 1 30 note f_bc: the byte fe_bskip stopped at 31 global f_bc ulong 1 32 note ---- long names (omc.om tok2 and ln_intern, no-caps arena 2026-11-11): fe_tok2 interns each word of 33 note 9..63 bytes that is not a number as the packed word 1 + 256 * index. Its low byte, 1, is below every 34 note byte a word can hold (33..255), so it never equals a name of 8 bytes or fewer or a keyword, and two 35 note words get the same packed word exactly when they are spelled the same: every table that compares packed 36 note words takes long names unchanged. Arena group long (6): f_ln_o where the spelling starts in the input 37 note (read there, never copied), f_ln_l its length, f_ln_x the index + 1 before it in its chain; group 38 note longhash (7): f_ln_h the chained hash, bucket -> index + 1 of the newest, f_lh_b its bits. f_ln_n: the 39 note count, bounded by the arena only. f_tw8: the word's first 8 bytes before interning (fe_cp_kind reads 40 note invariant there). Abstract, layout, layout-field and IR-mode names stay at 8. 41 global f_lh_b ulong 1 42 global f_ln_n ulong 1 43 global f_tw8 ulong 1 44 45 note ---- OM-2 profile (spec/omegese-om2.md, OMEGESE.md 9.13). om2 is 1 in an OM-2 unit (its first line 46 note that is not a note or blank is exactly om2, om2 diag or om2 fmt); om2m 0 compile, 1 diag, 2 fmt; 47 note om2ln/om2pos the line number and offset of that line; fmtm 1 while a unit is formatted; lbase and 48 note sbase shift reported lines and bytes back to the original input in fmt mode; tka/tkb the byte span of 49 note the last token; dexp what was being read (0 word 1 value 2 type 3 name 4 number 5 end 6 newline); 50 note dsev 0 derived, 2 unknown (an undeclared function or struct), 3 error ---- 51 global f_om2 ulong 1 52 global f_om2m ulong 1 53 global f_om2ln ulong 1 54 global f_om2pos ulong 1 55 global f_chkmod ulong 1 56 global f_chkln ulong 1 57 global f_lbase ulong 1 58 note f_lcur0: where the body pass starts (after the om2 and check leads); f_lmode 1 when main asked for 59 note @ng front-ir: the accepted unit is then lowered (fe_lout) where the check pass would exit 0 60 global f_lcur0 ulong 1 61 global f_lmode ulong 1 62 global f_sbase ulong 1 63 global f_tka ulong 1 64 global f_tkb ulong 1 65 global f_dexp ulong 1 66 global f_dsev ulong 1 67 68 note ---- executable contracts: OM-2 debug by default, release erases only validated pure predicates. 69 note Function prefixes are replayed at returns with their declaration scope, including inline frames. 70 global f_crel ulong 1 71 global f_cpure ulong 1 72 global f_cvalid ulong 1 73 global f_clim ulong 1 74 global f_crkind ulong 1 75 global f_crval ulong 1 76 global f_crtype ulong 1 77 global f_cfpos ulong 8 78 global f_cfline ulong 8 79 global f_cflim ulong 8 80 global f_cfhas ulong 8 81 global f_csnap ulong 8 82 global f_ckind ulong 1 83 84 note ---- OM-2 section 4 (unroll, inline, folding, bounds, sites). fn_inl/fn_body/fn_bln/fn_pn: a function's 85 note inline mark, its body offset and line, its parameter names. fstart: where the function being compiled 86 note starts (65536 words at most in OM-2). nmlo: names below it and at or above nglob are hidden while an 87 note inlined body is compiled (0 otherwise). fzone: open unrolled bodies and inline frames (folding is 88 note done only when it is above 0). inl and il_*: the inline frames (at most 4). ilp/nilp: the B words of 89 note an inlined ret, patched at its end. lastb/tgoc: the word after the last inlined ret's B and the last 90 note place a branch was patched to. u_*: the unrolled loop of each block. fok/fval/fty: a fold result. 91 note sitebuf/nsite: the omc-site records of om2 diag. 92 global f_nmlo ulong 1 93 global f_fzone ulong 1 94 global f_inl ulong 1 95 global f_il_cur ulong 8 96 global f_illine ulong 8 97 global f_il_ret ulong 8 98 global f_il_nn ulong 8 99 global f_il_lo ulong 8 100 global f_ilheld ulong 8 101 global f_il_ns ulong 8 102 global f_il_res ulong 8 103 global f_il_fn ulong 8 104 global f_il_p0 ulong 8 105 global f_nilp ulong 1 106 note fuel (E14, E16): the expansion fuel used by the function being compiled: an unrolled loop costs K when 107 note it starts, an inline expansion 1, at most 65536 in all (error 14) 108 global f_fuel ulong 1 109 global f_fok ulong 1 110 global f_fval ulong 1 111 global f_fty ulong 1 112 global f_nsite ulong 1 113 global f_nie ulong 1 114 115 note ---- name table (arena group names; no-caps 2026-11-11): packed name, register, type, length, kind, address -- 116 global f_nn ulong 1 117 note ---- floats in v registers: kind 9 is a float held in v(16 + pool index of x register rv), the twin of 118 note pool register rv; vsl marks each pool slot whose value lives in its twin (an f32/f64 local name, a 119 note kind 9 value), saved and loaded as D around a call. fpw asks the next value read for kind 9 (1: a new 120 note twin, 2 + r: the twin of r); fpo hands that request to the part that makes the value. A float local 121 note name (nm_fv 1) lives in its twin; its x register holds a copy only while a reader needs one. ---- 122 global f_vsl uchar 16 123 global f_fpw ulong 1 124 global f_fpo ulong 1 125 note fwv: rdval's fpw request at each nesting depth (kept here, not in a register of rdval) 126 127 note ---- function table (arena group fns; no-caps 2026-11-11): name, address (byte offset in out), return type, parameter count, 128 note per-parameter type/length/kind (6 each), name length, name offset in the input ---- 129 note x86 Linux retains the parser's sixteen logical slots in each native frame. 130 note No A64 instruction may pass emit once the explicit target is selected (error 25). 131 global f_xtarge ulong 1 132 note f_mac: 1 in a unit that begins `target macos` (ng only): the library words are keywords 133 global f_mac ulong 1 134 global f_nf ulong 1 135 global f_lastfn ulong 1 136 global f_scanni ulong 1 137 global f_ncalls ulong 1 138 139 140 note ---- compiler state ---- 141 global f_npar ulong 1 142 global f_held ulong 1 143 global f_nslot ulong 1 144 global f_curret ulong 1 145 global f_progmo ulong 1 146 global f_nglob ulong 1 147 global f_hostar ulong 1 148 global f_maptab ulong 1 149 global f_fdtab ulong 1 150 global f_stkbyt ulong 1 151 global f_dead ulong 1 152 global f_poolb ulong 1 153 154 note ---- structs (16) and fields (256). R6. nm_type 16+index, kind 6 own, 7 edit, 8 view ---- 155 global f_stname ulong 16 156 global f_st_nf uchar 16 157 global f_stcell uchar 16 158 global f_stfoff uchar 16 159 global f_nst ulong 1 160 global f_sfname ulong 256 161 global f_sftype uchar 256 162 global f_sf_len uchar 256 163 global f_sf_off uchar 256 164 global f_nsf ulong 1 165 global f_svk ulong 16 166 global f_svv ulong 16 167 global f_svt ulong 16 168 169 note ---- OM-2 section 5 external layouts (16) and their fields (256): name, SIZE, first field, field count, 170 note the cursor and line after the block's end (the body pass jumps there). Field: name, type, COUNT (0 a 171 note scalar), byte offset, 1 big-endian. lymap marks the bytes taken while a layout is read. nm_lay / 172 note fn_play: the layout (index + 1) of a layout parameter name / parameter slot, else 0 ---- 173 global f_lyname ulong 16 174 global f_lysize ulong 16 175 global f_ly_fo ulong 16 176 global f_ly_nf ulong 16 177 global f_ly_ec ulong 16 178 global f_ly_el ulong 16 179 global f_nly ulong 1 180 global f_lfname ulong 256 181 global f_lftype uchar 256 182 global f_lf_cnt ulong 256 183 global f_lf_off ulong 256 184 global f_lf_big uchar 256 185 global f_nlf ulong 1 186 global f_lymap uchar 4096 187 188 note ---- OM-2 section 5 fresh scratch (erratum E8). fn_pfr: 1 for a `fresh` parameter slot. nm_fr: the 189 note written-set slot (index + 1) a name's elements are tracked in, else 0. fz_n slots in use by the 190 note function being compiled (16), fz_len their N, fz_cur the elements definitely written on the path 191 note being compiled (bit i for element i); fz_ent / fz_thn (16 per block): the sets when the block opened 192 note and at its else. il_fz: fz_n when an inline frame opened. dobx 1: error 14 reports obligation=init ---- 193 global f_fz_n ulong 1 194 global f_fz_len ulong 16 195 global f_fz_cur ulong 16 196 global f_il_fz ulong 8 197 global f_dobx ulong 1 198 199 note ---- OM-2 section 5 abstract types (16; type 64 + index): name, its length, representation type (4 uint, 200 note 5 ulong), the preserving operations listed (1 rotr, 2 rotl, 4 and, 8 or, 16 xor), 1 when `holds NAME 201 note dup32` is declared. aw_*: the word reader of the exact-constructor test (place, packed word, length, 202 note newlines crossed before it) ---- 203 global f_abname ulong 16 204 global f_ab_len ulong 16 205 global f_abbase uchar 16 206 global f_ab_ops ulong 16 207 global f_abhold uchar 16 208 global f_nab ulong 1 209 global f_aw_p ulong 1 210 global f_aw_w ulong 1 211 global f_aw_l ulong 1 212 global f_aw_nl ulong 1 213 214 note ---- OM-2 section 6 unsized views (spec 4 slots, 6, erratum E2). An unsized `view T *` / `edit T *` 215 note name has length 0 in nm_len and its run-time element count in register nm_lr. Parameters take the 216 note registers x0..x5 by slots: an unsized array two (pointer, then count), every other parameter one 217 note (pwid, pslot); psl counts the slots of the fn line being read (6 at most, error 9). ul_k / ul_v: the 218 note count (kind 1 register / 3 number) of argument i of the call at value depth d, at d * 6 + i ---- 219 global f_psl ulong 1 220 note ---- OM-2 section 6 multi-entry units: nexp `export fn` lines (32 at most, function mode only), fn_exp 1 221 note for an exported function, expf 1 while an `export fn` line is read. With any export, words 0 .. E-1 222 note of the code are B to each export in source order and the code starts at byte 176 + 4E ---- 223 global f_nexp ulong 1 224 global f_expf ulong 1 225 226 note ======== leaf helpers ======== 227 228 note poolc: the i-th register of the pool x0..x6, x8..x15, x17 (x7 is the runtime, x16 scratch) 229 fn fe_poolc i ulong to ulong 230 if lt i 7 231 ret i 232 end 233 if lt i 15 234 ret add i 1 235 end 236 ret 17 237 end 238 239 note pwid: the parameter slots of fn table entry p: 2 for an unsized array (pointer, count), else 1 240 fn fe_pwid p ulong to ulong 241 k = ulong uchar get ar_m add get ar_rb 35 p 242 if and or eq k 2 eq k 3 eq ar_w 34 p 0 243 ret 2 244 end 245 ret 1 246 end 247 248 note unsz: 1 when name entry i is an unsized array (nm_len 0, its count in register nm_lr), else 0. A text 249 note (kind 5) of length 0 (`text e ""`) is sized: its count is the number 0 and it has no count register. 250 fn fe_unsz i ulong to ulong 251 if eq ar_c 8 i 10 252 ret 0 253 end 254 if and eq ar_w 7 i 0 ne ar_c 8 i 5 255 ret 1 256 end 257 ret 0 258 end 259 260 261 note ---- error reporting ---- 262 global f_msg uchar 65536 263 global f_mc ulong 1 264 265 note mflush: complete a diagnostic/query stdout chunk or report compiler output error 2. 266 fn fe_mflush to void 267 off = ulong 0 268 n = get f_mc 0 269 while lt off n 270 w = write 1 f_msg off sub n off 271 if le w 0 272 exit int 2 273 end 274 off = add off ulong w 275 end 276 put f_mc 0 0 277 end 278 279 fn fe_mputb b uchar to void 280 m = get f_mc 0 281 put f_msg m b 282 put f_mc 0 add m 1 283 end 284 285 fn fe_mputn v ulong to void 286 d = new uchar 20 0 287 i = ulong 0 288 x = v 289 put d 0 uchar add rem x 10 48 290 x = div x 10 291 i = add i 1 292 while gt x 0 293 put d i uchar add rem x 10 48 294 x = div x 10 295 i = add i 1 296 end 297 j = i 298 while gt j 0 299 j = sub j 1 300 fe_mputb get d j 301 end 302 end 303 304 note fail: write "omc: line N: error E" to stderr (fd 2) and exit with the code 305 fn fe_fail code ulong to void 306 put f_mc 0 0 307 fe_mputb 111 308 fe_mputb 109 309 fe_mputb 99 310 fe_mputb 58 311 fe_mputb 32 312 fe_mputb 108 313 fe_mputb 105 314 fe_mputb 110 315 fe_mputb 101 316 fe_mputb 32 317 fe_mputn add get f_line 0 get f_lbase 0 318 fe_mputb 58 319 fe_mputb 32 320 fe_mputb 101 321 fe_mputb 114 322 fe_mputb 114 323 fe_mputb 111 324 fe_mputb 114 325 fe_mputb 32 326 fe_mputn code 327 fe_mputb 10 328 w = write 2 f_msg 0 get f_mc 0 329 if ne get f_om2 0 0 330 if eq get f_om2m 0 1 331 fe_drec code 332 end 333 end 334 if and ne get f_chkmod 0 0 ne get f_chkmod 0 3 335 fe_diagrec code 336 end 337 note A full arena (error 14), and any error of a usage unit, ends with the ng-use record (ar_rec), as omc's 338 note omc-use record does 339 if or ne get ar_fl 0 0 eq get f_chkmod 0 3 340 ar_rec 2 341 end 342 exit int code 343 end 344 345 note mputw: the first n bytes (at most 8) of the little-endian packed word w 346 fn fe_mputw w ulong n ulong to void 347 i = ulong 0 348 x = w 349 while lt i n 350 fe_mputb uchar and x 255 351 x = shr x 8 352 i = add i 1 353 end 354 end 355 356 note dcol: the 1-based column of byte a in its line 357 fn fe_dcol a ulong to ulong 358 j = a 359 go = true 360 while go 361 m = ulong 0 362 while and go lt m 999999 363 if eq j 0 364 go = false 365 else 366 if eq ar_ib sub j 1 10 367 go = false 368 else 369 j = sub j 1 370 end 371 end 372 m = add m 1 373 end 374 end 375 ret add sub a j 1 376 end 377 378 note dsev_w: sev= incomplete when the failure is on the end-of-input token (or inside a text literal cut by 379 note the end), unknown for an undeclared function or struct, else error 380 fn fe_dsev_w code ulong to void 381 s = get f_dsev 0 382 if eq s 0 383 if eq get f_tk 0 3 384 s = ulong 1 385 end 386 if and eq code 22 ge get f_cur 0 get f_inlen 0 387 s = ulong 1 388 end 389 end 390 if eq s 1 391 fe_mputw `7308339910638005865` 8 392 fe_mputw 25972 2 393 ret 394 end 395 if eq s 2 396 fe_mputw `31093567915781749` 7 397 ret 398 end 399 fe_mputw `491496043109` 5 400 end 401 402 note dexp_w: expect= the class of token being read (end for an open function at the end of the input) 403 fn fe_dexp_w code ulong to void 404 e = get f_dexp 0 405 if eq code 15 406 e = ulong 5 407 end 408 if or eq code 6 eq code 8 409 e = ulong 4 410 end 411 if eq e 1 412 fe_mputw `435761734006` 5 413 ret 414 end 415 if eq e 2 416 fe_mputw `1701869940` 4 417 ret 418 end 419 if eq e 3 420 fe_mputw `1701667182` 4 421 ret 422 end 423 if eq e 4 424 fe_mputw `125779768604014` 6 425 ret 426 end 427 if eq e 5 428 fe_mputw `6581861` 3 429 ret 430 end 431 if eq e 6 432 fe_mputw `28550371718161774` 7 433 ret 434 end 435 fe_mputw `1685221239` 4 436 end 437 438 note dobl_w: obligation= from the code: 27 init, 28 ctor, 29 layout, 21 bounds, 14 growth, 12 regs, else - 439 fn fe_dobl_w code ulong to void 440 if eq code 30 441 fe_mputw `8386654075301556067` 8 442 ret 443 end 444 if eq code 27 445 fe_mputw `1953066601` 4 446 ret 447 end 448 if eq code 28 449 fe_mputw `1919906915` 4 450 ret 451 end 452 if eq code 29 453 fe_mputw `128047730221420` 6 454 ret 455 end 456 if eq code 21 457 fe_mputw `126875187113826` 6 458 ret 459 end 460 if and eq code 14 ne get f_dobx 0 0 461 fe_mputw `1953066601` 4 462 ret 463 end 464 if eq code 14 465 fe_mputw `114849429287527` 6 466 ret 467 end 468 if eq code 12 469 fe_mputw `1936156018` 4 470 ret 471 end 472 fe_mputb 45 473 end 474 475 note mputh: one byte as two lowercase hex digits 476 fn fe_mputh b ulong to void 477 hi = shr b 4 478 lo = and b 15 479 if lt hi 10 480 fe_mputb uchar add hi 48 481 else 482 fe_mputb uchar add hi 87 483 end 484 if lt lo 10 485 fe_mputb uchar add lo 48 486 else 487 fe_mputb uchar add lo 87 488 end 489 end 490 491 note drec: the om2 diag machine record after the human line (spec 1): code, sev, line (the human line), 492 note col, the half-open byte span of the token being read, expect, found (at most 32 bytes, hex), 493 note obligation, profile 494 fn fe_drec code ulong to void 495 put f_mc 0 0 496 fe_mputw `7449351137626647919` 8 497 fe_mputw `4424052638528581920` 8 498 fe_mputn code 499 fe_mputw `263979365152` 5 500 fe_dsev_w code 501 fe_mputw `67505853393952` 6 502 fe_mputn add get f_line 0 get f_lbase 0 503 a = get f_tka 0 504 b = get f_tkb 0 505 if le b a 506 b = a 507 if gt get f_cur 0 a 508 b = get f_cur 0 509 end 510 end 511 if gt b get f_inlen 0 512 b = get f_inlen 0 513 end 514 fe_mputw `263812244256` 5 515 fe_mputn fe_dcol a 516 fe_mputw `67544290456352` 6 517 fe_mputn add a get f_sbase 0 518 fe_mputb 45 519 fe_mputn add b get f_sbase 0 520 fe_mputw `4428273620941825312` 8 521 fe_dexp_w code 522 fe_mputw `17280399158765088` 7 523 if eq a b 524 fe_mputb 45 525 end 526 i = a 527 while and lt i b lt sub i a 32 528 fe_mputh ulong ar_ib i 529 i = add i 1 530 end 531 fe_mputw `8386097683628191520` 8 532 fe_mputw `1030647657` 4 533 fe_dobl_w code 534 fe_mputw `7308332183992823840` 8 535 fe_mputw `11210624683837` 6 536 w = write 2 f_msg 0 get f_mc 0 537 end 538 539 540 541 note tok_num: the word at [ts,cur) is [-]decimal, at most 20 digits, from -2^63 to 2^64 - 1 (error 6 542 note bad number, 8 out of range). tw = its raw 64 bits (a negative one as two's complement); tbig = 1 543 note when it is 2^63 or more (only a ulong holds it), else 0. As om4's TK_NUM. 544 note The float-marker scan walks the word in chunks of at most 999999 bytes: a single loop's hidden 545 note `1000000`-pass guard trapped 4 on a decimal word of `1000001` digits, which must refuse with error 6 (#671). 546 fn fe_tok_num to void 547 if ne get f_om2 0 0 548 if ne fe_tok_hex 0 549 ret 550 end 551 end 552 p = get f_ts 0 553 e = get f_cur 0 554 fl = false 555 i = p 556 while lt i e 557 c = sub e i 558 if gt c 999999 559 c = ulong 999999 560 end 561 for k ulong c 562 b = ar_ib add i k 563 if or or or eq b 46 eq b 101 eq b 69 eq b 102 564 fl = true 565 end 566 end 567 i = add i c 568 end 569 if fl 570 put f_tk 0 5 571 ret 572 end 573 minus = false 574 if eq ar_ib p 45 575 minus = true 576 p = add p 1 577 end 578 ndig = sub e p 579 if eq ndig 0 580 fe_nfail 6 581 end 582 if gt ndig 20 583 fe_nfail 6 584 end 585 v = ulong 0 586 lim = ulong `1844674407370955161` 587 i = p 588 while lt i e 589 d = sub ulong ar_ib i 48 590 if gt d 9 591 fe_nfail 6 592 end 593 if gt v lim 594 fe_nfail 8 595 end 596 if and eq v lim gt d 5 597 fe_nfail 8 598 end 599 v = add mul v 10 d 600 i = add i 1 601 end 602 half = shl ulong 1 63 603 put f_tbig 0 0 604 if minus 605 if gt v half 606 fe_nfail 8 607 end 608 put f_tw 0 sub ulong 0 v 609 else 610 if ge v half 611 put f_tbig 0 1 612 end 613 put f_tw 0 v 614 end 615 put f_tk 0 2 616 end 617 618 note tok_text: a text literal starting at the opening quote. tw = first byte offset, tl = source length 619 note (escapes not yet decoded). Ends at an unescaped '"' on the same line, followed by a blank/end. Err 22. 620 note (Loops over the input are two loops, the inner under `1000000` passes: om4 has no pass limit.) 621 fn fe_tok_text to void 622 put f_cur 0 add get f_cur 0 1 623 put f_tw 0 get f_cur 0 624 go = true 625 while go 626 n = ulong 0 627 while and go lt n 999999 628 if ge get f_cur 0 get f_inlen 0 629 fe_fail 22 630 end 631 b = ar_ib get f_cur 0 632 if eq b 10 633 fe_fail 22 634 end 635 if eq b 34 636 go = false 637 else 638 put f_cur 0 add get f_cur 0 1 639 if eq b 92 640 if ge get f_cur 0 get f_inlen 0 641 fe_fail 22 642 end 643 if eq ar_ib get f_cur 0 10 644 fe_fail 22 645 end 646 put f_cur 0 add get f_cur 0 1 647 end 648 end 649 n = add n 1 650 end 651 end 652 put f_tl 0 sub get f_cur 0 get f_tw 0 653 put f_cur 0 add get f_cur 0 1 654 put f_tk 0 4 655 if lt get f_cur 0 get f_inlen 0 656 if gt ar_ib get f_cur 0 32 657 fe_fail 22 658 end 659 end 660 end 661 662 note wscan: the first index in [p, e) whose input byte ends a word (32 or below, '(' or ')'), else e; its first 8 663 note bytes packed little-endian into tw. e is at most inlen and the input is the payload region at word 0 664 note (ar_rdin), so the bytes are read inline, a word at a time, without ar_ib's check (a call per byte made small 665 note units 15-22% slower than the fixed input buffer). The input is at most `134217728` bytes (the arena): one 666 note pass a byte. 667 fn fe_wscan p ulong e ulong to ulong 668 q = p 669 w = ulong 0 670 y = get ar_m shr p 3 671 while lt q e bound `134217729` 672 if eq and q 7 0 673 y = get ar_m shr q 3 674 end 675 b = and shr y shl and q 7 3 255 676 if or le b 32 or eq b 40 eq b 41 677 put f_tw 0 w 678 ret q 679 end 680 if lt sub q p 8 681 w = or w shl b shl sub q p 3 682 end 683 q = add q 1 684 end 685 put f_tw 0 w 686 ret q 687 end 688 689 note nlat: the first index in [p, e) whose input byte is a newline, else p when p is at or past e, else e (e at most 690 note inlen; read inline a word at a time as in fe_wscan; one pass a byte) 691 fn fe_nlat p ulong e ulong to ulong 692 q = p 693 y = get ar_m shr p 3 694 while lt q e bound `134217729` 695 if eq and q 7 0 696 y = get ar_m shr q 3 697 end 698 if eq and shr y shl and q 7 3 255 10 699 ret q 700 end 701 q = add q 1 702 end 703 ret q 704 end 705 706 note tok2: a word at cur with first byte c; packs 8 bytes into tw, sets tl and ts. A '"' is a text; a 707 note first byte '-' or a digit is a number. 708 fn fe_tok2 c uchar to void 709 if eq c 34 710 fe_tok_text 711 ret 712 end 713 put f_ts 0 get f_cur 0 714 if or eq c 40 eq c 41 715 put f_tw 0 ulong c 716 put f_tl 0 1 717 put f_cur 0 add get f_cur 0 1 718 put f_tk 0 1 719 ret 720 end 721 p = get f_cur 0 722 q = fe_wscan p get f_inlen 0 723 n = sub q p 724 w = get f_tw 0 725 put f_cur 0 q 726 put f_tw 0 w 727 put f_tl 0 n 728 put f_tw8 0 w 729 if and gt n 8 le n 63 730 if ne c 45 731 if or lt c 48 gt c 57 732 note intern the long name (the long-names notes above, omc.om ln_intern): its index k in order of first 733 note appearance; the packed word is 1 + 256 * k 734 k = fe_ln_intern get f_ts 0 n 735 put f_tw 0 add 1 shl k 8 736 end 737 end 738 end 739 note c is the word's first byte (the byte at ts, which fe_tok read): the number test needs no second read 740 f = c 741 isnum = false 742 if eq f 45 743 isnum = true 744 end 745 if and ge f 48 le f 57 746 isnum = true 747 end 748 if isnum 749 fe_tok_num 750 else 751 put f_tk 0 1 752 end 753 end 754 755 note bskip: the first index in [p, e) whose input byte is not a blank (space, tab, carriage return), else e; that 756 note byte into f_bc. Read inline a word at a time as in fe_wscan (e at most inlen); one pass a byte. 757 fn fe_bskip p ulong e ulong to ulong 758 q = p 759 y = get ar_m shr p 3 760 while lt q e bound `134217729` 761 if eq and q 7 0 762 y = get ar_m shr q 3 763 end 764 b = and shr y shl and q 7 3 255 765 if not or or eq b 32 eq b 9 eq b 13 766 put f_bc 0 b 767 ret q 768 end 769 q = add q 1 770 end 771 ret q 772 end 773 774 note tok: next word, skipping blanks (space, tab, carriage return); newline is end of line (kind 0) and 775 note bumps the line number; another byte below 32 is error 16; the end of the input is kind 3. om4 TOK. 776 fn fe_tok to void 777 q = fe_bskip get f_cur 0 get f_inlen 0 778 put f_cur 0 q 779 if ge q get f_inlen 0 780 put f_tka 0 get f_inlen 0 781 put f_tkb 0 get f_inlen 0 782 put f_tk 0 3 783 ret 784 end 785 c = uchar get f_bc 0 786 if eq c 10 787 put f_tka 0 q 788 put f_tkb 0 add q 1 789 put f_cur 0 add q 1 790 put f_line 0 add get f_line 0 1 791 put f_tk 0 0 792 ret 793 end 794 put f_tka 0 q 795 put f_tkb 0 add q 1 796 if lt c 32 797 fe_fail 16 798 end 799 put f_tka 0 q 800 put f_tkb 0 q 801 fe_tok2 c 802 put f_tkb 0 get f_cur 0 803 end 804 805 note ======== keyword lookup (original om4 KWTAB plus native host words 100..177, flock 197 and execpure 198) ======== 806 note genkw.awk describes the original om4 table only; retain the native host extension on regeneration. 807 note efi (178) is a keyword only under `target x86efi`; gate18 checks that scoped entry separately. 808 fn fe_kw w ulong to ulong 809 if eq w `7310034270740117605` 810 ret 198 811 end 812 if eq w `6584163` 813 ret 132 814 end 815 packed = or ulong 114 shl ulong 101 8 816 packed = or packed shl ulong 97 16 817 packed = or packed shl ulong 100 24 818 packed = or packed shl ulong 108 32 819 packed = or packed shl ulong 110 40 820 packed = or packed shl ulong 107 48 821 if eq w packed 822 ret 133 823 end 824 packed = or ulong 115 shl ulong 111 8 825 packed = or packed shl ulong 99 16 826 packed = or packed shl ulong 107 24 827 packed = or packed shl ulong 111 32 828 packed = or packed shl ulong 112 40 829 packed = or packed shl ulong 116 48 830 if eq w packed 831 ret 134 832 end 833 if eq w `120325193752946` 834 ret 135 835 end 836 if eq w `128017463930469` 837 ret 136 838 end 839 if eq w `28254586011020901` 840 ret 137 841 end 842 if eq w `491394459747` 843 ret 138 844 end 845 if eq w `109326067987558` 846 ret 139 847 end 848 if eq w `1952543859` 849 ret 140 850 end 851 if eq w `1802398060` 852 ret 141 853 end 854 if eq w `118122009688435` 855 ret 142 856 end 857 if eq w `431366170723` 858 ret 143 859 end 860 if eq w `32496501618073958` 861 ret 144 862 end 863 if eq w `110404104906087` 864 ret 145 865 end 866 if eq w `28263450605282663` 867 ret 146 868 end 869 if eq w `110403870025063` 870 ret 147 871 end 872 if eq w `28263390475740519` 873 ret 148 874 end 875 if eq w `499851228012` 876 ret 149 877 end 878 if eq w `7310575174812004980` 879 ret 150 880 end 881 if eq w `474450192483` 882 ret 151 883 end 884 if eq w `500152823651` 885 ret 152 886 end 887 if eq w `125796981695334` 888 ret 153 889 end 890 if eq w `28263429314995559` 891 ret 154 892 end 893 if eq w `461497265525` 894 ret 155 895 end 896 if eq w `109326135157862` 897 ret 156 898 end 899 if eq w `431215175021` 900 ret 157 901 end 902 if eq w `110404071351667` 903 ret 158 904 end 905 if eq w `28263390660289895` 906 ret 159 907 end 908 if eq w `28263390660289907` 909 ret 160 910 end 911 if eq w `431130767984` 912 ret 161 913 end 914 if eq w `111550659721072` 915 ret 162 916 end 917 if eq w `110404071351655` 918 ret 163 919 end 920 if eq w `126883592042867` 921 ret 164 922 end 923 if eq w `7959953343641905267` 924 ret 165 925 end 926 if eq w `119247140709732` 927 ret 166 928 end 929 if eq w `131277528260973` 930 ret 167 931 end 932 if eq w `31647734493634925` 933 ret 168 934 end 935 if eq w `28254586010624365` 936 ret 169 937 end 938 if eq w `7310584035480199533` 939 ret 170 940 end 941 if eq w `30518463021081956` 942 ret 171 943 end 944 if eq w `119247140124277` 945 ret 172 946 end 947 if eq w `32198529639276909` 948 ret 173 949 end 950 if eq w `127978875937133` 951 ret 174 952 end 953 if eq w `127979077263725` 954 ret 175 955 end 956 if eq w `28266723420430701` 957 ret 176 958 end 959 if eq w `28268896573219181` 960 ret 177 961 end 962 if eq w `30527267904513654` 963 ret 228 964 end 965 if eq w `31632320040101494` 966 ret 229 967 end 968 if eq w `8606486010553525878` 969 ret 230 970 end 971 if eq w `28260147925448293` 972 ret 231 973 end 974 if eq w `31932469534615158` 975 ret 232 976 end 977 if eq w `32767015939502704` 978 ret 235 979 end 980 if eq w `127979077595235` 981 ret 236 982 end 983 if eq w `127978876268643` 984 ret 237 985 end 986 if eq w `131320478265443` 987 ret 238 988 end 989 if eq w `31359662648747379` 990 ret 239 991 end 992 if eq w `31359662648747367` 993 ret 240 994 end 995 if eq w `461229747302` 996 ret 197 997 end 998 if eq w `1819242338` 999 ret 1 1000 end 1001 if eq w `491260502901` 1002 ret 2 1003 end 1004 if eq w 14453 1005 ret 2 1006 end 1007 if eq w `128034844210037` 1008 ret 3 1009 end 1010 if eq w `3551605` 1011 ret 3 1012 end 1013 if eq w `1953393013` 1014 ret 4 1015 end 1016 if eq w `3289973` 1017 ret 4 1018 end 1019 if eq w `444234427509` 1020 ret 5 1021 end 1022 if eq w `3421813` 1023 ret 5 1024 end 1025 if eq w `1702132066` 1026 ret 6 1027 end 1028 if eq w 14441 1029 ret 6 1030 end 1031 if eq w `500136110195` 1032 ret 7 1033 end 1034 if eq w `3551593` 1035 ret 7 1036 end 1037 if eq w `7630441` 1038 ret 8 1039 end 1040 if eq w `3289961` 1041 ret 8 1042 end 1043 if eq w `1735290732` 1044 ret 9 1045 end 1046 if eq w `3421801` 1047 ret 9 1048 end 1049 if eq w `6579297` 1050 ret 33 1051 end 1052 if eq w `6452595` 1053 ret 34 1054 end 1055 if eq w `7107949` 1056 ret 35 1057 end 1058 if eq w `7760228` 1059 ret 36 1060 end 1061 if eq w `7169394` 1062 ret 37 1063 end 1064 if eq w `6581857` 1065 ret 38 1066 end 1067 if eq w 29295 1068 ret 39 1069 end 1070 if eq w `7499640` 1071 ret 40 1072 end 1073 if eq w `7104627` 1074 ret 41 1075 end 1076 if eq w `7497843` 1077 ret 42 1078 end 1079 if eq w 29029 1080 ret 43 1081 end 1082 if eq w 25966 1083 ret 44 1084 end 1085 if eq w 29804 1086 ret 45 1087 end 1088 if eq w 25964 1089 ret 46 1090 end 1091 if eq w 29799 1092 ret 47 1093 end 1094 if eq w 25959 1095 ret 48 1096 end 1097 if eq w `6776174` 1098 ret 49 1099 end 1100 if eq w `7630702` 1101 ret 50 1102 end 1103 if eq w `7628135` 1104 ret 51 1105 end 1106 if eq w `7234924` 1107 ret 52 1108 end 1109 if eq w `1684104562` 1110 ret 53 1111 end 1112 if eq w `435744764535` 1113 ret 54 1114 end 1115 if eq w `1702195828` 1116 ret 55 1117 end 1118 if eq w `435728179558` 1119 ret 56 1120 end 1121 if eq w `2003134838` 1122 ret 57 1123 end 1124 if eq w `1953064037` 1125 ret 58 1126 end 1127 if eq w 28262 1128 ret 64 1129 end 1130 if eq w 28532 1131 ret 65 1132 end 1133 if eq w `6581861` 1134 ret 66 1135 end 1136 if eq w 26217 1137 ret 67 1138 end 1139 if eq w `1702063205` 1140 ret 68 1141 end 1142 if eq w `435610544247` 1143 ret 69 1144 end 1145 if eq w `431349919586` 1146 ret 70 1147 end 1148 if eq w `7499622` 1149 ret 71 1150 end 1151 if eq w `7628146` 1152 ret 72 1153 end 1154 if eq w 61 1155 ret 73 1156 end 1157 if eq w 40 1158 ret 74 1159 end 1160 if eq w 41 1161 ret 75 1162 end 1163 if eq w `1684631414` 1164 ret 76 1165 end 1166 if eq w `119165519096935` 1167 ret 78 1168 end 1169 if eq w `1954047348` 1170 ret 79 1171 end 1172 if eq w `7632240` 1173 ret 80 1174 end 1175 if eq w `1701147238` 1176 ret 81 1177 end 1178 if eq w `1953069157` 1179 ret 82 1180 end 1181 if eq w `1702129518` 1182 ret 83 1183 end 1184 if eq w `7824750` 1185 ret 84 1186 end 1187 if eq w `461195539042` 1188 ret 86 1189 end 1190 if eq w `1885434484` 1191 ret 87 1192 end 1193 if eq w `7239535` 1194 ret 77 1195 end 1196 if eq w `7308604897168158579` 1197 ret 131 1198 end 1199 if eq w `126918101919090` 1200 ret 130 1201 end 1202 if eq w `7453301735350958181` 1203 ret 124 1204 end 1205 if eq w `32481142782190962` 1206 ret 125 1207 end 1208 if eq w `491394461042` 1209 ret 126 1210 end 1211 if eq w `28263429247363435` 1212 ret 127 1213 end 1214 if eq w `32480013273033072` 1215 ret 128 1216 end 1217 if eq w `110404021020007` 1218 ret 129 1219 end 1220 if eq w `122498715312503` 1221 ret 123 1222 end 1223 if eq w `32497639802299751` 1224 ret 113 1225 end 1226 if eq w `32760384594014051` 1227 ret 114 1228 end 1229 if eq w `1684957538` 1230 ret 115 1231 end 1232 if eq w `28263429381382519` 1233 ret 116 1234 end 1235 if eq w `499851228006` 1236 ret 117 1237 end 1238 if eq w `1986225522` 1239 ret 118 1240 end 1241 if eq w `1684956531` 1242 ret 119 1243 end 1244 if eq w `32491051338263667` 1245 ret 120 1246 end 1247 if eq w `128017462948449` 1248 ret 121 1249 end 1250 if eq w `28254586010038881` 1251 ret 122 1252 end 1253 if eq w `111546465018726` 1254 ret 100 1255 end 1256 if eq w `427055215462` 1257 ret 101 1258 end 1259 if eq w `110429739705190` 1260 ret 102 1261 end 1262 if eq w `461262648166` 1263 ret 103 1264 end 1265 if eq w `33607047151054707` 1266 ret 104 1267 end 1268 if eq w `121382024472940` 1269 ret 105 1270 end 1271 if eq w `128026086171489` 1272 ret 106 1273 end 1274 if eq w `1802661734` 1275 ret 107 1276 end 1277 if eq w `431215375716` 1278 ret 108 1279 end 1280 if eq w `126918153105261` 1281 ret 109 1282 end 1283 if eq w `474148269926` 1284 ret 110 1285 end 1286 if eq w `118121959288437` 1287 ret 111 1288 end 1289 if eq w `32204027264196973` 1290 ret 112 1291 end 1292 if eq w `127970521019507` 1293 ret 85 1294 end 1295 if eq w `3289958` 1296 ret 88 1297 end 1298 if eq w `3421798` 1299 ret 89 1300 end 1301 if eq w `32777959416031586` 1302 ret 90 1303 end 1304 if eq w `500136244070` 1305 ret 91 1306 end 1307 if eq w `1935827302` 1308 ret 92 1309 end 1310 if eq w `1852403046` 1311 ret 93 1312 end 1313 if eq w `2019650918` 1314 ret 94 1315 end 1316 if eq w `112628629924211` 1317 ret 95 1318 end 1319 if eq w `7381246293360141935` 1320 ret 96 1321 end 1322 if eq w `7310870969309884259` 1323 ret 97 1324 end 1325 if eq w `7234314147887146352` 1326 ret 220 1327 end 1328 if eq w `32480013390212976` 1329 ret 221 1330 end 1331 if eq w `29118836274783603` 1332 ret 222 1333 end 1334 if eq w `7959665` 1335 ret 223 1336 end 1337 if eq w `7305804402314801251` 1338 ret 199 1339 end 1340 if eq w `8674333540260081763` 1341 ret 200 1342 end 1343 if eq w `7308604897285727600` 1344 ret 224 1345 end 1346 if eq w `6384998` 1347 ret 227 1348 end 1349 if eq w `33335428990204005` 1350 ret 233 1351 end 1352 note enlarge 244 (omc.om @`a53193cb`, run-time pools landing 1, OMEGESE 9.15): reserved in every unit, so it is 1353 note never a name (error 16) and a value that starts with it is error 9; NAME = enlarge P n is fe_s_enlarge. 1354 if eq w `28542713606205029` 1355 ret 244 1356 end 1357 note libfn 241, libptr 242 and libcall 243 are keywords only under `target macos` (a64/DESIGN.md s13); in every 1358 note other unit they are ordinary names, as omc reads them. 1359 if eq get f_mac 0 1 1360 if eq w `474164128108` 1361 ret 241 1362 end 1363 if eq w `125844427270508` 1364 ret 242 1365 end 1366 if eq w `30518463019772268` 1367 ret 243 1368 end 1369 end 1370 if eq get f_om2 0 0 1371 ret 0 1372 end 1373 ret fe_kw2 w 1374 end 1375 1376 note ======== OM-2 words (spec/omegese-om2.md): reserved only in an OM-2 unit. rotr 59, rotl 60 are 1377 note binary operators; dit 225 and scrub 226 are program-mode value words (OMEGESE 9.13.1); the rest are 1378 note statement and declaration words of later sections. ======== 1379 fn fe_kw2 w ulong to ulong 1380 if eq w `1920233330` 1381 ret 59 1382 end 1383 if eq w `1819570034` 1384 ret 60 1385 end 1386 if eq w `119212982038133` 1387 ret 181 1388 end 1389 if eq w `111524889521769` 1390 ret 182 1391 end 1392 if eq w `448612627046` 1393 ret 183 1394 end 1395 if eq w `8386654075301880417` 1396 ret 184 1397 end 1398 if eq w `1818322291` 1399 ret 185 1400 end 1401 if eq w `1852141679` 1402 ret 186 1403 end 1404 if eq w `495606067048` 1405 ret 187 1406 end 1407 if eq w `128047730221420` 1408 ret 188 1409 end 1410 if eq w `431315315046` 1411 ret 189 1412 end 1413 if eq w 29793 1414 ret 190 1415 end 1416 if eq w `111516484659564` 1417 ret 191 1418 end 1419 if eq w `6777186` 1420 ret 192 1421 end 1422 if eq w `1953653104` 1423 ret 193 1424 end 1425 if eq w `7632239` 1426 ret 194 1427 end 1428 if eq w `128034844735589` 1429 ret 195 1430 end 1431 if eq w `7565423` 1432 ret 196 1433 end 1434 if eq w `7629156` 1435 ret 225 1436 end 1437 if eq w `422877225843` 1438 ret 226 1439 end 1440 ret 0 1441 end 1442 1443 note nfail: a bad number (diag expect=number); unkfail: an undeclared function or struct (sev=unknown) 1444 fn fe_nfail code ulong to void 1445 put f_dexp 0 4 1446 fe_fail code 1447 end 1448 1449 fn fe_unkfail code ulong to void 1450 put f_dsev 0 2 1451 put f_dexp 0 3 1452 fe_fail code 1453 end 1454 1455 note lineis: the n bytes at q are the packed word w and the line ends right after them 1456 fn fe_lineis q ulong w ulong n ulong to ulong 1457 e = get f_inlen 0 1458 if gt add q n e 1459 ret 0 1460 end 1461 i = ulong 0 1462 x = w 1463 while lt i n 1464 if ne ulong ar_ib add q i and x 255 1465 ret 0 1466 end 1467 x = shr x 8 1468 i = add i 1 1469 end 1470 r = add q n 1471 if lt r e 1472 if ne ar_ib r 10 1473 ret 0 1474 end 1475 end 1476 ret 1 1477 end 1478 1479 note isnote: the word at p is note (the lexer ends a word at a blank, a parenthesis or the end) 1480 fn fe_isnote p ulong to ulong 1481 e = get f_inlen 0 1482 if gt add p 4 e 1483 ret 0 1484 end 1485 i = ulong 0 1486 x = ulong `1702129518` 1487 while lt i 4 1488 if ne ulong ar_ib add p i and x 255 1489 ret 0 1490 end 1491 x = shr x 8 1492 i = add i 1 1493 end 1494 r = add p 4 1495 if lt r e 1496 b = ar_ib r 1497 if and gt b 32 and ne b 40 ne b 41 1498 ret 0 1499 end 1500 end 1501 ret 1 1502 end 1503 1504 fn fe_chk_mode q ulong to ulong 1505 if ne fe_lineis q `461229090915` 5 0 1506 ret 1 1507 end 1508 if ne fe_lineis q `1954047342` 4 0 1509 ret 2 1510 end 1511 note usage (omc chk_mode 3, OmcNoCaps): compile as usual and write the use record in place of the output 1512 if ne fe_lineis q `435526136693` 5 0 1513 ret 3 1514 end 1515 ret 0 1516 end 1517 1518 fn fe_chk_lead to void 1519 e = get f_inlen 0 1520 p = ulong 0 1521 ln = ulong 1 1522 go = true 1523 while go 1524 m = ulong 0 1525 while and go lt m 999999 1526 q = fe_skipbl p 1527 if ge q e 1528 go = false 1529 else 1530 if eq ar_ib q 10 1531 p = add q 1 1532 ln = add ln 1 1533 else 1534 if ne fe_isnote q 0 1535 p = fe_skipln q 1536 ln = add ln 1 1537 else 1538 k = fe_chk_mode q 1539 if ne k 0 1540 put f_chkmod 0 k 1541 put f_chkln 0 ln 1542 put f_sbase 0 fe_skipln q 1543 end 1544 go = false 1545 end 1546 end 1547 end 1548 m = add m 1 1549 end 1550 end 1551 end 1552 1553 note om2lead: skip blank lines and note lines; when the next line is exactly om2 (1), om2 diag (2) or 1554 note om2 fmt (3) the unit is OM-2: om2, om2m, om2ln, om2pos. Anything else leaves the unit OM-1. 1555 fn fe_om2lead to void 1556 e = get f_inlen 0 1557 p = ulong 0 1558 ln = ulong 1 1559 if ne get f_chkmod 0 0 1560 p = get f_sbase 0 1561 ln = add get f_chkln 0 1 1562 end 1563 go = true 1564 while go 1565 m = ulong 0 1566 while and go lt m 999999 1567 q = fe_skipbl p 1568 if ge q e 1569 go = false 1570 else 1571 if eq ar_ib q 10 1572 p = add q 1 1573 ln = add ln 1 1574 else 1575 if ne fe_isnote q 0 1576 p = fe_skipln q 1577 ln = add ln 1 1578 else 1579 r = ulong 0 1580 if eq q p 1581 if ne fe_lineis q `3304815` 3 0 1582 r = ulong 1 1583 end 1584 if ne fe_lineis q `7449351137405332847` 8 0 1585 r = ulong 2 1586 end 1587 if ne fe_lineis q `32771382692703599` 7 0 1588 r = ulong 3 1589 end 1590 if eq r 0 1591 r = fe_cp_mode q 1592 end 1593 end 1594 if ne r 0 1595 put f_om2 0 1 1596 put f_om2m 0 sub r 1 1597 put f_om2ln 0 ln 1598 put f_om2pos 0 q 1599 end 1600 go = false 1601 end 1602 end 1603 end 1604 m = add m 1 1605 end 1606 end 1607 end 1608 1609 1610 note fmttail: blank lines at the end of the rest (n bytes) are error 6, at the first such line 1611 fn fe_fmttail n ulong to void 1612 lnb = ulong 0 1613 lnl = ulong 1 1614 ln = ulong 1 1615 i = ulong 0 1616 go = true 1617 while go 1618 m = ulong 0 1619 while and go lt m 999999 1620 if ge i n 1621 go = false 1622 else 1623 b = ar_ib i 1624 if eq b 10 1625 ln = add ln 1 1626 else 1627 if and ne b 32 ne b 9 1628 lnb = add i 1 1629 lnl = ln 1630 end 1631 end 1632 i = add i 1 1633 end 1634 m = add m 1 1635 end 1636 end 1637 bad = false 1638 if eq lnb 0 1639 if gt n 0 1640 bad = true 1641 lnl = ulong 0 1642 end 1643 end 1644 k = lnb 1645 fl = n 1646 go = true 1647 while go 1648 m = ulong 0 1649 while and go lt m 999999 1650 if ge k n 1651 go = false 1652 else 1653 if eq ar_ib k 10 1654 fl = k 1655 go = false 1656 end 1657 k = add k 1 1658 end 1659 m = add m 1 1660 end 1661 end 1662 if lt add fl 1 n 1663 bad = true 1664 end 1665 if bad 1666 put f_line 0 add lnl 1 1667 put f_tka 0 lnb 1668 put f_tkb 0 lnb 1669 fe_fail 6 1670 end 1671 end 1672 1673 fn fe_fmtprep to void 1674 if ne get f_om2pos 0 0 1675 put f_line 0 get f_om2ln 0 1676 put f_tka 0 get f_om2pos 0 1677 put f_tkb 0 get f_om2pos 0 1678 fe_fail 16 1679 end 1680 e = get f_inlen 0 1681 ln = ulong 1 1682 i = ulong 0 1683 go = true 1684 while go 1685 m = ulong 0 1686 while and go lt m 999999 1687 if ge i e 1688 go = false 1689 else 1690 b = ar_ib i 1691 if eq b 13 1692 put f_line 0 ln 1693 put f_tka 0 i 1694 put f_tkb 0 add i 1 1695 fe_fail 6 1696 end 1697 if eq b 10 1698 ln = add ln 1 1699 end 1700 i = add i 1 1701 end 1702 m = add m 1 1703 end 1704 end 1705 r = fe_skipln get f_om2pos 0 1706 put f_lbase 0 get f_om2ln 0 1707 put f_sbase 0 r 1708 n = sub e r 1709 j = ulong 0 1710 go = true 1711 while go 1712 m = ulong 0 1713 while and go lt m 999999 1714 if ge j n 1715 go = false 1716 else 1717 ar_bp 0 j ar_ib add r j 1718 j = add j 1 1719 end 1720 m = add m 1 1721 end 1722 end 1723 put f_inlen 0 n 1724 fe_fmttail n 1725 put f_om2 0 0 1726 put f_om2m 0 0 1727 put f_om2ln 0 0 1728 fe_om2lead 1729 if eq get f_om2m 0 2 1730 put f_line 0 get f_om2ln 0 1731 put f_tka 0 get f_om2pos 0 1732 put f_tkb 0 get f_om2pos 0 1733 fe_fail 16 1734 end 1735 end 1736 1737 1738 1739 note tok_hex (OM-2): 0x and 1..16 digits 0-9 a-f is the unsigned value (tk 2, tbig as tok_num). A - before 1740 note 0x, 0X, no digits, more than 16 digits, an uppercase or any other character is error 6. 0 when the 1741 note word is not a hex literal. 1742 fn fe_tok_hex to ulong 1743 p = get f_ts 0 1744 e = get f_cur 0 1745 if eq ar_ib p 45 1746 q = add p 1 1747 if lt add q 1 e 1748 if eq ar_ib q 48 1749 c = ar_ib add q 1 1750 if or eq c 120 eq c 88 1751 fe_nfail 6 1752 end 1753 end 1754 end 1755 ret 0 1756 end 1757 if ge add p 1 e 1758 ret 0 1759 end 1760 if ne ar_ib p 48 1761 ret 0 1762 end 1763 c = ar_ib add p 1 1764 if eq c 88 1765 fe_nfail 6 1766 end 1767 if ne c 120 1768 ret 0 1769 end 1770 n = sub e add p 2 1771 if eq n 0 1772 fe_nfail 6 1773 end 1774 if gt n 16 1775 fe_nfail 6 1776 end 1777 v = ulong 0 1778 i = add p 2 1779 while lt i e 1780 d = ulong ar_ib i 1781 if and ge d 48 le d 57 1782 v = or shl v 4 sub d 48 1783 else 1784 if and ge d 97 le d 102 1785 v = or shl v 4 sub d 87 1786 else 1787 fe_nfail 6 1788 end 1789 end 1790 i = add i 1 1791 end 1792 put f_tbig 0 shr v 63 1793 put f_tw 0 v 1794 put f_tk 0 2 1795 ret 1 1796 end 1797 1798 note ---- float literals: a token is the decimal value fsgn * fnd * 10^fp10, fsuf 0 none / 1 f32 / 2 f64. 1799 note fg_* hold the working state of the one literal being converted (see fparse/fbits/fnorm/fgen). 1800 global f_fsgn ulong 1 1801 global f_fnd ulong 1 1802 global f_fp10 long 1 1803 global f_fsuf ulong 1 1804 global f_fg_fl ulong 1 1805 global f_fgseen ulong 1 1806 global f_fg_ex long 1 1807 global f_fgesig long 1 1808 global f_fg_ed ulong 1 1809 global f_fg_ty ulong 1 1810 global f_fg_e long 1 1811 global f_fg_q ulong 1 1812 global f_fg_m ulong 1 1813 global f_fg_stk ulong 1 1814 global f_fbn ulong 80 1815 1816 note ======== float literals: decimal text to IEEE-754 binary32/binary64 ======== 1817 note The literal is fnd * 10^fp10 = A / D with A = fnd * 10^max(fp10,0) and D = 10^max(-fp10,0), both 1818 note held exactly as 40 32-bit limbs in fbn (A at 0, D at 40). The smaller of the two is shifted to the 1819 note other's bit length, then restoring division yields the first 64 quotient bits (fg_m, leading bit 1820 note set) and a remainder whose nonzero-ness is the sticky flag (fg_stk); froundsh rounds that exact 1821 note truncation once to nearest even and fpack packs it, subnormals included (#1024: the old converter 1822 note scaled one factor of ten at a time and dropped bits at every step). fp10 < -343 means a value 1823 note below (2^63-1)*10^-344 < 2^-1075, signed zero; fp10 > 308 means at least 10^309, above the 1824 note binary64 maximum (error 8). So A and D never exceed 1141 bits. 1825 1826 note blen: bits needed for x (0 for zero) 1827 fn fe_blen x ulong to ulong 1828 n = ulong 0 1829 while ne x 0 1830 x = shr x 1 1831 n = add n 1 1832 end 1833 ret n 1834 end 1835 1836 note fparse: read the literal text inp[pos, pos+len) into fsgn, fnd, fp10, fsuf (0 none, 1 f32, 2 f64). 1837 note Grammar: [-]digits[.digits][(e|E)[+|-]digits][f32|f64]. At most 2^63-1 significant digits 1838 note (error 8), a dot with no digit after it is error 6, |exponent| <= 999 (error 8). 1839 note The digit scans here and in fexp run as nested 999999-pass loops: a literal of more than `1000000` 1840 note zero digits trapped 4 in a single loop's hidden `1000000`-pass guard (#965). 1841 fn fe_fparse pos ulong ln ulong to void 1842 p = pos 1843 e = add pos ln 1844 put f_fsgn 0 0 1845 put f_fsuf 0 0 1846 put f_fnd 0 0 1847 put f_fg_fl 0 0 1848 put f_fgseen 0 0 1849 if eq ar_ib p 45 1850 put f_fsgn 0 1 1851 p = add p 1 1852 end 1853 go = true 1854 while go 1855 pos = ulong 0 1856 while and go lt pos 999999 1857 if ge p e 1858 go = false 1859 else 1860 d = sub ulong ar_ib p 48 1861 if le d 9 1862 if gt get f_fnd 0 `922337203685477580` 1863 fe_fail 8 1864 end 1865 if eq get f_fnd 0 `922337203685477580` 1866 if gt d 7 1867 fe_fail 8 1868 end 1869 end 1870 put f_fnd 0 add mul get f_fnd 0 10 d 1871 if ne get f_fgseen 0 0 1872 put f_fg_fl 0 add get f_fg_fl 0 1 1873 end 1874 p = add p 1 1875 else 1876 go = false 1877 if eq ar_ib p 46 1878 if eq get f_fgseen 0 0 1879 put f_fgseen 0 1 1880 p = add p 1 1881 go = true 1882 end 1883 end 1884 end 1885 end 1886 pos = add pos 1 1887 end 1888 end 1889 if and ne get f_fgseen 0 0 eq get f_fg_fl 0 0 1890 fe_fail 6 1891 end 1892 p = fe_fexp p e 1893 p = fe_fsufx p e 1894 if ne p e 1895 fe_fail 6 1896 end 1897 x = mul get f_fgesig 0 get f_fg_ex 0 1898 put f_fp10 0 sub x long get f_fg_fl 0 1899 end 1900 1901 note fexp: the exponent of the literal, if present: fg_ex, fg_esign, fg_ed. Returns the new position. 1902 fn fe_fexp p ulong e ulong to ulong 1903 put f_fg_ex 0 0 1904 put f_fgesig 0 1 1905 if and lt p e or eq ar_ib p 101 eq ar_ib p 69 1906 p = add p 1 1907 if lt p e 1908 if or eq ar_ib p 43 eq ar_ib p 45 1909 if eq ar_ib p 45 1910 put f_fgesig 0 -1 1911 end 1912 p = add p 1 1913 end 1914 end 1915 put f_fg_ed 0 0 1916 go = true 1917 while go 1918 m = ulong 0 1919 while and go lt m 999999 1920 if ge p e 1921 go = false 1922 else 1923 d = sub ulong ar_ib p 48 1924 if gt d 9 1925 go = false 1926 else 1927 put f_fg_ex 0 mul get f_fg_ex 0 10 1928 put f_fg_ex 0 add get f_fg_ex 0 long d 1929 if gt get f_fg_ex 0 999 1930 fe_fail 8 1931 end 1932 put f_fg_ed 0 add get f_fg_ed 0 1 1933 p = add p 1 1934 end 1935 end 1936 m = add m 1 1937 end 1938 end 1939 if eq get f_fg_ed 0 0 1940 fe_fail 6 1941 end 1942 end 1943 ret p 1944 end 1945 1946 note fsufx: the optional f32/f64 suffix: fsuf 1 or 2. Returns the new position. 1947 fn fe_fsufx p ulong e ulong to ulong 1948 if lt p e 1949 r = sub e p 1950 if ne r 3 1951 fe_fail 6 1952 end 1953 if ne ar_ib p 102 1954 fe_fail 6 1955 end 1956 if and eq ar_ib add p 1 51 eq ar_ib add p 2 50 1957 put f_fsuf 0 1 1958 else 1959 if and eq ar_ib add p 1 54 eq ar_ib add p 2 52 1960 put f_fsuf 0 2 1961 else 1962 fe_fail 6 1963 end 1964 end 1965 p = add p 3 1966 end 1967 ret p 1968 end 1969 1970 note fbmul: limbs fbn[o, o+40) times k (k < 2^32, so each limb step fits 64 bits); the product must fit 1971 note in 40 limbs. Returns its bit length, so fbmul o 1 only measures. 1972 fn fe_fbmul o ulong k ulong to ulong 1973 c = ulong 0 1974 t = ulong 0 1975 i = ulong 0 1976 while lt i 40 1977 j = add o i 1978 v = add mul get f_fbn j k c 1979 put f_fbn j and v `4294967295` 1980 c = shr v 32 1981 if ne and v `4294967295` 0 1982 t = add mul i 32 fe_blen and v `4294967295` 1983 end 1984 i = add i 1 1985 end 1986 ret t 1987 end 1988 1989 note fbpow: fbn[o, o+40) times b^n (b 2 or 10), in factors that stay below 2^32. 1990 fn fe_fbpow o ulong b ulong n ulong to void 1991 while gt n 0 1992 m = ulong 1 1993 c = ulong 0 1994 while and lt c n le mul m b `4294967295` 1995 m = mul m b 1996 c = add c 1 1997 end 1998 t = fe_fbmul o m 1999 n = sub n c 2000 end 2001 end 2002 2003 note fbsub: one restoring-division step. If A >= D then A = A - D and 1, else A is kept and 0. 2004 fn fe_fbsub to ulong 2005 r = ulong 2 2006 i = ulong 40 2007 while and gt i 0 eq r 2 2008 i = sub i 1 2009 a = get f_fbn i 2010 d = get f_fbn add i 40 2011 if lt a d 2012 r = ulong 0 2013 end 2014 if gt a d 2015 r = ulong 1 2016 end 2017 end 2018 if eq r 0 2019 ret 0 2020 end 2021 b = ulong 0 2022 i = ulong 0 2023 while lt i 40 2024 v = sub sub get f_fbn i get f_fbn add i 40 b 2025 put f_fbn i and v `4294967295` 2026 b = shr v 63 2027 i = add i 1 2028 end 2029 ret 1 2030 end 2031 2032 note froundsh: round fg_m right by sh bits to fg_q, nearest even; the guard and every lower bit 2033 note (plus fg_stk) decide. sh may be 64 (then q is zero and bit 63 is the guard). 2034 fn fe_froundsh sh ulong to void 2035 m = get f_fg_m 0 2036 q = ulong 0 2037 guard = ulong 0 2038 lost = ulong 0 2039 if eq sh 0 2040 q = m 2041 else 2042 if ge sh 64 2043 guard = shr m 63 2044 lost = and m `9223372036854775807` 2045 else 2046 q = shr m sh 2047 guard = and shr m sub sh 1 1 2048 if gt sub sh 1 0 2049 lost = and m sub shl 1 sub sh 1 1 2050 end 2051 end 2052 end 2053 sticky = or get f_fg_stk 0 lost 2054 if ne guard 0 2055 if or ne sticky 0 eq and q 1 1 2056 q = add q 1 2057 end 2058 end 2059 put f_fg_q 0 q 2060 end 2061 2062 note fpack: fg_m/fg_e to IEEE bits of fg_ty, including subnormals; a literal that rounds to infinity 2063 note is refused (error 8). 2064 fn fe_fpack to ulong 2065 p = ulong 53 2066 bias = long 1023 2067 maxe = long 2047 2068 emin = long -1022 2069 mb = ulong 52 2070 w = ulong 64 2071 if eq get f_fg_ty 0 10 2072 p = ulong 24 2073 bias = long 127 2074 maxe = long 255 2075 emin = long -126 2076 mb = ulong 23 2077 w = ulong 32 2078 end 2079 e = add get f_fg_e 0 63 2080 if ge e emin 2081 sh = sub 64 p 2082 fe_froundsh sh 2083 q = get f_fg_q 0 2084 if eq q shl 1 p 2085 q = shr q 1 2086 e = add e 1 2087 end 2088 E = add e bias 2089 if ge E maxe 2090 fe_fail 8 2091 end 2092 q = and q sub shl 1 sub p 1 1 2093 q = or q shl ulong E mb 2094 q = or q shl get f_fsgn 0 sub w 1 2095 ret q 2096 end 2097 k = ulong sub emin e 2098 sh = add sub 64 p k 2099 if gt sh 64 2100 ret shl get f_fsgn 0 sub w 1 2101 end 2102 fe_froundsh sh 2103 q = get f_fg_q 0 2104 q = or q shl get f_fsgn 0 sub w 1 2105 ret q 2106 end 2107 2108 note fbits: the parsed literal as IEEE bits of type ty (10 f32, 11 f64). Zero keeps the sign (-0.0). 2109 fn fe_fbits ty ulong to ulong 2110 put f_fg_ty 0 ty 2111 p = get f_fp10 0 2112 if or eq get f_fnd 0 0 lt p -343 2113 w = ulong 64 2114 if eq ty 10 2115 w = ulong 32 2116 end 2117 b = ulong 0 2118 if ne get f_fsgn 0 0 2119 b = shl ulong 1 sub w 1 2120 end 2121 ret b 2122 end 2123 if gt p 308 2124 fe_fail 8 2125 end 2126 i = ulong 0 2127 while lt i 80 2128 put f_fbn i 0 2129 i = add i 1 2130 end 2131 put f_fbn 0 and get f_fnd 0 `4294967295` 2132 put f_fbn 1 shr get f_fnd 0 32 2133 put f_fbn 40 1 2134 if gt p 0 2135 fe_fbpow 0 10 ulong p 2136 else 2137 fe_fbpow 40 10 ulong sub 0 p 2138 end 2139 a = fe_fbmul 0 1 2140 d = fe_fbmul 40 1 2141 e = long 0 2142 if lt a d 2143 fe_fbpow 0 2 sub d a 2144 e = sub 0 long sub d a 2145 else 2146 fe_fbpow 40 2 sub a d 2147 e = long sub a d 2148 end 2149 q = ulong 0 2150 while lt q `9223372036854775808` 2151 q = or shl q 1 fe_fbsub 2152 a = fe_fbmul 0 2 2153 e = sub e 1 2154 end 2155 put f_fg_m 0 q 2156 put f_fg_e 0 add e 1 2157 put f_fg_stk 0 fe_fbmul 0 1 2158 ret fe_fpack 2159 end 2160 2161 note fsizeof: sizeof T, or sizeof S for a struct: bytes. foffset: offsetof S f: the field's byte offset 2162 note in the struct's 8-byte-cell layout. Both are compile-time constants of type ulong. 2163 fn fe_fsizeof dst ulong to void 2164 sid = fe_peek_struct 2165 if ne sid 0 2166 si = sub sid 1 2167 n = ulong get f_stcell si 2168 fe_vdone 3 mul n 8 5 2169 ret 2170 end 2171 t = fe_typeword 2172 if ge t 64 2173 fe_fail 7 2174 end 2175 v = shl 1 fe_tlog t 2176 fe_vdone 3 v 5 2177 end 2178 2179 fn fe_foffset dst ulong to void 2180 fe_tok 2181 if ne get f_tk 0 1 2182 fe_fail 16 2183 end 2184 if gt get f_tl 0 63 2185 fe_fail 13 2186 end 2187 sid = fe_findstruct get f_tw 0 2188 if eq sid 0 2189 fe_unkfail 3 2190 end 2191 fe_tok 2192 if ne get f_tk 0 1 2193 fe_fail 16 2194 end 2195 if gt get f_tl 0 63 2196 fe_fail 13 2197 end 2198 f = fe_findfield sub sid 1 get f_tw 0 2199 if eq f 0 2200 fe_fail 3 2201 end 2202 off = ulong get f_sf_off sub f 1 2203 fe_vdone 3 mul off 8 5 2204 end 2205 2206 note fspan: a deferred literal stored as pos*`16777216`+len. Input stays below 2^23 bytes, so neither part 2207 note overflows its field; the old pos*64+len read a literal of 64 or more characters from the wrong span (#965). 2208 fn fe_fspan ty ulong packed ulong to ulong 2209 fe_fparse div packed `16777216` rem packed `16777216` 2210 ret fe_fbits ty 2211 end 2212 2213 fn fe_isfloat t ulong to ulong 2214 if or eq t 10 eq t 11 2215 ret 1 2216 end 2217 ret 0 2218 end 2219 2220 note ======== om4's small tables, as functions ======== 2221 note twid: width in bits by type 0..9 (bool 1; uchar ushort uint ulong; byte short int long) 2222 fn fe_twid t ulong to ulong 2223 if eq t 13 2224 ret 64 2225 end 2226 if eq t 10 2227 ret 32 2228 end 2229 if eq t 11 2230 ret 64 2231 end 2232 if eq t 1 2233 ret 1 2234 end 2235 if or eq t 2 eq t 6 2236 ret 8 2237 end 2238 if or eq t 3 eq t 7 2239 ret 16 2240 end 2241 if or eq t 4 eq t 8 2242 ret 32 2243 end 2244 if or eq t 5 eq t 9 2245 ret 64 2246 end 2247 ret 0 2248 end 2249 2250 note tlog: log2 of the element size by type 2251 fn fe_tlog t ulong to ulong 2252 if eq t 13 2253 ret 3 2254 end 2255 if eq t 10 2256 ret 2 2257 end 2258 if eq t 11 2259 ret 3 2260 end 2261 if or eq t 3 eq t 7 2262 ret 1 2263 end 2264 if or eq t 4 eq t 8 2265 ret 2 2266 end 2267 if or eq t 5 eq t 9 2268 ret 3 2269 end 2270 ret 0 2271 end 2272 2273 note regidx: the pool index of register r (the inverse of poolc; 255 for x7 and x16) 2274 fn fe_regidx r ulong to ulong 2275 if lt r 7 2276 ret r 2277 end 2278 if eq r 7 2279 ret 255 2280 end 2281 if lt r 16 2282 ret sub r 1 2283 end 2284 if eq r 16 2285 ret 255 2286 end 2287 ret 15 2288 end 2289 2290 note conds: the condition for eq ne lt le gt ge (i = 2 (op - 43) + 1 when signed): EQ 0, NE 1, LO 3 / LT 11, 2291 note LS 9 / LE 13, HI 8 / GT 12, HS 2 / GE 10 (Arm ARM Table C1-1). The opposite condition is cond xor 1. 2292 fn fe_conds i ulong to ulong 2293 if lt i 2 2294 ret 0 2295 end 2296 if lt i 4 2297 ret 1 2298 end 2299 if eq i 4 2300 ret 3 2301 end 2302 if eq i 5 2303 ret 11 2304 end 2305 if eq i 6 2306 ret 9 2307 end 2308 if eq i 7 2309 ret 13 2310 end 2311 if eq i 8 2312 ret 8 2313 end 2314 if eq i 9 2315 ret 12 2316 end 2317 if eq i 10 2318 ret 2 2319 end 2320 ret 10 2321 end 2322 2323 2324 2325 note ---- block stack (arena group blocks; no-caps 2026-11-11): kind (1 if, 2 else, 3 while, 4 for), branch to patch, loop head, loop 2326 note register, its type, names and held pool slots to restore at end, then-part ended (for else) ---- 2327 global f_nb ulong 1 2328 global f_curfn ulong 1 2329 global f_nbrk ulong 1 2330 global f_ncont ulong 1 2331 fn fe_dcat_w code ulong to void 2332 if or or eq code 4 eq code 6 eq code 16 2333 fe_mputw `9104236865280339` 7 2334 ret 2335 end 2336 if or or eq code 7 eq code 11 eq code 19 2337 fe_mputw `138601847124` 5 2338 ret 2339 end 2340 if or eq code 17 eq code 18 2341 fe_mputw `138903768134` 5 2342 ret 2343 end 2344 if or or eq code 3 eq code 10 eq code 13 2345 fe_mputw `138601644366` 5 2346 ret 2347 end 2348 if or or or eq code 12 eq code 14 eq code 23 eq code 24 2349 fe_mputw `6436850320626696515` 8 2350 fe_mputb 32 2351 ret 2352 end 2353 if or eq code 8 eq code 21 2354 fe_mputw `35481921143122` 6 2355 ret 2356 end 2357 if or or or eq code 27 eq code 28 eq code 29 eq code 30 2358 fe_mputw `6071768544483102531` 8 2359 fe_mputb 32 2360 ret 2361 end 2362 fe_mputw `9104236865280339` 7 2363 end 2364 2365 fn fe_dty_w t ulong to void 2366 if eq t 1 2367 fe_mputw `1819242338` 4 2368 ret 2369 end 2370 if eq t 2 2371 fe_mputw `491260502901` 5 2372 ret 2373 end 2374 if eq t 3 2375 fe_mputw `128034844210037` 6 2376 ret 2377 end 2378 if eq t 4 2379 fe_mputw `1953393013` 4 2380 ret 2381 end 2382 if eq t 5 2383 fe_mputw `444234427509` 5 2384 ret 2385 end 2386 if eq t 6 2387 fe_mputw `1702132066` 4 2388 ret 2389 end 2390 if eq t 7 2391 fe_mputw `500136110195` 5 2392 ret 2393 end 2394 if eq t 8 2395 fe_mputw `7630441` 3 2396 ret 2397 end 2398 if eq t 9 2399 fe_mputw `1735290732` 4 2400 ret 2401 end 2402 if eq t 10 2403 fe_mputw `3289958` 3 2404 ret 2405 end 2406 if eq t 11 2407 fe_mputw `3421798` 3 2408 ret 2409 end 2410 if eq t 12 2411 fe_mputw `1684631414` 4 2412 ret 2413 end 2414 if eq t 13 2415 fe_mputb 113 2416 fe_mputb 116 2417 fe_mputb 121 2418 ret 2419 end 2420 fe_mputw `2003134838` 4 2421 end 2422 2423 fn fe_dname_kind i ulong to void 2424 k = ulong uchar get ar_m add get ar_rb 8 i 2425 if eq k 4 2426 fe_mputw `119165519096935` 6 2427 ret 2428 end 2429 if eq k 5 2430 fe_mputw `1954047348` 4 2431 ret 2432 end 2433 if eq k 9 2434 fe_mputw `500152823651` 5 2435 ret 2436 end 2437 if or eq k 2 eq k 8 2438 fe_mputw `2003134838` 4 2439 ret 2440 end 2441 if or eq k 3 eq k 7 2442 fe_mputw `1953064037` 4 2443 ret 2444 end 2445 if ne get f_curfn 0 0 2446 f = sub get f_curfn 0 1 2447 np = ulong uchar get ar_m add get ar_rb 22 f 2448 endp = add get f_nglob 0 np 2449 if and ge i get f_nglob 0 lt i endp 2450 fe_mputw `469786321264` 5 2451 ret 2452 end 2453 end 2454 fe_mputw `465490374508` 5 2455 end 2456 2457 fn fe_mput_name w ulong to void 2458 if eq and w 255 1 2459 k = shr w 8 2460 i = ulong 0 2461 while lt i ulong ar_c 17 k 2462 o = get ar_m add get ar_rb 16 k 2463 fe_mputb ar_ib add o i 2464 i = add i 1 2465 end 2466 ret 2467 end 2468 x = w 2469 go = true 2470 while go 2471 if eq x 0 2472 go = false 2473 else 2474 b = and x 255 2475 if eq b 0 2476 go = false 2477 else 2478 fe_mputb uchar b 2479 x = shr x 8 2480 end 2481 end 2482 end 2483 end 2484 2485 2486 fn fe_mput_tok a ulong b ulong to void 2487 if eq a b 2488 if eq get f_tk 0 3 2489 fe_mputw `6713189` 3 2490 ret 2491 end 2492 fe_mputb 45 2493 ret 2494 end 2495 i = a 2496 while and lt i b lt sub i a 16 2497 c = ulong ar_ib i 2498 if and gt c 32 lt c 127 2499 fe_mputb uchar c 2500 else 2501 fe_mputh c 2502 end 2503 i = add i 1 2504 end 2505 end 2506 2507 fn fe_diagrec code ulong to void 2508 put f_mc 0 0 2509 fe_mputw `7594244768023276911` 8 2510 fe_mputw `11207551510369` 6 2511 if eq get f_om2 0 0 2512 fe_mputw `3239279` 3 2513 fe_mputb 32 2514 else 2515 fe_mputw `3304815` 3 2516 fe_mputb 32 2517 end 2518 fe_dcat_w code 2519 a = get f_tka 0 2520 b = get f_tkb 0 2521 if le b a 2522 b = a 2523 if gt get f_cur 0 a 2524 b = get f_cur 0 2525 end 2526 end 2527 if gt b get f_inlen 0 2528 b = get f_inlen 0 2529 end 2530 sa = a 2531 sb = b 2532 if ge sa get f_sbase 0 2533 sa = sub sa get f_sbase 0 2534 else 2535 sa = ulong 0 2536 end 2537 if ge sb get f_sbase 0 2538 sb = sub sb get f_sbase 0 2539 else 2540 sb = ulong 0 2541 end 2542 fe_mputw `263844884595` 5 2543 fe_mputn sa 2544 fe_mputb 45 2545 fe_mputn sb 2546 fe_mputb 32 2547 s = get f_dsev 0 2548 if eq s 0 2549 if eq get f_tk 0 3 2550 s = ulong 1 2551 end 2552 if and eq code 22 ge get f_cur 0 get f_inlen 0 2553 s = ulong 1 2554 end 2555 end 2556 if eq s 1 2557 fe_mputw `4993454379819552329` 8 2558 fe_mputw `2114900` 3 2559 else 2560 if eq s 2 2561 fe_mputw `2327894055524716117` 8 2562 else 2563 fe_mputw `35511885252934` 6 2564 end 2565 end 2566 note Repairability is independent of prefix finality; only capacity failures are unrepairable. 2567 if or or or eq code 12 eq code 14 eq code 23 eq code 24 2568 fe_mputw `5929342197426179669` 8 2569 fe_mputw `138601579073` 4 2570 else 2571 fe_mputw `4774187554571306322` 8 2572 fe_mputw `2114892` 2 2573 end 2574 fe_mputw `67505686012704` 6 2575 fe_mputn code 2576 fe_mputw `67505853393952` 6 2577 hl = get f_line 0 2578 if ne get f_chkmod 0 0 2579 if gt hl get f_chkln 0 2580 hl = sub hl get f_chkln 0 2581 else 2582 hl = ulong 1 2583 end 2584 end 2585 fe_mputn hl 2586 fe_mputw `4428273620941825312` 8 2587 fe_dexp_w code 2588 fe_mputw `17280399158765088` 7 2589 fe_mput_tok a b 2590 fe_mputb 10 2591 fe_mflush 2592 end 2593 2594 fn fe_emit_query to void 2595 put f_mc 0 0 2596 fe_mputw `8462595071175650671` 8 2597 fe_mputw `2869133187838565` 7 2598 fe_mputw `9071406607197043` 7 2599 if eq get f_curfn 0 0 2600 fe_mputw `7810779306727075700` 8 2601 fe_mputb 10 2602 fe_mputw `7166760226508402531` 8 2603 fe_mputw `7142830393916027764` 8 2604 fe_mputw `8028905624785088111` 8 2605 fe_mputw `8392569455039504738` 8 2606 fe_mputw `2338603462594687776` 8 2607 fe_mputw `44651802478` 5 2608 else 2609 fe_mputw `7957695015192261990` 8 2610 fe_mputb 10 2611 fe_mputw `7166760226508402531` 8 2612 fe_mputw `2338605647353508724` 8 2613 fe_mputw `7308332192711599721` 8 2614 fe_mputw `7021802451731703328` 8 2615 fe_mputw `8079585727842951280` 8 2616 fe_mputw `9117624560546933` 7 2617 fe_mputw `1702129518` 4 2618 in_loop = ulong 0 2619 j = get f_nb 0 2620 while and eq in_loop 0 gt j 0 bound `16777217` 2621 j = sub j 1 2622 if and ge ar_w 41 j 3 le ar_w 41 j 4 2623 in_loop = ulong 1 2624 end 2625 end 2626 if ne in_loop 0 2627 fe_mputw `7142827075067601440` 8 2628 fe_mputw `749134030103146095` 8 2629 else 2630 fe_mputb 10 2631 end 2632 end 2633 fe_mputw `2879017064423790` 7 2634 fe_mflush 2635 i = ulong 0 2636 while lt i get f_nn 0 bound `16777217` 2637 if ne ar_w 4 i 0 2638 fe_mput_name get ar_m add get ar_rb 4 i 2639 fe_mputb 32 2640 fe_dty_w ulong uchar get ar_m add get ar_rb 6 i 2641 fe_mputb 32 2642 fe_dname_kind i 2643 fe_mputb 10 2644 fe_mflush 2645 end 2646 i = add i 1 2647 end 2648 fe_mputw `7957695015192261990` 8 2649 fe_mputw 670323 3 2650 fe_mflush 2651 f = ulong 0 2652 while lt f get f_nf 0 bound `16777217` 2653 fe_mputw `2125414` 3 2654 note Single caller: spell the function name here rather than spend a bootstrap function slot. 2655 o = get ar_m add get ar_rb 24 f 2656 l = get ar_m add get ar_rb 23 f 2657 if and ne o 0 gt l 0 2658 i = ulong 0 2659 while lt i l 2660 fe_mputb ar_ib add o i 2661 i = add i 1 2662 end 2663 else 2664 fe_mput_name get ar_m add get ar_rb 20 f 2665 end 2666 fe_mputw `544175136` 4 2667 fe_dty_w ulong uchar get ar_m add get ar_rb 21 f 2668 np = ulong uchar get ar_m add get ar_rb 22 f 2669 p = ulong 0 2670 while lt p np 2671 fe_mputb 32 2672 fe_dty_w ulong ar_c 33 add mul f 6 p 2673 p = add p 1 2674 end 2675 fe_mputb 10 2676 fe_mflush 2677 f = add f 1 2678 end 2679 fe_mflush 2680 exit int 0 2681 end 2682 note ======== names and functions ======== 2683 note The name table (arena group names, 4), the long names (long, 6) and the functions (fns, 8) grow with the 2684 note arena; each has a chained hash (groups namehash 5, longhash 7, fnhash 9; bucket -> index + 1 of the 2685 note newest entry, f_nm_nx / f_ln_x / f_fn_nx the one before it in the chain) whose buckets double at twice 2686 note as many entries as buckets. omc.om's findname, nm_set, findfn and ln_intern (OmcNoCaps), ported. 2687 global f_nh_b ulong 1 2688 global f_fh_b ulong 1 2689 note f_lhb: the bucket bits of the front-ir lowering's name hash (fe_lfind) 2690 global f_lhb ulong 1 2691 2692 note need: group g is about to use index n; a full arena is error 14 with the ng-use record (fe_fail) 2693 fn fe_need g ulong n ulong to void 2694 if ne ar_need g n 0 2695 fe_fail 14 2696 end 2697 end 2698 2699 note hinit: the first room of the three hash tables (ar_init gave each group 1024 buckets) 2700 fn fe_hinit to void 2701 put f_nh_b 0 10 2702 put f_lh_b 0 10 2703 put f_fh_b 0 10 2704 put f_lhb 0 10 2705 end 2706 2707 note findname: packed name -> its index + 1 among the names in scope (0 none). om4 FINDNAME. The names in 2708 note scope are 0 .. nn - 1 (clim while a pure contract is read), without nglob .. nmlo - 1 while an inlined 2709 note body hides its caller's locals. The lowest such index whose packed name is w is the answer, as the 2710 note old front-to-back scan gave; the chain of w's bucket holds every name below nn, newest first. 2711 fn fe_findname w ulong to ulong 2712 n = get f_nn 0 2713 if ne get f_cpure 0 0 2714 n = get f_clim 0 2715 end 2716 g = get f_nglob 0 2717 lo = get f_nmlo 0 2718 k = get ar_m add get ar_rb 15 ar_hash w get f_nh_b 0 2719 best = ulong 0 2720 while ne k 0 bound `16777217` 2721 i = sub k 1 2722 if and lt i n eq ar_w 4 i w 2723 if or lt i g ge i lo 2724 best = k 2725 end 2726 end 2727 k = get ar_m add get ar_rb 14 i 2728 end 2729 ret best 2730 end 2731 2732 note nm_link: name i becomes the newest of its bucket's chain 2733 fn fe_nm_link i ulong to void 2734 h = ar_hash get ar_m add get ar_rb 4 i get f_nh_b 0 2735 put ar_m add get ar_rb 14 i get ar_m add get ar_rb 15 h 2736 put ar_m add get ar_rb 15 h add i 1 2737 end 2738 2739 note nm_unlk: name i, the newest name of its chain (every name above it has left), leaves it. Should a 2740 note chain ever not start with i, the buckets are rebuilt from names 0 .. i - 1 instead. 2741 fn fe_nm_unlk i ulong to void 2742 h = ar_hash get ar_m add get ar_rb 4 i get f_nh_b 0 2743 if eq ar_w 15 h add i 1 2744 put ar_m add get ar_rb 15 h get ar_m add get ar_rb 14 i 2745 else 2746 fe_nm_build i 2747 end 2748 end 2749 2750 note nm_build: empty buckets, then names 0 .. n - 1 linked in order 2751 fn fe_nm_build n ulong to void 2752 ar_gzero 5 2753 i = ulong 0 2754 while lt i n bound `16777217` 2755 fe_nm_link i 2756 i = add i 1 2757 end 2758 end 2759 2760 note nm_set: the names in scope become 0 .. v - 1 (every write of nn but addname's): names above v leave 2761 note their chains newest first; names between nn and v (a scope given back) join them again in order 2762 fn fe_nm_set v ulong to void 2763 n = get f_nn 0 2764 if gt v 0 2765 fe_need 4 sub v 1 2766 end 2767 while gt n v bound `16777217` 2768 n = sub n 1 2769 fe_nm_unlk n 2770 end 2771 while lt n v bound `16777217` 2772 fe_nm_link n 2773 n = add n 1 2774 end 2775 put f_nn 0 v 2776 end 2777 2778 note fn_same: function j is the name w of length l starting at input byte s (the test of the old scan) 2779 fn fe_fn_same j ulong w ulong l ulong s ulong to bool 2780 if ne ar_w 20 j w 2781 ret false 2782 end 2783 if eq and w 255 1 2784 ret true 2785 end 2786 fl = get ar_m add get ar_rb 23 j 2787 if le l 8 2788 ret le fl 8 2789 end 2790 if ne fl l 2791 ret false 2792 end 2793 o = get ar_m add get ar_rb 24 j 2794 k = ulong 8 2795 while lt k l bound `16777217` 2796 if ne ar_ib add o k ar_ib add s k 2797 ret false 2798 end 2799 k = add k 1 2800 end 2801 ret true 2802 end 2803 2804 note findfn: packed name w (first 8 bytes, or an interned long name), length l (any value up to 8 for a 2805 note short name), start s in the input (read only for a name over 8 bytes that is not interned) -> 2806 note function index + 1 (0 none), the lowest that matches, as the old scan gave. om4 FINDFN. 2807 fn fe_findfn w ulong l ulong s ulong to ulong 2808 k = get ar_m add get ar_rb 38 ar_hash w get f_fh_b 0 2809 best = ulong 0 2810 while ne k 0 bound `16777217` 2811 j = sub k 1 2812 if fe_fn_same j w l s 2813 best = k 2814 end 2815 k = get ar_m add get ar_rb 31 j 2816 end 2817 ret best 2818 end 2819 2820 note fn_link: function f becomes the newest of its bucket's chain; at twice as many functions as buckets 2821 note the buckets double and every function is linked again in order 2822 fn fe_fn_link f ulong to void 2823 h = ar_hash get ar_m add get ar_rb 20 f get f_fh_b 0 2824 put ar_m add get ar_rb 31 f get ar_m add get ar_rb 38 h 2825 put ar_m add get ar_rb 38 h add f 1 2826 if ge add f 1 shl ulong 2 get f_fh_b 0 2827 b = add get f_fh_b 0 1 2828 put f_fh_b 0 b 2829 fe_need 9 sub shl ulong 1 b 1 2830 ar_gzero 9 2831 j = ulong 0 2832 while le j f bound `16777217` 2833 h = ar_hash get ar_m add get ar_rb 20 j b 2834 put ar_m add get ar_rb 31 j get ar_m add get ar_rb 38 h 2835 put ar_m add get ar_rb 38 h add j 1 2836 j = add j 1 2837 end 2838 end 2839 end 2840 2841 note ln_hw: the hash word of the n input bytes at s 2842 fn fe_ln_hw s ulong n ulong to ulong 2843 w = ulong 0 2844 i = ulong 0 2845 while lt i n bound 64 2846 w = add mul w 31 ulong ar_ib add s i 2847 i = add i 1 2848 end 2849 ret w 2850 end 2851 2852 note ln_same: long name j is spelled as the n input bytes at s 2853 fn fe_ln_same j ulong s ulong n ulong to bool 2854 if ne ulong ar_c 17 j n 2855 ret false 2856 end 2857 o = get ar_m add get ar_rb 16 j 2858 i = ulong 0 2859 while lt i n bound 64 2860 if ne ar_ib add o i ar_ib add s i 2861 ret false 2862 end 2863 i = add i 1 2864 end 2865 ret true 2866 end 2867 2868 note ln_intern: the index of the long name spelled by the n input bytes at s. A spelling met for the first 2869 note time is appended (indices in order of first appearance, as before) and linked into its chain; at 2870 note twice as many long names as buckets the buckets double and every name is linked again. 2871 fn fe_ln_intern s ulong n ulong to ulong 2872 h = ar_hash fe_ln_hw s n get f_lh_b 0 2873 k = get ar_m add get ar_rb 19 h 2874 while ne k 0 bound `16777217` 2875 j = sub k 1 2876 if fe_ln_same j s n 2877 ret j 2878 end 2879 k = get ar_m add get ar_rb 18 j 2880 end 2881 k = get f_ln_n 0 2882 fe_need 6 k 2883 put ar_m add get ar_rb 16 k s 2884 ar_pc 17 k uchar n 2885 put ar_m add get ar_rb 18 k get ar_m add get ar_rb 19 h 2886 put ar_m add get ar_rb 19 h add k 1 2887 put f_ln_n 0 add k 1 2888 if ge add k 1 shl ulong 2 get f_lh_b 0 2889 fe_ln_rehash add k 1 2890 end 2891 ret k 2892 end 2893 2894 note ln_rehash: double the long-name buckets and link long names 0 .. c - 1 again in order 2895 fn fe_ln_rehash c ulong to void 2896 b = add get f_lh_b 0 1 2897 put f_lh_b 0 b 2898 fe_need 7 sub shl ulong 1 b 1 2899 ar_gzero 7 2900 j = ulong 0 2901 while lt j c bound `16777217` 2902 h = ar_hash fe_ln_hw ar_w 16 j ulong uchar get ar_m add get ar_rb 17 j b 2903 put ar_m add get ar_rb 18 j get ar_m add get ar_rb 19 h 2904 put ar_m add get ar_rb 19 h add j 1 2905 j = add j 1 2906 end 2907 end 2908 2909 note newname: the name must not be in use (a name in scope, a struct, layout, abstract or function): error 10 2910 fn fe_newname w ulong l ulong s ulong to void 2911 if ne fe_findstruct w 0 2912 fe_fail 10 2913 end 2914 if ne fe_findname w 0 2915 fe_fail 10 2916 end 2917 if ne fe_findlay w 0 2918 fe_fail 10 2919 end 2920 if ne fe_findab w 0 2921 fe_fail 10 2922 end 2923 if ne fe_findfn w l s 0 2924 fe_fail 10 2925 end 2926 end 2927 2928 note addname: packed name, register, type, length, kind, address. om4 ADDNAME. The table grows with the 2929 note arena (group names); at twice as many names as buckets the buckets double (nm_build). 2930 fn fe_addname w ulong r ulong t ulong ln ulong k ulong a ulong to void 2931 n = get f_nn 0 2932 fe_need 4 n 2933 put ar_m add get ar_rb 4 n w 2934 ar_pc 5 n uchar r 2935 ar_pc 6 n uchar t 2936 put ar_m add get ar_rb 7 n ln 2937 ar_pc 8 n uchar k 2938 put ar_m add get ar_rb 9 n a 2939 ar_pc 10 n 0 2940 ar_pc 11 n 0 2941 ar_pc 12 n 0 2942 ar_pc 13 n 0 2943 fe_nm_link n 2944 put f_nn 0 add n 1 2945 if ge add n 1 shl ulong 2 get f_nh_b 0 2946 put f_nh_b 0 add get f_nh_b 0 1 2947 fe_need 5 sub shl ulong 1 get f_nh_b 0 1 2948 fe_nm_build add n 1 2949 end 2950 end 2951 2952 note ======== registers and words ======== 2953 note alloc: the next temporary after the parameters. From omc.om alloc (@`943d9555` line 2975), which 2954 note refused with error 12 once the 16-register pool was full: a code generator limit that ng does not 2955 note have (D6), so the count goes on; slots past 16 share the last register number and keep no float flag. 2956 fn fe_alloc to ulong 2957 i = add get f_npar 0 get f_nslot 0 2958 if lt i len f_vsl 2959 put f_vsl i 0 2960 end 2961 put f_nslot 0 add get f_nslot 0 1 2962 ret fe_poolc i 2963 end 2964 2965 note destreg: d, or a new temporary when d is 255 2966 fn fe_destreg d ulong to ulong 2967 if eq d 255 2968 ret fe_alloc 2969 end 2970 ret d 2971 end 2972 2973 2974 note trapsite: a run-time check site. From omc.om trapsite (@`943d9555` line 2999), which also noted the 2975 note branch's place and trap code for the stub (error 14 past 8192 sites, a code generator limit ng does 2976 note not have, D6) and emitted it; the check pass keeps the om2 diag site record. 2977 fn fe_trapsite w ulong code ulong to void 2978 if eq get f_om2m 0 1 2979 fe_siterec 2980 end 2981 end 2982 2983 fn fe_trapc cc ulong code ulong to void 2984 fe_trapsite or `1409286144` cc code 2985 end 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 note chkext: CMP Xr, Wr, SXTB/SXTH/SXTW (SUBS extended, C6.2.463), then B.NE trap code 2997 fn fe_chkext r ulong t ulong code ulong to void 2998 fe_trapc 1 code 2999 end 3000 3001 note range: error 8 unless v is a value of type t; big = the number was written as 2^63 or more 3002 fn fe_range v ulong t ulong bigf ulong to void 3003 w = fe_twid t 3004 if eq w 64 3005 if eq t 9 3006 if ne bigf 0 3007 fe_fail 8 3008 end 3009 ret 3010 end 3011 if ne bigf 0 3012 ret 3013 end 3014 if ne shr v 63 0 3015 fe_fail 8 3016 end 3017 ret 3018 end 3019 if ne bigf 0 3020 fe_fail 8 3021 end 3022 lim = shl ulong 1 w 3023 if lt t 6 3024 if ge v lim 3025 fe_fail 8 3026 end 3027 ret 3028 end 3029 half = shr lim 1 3030 if ge add v half lim 3031 fe_fail 8 3032 end 3033 end 3034 3035 3036 note force: put a value (kind 1 register, 3 number, 4 flags, 9 float in a twin: FMOV Xr, Dn) in register 3037 note r; a bare number is error 11 3038 fn fe_force k ulong v ulong t ulong r ulong to void 3039 if eq k 1 3040 ret 3041 end 3042 if or eq k 3 eq k 7 3043 ret 3044 end 3045 if eq k 4 3046 ret 3047 end 3048 if eq k 9 3049 ret 3050 end 3051 fe_fail 11 3052 end 3053 3054 note matreg: a register holding the value 3055 fn fe_matreg k ulong v ulong t ulong to ulong 3056 if eq k 1 3057 ret v 3058 end 3059 if eq k 9 3060 ret v 3061 end 3062 r = fe_alloc 3063 fe_force k v t r 3064 ret r 3065 end 3066 3067 3068 3069 3070 note stkchk: program mode only: CMP SP, X28 (C6.2.463); B.LO trap 6 3071 fn fe_stkchk to void 3072 if ne get f_progmo 0 0 3073 fe_trapc 3 6 3074 end 3075 end 3076 3077 3078 fn fe_dead1 to void 3079 put f_dead 0 1 3080 end 3081 3082 note pushb / pushnh: open a block (om4 PUSHB, split in two because a call takes at most 6 values). omc.om 3083 note pushb @`943d9555` also took the block's branch and head places (code offsets); ng's check pass has no 3084 note code, so they are gone. 3085 fn fe_pushb k ulong reg ulong ty ulong to void 3086 n = get f_nb 0 3087 fe_need 11 n 3088 put ar_m add get ar_rb 41 n k 3089 put ar_m add get ar_rb 42 n reg 3090 put ar_m add get ar_rb 43 n ty 3091 put ar_m add get ar_rb 46 n 0 3092 put f_nb 0 add n 1 3093 note fz_push / fz_else / fz_join: the sets when block n opens; at its else (the then sets kept, the 3094 note opening sets back); at its end (kind k: 1 if, 2 else, 3 while, 4 for) 3095 j = ulong 0 3096 while lt j get f_fz_n 0 3097 put ar_m add get ar_rb 53 add mul n 16 j get f_fz_cur j 3098 j = add j 1 3099 end 3100 end 3101 3102 fn fe_pushnh names ulong hd ulong to void 3103 n = sub get f_nb 0 1 3104 put ar_m add get ar_rb 44 n names 3105 put ar_m add get ar_rb 45 n hd 3106 end 3107 3108 note ======== small readers ======== 3109 fn fe_elemtype t ulong to void 3110 if lt t 2 3111 fe_fail 9 3112 end 3113 if ge t 64 3114 fe_fail 7 3115 end 3116 end 3117 3118 note arrlen: an array length 1 .. `16777216` (error 8 below, 23 above, 23 when written as 2^63 or more) 3119 fn fe_arrlen v ulong to void 3120 if ne get f_tbig 0 0 3121 fe_fail 23 3122 end 3123 if or eq v 0 ne shr v 63 0 3124 fe_fail 8 3125 end 3126 if gt v `16777216` 3127 fe_fail 23 3128 end 3129 end 3130 3131 note lenval: an array length, loop bound or trap code token: a number, or an integer constant name (kind 9). 3132 note A name that is not an integer constant is error 16. When the line ends it is error eolc: 16 for a pool, 3133 note a new array or a parameter written without its length (OMEGESE s.7, as om4), 4 for trap and bound. 3134 fn fe_lenval eolc ulong to ulong 3135 fe_tok 3136 k = get f_tk 0 3137 if eq k 0 3138 fe_fail eolc 3139 end 3140 if eq k 2 3141 ret get f_tw 0 3142 end 3143 if eq k 1 3144 if le get f_tl 0 63 3145 e = fe_findname get f_tw 0 3146 if ne e 0 3147 if eq ar_c 8 sub e 1 9 3148 t = ulong uchar get ar_m add get ar_rb 6 sub e 1 3149 if ge t 10 3150 fe_fail 16 3151 end 3152 put f_tbig 0 0 3153 ret get ar_m add get ar_rb 9 sub e 1 3154 end 3155 end 3156 end 3157 end 3158 fe_fail 16 3159 ret 0 3160 end 3161 3162 note typeword: read a type name -> 1..9 3163 fn fe_typeword to ulong 3164 put f_dexp 0 2 3165 fe_tok 3166 k = get f_tk 0 3167 if eq k 0 3168 fe_fail 4 3169 end 3170 if ne k 1 3171 fe_fail 16 3172 end 3173 if gt get f_tl 0 8 3174 fe_fail 16 3175 end 3176 c = fe_kw get f_tw 0 3177 if eq c 0 3178 a = fe_findab get f_tw 0 3179 if ne a 0 3180 ret add a 63 3181 end 3182 fe_unkfail 16 3183 end 3184 if eq c 76 3185 fe_fail 9 3186 end 3187 if eq c 88 3188 ret 10 3189 end 3190 if eq c 89 3191 ret 11 3192 end 3193 if eq c 223 3194 ret 13 3195 end 3196 if gt sub c 1 8 3197 fe_fail 16 3198 end 3199 ret c 3200 end 3201 3202 note eol: the line must end here 3203 fn fe_eol to void 3204 put f_dexp 0 6 3205 fe_tok 3206 k = get f_tk 0 3207 if and ne k 0 ne k 3 3208 fe_fail 5 3209 end 3210 end 3211 3212 note arrname: read an array name -> its index + 1 3213 fn fe_arrname to ulong 3214 put f_dexp 0 3 3215 fe_tok 3216 k = get f_tk 0 3217 if eq k 0 3218 fe_fail 4 3219 end 3220 if eq k 3 3221 fe_fail 4 3222 end 3223 if ne k 1 3224 fe_fail 16 3225 end 3226 if gt get f_tl 0 63 3227 fe_fail 13 3228 end 3229 if eq fe_kw get f_tw 0 193 3230 fe_fail 9 3231 end 3232 e = fe_findname get f_tw 0 3233 if eq e 0 3234 fe_fail 3 3235 end 3236 if eq ar_c 8 sub e 1 0 3237 fe_fail 7 3238 end 3239 ret e 3240 end 3241 3242 note topname: read a new name for a global or a text -> its packed word 3243 fn fe_topname to ulong 3244 fe_tok 3245 if ne get f_tk 0 1 3246 fe_fail 16 3247 end 3248 if gt get f_tl 0 63 3249 fe_fail 13 3250 end 3251 w = get f_tw 0 3252 if ne fe_kw w 0 3253 fe_fail 16 3254 end 3255 fe_newname w get f_tl 0 get f_ts 0 3256 ret w 3257 end 3258 3259 note ---- value results (om4 x0 kind 1 register / 2 bare number / 3 typed number / 4 flags, x1 register, 3260 note number or condition, x2 type). fr: 32 cells per value nesting depth (arena group depth, 0..32768): 0..5 the two operands of 3261 note a binary op (kind, value, type each), 8..25 a call's arguments (kind, value, array name each) ---- 3262 global f_rk ulong 1 3263 global f_rv ulong 1 3264 global f_rt ulong 1 3265 global f_depth ulong 1 3266 3267 3268 note bo_fix: after a 64-bit op on rd: u8/u16/u32 wrap (canon), i8/i16/i32 overflow check (trap 1) 3269 fn fe_bo_fix rd ulong ty ulong to void 3270 if lt ty 6 3271 ret 3272 end 3273 if eq ty 9 3274 ret 3275 end 3276 fe_chkext rd ty 1 3277 end 3278 3279 note bo_schk: a shift amount in a register must be below the width: CMP Xb, #w; B.HS trap 7 3280 fn fe_bo_schk ty ulong rb ulong to void 3281 fe_trapc 2 7 3282 end 3283 3284 note add, sub: u32 the 32-bit form; i64 ADDS/SUBS + B.VS trap 1; others 64-bit then bo_fix (om4 BO_ADD) 3285 fn fe_bo_add op ulong ty ulong ra ulong rb ulong imm ulong rd ulong to void 3286 if eq ty 4 3287 ret 3288 end 3289 if eq ty 9 3290 fe_trapc 6 1 3291 ret 3292 end 3293 if eq ty 13 3294 if eq op 34 3295 fe_trapc 3 1 3296 else 3297 fe_trapc 2 1 3298 end 3299 ret 3300 end 3301 fe_bo_fix rd ty 3302 end 3303 3304 note mul: i64 SMULH t, MUL, CMP t, rd, ASR #63, B.NE trap 1 (om4 BO_MUL) 3305 fn fe_bo_mul ty ulong ra ulong rb ulong rd ulong to void 3306 if eq ty 9 3307 t = fe_alloc 3308 fe_trapc 1 1 3309 ret 3310 end 3311 if eq ty 13 3312 t = fe_alloc 3313 fe_trapc 1 1 3314 ret 3315 end 3316 if eq ty 4 3317 ret 3318 end 3319 fe_bo_fix rd ty 3320 end 3321 3322 note div, rem (om4 BO_DIV, BO_SDIV): CBZ Xb trap 2 unless fl bit 1 (b a number other than 0); UDIV or 3323 note SDIV; rem: t = a / b, rd = a - t * b (MSUB); i64 div: CMN Xb, #1; B.NE +3; NEGS XZR, Xa; B.VS trap 1, 3324 note unless fl bit 2 (b a number other than -1) 3325 fn fe_bo_div op ulong ty ulong ra ulong rb ulong rd ulong fl ulong to void 3326 if eq and fl 1 0 3327 fe_trapsite or `3019898880` rb 2 3328 end 3329 if eq op 37 3330 t = fe_alloc 3331 ret 3332 end 3333 if or lt ty 6 eq ty 13 3334 ret 3335 end 3336 if eq ty 9 3337 if eq and fl 2 0 3338 fe_trapc 6 1 3339 end 3340 end 3341 if ne ty 9 3342 fe_bo_fix rd ty 3343 end 3344 end 3345 3346 3347 3348 note shl (om4 BO_SHL, BS_64): by a number s: UBFM Xd, Xn, #(64-s) mod 64, #63-s; by a register: the amount 3349 note check, LSLV; i64: t = a << s, X16 = t >> s arithmetic, CMP X16, Xa, B.NE trap 1, MOV Xd, Xt 3350 fn fe_bo_shl ty ulong ra ulong rb ulong imm ulong rd ulong to void 3351 if eq ty 9 3352 t = fe_alloc 3353 if ne imm 0 3354 else 3355 fe_bo_schk ty rb 3356 end 3357 fe_trapc 1 1 3358 ret 3359 end 3360 if ne imm 0 3361 fe_bo_fix rd ty 3362 ret 3363 end 3364 fe_bo_schk ty rb 3365 if eq ty 4 3366 ret 3367 end 3368 fe_bo_fix rd ty 3369 end 3370 3371 note shr: unsigned LSR, signed ASR; by a number UBFM / SBFM Xd, Xn, #s, #63; by a register the amount check 3372 note then LSRV / ASRV (om4 BO_SHR) 3373 fn fe_bo_shr ty ulong ra ulong rb ulong imm ulong rd ulong to void 3374 if ne imm 0 3375 ret 3376 end 3377 fe_bo_schk ty rb 3378 end 3379 3380 note comparisons: CMP Xa, #imm or CMP Xa, Xb; the result is the flags and a condition (om4 BO_CMP) 3381 fn fe_bo_cmp op ulong ty ulong ra ulong rb ulong imm ulong to void 3382 i = mul sub op 43 2 3383 if and ge ty 6 le ty 9 3384 i = add i 1 3385 end 3386 put f_rk 0 4 3387 put f_rv 0 fe_conds i 3388 put f_rt 0 1 3389 end 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 note vtw: the twin of pool register r, v(16 + its pool index): v16..v31, caller-saved in AAPCS64 3415 fn fe_vtw r ulong to ulong 3416 ret add 16 fe_regidx r 3417 end 3418 3419 3420 3421 3422 note fvop: the v register holding float operand (kind k, value v, type t): its twin for kind 9, else v 3423 note register s, filled from the constant or from the operand's x register. 3424 fn fe_fvop k ulong v ulong t ulong s ulong to ulong 3425 if eq k 9 3426 ret fe_vtw v 3427 end 3428 if eq k 7 3429 ret s 3430 end 3431 r = fe_matreg k v t 3432 ret s 3433 end 3434 3435 note fvdst: the pool register whose twin takes a kind 9 result for request o (fpw): 1 a new one, its slot 3436 note marked as living in v; 2 + r the twin of r (a float local name). 3437 fn fe_fvdst o ulong to ulong 3438 if eq o 1 3439 r = fe_alloc 3440 put f_vsl fe_regidx r uchar 1 3441 ret r 3442 end 3443 ret sub o 2 3444 end 3445 3446 note fvset: float value (kind k, value v, type t) into the twin of r: FMOV Dd, Dn (C7.2.130), the constant, 3447 note or FMOV from its x register. Nothing when it is already there. 3448 fn fe_fvset k ulong v ulong t ulong r ulong to void 3449 if eq k 9 3450 ret 3451 end 3452 if eq k 7 3453 ret 3454 end 3455 x = fe_matreg k v t 3456 end 3457 3458 3459 3460 3461 3462 note fintr: sqrt or abs of one float value; fminmax: min or max of two values of one float type. 3463 note Both refuse a bare integer operand and an unresolved literal, as everywhere else. A request o (fpo) 3464 note makes the result in a twin (kind 9); otherwise it moves to x register destreg dst (kind 1). 3465 fn fe_fintr c ulong dst ulong to void 3466 o = get f_fpo 0 3467 put f_fpo 0 0 3468 put f_fpw 0 1 3469 fe_rdval 0 0 255 0 3470 if eq get f_rk 0 2 3471 fe_fail 7 3472 end 3473 if eq get f_rk 0 6 3474 fe_fail 11 3475 end 3476 t = get f_rt 0 3477 if eq fe_isfloat t 0 3478 fe_fail 7 3479 end 3480 va = fe_fvop get f_rk 0 get f_rv 0 t 0 3481 if eq o 0 3482 rd = fe_destreg dst 3483 put f_rk 0 1 3484 put f_rv 0 rd 3485 else 3486 r = fe_fvdst o 3487 put f_rk 0 9 3488 put f_rv 0 r 3489 end 3490 put f_rt 0 t 3491 fe_vdec 3492 end 3493 3494 fn fe_fminmax c ulong dst ulong to void 3495 o = get f_fpo 0 3496 put f_fpo 0 0 3497 put f_fpw 0 1 3498 fe_rdval 0 0 255 0 3499 if or eq get f_rk 0 2 eq get f_rk 0 6 3500 fe_fail 11 3501 end 3502 atp = get f_rt 0 3503 ak = get f_rk 0 3504 av = get f_rv 0 3505 put f_fpw 0 1 3506 fe_rdval 0 0 255 0 3507 if or eq get f_rk 0 2 eq get f_rk 0 6 3508 fe_fail 11 3509 end 3510 if or eq fe_isfloat atp 0 eq fe_isfloat get f_rt 0 0 3511 fe_fail 7 3512 end 3513 if ne atp get f_rt 0 3514 fe_fail 7 3515 end 3516 va = fe_fvop ak av atp 0 3517 vb = fe_fvop get f_rk 0 get f_rv 0 atp 1 3518 if eq o 0 3519 rd = fe_destreg dst 3520 put f_rk 0 1 3521 put f_rv 0 rd 3522 else 3523 r = fe_fvdst o 3524 put f_rk 0 9 3525 put f_rv 0 r 3526 end 3527 put f_rt 0 atp 3528 fe_vdec 3529 end 3530 3531 note FMADD (scalar), ARM C7: one rounded multiply-add, not FMUL followed by FADD. 3532 note The addend is Ra, bits 14..10; multiplicands Rn, Rm are bits 9..5, 20..16. 3533 fn fe_ffma dst ulong to void 3534 o = get f_fpo 0 3535 put f_fpo 0 0 3536 note x86's baseline is SSE2, not FMA3. No unfused fallback is permitted. 3537 put f_fpw 0 1 3538 fe_rdval 0 0 255 0 3539 if eq get f_rk 0 6 3540 fe_fail 11 3541 end 3542 atp = get f_rt 0 3543 if eq fe_isfloat atp 0 3544 fe_fail 7 3545 end 3546 ak = get f_rk 0 3547 av = get f_rv 0 3548 put f_fpw 0 1 3549 fe_rdval 0 0 255 0 3550 if eq get f_rk 0 6 3551 fe_fail 11 3552 end 3553 if ne get f_rt 0 atp 3554 fe_fail 7 3555 end 3556 bk = get f_rk 0 3557 bv = get f_rv 0 3558 put f_fpw 0 1 3559 fe_rdval 0 0 255 0 3560 if eq get f_rk 0 6 3561 fe_fail 11 3562 end 3563 if ne get f_rt 0 atp 3564 fe_fail 7 3565 end 3566 va = fe_fvop ak av atp 0 3567 vb = fe_fvop bk bv atp 1 3568 vc = fe_fvop get f_rk 0 get f_rv 0 atp 2 3569 r = ulong 0 3570 if eq o 0 3571 r = fe_destreg dst 3572 else 3573 r = fe_fvdst o 3574 end 3575 b = ulong `520093696` 3576 if eq atp 11 3577 b = `524288000` 3578 end 3579 b = or b shl vb 16 3580 b = or b shl vc 10 3581 b = or b shl va 5 3582 if eq o 0 3583 put f_rk 0 1 3584 else 3585 put f_rk 0 9 3586 end 3587 put f_rv 0 r 3588 put f_rt 0 atp 3589 fe_vdec 3590 end 3591 3592 note fcond: the condition for a float compare op: EQ, NE, MI (lt), LS (le), GT, GE. MI/LS/GT/GE are 3593 note false for NaN, so unordered comparisons come out as the IEEE rules require. 3594 fn fe_fcond op ulong to ulong 3595 i = sub op 43 3596 if eq i 0 3597 ret 0 3598 end 3599 if eq i 1 3600 ret 1 3601 end 3602 if eq i 2 3603 ret 4 3604 end 3605 if eq i 3 3606 ret 9 3607 end 3608 if eq i 4 3609 ret 12 3610 end 3611 ret 10 3612 end 3613 3614 note fp_cmp: FCMP Sn, Sm / Dn, Dm (scalar) of v registers va, vb: 0x1E202000 / 0x1E602000 with Rm and Rn 3615 note zero, so both fields come from va and vb alone (#861: the S word had Rm bit 0 set, and an even vb 3616 note read the next twin). 3617 fn fe_fp_cmp op ulong ty ulong va ulong vb ulong to void 3618 put f_rk 0 4 3619 put f_rv 0 fe_fcond op 3620 put f_rt 0 1 3621 end 3622 3623 note fp_conv: one scalar conversion (int<->float, f32<->f64) into a new x register. Same type is a copy. 3624 note Returns the register. A float result is made in v(rd), or in v0 when rd is x17 (v17 is a twin). 3625 fn fe_fp_conv ft ulong tt ulong ra ulong to ulong 3626 if eq ft tt 3627 ret ra 3628 end 3629 if eq ft 1 3630 fe_fail 9 3631 end 3632 if eq tt 1 3633 fe_fail 9 3634 end 3635 rd = fe_alloc 3636 if eq fe_isfloat tt 0 3637 ret rd 3638 end 3639 ret rd 3640 end 3641 3642 3643 3644 3645 3646 3647 3648 3649 fn fe_binrot op ulong dst ulong ix ulong to void 3650 ty = get ar_m add get ar_rb 59 add ix 2 3651 if or lt ty 2 gt ty 5 3652 fe_fail 7 3653 end 3654 ra = fe_matreg ar_w 59 ix get ar_m add get ar_rb 59 add ix 1 ty 3655 bk = get ar_m add get ar_rb 59 add ix 3 3656 bn = get ar_m add get ar_rb 59 add ix 4 3657 w = fe_twid ty 3658 rb = ulong 0 3659 useimm = false 3660 if and eq bk 3 lt bn w 3661 useimm = true 3662 rb = bn 3663 else 3664 rb = fe_matreg bk bn ar_w 59 add ix 5 3665 fe_bo_schk ty rb 3666 end 3667 rd = fe_destreg dst 3668 if useimm 3669 s = rb 3670 if and eq op 60 ne s 0 3671 s = sub w s 3672 end 3673 else 3674 if eq op 60 3675 rr = fe_alloc 3676 end 3677 end 3678 put f_rk 0 1 3679 put f_rv 0 rd 3680 put f_rt 0 ty 3681 end 3682 3683 note binop: op 33..48, destination (255 none), ix the fr slot of a (kind, number/register, type) then b. 3684 note Result in rk/rv/rt. om4 BINOP. A float op reads its operands as v registers; with a request (fpo) 3685 note the result stays in a twin (kind 9), else it moves to x (kind 1). 3686 fn fe_binop op ulong dst ulong ix ulong to void 3687 if ne get f_fzone 0 0 3688 if and eq ar_w 59 ix 3 eq ar_w 59 add ix 3 3 3689 fe_foldbin op ar_w 59 add ix 2 ar_w 59 add ix 1 get ar_m add get ar_rb 59 add ix 4 3690 if ne get f_fok 0 0 3691 put f_rk 0 3 3692 put f_rv 0 get f_fval 0 3693 put f_rt 0 get f_fty 0 3694 ret 3695 end 3696 end 3697 end 3698 if or eq op 59 eq op 60 3699 fe_binrot op dst ix 3700 ret 3701 end 3702 ty = get ar_m add get ar_rb 59 add ix 2 3703 if ne fe_isfloat ty 0 3704 o = get f_fpo 0 3705 put f_fpo 0 0 3706 va = fe_fvop ar_w 59 ix get ar_m add get ar_rb 59 add ix 1 ty 0 3707 vb = fe_fvop ar_w 59 add ix 3 get ar_m add get ar_rb 59 add ix 4 ty 1 3708 if ge op 43 3709 fe_fp_cmp op ty va vb 3710 ret 3711 end 3712 if or or lt op 33 gt op 36 ge op 41 3713 fe_fail 7 3714 end 3715 if eq o 0 3716 rd = fe_destreg dst 3717 put f_rk 0 1 3718 put f_rv 0 rd 3719 else 3720 r = fe_fvdst o 3721 put f_rk 0 9 3722 put f_rv 0 r 3723 end 3724 put f_rt 0 ty 3725 ret 3726 end 3727 ra = fe_matreg ar_w 59 ix get ar_m add get ar_rb 59 add ix 1 ty 3728 if eq ty 13 3729 if and ge op 38 le op 42 3730 fe_fail 7 3731 end 3732 end 3733 imm = ulong 0 3734 bk = get ar_m add get ar_rb 59 add ix 3 3735 bn = get ar_m add get ar_rb 59 add ix 4 3736 rb = ulong 0 3737 useimm = false 3738 if eq bk 3 3739 if or eq op 41 eq op 42 3740 if lt bn fe_twid ty 3741 useimm = true 3742 end 3743 else 3744 if or lt op 35 ge op 43 3745 if le bn 4095 3746 useimm = true 3747 end 3748 end 3749 end 3750 end 3751 if useimm 3752 rb = bn 3753 imm = ulong 1 3754 else 3755 rb = fe_matreg bk bn ar_w 59 add ix 5 3756 end 3757 if ge op 43 3758 fe_bo_cmp op ty ra rb imm 3759 ret 3760 end 3761 if eq ty 1 3762 if gt sub op 38 2 3763 fe_fail 7 3764 end 3765 end 3766 rd = fe_destreg dst 3767 if lt op 35 3768 fe_bo_add op ty ra rb imm rd 3769 else 3770 if eq op 35 3771 fe_bo_mul ty ra rb rd 3772 else 3773 if lt op 38 3774 fl = ulong 0 3775 if and eq bk 3 ne bn 0 3776 fl = or fl 1 3777 end 3778 if and eq bk 3 ne bn `18446744073709551615` 3779 fl = or fl 2 3780 end 3781 fe_bo_div op ty ra rb rd fl 3782 else 3783 if lt op 41 3784 else 3785 if eq op 41 3786 fe_bo_shl ty ra rb imm rd 3787 else 3788 fe_bo_shr ty ra rb imm rd 3789 end 3790 end 3791 end 3792 end 3793 end 3794 put f_rk 0 1 3795 put f_rv 0 rd 3796 put f_rt 0 ty 3797 end 3798 3799 note ======== calls: registers saved around a call and loaded back ======== 3800 global f_svn ulong 1 3801 global f_sva ulong 1 3802 note save: n = registers in use (parameters + pool slots), A = 8 (n + 1) rounded up to 16: SUB SP, SP, #A 3803 note (C6.2.457); the stack check; STR Xr, [SP, #8j] for each (C6.2.415), or STR Dj+16 (SIMD&FP, C7.2.331) 3804 note for a slot living in its twin (vsl); STR X30, [SP, #8n]. Out: svn n, sva A. om4 SAVE. 3805 fn fe_save to void 3806 n = add get f_npar 0 get f_nslot 0 3807 a = shl shr add n 2 1 4 3808 put f_svn 0 n 3809 put f_sva 0 a 3810 fe_stkchk 3811 j = ulong 0 3812 while lt j n 3813 j = add j 1 3814 end 3815 end 3816 3817 3818 3819 note restore: d destination (255: a new temporary at pool slot `slot`), slot the pool slot before the 3820 note arguments, n saved count, a save bytes, res 1 if there is a result in X0. MOV Xd, X0 (C6.2.282); LDR 3821 note each register in use before the arguments except Xd (C6.2.216), or LDR Dj+16 (C7.2.191) instead for a 3822 note slot living in its twin; LDR X30; ADD SP, SP, #A (C6.2.5). Returns Xd (255 when no result). om4 3823 note RESTORE. 3824 fn fe_restore d ulong slot ulong n ulong a ulong res ulong to ulong 3825 put f_nslot 0 slot 3826 rd = ulong 255 3827 if ne res 0 3828 rd = d 3829 if eq d 255 3830 rd = fe_alloc 3831 end 3832 end 3833 m = add get f_npar 0 slot 3834 j = ulong 0 3835 while lt j m 3836 j = add j 1 3837 end 3838 ret rd 3839 end 3840 3841 note ca_bl: BL to function f (index + 1), C6.2.43 3842 fn fe_ca_bl f ulong to void 3843 n = get f_ncalls 0 3844 fe_need 10 n 3845 put ar_m add get ar_rb 39 n get f_curfn 0 3846 put ar_m add get ar_rb 40 n f 3847 put f_ncalls 0 add n 1 3848 3849 end 3850 3851 note ======== element addresses and array arguments ======== 3852 global f_ea_b ulong 1 3853 global f_ea_i ulong 1 3854 global f_ea_k ulong 1 3855 3856 note elemaddr: array name e (index + 1), index value (kind, number or register, type). A number index must 3857 note be inside the array (error 21) and needs no check; a register index: CMP Xi, #len (C6.2.96) or CMP Xi, 3858 note Xt (C6.2.97), B.HS trap 3 (unsigned, so a negative signed index traps too). Out: ea_b base register 3859 note (the array's register, or a new one holding its address), ea_i index register. om4 ELEMADDR. 3860 note OM-2 unsized array (unsz): every index, a number too, is checked against its count register nm_lr 3861 note (CMP Xi, Xn; B.HS trap 3); none is eliminated (spec 4, 6). 3862 fn fe_elemaddr e ulong k ulong v ulong t ulong to void 3863 if or or eq t 1 eq t 10 eq t 11 3864 fe_fail 7 3865 end 3866 i = sub e 1 3867 if eq ar_c 8 i 10 3868 put f_ea_i 0 fe_matreg k v t 3869 put f_ea_b 0 fe_alloc 3870 unused = fe_alloc 3871 fe_trapc 2 3 3872 ret 3873 end 3874 ln = get ar_m add get ar_rb 7 i 3875 x = v 3876 if ne fe_unsz i 0 3877 x = fe_matreg k v t 3878 fe_trapc 2 3 3879 else 3880 if eq k 3 3881 if ge v ln 3882 fe_fail 21 3883 end 3884 if and ne get f_om2 0 0 le v 4095 3885 x = ulong 255 3886 put f_ea_k 0 v 3887 else 3888 x = fe_alloc 3889 end 3890 else 3891 if le ln 4095 3892 else 3893 y = fe_alloc 3894 end 3895 fe_trapc 2 3 3896 end 3897 end 3898 put f_ea_i 0 x 3899 if ge ar_c 8 i 4 3900 b = fe_alloc 3901 put f_ea_b 0 b 3902 else 3903 put f_ea_b 0 ulong uchar get ar_m add get ar_rb 5 i 3904 end 3905 end 3906 3907 note aa_word: the next word of an array argument must be a name of at most 8 bytes 3908 fn fe_aa_word to void 3909 fe_tok 3910 k = get f_tk 0 3911 if eq k 0 3912 fe_fail 4 3913 end 3914 if ne k 1 3915 fe_fail 16 3916 end 3917 if gt get f_tl 0 63 3918 fe_fail 13 3919 end 3920 end 3921 3922 note arrarg: an array argument for parameter pi of function f (index + 1): [view | edit] NAME. Its type and 3923 note length must equal the parameter's; an edit parameter needs a writable array (local or edit, error 20; 3924 note a view passed to it is error 20, OMEGESE.md 9.4); a global is never passed (error 19). Out: rk 5 3925 note (register rv) or 6 (address rv, a text), rt the name entry. om4 ARRARG. 3926 note OM-2: an unsized parameter (length 0) takes an array of any length (erratum E2), whose count goes to 3927 note ul_k / ul_v at depth * 6 + pi: its count register, or its length as a number. `part` is read by arrpart. 3928 fn fe_arrarg f ulong pi ulong to void 3929 md = ulong 0 3930 fe_aa_word 3931 w = get f_tw 0 3932 c = fe_kw w 3933 if ne c 0 3934 if eq c 193 3935 fe_arrpart f pi 0 3936 ret 3937 end 3938 if or lt c 57 gt c 58 3939 fe_fail 16 3940 end 3941 md = c 3942 fe_aa_word 3943 w = get f_tw 0 3944 if eq fe_kw w 193 3945 fe_arrpart f pi md 3946 ret 3947 end 3948 end 3949 e = fe_findname w 3950 if eq e 0 3951 fe_fail 3 3952 end 3953 i = sub e 1 3954 k = ulong uchar get ar_m add get ar_rb 8 i 3955 if eq k 0 3956 fe_fail 7 3957 end 3958 if eq k 10 3959 fe_fail 19 3960 end 3961 if ge k 6 3962 fe_fail 7 3963 end 3964 if eq k 4 3965 fe_fail 19 3966 end 3967 p = add mul sub f 1 6 pi 3968 if eq ar_c 35 p 3 3969 if eq md 57 3970 fe_fail 20 3971 end 3972 if and ne k 1 ne k 3 3973 fe_fail 20 3974 end 3975 else 3976 if eq md 58 3977 fe_fail 7 3978 end 3979 end 3980 if ne ar_c 6 i ar_c 33 p 3981 fe_fail 7 3982 end 3983 ux = add mul get f_depth 0 6 pi 3984 if eq ar_w 34 p 0 3985 if ne fe_unsz i 0 3986 ar_pw 61 ux 1 3987 put ar_m add get ar_rb 62 ux ulong ar_c 13 i 3988 else 3989 put ar_m add get ar_rb 61 ux 3 3990 put ar_m add get ar_rb 62 ux ar_w 7 i 3991 end 3992 else 3993 if ne ar_w 7 i ar_w 34 p 3994 fe_fail 7 3995 end 3996 end 3997 put f_rt 0 e 3998 if eq k 5 3999 put f_rk 0 6 4000 put f_rv 0 ar_w 9 i 4001 else 4002 put f_rk 0 5 4003 put f_rv 0 ulong ar_c 5 i 4004 end 4005 end 4006 4007 note arrpart (OM-2, spec 6): `part A o k` as argument pi of function f (index + 1); md 57 / 58 when `view` / 4008 note `edit` was written before it. A is a name (a global is error 19, a fresh array 27); o, then k, are 4009 note ulong values. Checks, in this order: o <= len A (CMP Xo, Xlen; B.HI trap 3), then k <= len A - o (SUB, 4010 note CMP, B.HI trap 3); the wrapped o + k is never formed. The part is a view of A + o * size with count k: 4011 note an edit when A is writable (local or edit) and no `view` was written, else a view. It goes only to an 4012 note unsized parameter (error 7). Out as arrarg; rt is A, so for error 19 the part counts as its base. 4013 fn fe_arrpart f ulong pi ulong md ulong to void 4014 p = add mul sub f 1 6 pi 4015 e = fe_arrname 4016 i = sub e 1 4017 k = ulong uchar get ar_m add get ar_rb 8 i 4018 if eq k 10 4019 fe_fail 19 4020 end 4021 if ge k 6 4022 fe_fail 7 4023 end 4024 if eq k 4 4025 fe_fail 19 4026 end 4027 fe_fz_arg e 4028 if eq ar_c 35 p 3 4029 if eq md 57 4030 fe_fail 20 4031 end 4032 if and ne k 1 ne k 3 4033 fe_fail 20 4034 end 4035 else 4036 if eq md 58 4037 fe_fail 7 4038 end 4039 end 4040 if ne ulong ar_c 6 i ulong ar_c 33 p 4041 fe_fail 7 4042 end 4043 if ne ar_w 34 p 0 4044 fe_fail 7 4045 end 4046 fe_rdval 0 5 255 0 4047 k = get f_rt 0 4048 if and ne k 5 ne k 13 4049 fe_fail 7 4050 end 4051 ro = fe_matreg get f_rk 0 get f_rv 0 k 4052 fe_rdval 0 5 255 0 4053 k = get f_rt 0 4054 if and ne k 5 ne k 13 4055 fe_fail 7 4056 end 4057 rn = fe_matreg get f_rk 0 get f_rv 0 k 4058 d = fe_partck i ro rn 4059 ux = add mul get f_depth 0 6 pi 4060 ar_pw 61 ux 1 4061 put ar_m add get ar_rb 62 ux rn 4062 put f_rt 0 e 4063 put f_rk 0 5 4064 put f_rv 0 d 4065 end 4066 4067 note partck: the two checks of part (name index i, o in ro, k in rn), then the part's base register 4068 fn fe_partck i ulong ro ulong rn ulong to ulong 4069 if eq fe_unsz i 0 4070 rl = fe_alloc 4071 end 4072 fe_trapc 8 3 4073 d = fe_alloc 4074 fe_trapc 8 3 4075 if eq ar_c 8 i 5 4076 b = fe_alloc 4077 end 4078 ret d 4079 end 4080 4081 note ======== the parts of the value reader that read no further value ======== 4082 fn fe_vdec to void 4083 if and ne get f_cpure 0 0 ge get f_rt 0 10 4084 fe_fail 30 4085 end 4086 put f_depth 0 sub get f_depth 0 1 4087 end 4088 4089 note vdone: a value's result, and one nesting level less (om4 VT_RET) 4090 fn fe_vdone k ulong v ulong t ulong to void 4091 put f_rk 0 k 4092 put f_rv 0 v 4093 put f_rt 0 t 4094 fe_vdec 4095 end 4096 4097 note fwreq: hand this depth's fpw request to the part that makes the value (fpo) 4098 fn fe_fwreq to void 4099 put f_fpo 0 get ar_m add get ar_rb 60 get f_depth 0 4100 end 4101 4102 note vt_un: neg / not of the value in rk/rv/rt (a bare number already refused). neg: NEG Xd, Xm (SUB from 4103 note XZR, C6.2.458; the 32-bit form for u32), i64 NEGS + B.VS trap 1 (C6.2.465), then the wrap or the 4104 note sign check; not: bool EOR Xd, Xn, #1 (C6.2.155), else MVN (ORN from XZR, C6.2.300), then the wrap. 4105 note om4 VU1 .. VU_E. Float neg: FNEG (C7.2.144) of the operand's v register; with a request (fpo) the 4106 note result stays in a twin (kind 9). 4107 fn fe_vt_un c ulong dst ulong to void 4108 o = get f_fpo 0 4109 put f_fpo 0 0 4110 if ne get f_fzone 0 0 4111 if eq get f_rk 0 3 4112 fe_foldun c get f_rt 0 get f_rv 0 4113 if ne get f_fok 0 0 4114 put f_rv 0 get f_fval 0 4115 ret 4116 end 4117 end 4118 end 4119 ty = get f_rt 0 4120 if or eq ty 10 eq ty 11 4121 if eq c 50 4122 fe_fail 7 4123 end 4124 va = fe_fvop get f_rk 0 get f_rv 0 ty 0 4125 if eq o 0 4126 rd = fe_destreg dst 4127 put f_rk 0 1 4128 put f_rv 0 rd 4129 else 4130 r = fe_fvdst o 4131 put f_rk 0 9 4132 put f_rv 0 r 4133 end 4134 put f_rt 0 ty 4135 ret 4136 end 4137 ra = fe_matreg get f_rk 0 get f_rv 0 ty 4138 rd = fe_destreg dst 4139 if eq c 50 4140 if eq ty 13 4141 fe_fail 7 4142 end 4143 else 4144 if or eq ty 1 eq ty 13 4145 fe_fail 7 4146 end 4147 if eq ty 9 4148 fe_trapc 6 1 4149 else 4150 if eq ty 4 4151 else 4152 if lt ty 6 4153 else 4154 fe_chkext rd ty 1 4155 end 4156 end 4157 end 4158 end 4159 put f_rk 0 1 4160 put f_rv 0 rd 4161 put f_rt 0 ty 4162 end 4163 4164 note vt_conv: the value in rk/rv/rt converted to type tt (neither bool, error 9). Out of range when any bit 4165 note at or above s is set: LSR Xt, Xa, #s (UBFM, C6.2.487); CBNZ Xt trap 5 (C6.2.77); signed to a narrower 4166 note signed type: the sign-extension check, trap 5. om4 VTT1 .. VC_OK. To a float with a request (fpo): the 4167 note conversion is made in a twin (kind 9); the same float type is left as it is. 4168 fn fe_vt_conv tt ulong to void 4169 o = get f_fpo 0 4170 put f_fpo 0 0 4171 ft = get f_rt 0 4172 if or or or eq ft 10 eq ft 11 eq tt 10 eq tt 11 4173 if or eq ft 13 eq tt 13 4174 fe_fail 7 4175 end 4176 if eq ft 1 4177 fe_fail 9 4178 end 4179 if eq tt 1 4180 fe_fail 9 4181 end 4182 if and ne o 0 ne fe_isfloat tt 0 4183 if eq ft tt 4184 ret 4185 end 4186 ra = fe_matreg get f_rk 0 get f_rv 0 ft 4187 r = fe_fvdst o 4188 put f_rk 0 9 4189 put f_rv 0 r 4190 put f_rt 0 tt 4191 ret 4192 end 4193 ra = fe_matreg get f_rk 0 get f_rv 0 ft 4194 rd = fe_fp_conv ft tt ra 4195 put f_rk 0 1 4196 put f_rv 0 rd 4197 put f_rt 0 tt 4198 ret 4199 end 4200 ra = fe_matreg get f_rk 0 get f_rv 0 ft 4201 if eq ft 1 4202 fe_fail 9 4203 end 4204 if eq tt 1 4205 fe_fail 9 4206 end 4207 wf = fe_twid ft 4208 wt = fe_twid tt 4209 s = ulong 99 4210 sgf = and ge ft 6 le ft 9 4211 sgt = and ge tt 6 le tt 9 4212 if eq sgf 0 4213 if ne sgt 0 4214 if ge wf wt 4215 s = sub wt 1 4216 end 4217 else 4218 if gt wf wt 4219 s = wt 4220 end 4221 end 4222 else 4223 if eq sgt 0 4224 s = wt 4225 if gt s 63 4226 s = ulong 63 4227 end 4228 else 4229 if gt wf wt 4230 fe_chkext ra tt 5 4231 end 4232 end 4233 end 4234 if ne s 99 4235 t = fe_alloc 4236 fe_trapsite or `3036676096` t 5 4237 end 4238 put f_rk 0 1 4239 put f_rv 0 ra 4240 put f_rt 0 tt 4241 end 4242 4243 note vt_get: get A i with the index value in rk/rv/rt: the element address, then the load of the element 4244 note type, register offset (LDOP table). om4 VT_GET. A float element with a request (fpo) loads straight 4245 note into a twin: the same word with V (bit 26), LDR St/Dt (C7.2.192) (kind 9). 4246 fn fe_vt_get e ulong dst ulong to void 4247 o = get f_fpo 0 4248 put f_fpo 0 0 4249 fe_elemaddr e get f_rk 0 get f_rv 0 get f_rt 0 4250 ty = ulong uchar get ar_m add get ar_rb 6 sub e 1 4251 if and ne o 0 ne fe_isfloat ty 0 4252 r = fe_fvdst o 4253 put f_rk 0 9 4254 put f_rv 0 r 4255 put f_rt 0 ty 4256 ret 4257 end 4258 rd = fe_destreg dst 4259 put f_rk 0 1 4260 put f_rv 0 rd 4261 put f_rt 0 ty 4262 end 4263 4264 note vs_chk: read / write bounds: n <= len A and off <= len A - n, else trap 3 (CMP C6.2.97, B.HI C6.2.34, 4265 note SUB C6.2.458). om4 VT_SYS. 4266 fn fe_vs_chk e ulong ro ulong rn ulong to void 4267 if ne ar_c 6 sub e 1 2 4268 fe_fail 7 4269 end 4270 t = fe_alloc 4271 fe_trapc 8 3 4272 fe_trapc 8 3 4273 end 4274 4275 note vs_call: save the registers in use, X0 = fd, X1 = A + off (ADD through X16, C6.2.6), X2 = n, X8 = 63 4276 note (read) or 64 (write) (MOVZ C6.2.285), SVC #0 (C6.2.466). om4 VT_SYS. 4277 fn fe_vs_call c ulong fk ulong fv ulong e ulong ro ulong rn ulong to void 4278 fe_save 4279 end 4280 4281 note ca_scal: a scalar argument just read (rk/rv/rt) for parameter p: flags into a register; its type 4282 note must be the parameter's; stored at fr[q..q+2]. om4 CA1 .. CA_PUT. 4283 fn fe_ca_scal p ulong q ulong to void 4284 if eq get f_rk 0 4 4285 put f_rv 0 fe_matreg 4 get f_rv 0 get f_rt 0 4286 put f_rk 0 1 4287 put f_rt 0 1 4288 end 4289 if ne get f_rt 0 ulong ar_c 33 p 4290 fe_fail 7 4291 end 4292 put ar_m add get ar_rb 59 q get f_rk 0 4293 put ar_m add get ar_rb 59 add q 1 get f_rv 0 4294 put ar_m add get ar_rb 59 add q 2 0 4295 end 4296 4297 note ca_arr: an array argument i of function f, call frame cb: one array passed twice is error 19. 4298 note om4 CA_ARR .. CA_PUT. 4299 fn fe_ca_arr f ulong i ulong cb ulong to void 4300 fe_arrarg f i 4301 j = ulong 0 4302 while lt j i 4303 if eq ar_w 59 add add cb mul j 3 2 get f_rt 0 4304 fe_fail 19 4305 end 4306 j = add j 1 4307 end 4308 q = add cb mul i 3 4309 put ar_m add get ar_rb 59 q get f_rk 0 4310 put ar_m add get ar_rb 59 add q 1 get f_rv 0 4311 put ar_m add get ar_rb 59 add q 2 get f_rt 0 4312 end 4313 4314 note ca_end: all arguments read: save, the arguments into X0.., BL, restore. Frame cb: 3 per argument, 4315 note then cb+18 the parameter count, cb+19 the pool slot before the arguments. om4 CA_DONE .. CA5. 4316 fn fe_ca_end f ulong dst ulong cb ulong to void 4317 fe_save 4318 np = get ar_m add get ar_rb 59 add cb 18 4319 i = ulong 0 4320 while lt i np 4321 i = add i 1 4322 end 4323 fe_ca_bl f 4324 hr = ulong 1 4325 if eq ar_c 21 sub f 1 12 4326 hr = ulong 0 4327 end 4328 n = get f_svn 0 4329 a = get f_sva 0 4330 sl = get ar_m add get ar_rb 59 add cb 19 4331 r = fe_restore dst sl n a hr 4332 put f_rk 0 1 4333 put f_rv 0 r 4334 put f_rt 0 ulong ar_c 21 sub f 1 4335 end 4336 4337 note vs_fd, vs_arr, vs_off, vs_end: the steps of read / write between the values it reads, with the fd 4338 note (kind, value), the offset register and the pool slot before kept in fr[x+8..x+11] (om4's VT_SYS 4339 note frame slots 4, 5, 7 and 14) 4340 fn fe_vs_fd x ulong to void 4341 if ne get f_rt 0 8 4342 fe_fail 7 4343 end 4344 put ar_m add get ar_rb 59 add x 9 get f_rk 0 4345 put ar_m add get ar_rb 59 add x 10 get f_rv 0 4346 end 4347 4348 fn fe_vs_arr c ulong e ulong to void 4349 fe_fz_arg e 4350 if and ne ar_c 8 sub e 1 10 ge ar_c 8 sub e 1 6 4351 fe_fail 7 4352 end 4353 if eq c 53 4354 k = uchar get ar_m add get ar_rb 8 sub e 1 4355 if or eq k 2 eq k 5 4356 fe_fail 20 4357 end 4358 end 4359 end 4360 4361 fn fe_vs_off x ulong to void 4362 if ne get f_rt 0 5 4363 fe_fail 7 4364 end 4365 note the call can grow the arena and move region 59: its result first, then the store's address 4366 rv59 = fe_matreg get f_rk 0 get f_rv 0 get f_rt 0 4367 put ar_m add get ar_rb 59 add x 11 rv59 4368 end 4369 4370 fn fe_vs_end c ulong e ulong dst ulong x ulong to void 4371 if ne get f_rt 0 5 4372 fe_fail 7 4373 end 4374 rn = fe_matreg get f_rk 0 get f_rv 0 get f_rt 0 4375 ro = get ar_m add get ar_rb 59 add x 11 4376 fe_vs_chk e ro rn 4377 fk = get ar_m add get ar_rb 59 add x 9 4378 fv = get ar_m add get ar_rb 59 add x 10 4379 fe_vs_call c fk fv e ro rn 4380 sl = get ar_m add get ar_rb 59 add x 8 4381 n = get f_svn 0 4382 a = get f_sva 0 4383 r = fe_restore dst sl n a 1 4384 fe_vdone 1 r 9 4385 end 4386 4387 note Native Linux ARM64 host operations. Encoding forms are those in seed/rung2/table.s2. 4388 note Syscall numbers and layouts: Linux asm-generic/unistd.h, fcntl.h and time.h. 4389 note No raw address or arbitrary syscall is exposed to an Omega program. 4390 fn fe_hargc c ulong to ulong 4391 if eq c 107 4392 ret 0 4393 end 4394 if eq c 109 4395 ret 0 4396 end 4397 if eq c 129 4398 ret 0 4399 end 4400 if eq c 145 4401 ret 0 4402 end 4403 if eq c 146 4404 ret 0 4405 end 4406 if eq c 147 4407 ret 0 4408 end 4409 if eq c 148 4410 ret 0 4411 end 4412 if eq c 154 4413 ret 0 4414 end 4415 if eq c 158 4416 ret 0 4417 end 4418 if eq c 100 4419 ret 1 4420 end 4421 if eq c 101 4422 ret 1 4423 end 4424 if eq c 153 4425 ret 1 4426 end 4427 if eq c 155 4428 ret 1 4429 end 4430 if eq c 156 4431 ret 1 4432 end 4433 if eq c 159 4434 ret 1 4435 end 4436 if eq c 163 4437 ret 1 4438 end 4439 if eq c 164 4440 ret 1 4441 end 4442 if eq c 102 4443 ret 2 4444 end 4445 if eq c 105 4446 ret 2 4447 end 4448 if eq c 106 4449 ret 2 4450 end 4451 if eq c 127 4452 ret 2 4453 end 4454 if eq c 139 4455 ret 2 4456 end 4457 if eq c 160 4458 ret 2 4459 end 4460 if eq c 165 4461 ret 2 4462 end 4463 if eq c 197 4464 ret 2 4465 end 4466 if eq c 240 4467 ret 2 4468 end 4469 ret 3 4470 end 4471 fn fe_harg x ulong i ulong ty ulong to void 4472 fe_rdval 0 ty 255 0 4473 if ne get f_rt 0 ty 4474 fe_fail 7 4475 end 4476 q = add add x 8 mul i 2 4477 put ar_m add get ar_rb 59 q get f_rk 0 4478 put ar_m add get ar_rb 59 add q 1 get f_rv 0 4479 end 4480 fn fe_hreturn dst ulong x ulong to void 4481 sl = get ar_m add get ar_rb 59 add x 7 4482 n = get f_svn 0 4483 a = get f_sva 0 4484 r = fe_restore dst sl n a 1 4485 fe_vdone 1 r 9 4486 end 4487 fn fe_hscalar c ulong dst ulong x ulong to void 4488 np = fe_hargc c 4489 for i ulong np 4490 ty = ulong 8 4491 if or and eq c 103 eq i 1 and eq c 139 eq i 1 4492 ty = ulong 9 4493 end 4494 fe_harg x i ty 4495 end 4496 note VFIO descriptor-kind state exists only in standalone programs, never in OM-2 unit contexts. 4497 if and ne get f_progmo 0 0 or eq c 100 eq c 108 4498 if eq get f_fdtab 0 0 4499 fdpool = get f_poolb 0 4500 if gt fdpool `1073739776` 4501 fe_fail 23 4502 end 4503 put f_fdtab 0 add `276824064` fdpool 4504 put f_poolb 0 add fdpool 2048 4505 end 4506 end 4507 fe_save 4508 fe_hreturn dst x 4509 end 4510 fn fe_hclock c ulong dst ulong x ulong to void 4511 fe_save 4512 fe_stkchk 4513 note Reject overflow before seconds are multiplied; clock result is a signed nanosecond count. 4514 fe_trapc 8 1 4515 fe_trapc 6 1 4516 fe_hreturn dst x 4517 end 4518 fn fe_harray x ulong writable ulong to ulong 4519 e = fe_arrname 4520 if eq ar_c 8 sub e 1 10 4521 fe_fail 7 4522 end 4523 if ne ar_c 6 sub e 1 2 4524 fe_fail 7 4525 end 4526 if ne writable 0 4527 fe_vs_arr 53 e 4528 end 4529 fe_fz_arg e 4530 put ar_m add get ar_rb 59 add x 20 e 4531 fe_harg x 0 5 4532 fe_harg x 1 5 4533 ro = fe_matreg ar_w 59 add x 8 get ar_m add get ar_rb 59 add x 9 5 4534 rn = fe_matreg ar_w 59 add x 10 get ar_m add get ar_rb 59 add x 11 5 4535 put ar_m add get ar_rb 59 add x 21 ro 4536 put ar_m add get ar_rb 59 add x 22 rn 4537 fe_vs_chk e ro rn 4538 ret e 4539 end 4540 note Copy a checked path to a private 4096-byte stack buffer. Reject embedded zero bytes. 4541 note Public paths remain length-delimited; only the kernel-facing private copy has a terminator. 4542 fn fe_hpathcp x ulong to void 4543 fe_save 4544 fe_trapc 8 3 4545 end 4546 fn fe_hcopy to void 4547 fe_stkchk 4548 fe_trapc 0 3 4549 end 4550 fn fe_hpath c ulong dst ulong x ulong to void 4551 e = fe_harray x 0 4552 if or eq c 110 eq c 151 4553 fe_harg x 2 8 4554 fe_harg x 3 8 4555 end 4556 if or or or eq c 112 eq c 143 eq c 144 eq c 157 4557 fe_harg x 2 8 4558 end 4559 if eq c 150 4560 fe_harg x 2 9 4561 end 4562 fe_hpathcp x 4563 fe_hcopy 4564 fe_hreturn dst x 4565 end 4566 fn fe_hbuffer c ulong dst ulong x ulong to void 4567 fe_harg x 4 8 4568 wr = ulong 0 4569 if or or or or or eq c 113 eq c 116 eq c 117 eq c 118 eq c 131 eq c 224 4570 wr = ulong 1 4571 end 4572 e = fe_harray x wr 4573 if or or eq c 116 eq c 118 eq c 119 4574 fe_harg x 2 8 4575 end 4576 if or eq c 116 eq c 117 4577 tmp = fe_alloc 4578 fe_trapc 3 3 4579 end 4580 fe_save 4581 4582 if or eq c 131 eq c 224 4583 note Socket-name queries use a private 32-bit socklen and return the full length. 4584 fe_stkchk 4585 else 4586 end 4587 fe_hreturn dst x 4588 end 4589 fn fe_hargs c ulong dst ulong x ulong to void 4590 if eq c 121 4591 fe_save 4592 fe_hreturn dst x 4593 ret 4594 end 4595 if eq c 136 4596 note envcnt: walk the environment vector X27 + 8*(argc+2) (after argv's own null word) until the 4597 note terminating null. 4598 fe_save 4599 fe_hreturn dst x 4600 ret 4601 end 4602 fe_harg x 4 5 4603 e = fe_harray x 1 4604 fe_save 4605 if eq c 137 4606 note envread: envp[index] lives at X27 + 8*(argc+2+index); scan the entries before it so an 4607 note index at or past the count traps 3 even when the vector is sparse or empty. 4608 fe_trapc 0 3 4609 fe_trapc 0 3 4610 else 4611 fe_trapc 2 3 4612 end 4613 fe_trapc 2 3 4614 fe_hreturn dst x 4615 end 4616 4617 note waitio(fd int, events int, timeout_ns long): revents, 0 timeout, or negative errno. 4618 note ppoll uses one private pollfd and one private timespec. Negative timeout is infinite. 4619 fn fe_hwaitio dst ulong x ulong to void 4620 fe_harg x 0 8 4621 fe_harg x 1 8 4622 fe_harg x 2 9 4623 fe_save 4624 note pollfd.events is 16 bits; refuse truncation of the public int argument. 4625 fe_trapc 11 3 4626 fe_trapc 8 3 4627 fe_stkchk 4628 fe_hreturn dst x 4629 end 4630 4631 note A packed argument list is u16 count followed by count (u16 length, bytes) records. 4632 note Byte order is little-endian. The packet is at most 4096 bytes and 64 records. 4633 note The decoder constructs kernel pointers only in private stack memory. 4634 fn fe_hpack c ulong dst ulong x ulong to void 4635 e = fe_harray x 0 4636 if eq c 125 4637 fe_harg x 2 8 4638 end 4639 note execenv 233 (omc.om hpack, hnpass): a second packet, the environment, read the same way; its 4640 note byte and record caps are checked before the stack check, and the record scan runs once per packet. 4641 np = ulong 1 4642 if eq c 233 4643 e = fe_harray x 0 4644 np = ulong 2 4645 end 4646 fe_save 4647 fe_trapc 8 3 4648 fe_trapc 3 3 4649 if eq c 233 4650 fe_trapc 8 3 4651 fe_trapc 3 3 4652 end 4653 fe_stkchk 4654 for pass ulong np bound 2 4655 fe_trapc 0 3 4656 fe_trapc 8 3 4657 if or or eq c 125 eq c 141 eq c 142 4658 fe_trapc 1 3 4659 end 4660 fe_trapc 3 3 4661 fe_trapc 8 3 4662 note A program path and both rename paths must be nonempty. 4663 if or eq c 124 eq c 198 4664 fe_trapc 0 3 4665 else 4666 fe_trapc 0 3 4667 end 4668 fe_trapc 0 3 4669 fe_trapc 1 3 4670 end 4671 if or or eq c 124 eq c 198 eq c 233 4672 note Exec admits only the caller-assigned standard streams. Linux close_range with UNSHARE 4673 note closes every descriptor >=3 in a private table. Failure returns without executing a child; 4674 note no guessed descriptor ceiling or permissive fallback. This is not filesystem isolation. 4675 note outer and done are dead after the packet scan; they are reused for the two branch sites here. 4676 if eq c 198 4677 note execpure strict stdio profile: Linux UAPI layouts in 640 private guest stack bytes, never an 4678 note exposed native pointer. sock_filter is u16 code,u8 jt,u8 jf,u32 k; sock_fprog has its length at 4679 note 0 and its pointer at 8 on AArch64. A Landlock path rule is a packed u64 allowed_access plus an 4680 note s32 parent_fd; prlimit64 takes two u64s. Each step that returns a negative value branches (B.LT) 4681 note to the common restore with the kernel error in x0. ADD x16,SP,#k then STR x0,[x16] stores a word. 4682 n = ulong 0 4683 fe_stkchk 4684 note Extra descriptors are already closed in a private table. Pin the executable as descriptor 3. 4685 n = add n 1 4686 note ABI3 rights through TRUNCATE are all handled, with only read/execute of that one inode allowed. 4687 n = add n 1 4688 n = add n 1 4689 n = add n 1 4690 n = add n 1 4691 n = add n 1 4692 note Per-process ceilings as (resource, soft, hard): CPU, FSIZE, STACK, CORE, NPROC, NOFILE, AS. 4693 note Pipe-output and wall budgets additionally require the trusted supervisor. 4694 for i ulong 7 4695 n = add n 1 4696 end 4697 note Validate architecture, then read only 0, write only 1/2, exit/exit_group. Everything else is EPERM. 4698 note execveat is restricted to descriptor 3 and AT_EMPTY_PATH; Landlock also binds execution to inode 3. 4699 note The inode rule is essential: an absolute execveat path otherwise ignores its dirfd argument. 4700 note Entry i = code | jt<<16 | jf<<24 | k<<32, stored at SP+128+8i. (code jt jf k) rows in order: 4701 note (32 0 0 4) (21 1 0 `3221225655`) (6 0 0 `2147483648`) (32 0 0 0) (21 0 3 63) (32 0 0 16) (21 0 1 0) (6 0 0 `2147418112`) (32 0 0 0) 4702 note (21 0 4 64) (32 0 0 16) (21 1 0 1) (21 0 1 2) (6 0 0 `2147418112`) (32 0 0 0) (21 0 1 93) (6 0 0 `2147418112`) (21 0 1 94) 4703 note (6 0 0 `2147418112`) (32 0 0 0) (21 0 5 281) (32 0 0 16) (21 0 3 3) (32 0 0 48) (21 0 1 4096) (6 0 0 `2147418112`) (6 0 0 327681) 4704 n = add n 1 4705 note Restore the original packet stack before entering the pinned executable. Descriptor 3 is CLOEXEC. 4706 while gt n 0 4707 n = sub n 1 4708 end 4709 else 4710 end 4711 else 4712 end 4713 fe_hreturn dst x 4714 end 4715 4716 note prlimit pid res A off n (keyword 235, omc.om hprlim): pid and res int, A a writable byte slice; 4717 note no trap site of its own (n other than 16 or 32 returns -22 at run time). 4718 fn fe_hprlim dst ulong x ulong to void 4719 fe_harg x 2 8 4720 fe_harg x 3 8 4721 e = fe_harray x 1 4722 fe_save 4723 fe_hreturn dst x 4724 end 4725 4726 note cpuset 236 / cpuget 237 pid A off n, cpunow 238 (keywords 236..238, omc.om hsched): pid int, A a byte 4727 note slice (cpuget writable); cpunow has no operand and checks the stack floor before its 16-byte slot. 4728 note No trap site of its own beyond the slice check. 4729 fn fe_hsched c ulong dst ulong x ulong to void 4730 if eq c 238 4731 fe_save 4732 fe_stkchk 4733 fe_hreturn dst x 4734 ret 4735 end 4736 fe_harg x 2 8 4737 w = ulong 0 4738 if eq c 237 4739 w = ulong 1 4740 end 4741 e = fe_harray x w 4742 fe_save 4743 fe_hreturn dst x 4744 end 4745 4746 fn fe_hreadlnk dst ulong x ulong to void 4747 e = fe_harray x 0 4748 put ar_m add get ar_rb 59 add x 23 e 4749 put ar_m add get ar_rb 59 add x 24 ar_w 59 add x 21 4750 put ar_m add get ar_rb 59 add x 25 ar_w 59 add x 22 4751 e = fe_harray x 1 4752 put ar_m add get ar_rb 59 add x 26 e 4753 put ar_m add get ar_rb 59 add x 27 ar_w 59 add x 21 4754 put ar_m add get ar_rb 59 add x 28 ar_w 59 add x 22 4755 put ar_m add get ar_rb 59 add x 20 ar_w 59 add x 23 4756 put ar_m add get ar_rb 59 add x 21 ar_w 59 add x 24 4757 put ar_m add get ar_rb 59 add x 22 ar_w 59 add x 25 4758 fe_hpathcp x 4759 note readlnk refuses an empty path before the kernel call. 4760 fe_trapc 0 3 4761 fe_hcopy 4762 fe_hreturn dst x 4763 end 4764 note stat: path slice (readonly) + output slice, at least 128 bytes for the ARM64 stat structure. 4765 note Linux newfstatat(AT_FDCWD, path, out, 0); returns 0 or -errno. A short output traps 3. 4766 note pread/pwrite: fd, byte slice (off, n), position long. The file offset is not moved. 4767 note pread (161) writes A, so A must be writable (error 20); pwrite (162) only reads A, so a text is allowed. 4768 fn fe_hpread c ulong dst ulong x ulong to void 4769 fe_harg x 4 8 4770 wr = ulong 0 4771 if eq c 161 4772 wr = ulong 1 4773 end 4774 e = fe_harray x wr 4775 fe_harg x 3 9 4776 fe_save 4777 fe_hreturn dst x 4778 end 4779 4780 fn fe_hstat c ulong dst ulong x ulong to void 4781 e = fe_harray x 0 4782 put ar_m add get ar_rb 59 add x 23 e 4783 put ar_m add get ar_rb 59 add x 24 ar_w 59 add x 21 4784 put ar_m add get ar_rb 59 add x 25 ar_w 59 add x 22 4785 e = fe_harray x 1 4786 put ar_m add get ar_rb 59 add x 26 e 4787 put ar_m add get ar_rb 59 add x 27 ar_w 59 add x 21 4788 put ar_m add get ar_rb 59 add x 28 ar_w 59 add x 22 4789 put ar_m add get ar_rb 59 add x 20 ar_w 59 add x 23 4790 put ar_m add get ar_rb 59 add x 21 ar_w 59 add x 24 4791 put ar_m add get ar_rb 59 add x 22 ar_w 59 add x 25 4792 fe_hpathcp x 4793 note stat refuses an empty path before the kernel call. 4794 fe_trapc 0 3 4795 fe_trapc 3 3 4796 fe_hcopy 4797 fe_hreturn dst x 4798 end 4799 fn fe_hsockopt dst ulong x ulong to void 4800 fe_harg x 2 8 4801 fe_harg x 3 8 4802 fe_harg x 4 8 4803 e = fe_harray x 0 4804 fe_save 4805 note Only scalar transport options; no filters, devices, credentials or pointer-bearing options. 4806 fe_hreturn dst x 4807 end 4808 4809 4810 note SO_PEERCRED: fixed 12-byte ucred result, never a caller-chosen getsockopt operation. 4811 fn fe_hpeercr dst ulong x ulong to void 4812 fe_harg x 4 8 4813 e = fe_harray x 1 4814 fe_save 4815 fe_trapc 3 3 4816 fe_stkchk 4817 fe_hreturn dst x 4818 end 4819 4820 note pollfds uses packed Linux pollfd records; length is bytes, each record is 8 bytes. 4821 note Maximum 1024 records, checked before ppoll. Kernel writes only revents in the checked slice. 4822 fn fe_hpollfds dst ulong x ulong to void 4823 e = fe_harray x 1 4824 fe_harg x 2 9 4825 fe_save 4826 fe_trapc 1 3 4827 fe_trapc 8 3 4828 fe_stkchk 4829 fe_hreturn dst x 4830 end 4831 4832 note sendmsg has one checked iovec and no ancillary data or exposed kernel pointers. 4833 note Arm ARM STR unsigned offset: imm12 scaled by 8, Rn=SP; private msghdr then iovec. 4834 fn fe_hsendmsg dst ulong x ulong to void 4835 fe_harg x 4 8 4836 e = fe_harray x 0 4837 fe_harg x 2 8 4838 fe_save 4839 fe_stkchk 4840 fe_hreturn dst x 4841 end 4842 4843 note Bounded mapping table belongs to the emitted program, not the compiler process. 4844 note 128 slots of address, byte length, generation, access. Only owned spans are accessible. 4845 note Function mode has no program image: the caller's runtime table supplies the zero-initialised 4846 note 4096-byte table at entry 31 (mcheck and mnew load it from [x7, #248]); nothing is reserved here. 4847 fn fe_mtinit to void 4848 if eq get f_progmo 0 0 4849 ret 4850 end 4851 if eq get f_maptab 0 0 4852 p = get f_poolb 0 4853 if gt p `1073737728` 4854 fe_fail 23 4855 end 4856 put f_maptab 0 add `276824064` p 4857 put f_poolb 0 add p 4096 4858 end 4859 end 4860 4861 fn fe_fdcheck kind ulong to void 4862 fe_trapc 0 3 4863 end 4864 4865 4866 4867 note Validate a long handle in X10; produce entry X11, base X13, length X12. 4868 note The slot's generation defeats a stale handle after close and slot reuse. 4869 fn fe_mcheck to void 4870 fe_trapc 3 3 4871 if eq get f_progmo 0 0 4872 fe_trapc 3 3 4873 fe_trapc 8 3 4874 fe_trapc 8 3 4875 else 4876 fe_trapc 8 3 4877 end 4878 fe_trapc 0 3 4879 fe_trapc 1 3 4880 fe_trapc 0 3 4881 end 4882 4883 note mapnew fd:int offset:ulong bytes:ulong access:int mode:int -> long handle/errno. 4884 note Access 1 or 3 and modes 1/2/33/34 must be literal. No fixed address or executable map. 4885 note vfiomap fd:int A off n -> long handle/errno: n must be 32, a struct vfio_region_info the kernel 4886 note filled. Its flags need READ|MMAP (1|4); size and offset come from the span. Always read-only shared. 4887 note vfiomapw is the same with flags READ|WRITE|MMAP (7) and a read/write shared map, so mapset can store 4888 note to device registers (BAR0 MMIO). Only a span the kernel reported writable maps writable. 4889 fn fe_mnew c ulong dst ulong x ulong to void 4890 acc = ulong 0 4891 mode = ulong `1048610` 4892 if or eq c 229 eq c 230 4893 fe_harg x 4 8 4894 note each call can grow the arena and move region 59: its result first, then the store's address 4895 rv59 = fe_harray x 0 4896 put ar_m add get ar_rb 59 add x 20 rv59 4897 rv59 = fe_alloc 4898 put ar_m add get ar_rb 59 add x 23 rv59 4899 fe_trapc 1 3 4900 acc = ulong 1 4901 if eq c 230 4902 acc = ulong 3 4903 end 4904 mode = ulong 1 4905 end 4906 if eq c 167 4907 fe_harg x 0 8 4908 fe_harg x 1 5 4909 fe_harg x 2 5 4910 fe_harg x 3 8 4911 fe_harg x 4 8 4912 if or ne ar_w 59 add x 14 3 ne ar_w 59 add x 16 3 4913 fe_fail 9 4914 end 4915 acc = get ar_m add get ar_rb 59 add x 15 4916 mode = get ar_m add get ar_rb 59 add x 17 4917 if and ne acc 1 ne acc 3 4918 fe_fail 9 4919 end 4920 if and and and ne mode 1 ne mode 2 ne mode 33 ne mode 34 4921 fe_fail 9 4922 end 4923 end 4924 if eq c 176 4925 fe_harg x 1 5 4926 fe_harg x 2 5 4927 end 4928 fe_save 4929 if or eq c 229 eq c 230 4930 fe_trapc 1 3 4931 else 4932 end 4933 fe_trapc 0 3 4934 fe_trapc 8 3 4935 if eq c 167 4936 if ge mode 32 4937 fe_trapc 1 3 4938 fe_trapc 1 3 4939 end 4940 end 4941 if eq c 176 4942 note Reservations are page aligned and bounded below the 40-bit GPU command limit. 4943 fe_trapc 3 3 4944 fe_trapc 8 3 4945 fe_trapc 1 3 4946 fe_trapc 1 3 4947 end 4948 if eq get f_progmo 0 0 4949 fe_trapc 3 3 4950 fe_trapc 8 3 4951 fe_trapc 3 3 4952 fe_trapc 8 3 4953 else 4954 end 4955 if eq c 176 4956 note Old kernels may ignore NOREPLACE; reject and unmap any displaced result. 4957 fe_trapc 1 3 4958 end 4959 fe_hreturn dst x 4960 end 4961 4962 note Replace only an entire owned PROT_NONE reservation. Failed binds retire the handle. 4963 fn fe_mbind dst ulong x ulong to void 4964 fe_harg x 0 9 4965 fe_harg x 1 8 4966 fe_harg x 2 5 4967 fe_harg x 3 8 4968 if ne ar_w 59 add x 14 3 4969 fe_fail 9 4970 end 4971 acc = get ar_m add get ar_rb 59 add x 15 4972 if and ne acc 1 ne acc 3 4973 fe_fail 9 4974 end 4975 fe_save 4976 fe_mcheck 4977 fe_trapc 1 3 4978 fe_trapc 1 3 4979 note Preserve a droppable owner but forbid a second bind if cleanup also fails. 4980 fe_trapc 1 3 4981 fe_hreturn dst x 4982 end 4983 4984 note Copies traverse only checked live mapped spans and normal bounded byte arrays. 4985 note mapread writes A; mapwrite reads A. Both return the count, with no pointer decay. 4986 fn fe_mcopy c ulong dst ulong x ulong to void 4987 fe_harg x 4 9 4988 fe_harg x 3 5 4989 wr = ulong 0 4990 if eq c 169 4991 wr = ulong 1 4992 end 4993 e = fe_harray x wr 4994 fe_save 4995 fe_mcheck 4996 fe_trapc 0 3 4997 if eq get f_progmo 0 0 4998 fe_trapc 8 3 4999 end 5000 fe_trapc 8 3 5001 fe_trapc 8 3 5002 if eq c 170 5003 fe_trapc 1 3 5004 end 5005 fe_hreturn dst x 5006 end 5007 5008 note NVRM NVOS21/NVOS54 parameter binding. The kernel sees one private header. 5009 note Pointer and length are derived from a checked byte span, never from user bytes. 5010 note Request is exactly the 32-byte RM_ALLOC or RM_CONTROL encoding. 5011 fn fe_hdevcall dst ulong x ulong to void 5012 n = fe_xhreq 171 x 5013 e = fe_harray x 1 5014 put ar_m add get ar_rb 59 add x 23 e 5015 put ar_m add get ar_rb 59 add x 24 ar_w 59 add x 21 5016 t = fe_alloc 5017 fe_trapc 1 3 5018 f = fe_harray x 1 5019 if eq e f 5020 fe_fail 19 5021 end 5022 t = fe_alloc 5023 fe_trapc 8 3 5024 fe_save 5025 note Refuse overlapping parameter/header spans even through distinct edit parameters. 5026 fe_trapc 3 3 5027 fe_trapc 1 3 5028 fe_stkchk 5029 fe_hreturn dst x 5030 end 5031 5032 5033 note Mapped-address export for driver GPU VA serialization; no arbitrary-address access. 5034 note Aligned word access uses exactly one 32/64-bit load/store bracketed by DSB SY. 5035 fn fe_mmapio c ulong dst ulong x ulong to void 5036 fe_harg x 0 9 5037 if eq c 173 5038 fe_save 5039 fe_mcheck 5040 fe_hreturn dst x 5041 put f_rt 0 5 5042 ret 5043 end 5044 fe_harg x 1 5 5045 fe_harg x 2 8 5046 if ne ar_w 59 add x 12 3 5047 fe_fail 9 5048 end 5049 w = get ar_m add get ar_rb 59 add x 13 5050 if and ne w 4 ne w 8 5051 fe_fail 9 5052 end 5053 if eq c 175 5054 fe_harg x 3 5 5055 end 5056 fe_save 5057 fe_mcheck 5058 fe_trapc 0 3 5059 if eq get f_progmo 0 0 5060 fe_trapc 8 3 5061 end 5062 fe_trapc 8 3 5063 fe_trapc 3 3 5064 fe_trapc 1 3 5065 if eq c 175 5066 fe_trapc 1 3 5067 if eq w 4 5068 fe_trapc 8 3 5069 end 5070 fe_hreturn dst x 5071 else 5072 fe_hreturn dst x 5073 put f_rt 0 5 5074 end 5075 end 5076 5077 fn fe_hostval c ulong dst ulong to void 5078 note Function mode (no program image: no argv in x27, no x28 stack floor, no globals) refuses host 5079 note words with error 9, except in an OM-2 unit the file and identity subset that needs none of the 5080 note image: fclose 100, fopen 110, fstat 117, stat 140, getuid 145, geteuid 146, getgid 147, getegid 148, 5081 note lstat 149 (OMEGESE.md 10, spec/omegese-om2.md); the clocks monons 109, realns 130 and sleepns 120; 5082 note and the device subset devctl 166, mapnew 167, mapdrop 168, mapread 169, mapwrite 170, devcall 171, 5083 note uvmctl 172, mapaddr 173, mapget 174, mapset 175, maphold 176 and mapbind 177. Fixed replacement 5084 note is only over a whole live PROT_NONE reservation owned by this table. Each is save, inline svc, 5085 note restore; x7 and x19..x28 are never written. Function-mode table entry31 points at a 32-byte 5086 note header (capacity1..4098, generation base, generation limit, reserved) then capacity32-byte slots. 5087 note Handles use13slot bits; program mode retains its raw128slots and8slot-bit handles. 5088 if eq get f_progmo 0 0 5089 if eq get f_om2 0 0 5090 fe_fail 9 5091 end 5092 ok = ulong 0 5093 if or or eq c 100 eq c 110 or eq c 117 eq c 140 5094 ok = ulong 1 5095 end 5096 if and ge c 145 le c 149 5097 ok = ulong 1 5098 end 5099 if or or eq c 109 eq c 120 eq c 130 5100 ok = ulong 1 5101 end 5102 if and ge c 166 le c 177 5103 ok = ulong 1 5104 end 5105 if eq ok 0 5106 fe_fail 9 5107 end 5108 end 5109 x = mul get f_depth 0 32 5110 put ar_m add get ar_rb 59 add x 7 get f_nslot 0 5111 note The library words of `target macos`: libfn k (int), libptr A off n (a writable byte slice), libcall F A off n 5112 note (F ulong, then the register file). Each gives a long. Typed here; lowered by lhost from lhfmt. 5113 if and ge c 241 le c 243 5114 if eq c 241 5115 fe_harg x 0 8 5116 end 5117 if eq c 242 5118 e = fe_harray x 1 5119 end 5120 if eq c 243 5121 fe_harg x 4 5 5122 e = fe_harray x 1 5123 end 5124 fe_save 5125 fe_hreturn dst x 5126 ret 5127 end 5128 note VFIO words are program-only. These IDs are disjoint from efi178, qty223 and peername224. 5129 if and ge c 228 le c 232 5130 if eq get f_fdtab 0 0 5131 fdpool = get f_poolb 0 5132 if gt fdpool `1073739776` 5133 fe_fail 23 5134 end 5135 put f_fdtab 0 add `276824064` fdpool 5136 put f_poolb 0 add fdpool 2048 5137 end 5138 if eq c 228 5139 note VFIO container, group and device requests: _IO(';', 100 + k) from linux/vfio.h, exact allowlist and 5140 note shapes. GET_API_VERSION 15204 takes no argument (n 0). DEVICE_RESET 15215 is not allowed: W0 never 5141 note resets the device from Omega (Drake: W0a only, no FLR). CHECK_EXTENSION 15205 and 5142 note SET_IOMMU 15206 pass the 4-byte little-endian value in the span; SET_IOMMU accepts only TYPE1v2 (3). 5143 note GROUP_SET_CONTAINER 15208 points at a 4-byte fd. GROUP_GET_STATUS 15207 (8), DEVICE_GET_INFO 15211 5144 note (24) and DEVICE_GET_REGION_INFO 15212 (32) point at the span after the compiler itself stores 5145 note argsz = n, so the kernel copies at most n bytes. GROUP_GET_DEVICE_FD 15210 passes a private zero- 5146 note terminated copy of a non-empty span (at most 4095 bytes, no embedded zero). 5147 note IOMMU_MAP_DMA 15217 (32) takes an Omega mapping handle in the vaddr field (bytes 8..15), never an 5148 note address: the compiler checks the handle like mapget, requires a read/write mapping and flags exactly 5149 note READ|WRITE (3), then stores the mapping's own base address and whole length into vaddr and size. 5150 note The caller chooses only the IOVA (bytes 16..23). IOMMU_UNMAP_DMA 15218 (24) requires flags 0 (no 5151 note dirty bitmap, no ALL, no VADDR) and unmaps only the caller's IOVA range in its own container. 5152 fe_mtinit 5153 fe_harg x 4 8 5154 fe_harg x 2 4 5155 if ne ar_w 59 add x 12 3 5156 fe_fail 9 5157 end 5158 q = get ar_m add get ar_rb 59 add x 13 5159 if eq q 15210 5160 e = fe_harray x 0 5161 fe_hpathcp x 5162 fe_trapc 0 3 5163 fe_hcopy 5164 fe_hreturn dst x 5165 ret 5166 end 5167 n = ulong 99 5168 if eq q 15204 5169 n = ulong 0 5170 end 5171 if or or eq q 15205 eq q 15206 eq q 15208 5172 n = ulong 4 5173 end 5174 if eq q 15207 5175 n = ulong 8 5176 end 5177 if eq q 15211 5178 n = ulong 24 5179 end 5180 if eq q 15212 5181 n = ulong 32 5182 end 5183 if eq q 15217 5184 n = ulong 32 5185 end 5186 if eq q 15218 5187 n = ulong 24 5188 end 5189 if eq n 99 5190 fe_fail 9 5191 end 5192 put ar_m add get ar_rb 59 add x 23 n 5193 e = fe_harray x 1 5194 t = fe_alloc 5195 fe_trapc 1 3 5196 fe_save 5197 if eq q 15217 5198 fe_trapc 1 3 5199 fe_mcheck 5200 fe_trapc 1 3 5201 end 5202 if eq q 15218 5203 fe_trapc 1 3 5204 end 5205 if eq q 15206 5206 fe_trapc 1 3 5207 end 5208 fe_hreturn dst x 5209 end 5210 if or eq c 229 eq c 230 5211 fe_mtinit 5212 fe_mnew c dst x 5213 end 5214 if eq c 231 5215 note Fixed eventfd flags: CLOEXEC prevents exec leakage; NONBLOCK makes drained reads safe. 5216 fe_harg x 0 4 5217 fe_save 5218 fe_hreturn dst x 5219 end 5220 if eq c 232 5221 note GET_IRQ_INFO and SET_IRQS only; caller bytes cannot introduce pointers or arbitrary ioctls. 5222 fe_harg x 4 8 5223 fe_harg x 2 4 5224 if ne ar_w 59 add x 12 3 5225 fe_fail 9 5226 end 5227 q = get ar_m add get ar_rb 59 add x 13 5228 if and ne q 15213 ne q 15214 5229 fe_fail 9 5230 end 5231 e = fe_harray x 1 5232 fe_save 5233 fe_fdcheck 1 5234 if eq q 15213 5235 fe_trapc 1 3 5236 else 5237 fe_trapc 3 3 5238 fe_trapc 8 3 5239 end 5240 fe_trapc 1 3 5241 if eq q 15214 5242 fe_trapc 8 3 5243 fe_trapc 8 3 5244 fe_trapc 1 3 5245 note DATA_NONE MASK or UNMASK. Linux checks the device's MASKABLE capability. 5246 fe_trapc 1 3 5247 fe_trapc 0 3 5248 fe_trapc 1 3 5249 fe_trapc 1 3 5250 fe_trapc 0 3 5251 fe_trapc 1 3 5252 fe_fdcheck 2 5253 end 5254 fe_hreturn dst x 5255 end 5256 ret 5257 end 5258 if eq c 197 5259 fe_hscalar c dst x 5260 ret 5261 end 5262 note execpure 198 and execenv 233 are dispatched here, before the ge c 173 mapped-memory range below 5263 note would claim them. 5264 if or eq c 198 eq c 233 5265 fe_hpack c dst x 5266 ret 5267 end 5268 if eq c 220 5269 fe_hpeercr dst x 5270 ret 5271 end 5272 if eq c 235 5273 fe_hprlim dst x 5274 ret 5275 end 5276 if and ge c 236 le c 238 5277 fe_hsched c dst x 5278 ret 5279 end 5280 if or eq c 239 eq c 240 5281 fe_hscalar c dst x 5282 ret 5283 end 5284 if eq c 221 5285 fe_hpollfds dst x 5286 ret 5287 end 5288 if eq c 222 5289 fe_hsendmsg dst x 5290 ret 5291 end 5292 if eq c 224 5293 fe_hbuffer c dst x 5294 ret 5295 end 5296 if eq c 176 5297 fe_mtinit 5298 fe_mnew c dst x 5299 ret 5300 end 5301 if eq c 177 5302 fe_mtinit 5303 fe_mbind dst x 5304 ret 5305 end 5306 if ge c 173 5307 fe_mtinit 5308 fe_mmapio c dst x 5309 ret 5310 end 5311 if eq c 172 5312 note Linux UVM has unencoded commands. Exact allowlist and ABI580.173.02 byte sizes. 5313 note the call can grow the arena and move region 59: its result first, then the store's address 5314 rv59 = fe_xhreq 172 x 5315 put ar_m add get ar_rb 59 add x 23 rv59 5316 e = fe_harray x 1 5317 t = fe_alloc 5318 fe_trapc 1 3 5319 fe_save 5320 fe_hreturn dst x 5321 ret 5322 end 5323 if eq c 171 5324 fe_hdevcall dst x 5325 ret 5326 end 5327 if ge c 167 5328 fe_mtinit 5329 if eq c 167 5330 fe_mnew c dst x 5331 ret 5332 end 5333 if eq c 168 5334 fe_harg x 0 9 5335 fe_save 5336 fe_mcheck 5337 fe_hreturn dst x 5338 ret 5339 end 5340 fe_mcopy c dst x 5341 ret 5342 end 5343 if eq c 166 5344 note Same bounded ioctl contract as L605 src/device/omc.om at `0dee699`. 5345 note Compose with native host words instead of maintaining a second compiler. 5346 note Only literal FIONREAD, encoded read/write NVRM F, or five exact aien-gpu ABI1 A requests. 5347 note the call can grow the arena and move region 59: its result first, then the store's address 5348 rv59 = fe_xhreq 166 x 5349 put ar_m add get ar_rb 59 add x 23 rv59 5350 e = fe_harray x 1 5351 t = fe_alloc 5352 fe_trapc 1 3 5353 fe_save 5354 fe_hreturn dst x 5355 ret 5356 end 5357 if eq c 132 5358 e = fe_harray x 1 5359 fe_save 5360 fe_hreturn dst x 5361 ret 5362 end 5363 if eq c 133 5364 fe_hreadlnk dst x 5365 ret 5366 end 5367 if eq c 134 5368 fe_hsockopt dst x 5369 ret 5370 end 5371 if eq c 135 5372 note random A off n flags: Linux getrandom into a writable byte slice. Returns the bytes written or 5373 note minus the Linux error number. flags follows getrandom(2): 0 blocks until the pool is ready, 5374 note 1 (GRND_NONBLOCK) returns -EAGAIN instead, 2 (GRND_INSECURE) may return non-cryptographic bytes. 5375 e = fe_harray x 1 5376 fe_harg x 2 8 5377 fe_save 5378 fe_hreturn dst x 5379 ret 5380 end 5381 if or eq c 109 eq c 130 5382 fe_hclock c dst x 5383 ret 5384 end 5385 if or and ge c 113 le c 119 eq c 131 5386 fe_hbuffer c dst x 5387 ret 5388 end 5389 if eq c 120 5390 fe_harg x 0 9 5391 fe_save 5392 fe_trapc 11 3 5393 fe_stkchk 5394 note MSUB x5,x4,x3,x2 gives the subsecond remainder. 5395 fe_hreturn dst x 5396 ret 5397 end 5398 if eq c 123 5399 fe_hwaitio dst x 5400 ret 5401 end 5402 if or or or eq c 124 eq c 125 eq c 141 eq c 142 5403 fe_hpack c dst x 5404 ret 5405 end 5406 if or or or or or or eq c 126 eq c 138 eq c 143 eq c 144 eq c 150 eq c 151 eq c 157 5407 fe_hpath c dst x 5408 ret 5409 end 5410 if eq c 140 5411 fe_hstat 140 dst x 5412 ret 5413 end 5414 if eq c 149 5415 fe_hstat 149 dst x 5416 ret 5417 end 5418 if and ge c 145 le c 148 5419 fe_hscalar c dst x 5420 ret 5421 end 5422 if or or or eq c 153 eq c 154 eq c 155 eq c 156 5423 fe_hscalar c dst x 5424 ret 5425 end 5426 if and ge c 158 le c 160 5427 fe_hscalar c dst x 5428 ret 5429 end 5430 if or eq c 161 eq c 162 5431 fe_hpread c dst x 5432 ret 5433 end 5434 if and ge c 163 le c 165 5435 fe_hscalar c dst x 5436 ret 5437 end 5438 if or or eq c 127 eq c 129 eq c 139 5439 fe_hscalar c dst x 5440 ret 5441 end 5442 if eq c 128 5443 e = fe_harray x 1 5444 fe_harg x 2 8 5445 tmp = fe_alloc 5446 fe_trapc 3 3 5447 fe_save 5448 fe_hreturn dst x 5449 ret 5450 end 5451 if ge c 121 5452 put f_hostar 0 1 5453 fe_hargs c dst x 5454 ret 5455 end 5456 if ge c 110 5457 fe_hpath c dst x 5458 ret 5459 end 5460 fe_hscalar c dst x 5461 end 5462 5463 note ======== rdval: read one value (om4 VAL, VALTOK, CALL and the VT_ parts, one self-recursive 5464 note function because a function calls only earlier functions or itself) ======== 5465 note mode 0: read the first word; 1: the first word is the current token; 2: a call of function fe (index 5466 note + 1), its arguments still to read. exp the expected type (0 none), dst the destination register (255 5467 note none). Out: rk kind (1 register, 2 bare number, 3 typed number, 4 flags, 9 a float in a twin, only when 5468 note asked for by fpw), rv register / number / condition, rt type (for a bare number: 1 when written as 2^63 5469 note or more). Only the outermost op writes the destination. Every value nests one level deeper (at most 5470 note 32768, error 14: what bounds it is ng's own stack, see the note at the depth check); a call does not. 5471 fn fe_rdval mode ulong exp ulong dst ulong fe ulong to void 5472 note fwtake: rdval's entry: keep the caller's fpw request for this depth (none on x86, which has no twins) 5473 put ar_m add get ar_rb 60 add get f_depth 0 1 get f_fpw 0 5474 put f_fpw 0 0 5475 put f_dexp 0 1 5476 if eq mode 2 5477 if ne get f_cpure 0 0 5478 fe_fail 30 5479 end 5480 if ne get f_om2 0 0 5481 if ne ar_c 25 sub fe 1 0 5482 fe_inl_call fe dst 5483 ret 5484 end 5485 end 5486 cb = add mul get f_depth 0 32 8 5487 put ar_m add get ar_rb 59 add cb 18 ulong ar_c 22 sub fe 1 5488 put ar_m add get ar_rb 59 add cb 19 get f_nslot 0 5489 if eq get f_progmo 0 0 5490 if eq get f_curfn 0 fe 5491 fe_fail 9 5492 end 5493 end 5494 i = ulong 0 5495 while lt i ar_w 59 add cb 18 5496 p = add mul sub fe 1 6 i 5497 if eq ar_c 35 p 0 5498 if ne fe_isfloat ulong ar_c 33 p 0 5499 put f_fpw 0 1 5500 end 5501 fe_rdval 0 ulong ar_c 33 p 255 0 5502 fe_ca_scal p add cb mul i 3 5503 else 5504 if ge ar_c 35 p 6 5505 fe_ca_st fe i cb 5506 else 5507 fe_ca_arr fe i cb 5508 fe_fz_arg get f_rt 0 5509 end 5510 end 5511 i = add i 1 5512 end 5513 fe_ca_end fe dst cb 5514 ret 5515 end 5516 if eq mode 0 5517 fe_tok 5518 end 5519 if ne get f_cpure 0 0 5520 fe_cp_token 5521 end 5522 put f_depth 0 add get f_depth 0 1 5523 note value nesting: the per-depth cells (f_fr, f_fwv, f_ul_k, f_ul_v) are arena group depth and grow. What 5524 note bounds the depth is ng's own stack: fe_rdval (and front-ir's fe_lval after it) recurse once per level, and 5525 note ng, an omc program, has the fixed 8 MiB stack pool of program mode; past it ng would trap 6 with no line. 5526 note Measured 2026-11-11 with this bound lifted: nested calls are the deepest frame, about 243 bytes per level in 5527 note front-ir (trap 6 between 34000 and 35000 levels) and 142 in the check pass (between 58000 and 60000). 5528 note Allowing 256 bytes per level, as omc does, `8388608` / 256 = 32768 levels, omc's own bound (gate15's 5529 note g15_e14_capacity: both refuse 14); deeper is error 14 on its line, a clean refusal before the stack ends. 5530 note seed/ng/tests/nocaps/gate.om lowers each measured shape 32767 deep, so a frame that grows is noticed. 5531 if gt get f_depth 0 32768 5532 fe_fail 14 5533 end 5534 fe_need 15 add get f_depth 0 1 5535 if or eq get f_tk 0 0 eq get f_tk 0 3 5536 fe_fail 4 5537 end 5538 if eq get f_tk 0 4 5539 fe_fail 16 5540 end 5541 if eq get f_tk 0 5 5542 if ge exp 64 5543 fe_fail 7 5544 end 5545 fe_fparse get f_ts 0 get f_tl 0 5546 t = ulong 0 5547 if eq get f_fsuf 0 0 5548 if eq exp 0 5549 fe_vdone 6 add mul get f_ts 0 `16777216` get f_tl 0 ulong 0 5550 ret 5551 end 5552 if eq fe_isfloat exp 0 5553 fe_fail 7 5554 end 5555 t = exp 5556 else 5557 t = ulong 10 5558 if eq get f_fsuf 0 2 5559 t = ulong 11 5560 end 5561 if and ne exp 0 ne exp t 5562 fe_fail 7 5563 end 5564 end 5565 v = fe_fbits t 5566 fe_vdone 7 v t 5567 ret 5568 end 5569 if eq get f_tk 0 2 5570 if eq exp 0 5571 fe_vdone 2 get f_tw 0 get f_tbig 0 5572 ret 5573 end 5574 note an integer literal where a float is expected is the mixing OMEGESE 9.9 refuses (error 7); before 5575 note this it was stored as raw bits (f64 x = 1 held 0x1). The conversion f64 1 reads it with exp 0. 5576 if or ge exp 64 ne fe_isfloat exp 0 5577 fe_fail 7 5578 end 5579 fe_range get f_tw 0 exp get f_tbig 0 5580 fe_vdone 3 get f_tw 0 exp 5581 ret 5582 end 5583 if gt get f_tl 0 8 5584 f = fe_findfn get f_tw 0 get f_tl 0 get f_ts 0 5585 if eq f 0 5586 if gt get f_tl 0 63 5587 fe_unkfail 13 5588 end 5589 else 5590 if eq ar_c 21 sub f 1 12 5591 fe_fail 7 5592 end 5593 fe_rdval 2 0 dst f 5594 fe_vdec 5595 ret 5596 end 5597 end 5598 c = fe_kw get f_tw 0 5599 if eq c 178 5600 fe_xefival dst 5601 ret 5602 end 5603 if eq c 0 5604 if ne get f_cpure 0 0 5605 if eq get f_tw 0 `128009175786866` 5606 if eq get f_crkind 0 0 5607 fe_fail 30 5608 end 5609 fe_vdone get f_crkind 0 get f_crval 0 get f_crtype 0 5610 ret 5611 end 5612 end 5613 e = fe_findname get f_tw 0 5614 if ne e 0 5615 if eq ar_c 8 sub e 1 9 5616 ct = ulong ar_c 6 sub e 1 5617 cv = get ar_m add get ar_rb 9 sub e 1 5618 if ne fe_isfloat ct 0 5619 fe_vdone 7 cv ct 5620 else 5621 fe_vdone 3 cv ct 5622 end 5623 ret 5624 end 5625 if ne ar_c 8 sub e 1 0 5626 fe_fail 7 5627 end 5628 e1 = sub e 1 5629 if ne ar_c 10 e1 0 5630 nr = ulong uchar get ar_m add get ar_rb 5 e1 5631 if ne ar_w 60 get f_depth 0 0 5632 fe_vdone 9 nr ulong uchar get ar_m add get ar_rb 6 e1 5633 else 5634 fe_vdone 1 nr ulong uchar get ar_m add get ar_rb 6 e1 5635 end 5636 else 5637 fe_vdone 1 ulong ar_c 5 e1 ulong uchar get ar_m add get ar_rb 6 e1 5638 end 5639 if ne get f_cpure 0 0 5640 if ge get f_rt 0 10 5641 fe_fail 30 5642 end 5643 end 5644 ret 5645 end 5646 f = fe_findfn get f_tw 0 0 0 5647 if eq f 0 5648 fe_unkfail 3 5649 end 5650 if eq ar_c 21 sub f 1 12 5651 fe_fail 7 5652 end 5653 fe_rdval 2 0 dst f 5654 fe_vdec 5655 ret 5656 end 5657 if or eq c 88 eq c 89 5658 t = ulong 10 5659 if eq c 89 5660 t = ulong 11 5661 end 5662 fe_rdval 0 0 255 0 5663 if ge get f_rt 0 64 5664 fe_fail 7 5665 end 5666 if eq get f_rk 0 6 5667 v = fe_fspan t get f_rv 0 5668 put f_rk 0 7 5669 put f_rv 0 v 5670 put f_rt 0 t 5671 end 5672 if eq get f_rk 0 2 5673 fe_range get f_rv 0 9 get f_tbig 0 5674 put f_rk 0 3 5675 put f_rt 0 9 5676 end 5677 if eq get f_rt 0 1 5678 fe_fail 7 5679 end 5680 fe_fwreq 5681 fe_vt_conv t 5682 fe_vdec 5683 ret 5684 end 5685 if eq c 90 5686 tt = fe_typeword 5687 fe_rdval 0 0 255 0 5688 if or eq get f_rk 0 6 eq get f_rk 0 2 5689 fe_fail 11 5690 end 5691 ft = get f_rt 0 5692 if eq ft 1 5693 fe_fail 7 5694 end 5695 if or ge ft 64 ge tt 64 5696 fe_fail 7 5697 end 5698 if ne fe_twid ft fe_twid tt 5699 fe_fail 7 5700 end 5701 r = fe_matreg get f_rk 0 get f_rv 0 ft 5702 note A register holds an 8/16/32-bit unsigned value and an f32 zero-extended (canon, FMOV W) and a signed 5703 note one sign-extended, so a bitcast that changes the extension extends the bits again for tt, into a new 5704 note register (a name's register keeps its value). f32 takes the uint form. 5705 if ne fe_twid tt 64 5706 if ne and ge ft 6 le ft 8 and ge tt 6 le tt 8 5707 ct = tt 5708 if eq tt 10 5709 ct = ulong 4 5710 end 5711 rd = fe_destreg dst 5712 r = rd 5713 end 5714 end 5715 put f_rk 0 1 5716 put f_rv 0 r 5717 put f_rt 0 tt 5718 fe_vdec 5719 ret 5720 end 5721 if or or or eq c 91 eq c 92 eq c 93 eq c 94 5722 fe_fwreq 5723 if or eq c 91 eq c 92 5724 fe_fintr c dst 5725 else 5726 fe_fminmax c dst 5727 end 5728 ret 5729 end 5730 if eq c 227 5731 fe_fwreq 5732 fe_ffma dst 5733 ret 5734 end 5735 if eq c 95 5736 fe_fsizeof dst 5737 ret 5738 end 5739 if eq c 96 5740 fe_foffset dst 5741 ret 5742 end 5743 if le sub c 1 8 5744 fe_tok 5745 if eq get f_tk 0 2 5746 fe_range get f_tw 0 c get f_tbig 0 5747 fe_vdone 3 get f_tw 0 c 5748 ret 5749 end 5750 fe_rdval 1 0 255 0 5751 if ge get f_rt 0 64 5752 fe_fail 7 5753 end 5754 if eq get f_rk 0 2 5755 fe_fail 11 5756 end 5757 fe_vt_conv c 5758 fe_vdec 5759 ret 5760 end 5761 if eq c 223 5762 fe_tok 5763 if eq get f_tk 0 2 5764 fe_range get f_tw 0 13 get f_tbig 0 5765 fe_vdone 3 get f_tw 0 13 5766 ret 5767 end 5768 fe_rdval 1 0 255 0 5769 if eq get f_rk 0 6 5770 fe_fail 7 5771 end 5772 if ge get f_rt 0 64 5773 fe_fail 7 5774 end 5775 if eq get f_rk 0 2 5776 fe_fail 11 5777 end 5778 fe_vt_conv 13 5779 fe_vdec 5780 ret 5781 end 5782 if eq c 74 5783 put f_fpw 0 get ar_m add get ar_rb 60 get f_depth 0 5784 fe_rdval 0 exp dst 0 5785 fe_tok 5786 if ne get f_tk 0 1 5787 fe_fail 16 5788 end 5789 if gt get f_tl 0 8 5790 fe_fail 16 5791 end 5792 if ne fe_kw get f_tw 0 75 5793 fe_fail 16 5794 end 5795 fe_vdec 5796 ret 5797 end 5798 if or eq c 77 eq c 193 5799 fe_fail 9 5800 end 5801 if or eq c 225 eq c 226 5802 if or eq get f_progmo 0 0 ne get f_irmode 0 0 5803 fe_fail 9 5804 end 5805 x = mul get f_depth 0 32 5806 sl = get f_nslot 0 5807 note dit and scrub are emitted inline here, not in helper functions: om4 holds 512 functions and omc.om 5808 note uses 511 of them (seed/omc/size-history.tsv). 5809 if eq c 225 5810 note dit: OM-2 `dit v` (program mode): v is int, 0 or 1, else trap 3. Sets PSTATE.DIT (Arm ARM 5811 note C5.2.4: DIT is bit 24 of the special-purpose register; MRS/MSR , DIT have op0 3, op1 3, CRn 4, 5812 note CRm 2, op2 5) and gives the previous bit as a long 0 or 1. CMP Xv, #1 = SUBS XZR (C6.2.464); B.HI 5813 note trap 3; LSL X16, Xv, #24 = UBFM X16, Xv, #40, #39 (C6.2.487), taken before the destination is 5814 note written because the destination may be v's own register; MRS Xd, DIT (C6.2.287); MSR DIT, X16 5815 note (C6.2.289); UBFX Xd, Xd, #24, #1 = UBFM Xd, Xd, #24, #24. Writes to PSTATE are in program order 5816 note without further synchronization (C5.1), so the next instruction already runs under the new bit. 5817 fe_harg x 0 8 5818 r = fe_matreg ar_w 59 add x 8 get ar_m add get ar_rb 59 add x 9 8 5819 fe_trapc 8 3 5820 put f_nslot 0 sl 5821 d = fe_destreg dst 5822 fe_vdone 1 d 9 5823 ret 5824 end 5825 note scrub: OM-2 `scrub n` (program mode): n is ulong, a multiple of 16 and at most `1048576`, else trap 3. 5826 note TST Xn, #15 = ANDS XZR (C6.2.16, N 1 immr 0 imms 3); B.NE trap 3; X16 = `1048576`; CMP Xn, X16 = 5827 note SUBS XZR (C6.2.465); B.HI trap 3. X16 = SP - n: SUB X16, SP, Xn, UXTX (C6.2.456); CMP X16, X28 5828 note (C6.2.465); B.LO trap 6, before any store. Loop: CMP SP, X16 = SUBS XZR, SP, X16, UXTX (C6.2.463); 5829 note B.LS out; STP XZR, XZR, [X16], #16 (C6.2.414, post-index); B back (C6.2.35). Then MOVZ Xr, #0 5830 note (C6.2.319) for every pool register at index npar + nslot or above (no live value: parameters, 5831 note locals and the held parts of the expression sit below), X16, and X7, X18-X26, X29, which program 5832 note mode never names; then MOVI Vd.2D, #0 (C7.2.247) for V0-V15 and for every twin V16+j except those 5833 note of a live slot j (below npar + nslot) whose value lives in its twin (vsl: an f32/f64 local name or a 5834 note held kind 9 float, as save stores it); a twin of a free slot or of a slot whose value is in its x 5835 note register holds nothing live. V0-V15 carry a float only inside one operation. Never touched: SP, X27 5836 note (the Linux initial stack under args), X28 (the stack floor), X30 (the return address), the live pool 5837 note registers and live twins, NZCV, FPCR, FPSR, and the SVE P registers and FFR. Gives long 0. 5838 fe_harg x 0 5 5839 r = fe_matreg ar_w 59 add x 8 get ar_m add get ar_rb 59 add x 9 5 5840 fe_trapc 1 3 5841 fe_trapc 8 3 5842 fe_trapc 3 6 5843 put f_nslot 0 sl 5844 d = fe_destreg dst 5845 fe_vdone 1 d 9 5846 ret 5847 end 5848 if or or and ge c 100 le c 177 and ge c 197 le c 198 and ge c 220 le c 222 5849 fe_hostval c dst 5850 ret 5851 end 5852 if eq c 224 5853 fe_hostval c dst 5854 ret 5855 end 5856 if or or and ge c 228 le c 232 or eq c 233 eq c 235 and ge c 236 le c 240 5857 fe_hostval c dst 5858 ret 5859 end 5860 if and ge c 241 le c 243 5861 fe_hostval c dst 5862 ret 5863 end 5864 if eq c 186 5865 fe_rdval 0 0 255 0 5866 fe_ab_open 5867 fe_vdec 5868 ret 5869 end 5870 if eq c 185 5871 fe_ab_seal 5872 fe_vdec 5873 ret 5874 end 5875 if eq c 51 5876 e = fe_arrname 5877 if and ne ar_c 8 sub e 1 10 ge ar_c 8 sub e 1 6 5878 fe_vt_fget e dst 5879 fe_vdec 5880 ret 5881 end 5882 if ne fe_ly_get e dst 0 5883 fe_vdec 5884 ret 5885 end 5886 fe_rdval 0 5 255 0 5887 fe_fz_get e 5888 fe_fwreq 5889 fe_vt_get e dst 5890 fe_vdec 5891 ret 5892 end 5893 if eq c 52 5894 e = fe_arrname 5895 if eq ar_c 8 sub e 1 10 5896 fe_vdone 1 fe_destreg dst 5 5897 ret 5898 end 5899 if ge ar_c 8 sub e 1 6 5900 fe_fail 7 5901 end 5902 if ne fe_unsz sub e 1 0 5903 fe_vdone 1 ulong uchar get ar_m add get ar_rb 13 sub e 1 5 5904 ret 5905 end 5906 fe_vdone 3 get ar_m add get ar_rb 7 sub e 1 5 5907 ret 5908 end 5909 if or eq c 53 eq c 54 5910 x = mul get f_depth 0 32 5911 put ar_m add get ar_rb 59 add x 8 get f_nslot 0 5912 fe_rdval 0 8 255 0 5913 fe_vs_fd x 5914 e = fe_arrname 5915 fe_vs_arr c e 5916 fe_rdval 0 5 255 0 5917 fe_vs_off x 5918 fe_rdval 0 5 255 0 5919 fe_vs_end c e dst x 5920 ret 5921 end 5922 if eq c 55 5923 fe_vdone 3 1 1 5924 ret 5925 end 5926 if eq c 56 5927 fe_vdone 3 0 1 5928 ret 5929 end 5930 if and gt sub c 33 17 gt sub c 59 1 5931 if eq c 244 5932 fe_fail 9 5933 end 5934 fe_fail 16 5935 end 5936 if and ge c 49 le c 50 5937 put f_fpw 0 1 5938 fe_rdval 0 exp 255 0 5939 if ge get f_rt 0 64 5940 fe_fail 7 5941 end 5942 if and eq c 50 eq get f_rk 0 4 5943 put f_rv 0 xor get f_rv 0 1 5944 fe_vdec 5945 ret 5946 end 5947 if eq get f_rk 0 2 5948 fe_fail 11 5949 end 5950 fe_fwreq 5951 fe_vt_un c dst 5952 fe_vdec 5953 ret 5954 end 5955 put f_fpw 0 1 5956 fe_rdval 0 0 255 0 5957 ak = get f_rk 0 5958 av = get f_rv 0 5959 atp = get f_rt 0 5960 if eq ak 4 5961 av = fe_matreg 4 av atp 5962 ak = ulong 1 5963 atp = ulong 1 5964 end 5965 put f_fpw 0 1 5966 fe_rdval 0 0 255 0 5967 bk = get f_rk 0 5968 bv = get f_rv 0 5969 bt = get f_rt 0 5970 if eq bk 4 5971 bv = fe_matreg 4 bv bt 5972 bk = ulong 1 5973 bt = ulong 1 5974 end 5975 if or ge atp 64 ge bt 64 5976 x = mul get f_depth 0 32 5977 ar_pw 59 x ak 5978 ar_pw 59 add x 1 av 5979 ar_pw 59 add x 2 atp 5980 ar_pw 59 add x 3 bk 5981 ar_pw 59 add x 4 bv 5982 ar_pw 59 add x 5 bt 5983 fe_ab_bin c dst x 5984 fe_vdec 5985 ret 5986 end 5987 if and eq ak 6 eq bk 6 5988 fe_fail 11 5989 end 5990 if or ne fe_isfloat atp 0 ne fe_isfloat bt 0 5991 if eq ak 6 5992 if eq bt 0 5993 fe_fail 11 5994 end 5995 if eq fe_isfloat bt 0 5996 fe_fail 7 5997 end 5998 av = fe_fspan bt av 5999 ak = ulong 7 6000 atp = bt 6001 end 6002 if eq bk 6 6003 if eq atp 0 6004 fe_fail 11 6005 end 6006 if eq fe_isfloat atp 0 6007 fe_fail 7 6008 end 6009 bv = fe_fspan atp bv 6010 bk = ulong 7 6011 bt = atp 6012 end 6013 if or eq ak 2 eq ak 3 6014 fe_fail 7 6015 end 6016 if or eq bk 2 eq bk 3 6017 fe_fail 7 6018 end 6019 end 6020 if or eq ak 6 eq bk 6 6021 fe_fail 7 6022 end 6023 if eq ak 2 6024 if eq bk 2 6025 fe_fail 11 6026 end 6027 fe_range av bt atp 6028 atp = bt 6029 ak = ulong 3 6030 end 6031 if eq bk 2 6032 fe_range bv atp bt 6033 bt = atp 6034 bk = ulong 3 6035 end 6036 if and ne c 41 ne c 42 6037 if ne atp bt 6038 fe_fail 7 6039 end 6040 end 6041 x = mul get f_depth 0 32 6042 ar_pw 59 x ak 6043 ar_pw 59 add x 1 av 6044 ar_pw 59 add x 2 atp 6045 ar_pw 59 add x 3 bk 6046 ar_pw 59 add x 4 bv 6047 ar_pw 59 add x 5 bt 6048 if ne fe_isfloat atp 0 6049 fe_fwreq 6050 end 6051 fe_binop c dst x 6052 fe_vdec 6053 end 6054 6055 note cond: read a condition, which must be a bool value (error 7). From omc.om cond (@`943d9555` line 8693), 6056 note which also emitted the branch taken when the condition is false and returned that branch's place; 6057 note this check pass emits no code, so it returns nothing. 6058 fn fe_cond to void 6059 fe_rdval 0 1 255 0 6060 if ne get f_rt 0 1 6061 fe_fail 7 6062 end 6063 end 6064 6065 note ======== statements, one per line (om4 STMT and the S_ parts) ======== 6066 note skipnl: note ...: the rest of the line is not read (up to the newline, which tok reads). om4 S_NOTE. 6067 fn fe_skipnl to void 6068 put f_cur 0 fe_nlat get f_cur 0 get f_inlen 0 6069 end 6070 6071 6072 note sa_arr: x = new T N v: N elements of type T on the stack, each set to v; only in the function's 6073 note outermost block, so the stack held by local arrays is known at every ret. SUB SP (C6.2.457); program 6074 note mode: the stack check; MOV Xb, SP (ADD immediate, C6.2.5); then the fill loop: STR v, [Xb, Xi, LSL]; 6075 note ADD Xi, Xi, #1; CMP Xi, #N or Xn; B.LO back (C6.2.34). om4 SA_ARR. 6076 fn fe_sa_arr w ulong to void 6077 if ne get f_nb 0 0 6078 fe_fail 9 6079 end 6080 t = fe_typeword 6081 fe_elemtype t 6082 n = fe_lenval 16 6083 fe_arrlen n 6084 by = shl shr add shl n fe_tlog t 15 4 4 6085 s = add get f_stkbyt 0 by 6086 if gt s `4194304` 6087 fe_fail 23 6088 end 6089 put f_stkbyt 0 s 6090 r = fe_alloc 6091 put f_held 0 get f_nslot 0 6092 fe_rdval 0 t 255 0 6093 if ne get f_rt 0 t 6094 fe_fail 7 6095 end 6096 v = fe_matreg get f_rk 0 get f_rv 0 get f_rt 0 6097 fe_stkchk 6098 i = fe_alloc 6099 if gt n 4095 6100 m = fe_alloc 6101 end 6102 fe_addname w r t n 1 0 6103 end 6104 6105 note s_enlarge: NAME = enlarge P n (omc.om s_enlarge @`a53193cb`, OMEGESE 9.15), only as the whole of an 6106 note assignment. NAME is checked before P, and P before n, matching omc's refusal order. 6107 note Pools are name kind 10. The count is ulong and the result is a long scalar. 6108 fn fe_s_enlarge w ulong to void 6109 e = fe_findname w 6110 r = ulong 0 6111 if ne e 0 6112 i = sub e 1 6113 if ne ar_c 8 i 0 6114 fe_fail 7 6115 end 6116 if ne ar_c 6 i 9 6117 fe_fail 7 6118 end 6119 r = ulong ar_c 5 i 6120 else 6121 if ne fe_findfn w 0 0 0 6122 fe_fail 10 6123 end 6124 r = fe_alloc 6125 put f_held 0 get f_nslot 0 6126 end 6127 p = fe_arrname 6128 if ne ar_c 8 sub p 1 10 6129 fe_fail 7 6130 end 6131 sl = get f_nslot 0 6132 fe_rdval 0 5 255 0 6133 if eq get f_rk 0 2 6134 fe_fail 11 6135 end 6136 if ne get f_rt 0 5 6137 fe_fail 7 6138 end 6139 nv = fe_matreg get f_rk 0 get f_rv 0 5 6140 fe_save 6141 r = fe_restore r sl get f_svn 0 get f_sva 0 1 6142 if eq e 0 6143 fe_addname w r 9 0 0 0 6144 end 6145 fe_eol 6146 end 6147 6148 note s_assign: name [=] value (an existing scalar, or a new one), or name = new T N v. om4 S_ASSIGN. A new 6149 note f32/f64 name lives in the twin of its register (nm_fv, vsl): the value is made there when it can be. 6150 fn fe_s_assign w ulong to void 6151 fe_tok 6152 if eq get f_tk 0 1 6153 if le get f_tl 0 8 6154 if eq fe_kw get f_tw 0 73 6155 fe_tok 6156 end 6157 end 6158 end 6159 if eq get f_tk 0 1 6160 if eq get f_tl 0 7 6161 if eq get f_tw 0 `28542713606205029` 6162 fe_s_enlarge w 6163 ret 6164 end 6165 end 6166 end 6167 e = fe_findname w 6168 if ne e 0 6169 i = sub e 1 6170 if ne ar_c 8 i 0 6171 fe_fail 7 6172 end 6173 r = ulong uchar get ar_m add get ar_rb 5 i 6174 t = ulong uchar get ar_m add get ar_rb 6 i 6175 if ne ar_c 10 i 0 6176 put f_fpw 0 add r 2 6177 fe_rdval 1 t 255 0 6178 if ne get f_rt 0 t 6179 fe_fail 7 6180 end 6181 fe_fvset get f_rk 0 get f_rv 0 t r 6182 fe_eol 6183 ret 6184 end 6185 fe_rdval 1 t r 0 6186 if ne get f_rt 0 t 6187 fe_fail 7 6188 end 6189 fe_force get f_rk 0 get f_rv 0 get f_rt 0 r 6190 fe_eol 6191 ret 6192 end 6193 if ne fe_findfn w 0 0 0 6194 fe_fail 10 6195 end 6196 if eq get f_tk 0 1 6197 if le get f_tl 0 8 6198 if eq fe_kw get f_tw 0 84 6199 fe_sa_new w 6200 fe_eol 6201 ret 6202 end 6203 end 6204 end 6205 r = fe_alloc 6206 put f_held 0 get f_nslot 0 6207 put f_fpw 0 add r 2 6208 fe_rdval 1 0 r 0 6209 if eq get f_rk 0 2 6210 fe_fail 11 6211 end 6212 t = get f_rt 0 6213 if and ne fe_isfloat t 0 eq get f_xtarge 0 0 6214 fe_fvset get f_rk 0 get f_rv 0 t r 6215 put f_vsl fe_regidx r uchar 1 6216 fe_addname w r t 0 0 0 6217 ar_pc 10 sub get f_nn 0 1 uchar 1 6218 else 6219 fe_force get f_rk 0 get f_rv 0 t r 6220 fe_addname w r t 0 0 0 6221 end 6222 fe_eol 6223 end 6224 6225 note s_name: a name at the start of a line: a call of a void function, or name [=] value. om4 S_NAME. 6226 fn fe_s_name w ulong to void 6227 if ne fe_findname w 0 6228 fe_s_assign w 6229 ret 6230 end 6231 f = fe_findfn w get f_tl 0 0 6232 if eq f 0 6233 fe_s_assign w 6234 ret 6235 end 6236 if ne ar_c 21 sub f 1 12 6237 fe_fail 7 6238 end 6239 fe_rdval 2 0 255 f 6240 fe_eol 6241 end 6242 6243 note fn_p: the type of parameter np (name pw) of function f (index): T, or view / edit T N (an array: 6244 note kind 2 / 3, element type, length 1 .. 2^24). om4 FN_P .. FN_ADD. 6245 fn fe_fn_p f ulong np ulong pw ulong to void 6246 fe_tok 6247 if ne get f_tk 0 1 6248 fe_fail 16 6249 end 6250 if gt get f_tl 0 8 6251 fe_fail 16 6252 end 6253 c = fe_kw get f_tw 0 6254 t = ulong 0 6255 ln = ulong 0 6256 k = ulong 0 6257 if eq c 194 6258 fe_fn_p_out f np pw 6259 ret 6260 end 6261 if or eq c 57 eq c 58 6262 k = sub c 55 6263 sid = fe_peek_struct 6264 if ne sid 0 6265 fe_fn_p_st f np pw sid k 6266 ret 6267 end 6268 if ne get f_om2 0 0 6269 lid = fe_peek_lay 6270 if ne lid 0 6271 fe_fn_p_ly f np pw lid k 6272 ret 6273 end 6274 end 6275 t = fe_typeword 6276 fe_elemtype t 6277 if and ne get f_om2 0 0 ne fe_peekstar 0 6278 fe_tok 6279 else 6280 ln = fe_lenval 16 6281 fe_arrlen ln 6282 if ne get f_om2 0 0 6283 if eq fe_peekw 183 6284 fe_tok 6285 fe_fz_par f np k ln 6286 end 6287 end 6288 end 6289 else 6290 if eq c 88 6291 t = ulong 10 6292 else 6293 if eq c 89 6294 t = ulong 11 6295 else 6296 if eq c 223 6297 t = ulong 13 6298 else 6299 if gt sub c 1 8 6300 t = fe_abty 6301 else 6302 t = c 6303 end 6304 end 6305 end 6306 end 6307 end 6308 fe_addname pw fe_poolc get f_psl 0 t ln k 0 6309 if and ne k 0 eq ln 0 6310 ar_pc 13 sub get f_nn 0 1 uchar fe_poolc add get f_psl 0 1 6311 end 6312 fe_fz_bind add mul f 6 np ln 6313 p = add mul f 6 np 6314 ar_pc 33 p uchar t 6315 put ar_m add get ar_rb 34 p ln 6316 ar_pc 35 p uchar k 6317 end 6318 6319 note fn_p_out (OM-2, spec 6, erratum E1): `NAME out T N`, a sized array the unit writes and the bridge owns 6320 note (copied out only after status 0). Inside the unit it is an edit of T N (kind 3) in one slot, its 6321 note pointer; a length `*` is error 16, and so is `fresh` after it. 6322 fn fe_fn_p_out f ulong np ulong pw ulong to void 6323 t = fe_typeword 6324 fe_elemtype t 6325 ln = fe_lenval 16 6326 fe_arrlen ln 6327 fe_addname pw fe_poolc get f_psl 0 t ln 3 0 6328 p = add mul f 6 np 6329 ar_pc 33 p uchar t 6330 put ar_m add get ar_rb 34 p ln 6331 ar_pc 35 p 3 6332 end 6333 6334 note fn_to: to T | to void at the end of a fn line; the function's state starts. om4 FN_TO .. FN_T2. 6335 fn fe_fn_to f ulong np ulong to void 6336 fe_tok 6337 if eq get f_tk 0 0 6338 fe_fail 4 6339 end 6340 if ne get f_tk 0 1 6341 fe_fail 16 6342 end 6343 if gt get f_tl 0 8 6344 fe_fail 16 6345 end 6346 c = fe_kw get f_tw 0 6347 r = c 6348 if eq c 76 6349 r = ulong 12 6350 else 6351 if eq c 88 6352 r = ulong 10 6353 else 6354 if eq c 89 6355 r = ulong 11 6356 else 6357 if eq c 223 6358 r = ulong 13 6359 else 6360 if gt sub c 1 8 6361 r = fe_abty 6362 else 6363 r = c 6364 end 6365 end 6366 end 6367 end 6368 end 6369 put f_curret 0 r 6370 ar_pc 21 f uchar r 6371 ar_pc 22 f uchar np 6372 put f_stkbyt 0 0 6373 put f_dead 0 0 6374 put f_npar 0 get f_psl 0 6375 put f_nslot 0 0 6376 for j ulong 16 6377 put f_vsl j 0 6378 end 6379 put f_held 0 0 6380 put f_nb 0 0 6381 fe_fn_tail f 6382 end 6383 6384 note s_fn: fn name (param type | param view T N | param edit T N)* to type | void. om4 S_FN. 6385 note A name of 9..63 bytes is never a keyword: tw packs only its first 8 bytes (continue_x is not continue). 6386 fn fe_s_fn to void 6387 if ne get f_curret 0 0 6388 fe_fail 15 6389 end 6390 fe_tok 6391 if ne get f_tk 0 1 6392 fe_fail 16 6393 end 6394 if gt get f_tl 0 63 6395 fe_fail 13 6396 end 6397 w = get f_tw 0 6398 if le get f_tl 0 8 6399 if ne fe_kw w 0 6400 fe_fail 16 6401 end 6402 end 6403 l = get f_tl 0 6404 s = get f_ts 0 6405 f = ulong 0 6406 if eq get f_scanni 0 1 6407 fe_newname w l s 6408 f = get f_nf 0 6409 fe_need 8 f 6410 put f_nf 0 add f 1 6411 put f_curfn 0 add f 1 6412 put f_lastfn 0 add f 1 6413 put ar_m add get ar_rb 20 f w 6414 ar_pc 21 f 0 6415 ar_pc 22 f 0 6416 put ar_m add get ar_rb 23 f l 6417 put ar_m add get ar_rb 24 f s 6418 ar_pc 30 f uchar get f_expf 0 6419 fe_fn_link f 6420 else 6421 f = sub fe_findfn w l s 1 6422 put f_curfn 0 add f 1 6423 put f_lastfn 0 add f 1 6424 put f_fuel 0 0 6425 put f_fz_n 0 0 6426 end 6427 fe_nm_set get f_nglob 0 6428 put f_psl 0 0 6429 np = ulong 0 6430 go = true 6431 while go 6432 fe_tok 6433 if eq get f_tk 0 0 6434 fe_fail 4 6435 end 6436 if ne get f_tk 0 1 6437 fe_fail 16 6438 end 6439 if gt get f_tl 0 63 6440 fe_fail 13 6441 end 6442 pw = get f_tw 0 6443 c = fe_kw pw 6444 if eq c 65 6445 go = false 6446 else 6447 if ne c 0 6448 fe_fail 16 6449 end 6450 fe_newname pw get f_tl 0 get f_ts 0 6451 if ge get f_psl 0 6 6452 fe_fail 9 6453 end 6454 fe_fn_p f np pw 6455 ar_pw 32 add mul f 6 np pw 6456 put f_psl 0 add get f_psl 0 fe_pwid add mul f 6 np 6457 if gt get f_psl 0 6 6458 fe_fail 9 6459 end 6460 np = add np 1 6461 end 6462 end 6463 fe_fn_to f np 6464 fe_ab_entry f 6465 if eq get f_scanni 0 0 6466 fe_cp_entry 6467 end 6468 if eq get f_scanni 0 1 6469 put f_curret 0 0 6470 note keep the top-level consts read so far: a later const must not take an earlier one's slot. 6471 fe_nm_set get f_nglob 0 6472 end 6473 end 6474 6475 note s_ret: ret [value]: the value into X0, give back the local arrays' stack, RET. om4 S_RET. 6476 fn fe_s_ret to void 6477 if ne get f_inl 0 0 6478 fe_s_iret 6479 ret 6480 end 6481 r = get f_curret 0 6482 if eq r 12 6483 fe_eol 6484 fe_cp_post 0 0 r 6485 fe_dead1 6486 ret 6487 end 6488 dst = ulong 0 6489 if and ne get f_cfhas 0 0 eq get f_crel 0 0 6490 dst = ulong 255 6491 end 6492 fe_rdval 0 r dst 0 6493 if ne get f_rt 0 r 6494 fe_fail 7 6495 end 6496 if and ne get f_cfhas 0 0 eq get f_crel 0 0 6497 rr = fe_matreg get f_rk 0 get f_rv 0 r 6498 fe_eol 6499 fe_cp_post 1 rr r 6500 fe_force 1 rr r 0 6501 else 6502 fe_force get f_rk 0 get f_rv 0 get f_rt 0 0 6503 fe_eol 6504 fe_cp_post 1 0 r 6505 end 6506 fe_dead1 6507 end 6508 6509 note s_break: leave the innermost loop: find the nearest block of kind 3 (while) or 4 (for), emit an 6510 note always-taken B.cond to the loop's exit and record the word for s_end to patch. Outside a loop the 6511 note line is error 9. Like ret, the line ends the path (a later line in the same block is error 17). 6512 fn fe_s_break to void 6513 j = get f_nb 0 6514 found = ulong 0 6515 bi = ulong 0 6516 while and eq found 0 gt j 0 bound `16777217` 6517 j = sub j 1 6518 if ge ar_w 41 j 3 6519 found = ulong 1 6520 bi = j 6521 end 6522 end 6523 if eq found 0 6524 fe_fail 9 6525 end 6526 if ge ar_w 41 bi 5 6527 fe_fail 9 6528 end 6529 n = get f_nbrk 0 6530 fe_need 12 n 6531 put ar_m add get ar_rb 55 n bi 6532 put f_nbrk 0 add n 1 6533 fe_dead1 6534 fe_eol 6535 end 6536 6537 note s_cont: continue: like break it finds the innermost loop, but its exit is the latch: the head of a 6538 note while, the increment of a for (patched by s_end). Outside a loop it is error 9; the line ends the 6539 note path (error 17 for a later line in the same block). 6540 fn fe_s_cont to void 6541 j = get f_nb 0 6542 found = ulong 0 6543 bi = ulong 0 6544 while and eq found 0 gt j 0 bound `16777217` 6545 j = sub j 1 6546 if ge ar_w 41 j 3 6547 found = ulong 1 6548 bi = j 6549 end 6550 end 6551 if eq found 0 6552 fe_fail 9 6553 end 6554 if ge ar_w 41 bi 5 6555 fe_fail 9 6556 end 6557 n = get f_ncont 0 6558 fe_need 13 n 6559 put ar_m add get ar_rb 56 n bi 6560 put f_ncont 0 add n 1 6561 fe_dead1 6562 fe_eol 6563 end 6564 6565 6566 note s_put: put A i v: index, then value, then the checked store (STOP table). om4 S_PUT. 6567 fn fe_s_put to void 6568 e = fe_arrname 6569 k = uchar get ar_m add get ar_rb 8 sub e 1 6570 if and ne k 10 ge k 6 6571 fe_s_putf e 6572 ret 6573 end 6574 if or eq k 2 eq k 5 6575 fe_fail 20 6576 end 6577 if ne fe_ly_put e 0 6578 ret 6579 end 6580 fe_rdval 0 5 255 0 6581 ik = get f_rk 0 6582 iv = get f_rv 0 6583 it = get f_rt 0 6584 t = ulong uchar get ar_m add get ar_rb 6 sub e 1 6585 if ne fe_isfloat t 0 6586 put f_fpw 0 1 6587 end 6588 fe_rdval 0 t 255 0 6589 if ne get f_rt 0 t 6590 fe_fail 7 6591 end 6592 if eq get f_rk 0 9 6593 fe_fz_put e ik iv 6594 fe_elemaddr e ik iv it 6595 fe_eol 6596 ret 6597 end 6598 v = fe_matreg get f_rk 0 get f_rv 0 get f_rt 0 6599 fe_fz_put e ik iv 6600 fe_elemaddr e ik iv it 6601 fe_eol 6602 end 6603 6604 note s_const: const NAME TYPE LITERAL at top level. The value is a typed number (integer or float) 6605 note read wherever a value goes; it may not be assigned and is refused in IR mode. 6606 fn fe_s_const to void 6607 fe_tok 6608 if ne get f_tk 0 1 6609 fe_fail 16 6610 end 6611 if gt get f_tl 0 63 6612 fe_fail 13 6613 end 6614 w = get f_tw 0 6615 if ne fe_kw w 0 6616 fe_fail 16 6617 end 6618 fe_newname w get f_tl 0 get f_ts 0 6619 t = fe_typeword 6620 if ge t 64 6621 fe_fail 7 6622 end 6623 if ne fe_isfloat t 0 6624 note float constant: rdval reads the float token as a value (kind 6); fspan converts it to the 6625 note target type's bits and rdval has already balanced the nesting depth. 6626 fe_rdval 0 0 255 0 6627 if ne get f_rk 0 6 6628 fe_fail 16 6629 end 6630 v = fe_fspan t get f_rv 0 6631 fe_addname w 0 t 0 9 v 6632 put f_nglob 0 get f_nn 0 6633 fe_eol 6634 ret 6635 end 6636 fe_tok 6637 if eq get f_tk 0 0 6638 fe_fail 4 6639 end 6640 if eq get f_tk 0 5 6641 fe_fail 7 6642 end 6643 if ne get f_tk 0 2 6644 fe_fail 16 6645 end 6646 v = get f_tw 0 6647 fe_range v t get f_tbig 0 6648 fe_addname w 0 t 0 9 v 6649 put f_nglob 0 get f_nn 0 6650 fe_eol 6651 end 6652 6653 note A runtime pool has a distinct name kind and a private descriptor. 6654 fn fe_sgpool w ulong t ulong to void 6655 if or eq get f_progmo 0 0 ne get f_irmode 0 0 6656 fe_fail 9 6657 end 6658 pb = get f_poolb 0 6659 n = add pb 16 6660 if gt n `1073741824` 6661 fe_fail 23 6662 end 6663 put f_poolb 0 n 6664 fe_addname w 0 t 0 10 add `276824064` pb 6665 put f_nglob 0 get f_nn 0 6666 fe_eol 6667 end 6668 6669 note s_global: global NAME T N: a fixed pool of N elements, zero at start, in the read/write part of the 6670 note program image after the 8 MiB stack pool (address 0x10800000 + pool bytes so far); at most 1 GiB of 6671 note pools (error 23). om4 S_GLOBAL. 6672 fn fe_s_global to void 6673 w = fe_topname 6674 t = fe_typeword 6675 fe_elemtype t 6676 if ne fe_peekstar 0 6677 fe_tok 6678 fe_sgpool w t 6679 ret 6680 end 6681 n = fe_lenval 16 6682 fe_arrlen n 6683 by = shl shr add shl n fe_tlog t 15 4 4 6684 pb = get f_poolb 0 6685 a = add `276824064` pb 6686 s = add pb by 6687 if gt s `1073741824` 6688 fe_fail 23 6689 end 6690 put f_poolb 0 s 6691 fe_addname w 0 t n 4 a 6692 put f_nglob 0 get f_nn 0 6693 fe_eol 6694 end 6695 6696 note s_text: text NAME "...": read-only bytes (escapes \n \t \\ \", any other is error 22) with their 6697 note length. From omc.om s_text (@`943d9555` line 9362), which also wrote the bytes into the program image, 6698 note padded to a word, and gave the name its address 0x400000 + its place; this check pass keeps the 6699 note count and records address 0. 6700 fn fe_s_text to void 6701 w = fe_topname 6702 fe_tok 6703 if ne get f_tk 0 4 6704 fe_fail 16 6705 end 6706 p = get f_tw 0 6707 e = add p get f_tl 0 6708 n = ulong 0 6709 go = true 6710 while go 6711 m = ulong 0 6712 while and go lt m 999999 6713 if ge p e 6714 go = false 6715 else 6716 b = ar_ib p 6717 p = add p 1 6718 if eq b 92 6719 b = ar_ib p 6720 p = add p 1 6721 if eq b 110 6722 b = uchar 10 6723 else 6724 if eq b 116 6725 b = uchar 9 6726 else 6727 if and ne b 92 ne b 34 6728 fe_fail 22 6729 end 6730 end 6731 end 6732 end 6733 n = add n 1 6734 end 6735 m = add m 1 6736 end 6737 end 6738 note Empty text carries no data; its zero count forbids every access. 6739 fe_addname w 0 2 n 5 0 6740 put f_nglob 0 get f_nn 0 6741 fe_eol 6742 end 6743 6744 note s_else: jump over the else part (B, C6.2.35); the if's false branch lands after that jump. om4 S_ELSE. 6745 fn fe_s_else to void 6746 n = get f_nb 0 6747 if eq n 0 6748 fe_fail 15 6749 end 6750 i = sub n 1 6751 if ne ar_w 41 i 1 6752 fe_fail 15 6753 end 6754 put ar_m add get ar_rb 41 i 2 6755 fe_fz_else i 6756 fe_nm_set get ar_m add get ar_rb 44 i 6757 put f_held 0 get ar_m add get ar_rb 45 i 6758 put ar_m add get ar_rb 46 i get f_dead 0 6759 put f_dead 0 0 6760 fe_eol 6761 end 6762 6763 note lpcnt: the hidden counter check of a loop: CMP Xc, #N (C6.2.96) or CMP Xc, Xn (C6.2.97); B.HS trap 6764 note 4; ADD Xc, Xc, #1 (C6.2.5). om4 SW_NOB .. SW_G and the same in S_FOR. 6765 fn fe_lpcnt c ulong n ulong to void 6766 if le n 4095 6767 else 6768 m = fe_alloc 6769 end 6770 fe_trapc 2 4 6771 end 6772 6773 note s_while: while cond [bound N]: hidden counter = 0; head: cond false -> exit; counter >= N -> trap 4; 6774 note counter = counter + 1; body; B head. N is 1 .. `9223372036854775807` (error 8), `1000000` with no bound. om4 S_WHILE. 6775 fn fe_s_while to void 6776 sn = get f_nn 0 6777 sh = get f_held 0 6778 c = fe_alloc 6779 put f_held 0 get f_nslot 0 6780 fe_cp_head fe_skipln get f_cur 0 add get f_line 0 1 6781 fe_cond 6782 n = ulong `1000000` 6783 fe_tok 6784 k = get f_tk 0 6785 if and ne k 0 ne k 3 6786 if ne k 1 6787 fe_fail 5 6788 end 6789 if gt get f_tl 0 8 6790 fe_fail 5 6791 end 6792 if ne fe_kw get f_tw 0 70 6793 fe_fail 5 6794 end 6795 v = fe_lenval 4 6796 if ge sub v 1 `9223372036854775807` 6797 fe_fail 8 6798 end 6799 n = v 6800 fe_eol 6801 end 6802 fe_lpcnt c n 6803 fe_pushb 3 c 0 6804 fe_pushnh sn sh 6805 fe_cp_skip 6806 end 6807 6808 6809 note sf_num: for i T K with K a number: i = 0 (MOVZ, C6.2.285); head: CMP Xi, #K or Xk; B.HS/B.GE exit. 6810 note With `bound N` a hidden counter c = 0 is checked after the exit test, as in s_while. om4 SF_NUM .. SF_PUSH. 6811 note The optional `bound N` before the line's end: N a number or an integer constant, 1 .. 6812 note `9223372036854775807` (error 8, as s_while; 4 when N is missing); bn = 0 when no bound is written. 6813 fn fe_sf_num w ulong t ulong kk ulong sn ulong sh ulong to void 6814 bn = ulong 0 6815 if eq fe_peekw 70 6816 fe_tok 6817 bn = fe_lenval 4 6818 if ge sub bn 1 `9223372036854775807` 6819 fe_fail 8 6820 end 6821 end 6822 fe_eol 6823 i = fe_alloc 6824 put f_held 0 get f_nslot 0 6825 fe_addname w i t 0 0 0 6826 c = ulong 0 6827 if ne bn 0 6828 c = fe_alloc 6829 put f_held 0 get f_nslot 0 6830 end 6831 fe_cp_head get f_cur 0 get f_line 0 6832 if le kk 4095 6833 else 6834 k = fe_alloc 6835 end 6836 if ne bn 0 6837 fe_lpcnt c bn 6838 end 6839 fe_pushb 4 i t 6840 fe_pushnh sn sh 6841 fe_cp_skip 6842 end 6843 6844 note sf_val: for i T K with K a value of type T in register kr: i = 0; the hidden counter c = 0; head: CMP 6845 note Xi, Xk; B.HS/B.GE exit; the counter guard of a while: `bound N` (read as in sf_num), else `1000000`. 6846 note om4 SF_VAL. 6847 fn fe_sf_val w ulong t ulong kr ulong sn ulong sh ulong to void 6848 n = ulong `1000000` 6849 if eq fe_peekw 70 6850 fe_tok 6851 n = fe_lenval 4 6852 if ge sub n 1 `9223372036854775807` 6853 fe_fail 8 6854 end 6855 end 6856 fe_eol 6857 i = fe_alloc 6858 put f_held 0 get f_nslot 0 6859 fe_addname w i t 0 0 0 6860 c = fe_alloc 6861 put f_held 0 get f_nslot 0 6862 fe_cp_head get f_cur 0 get f_line 0 6863 fe_lpcnt c n 6864 fe_pushb 4 i t 6865 fe_pushnh sn sh 6866 fe_cp_skip 6867 end 6868 6869 note s_for: for i T K [bound N]: i = 0; head: not i < K -> exit; body; latch i = add i 1; B head. K a number, 6870 note or a value of type T: a name is read at every pass, another value once before the loop. More than N 6871 note passes (default `1000000` for a value K, no limit for a number K) trap 4. om4 S_FOR. 6872 fn fe_s_for to void 6873 sn = get f_nn 0 6874 sh = get f_held 0 6875 fe_tok 6876 if eq get f_tk 0 0 6877 fe_fail 4 6878 end 6879 if ne get f_tk 0 1 6880 fe_fail 16 6881 end 6882 if gt get f_tl 0 63 6883 fe_fail 13 6884 end 6885 w = get f_tw 0 6886 if ne fe_kw w 0 6887 fe_fail 16 6888 end 6889 fe_newname w get f_tl 0 get f_ts 0 6890 t = fe_typeword 6891 if or eq t 1 ge t 10 6892 fe_fail 7 6893 end 6894 fe_tok 6895 if eq get f_tk 0 0 6896 fe_fail 4 6897 end 6898 if eq get f_tk 0 2 6899 fe_range get f_tw 0 t get f_tbig 0 6900 if ne get f_om2 0 0 6901 kk = get f_tw 0 6902 if eq fe_peekw 181 6903 fe_s_unroll w t kk sn sh 6904 ret 6905 end 6906 put f_tw 0 kk 6907 end 6908 fe_sf_num w t get f_tw 0 sn sh 6909 ret 6910 end 6911 fe_rdval 1 t 255 0 6912 if ne get f_rt 0 t 6913 fe_fail 7 6914 end 6915 if ne get f_om2 0 0 6916 if eq fe_peekw 181 6917 fe_fail 16 6918 end 6919 end 6920 if eq get f_rk 0 3 6921 fe_sf_num w t get f_rv 0 sn sh 6922 ret 6923 end 6924 kr = fe_matreg get f_rk 0 get f_rv 0 get f_rt 0 6925 fe_sf_val w t kr sn sh 6926 end 6927 6928 note ======== OM-2 section 4: unroll, inline, folding, the growth bound and trap-site records ======== 6929 note peekstar: 1 when the next word is `*` (an unsized array, OM-2), without reading it 6930 fn fe_peekstar to ulong 6931 c0 = get f_cur 0 6932 l0 = get f_line 0 6933 a0 = get f_tka 0 6934 b0 = get f_tkb 0 6935 fe_tok 6936 r = ulong 0 6937 if and eq get f_tk 0 1 eq get f_tl 0 1 6938 if eq get f_tw 0 42 6939 r = ulong 1 6940 end 6941 end 6942 put f_cur 0 c0 6943 put f_line 0 l0 6944 put f_tka 0 a0 6945 put f_tkb 0 b0 6946 ret r 6947 end 6948 6949 note peekw: the keyword code of the next word (0 for anything else) without reading it 6950 fn fe_peekw to ulong 6951 c0 = get f_cur 0 6952 l0 = get f_line 0 6953 a0 = get f_tka 0 6954 b0 = get f_tkb 0 6955 fe_tok 6956 r = ulong 0 6957 if eq get f_tk 0 1 6958 if le get f_tl 0 8 6959 r = fe_kw get f_tw 0 6960 end 6961 end 6962 put f_cur 0 c0 6963 put f_line 0 l0 6964 put f_tka 0 a0 6965 put f_tkb 0 b0 6966 ret r 6967 end 6968 6969 note s_unroll: for i T K unroll (K a number 1..64, error 8 outside). i is a constant name (kind 9) bound to 6970 note 0..K-1 in turn; the body is read K times from its first line (s_unr). No branch is emitted. 6971 fn fe_s_unroll w ulong t ulong kk ulong sn ulong sh ulong to void 6972 if or eq kk 0 gt kk 64 6973 fe_fail 8 6974 end 6975 fe_fuelc get f_line 0 kk 6976 fe_tok 6977 fe_eol 6978 fe_addname w 0 t 0 9 0 6979 n = get f_nb 0 6980 fe_pushb 5 sub get f_nn 0 1 t 6981 fe_pushnh sn sh 6982 put ar_m add get ar_rb 47 n get f_cur 0 6983 put ar_m add get ar_rb 48 n get f_line 0 6984 put ar_m add get ar_rb 49 n 0 6985 put ar_m add get ar_rb 50 n kk 6986 put ar_m add get ar_rb 51 n get f_nn 0 6987 put ar_m add get ar_rb 52 n get f_held 0 6988 put f_fzone 0 add get f_fzone 0 1 6989 fe_cp_head get f_cur 0 get f_line 0 6990 fe_cp_skip 6991 end 6992 6993 note fuelc: charge n to the function's fuel at the construct on line ln, before anything of it expands; a 6994 note total above 65536 is error 14 on line ln (E14, E16) 6995 fn fe_fuelc ln ulong n ulong to void 6996 if gt add get f_fuel 0 n 65536 6997 put f_line 0 ln 6998 fe_fail 14 6999 end 7000 put f_fuel 0 add get f_fuel 0 n 7001 end 7002 7003 note s_unr: the end of an unrolled body: read it again with the next value of i, or close the block 7004 fn fe_s_unr i ulong to void 7005 fe_eol 7006 it = add get ar_m add get ar_rb 49 i 1 7007 if lt it ar_w 50 i 7008 put ar_m add get ar_rb 49 i it 7009 put ar_m add get ar_rb 9 get ar_m add get ar_rb 42 i it 7010 fe_nm_set get ar_m add get ar_rb 51 i 7011 put f_held 0 get ar_m add get ar_rb 52 i 7012 put f_nslot 0 get ar_m add get ar_rb 52 i 7013 put f_dead 0 0 7014 put f_cur 0 get ar_m add get ar_rb 47 i 7015 put f_line 0 get ar_m add get ar_rb 48 i 7016 fe_cp_head get f_cur 0 get f_line 0 7017 fe_cp_skip 7018 ret 7019 end 7020 put ar_m add get ar_rb 49 i it 7021 put ar_m add get ar_rb 9 get ar_m add get ar_rb 42 i it 7022 fe_nm_set get ar_m add get ar_rb 51 i 7023 put f_nslot 0 get ar_m add get ar_rb 52 i 7024 fe_cp_head get ar_m add get ar_rb 47 i get ar_m add get ar_rb 48 i 7025 put f_nb 0 i 7026 fe_nm_set get ar_m add get ar_rb 44 i 7027 put f_held 0 get ar_m add get ar_rb 45 i 7028 put f_dead 0 0 7029 put f_fzone 0 sub get f_fzone 0 1 7030 end 7031 7032 note fn_tail: the end of a fn line: an optional inline (OM-2), then the line ends; records the body start 7033 fn fe_fn_tail f ulong to void 7034 fe_tok 7035 k = get f_tk 0 7036 if eq k 1 7037 if ne get f_om2 0 0 7038 if le get f_tl 0 8 7039 if eq fe_kw get f_tw 0 182 7040 ar_pc 25 f 1 7041 fe_eol 7042 put ar_m add get ar_rb 26 f get f_cur 0 7043 put ar_m add get ar_rb 27 f get f_line 0 7044 ret 7045 end 7046 end 7047 end 7048 end 7049 if and ne k 0 ne k 3 7050 put f_dexp 0 6 7051 fe_fail 5 7052 end 7053 put ar_m add get ar_rb 26 f get f_cur 0 7054 put ar_m add get ar_rb 27 f get f_line 0 7055 end 7056 7057 note inl_call: a call of an inline function fe (index + 1): the result register first (dst, or the next 7058 note pool slot), then the arguments left to right exactly as for a call, then the body in place. 7059 fn fe_inl_call fe ulong dst ulong to void 7060 s0 = get f_nslot 0 7061 rres = ulong 255 7062 ns = s0 7063 if ne ar_c 21 sub fe 1 12 7064 if eq dst 255 7065 rres = fe_alloc 7066 ns = add s0 1 7067 else 7068 rres = dst 7069 end 7070 end 7071 cb = add mul get f_depth 0 32 8 7072 np = ulong uchar get ar_m add get ar_rb 22 sub fe 1 7073 put ar_m add get ar_rb 59 add cb 18 np 7074 put ar_m add get ar_rb 59 add cb 19 get f_nslot 0 7075 i = ulong 0 7076 while lt i np 7077 p = add mul sub fe 1 6 i 7078 if eq ar_c 35 p 0 7079 fe_rdval 0 ulong ar_c 33 p 255 0 7080 fe_ca_scal p add cb mul i 3 7081 else 7082 if ge ar_c 35 p 6 7083 fe_ca_st fe i cb 7084 else 7085 fe_ca_arr fe i cb 7086 end 7087 end 7088 i = add i 1 7089 end 7090 fe_inl_body fe cb ns rres 7091 end 7092 7093 note inl_par: bind parameter i of inline function fe to its argument in frame cb. A scalar held in a 7094 note temporary register (pool index hb or above) is taken as it is; any other scalar is copied to a new 7095 note register. An array or struct takes its base register; a text's address is loaded into one. An 7096 note unsized array parameter also takes its count register, or a new one holding a number count. 7097 fn fe_inl_par fe ulong cb ulong i ulong hb ulong to void 7098 p = add mul sub fe 1 6 i 7099 q = add cb mul i 3 7100 k = get ar_m add get ar_rb 59 q 7101 v = get ar_m add get ar_rb 59 add q 1 7102 r = ulong 0 7103 if eq ar_c 35 p 0 7104 if and eq k 1 ge fe_regidx v hb 7105 r = v 7106 else 7107 r = fe_alloc 7108 fe_force k v ulong uchar get ar_m add get ar_rb 33 p r 7109 end 7110 else 7111 if eq k 5 7112 r = v 7113 else 7114 r = fe_alloc 7115 end 7116 end 7117 fe_inl_add p r 7118 if eq fe_pwid p 2 7119 fe_inl_lr add mul div cb 32 6 i 7120 end 7121 fe_fz_inl p get ar_m add get ar_rb 59 add q 2 7122 end 7123 7124 note inl_lr: the unsized parameter name just added gets the count of argument ux (ul_k / ul_v): its 7125 note register, or a new one holding the number 7126 fn fe_inl_lr ux ulong to void 7127 lr = get ar_m add get ar_rb 62 ux 7128 if ne ar_w 61 ux 1 7129 lr = fe_alloc 7130 end 7131 ar_pc 13 sub get f_nn 0 1 uchar lr 7132 end 7133 7134 note inl_add: the name of parameter slot p on register r (a view struct is name kind 8, an edit one 7) 7135 fn fe_inl_add p ulong r ulong to void 7136 pk = ulong ar_c 35 p 7137 if eq pk 0 7138 fe_addname get ar_m add get ar_rb 32 p r ulong uchar get ar_m add get ar_rb 33 p 0 0 0 7139 ret 7140 end 7141 nk = pk 7142 if eq pk 6 7143 nk = ulong 8 7144 end 7145 fe_addname ar_w 32 p r ulong ar_c 33 p get ar_m add get ar_rb 34 p nk 0 7146 ar_pc 11 sub get f_nn 0 1 uchar get ar_m add get ar_rb 36 p 7147 end 7148 7149 note inl_edge: record the call-graph edge (expanding function -> inline function) once (arena group inledge) 7150 fn fe_inl_edge a ulong b ulong to void 7151 n = get f_nie 0 7152 j = ulong 0 7153 while lt j n bound `16777217` 7154 if and eq ar_w 57 j a eq ar_w 58 j b 7155 ret 7156 end 7157 j = add j 1 7158 end 7159 fe_need 14 n 7160 put ar_m add get ar_rb 57 n a 7161 put ar_m add get ar_rb 58 n b 7162 put f_nie 0 add n 1 7163 end 7164 7165 note inl_body: at most 4 nested inline frames (error 14); an inline function reached again while it is 7166 note being inlined, or from its own body, is error 9. The caller's local names are hidden, the parameters 7167 note bound, and the body's lines compiled here until its end (s_inlx) closes the frame. 7168 note Each expansion costs one unit of the function's fuel (E14). 7169 fn fe_inl_body fe ulong cb ulong ns ulong rres ulong to void 7170 lv = get f_inl 0 7171 fe_fuelc get f_line 0 1 7172 if ge lv 4 7173 fe_fail 14 7174 end 7175 if eq get f_curfn 0 fe 7176 fe_fail 9 7177 end 7178 j = ulong 0 7179 while lt j lv 7180 if eq get f_il_fn j fe 7181 fe_fail 9 7182 end 7183 j = add j 1 7184 end 7185 fe_inl_edge get f_curfn 0 fe 7186 put f_il_cur lv get f_cur 0 7187 put f_illine lv get f_line 0 7188 put f_il_ret lv get f_curret 0 7189 put f_il_nn lv get f_nn 0 7190 put f_il_lo lv get f_nmlo 0 7191 put f_ilheld lv get f_held 0 7192 put f_il_ns lv ns 7193 put f_il_res lv rres 7194 put f_il_fn lv fe 7195 put f_il_p0 lv get f_nilp 0 7196 put f_il_fz lv get f_fz_n 0 7197 fe_inl_bind fe cb 7198 fe_pushb 6 fe 0 7199 fe_pushnh get f_il_nn lv get f_ilheld lv 7200 put f_inl 0 add lv 1 7201 put f_fzone 0 add get f_fzone 0 1 7202 put f_curret 0 ulong uchar get ar_m add get ar_rb 21 sub fe 1 7203 put f_dead 0 0 7204 put f_cur 0 get ar_m add get ar_rb 26 sub fe 1 7205 put f_line 0 get ar_m add get ar_rb 27 sub fe 1 7206 fe_cp_entry 7207 fe_inl_run lv 7208 end 7209 7210 note inl_bind: hide the caller's local names, bind the parameters, protect every register in use 7211 fn fe_inl_bind fe ulong cb ulong to void 7212 hb = add get f_npar 0 get f_held 0 7213 put f_nmlo 0 get f_nn 0 7214 np = ulong uchar get ar_m add get ar_rb 22 sub fe 1 7215 i = ulong 0 7216 while lt i np 7217 fe_inl_par fe cb i hb 7218 i = add i 1 7219 end 7220 put f_held 0 get f_nslot 0 7221 end 7222 7223 note inl_run: compile the inlined body's lines until its frame (level lv) is closed 7224 fn fe_inl_run lv ulong to void 7225 go = true 7226 while go 7227 m = ulong 0 7228 while and go lt m 999999 7229 if ne fe_stmt 0 7230 fe_fail 15 7231 end 7232 if le get f_inl 0 lv 7233 go = false 7234 end 7235 m = add m 1 7236 end 7237 end 7238 end 7239 7240 note inlb: the B of an inlined ret, patched to the frame's end 7241 fn fe_inlb to void 7242 n = get f_nilp 0 7243 note a counter only (no table: ng emits no B words) 7244 put f_nilp 0 add n 1 7245 end 7246 7247 note s_iret: ret inside an inlined body: the value into the frame's result register, then B to its end 7248 fn fe_s_iret to void 7249 lv = sub get f_inl 0 1 7250 r = get f_curret 0 7251 if eq r 12 7252 fe_eol 7253 fe_cp_post 0 0 r 7254 fe_inlb 7255 fe_dead1 7256 ret 7257 end 7258 if and ne get f_cfhas get f_inl 0 0 eq get f_crel 0 0 7259 fe_rdval 0 r 255 0 7260 if ne get f_rt 0 r 7261 fe_fail 7 7262 end 7263 rr = fe_matreg get f_rk 0 get f_rv 0 r 7264 fe_eol 7265 fe_cp_post 1 rr r 7266 fe_force 1 rr r get f_il_res lv 7267 else 7268 fe_rdval 0 r get f_il_res lv 0 7269 if ne get f_rt 0 r 7270 fe_fail 7 7271 end 7272 fe_force get f_rk 0 get f_rv 0 get f_rt 0 get f_il_res lv 7273 fe_eol 7274 fe_cp_post 1 get f_il_res lv r 7275 end 7276 fe_inlb 7277 fe_dead1 7278 end 7279 7280 note s_inlx: the end of an inlined body: a value function must not reach it (error 18). A last ret's B 7281 note that is the last word, with no branch patched to the place after it, is taken back; the other rets 7282 note branch here. The caller's line, names, registers and return type come back; the result is in rk/rv/rt. 7283 fn fe_s_inlx i ulong to void 7284 fe_eol 7285 lv = sub get f_inl 0 1 7286 fe = get f_il_fn lv 7287 if eq get f_dead 0 0 7288 if ne ar_c 21 sub fe 1 12 7289 fe_fail 18 7290 end 7291 fe_cp_post 0 0 12 7292 end 7293 fe_inl_pat get f_il_p0 lv 7294 put f_nb 0 i 7295 put f_cur 0 get f_il_cur lv 7296 put f_line 0 get f_illine lv 7297 put f_curret 0 get f_il_ret lv 7298 fe_nm_set get f_il_nn lv 7299 put f_nmlo 0 get f_il_lo lv 7300 put f_held 0 get f_ilheld lv 7301 put f_nslot 0 get f_il_ns lv 7302 put f_dead 0 0 7303 put f_inl 0 lv 7304 put f_fzone 0 sub get f_fzone 0 1 7305 put f_fz_n 0 get f_il_fz lv 7306 put f_rk 0 1 7307 put f_rv 0 get f_il_res lv 7308 put f_rt 0 ulong uchar get ar_m add get ar_rb 21 sub fe 1 7309 end 7310 7311 note inl_pat: end an inline frame: its ret count (fe_inlb, a counter only: ng emits no B words) goes back to p0 7312 fn fe_inl_pat p0 ulong to void 7313 put f_nilp 0 p0 7314 end 7315 7316 note ---- folding (only while fzone is above 0): an operation on two typed numbers is computed with OM-1 7317 note arithmetic: unsigned wraps to its width, signed results are sign-extended; an operation that would 7318 note trap (signed overflow, divide by 0, a shift or rotate amount at or above the width) is not folded. 7319 fn fe_fmask w ulong to ulong 7320 if ge w 64 7321 ret not ulong 0 7322 end 7323 ret sub shl ulong 1 w 1 7324 end 7325 7326 fn fe_fasr x ulong s ulong to ulong 7327 if eq shr x 63 0 7328 ret shr x s 7329 end 7330 ret not shr not x s 7331 end 7332 7333 fn fe_fsext r ulong w ulong to ulong 7334 if ge w 64 7335 ret r 7336 end 7337 ret fe_fasr shl r sub 64 w sub 64 w 7338 end 7339 7340 fn fe_fyes v ulong t ulong to void 7341 put f_fval 0 v 7342 put f_fty 0 t 7343 put f_fok 0 1 7344 end 7345 7346 fn fe_fb_cmp op ulong sg ulong a ulong b ulong to void 7347 x = a 7348 y = b 7349 if ne sg 0 7350 x = xor a shl ulong 1 63 7351 y = xor b shl ulong 1 63 7352 end 7353 r = false 7354 if eq op 43 7355 r = eq x y 7356 end 7357 if eq op 44 7358 r = ne x y 7359 end 7360 if eq op 45 7361 r = lt x y 7362 end 7363 if eq op 46 7364 r = le x y 7365 end 7366 if eq op 47 7367 r = gt x y 7368 end 7369 if eq op 48 7370 r = ge x y 7371 end 7372 v = ulong 0 7373 if r 7374 v = ulong 1 7375 end 7376 fe_fyes v 1 7377 end 7378 7379 fn fe_fb_arith op ulong ty ulong w ulong sg ulong a ulong b ulong to void 7380 r = ulong 0 7381 if eq op 33 7382 r = add a b 7383 end 7384 if eq op 34 7385 r = sub a b 7386 end 7387 if eq op 35 7388 if ne sg 0 7389 if ge add a shl ulong 1 31 shl ulong 1 32 7390 ret 7391 end 7392 if ge add b shl ulong 1 31 shl ulong 1 32 7393 ret 7394 end 7395 end 7396 r = mul a b 7397 end 7398 if eq sg 0 7399 fe_fyes and r fe_fmask w ty 7400 ret 7401 end 7402 if eq w 64 7403 if eq op 33 7404 if ne shr and xor a r xor b r 63 0 7405 ret 7406 end 7407 end 7408 if eq op 34 7409 if ne shr and xor a b xor a r 63 0 7410 ret 7411 end 7412 end 7413 fe_fyes r ty 7414 ret 7415 end 7416 if ne fe_fsext r w r 7417 ret 7418 end 7419 fe_fyes r ty 7420 end 7421 7422 fn fe_fb_div op ulong ty ulong w ulong sg ulong a ulong b ulong to void 7423 if eq b 0 7424 ret 7425 end 7426 if eq sg 0 7427 if eq op 36 7428 fe_fyes div a b ty 7429 else 7430 fe_fyes rem a b ty 7431 end 7432 ret 7433 end 7434 na = shr a 63 7435 sb = shr b 63 7436 ma = a 7437 if ne na 0 7438 ma = sub 0 a 7439 end 7440 mb = b 7441 if ne sb 0 7442 mb = sub 0 b 7443 end 7444 if eq op 37 7445 rr = rem ma mb 7446 if ne na 0 7447 rr = sub 0 rr 7448 end 7449 fe_fyes rr ty 7450 ret 7451 end 7452 if eq w 64 7453 if eq a shl ulong 1 63 7454 if eq b not ulong 0 7455 ret 7456 end 7457 end 7458 end 7459 q = div ma mb 7460 if ne xor na sb 0 7461 q = sub 0 q 7462 end 7463 if ne fe_fsext q w q 7464 ret 7465 end 7466 fe_fyes q ty 7467 end 7468 7469 fn fe_fb_shift op ulong ty ulong w ulong sg ulong a ulong b ulong to void 7470 if ge b w 7471 ret 7472 end 7473 if eq op 42 7474 if eq sg 0 7475 fe_fyes shr a b ty 7476 else 7477 fe_fyes fe_fasr a b ty 7478 end 7479 ret 7480 end 7481 r = shl a b 7482 if eq sg 0 7483 fe_fyes and r fe_fmask w ty 7484 ret 7485 end 7486 if eq w 64 7487 if ne fe_fasr r b a 7488 ret 7489 end 7490 fe_fyes r ty 7491 ret 7492 end 7493 if ne fe_fsext r w r 7494 ret 7495 end 7496 fe_fyes r ty 7497 end 7498 7499 fn fe_fb_rot op ulong ty ulong w ulong a ulong b ulong to void 7500 if ge b w 7501 ret 7502 end 7503 s = b 7504 if and eq op 60 ne s 0 7505 s = sub w s 7506 end 7507 if eq s 0 7508 fe_fyes a ty 7509 ret 7510 end 7511 fe_fyes and or shr a s shl a sub w s fe_fmask w ty 7512 end 7513 7514 note foldbin: op on the typed numbers a, b of type ty (b's own type for a shift); fok 1 when folded 7515 fn fe_foldbin op ulong ty ulong a ulong b ulong to void 7516 put f_fok 0 0 7517 if or eq ty 0 ge ty 10 7518 ret 7519 end 7520 sg = ulong 0 7521 if ge ty 6 7522 sg = ulong 1 7523 end 7524 if and ge op 43 le op 48 7525 fe_fb_cmp op sg a b 7526 ret 7527 end 7528 if and ge op 38 le op 40 7529 r = and a b 7530 if eq op 39 7531 r = or a b 7532 end 7533 if eq op 40 7534 r = xor a b 7535 end 7536 fe_fyes r ty 7537 ret 7538 end 7539 if eq ty 1 7540 ret 7541 end 7542 w = fe_twid ty 7543 if le op 35 7544 fe_fb_arith op ty w sg a b 7545 ret 7546 end 7547 if le op 37 7548 fe_fb_div op ty w sg a b 7549 ret 7550 end 7551 if le op 42 7552 fe_fb_shift op ty w sg a b 7553 ret 7554 end 7555 if or eq op 59 eq op 60 7556 if le ty 5 7557 fe_fb_rot op ty w a b 7558 end 7559 end 7560 end 7561 7562 note foldun: neg (49) / not (50) of the typed number a 7563 fn fe_foldun c ulong ty ulong a ulong to void 7564 put f_fok 0 0 7565 if or eq ty 0 ge ty 10 7566 ret 7567 end 7568 if eq c 50 7569 if eq ty 1 7570 fe_fyes xor a 1 ty 7571 ret 7572 end 7573 if lt ty 6 7574 fe_fyes and not a fe_fmask fe_twid ty ty 7575 ret 7576 end 7577 fe_fyes not a ty 7578 ret 7579 end 7580 if eq ty 1 7581 ret 7582 end 7583 r = sub 0 a 7584 if lt ty 6 7585 fe_fyes and r fe_fmask fe_twid ty ty 7586 ret 7587 end 7588 w = fe_twid ty 7589 if eq w 64 7590 if eq a shl ulong 1 63 7591 ret 7592 end 7593 fe_fyes r ty 7594 ret 7595 end 7596 if ne fe_fsext r w r 7597 ret 7598 end 7599 fe_fyes r ty 7600 end 7601 7602 note ---- omc-site records (om2 diag): one per runtime trap site, in emission order, after the artifact 7603 note on stderr: omc-site 1 line=N iter=k, k the counters of the open unrolled loops outer to inner 7604 note joined by '.', or '-'. 7605 fn fe_siteb b ulong to void 7606 n = get f_nsite 0 7607 fe_need 3 n 7608 ar_bp 3 n uchar b 7609 put f_nsite 0 add n 1 7610 end 7611 7612 fn fe_sitew w ulong n ulong to void 7613 i = ulong 0 7614 x = w 7615 while lt i n 7616 fe_siteb and x 255 7617 x = shr x 8 7618 i = add i 1 7619 end 7620 end 7621 7622 fn fe_siten v ulong to void 7623 d = new uchar 20 0 7624 i = ulong 0 7625 x = v 7626 put d 0 uchar add rem x 10 48 7627 x = div x 10 7628 i = add i 1 7629 while gt x 0 7630 put d i uchar add rem x 10 48 7631 x = div x 10 7632 i = add i 1 7633 end 7634 j = i 7635 while gt j 0 7636 j = sub j 1 7637 fe_siteb ulong get d j 7638 end 7639 end 7640 7641 fn fe_siterec to void 7642 fe_sitew `7310584038532803951` 8 7643 fe_sitew `4424063608026050848` 8 7644 fe_siten add get f_line 0 get f_lbase 0 7645 fe_sitew `67561537693984` 6 7646 any = false 7647 j = ulong 0 7648 while lt j get f_nb 0 bound `16777217` 7649 if eq ar_w 41 j 5 7650 if any 7651 fe_siteb 46 7652 end 7653 fe_siten get ar_m add get ar_rb 49 j 7654 any = true 7655 end 7656 j = add j 1 7657 end 7658 if not any 7659 fe_siteb 45 7660 end 7661 fe_siteb 10 7662 end 7663 7664 fn fe_sitesout to void 7665 z = ar_out 2 3 0 get f_nsite 0 7666 end 7667 7668 note finish: end of a function: a function that needs a value must not reach its end (error 18), a void 7669 note one returns. From omc.om finish (@`943d9555` line 10463), which then emitted the trap stubs; the check 7670 note pass has none. 7671 fn fe_finish to void 7672 fe_eol 7673 if eq get f_dead 0 0 7674 if ne get f_curret 0 12 7675 fe_fail 18 7676 end 7677 fe_cp_post 0 0 12 7678 end 7679 put f_curret 0 0 7680 fe_nm_set get f_nglob 0 7681 put f_curfn 0 0 7682 put f_nbrk 0 0 7683 put f_ncont 0 0 7684 end 7685 7686 note s_end: close the innermost block (if: patch its branch; else: patch its jump; while: B head; for: i = 7687 note add i 1, B head), or the function. om4 S_END. 7688 fn fe_s_end to void 7689 n = get f_nb 0 7690 if eq n 0 7691 fe_finish 7692 ret 7693 end 7694 i = sub n 1 7695 if eq ar_w 41 i 5 7696 fe_s_unr i 7697 ret 7698 end 7699 if eq ar_w 41 i 6 7700 fe_s_inlx i 7701 ret 7702 end 7703 put f_nb 0 i 7704 k = get ar_m add get ar_rb 41 i 7705 fe_fz_join i k 7706 if eq k 2 7707 put f_dead 0 and get f_dead 0 get ar_m add get ar_rb 46 i 7708 else 7709 put f_dead 0 0 7710 end 7711 if eq k 4 7712 j = ulong 0 7713 while lt j get f_ncont 0 bound `16777217` 7714 if eq ar_w 56 j i 7715 put ar_m add get ar_rb 56 j `18446744073709551615` 7716 end 7717 j = add j 1 7718 end 7719 put ar_m add get ar_rb 59 0 1 7720 put ar_m add get ar_rb 59 1 get ar_m add get ar_rb 42 i 7721 put ar_m add get ar_rb 59 2 get ar_m add get ar_rb 43 i 7722 put ar_m add get ar_rb 59 3 3 7723 put ar_m add get ar_rb 59 4 1 7724 put ar_m add get ar_rb 59 5 get ar_m add get ar_rb 43 i 7725 fe_binop 33 get ar_m add get ar_rb 42 i 0 7726 end 7727 if eq k 3 7728 j = ulong 0 7729 while lt j get f_ncont 0 bound `16777217` 7730 if eq ar_w 56 j i 7731 put ar_m add get ar_rb 56 j `18446744073709551615` 7732 end 7733 j = add j 1 7734 end 7735 end 7736 if ge k 3 7737 j = ulong 0 7738 while lt j get f_nbrk 0 bound `16777217` 7739 if eq ar_w 55 j i 7740 put ar_m add get ar_rb 55 j `18446744073709551615` 7741 end 7742 j = add j 1 7743 end 7744 end 7745 fe_nm_set get ar_m add get ar_rb 44 i 7746 put f_held 0 get ar_m add get ar_rb 45 i 7747 fe_eol 7748 end 7749 7750 note ======== the end of the input: the output ======== 7751 note writeout: the unit was accepted; the om2 diag trap-site records to stderr, then exit 0. 7752 note From omc.om@`943d9555` writeout (10591-10624) without the machine-code output. 7753 fn fe_writeout st ulong to void 7754 if ne get f_lmode 0 0 7755 exit fe_lout 7756 end 7757 note usage (check mode 3): the unit compiled as usual; the ng-use record (ar_rec) to stdout in place of output 7758 if eq get f_chkmod 0 3 7759 ar_rec 1 7760 exit int 0 7761 end 7762 if eq get f_chkmod 0 1 7763 put f_mc 0 0 7764 fe_mputw `7594244768023276911` 8 7765 fe_mputw `11207551510369` 6 7766 fe_mflush 7767 exit int 0 7768 end 7769 if eq get f_om2m 0 1 7770 fe_sitesout 7771 end 7772 exit int 0 7773 end 7774 7775 7776 note eof_prog: program mode: start code = MOVZ X28, #0x1000, LSL 16 (stack pool floor); MOVZ X16, #0x1080, 7777 note LSL 16; MOV SP, X16 (ADD immediate, C6.2.5); BL main (C6.2.43); [MOVZ X0, #0 for a void main]; MOVZ X8, 7778 note #93; SVC #0. The entry word after the header is a B to it; the header gets the file and pool sizes. 7779 note om4 EOF_PROG. 7780 fn fe_eof_prog to void 7781 f = fe_findfn `1852399981` 4 0 7782 if eq f 0 7783 fe_fail 16 7784 end 7785 if ne ar_c 22 sub f 1 0 7786 fe_fail 9 7787 end 7788 fe_writeout 0 7789 end 7790 7791 note s_eof: end of input: no open function (error 15), some function (16); function mode: no globals or 7792 note texts (9, fnstore; consts fold and are allowed); one function: its bare words; more: the entry word, a 7793 note B to the last function. om4 S_EOF. 7794 note Resolve every call after all addresses are known (ng emits no code, so there is nothing to patch). In 7795 note function mode a function is settled when every function it calls is (leaves of the call graph first); 7796 note any function left unsettled forms or reaches a cycle (error 9). fe_ksettle finds the same set as the 7797 note old nf rounds over every call, in linear time (omc.om ksettle, OmcNoCaps). 7798 fn fe_resolve to void 7799 n = get f_ncalls 0 7800 if eq get f_progmo 0 0 7801 fe_ksettle n 7802 f = ulong 0 7803 while lt f get f_nf 0 bound `16777217` 7804 if eq ar_c 28 f 0 7805 put f_dsev 0 3 7806 fe_fail 9 7807 end 7808 f = add f 1 7809 end 7810 end 7811 end 7812 7813 note ksettle: Kahn's order over the n call records (a caller 0 is no function's call and is skipped). 7814 note f_k_deg: the calls function f makes to functions not yet settled; f_k_st / f_k_ed: the callers of each 7815 note callee, grouped by callee (f_k_st g .. f_k_st g + 1 - 1 in f_k_ed), f_k_cu the fill cursor; f_k_q: the 7816 note settled functions in order. A function is settled when its count reaches 0. Arena groups kahnfn and 7817 note kahncall. 7818 fn fe_ksettle n ulong to void 7819 fc = get f_nf 0 7820 fe_need 16 fc 7821 fe_need 17 n 7822 f = ulong 0 7823 while le f fc bound `16777217` 7824 put ar_m add get ar_rb 63 f 0 7825 put ar_m add get ar_rb 64 f 0 7826 f = add f 1 7827 end 7828 i = ulong 0 7829 while lt i n bound `16777217` 7830 a = get ar_m add get ar_rb 39 i 7831 if ne a 0 7832 b = get ar_m add get ar_rb 40 i 7833 put ar_m add get ar_rb 63 sub a 1 add ar_w 63 sub a 1 1 7834 put ar_m add get ar_rb 64 b add ar_w 64 b 1 7835 end 7836 i = add i 1 7837 end 7838 f = ulong 1 7839 while le f fc bound `16777217` 7840 put ar_m add get ar_rb 64 f add ar_w 64 f ar_w 64 sub f 1 7841 f = add f 1 7842 end 7843 f = ulong 0 7844 while lt f fc bound `16777217` 7845 put ar_m add get ar_rb 65 f get ar_m add get ar_rb 64 f 7846 f = add f 1 7847 end 7848 i = ulong 0 7849 while lt i n bound `16777217` 7850 a = get ar_m add get ar_rb 39 i 7851 if ne a 0 7852 g = sub get ar_m add get ar_rb 40 i 1 7853 put ar_m add get ar_rb 67 ar_w 65 g sub a 1 7854 put ar_m add get ar_rb 65 g add ar_w 65 g 1 7855 end 7856 i = add i 1 7857 end 7858 t = ulong 0 7859 f = ulong 0 7860 while lt f fc bound `16777217` 7861 if eq ar_w 63 f 0 7862 put ar_m add get ar_rb 66 t f 7863 t = add t 1 7864 end 7865 f = add f 1 7866 end 7867 h = ulong 0 7868 while lt h t bound `16777217` 7869 g = get ar_m add get ar_rb 66 h 7870 h = add h 1 7871 ar_pc 28 g 1 7872 e = get ar_m add get ar_rb 64 add g 1 7873 j = get ar_m add get ar_rb 64 g 7874 while lt j e bound `16777217` 7875 c = ar_w 67 j 7876 d = sub ar_w 63 c 1 7877 ar_pw 63 c d 7878 if eq d 0 7879 ar_pw 66 t c 7880 t = add t 1 7881 end 7882 j = add j 1 7883 end 7884 end 7885 end 7886 7887 note reachself: 1 when function f (index + 1) reaches itself 7888 fn fe_reachself f ulong to ulong 7889 i = ulong 0 7890 while lt i get f_nf 0 bound `16777217` 7891 ar_pc 29 i 0 7892 i = add i 1 7893 end 7894 ar_pc 29 sub f 1 1 7895 go = true 7896 pass = ulong 0 7897 while and go le pass get f_nf 0 bound `16777217` 7898 r = fe_rscan f 0 7899 if eq r 2 7900 ret 1 7901 end 7902 s = fe_rscan f 1 7903 if eq s 2 7904 ret 1 7905 end 7906 go = or ne r 0 ne s 0 7907 pass = add pass 1 7908 end 7909 ret 0 7910 end 7911 7912 note rscan: one pass over the calls (w 0) or the inline edges (w 1): 2 when an edge from a reached 7913 note function leads to f, 1 when a function was newly reached, else 0 7914 fn fe_rscan f ulong w ulong to ulong 7915 n = get f_ncalls 0 7916 if ne w 0 7917 n = get f_nie 0 7918 end 7919 ch = ulong 0 7920 j = ulong 0 7921 while lt j n bound `16777217` 7922 a = get ar_m add get ar_rb 39 j 7923 b = get ar_m add get ar_rb 40 j 7924 if ne w 0 7925 a = get ar_m add get ar_rb 57 j 7926 b = get ar_m add get ar_rb 58 j 7927 end 7928 if ne ar_c 29 sub a 1 0 7929 if eq b f 7930 ret 2 7931 end 7932 if eq ar_c 29 sub b 1 0 7933 ar_pc 29 sub b 1 1 7934 ch = ulong 1 7935 end 7936 end 7937 j = add j 1 7938 end 7939 ret ch 7940 end 7941 7942 fn fe_s_eof to void 7943 if eq get f_chkmod 0 2 7944 fe_emit_query 7945 end 7946 if ne get f_curret 0 0 7947 fe_fail 15 7948 end 7949 if eq get f_nf 0 0 7950 fe_fail 16 7951 end 7952 if ne get f_om2 0 0 7953 note inlcyc (OM-2): an inline function that reaches itself through the whole call graph (the calls made, 7954 note plus an edge from each function to every inline function expanded in it) is error 9 at the end. 7955 f = ulong 1 7956 while le f get f_nf 0 bound `16777217` 7957 if ne ar_c 25 sub f 1 0 7958 if ne fe_reachself f 0 7959 put f_dsev 0 3 7960 fe_fail 9 7961 end 7962 end 7963 f = add f 1 7964 end 7965 end 7966 fe_resolve 7967 if ne get f_progmo 0 0 7968 fe_eof_prog 7969 end 7970 if eq get f_progmo 0 0 7971 note fnstore: function mode. A top-level global pool (kind 4) or text (kind 5) needs the program image and 7972 note is error 9; a const (kind 9) is folded to a typed number wherever it is read, so it composes here too. 7973 i = ulong 0 7974 while lt i get f_nglob 0 bound `16777217` 7975 if ne ar_c 8 i 9 7976 fe_fail 9 7977 end 7978 i = add i 1 7979 end 7980 end 7981 if ne get f_nexp 0 0 7982 note expwords (OM-2, spec 6): words 0 .. E-1 of a multi-entry unit, B to each export in source order 7983 atp = ulong 176 7984 f = ulong 0 7985 while lt f get f_nf 0 bound `16777217` 7986 if ne ar_c 30 f 0 7987 atp = add atp 4 7988 end 7989 f = add f 1 7990 end 7991 fe_writeout 176 7992 end 7993 if eq get f_nf 0 1 7994 fe_writeout 180 7995 end 7996 fe_writeout 176 7997 end 7998 7999 note stmt: one line. Returns 1 at the end of the input. om4 STMT. 8000 fn fe_stmt to ulong 8001 put f_dexp 0 0 8002 put f_nslot 0 get f_held 0 8003 fe_tok 8004 k = get f_tk 0 8005 if eq k 0 8006 ret 0 8007 end 8008 if eq k 3 8009 fe_s_eof 8010 ret 1 8011 end 8012 if ne k 1 8013 fe_fail 16 8014 end 8015 if and ne get f_chkmod 0 0 eq get f_line 0 get f_chkln 0 8016 fe_skipnl 8017 ret 0 8018 end 8019 if and ne get f_om2 0 0 eq get f_line 0 get f_om2ln 0 8020 fe_skipnl 8021 ret 0 8022 end 8023 if ne fe_cp_kind 0 8024 fe_fail 30 8025 end 8026 if gt get f_tl 0 8 8027 note s_long: a word over 8 characters at the start of a line: a call of a void function (om4 S_LONG), or 8028 note a long name of up to 63 bytes, which goes on below as a short name does. 8029 if eq get f_curret 0 0 8030 fe_fail 13 8031 end 8032 if ne get f_dead 0 0 8033 fe_fail 17 8034 end 8035 f = fe_findfn get f_tw 0 get f_tl 0 get f_ts 0 8036 if eq f 0 8037 if gt get f_tl 0 63 8038 fe_unkfail 13 8039 end 8040 else 8041 if ne ar_c 21 sub f 1 12 8042 fe_fail 7 8043 end 8044 fe_rdval 2 0 255 f 8045 fe_eol 8046 ret 0 8047 end 8048 end 8049 w = get f_tw 0 8050 c = fe_kw w 8051 if eq c 83 8052 fe_skipnl 8053 ret 0 8054 end 8055 if eq c 64 8056 fe_s_fn 8057 ret 0 8058 end 8059 if eq get f_curret 0 0 8060 if eq c 78 8061 fe_s_global 8062 ret 0 8063 end 8064 if eq c 79 8065 fe_s_text 8066 ret 0 8067 end 8068 if eq c 152 8069 fe_s_const 8070 ret 0 8071 end 8072 if eq c 85 8073 fe_skipnl 8074 ret 0 8075 end 8076 if eq c 195 8077 fe_s_export 8078 ret 0 8079 end 8080 if eq c 188 8081 note s_lyskip: the body pass jumps to the place after the layout's end (read in the names pass) 8082 fe_tok 8083 li = sub fe_findlay get f_tw 0 1 8084 put f_cur 0 get f_ly_ec li 8085 put f_line 0 get f_ly_el li 8086 ret 0 8087 end 8088 if or eq c 184 eq c 187 8089 fe_skipnl 8090 ret 0 8091 end 8092 fe_fail 16 8093 end 8094 if eq c 66 8095 fe_s_end 8096 ret 0 8097 end 8098 if eq c 68 8099 fe_s_else 8100 ret 0 8101 end 8102 if ne get f_dead 0 0 8103 fe_fail 17 8104 end 8105 if eq c 0 8106 fe_s_name w 8107 ret 0 8108 end 8109 if eq c 67 8110 note s_if: if cond: the false branch is patched at else / end. om4 S_IF. 8111 fe_cond 8112 fe_pushb 1 0 0 8113 fe_pushnh get f_nn 0 get f_held 0 8114 fe_eol 8115 ret 0 8116 end 8117 if eq c 69 8118 fe_s_while 8119 ret 0 8120 end 8121 if eq c 71 8122 fe_s_for 8123 ret 0 8124 end 8125 if eq c 72 8126 fe_s_ret 8127 ret 0 8128 end 8129 if eq c 80 8130 fe_s_put 8131 ret 0 8132 end 8133 if eq c 82 8134 note s_exit: exit value (int): Linux exit (system call 93: MOVZ X8, #93, C6.2.285; SVC #0, C6.2.466); the 8135 note path ends. om4 S_EXIT. 8136 fe_rdval 0 8 255 0 8137 if ne get f_rt 0 8 8138 fe_fail 7 8139 end 8140 fe_force get f_rk 0 get f_rv 0 get f_rt 0 0 8141 fe_dead1 8142 fe_eol 8143 ret 0 8144 end 8145 if eq c 86 8146 fe_s_break 8147 ret 0 8148 end 8149 if eq c 87 8150 note s_trap: trap N (1 .. 14): an always-taken branch to the trap stub for code N, which finish makes. 8151 note Program mode exits 100 + N; function mode calls OscRt.trap (OMEGESE 9.1). The line ends the path. 8152 v = fe_lenval 4 8153 if or lt v 1 gt v 14 8154 fe_fail 8 8155 end 8156 fe_trapc 14 v 8157 fe_dead1 8158 fe_eol 8159 ret 0 8160 end 8161 note cpufence (keyword 199, a statement without operands): the host CPU publication barrier. AArch64: 8162 note DSB SY (`d5033f9f`, the full-system barrier mapget/mapset already bracket their access with). x86-64: 8163 note MFENCE (0F AE F0), the fence the x86 mapget/mapset use. Every earlier load and store completes before 8164 note any later one, so a GPU or another CPU that observes a later store also observes the earlier ones. 8165 note Inline here, not a function: om4 builds omc and holds at most 512 functions, 511 in use. 8166 if eq c 199 8167 fe_eol 8168 ret 0 8169 end 8170 note cpurelax (keyword 200, a statement without operands): spin-wait hint, no ordering. AArch64: YIELD 8171 note (`d503203f`). x86-64: PAUSE (F3 90). Use it in a bounded poll loop; pair it with cpufence for order. 8172 if eq c 200 8173 fe_eol 8174 ret 0 8175 end 8176 if eq c 97 8177 fe_s_cont 8178 ret 0 8179 end 8180 if or or or eq c 77 eq c 78 eq c 79 eq c 81 8181 fe_fail 9 8182 end 8183 if or eq c 85 eq c 193 8184 fe_fail 9 8185 end 8186 fe_fail 16 8187 ret 0 8188 end 8189 8190 note ======== program mode: some line is `fn main` (blanks, fn, blanks, main, then a blank or the end) ======== 8191 note skipbl: the first place at or after q that is not a space or tab (or the end) 8192 fn fe_skipbl q ulong to ulong 8193 e = get f_inlen 0 8194 p = q 8195 go = true 8196 while go 8197 m = ulong 0 8198 while and go lt m 999999 8199 if ge p e 8200 go = false 8201 else 8202 b = ar_ib p 8203 if or eq b 32 eq b 9 8204 p = add p 1 8205 else 8206 go = false 8207 end 8208 end 8209 m = add m 1 8210 end 8211 end 8212 ret p 8213 end 8214 8215 note skipln: the place after the next newline at or after q (or the end) 8216 fn fe_skipln q ulong to ulong 8217 e = get f_inlen 0 8218 p = fe_nlat q e 8219 if lt p e 8220 ret add p 1 8221 end 8222 ret p 8223 end 8224 8225 note ps_at: the line's first byte that is not blank is at p: 1 when the line is `fn main`, 2 when the input 8226 note ends while deciding, else 0. om4 PS_LINE .. PS_YES. 8227 fn fe_ps_at p ulong to ulong 8228 e = get f_inlen 0 8229 if ne ar_ib p 102 8230 ret 0 8231 end 8232 q = add p 1 8233 if ge q e 8234 ret 2 8235 end 8236 if ne ar_ib q 110 8237 ret 0 8238 end 8239 r = add q 1 8240 q = fe_skipbl r 8241 if ge q e 8242 ret 2 8243 end 8244 if eq q r 8245 ret 0 8246 end 8247 if gt add q 4 e 8248 ret 0 8249 end 8250 if ne ar_ib q 109 8251 ret 0 8252 end 8253 if ne ar_ib add q 1 97 8254 ret 0 8255 end 8256 if ne ar_ib add q 2 105 8257 ret 0 8258 end 8259 if ne ar_ib add q 3 110 8260 ret 0 8261 end 8262 if ge add q 4 e 8263 ret 1 8264 end 8265 if gt ar_ib add q 4 32 8266 ret 0 8267 end 8268 ret 1 8269 end 8270 8271 fn fe_prescan to void 8272 e = get f_inlen 0 8273 p = ulong 0 8274 go = true 8275 while go 8276 m = ulong 0 8277 while and go lt m 999999 8278 p = fe_skipbl p 8279 if ge p e 8280 go = false 8281 else 8282 r = fe_ps_at p 8283 if eq r 1 8284 put f_progmo 0 1 8285 go = false 8286 end 8287 if eq r 2 8288 go = false 8289 end 8290 if go 8291 p = fe_skipln p 8292 if ge p e 8293 go = false 8294 end 8295 end 8296 end 8297 m = add m 1 8298 end 8299 end 8300 end 8301 8302 note First collect signatures. Only fn headers are parsed here; other lines are read in the body pass. 8303 fn fe_namescan to void 8304 put f_scanni 0 1 8305 put f_line 0 1 8306 go = true 8307 while go 8308 n = ulong 0 8309 while and go lt n 999999 8310 fe_tok 8311 if eq get f_tk 0 3 8312 go = false 8313 else 8314 if ne get f_tk 0 0 8315 if and eq get f_tk 0 1 eq get f_tw 0 28262 8316 fe_s_fn 8317 else 8318 if and eq get f_tk 0 1 eq get f_tw 0 `127970521019507` 8319 fe_s_struct 8320 else 8321 if and eq get f_tk 0 1 eq get f_tw 0 `500152823651` 8322 fe_s_const 8323 else 8324 if eq fe_ns_om2 0 8325 fe_skipnl 8326 end 8327 end 8328 end 8329 end 8330 end 8331 end 8332 n = add n 1 8333 end 8334 end 8335 put f_scanni 0 0 8336 put f_cur 0 0 8337 put f_line 0 1 8338 fe_nm_set 0 8339 put f_nglob 0 0 8340 put f_curfn 0 0 8341 put f_curret 0 0 8342 put f_npar 0 0 8343 put f_nslot 0 0 8344 for j ulong 16 8345 put f_vsl j 0 8346 end 8347 put f_held 0 0 8348 end 8349 8350 note ======== R6 structs (omc only; om4 stays the parent that rebuilds this file) ======== 8351 note A struct is 8-byte cells, declaration order, no padding (OSC-2). new is a stack slot, given 8352 note back at ret, like a local array. There is no free (decision 24). Field scale: cell << (3 - tlog) 8353 note so a typed store lands on cell * 8. Pack of struct is `127970521019507` (Wolfram, little-endian). 8354 8355 note findstruct: packed name -> index + 1, or 0 8356 fn fe_findstruct w ulong to ulong 8357 i = ulong 0 8358 n = get f_nst 0 8359 while lt i n 8360 if eq get f_stname i w 8361 ret add i 1 8362 end 8363 i = add i 1 8364 end 8365 ret 0 8366 end 8367 8368 note findfield: struct index, packed field name -> field-table index + 1, or 0 8369 fn fe_findfield si ulong w ulong to ulong 8370 fo = ulong get f_stfoff si 8371 nfd = ulong get f_st_nf si 8372 i = ulong 0 8373 while lt i nfd 8374 j = add fo i 8375 if eq get f_sfname j w 8376 ret add j 1 8377 end 8378 i = add i 1 8379 end 8380 ret 0 8381 end 8382 8383 note field_dup: 1 if w is already a field of the struct being read (fields fo .. nsf) 8384 fn fe_field_dup fo ulong w ulong to ulong 8385 i = fo 8386 e = get f_nsf 0 8387 while lt i e 8388 if eq get f_sfname i w 8389 ret 1 8390 end 8391 i = add i 1 8392 end 8393 ret 0 8394 end 8395 8396 note s_field: the current word is a field name of struct w. Returns the cell count after this field. 8397 fn fe_s_field w ulong fo ulong cells ulong to ulong 8398 if gt get f_tl 0 63 8399 fe_fail 13 8400 end 8401 if ne fe_kw get f_tw 0 0 8402 fe_fail 16 8403 end 8404 fw = get f_tw 0 8405 if eq fw w 8406 fe_fail 10 8407 end 8408 if ne fe_findstruct fw 0 8409 fe_fail 10 8410 end 8411 if ne fe_field_dup fo fw 0 8412 fe_fail 10 8413 end 8414 t = fe_typeword 8415 if ge t 64 8416 fe_fail 7 8417 end 8418 ln = ulong 0 8419 p = get f_cur 0 8420 ln0 = get f_line 0 8421 fe_tok 8422 k = get f_tk 0 8423 if eq k 2 8424 ln = get f_tw 0 8425 if ne get f_tbig 0 0 8426 fe_fail 14 8427 end 8428 if or eq ln 0 gt ln 64 8429 fe_fail 14 8430 end 8431 else 8432 if eq k 1 8433 e = fe_findname get f_tw 0 8434 if ne e 0 8435 if eq ar_c 8 sub e 1 9 8436 ct = ulong ar_c 6 sub e 1 8437 if ge ct 10 8438 fe_fail 14 8439 end 8440 ln = ar_w 9 sub e 1 8441 if or eq ln 0 gt ln 64 8442 fe_fail 14 8443 end 8444 else 8445 put f_cur 0 p 8446 put f_line 0 ln0 8447 end 8448 else 8449 put f_cur 0 p 8450 put f_line 0 ln0 8451 end 8452 else 8453 put f_cur 0 p 8454 put f_line 0 ln0 8455 end 8456 end 8457 addc = ulong 1 8458 if ne ln 0 8459 addc = ln 8460 end 8461 if gt add cells addc 64 8462 fe_fail 14 8463 end 8464 put f_sfname get f_nsf 0 fw 8465 put f_sftype get f_nsf 0 uchar t 8466 put f_sf_len get f_nsf 0 uchar ln 8467 put f_sf_off get f_nsf 0 uchar cells 8468 put f_nsf 0 add get f_nsf 0 1 8469 ret add cells addc 8470 end 8471 8472 note s_struct: struct Name (field type [len])* end. Before any fn (namescan). 1..16 fields, <= 64 cells. 8473 fn fe_s_struct to void 8474 if ne get f_nf 0 0 8475 fe_fail 9 8476 end 8477 fe_tok 8478 if ne get f_tk 0 1 8479 fe_fail 16 8480 end 8481 if gt get f_tl 0 63 8482 fe_fail 13 8483 end 8484 if ne fe_kw get f_tw 0 0 8485 fe_fail 16 8486 end 8487 w = get f_tw 0 8488 if ne fe_findstruct w 0 8489 fe_fail 10 8490 end 8491 if ne fe_findfn w get f_tl 0 get f_ts 0 0 8492 fe_fail 10 8493 end 8494 if ge get f_nst 0 16 8495 fe_fail 14 8496 end 8497 sid = get f_nst 0 8498 fo = get f_nsf 0 8499 cells = ulong 0 8500 nfld = ulong 0 8501 go = true 8502 while go 8503 fe_tok 8504 if eq get f_tk 0 0 8505 fe_fail 4 8506 end 8507 if ne get f_tk 0 1 8508 fe_fail 16 8509 end 8510 if eq fe_kw get f_tw 0 66 8511 go = false 8512 else 8513 if ge nfld 16 8514 fe_fail 14 8515 end 8516 cells = fe_s_field w fo cells 8517 nfld = add nfld 1 8518 end 8519 end 8520 if eq nfld 0 8521 fe_fail 16 8522 end 8523 put f_stname sid w 8524 put f_st_nf sid uchar nfld 8525 put f_stcell sid uchar cells 8526 put f_stfoff sid uchar fo 8527 put f_nst 0 add sid 1 8528 fe_eol 8529 end 8530 8531 note peek_struct: if the next word is a struct name, consume it and return index + 1; else rewind 8532 fn fe_peek_struct to ulong 8533 p = get f_cur 0 8534 ln = get f_line 0 8535 fe_tok 8536 if ne get f_tk 0 1 8537 put f_cur 0 p 8538 put f_line 0 ln 8539 ret 0 8540 end 8541 sid = fe_findstruct get f_tw 0 8542 if eq sid 0 8543 put f_cur 0 p 8544 put f_line 0 ln 8545 ret 0 8546 end 8547 ret sid 8548 end 8549 8550 note fn_p_st: parameter pw is view (k 2, name kind 8) or edit (k 3, name kind 7). fn_pk is 6 or 7. 8551 fn fe_fn_p_st f ulong np ulong pw ulong sid ulong k ulong to void 8552 si = sub sid 1 8553 t = add si 16 8554 ln = ulong get f_stcell si 8555 sk = add k 4 8556 if eq k 2 8557 fe_addname pw fe_poolc get f_psl 0 t ln 8 0 8558 else 8559 fe_addname pw fe_poolc get f_psl 0 t ln 7 0 8560 end 8561 p = add mul f 6 np 8562 ar_pc 33 p uchar t 8563 put ar_m add get ar_rb 34 p ln 8564 ar_pc 35 p uchar sk 8565 end 8566 8567 note sa_new: name = new . Rewind unless the next word is a struct name. 8568 fn fe_sa_new w ulong to void 8569 if ne get f_om2 0 0 8570 if ne get f_inl 0 0 8571 fe_fail 9 8572 end 8573 if ne ar_c 25 sub get f_curfn 0 1 0 8574 fe_fail 9 8575 end 8576 end 8577 p = get f_cur 0 8578 ln = get f_line 0 8579 fe_tok 8580 sid = ulong 0 8581 if eq get f_tk 0 1 8582 sid = fe_findstruct get f_tw 0 8583 end 8584 if ne sid 0 8585 fe_sa_st w sid 8586 ret 8587 end 8588 put f_cur 0 p 8589 put f_line 0 ln 8590 fe_sa_arr w 8591 end 8592 8593 note st_read: one value per field, saved in svk/svv/svt. An array field takes one value. 8594 fn fe_st_read si ulong to void 8595 fo = ulong get f_stfoff si 8596 nfd = ulong get f_st_nf si 8597 i = ulong 0 8598 while lt i nfd 8599 ft = ulong get f_sftype add fo i 8600 fe_rdval 0 ft 255 0 8601 if ne get f_rt 0 ft 8602 fe_fail 7 8603 end 8604 put f_svk i get f_rk 0 8605 put f_svv i get f_rv 0 8606 put f_svt i get f_rt 0 8607 i = add i 1 8608 end 8609 end 8610 8611 note st_store: STR of v at cell, scaled so the typed store lands on cell * 8. ADD is not used; the 8612 note index register holds cell << (3 - tlog). STR register-offset is the STOP table (om4). 8613 fn fe_st_store base ulong idx ulong cell ulong t ulong v ulong to void 8614 put f_ea_b 0 base 8615 put f_ea_i 0 idx 8616 end 8617 8618 note st_ixreg: runtime element index iv, field length fl, cell offset off. CMP + B.HS trap 3 8619 note (elemaddr, C6.2.96 / C6.2.34), then ADD Xidx, Xiv, #off (C6.2.5, base word `2432696320`) and 8620 note LSL by 3 - tlog (bo_lsl) so the STOP store lands on (off + i) * 8. 8621 fn fe_st_ixreg idx ulong iv ulong off ulong fl ulong t ulong to void 8622 fe_trapc 2 3 8623 end 8624 8625 note st_ld: LDR of type t from base + idx into dst (or a new register). LDOP table, as vt_get. 8626 fn fe_st_ld base ulong idx ulong t ulong dst ulong to void 8627 rd = fe_destreg dst 8628 put f_rk 0 1 8629 put f_rv 0 rd 8630 put f_rt 0 t 8631 end 8632 8633 note st_write1: store field j (value saved at sv* i) into the struct at base. 8634 fn fe_st_write1 base ulong tmp ulong idx ulong j ulong i ulong to void 8635 ft = ulong get f_sftype j 8636 fl = ulong get f_sf_len j 8637 off = ulong get f_sf_off j 8638 fe_force get f_svk i get f_svv i get f_svt i tmp 8639 if eq fl 0 8640 fe_st_store base idx off ft tmp 8641 else 8642 k = ulong 0 8643 while lt k fl 8644 fe_st_store base idx add off k ft tmp 8645 k = add k 1 8646 end 8647 end 8648 end 8649 8650 note st_write: store each field value. An array field is filled with its one value. 8651 fn fe_st_write base ulong tmp ulong idx ulong si ulong to void 8652 fo = ulong get f_stfoff si 8653 nfd = ulong get f_st_nf si 8654 i = ulong 0 8655 while lt i nfd 8656 fe_st_write1 base tmp idx add fo i i 8657 i = add i 1 8658 end 8659 end 8660 8661 note sa_st: p = new S v1 .. vn. Stack slot of the cell count, 16-byte aligned, outermost block only. 8662 fn fe_sa_st w ulong sid ulong to void 8663 if ne get f_nb 0 0 8664 fe_fail 9 8665 end 8666 si = sub sid 1 8667 cells = ulong get f_stcell si 8668 by = shl shr add shl cells 3 15 4 4 8669 s = add get f_stkbyt 0 by 8670 if gt s `4194304` 8671 fe_fail 23 8672 end 8673 put f_stkbyt 0 s 8674 r = fe_alloc 8675 put f_held 0 get f_nslot 0 8676 fe_st_read si 8677 fe_stkchk 8678 tmp = fe_alloc 8679 idx = fe_alloc 8680 fe_st_write r tmp idx si 8681 fe_addname w r add si 16 cells 6 0 8682 end 8683 8684 note ======== OM-2 section 5: abstract types (spec 5, errata E8, E9). `abstract NAME T [ops W..]` and 8685 note `holds NAME dup32` at top level before the first fn (names pass). NAME is type 64 + index: a value of 8686 note it comes only from `seal NAME v` inside the function NAMEmk returning NAME (else error 28), `open v` 8687 note gives the T value, and the listed operations (rotr/rotl with a T count, and/or/xor of two NAME 8688 note values) keep NAME; anything else on it, a T value or a number where NAME is needed, an array of it and 8689 note the entry function's parameters and result are error 7. With holds, seal checks high32 == low32 8690 note (LSR, CMP ..., UXTW, B.NE trap 10) unless the constructor body is exactly `ret seal NAME or shl ulong 8691 note x 32 ulong x` with x a uint parameter (rule dup32: uint values are held zero-extended). om2 diag 8692 note reports each check as omc-check 1 kept|erased line=N rule=dup32|-. ======== 8693 fn fe_findab w ulong to ulong 8694 i = ulong 0 8695 while lt i get f_nab 0 8696 if eq get f_abname i w 8697 ret add i 1 8698 end 8699 i = add i 1 8700 end 8701 ret 0 8702 end 8703 8704 note abty: the current word (not a type word) as an abstract type; anything else is error 16 8705 fn fe_abty to ulong 8706 a = fe_findab get f_tw 0 8707 if eq a 0 8708 fe_fail 16 8709 end 8710 ret add a 63 8711 end 8712 8713 note opbit: the ops bit of a preserving operation (rotr rotl and or xor), else 0 8714 fn fe_opbit c ulong to ulong 8715 if eq c 59 8716 ret 1 8717 end 8718 if eq c 60 8719 ret 2 8720 end 8721 if eq c 38 8722 ret 4 8723 end 8724 if eq c 39 8725 ret 8 8726 end 8727 if eq c 40 8728 ret 16 8729 end 8730 ret 0 8731 end 8732 8733 note s_abstract: abstract NAME uint|ulong [ops W ..] (another type is error 7, another op word 16) 8734 fn fe_s_abstract to void 8735 if ne get f_nf 0 0 8736 fe_fail 9 8737 end 8738 fe_tok 8739 if ne get f_tk 0 1 8740 fe_fail 16 8741 end 8742 if gt get f_tl 0 8 8743 fe_fail 13 8744 end 8745 w = get f_tw 0 8746 if ne fe_kw w 0 8747 fe_fail 16 8748 end 8749 fe_newname w get f_tl 0 get f_ts 0 8750 n = get f_nab 0 8751 if ge n 16 8752 fe_fail 14 8753 end 8754 put f_ab_len n get f_tl 0 8755 t = fe_typeword 8756 if and ne t 4 ne t 5 8757 fe_fail 7 8758 end 8759 opsb = ulong 0 8760 fe_tok 8761 if eq get f_tk 0 1 8762 if or gt get f_tl 0 8 ne fe_kw get f_tw 0 196 8763 fe_fail 5 8764 end 8765 go = true 8766 while go 8767 fe_tok 8768 k = get f_tk 0 8769 if or eq k 0 eq k 3 8770 go = false 8771 else 8772 if or ne k 1 gt get f_tl 0 8 8773 fe_fail 16 8774 end 8775 b = fe_opbit fe_kw get f_tw 0 8776 if eq b 0 8777 fe_fail 16 8778 end 8779 opsb = or opsb b 8780 end 8781 end 8782 else 8783 if and ne get f_tk 0 0 ne get f_tk 0 3 8784 fe_fail 5 8785 end 8786 end 8787 put f_abname n w 8788 put f_abbase n uchar t 8789 put f_ab_ops n opsb 8790 put f_nab 0 add n 1 8791 end 8792 8793 note ab_entry: function f (index) is the entry of a function-mode unit: no abstract parameter or result 8794 fn fe_ab_entry f ulong to void 8795 if eq get f_om2 0 0 8796 ret 8797 end 8798 if ne get f_scanni 0 0 8799 ret 8800 end 8801 if ne get f_progmo 0 0 8802 ret 8803 end 8804 if ne get f_nexp 0 0 8805 if eq ar_c 30 f 0 8806 ret 8807 end 8808 else 8809 if ne add f 1 get f_nf 0 8810 ret 8811 end 8812 end 8813 if ge ar_c 21 f 64 8814 fe_fail 7 8815 end 8816 i = ulong 0 8817 while lt i ulong ar_c 22 f 8818 if ge ar_c 33 add mul f 6 i 64 8819 fe_fail 7 8820 end 8821 i = add i 1 8822 end 8823 end 8824 8825 note ab_open: open v (the value read): an abstract value becomes its representation type 8826 fn fe_ab_open to void 8827 t = get f_rt 0 8828 if lt t 64 8829 fe_fail 7 8830 end 8831 put f_rt 0 ulong get f_abbase sub t 64 8832 end 8833 8834 note ab_seal: seal NAME v, only in the function NAMEmk (inlined or not) returning NAME (else error 28) 8835 fn fe_ab_seal to void 8836 fe_tok 8837 if or eq get f_tk 0 0 eq get f_tk 0 3 8838 fe_fail 4 8839 end 8840 a = ulong 0 8841 if and eq get f_tk 0 1 le get f_tl 0 8 8842 a = fe_findab get f_tw 0 8843 end 8844 if eq a 0 8845 fe_fail 16 8846 end 8847 a = sub a 1 8848 fe = get f_curfn 0 8849 if ne get f_inl 0 0 8850 fe = get f_il_fn sub get f_inl 0 1 8851 end 8852 if eq fe_ab_ctor fe a 0 8853 fe_fail 28 8854 end 8855 t = ulong get f_abbase a 8856 fe_rdval 0 t 255 0 8857 if ne get f_rt 0 t 8858 fe_fail 7 8859 end 8860 r = fe_matreg get f_rk 0 get f_rv 0 get f_rt 0 8861 if ne get f_abhold a 0 8862 fe_ab_check fe a r 8863 end 8864 put f_rk 0 1 8865 put f_rv 0 r 8866 put f_rt 0 add a 64 8867 end 8868 8869 note ab_ctor: 1 when function fe (index + 1) is NAMEmk for abstract a and returns it 8870 fn fe_ab_ctor fe ulong a ulong to ulong 8871 if eq fe 0 8872 ret 0 8873 end 8874 f = sub fe 1 8875 if ne ulong ar_c 21 f add a 64 8876 ret 0 8877 end 8878 l = get f_ab_len a 8879 if ne ar_w 23 f add l 2 8880 ret 0 8881 end 8882 o = get ar_m add get ar_rb 24 f 8883 w = get f_abname a 8884 i = ulong 0 8885 while lt i l 8886 if ne ulong ar_ib add o i and shr w shl i 3 255 8887 ret 0 8888 end 8889 i = add i 1 8890 end 8891 if ne ar_ib add o l 109 8892 ret 0 8893 end 8894 if ne ar_ib add add o l 1 107 8895 ret 0 8896 end 8897 ret 1 8898 end 8899 8900 note ab_check: the dup32 check of a seal (value in r): erased for the exact body, else LSR Xt, Xr, #32 8901 note (UBFM, C6.2.487); CMP Xt, Wr, UXTW (SUBS extended, C6.2.463); B.NE trap 10 8902 fn fe_ab_check fe ulong a ulong r ulong to void 8903 ex = fe_ab_exact fe a 8904 if eq get f_om2m 0 1 8905 note ab_rec: omc-check 1 kept|erased line=N rule=dup32|- (om2 diag, with the omc-site records) 8906 fe_sitew `7162245557575183727` 8 8907 fe_sitew `540090475` 4 8908 if ne ex 0 8909 fe_sitew `110386890240613` 6 8910 else 8911 fe_sitew `1953523051` 4 8912 end 8913 fe_sitew `67505853393952` 6 8914 fe_siten add get f_line 0 get f_lbase 0 8915 fe_sitew `67505820627488` 6 8916 if ne ex 0 8917 fe_sitew `215611372900` 5 8918 else 8919 fe_siteb 45 8920 end 8921 fe_siteb 10 8922 end 8923 if eq ex 0 8924 t = fe_alloc 8925 fe_trapc 1 10 8926 end 8927 end 8928 8929 note aw_next: the next word of the input from aw_p (blanks skipped, newlines counted in aw_nl) 8930 fn fe_aw_next to void 8931 p = get f_aw_p 0 8932 e = get f_inlen 0 8933 nl = ulong 0 8934 go = true 8935 while and go lt p e bound `134217729` 8936 b = ar_ib p 8937 if or eq b 32 eq b 9 8938 p = add p 1 8939 else 8940 if eq b 10 8941 nl = add nl 1 8942 p = add p 1 8943 else 8944 go = false 8945 end 8946 end 8947 end 8948 w = ulong 0 8949 l = ulong 0 8950 go2 = true 8951 while and go2 lt p e bound `134217729` 8952 c = ar_ib p 8953 if or or eq c 32 eq c 9 eq c 10 8954 go2 = false 8955 else 8956 if lt l 8 8957 w = or w shl ulong c shl l 3 8958 end 8959 l = add l 1 8960 p = add p 1 8961 end 8962 end 8963 put f_aw_p 0 p 8964 put f_aw_w 0 w 8965 put f_aw_l 0 l 8966 put f_aw_nl 0 nl 8967 end 8968 8969 note aw_is: the next word is w (length l) after exactly nl newlines 8970 fn fe_aw_is w ulong l ulong nl ulong to ulong 8971 fe_aw_next 8972 if ne get f_aw_w 0 w 8973 ret 0 8974 end 8975 if ne get f_aw_l 0 l 8976 ret 0 8977 end 8978 if ne get f_aw_nl 0 nl 8979 ret 0 8980 end 8981 ret 1 8982 end 8983 8984 note ab_upar: x (length xl) is a uint scalar parameter of function f (index) 8985 fn fe_ab_upar f ulong x ulong xl ulong to ulong 8986 if gt xl 8 8987 ret 0 8988 end 8989 i = ulong 0 8990 while lt i ulong ar_c 22 f 8991 p = add mul f 6 i 8992 if eq ar_w 32 p x 8993 if eq ar_c 35 p 0 8994 if eq ar_c 33 p 4 8995 ret 1 8996 end 8997 end 8998 end 8999 i = add i 1 9000 end 9001 ret 0 9002 end 9003 9004 note ab_exact: the body of constructor fe is exactly `ret seal NAME or shl ulong x 32 ulong x` then `end` 9005 fn fe_ab_exact fe ulong a ulong to ulong 9006 f = sub fe 1 9007 put f_aw_p 0 get ar_m add get ar_rb 26 f 9008 if eq fe_aw_is `7628146` 3 0 0 9009 ret 0 9010 end 9011 if eq fe_aw_is `1818322291` 4 0 0 9012 ret 0 9013 end 9014 if eq fe_aw_is get f_abname a get f_ab_len a 0 0 9015 ret 0 9016 end 9017 if eq fe_aw_is 29295 2 0 0 9018 ret 0 9019 end 9020 if eq fe_aw_is `7104627` 3 0 0 9021 ret 0 9022 end 9023 if eq fe_aw_is `444234427509` 5 0 0 9024 ret 0 9025 end 9026 fe_aw_next 9027 if ne get f_aw_nl 0 0 9028 ret 0 9029 end 9030 x = get f_aw_w 0 9031 xl = get f_aw_l 0 9032 if eq fe_ab_upar f x xl 0 9033 ret 0 9034 end 9035 if eq fe_aw_is 12851 2 0 0 9036 ret 0 9037 end 9038 if eq fe_aw_is `444234427509` 5 0 0 9039 ret 0 9040 end 9041 if eq fe_aw_is x xl 0 0 9042 ret 0 9043 end 9044 if eq fe_aw_is `6581861` 3 1 0 9045 ret 0 9046 end 9047 fe_aw_next 9048 if and ne get f_aw_l 0 0 eq get f_aw_nl 0 0 9049 ret 0 9050 end 9051 ret 1 9052 end 9053 9054 note ab_bin: a binary operation whose operand (fr[x..x+5]) is abstract: only a listed preserving one, run 9055 note on the representation type T and giving NAME; rotr/rotl take a T count (E9), and/or/xor two NAME values 9056 fn fe_ab_bin c ulong dst ulong x ulong to void 9057 atp = get ar_m add get ar_rb 59 add x 2 9058 if lt atp 64 9059 fe_fail 7 9060 end 9061 a = sub atp 64 9062 b = fe_opbit c 9063 if eq b 0 9064 fe_fail 7 9065 end 9066 if eq and get f_ab_ops a b 0 9067 fe_fail 7 9068 end 9069 t = ulong get f_abbase a 9070 bk = get ar_m add get ar_rb 59 add x 3 9071 bt = get ar_m add get ar_rb 59 add x 5 9072 if or eq c 59 eq c 60 9073 if eq bk 2 9074 fe_range get ar_m add get ar_rb 59 add x 4 t bt 9075 put ar_m add get ar_rb 59 add x 3 3 9076 else 9077 if ne bt t 9078 fe_fail 7 9079 end 9080 end 9081 else 9082 if ne bt atp 9083 fe_fail 7 9084 end 9085 end 9086 put ar_m add get ar_rb 59 add x 2 t 9087 put ar_m add get ar_rb 59 add x 5 t 9088 fe_binop c dst x 9089 put f_rt 0 atp 9090 end 9091 9092 note ======== OM-2 section 5: fresh scratch (spec 5, erratum E8). `NAME edit T N fresh` (N <= 64): the 9093 note incoming elements are unspecified. Each such array has a written set (bit i: element i definitely 9094 note written on the path being compiled). A put with a number index (after unrolling and inlining) sets 9095 note its bit; a get with a number index needs its bit, any other get all N bits (else error 27, 9096 note obligation=init). Joins: an if without else, a while and a rolled for keep the set they opened with; 9097 note an if/else takes the intersection of its arms (or the arm that does not end in ret); an unrolled 9098 note body and an inlined body keep what they wrote. Passing the array to a non-inline call, read, write or 9099 note a host operation is error 27; an inline callee works on the same set. ======== 9100 note fz_par: parameter slot f*6+np of kind k with N = ln is fresh: an edit only (else 16), N <= 64 (else 14) 9101 fn fe_fz_par f ulong np ulong k ulong ln ulong to void 9102 if ne k 3 9103 fe_fail 16 9104 end 9105 if gt ln 64 9106 put f_dobx 0 1 9107 fe_fail 14 9108 end 9109 ar_pc 37 add mul f 6 np 1 9110 end 9111 9112 note fz_bind: the parameter name just added for slot p gets a new written set in the body pass 9113 fn fe_fz_bind p ulong ln ulong to void 9114 if eq ar_c 37 p 0 9115 ret 9116 end 9117 if ne get f_scanni 0 0 9118 ret 9119 end 9120 fe_fz_new sub get f_nn 0 1 ln 9121 end 9122 9123 note fz_new: a new, empty written set of N elements for name index n (16 per function, error 14) 9124 fn fe_fz_new n ulong ln ulong to void 9125 s = get f_fz_n 0 9126 if ge s 16 9127 put f_dobx 0 1 9128 fe_fail 14 9129 end 9130 put f_fz_len s ln 9131 put f_fz_cur s 0 9132 ar_pc 12 n uchar add s 1 9133 put f_fz_n 0 add s 1 9134 end 9135 9136 note fz_inl: an inline parameter slot p bound to array name e: its own fresh set, or e's set 9137 fn fe_fz_inl p ulong e ulong to void 9138 pk = ulong ar_c 35 p 9139 if or eq pk 0 ge pk 6 9140 ret 9141 end 9142 n = sub get f_nn 0 1 9143 if ne ar_c 37 p 0 9144 fe_fz_new n get ar_m add get ar_rb 34 p 9145 ret 9146 end 9147 ar_pc 12 n uchar get ar_m add get ar_rb 12 sub e 1 9148 end 9149 9150 fn fe_fz_else i ulong to void 9151 j = ulong 0 9152 while lt j get f_fz_n 0 9153 x = add mul i 16 j 9154 put ar_m add get ar_rb 54 x get f_fz_cur j 9155 put f_fz_cur j get ar_m add get ar_rb 53 x 9156 j = add j 1 9157 end 9158 end 9159 9160 fn fe_fz_join i ulong k ulong to void 9161 td = get ar_m add get ar_rb 46 i 9162 ed = get f_dead 0 9163 j = ulong 0 9164 while lt j get f_fz_n 0 9165 x = add mul i 16 j 9166 if eq k 2 9167 v = and get f_fz_cur j get ar_m add get ar_rb 54 x 9168 if and ne td 0 eq ed 0 9169 v = get f_fz_cur j 9170 end 9171 if and ne ed 0 eq td 0 9172 v = get ar_m add get ar_rb 54 x 9173 end 9174 put f_fz_cur j v 9175 else 9176 put f_fz_cur j get ar_m add get ar_rb 53 x 9177 end 9178 j = add j 1 9179 end 9180 end 9181 9182 note fz_get: get e i with the index in rk/rv/rt 9183 fn fe_fz_get e ulong to void 9184 if ne get f_cvalid 0 0 9185 ret 9186 end 9187 s = ulong uchar get ar_m add get ar_rb 12 sub e 1 9188 if eq s 0 9189 ret 9190 end 9191 s = sub s 1 9192 n = get f_fz_len s 9193 if eq get f_rk 0 3 9194 v = get f_rv 0 9195 if lt v n 9196 if eq and shr get f_fz_cur s v 1 0 9197 fe_fail 27 9198 end 9199 end 9200 ret 9201 end 9202 if ne get f_fz_cur s fe_fmask n 9203 fe_fail 27 9204 end 9205 end 9206 9207 note fz_put: put e i v with index (k, v): a number index sets its bit 9208 fn fe_fz_put e ulong k ulong v ulong to void 9209 s = ulong uchar get ar_m add get ar_rb 12 sub e 1 9210 if eq s 0 9211 ret 9212 end 9213 s = sub s 1 9214 if eq k 3 9215 if lt v get f_fz_len s 9216 put f_fz_cur s or get f_fz_cur s shl ulong 1 v 9217 end 9218 end 9219 end 9220 9221 note fz_arg: array name e leaves the analysis (a non-inline call, read, write, a host operation): error 27 9222 note when it is tracked 9223 fn fe_fz_arg e ulong to void 9224 if ne ar_c 12 sub e 1 0 9225 fe_fail 27 9226 end 9227 end 9228 9229 note ======== OM-2 section 5: external layouts (spec 5, errata E5, E8, E9). `layout NAME SIZE`, then one 9230 note `field F T [COUNT] at OFF little|big` per line, then `end`, before the first fn. Read in the names pass; 9231 note the body pass jumps over the block. A parameter `c view|edit NAME` is a uchar array of SIZE bytes (one 9232 note pointer); `get c F [i]` / `put c F [i] v` load / store the field at its width and byte order: 9233 note LDR/STR (register, unscaled offset; C6.2.216 family) at base + OFF + i * width, REV16 / REV (C6.2.333, 9234 note C6.2.331) for big, a run-time index checked like an array's (CMP, B.HS trap 3) ======== 9235 note findlay: packed name -> layout index + 1, or 0 9236 fn fe_findlay w ulong to ulong 9237 i = ulong 0 9238 while lt i get f_nly 0 9239 if eq get f_lyname i w 9240 ret add i 1 9241 end 9242 i = add i 1 9243 end 9244 ret 0 9245 end 9246 9247 note findlf: layout index li, packed field name -> field-table index + 1, or 0 9248 fn fe_findlf li ulong w ulong to ulong 9249 fo = get f_ly_fo li 9250 i = ulong 0 9251 while lt i get f_ly_nf li 9252 if eq get f_lfname add fo i w 9253 ret add add fo i 1 9254 end 9255 i = add i 1 9256 end 9257 ret 0 9258 end 9259 9260 note ns_om2: an OM-2 declaration line in the names pass (1 when it was read), else 0 9261 fn fe_ns_om2 to ulong 9262 if eq get f_om2 0 0 9263 ret 0 9264 end 9265 if ne get f_tk 0 1 9266 ret 0 9267 end 9268 if gt get f_tl 0 8 9269 ret 0 9270 end 9271 if eq get f_tw 0 `128047730221420` 9272 fe_s_layout 9273 ret 1 9274 end 9275 if eq get f_tw 0 `8386654075301880417` 9276 fe_s_abstract 9277 ret 1 9278 end 9279 if eq get f_tw 0 `495606067048` 9280 note s_holds: holds NAME dup32 (ulong representation only); any other predicate is error 28 on this line 9281 if ne get f_nf 0 0 9282 fe_fail 9 9283 end 9284 fe_tok 9285 if ne get f_tk 0 1 9286 fe_fail 16 9287 end 9288 a = ulong 0 9289 if le get f_tl 0 8 9290 a = fe_findab get f_tw 0 9291 end 9292 if eq a 0 9293 fe_fail 16 9294 end 9295 a = sub a 1 9296 fe_tok 9297 if or eq get f_tk 0 0 eq get f_tk 0 3 9298 fe_fail 4 9299 end 9300 if ne get f_tk 0 1 9301 fe_fail 28 9302 end 9303 if or ne get f_tl 0 5 ne get f_tw 0 `215611372900` 9304 fe_fail 28 9305 end 9306 if ne get f_abbase a 5 9307 fe_fail 28 9308 end 9309 if ne get f_abhold a 0 9310 fe_fail 10 9311 end 9312 put f_abhold a 1 9313 fe_eol 9314 ret 1 9315 end 9316 if eq get f_tw 0 `128034844735589` 9317 fe_s_export 9318 ret 1 9319 end 9320 ret 0 9321 end 9322 9323 note s_export (OM-2, spec 6): `export fn ...` at top level: the fn line of an exported entry, in both 9324 note passes. Function mode only (error 9), at most 32 (error 14), counted and marked in the names pass. 9325 fn fe_s_export to void 9326 fe_tok 9327 if or ne get f_tk 0 1 ne get f_tw 0 28262 9328 fe_fail 16 9329 end 9330 if eq get f_scanni 0 1 9331 if ne get f_progmo 0 0 9332 fe_fail 9 9333 end 9334 if ge get f_nexp 0 32 9335 fe_fail 14 9336 end 9337 put f_nexp 0 add get f_nexp 0 1 9338 end 9339 put f_expf 0 1 9340 fe_s_fn 9341 put f_expf 0 0 9342 end 9343 9344 note ly_num: the next token must be a number (error 4 at the line end, 16 for another token, 29 when it 9345 note was written as 2^63 or more) 9346 fn fe_ly_num to ulong 9347 fe_tok 9348 if or eq get f_tk 0 0 eq get f_tk 0 3 9349 fe_fail 4 9350 end 9351 if ne get f_tk 0 2 9352 fe_fail 16 9353 end 9354 if ne get f_tbig 0 0 9355 fe_fail 29 9356 end 9357 ret get f_tw 0 9358 end 9359 9360 note s_layout: SIZE 1..4096 and a layout after the first fn are error 29 on the layout line 9361 fn fe_s_layout to void 9362 if ne get f_nf 0 0 9363 fe_fail 29 9364 end 9365 fe_tok 9366 if ne get f_tk 0 1 9367 fe_fail 16 9368 end 9369 if gt get f_tl 0 8 9370 fe_fail 13 9371 end 9372 w = get f_tw 0 9373 if ne fe_kw w 0 9374 fe_fail 16 9375 end 9376 fe_newname w get f_tl 0 get f_ts 0 9377 if ge get f_nly 0 16 9378 fe_fail 14 9379 end 9380 sz = fe_ly_num 9381 if or eq sz 0 gt sz 4096 9382 fe_fail 29 9383 end 9384 fe_eol 9385 li = get f_nly 0 9386 fo = get f_nlf 0 9387 i = ulong 0 9388 while lt i sz 9389 put f_lymap i 0 9390 i = add i 1 9391 end 9392 go = true 9393 while go 9394 fe_tok 9395 k = get f_tk 0 9396 if eq k 3 9397 fe_fail 4 9398 end 9399 if eq k 1 9400 c = ulong 0 9401 if le get f_tl 0 8 9402 c = fe_kw get f_tw 0 9403 end 9404 if eq c 66 9405 fe_eol 9406 go = false 9407 else 9408 if eq c 83 9409 fe_skipnl 9410 else 9411 if ne c 189 9412 fe_fail 16 9413 end 9414 fe_ly_field fo sz 9415 end 9416 end 9417 else 9418 if ne k 0 9419 fe_fail 16 9420 end 9421 end 9422 end 9423 put f_lyname li w 9424 put f_lysize li sz 9425 put f_ly_fo li fo 9426 put f_ly_nf li sub get f_nlf 0 fo 9427 put f_ly_ec li get f_cur 0 9428 put f_ly_el li get f_line 0 9429 put f_nly 0 add li 1 9430 end 9431 9432 note ly_field: F T [COUNT] at OFF little|big. A field over SIZE, a COUNT outside 1..4096, an OFF out of range 9433 note or two fields sharing a byte are error 29 on the field line. Field types are the integer types. 9434 fn fe_ly_field fo ulong sz ulong to void 9435 fe_tok 9436 if or eq get f_tk 0 0 eq get f_tk 0 3 9437 fe_fail 4 9438 end 9439 if ne get f_tk 0 1 9440 fe_fail 16 9441 end 9442 if gt get f_tl 0 8 9443 fe_fail 13 9444 end 9445 fw = get f_tw 0 9446 if ne fe_kw fw 0 9447 fe_fail 16 9448 end 9449 n = get f_nlf 0 9450 i = fo 9451 while lt i n 9452 if eq get f_lfname i fw 9453 fe_fail 10 9454 end 9455 i = add i 1 9456 end 9457 if ge n 256 9458 fe_fail 14 9459 end 9460 t = fe_typeword 9461 if or lt t 2 gt t 9 9462 fe_fail 7 9463 end 9464 cnt = ulong 0 9465 fe_tok 9466 if eq get f_tk 0 2 9467 if ne get f_tbig 0 0 9468 fe_fail 29 9469 end 9470 cnt = get f_tw 0 9471 if or eq cnt 0 gt cnt 4096 9472 fe_fail 29 9473 end 9474 fe_tok 9475 end 9476 if or eq get f_tk 0 0 eq get f_tk 0 3 9477 fe_fail 4 9478 end 9479 if ne get f_tk 0 1 9480 fe_fail 16 9481 end 9482 if ne fe_kw get f_tw 0 190 9483 fe_fail 16 9484 end 9485 off = fe_ly_num 9486 bigf = fe_ly_end 9487 fe_ly_mark off cnt t sz 9488 fe_eol 9489 put f_lfname n fw 9490 put f_lftype n uchar t 9491 put f_lf_cnt n cnt 9492 put f_lf_off n off 9493 put f_lf_big n uchar bigf 9494 put f_nlf 0 add n 1 9495 end 9496 9497 note ly_end: little (0) or big (1) 9498 fn fe_ly_end to ulong 9499 fe_tok 9500 if or eq get f_tk 0 0 eq get f_tk 0 3 9501 fe_fail 4 9502 end 9503 if ne get f_tk 0 1 9504 fe_fail 16 9505 end 9506 c = fe_kw get f_tw 0 9507 if eq c 191 9508 ret 0 9509 end 9510 if eq c 192 9511 ret 1 9512 end 9513 fe_fail 16 9514 ret 0 9515 end 9516 9517 note ly_mark: the bytes OFF .. OFF + max(COUNT, 1) * width must lie inside SIZE and be free (error 29) 9518 fn fe_ly_mark off ulong cnt ulong t ulong sz ulong to void 9519 n = cnt 9520 if eq n 0 9521 n = ulong 1 9522 end 9523 by = shl n fe_tlog t 9524 if gt off sz 9525 fe_fail 29 9526 end 9527 e = add off by 9528 if gt e sz 9529 fe_fail 29 9530 end 9531 i = off 9532 while lt i e 9533 if ne get f_lymap i 0 9534 fe_fail 29 9535 end 9536 put f_lymap i 1 9537 i = add i 1 9538 end 9539 end 9540 9541 note peek_lay: if the next word is a layout name, consume it and return index + 1; else rewind 9542 fn fe_peek_lay to ulong 9543 p = get f_cur 0 9544 ln = get f_line 0 9545 fe_tok 9546 if eq get f_tk 0 1 9547 if le get f_tl 0 8 9548 lid = fe_findlay get f_tw 0 9549 if ne lid 0 9550 ret lid 9551 end 9552 end 9553 end 9554 put f_cur 0 p 9555 put f_line 0 ln 9556 ret 0 9557 end 9558 9559 note fn_p_ly: parameter pw is a layout (view k 2 / edit k 3): a uchar array of SIZE bytes, name kind 2 / 3 9560 fn fe_fn_p_ly f ulong np ulong pw ulong lid ulong k ulong to void 9561 ln = get f_lysize sub lid 1 9562 fe_addname pw fe_poolc get f_psl 0 2 ln k 0 9563 ar_pc 11 sub get f_nn 0 1 uchar lid 9564 p = add mul f 6 np 9565 ar_pc 33 p 2 9566 put ar_m add get ar_rb 34 p ln 9567 ar_pc 35 p uchar k 9568 ar_pc 36 p uchar lid 9569 end 9570 9571 note ly_fld: for a layout name e, when the next word is one of its fields: consume it, return the field-table 9572 note index + 1; otherwise rewind and return 0 (the name is then an ordinary uchar array) 9573 fn fe_ly_fld e ulong to ulong 9574 lid = ulong uchar get ar_m add get ar_rb 11 sub e 1 9575 if eq lid 0 9576 ret 0 9577 end 9578 p = get f_cur 0 9579 ln = get f_line 0 9580 fe_tok 9581 if eq get f_tk 0 1 9582 if le get f_tl 0 8 9583 j = fe_findlf sub lid 1 get f_tw 0 9584 if ne j 0 9585 ret j 9586 end 9587 end 9588 end 9589 put f_cur 0 p 9590 put f_line 0 ln 9591 ret 0 9592 end 9593 9594 9595 9596 9597 note ly_ix: the byte-offset register of element (k, v, t) of array field j: a number index must be below 9598 note COUNT (error 21); a register index: CMP Xi, #COUNT or Xc (C6.2.96 / C6.2.97), B.HS trap 3, then 9599 note Xo = OFF; ADD Xo, Xo, Xi, LSL #log2 width (C6.2.6) 9600 fn fe_ly_ix j ulong k ulong v ulong t ulong to ulong 9601 if or eq t 1 ge t 10 9602 fe_fail 7 9603 end 9604 cnt = get f_lf_cnt j 9605 x = fe_alloc 9606 if eq k 3 9607 if ge v cnt 9608 fe_fail 21 9609 end 9610 ret x 9611 end 9612 r = fe_matreg k v t 9613 if le cnt 4095 9614 else 9615 y = fe_alloc 9616 end 9617 fe_trapc 2 3 9618 ret x 9619 end 9620 9621 note ly_get: get c F [i] on a layout name e (1 when it was a field, the value in rk/rv/rt), else 0 9622 fn fe_ly_get e ulong dst ulong to ulong 9623 j = fe_ly_fld e 9624 if eq j 0 9625 ret 0 9626 end 9627 j = sub j 1 9628 ft = ulong get f_lftype j 9629 if eq get f_lf_cnt j 0 9630 x = fe_alloc 9631 else 9632 fe_rdval 0 5 255 0 9633 x = fe_ly_ix j get f_rk 0 get f_rv 0 get f_rt 0 9634 end 9635 rd = fe_destreg dst 9636 put f_rk 0 1 9637 put f_rv 0 rd 9638 put f_rt 0 ft 9639 ret 1 9640 end 9641 9642 note ly_put: put c F [i] v on a layout name e (an edit; a view was refused 20 before): index, value, then 9643 note the store; 1 when it was a field, else 0 9644 fn fe_ly_put e ulong to ulong 9645 j = fe_ly_fld e 9646 if eq j 0 9647 ret 0 9648 end 9649 j = sub j 1 9650 if ne get f_lf_cnt j 0 9651 fe_rdval 0 5 255 0 9652 put f_svk 0 get f_rk 0 9653 put f_svv 0 get f_rv 0 9654 put f_svt 0 get f_rt 0 9655 end 9656 fe_ly_st e j 9657 fe_eol 9658 ret 1 9659 end 9660 9661 note ly_st: the value of field j (index saved in svk/svv/svt), then the store through layout name e 9662 fn fe_ly_st e ulong j ulong to void 9663 ft = ulong get f_lftype j 9664 cnt = get f_lf_cnt j 9665 fe_rdval 0 ft 255 0 9666 if ne get f_rt 0 ft 9667 fe_fail 7 9668 end 9669 v = fe_matreg get f_rk 0 get f_rv 0 get f_rt 0 9670 if eq cnt 0 9671 x = fe_alloc 9672 else 9673 x = fe_ly_ix j get f_svk 0 get f_svv 0 get f_svt 0 9674 end 9675 if and ne get f_lf_big j 0 ne fe_tlog ft 0 9676 y = fe_alloc 9677 end 9678 end 9679 9680 note vt_fget_go: field j of struct name e. Scalar, or an index then the element. 9681 fn fe_vt_fget_go e ulong dst ulong j ulong to void 9682 fl = ulong get f_sf_len j 9683 ft = ulong get f_sftype j 9684 off = ulong get f_sf_off j 9685 base = ulong uchar get ar_m add get ar_rb 5 sub e 1 9686 idx = fe_alloc 9687 if eq fl 0 9688 fe_st_store_ld base idx off ft dst 9689 else 9690 fe_rdval 0 5 255 0 9691 if eq get f_rt 0 1 9692 fe_fail 7 9693 end 9694 if eq get f_rk 0 3 9695 if ge get f_rv 0 fl 9696 fe_fail 21 9697 end 9698 fe_st_store_ld base idx add off get f_rv 0 ft dst 9699 else 9700 if ne get f_rk 0 1 9701 fe_fail 7 9702 end 9703 fe_st_ixreg idx get f_rv 0 off fl ft 9704 fe_st_ld base idx ft dst 9705 end 9706 end 9707 end 9708 9709 note vt_fget: get p f, or get p f i for an array field. Kind 6 own, 7 edit, 8 view; all may be read. 9710 fn fe_vt_fget e ulong dst ulong to void 9711 i = sub e 1 9712 fe_tok 9713 if ne get f_tk 0 1 9714 fe_fail 16 9715 end 9716 if gt get f_tl 0 63 9717 fe_fail 13 9718 end 9719 si = sub ulong uchar get ar_m add get ar_rb 6 i 16 9720 fid = fe_findfield si get f_tw 0 9721 if eq fid 0 9722 fe_fail 3 9723 end 9724 fe_vt_fget_go e dst sub fid 1 9725 end 9726 9727 note st_store_ld: constant cell, then load. Split out so vt_fget stays under 16 registers. 9728 fn fe_st_store_ld base ulong idx ulong cell ulong t ulong dst ulong to void 9729 fe_st_ld base idx t dst 9730 end 9731 9732 note s_putf_go: field j of struct name e. Read the value (and the index, if an array field) and store. 9733 fn fe_s_putf_go e ulong j ulong to void 9734 fl = ulong get f_sf_len j 9735 ft = ulong get f_sftype j 9736 off = ulong get f_sf_off j 9737 base = ulong uchar get ar_m add get ar_rb 5 sub e 1 9738 if ne fl 0 9739 fe_rdval 0 5 255 0 9740 if eq get f_rt 0 1 9741 fe_fail 7 9742 end 9743 put f_svk 0 get f_rk 0 9744 put f_svv 0 get f_rv 0 9745 put f_svt 0 get f_rt 0 9746 end 9747 fe_rdval 0 ft 255 0 9748 if ne get f_rt 0 ft 9749 fe_fail 7 9750 end 9751 v = fe_matreg get f_rk 0 get f_rv 0 get f_rt 0 9752 idx = fe_alloc 9753 if eq fl 0 9754 fe_st_store base idx off ft v 9755 else 9756 fe_s_putf_ix base idx v off fl ft 9757 end 9758 fe_eol 9759 end 9760 9761 note s_putf: put p f v, or put p f i v. A view struct is error 20. 9762 fn fe_s_putf e ulong to void 9763 i = sub e 1 9764 if eq ulong ar_c 8 i 8 9765 fe_fail 20 9766 end 9767 fe_tok 9768 if ne get f_tk 0 1 9769 fe_fail 16 9770 end 9771 if gt get f_tl 0 63 9772 fe_fail 13 9773 end 9774 si = sub ulong uchar get ar_m add get ar_rb 6 i 16 9775 fid = fe_findfield si get f_tw 0 9776 if eq fid 0 9777 fe_fail 3 9778 end 9779 fe_s_putf_go e sub fid 1 9780 end 9781 9782 note s_putf_ix: the index was saved in svk/svv/svt before the value was read 9783 fn fe_s_putf_ix base ulong idx ulong v ulong off ulong fl ulong ft ulong to void 9784 ik = get f_svk 0 9785 iv = get f_svv 0 9786 if eq get f_svt 0 1 9787 fe_fail 7 9788 end 9789 if eq ik 3 9790 if ge iv fl 9791 fe_fail 21 9792 end 9793 fe_st_store base idx add off iv ft v 9794 else 9795 if ne ik 1 9796 fe_fail 7 9797 end 9798 fe_st_ixreg idx iv off fl ft 9799 put f_ea_b 0 base 9800 put f_ea_i 0 idx 9801 end 9802 end 9803 9804 note ca_st_ok: read one struct argument of parameter i of function f. Returns the name entry. 9805 fn fe_ca_st_ok f ulong i ulong to ulong 9806 md = ulong 0 9807 fe_aa_word 9808 w = get f_tw 0 9809 c = fe_kw w 9810 if ne c 0 9811 if or lt c 57 gt c 58 9812 fe_fail 16 9813 end 9814 md = c 9815 fe_aa_word 9816 w = get f_tw 0 9817 end 9818 e = fe_findname w 9819 if eq e 0 9820 fe_fail 3 9821 end 9822 ni = sub e 1 9823 k = ulong uchar get ar_m add get ar_rb 8 ni 9824 if or eq k 10 lt k 6 9825 fe_fail 7 9826 end 9827 p = add mul sub f 1 6 i 9828 pk = ulong ar_c 35 p 9829 if eq pk 7 9830 if eq md 57 9831 fe_fail 20 9832 end 9833 if eq k 8 9834 fe_fail 20 9835 end 9836 else 9837 if eq md 58 9838 fe_fail 7 9839 end 9840 end 9841 if ne ulong ar_c 6 ni ulong ar_c 33 p 9842 fe_fail 7 9843 end 9844 ret e 9845 end 9846 9847 note ca_st: a struct argument. edit (fn_pk 7) needs own or edit; view takes any. Same struct. 9848 fn fe_ca_st f ulong i ulong cb ulong to void 9849 e = fe_ca_st_ok f i 9850 note ca_dist: the same struct name passed twice in one call is error 19. 9851 j = ulong 0 9852 while lt j i 9853 if eq ar_w 59 add add cb mul j 3 2 e 9854 fe_fail 19 9855 end 9856 j = add j 1 9857 end 9858 q = add cb mul i 3 9859 put ar_m add get ar_rb 59 q 5 9860 put ar_m add get ar_rb 59 add q 1 ulong ar_c 5 sub e 1 9861 put ar_m add get ar_rb 59 add q 2 e 9862 end 9863 note ---- R6 IR. A leading line `ir` writes OSC IR version 1. The AArch64 path is not taken. 9864 note Worksheet ir_match.py matched omega_emit on the 10 dev programs; this is that algorithm. 9865 9866 9867 note ir_lead: 1 when the first line is "ir" (after blanks). Both scans run as nested 999999-pass loops, 9868 note so more than `1000000` leading blanks or first-line bytes are read, not trapped 4 (#671). 9869 fn fe_ir_lead to ulong 9870 p = ulong 0 9871 go = true 9872 while go 9873 m = ulong 0 9874 while and go lt m 999999 9875 if ge p get f_inlen 0 9876 go = false 9877 else 9878 c = ar_ib p 9879 if gt c 32 9880 go = false 9881 else 9882 if eq c 10 9883 ret 0 9884 end 9885 p = add p 1 9886 end 9887 end 9888 m = add m 1 9889 end 9890 end 9891 if ge add p 3 get f_inlen 0 9892 ret 0 9893 end 9894 if ne ar_ib p 105 9895 ret 0 9896 end 9897 if ne ar_ib add p 1 114 9898 ret 0 9899 end 9900 if gt ar_ib add p 2 32 9901 ret 0 9902 end 9903 q = add p 2 9904 go = true 9905 while go 9906 m = ulong 0 9907 while and go lt m 999999 9908 if ge q get f_inlen 0 9909 go = false 9910 else 9911 if eq ar_ib q 10 9912 go = false 9913 else 9914 q = add q 1 9915 end 9916 end 9917 m = add m 1 9918 end 9919 end 9920 if lt q get f_inlen 0 9921 q = add q 1 9922 end 9923 put f_cur 0 q 9924 put f_line 0 2 9925 ret 1 9926 end 9927 9928 9929 9930 9931 9932 9933 9934 9935 9936 9937 9938 9939 9940 9941 9942 9943 9944 9945 9946 9947 9948 9949 9950 9951 9952 9953 9954 9955 9956 9957 9958 9959 9960 9961 9962 9963 9964 9965 9966 9967 9968 9969 9970 9971 9972 9973 9974 note ======== executable contract predicates (OM-2, native targets) ======== 9975 note Token packs below: Wolfram FromDigits[Reverse[ToCharacterCode[word]],256]. 9976 note Contract words are contextual: OM-1 name meanings and keyword-table bytes do not change. 9977 note Explicit native build policy, with syntax and purity checked in both policies. 9978 note om2 debug / om2 release and om2 diag debug / om2 diag release; fmt stays canonical. 9979 fn fe_cp_mode q ulong to ulong 9980 if gt add q 4 get f_inlen 0 9981 ret 0 9982 end 9983 if ne ar_ib q 111 9984 ret 0 9985 end 9986 if ne ar_ib add q 1 109 9987 ret 0 9988 end 9989 if ne ar_ib add q 2 50 9990 ret 0 9991 end 9992 if ne ar_ib add q 3 32 9993 ret 0 9994 end 9995 p = add q 4 9996 m = ulong 1 9997 if le add p 5 get f_inlen 0 9998 if and eq ar_ib p 100 eq ar_ib add p 1 105 9999 if and eq ar_ib add p 2 97 eq ar_ib add p 3 103 10000 if eq ar_ib add p 4 32 10001 p = add p 5 10002 m = ulong 2 10003 end 10004 end 10005 end 10006 end 10007 if ne fe_lineis p `28555834798400882` 7 0 10008 put f_crel 0 1 10009 ret m 10010 end 10011 if ne fe_lineis p `444351014244` 5 0 10012 ret m 10013 end 10014 ret 0 10015 end 10016 10017 fn fe_cp_kind to ulong 10018 if and eq get f_om2 0 0 eq get f_irmode 0 0 10019 ret 0 10020 end 10021 if ne get f_tk 0 1 10022 ret 0 10023 end 10024 if and eq get f_tl 0 8 eq get f_tw 0 `8315178084276987250` 10025 ret 1 10026 end 10027 if and eq get f_tl 0 7 eq get f_tw 0 `32481164592901733` 10028 ret 2 10029 end 10030 if and eq get f_tl 0 9 eq get f_tw8 0 `7953754356895346281` 10031 if eq ar_ib add get f_ts 0 8 116 10032 ret 3 10033 end 10034 end 10035 ret 0 10036 end 10037 10038 note cp_next reads the next prefix clause, ignoring comments and blanks; a nonclause is unread. 10039 fn fe_cp_next to ulong 10040 p = get f_cur 0 10041 l = get f_line 0 10042 go = true 10043 while go 10044 fe_tok 10045 if eq get f_tk 0 1 10046 if and eq get f_tl 0 4 eq get f_tw 0 `1702129518` 10047 fe_skipnl 10048 else 10049 go = false 10050 end 10051 else 10052 if ne get f_tk 0 0 10053 go = false 10054 end 10055 end 10056 end 10057 k = fe_cp_kind 10058 if eq k 0 10059 put f_cur 0 p 10060 put f_line 0 l 10061 end 10062 ret k 10063 end 10064 10065 note Recursive purity allowlist, before rdval dispatch. No calls, floats, host or mapped operations. 10066 fn fe_cp_token to void 10067 if eq get f_tk 0 2 10068 ret 10069 end 10070 if ne get f_tk 0 1 10071 fe_fail 30 10072 end 10073 if gt get f_tl 0 63 10074 fe_fail 30 10075 end 10076 c = fe_kw get f_tw 0 10077 if eq c 0 10078 ret 10079 end 10080 if le sub c 1 8 10081 ret 10082 end 10083 if le sub c 33 19 10084 ret 10085 end 10086 if or eq c 55 eq c 56 10087 ret 10088 end 10089 if or or eq c 59 eq c 60 eq c 74 10090 ret 10091 end 10092 fe_fail 30 10093 end 10094 10095 note cp_erase: take back a release-erased contract's diag site records. From omc.om cp_erase (@`943d9555` line 14464), 10096 note which also took back its code, trap records and branch targets; the check pass has none. 10097 fn fe_cp_erase to void 10098 put f_nsite 0 get f_csnap 2 10099 end 10100 10101 fn fe_cp_eval code ulong erase ulong to void 10102 ln = get f_line 0 10103 rule = ulong 0 10104 note Pure evaluation changes no names, calls, inline frames or writes. 10105 note Snapshot the diagnostic sites, the pool slots and the fuel zone (omc.om also snapshot code effects). 10106 put f_csnap 2 get f_nsite 0 10107 put f_csnap 3 get f_nslot 0 10108 put f_csnap 4 get f_fzone 0 10109 put f_cpure 0 1 10110 put f_fzone 0 1 10111 fe_rdval 0 1 255 0 10112 if ne get f_rt 0 1 10113 fe_fail 7 10114 end 10115 fe_eol 10116 nextln = get f_line 0 10117 put f_line 0 ln 10118 if and eq get f_rk 0 3 ne get f_rv 0 0 10119 rule = ulong 1 10120 fe_cp_erase 10121 else 10122 if or ne erase 0 ne get f_crel 0 0 10123 rule = ulong 2 10124 fe_cp_erase 10125 else 10126 if eq get f_rk 0 3 10127 fe_trapc 14 code 10128 else 10129 if eq get f_rk 0 4 10130 fe_trapc xor get f_rv 0 1 code 10131 else 10132 r = fe_matreg get f_rk 0 get f_rv 0 get f_rt 0 10133 fe_trapsite or `3019898880` r code 10134 end 10135 end 10136 end 10137 end 10138 if and eq get f_om2m 0 1 eq erase 0 10139 fe_cp_rec rule 10140 end 10141 put f_line 0 nextln 10142 put f_cpure 0 0 10143 put f_cvalid 0 0 10144 put f_fzone 0 get f_csnap 4 10145 put f_nslot 0 get f_csnap 3 10146 end 10147 10148 note omc-check distinguishes a proof from release policy; initial deferred validation is silent. 10149 fn fe_cp_rec rule ulong to void 10150 fe_sitew `7162245557575183727` 8 10151 fe_sitew `540090475` 4 10152 if eq rule 0 10153 fe_sitew `1953523051` 4 10154 else 10155 fe_sitew `110386890240613` 6 10156 end 10157 fe_sitew `67505853393952` 6 10158 fe_siten add get f_line 0 get f_lbase 0 10159 fe_sitew `67505820627488` 6 10160 if eq rule 0 10161 fe_sitew `28549272340166002` 7 10162 end 10163 if eq rule 1 10164 fe_sitew `8389750308618530659` 8 10165 fe_sitew `435762132013` 5 10166 end 10167 if eq rule 2 10168 fe_sitew `28555834798400882` 7 10169 end 10170 fe_sitew `67501558426400` 6 10171 if eq get f_ckind 0 1 10172 fe_sitew `8315178084276987250` 8 10173 end 10174 if eq get f_ckind 0 2 10175 fe_sitew `32481164592901733` 7 10176 end 10177 if eq get f_ckind 0 3 10178 fe_sitew `7953754356895346281` 8 10179 fe_siteb 116 10180 end 10181 fe_siteb 10 10182 end 10183 10184 note Function prefix predicates bind only globals and parameters visible on entry. 10185 fn fe_cp_entry to void 10186 lv = get f_inl 0 10187 put f_cfhas lv 0 10188 if eq get f_om2 0 0 10189 ret 10190 end 10191 put f_cfpos lv get f_cur 0 10192 put f_cfline lv get f_line 0 10193 put f_cflim lv get f_nn 0 10194 put f_clim 0 get f_nn 0 10195 k = fe_cp_next 10196 n = ulong 0 10197 while ne k 0 10198 put f_ckind 0 k 10199 if ge n 64 10200 fe_fail 14 10201 end 10202 if eq k 3 10203 fe_fail 30 10204 end 10205 put f_crkind 0 0 10206 if eq k 1 10207 fe_cp_eval 9 0 10208 else 10209 put f_cfhas lv 1 10210 ns = get f_nslot 0 10211 put f_crtype 0 get f_curret 0 10212 if ne get f_curret 0 12 10213 put f_crkind 0 1 10214 put f_crval 0 fe_alloc 10215 end 10216 put f_cvalid 0 1 10217 fe_cp_eval 10 1 10218 put f_nslot 0 ns 10219 end 10220 n = add n 1 10221 k = fe_cp_next 10222 end 10223 end 10224 10225 note Return expressions are evaluated once, before postconditions, without overwriting argument X0. 10226 fn fe_cp_post kind ulong value ulong ty ulong to void 10227 lv = get f_inl 0 10228 if eq get f_cfhas lv 0 10229 ret 10230 end 10231 p = get f_cur 0 10232 l = get f_line 0 10233 put f_cur 0 get f_cfpos lv 10234 put f_line 0 get f_cfline lv 10235 put f_clim 0 get f_cflim lv 10236 put f_crkind 0 kind 10237 put f_crval 0 value 10238 put f_crtype 0 ty 10239 k = fe_cp_next 10240 while ne k 0 10241 if eq k 2 10242 put f_ckind 0 2 10243 fe_cp_eval 10 0 10244 else 10245 fe_skipnl 10246 end 10247 k = fe_cp_next 10248 end 10249 put f_cur 0 p 10250 put f_line 0 l 10251 end 10252 10253 note Loop invariants execute at the head, including zero trips and final false condition. 10254 note Continue reaches the checked head (for increments first); break bypasses it. 10255 fn fe_cp_head pos ulong ln ulong to void 10256 if eq get f_om2 0 0 10257 ret 10258 end 10259 p = get f_cur 0 10260 l = get f_line 0 10261 put f_cur 0 pos 10262 put f_line 0 ln 10263 put f_clim 0 get f_nn 0 10264 put f_crkind 0 0 10265 k = fe_cp_next 10266 n = ulong 0 10267 while eq k 3 10268 put f_ckind 0 3 10269 if ge n 64 10270 fe_fail 14 10271 end 10272 fe_cp_eval 10 0 10273 n = add n 1 10274 k = fe_cp_next 10275 end 10276 put f_cur 0 p 10277 put f_line 0 l 10278 end 10279 10280 note Head clauses have already been checked and emitted before the condition, never at body entry. 10281 fn fe_cp_skip to void 10282 if eq get f_om2 0 0 10283 ret 10284 end 10285 p = get f_cur 0 10286 l = get f_line 0 10287 k = fe_cp_next 10288 while eq k 3 10289 fe_skipnl 10290 p = get f_cur 0 10291 l = get f_line 0 10292 k = fe_cp_next 10293 end 10294 put f_cur 0 p 10295 put f_line 0 l 10296 end 10297 10298 note check: the unit in the payload region of the arena (bytes 0 .. n - 1), as omc.om main (@`943d9555` line 10299 note 14676) reads it from stdin. main.om's modes @ng front-check and front-ir read it there (ar_rdin) and 10300 note give every other region its first room (ar_init); a payload the arena cannot hold is error 14 there, as 10301 note in omc (a stdin read error is main.om's exit 27, not omc's 1). Exit or return as omc: 0 accepted, the 10302 note refusal's code after its stderr line; 64 for a unit ng does not take. 10303 fn fe_check n ulong to int 10304 fe_hinit 10305 put f_inlen 0 n 10306 fe_xlead 10307 note ng has no x86 or EFI target (D8): such a unit is outside the front end (exit 64). omc.om main 10308 note (@`943d9555` line 14698) went on to set up the x86 code buffer here. 10309 if gt get f_xtarge 0 0 10310 exit int 64 10311 end 10312 fe_chk_lead 10313 fe_om2lead 10314 if eq get f_om2m 0 2 10315 fe_fmtprep 10316 end 10317 note IR v1 mode (omc.om ir_run, main @`943d9555` line 14704) is not ng's input language: exit 64 10318 if ne fe_ir_lead 0 10319 exit int 64 10320 end 10321 fe_prescan 10322 fe_namescan 10323 put f_line 0 1 10324 put f_lcur0 0 get f_cur 0 10325 done = false 10326 while not done 10327 m = ulong 0 10328 while and not done lt m 999999 10329 if ne fe_stmt 0 10330 done = true 10331 end 10332 m = add m 1 10333 end 10334 end 10335 ret 0 10336 end 10337 10338 10339 10340 note One compile-time ioctl allowlist is shared by both native Linux backends. 10341 fn fe_xhreq c ulong x ulong to ulong 10342 fe_harg x 4 8 10343 fe_harg x 2 4 10344 if ne ar_w 59 add x 12 3 10345 fe_fail 9 10346 end 10347 q = get ar_m add get ar_rb 59 add x 13 10348 n = ulong 4 10349 if eq c 166 10350 if ne q 21531 10351 if ne and q `3221290752` `3221243392` 10352 ok = eq q `2154840336` 10353 ok = or ok eq q `3224387873` 10354 ok = or ok eq q `3222815010` 10355 ok = or ok eq q `3225960739` 10356 ok = or ok eq q `3222815012` 10357 if not ok 10358 fe_fail 9 10359 end 10360 end 10361 n = and shr q 16 16383 10362 if eq n 0 10363 fe_fail 9 10364 end 10365 end 10366 end 10367 if eq c 172 10368 n = ulong 0 10369 if eq q `805306369` 10370 n = ulong 16 10371 end 10372 if eq q 75 10373 n = ulong 8 10374 end 10375 if eq q 37 10376 n = ulong 40 10377 end 10378 if or eq q 38 eq q 26 10379 n = ulong 20 10380 end 10381 if eq q 25 10382 n = ulong 32 10383 end 10384 if eq q 27 10385 n = ulong 56 10386 end 10387 if eq q 28 10388 n = ulong 28 10389 end 10390 if eq q 33 10391 n = ulong 9264 10392 end 10393 if or eq q 34 eq q 73 10394 n = ulong 24 10395 end 10396 if eq n 0 10397 fe_fail 9 10398 end 10399 end 10400 if eq c 171 10401 if and ne q `3223340586` ne q `3223340587` 10402 fe_fail 9 10403 end 10404 n = ulong 32 10405 end 10406 ret n 10407 end 10408 10409 10410 10411 10412 10413 10414 10415 10416 10417 10418 10419 10420 10421 10422 10423 10424 10425 10426 10427 10428 10429 10430 10431 10432 10433 10434 10435 10436 10437 10438 10439 10440 10441 10442 10443 10444 10445 10446 10447 fn fe_xlead to void 10448 note Only the exact bytes "target " at offset zero select a target (x86, or ng's macos). Default parsing is untouched. 10449 if lt get f_inlen 0 8 10450 ret 10451 end 10452 if or ne uchar and shr get ar_m 0 0 255 116 ne uchar and shr get ar_m 0 8 255 97 10453 ret 10454 end 10455 if or ne uchar and shr get ar_m 0 16 255 114 ne uchar and shr get ar_m 0 24 255 103 10456 ret 10457 end 10458 if or ne uchar and shr get ar_m 0 32 255 101 ne uchar and shr get ar_m 0 40 255 116 10459 ret 10460 end 10461 if ne uchar and shr get ar_m 0 48 255 32 10462 ret 10463 end 10464 put f_cur 0 0 10465 put f_line 0 1 10466 fe_tok 10467 fe_tok 10468 if and eq get f_tw 0 `8679965255892613240` eq get f_tl 0 8 10469 put f_xtarge 0 1 10470 else 10471 if and eq get f_tw 0 `115888505632888` eq get f_tl 0 6 10472 put f_xtarge 0 2 10473 else 10474 note `target macos` is ng's own: the unit stays in the front end (f_xtarge 0), with the library words as keywords 10475 if and eq get f_tw 0 `495790023021` eq get f_tl 0 5 10476 put f_mac 0 1 10477 else 10478 fe_fail 25 10479 end 10480 end 10481 end 10482 fe_eol 10483 p = ulong 0 10484 while lt p get f_cur 0 bound `134217729` 10485 if ne ar_ib p 10 10486 ar_bp 0 p 32 10487 end 10488 p = add p 1 10489 end 10490 put f_cur 0 0 10491 put f_line 0 1 10492 end 10493 10494 10495 10496 note ======== x86efi: UEFI 2.10 PE32+ application (docs/X86-EFI.md) ======== 10497 note efi OP ARG A OFF N -> ulong EFI_STATUS or result. OP is a literal 0..14; A is writable uchar 10498 note storage, bounds checked before any firmware call; ARG is never a pointer. Errors are 2^63|code. 10499 note Private state occupies the first 16 KiB of the PE .bss, below the owned 8 MiB stack. Firmware is 10500 note called per UEFI 2.3.4.2: RCX/RDX/R8/R9, 32-byte home area, an 80-byte 16-aligned reservation. 10501 note Language values stay in RBP slots, so integers and floats survive every firmware call. 10502 note Port of the Allen x86efi fork (operations 0..11) onto main's backend; 12, 13 and 14 are new. 10503 10504 10505 10506 10507 10508 10509 note xefival: `efi` as a value. From omc.om xefival (@`943d9555` line 17606): every target but x86 EFI 10510 note refuses it with error 25 before reading anything, and x86 EFI units exit 64 here (D8). 10511 fn fe_xefival dst ulong to void 10512 fe_fail 25 10513 end 10514 10515 10516 10517 10518 10519 10520 10521 10522 10523 10524 10525 10526 note ======== @ng front-ir: lower a unit fe_check accepted to ΩIR (seed/ng/IR.md s13) ======== 10527 note A second walk over the source with the same tokenizer, after fe_check has proved the unit valid, so 10528 note every refusal keeps omc's code and this walk never refuses. Values are SSA: a name holds its current 10529 note value handle; a join block (if merge, loop head, loop latch, break target) takes the token and every 10530 note scalar name in scope as block parameters, and each br passes the current ones. cbr targets take only 10531 note the token and see the dominating values. A construct this walk does not lower exits 64 with 10532 note "ng: front-ir: line N: not lowered" (scope, not a refusal). 10533 note Names: f_lnk 0 scalar (f_lnv its value), 1 local or parameter array (f_lnv its REF), 2 global array 10534 note (f_lnv the IR global), 3 constant (f_lnc its canonical bits), 4 text (f_lnv the IR global, class 1), 10535 note 5 array parameter, sized or unsized (f_lnv its SLICE, f_lnc its access: 0 view, 1 edit). 10536 note f_lnt is the omc type (element type for arrays), f_lnc the length for sized arrays. A hidden loop counter 10537 note has name word 0, which no lookup asks for. 10538 note An array parameter (view or edit) is a REF with access 1: ΩIR v1 has no op that narrows a REF's access, 10539 note and a local array (access 1) is passed to view parameters; the view rule itself is fe_check's error 20. 10540 global f_lnn ulong 1 10541 global f_lntop ulong 1 10542 global f_lfn uint 1 10543 global f_lbk uint 1 10544 global f_ltk uint 1 10545 global f_lcret ulong 1 10546 global f_lrv uint 1 10547 global f_lrt ulong 1 10548 global f_lrk ulong 1 10549 global f_lrb ulong 1 10550 global f_lat ulong 1 10551 global f_lal ulong 1 10552 note block stack: kind (1 if, 2 if after else, 3 while, 4 for), names at open n0, names with the loop's own 10553 note n1, join, head, false or exit block, break join, latch, snapshot base 10554 global f_lsd ulong 1 10555 global f_lsp ulong 1 10556 global f_lah ulong 1 10557 global f_lan ulong 1 10558 global f_lcp ulong 1 10559 global f_lqw ulong 1 10560 global f_lqt ulong 1 10561 global f_lqm ulong 1 10562 global f_lqb ulong 1 10563 global f_lqv uint 1 10564 global f_lqn ulong 1 10565 note Contract lowering state: function prefix, entry name limit, and one evaluated return value. 10566 global f_lcpos ulong 1 10567 global f_lclin ulong 1 10568 global f_lclim ulong 1 10569 global f_lcact ulong 1 10570 global f_lcval uint 1 10571 global f_lctyp ulong 1 10572 note A put evaluates the field index before its value; field bounds are checked after that value. 10573 global f_lfo ulong 1 10574 global f_lfc ulong 1 10575 global f_lfi uint 1 10576 text f_lmsg "ng: front-ir: line : not lowered\n" 10577 10578 note lno: outside what this walk lowers: one stderr line, exit 64 10579 fn fe_lno to void 10580 put f_mc 0 0 10581 for j ulong 19 10582 fe_mputb get f_lmsg j 10583 end 10584 fe_mputn add get f_line 0 get f_lbase 0 10585 for j ulong 14 10586 fe_mputb get f_lmsg add j 19 10587 end 10588 w = write 2 f_msg 0 get f_mc 0 10589 exit int 64 10590 end 10591 10592 note lty: omc type -> ΩIR type id (bool .. long 1..9 unchanged, f32 13, f64 14, void 0) 10593 fn fe_lty t ulong to uint 10594 if ge t 64 10595 ret fe_lty ulong get f_abbase sub t 64 10596 end 10597 if eq t 10 10598 ret 13 10599 end 10600 if eq t 11 10601 ret 14 10602 end 10603 if eq t 12 10604 ret 0 10605 end 10606 note qty (omc type 13) is a u64 whose add, sub and mul trap 1 on any wrap (chk.add/sub/mul, fe_lbop) 10607 if eq t 13 10608 ret 5 10609 end 10610 if or eq t 0 gt t 9 10611 fe_lno 10612 end 10613 ret uint t 10614 end 10615 10616 fn fe_lsg t ulong to bool 10617 ret and ge t 6 le t 9 10618 end 10619 10620 note lcan: canonical const bits of v for type t (IR.md s7.1) 10621 fn fe_lcan t ulong v ulong to ulong 10622 if ne fe_isfloat t 0 10623 ret v 10624 end 10625 w = fe_twid t 10626 if ge w 64 10627 ret v 10628 end 10629 m = sub shl ulong 1 w 1 10630 x = and v m 10631 if fe_lsg t 10632 if ne and shr x sub w 1 1 0 10633 x = or x not m 10634 end 10635 end 10636 ret x 10637 end 10638 10639 note lref: REF (access a, space 0) to ARRAY of n elements of omc type t 10640 fn fe_lref t ulong n ulong a uint to uint 10641 ret ir_tref ir_tarr fe_lty t uint n a 0 10642 end 10643 10644 note lop: op in the current block; operand 0 is the current token when the op carries one, and an E op 10645 note makes its new token current 10646 fn fe_lop op uint ty uint imm ulong n uint to uint 10647 if eq get f_lbk 0 0 10648 fe_lno 10649 end 10650 o = ir_op get f_lbk 0 op ty imm n 10651 if ne ir_htok op 0 10652 ir_set o 0 get f_ltk 0 10653 end 10654 if eq get i_rtk op 1 10655 put f_ltk 0 ir_otok o 10656 end 10657 ret o 10658 end 10659 10660 fn fe_lcst t ulong v ulong to uint 10661 o = fe_lop 1 fe_lty t fe_lcan t v 0 10662 ret ir_res o 10663 end 10664 10665 fn fe_lp1 op uint t ulong imm ulong a uint to uint 10666 o = fe_lop op fe_lty t imm 1 10667 ir_set o 0 a 10668 ret ir_res o 10669 end 10670 10671 fn fe_lp2 op uint t ulong a uint b uint to uint 10672 o = fe_lop op fe_lty t 0 2 10673 ir_set o 0 a 10674 ir_set o 1 b 10675 ret ir_res o 10676 end 10677 10678 fn fe_lck1 op uint code ulong a uint to void 10679 o = fe_lop op 0 code 2 10680 ir_set o 1 a 10681 end 10682 10683 fn fe_lck2 op uint code ulong a uint b uint to void 10684 o = fe_lop op 0 code 3 10685 ir_set o 1 a 10686 ir_set o 2 b 10687 end 10688 10689 note lck3: chk.bounds / chk.slice (trap 3) on r, a, b 10690 fn fe_lck3 op uint r uint a uint b uint to void 10691 o = fe_lop op 0 3 4 10692 ir_set o 1 r 10693 ir_set o 2 a 10694 ir_set o 3 b 10695 end 10696 10697 fn fe_lval v uint t ulong to void 10698 put f_lrv 0 v 10699 put f_lrt 0 t 10700 put f_lrk 0 0 10701 end 10702 10703 note ---- names ---- 10704 note The lowering's names are arena group lnames (f_lnw .. f_lnc, f_lnx the index + 1 before it in its chain) 10705 note with a chained hash, group lnamehash (f_lnh, f_lhb bits): fe_lfind is the newest name in scope with the 10706 note packed word, as the old back-to-front scan gave; every write of f_lnn but fe_ladd's goes through fe_lnm_set. 10707 fn fe_ladd w ulong k ulong t ulong v uint c ulong to void 10708 n = get f_lnn 0 10709 fe_need 18 n 10710 put ar_m add get ar_rb 68 n w 10711 ar_pc 69 n uchar k 10712 put ar_m add get ar_rb 70 n t 10713 ar_pu 71 n v 10714 put ar_m add get ar_rb 72 n c 10715 fe_lnm_link n 10716 put f_lnn 0 add n 1 10717 if ge add n 1 shl ulong 2 get f_lhb 0 10718 put f_lhb 0 add get f_lhb 0 1 10719 fe_need 19 sub shl ulong 1 get f_lhb 0 1 10720 ar_gzero 19 10721 i = ulong 0 10722 while le i n bound `16777217` 10723 fe_lnm_link i 10724 i = add i 1 10725 end 10726 end 10727 end 10728 10729 fn fe_lnm_link i ulong to void 10730 h = ar_hash get ar_m add get ar_rb 68 i get f_lhb 0 10731 put ar_m add get ar_rb 73 i get ar_m add get ar_rb 74 h 10732 put ar_m add get ar_rb 74 h add i 1 10733 end 10734 10735 note lnm_set: the lowering's names in scope become 0 .. v - 1: names above v leave their chains newest first 10736 note (each is the newest of its chain then), names between f_lnn and v join them again in order 10737 fn fe_lnm_set v ulong to void 10738 n = get f_lnn 0 10739 while gt n v bound `16777217` 10740 n = sub n 1 10741 h = ar_hash get ar_m add get ar_rb 68 n get f_lhb 0 10742 put ar_m add get ar_rb 74 h get ar_m add get ar_rb 73 n 10743 end 10744 while lt n v bound `16777217` 10745 fe_lnm_link n 10746 n = add n 1 10747 end 10748 put f_lnn 0 v 10749 end 10750 10751 fn fe_lfind w ulong to ulong 10752 k = get ar_m add get ar_rb 74 ar_hash w get f_lhb 0 10753 while ne k 0 bound `16777217` 10754 if eq ar_w 68 sub k 1 w 10755 if or eq get f_lcact 0 0 lt sub k 1 get f_lclim 0 10756 ret k 10757 end 10758 end 10759 k = get ar_m add get ar_rb 73 sub k 1 10760 end 10761 ret 0 10762 end 10763 10764 note ltyw: a scalar type word (uchar .. long, f32, f64) -> omc type 10765 fn fe_ltyw to ulong 10766 fe_tok 10767 if or ne get f_tk 0 1 gt get f_tl 0 8 10768 fe_lno 10769 end 10770 c = fe_kw get f_tw 0 10771 if eq c 88 10772 ret 10 10773 end 10774 if eq c 89 10775 ret 11 10776 end 10777 if eq c 223 10778 ret 13 10779 end 10780 if or lt c 2 gt c 9 10781 fe_lno 10782 end 10783 ret c 10784 end 10785 10786 note llen: a length, bound or trap code: a number or an integer constant name 10787 fn fe_llen to ulong 10788 fe_tok 10789 if eq get f_tk 0 2 10790 ret get f_tw 0 10791 end 10792 if eq get f_tk 0 1 10793 x = fe_lfind get f_tw 0 10794 if ne x 0 10795 if eq ar_c 69 sub x 1 3 10796 ret get ar_m add get ar_rb 72 sub x 1 10797 end 10798 end 10799 end 10800 fe_lno 10801 ret 0 10802 end 10803 10804 note ---- blocks and joins ---- 10805 note ljoin: a new block taking the token and every scalar name in [0, n0) 10806 fn fe_ljoin n0 ulong to uint 10807 b = ir_blk get f_lfn 0 10808 for i ulong n0 bound `16777217` 10809 if eq ar_c 69 i 0 10810 v = ir_bpar b fe_lty get ar_m add get ar_rb 70 i 10811 end 10812 end 10813 if gt get i_bnp b 64 10814 fe_lno 10815 end 10816 ret b 10817 end 10818 10819 note lbr: br from the current block to b with the token and the scalar names in [0, n0); the path ends 10820 fn fe_lbr b uint n0 ulong to void 10821 m = uint 0 10822 for i ulong n0 bound `16777217` 10823 if eq ar_c 69 i 0 10824 m = add m 1 10825 end 10826 end 10827 o = fe_lop 60 0 0 add m 2 10828 ir_set o 0 b 10829 ir_set o 1 get f_ltk 0 10830 k = uint 2 10831 for i ulong n0 bound `16777217` 10832 if eq ar_c 69 i 0 10833 ir_set o k uint get ar_m add get ar_rb 71 i 10834 k = add k 1 10835 end 10836 end 10837 put f_lbk 0 0 10838 end 10839 10840 note lbind: the scalar names in [0, n0) take b's parameters after its token 10841 fn fe_lbind b uint n0 ulong to void 10842 v = get i_vnx ir_btok b 10843 for i ulong n0 bound `16777217` 10844 if eq ar_c 69 i 0 10845 ar_pu 71 i v 10846 v = get i_vnx v 10847 end 10848 end 10849 end 10850 10851 fn fe_lgo b uint to void 10852 put f_lbk 0 b 10853 put f_ltk 0 ir_btok b 10854 end 10855 10856 fn fe_lenter b uint n0 ulong to void 10857 fe_lgo b 10858 fe_lbind b n0 10859 end 10860 10861 fn fe_lpush n0 ulong to void 10862 p = get f_lsp 0 10863 fe_need 21 add p n0 10864 for i ulong n0 bound `16777217` 10865 ar_pu 84 add p i uint get ar_m add get ar_rb 71 i 10866 end 10867 put f_lsp 0 add p n0 10868 end 10869 10870 fn fe_lrest p ulong n0 ulong to void 10871 for i ulong n0 bound `16777217` 10872 ar_pu 71 i uint get ar_m add get ar_rb 84 add p i 10873 end 10874 end 10875 10876 fn fe_lpshb k ulong n0 ulong n1 ulong h uint x uint to void 10877 d = get f_lsd 0 10878 fe_need 20 d 10879 ar_pc 75 d uchar k 10880 put ar_m add get ar_rb 76 d n0 10881 put ar_m add get ar_rb 77 d n1 10882 ar_pu 79 d h 10883 ar_pu 80 d x 10884 ar_pu 78 d 0 10885 ar_pu 81 d 0 10886 ar_pu 82 d 0 10887 put ar_m add get ar_rb 83 d get f_lsp 0 10888 put f_lsd 0 add d 1 10889 end 10890 10891 fn fe_lgetj d ulong to uint 10892 if eq ar_u 78 d 0 10893 ar_pu 78 d fe_ljoin get ar_m add get ar_rb 76 d 10894 end 10895 ret uint get ar_m add get ar_rb 78 d 10896 end 10897 10898 fn fe_lgete d ulong to uint 10899 if eq ar_u 81 d 0 10900 ar_pu 81 d fe_ljoin get ar_m add get ar_rb 76 d 10901 end 10902 ret uint get ar_m add get ar_rb 81 d 10903 end 10904 10905 fn fe_lgetl d ulong to uint 10906 if eq ar_u 82 d 0 10907 ar_pu 82 d fe_ljoin get ar_m add get ar_rb 77 d 10908 end 10909 ret uint get ar_m add get ar_rb 82 d 10910 end 10911 10912 note lloop: the innermost open loop 10913 fn fe_lloop to ulong 10914 d = get f_lsd 0 10915 while gt d 0 bound `16777217` 10916 d = sub d 1 10917 if ge ar_c 75 d 3 10918 ret d 10919 end 10920 end 10921 fe_lno 10922 ret 0 10923 end 10924 10925 note ---- values: the result is f_lrv (handle), f_lrt (omc type), f_lrk (0 a value, 1 an untyped integer 10926 note literal with bits f_lrb, 2 an untyped float literal with its packed span f_lrb) ---- 10927 fn fe_lfix e ulong to void 10928 if eq e 0 10929 ret 10930 end 10931 k = get f_lrk 0 10932 if eq k 1 10933 fe_lval fe_lcst e get f_lrb 0 e 10934 end 10935 if eq k 2 10936 fe_lval fe_lcst e fe_fspan e get f_lrb 0 e 10937 end 10938 end 10939 10940 fn fe_lx e ulong to void 10941 fe_tok 10942 fe_lxt e 10943 end 10944 10945 note lxt: a value whose first token is read; e the expected type (0 none), which an untyped literal takes 10946 fn fe_lxt e ulong to void 10947 put f_lrk 0 0 10948 k = get f_tk 0 10949 if eq k 2 10950 put f_lrk 0 1 10951 put f_lrb 0 get f_tw 0 10952 put f_lrt 0 0 10953 fe_lfix e 10954 ret 10955 end 10956 if eq k 5 10957 fe_fparse get f_ts 0 get f_tl 0 10958 if eq get f_fsuf 0 0 10959 put f_lrk 0 2 10960 put f_lrb 0 add mul get f_ts 0 `16777216` get f_tl 0 10961 put f_lrt 0 0 10962 fe_lfix e 10963 ret 10964 end 10965 t = ulong 10 10966 if eq get f_fsuf 0 2 10967 t = ulong 11 10968 end 10969 fe_lval fe_lcst t fe_fbits t t 10970 ret 10971 end 10972 if ne k 1 10973 fe_lno 10974 end 10975 if gt get f_tl 0 8 10976 fe_lname1 10977 ret 10978 end 10979 fe_lword e fe_kw get f_tw 0 10980 end 10981 10982 fn fe_lword e ulong c ulong to void 10983 if eq c 95 10984 fe_lsize 10985 ret 10986 end 10987 if eq c 96 10988 fe_loffset 10989 ret 10990 end 10991 if eq c 185 10992 fe_lseal 10993 ret 10994 end 10995 if eq c 186 10996 fe_lx 0 10997 fe_lval get f_lrv 0 ulong get f_abbase sub get f_lrt 0 64 10998 ret 10999 end 11000 if eq c 0 11001 fe_lname1 11002 ret 11003 end 11004 if and ge c 33 le c 48 11005 fe_lbin c 11006 ret 11007 end 11008 if or eq c 59 eq c 60 11009 fe_lbin c 11010 ret 11011 end 11012 if or eq c 91 eq c 92 11013 fe_lx 0 11014 if ne get f_lrk 0 0 11015 fe_lno 11016 end 11017 t = get f_lrt 0 11018 fe_lval fe_lp1 uint add 26 sub c 91 t 0 get f_lrv 0 t 11019 ret 11020 end 11021 if or eq c 93 eq c 94 11022 fe_lfmm c 11023 ret 11024 end 11025 if or eq c 49 eq c 50 11026 fe_lx e 11027 fe_lun c 11028 ret 11029 end 11030 if eq c 51 11031 fe_lget 11032 ret 11033 end 11034 if eq c 52 11035 x = fe_lanm 11036 if eq ar_c 69 x 9 11037 o = fe_lop 112 5 ar_w 71 x 1 11038 fe_lval ir_res o 5 11039 ret 11040 end 11041 if or eq ar_c 69 x 5 eq ar_c 69 x 8 11042 o = fe_lop 53 5 0 1 11043 ir_set o 0 uint get ar_m add get ar_rb 71 x 11044 fe_lval ir_res o 5 11045 ret 11046 end 11047 fe_lval fe_lcst 5 get f_lal 0 5 11048 ret 11049 end 11050 if or eq c 53 eq c 54 11051 fe_lio c 11052 ret 11053 end 11054 if or eq c 55 eq c 56 11055 v = ulong 0 11056 if eq c 55 11057 v = ulong 1 11058 end 11059 fe_lval fe_lcst 1 v 1 11060 ret 11061 end 11062 if or eq c 109 eq c 130 11063 o = fe_lop 110 9 c 1 11064 fe_lval ir_res o 9 11065 ret 11066 end 11067 if ne fe_lhfmt c 0 11068 fe_lhost c 11069 ret 11070 end 11071 if or eq c 88 eq c 89 11072 fe_lfcv c 11073 ret 11074 end 11075 if eq c 223 11076 fe_lqty 11077 ret 11078 end 11079 if le sub c 1 8 11080 fe_licv c 11081 ret 11082 end 11083 if eq c 90 11084 fe_lbc 11085 ret 11086 end 11087 if eq c 74 11088 fe_lx e 11089 fe_tok 11090 ret 11091 end 11092 if eq c 227 11093 fe_lfma 11094 ret 11095 end 11096 fe_lno 11097 end 11098 11099 note Nominal constructors have been checked for scope and allowed operations by fe_check. 11100 note A retained dup32 predicate checks the physical halves, including in release mode as omc does. 11101 fn fe_lseal to void 11102 fe_tok 11103 a = sub fe_findab get f_tw 0 1 11104 t = ulong get f_abbase a 11105 fe_lx t 11106 v = get f_lrv 0 11107 if ne get f_abhold a 0 11108 if eq fe_ab_exact ulong get f_lfn 0 a 0 11109 hi = fe_lp2 21 5 v fe_lcst 5 32 11110 lo = fe_lp2 16 5 v fe_lcst 5 `4294967295` 11111 ok = fe_lp2 30 1 hi lo 11112 fe_lck1 82 10 ok 11113 end 11114 end 11115 fe_lval v add a 64 11116 end 11117 11118 note lfma: fma a b c on three values of one float type (omc ffma refuses an untyped literal, 11, and mixed 11119 note types, 7), rounded once: the ΩIR fma (46, IR.md s7.4), never a mul then an add 11120 fn fe_lfma to void 11121 fe_lx 0 11122 t = get f_lrt 0 11123 fa = fe_lfop t 11124 fe_lx 0 11125 fb = fe_lfop t 11126 fe_lx 0 11127 fc = fe_lfop t 11128 o = fe_lop 46 fe_lty t 0 3 11129 ir_set o 0 fa 11130 ir_set o 1 fb 11131 ir_set o 2 fc 11132 fe_lval ir_res o t 11133 end 11134 11135 note lfop: the current value as an fma operand of float type t; anything else is not lowered 11136 fn fe_lfop t ulong to uint 11137 if ne get f_lrk 0 0 11138 fe_lno 11139 end 11140 if or ne get f_lrt 0 t eq fe_isfloat t 0 11141 fe_lno 11142 end 11143 ret get f_lrv 0 11144 end 11145 11146 note lname1: a short name as a value: a scalar, a constant, or a call 11147 fn fe_lname1 to void 11148 w = get f_tw 0 11149 if and ne get f_lcact 0 0 eq w `128009175786866` 11150 if eq get f_lctyp 0 12 11151 fe_lno 11152 end 11153 fe_lval get f_lcval 0 get f_lctyp 0 11154 ret 11155 end 11156 x = fe_lfind w 11157 if ne x 0 11158 i = sub x 1 11159 k = uchar get ar_m add get ar_rb 69 i 11160 if eq k 0 11161 fe_lval ar_u 71 i get ar_m add get ar_rb 70 i 11162 ret 11163 end 11164 if eq k 3 11165 fe_lval fe_lcst get ar_m add get ar_rb 70 i get ar_m add get ar_rb 72 i get ar_m add get ar_rb 70 i 11166 ret 11167 end 11168 fe_lno 11169 end 11170 fe_lcall fe_findfn w 0 0 11171 end 11172 11173 fn fe_lun c ulong to void 11174 t = get f_lrt 0 11175 a = get f_lrv 0 11176 if ne get f_lrk 0 0 11177 fe_lno 11178 end 11179 if eq c 50 11180 fe_lval fe_lp1 19 t 0 a t 11181 ret 11182 end 11183 if fe_lsg t 11184 fe_lck1 73 1 a 11185 end 11186 fe_lval fe_lp1 15 t 0 a t 11187 end 11188 11189 fn fe_llit t ulong k ulong b ulong to uint 11190 if eq k 1 11191 ret fe_lcst t b 11192 end 11193 ret fe_lcst t fe_fspan t b 11194 end 11195 11196 fn fe_lbin c ulong to void 11197 fe_lx 0 11198 ak = get f_lrk 0 11199 av = get f_lrv 0 11200 aty = get f_lrt 0 11201 ab = get f_lrb 0 11202 fe_lx 0 11203 bk = get f_lrk 0 11204 bv = get f_lrv 0 11205 bt = get f_lrt 0 11206 if ge aty 64 11207 t = ulong get f_abbase sub aty 64 11208 if ne bk 0 11209 bv = fe_llit t bk get f_lrb 0 11210 end 11211 fe_lbop c t av bv 11212 put f_lrt 0 aty 11213 ret 11214 end 11215 if ne ak 0 11216 aty = bt 11217 av = fe_llit aty ak ab 11218 end 11219 if ne bk 0 11220 bt = aty 11221 bv = fe_llit bt bk get f_lrb 0 11222 end 11223 if ne aty bt 11224 if not fe_lshx c aty bt 11225 fe_lno 11226 end 11227 bv = fe_lsham aty bt bv 11228 end 11229 fe_lbop c aty av bv 11230 end 11231 11232 note lfmm: fmin 93 / fmax 94 as IR min 24 / max 25 (IR.md s7.3: OMEGESE FMINNM/FMAXNM; one quiet NaN gives the 11233 note other operand, a signaling NaN gives that NaN quieted, -0 below +0). omc requires two typed values of one 11234 note float type (an untyped literal is error 11, mixed types error 7: the check pass refused those already). 11235 fn fe_lfmm c ulong to void 11236 fe_lx 0 11237 if ne get f_lrk 0 0 11238 fe_lno 11239 end 11240 t = get f_lrt 0 11241 a = get f_lrv 0 11242 fe_lx 0 11243 if ne get f_lrk 0 0 11244 fe_lno 11245 end 11246 if or ne get f_lrt 0 t eq fe_isfloat t 0 11247 fe_lno 11248 end 11249 fe_lval fe_lp2 uint add 24 sub c 93 t a get f_lrv 0 t 11250 end 11251 11252 note lshx: shl (41) or shr (42) on an integer value and an integer or qty amount of another type. omc admits 11253 note only a shift with mixed operand types (rdval's type check skips c 41, 42); a qty amount is a u64 (a qty 11254 note value is error 7 in omc, never here); a bool or float amount, which omc also admits, and a mixed rotate 11255 note (omc error 7) stay not lowered. 11256 fn fe_lshx c ulong a ulong b ulong to bool 11257 if and ne c 41 ne c 42 11258 ret false 11259 end 11260 ret and and ge a 2 le a 9 or and ge b 2 le b 9 eq b 13 11261 end 11262 11263 note lsham: the amount v (integer type b) of a shift of an integer value of type a, as a value of type a. 11264 note omc tests the amount's 64-bit register, sign- or zero-extended by b, against a's width, unsigned 11265 note (bo_schk: CMP Xb, #w; B.HS trap 7), so a negative amount traps 7 like one at or past the width and a 11266 note wide one is never wrapped. Here: conv to u64 (int to int keeps that extension, IR.md s7.3), lt w, 11267 note chk.true 7, then conv to a, exact because the amount is now below w. fe_lbop then checks as before. 11268 fn fe_lsham a ulong b ulong v uint to uint 11269 u = v 11270 if and ne b 5 ne b 13 11271 u = fe_lp1 36 5 0 v 11272 end 11273 k = fe_lp2 32 1 u fe_lcst 5 fe_twid a 11274 fe_lck1 82 7 k 11275 if eq a 5 11276 ret u 11277 end 11278 ret fe_lp1 36 a 0 u 11279 end 11280 11281 note lbop: binary op c (add 33 .. ge 48, rotr 59, rotl 60) on a and b of omc type t, with the checks of 11282 note IR.md s13; a rotate checks its amount like a shift (omc.om rotate: trap 7 at or past the width) 11283 fn fe_lbop c ulong t ulong a uint b uint to void 11284 s = fe_lsg t 11285 if ge c 59 11286 if s 11287 fe_lno 11288 end 11289 fe_lck1 77 7 b 11290 fe_lval fe_lp2 uint sub 82 c t a b t 11291 ret 11292 end 11293 if ge c 43 11294 fe_lval fe_lp2 uint add sub c 43 30 1 a b 1 11295 ret 11296 end 11297 if le c 35 11298 if or s eq t 13 11299 fe_lck2 uint add sub c 33 70 1 a b 11300 end 11301 fe_lval fe_lp2 uint add sub c 33 10 t a b t 11302 ret 11303 end 11304 if le c 37 11305 if eq fe_isfloat t 0 11306 fe_lck1 74 2 b 11307 if and s eq c 36 11308 fe_lck2 75 1 a b 11309 end 11310 end 11311 fe_lval fe_lp2 uint add sub c 36 13 t a b t 11312 ret 11313 end 11314 if le c 40 11315 fe_lval fe_lp2 uint add sub c 38 16 t a b t 11316 ret 11317 end 11318 fe_lck1 77 7 b 11319 if and s eq c 41 11320 fe_lck2 76 1 a b 11321 end 11322 fe_lval fe_lp2 uint add sub c 41 20 t a b t 11323 end 11324 11325 note lanm: an array name token -> its name index; f_lat its element type, f_lal its length (a slice's: its 11326 note access); lanm0 the same for the token already read 11327 fn fe_lanm to ulong 11328 fe_tok 11329 ret fe_lanm0 11330 end 11331 fn fe_lanm0 to ulong 11332 if ne get f_tk 0 1 11333 fe_lno 11334 end 11335 x = fe_lfind get f_tw 0 11336 if eq x 0 11337 fe_lno 11338 end 11339 i = sub x 1 11340 k = uchar get ar_m add get ar_rb 69 i 11341 if or eq k 0 eq k 3 11342 fe_lno 11343 end 11344 put f_lat 0 get ar_m add get ar_rb 70 i 11345 put f_lal 0 get ar_m add get ar_rb 72 i 11346 ret i 11347 end 11348 11349 note laref: an array name token -> its REF value (a global's from gaddr) or its SLICE (an unsized 11350 note parameter, or an empty text sliced to 0 bytes from its 1-byte backing global); laref0 for index i 11351 fn fe_laref to uint 11352 ret fe_laref0 fe_lanm 11353 end 11354 fn fe_laref0 i ulong to uint 11355 k = uchar get ar_m add get ar_rb 69 i 11356 if eq k 9 11357 fe_lno 11358 end 11359 if or or eq k 1 eq k 5 or or eq k 6 eq k 7 eq k 8 11360 ret uint get ar_m add get ar_rb 71 i 11361 end 11362 a = uint 1 11363 if eq k 4 11364 a = uint 0 11365 if eq ar_w 72 i 0 11366 r = ir_res fe_lop 52 fe_lref 2 1 0 ulong uint get ar_m add get ar_rb 71 i 0 11367 z = fe_lcst 5 0 11368 fe_lck3 80 r z z 11369 s = fe_lop 54 ir_tslc 2 0 0 0 4 11370 ir_set s 1 r 11371 ir_set s 2 z 11372 ir_set s 3 z 11373 ret ir_res s 11374 end 11375 end 11376 o = fe_lop 52 fe_lref get ar_m add get ar_rb 70 i get ar_m add get ar_rb 72 i a ulong uint get ar_m add get ar_rb 71 i 0 11377 ret ir_res o 11378 end 11379 11380 note lkw0: the keyword id of the token already read (0 for anything but a keyword) 11381 fn fe_lkw0 to ulong 11382 if or ne get f_tk 0 1 gt get f_tl 0 8 11383 ret 0 11384 end 11385 ret fe_kw get f_tw 0 11386 end 11387 11388 note larg: the array argument for parameter slot q: [view | edit] NAME, or [view | edit] part NAME o k for 11389 note an unsized parameter (omc.om arrarg, arrpart). Every array parameter, sized or not, takes a SLICE of its 11390 note own access: the name's slice when that access is the same, else `slice` over the whole array or over the 11391 note part (so a text passes to a sized view parameter; fe_check already matched a sized parameter's length) 11392 fn fe_larg q ulong to uint 11393 fe_tok 11394 c = fe_lkw0 11395 if or eq c 57 eq c 58 11396 fe_tok 11397 c = fe_lkw0 11398 end 11399 pl = get ar_m add get ar_rb 34 q 11400 if ge ar_c 35 q 6 11401 i = fe_lanm0 11402 r = fe_laref0 i 11403 if and eq ar_c 69 i 7 eq ar_w 72 i ulong sub ar_c 35 q 6 11404 ret r 11405 end 11406 ret fe_lslc q r fe_lcst 5 0 fe_lcst 5 ulong get f_stcell sub ar_w 70 i 16 11407 end 11408 if eq c 193 11409 if ne pl 0 11410 fe_lno 11411 end 11412 r = fe_laref 11413 fe_lx 5 11414 off = fe_lidx 11415 fe_lx 5 11416 ret fe_lslc q r off fe_lidx 11417 end 11418 i = fe_lanm0 11419 r = fe_laref0 i 11420 k = ar_c 69 i 11421 a = ulong 0 11422 if eq ar_c 35 q 3 11423 a = ulong 1 11424 end 11425 if and or eq k 5 eq k 8 eq ar_w 72 i a 11426 ret r 11427 end 11428 if and eq k 4 eq ar_w 72 i 0 11429 if eq a 0 11430 ret r 11431 end 11432 end 11433 n = uint 0 11434 if or eq k 5 eq k 8 11435 o = fe_lop 53 5 0 1 11436 ir_set o 0 r 11437 n = ir_res o 11438 else 11439 n = fe_lcst 5 get ar_m add get ar_rb 72 i 11440 end 11441 ret fe_lslc q r fe_lcst 5 0 n 11442 end 11443 11444 note lslc: the SLICE r[off, off + n) for parameter slot q (its element type and access), after chk.slice 11445 note (trap 3: omc.om arrpart's two checks, off <= len and n <= len - off, in one) 11446 fn fe_lslc q ulong r uint off uint n uint to uint 11447 fe_lck3 80 r off n 11448 a = uint 0 11449 if or eq ar_c 35 q 3 eq ar_c 35 q 7 11450 a = uint 1 11451 end 11452 t = uint 5 11453 if lt ar_c 35 q 6 11454 t = fe_lty ulong ar_c 33 q 11455 end 11456 o = fe_lop 54 ir_tslc t a 0 0 4 11457 ir_set o 1 r 11458 ir_set o 2 off 11459 ir_set o 3 n 11460 ret ir_res o 11461 end 11462 11463 note lidx: the current value as a u64 index (a narrower or signed one converted; a negative one then fails 11464 note the bounds check, as omc's unsigned compare) 11465 fn fe_lidx to uint 11466 t = get f_lrt 0 11467 v = get f_lrv 0 11468 if or eq t 5 eq t 13 11469 ret v 11470 end 11471 if or eq t 1 ge t 10 11472 fe_lno 11473 end 11474 ret fe_lp1 36 5 0 v 11475 end 11476 11477 fn fe_lget to void 11478 ni = fe_lanm 11479 if eq ar_c 69 ni 9 11480 fe_lpoolget ni 11481 ret 11482 end 11483 if eq ar_c 69 ni 8 11484 if fe_llyget ni 11485 ret 11486 end 11487 put f_lat 0 2 11488 else 11489 if ge ar_c 69 ni 6 11490 fe_lstget ni 11491 ret 11492 end 11493 end 11494 r = fe_laref0 ni 11495 t = get f_lat 0 11496 fe_lx 5 11497 i = fe_lidx 11498 fe_lck3 79 r i fe_lcst 5 1 11499 o = fe_lop 42 fe_lty t 0 3 11500 ir_set o 1 r 11501 ir_set o 2 i 11502 fe_lval ir_res o t 11503 end 11504 11505 note lio: read / write fd A off n: chk.slice on (A, off, n), then host (IR.md s7.11) 11506 fn fe_lio c ulong to void 11507 fe_lx 8 11508 fd = get f_lrv 0 11509 ni = fe_lanm 11510 if eq ar_c 69 ni 9 11511 fe_lpoolio c fd ni 11512 ret 11513 end 11514 r = fe_laref0 ni 11515 fe_lx 5 11516 off = get f_lrv 0 11517 fe_lx 5 11518 n = get f_lrv 0 11519 fe_lck3 80 r off n 11520 o = fe_lop 110 9 c 5 11521 ir_set o 1 fd 11522 ir_set o 2 r 11523 ir_set o 3 off 11524 ir_set o 4 n 11525 fe_lval ir_res o 9 11526 end 11527 11528 note lhfmt: the source argument letters of host word c (seed/ng/hostwords.tsv `args`, IR.md s7.11), one 11529 note byte each from the low end, then a 1 byte above the last (1 for no argument); 0 for a word lowered 11530 note elsewhere (read, write, monons, realns: above; cpufence, cpurelax: statements) or not a host word. 11531 note Generated from hostwords.tsv; ngcheck checks every lowered host op against the same table. 11532 fn fe_lhfmt c ulong to ulong 11533 if eq c 241 11534 ret 361 11535 end 11536 if eq c 242 11537 ret 375 11538 end 11539 if eq c 243 11540 ret 96076 11541 end 11542 if eq c 100 11543 ret 361 11544 end 11545 if eq c 101 11546 ret 361 11547 end 11548 if eq c 102 11549 ret 92521 11550 end 11551 if eq c 103 11552 ret `23686249` 11553 end 11554 if eq c 104 11555 ret `23685481` 11556 end 11557 if eq c 105 11558 ret 92521 11559 end 11560 if eq c 106 11561 ret 92521 11562 end 11563 if eq c 107 11564 ret 1 11565 end 11566 if eq c 108 11567 ret `23685481` 11568 end 11569 if eq c 110 11570 ret `23685490` 11571 end 11572 if eq c 111 11573 ret 370 11574 end 11575 if eq c 112 11576 ret 92530 11577 end 11578 if eq c 113 11579 ret 96105 11580 end 11581 if eq c 114 11582 ret 94825 11583 end 11584 if eq c 115 11585 ret 94825 11586 end 11587 if eq c 116 11588 ret `23689065` 11589 end 11590 if eq c 117 11591 ret 96105 11592 end 11593 if eq c 118 11594 ret `23689065` 11595 end 11596 if eq c 119 11597 ret `23687785` 11598 end 11599 if eq c 120 11600 ret 364 11601 end 11602 if eq c 121 11603 ret 1 11604 end 11605 if eq c 122 11606 ret 96076 11607 end 11608 if eq c 123 11609 ret `23882089` 11610 end 11611 if eq c 124 11612 ret 370 11613 end 11614 if eq c 125 11615 ret 92530 11616 end 11617 if eq c 126 11618 ret 370 11619 end 11620 if eq c 127 11621 ret 92521 11622 end 11623 if eq c 128 11624 ret 92535 11625 end 11626 if eq c 129 11627 ret 1 11628 end 11629 if eq c 131 11630 ret 96105 11631 end 11632 if eq c 132 11633 ret 375 11634 end 11635 if eq c 133 11636 ret 96114 11637 end 11638 if eq c 134 11639 ret `6214478185` 11640 end 11641 if eq c 135 11642 ret 92535 11643 end 11644 if eq c 136 11645 ret 1 11646 end 11647 if eq c 137 11648 ret 96076 11649 end 11650 if eq c 138 11651 ret 370 11652 end 11653 if eq c 139 11654 ret 93289 11655 end 11656 if eq c 140 11657 ret 96114 11658 end 11659 if eq c 141 11660 ret 370 11661 end 11662 if eq c 142 11663 ret 370 11664 end 11665 if eq c 143 11666 ret 92530 11667 end 11668 if eq c 144 11669 ret 92530 11670 end 11671 if eq c 145 11672 ret 1 11673 end 11674 if eq c 146 11675 ret 1 11676 end 11677 if eq c 147 11678 ret 1 11679 end 11680 if eq c 148 11681 ret 1 11682 end 11683 if eq c 149 11684 ret 96114 11685 end 11686 if eq c 150 11687 ret 93298 11688 end 11689 if eq c 151 11690 ret `23685490` 11691 end 11692 if eq c 153 11693 ret 361 11694 end 11695 if eq c 154 11696 ret 1 11697 end 11698 if eq c 155 11699 ret 361 11700 end 11701 if eq c 156 11702 ret 361 11703 end 11704 if eq c 157 11705 ret 92530 11706 end 11707 if eq c 158 11708 ret 1 11709 end 11710 if eq c 159 11711 ret 361 11712 end 11713 if eq c 160 11714 ret 92521 11715 end 11716 if eq c 161 11717 ret `23885673` 11718 end 11719 if eq c 162 11720 ret `23884393` 11721 end 11722 if eq c 163 11723 ret 361 11724 end 11725 if eq c 164 11726 ret 361 11727 end 11728 if eq c 165 11729 ret 92521 11730 end 11731 if eq c 166 11732 ret `24606057` 11733 end 11734 if eq c 167 11735 ret `1552249801833` 11736 end 11737 if eq c 168 11738 ret 364 11739 end 11740 if eq c 169 11741 ret `24595564` 11742 end 11743 if eq c 170 11744 ret `24267884` 11745 end 11746 if eq c 171 11747 ret `6299284841` 11748 end 11749 if eq c 172 11750 ret `24606057` 11751 end 11752 if eq c 173 11753 ret 364 11754 end 11755 if eq c 174 11756 ret `23678060` 11757 end 11758 if eq c 175 11759 ret `5576936556` 11760 end 11761 if eq c 176 11762 ret 85068 11763 end 11764 if eq c 177 11765 ret `6061582700` 11766 end 11767 if eq c 197 11768 ret 92521 11769 end 11770 if eq c 198 11771 ret 370 11772 end 11773 if eq c 220 11774 ret 96105 11775 end 11776 if eq c 221 11777 ret 93303 11778 end 11779 if eq c 222 11780 ret `23687785` 11781 end 11782 if eq c 224 11783 ret 96105 11784 end 11785 if eq c 228 11786 ret `22246761` 11787 end 11788 if eq c 229 11789 ret 94825 11790 end 11791 if eq c 230 11792 ret 94825 11793 end 11794 if eq c 231 11795 ret 373 11796 end 11797 if eq c 232 11798 ret `24606057` 11799 end 11800 if eq c 233 11801 ret 94834 11802 end 11803 if eq c 235 11804 ret `24602985` 11805 end 11806 if eq c 236 11807 ret 94825 11808 end 11809 if eq c 237 11810 ret 96105 11811 end 11812 if eq c 238 11813 ret 1 11814 end 11815 if eq c 239 11816 ret `23685481` 11817 end 11818 if eq c 240 11819 ret 92521 11820 end 11821 ret 0 11822 end 11823 11824 note lhost: host word c as a value: each argument in source order (i int, l long, L ulong, u uint from a 11825 note constant, r w S a byte array name, then off and n as ulong with chk.slice on the three, as omc checks 11826 note each slice where it is read), then `host` with ty i64; mapaddr and mapget give omc's ulong 11827 note (conv of the same bits). Operands wait on the call-argument stack so a nested host value is safe. 11828 fn fe_lhost c ulong to void 11829 f = fe_lhfmt c 11830 bs = get f_lcp 0 11831 fe_need 23 add bs 16 11832 put f_lcp 0 add bs 16 11833 na = ulong 0 11834 while gt f 1 bound 8 11835 ch = and f 255 11836 f = shr f 8 11837 if or or eq ch 114 eq ch 119 eq ch 83 11838 ar = fe_laref 11839 fe_lx 5 11840 ao = get f_lrv 0 11841 fe_lx 5 11842 an = get f_lrv 0 11843 fe_lck3 80 ar ao an 11844 ar_pu 86 add bs na ar 11845 ar_pu 86 add add bs na 1 ao 11846 ar_pu 86 add add bs na 2 an 11847 na = add na 3 11848 else 11849 t = ulong 8 11850 if eq ch 108 11851 t = ulong 9 11852 end 11853 if eq ch 76 11854 t = ulong 5 11855 end 11856 if eq ch 117 11857 t = ulong 4 11858 end 11859 fe_lx t 11860 ar_pu 86 add bs na get f_lrv 0 11861 na = add na 1 11862 end 11863 end 11864 o = fe_lop 110 9 c uint add na 1 11865 for j ulong na bound 16 11866 ir_set o uint add j 1 ar_u 86 add bs j 11867 end 11868 put f_lcp 0 bs 11869 v = ir_res o 11870 if or eq c 173 eq c 174 11871 fe_lval fe_lp1 36 5 0 v 5 11872 ret 11873 end 11874 fe_lval v 9 11875 end 11876 11877 note lcf: only integer-to-integer conversions can trap 5. Float-to-integer conv truncates, 11878 note saturates to the destination range and maps NaN to zero (IR.md s7.3; omc fp_toint). 11879 fn fe_lcf s ulong d ulong to bool 11880 if ne fe_isfloat s 0 11881 ret false 11882 end 11883 ws = fe_twid s 11884 wd = fe_twid d 11885 a = fe_lsg s 11886 b = fe_lsg d 11887 if and a not b 11888 ret true 11889 end 11890 if and not a b 11891 ret le wd ws 11892 end 11893 ret lt wd ws 11894 end 11895 11896 note lcv: the current value converted to omc type dt (chk.conv when it can fail, then conv) 11897 fn fe_lcv dt ulong to void 11898 st = get f_lrt 0 11899 v = get f_lrv 0 11900 if eq st dt 11901 ret 11902 end 11903 if or eq st 1 eq dt 1 11904 fe_lno 11905 end 11906 note qty and ulong are both u64 in ΩIR: the conversion keeps the value (omc: no check either way) 11907 if or eq st 13 eq dt 13 11908 if and eq fe_isfloat st 0 eq fe_lty st fe_lty dt 11909 fe_lval v dt 11910 ret 11911 end 11912 end 11913 if eq fe_isfloat dt 0 11914 if fe_lcf st dt 11915 o = fe_lop 78 fe_lty dt 5 2 11916 ir_set o 1 v 11917 end 11918 end 11919 fe_lval fe_lp1 36 dt 0 v dt 11920 end 11921 11922 fn fe_licv c ulong to void 11923 fe_tok 11924 if eq get f_tk 0 2 11925 fe_lval fe_lcst c get f_tw 0 c 11926 ret 11927 end 11928 fe_lxt 0 11929 if ne get f_lrk 0 0 11930 fe_lno 11931 end 11932 fe_lcv c 11933 end 11934 11935 note lqty: qty V (keyword 223) as fe_licv with omc type 13: a literal is a qty constant; a signed value is 11936 note checked (chk.conv u64, trap 5 when negative), an unsigned one kept 11937 fn fe_lqty to void 11938 fe_tok 11939 if eq get f_tk 0 2 11940 fe_lval fe_lcst 13 get f_tw 0 13 11941 ret 11942 end 11943 fe_lxt 0 11944 if ne get f_lrk 0 0 11945 fe_lno 11946 end 11947 fe_lcv 13 11948 end 11949 11950 note lfcv: f32 v / f64 v; an untyped integer literal is a long first, as fe_rdval 11951 fn fe_lfcv c ulong to void 11952 t = ulong 10 11953 if eq c 89 11954 t = ulong 11 11955 end 11956 fe_lx 0 11957 k = get f_lrk 0 11958 if eq k 2 11959 fe_lval fe_lcst t fe_fspan t get f_lrb 0 t 11960 ret 11961 end 11962 if eq k 1 11963 fe_lval fe_lcst 9 get f_lrb 0 9 11964 end 11965 fe_lcv t 11966 end 11967 11968 fn fe_lbc to void 11969 tt = fe_ltyw 11970 fe_lx 0 11971 if ne get f_lrk 0 0 11972 fe_lno 11973 end 11974 if ne get f_lrt 0 tt 11975 fe_lval fe_lp1 37 tt 0 get f_lrv 0 tt 11976 end 11977 end 11978 11979 note lcall: call of function f (index + 1 = its ΩIR handle); the arguments are read first 11980 fn fe_lcall f ulong to void 11981 if eq f 0 11982 fe_lno 11983 end 11984 j = sub f 1 11985 np = ulong uchar get ar_m add get ar_rb 22 j 11986 bs = get f_lcp 0 11987 fe_need 23 add bs np 11988 put f_lcp 0 add bs np 11989 for p ulong np bound 6 11990 q = add mul j 6 p 11991 if eq ar_c 35 q 0 11992 fe_lx ulong uchar get ar_m add get ar_rb 33 q 11993 ar_pu 86 add bs p get f_lrv 0 11994 else 11995 ar_pu 86 add bs p fe_larg q 11996 end 11997 end 11998 rt = ulong uchar get ar_m add get ar_rb 21 j 11999 o = fe_lop 64 fe_lty rt 0 uint add np 2 12000 ir_set o 1 uint f 12001 for p ulong np bound 6 12002 ir_set o uint add p 2 ar_u 86 add bs p 12003 end 12004 put f_lcp 0 bs 12005 fe_lval ir_res o rt 12006 end 12007 12008 note Structs preserve omc's eight-byte cells using ulong backing storage, including array fields. 12009 fn fe_lsize to void 12010 sid = fe_peek_struct 12011 if ne sid 0 12012 fe_lval fe_lcst 5 mul ulong get f_stcell sub sid 1 8 5 12013 ret 12014 end 12015 t = fe_typeword 12016 fe_lval fe_lcst 5 shl ulong 1 fe_tlog t 5 12017 end 12018 fn fe_loffset to void 12019 fe_tok 12020 sid = sub fe_findstruct get f_tw 0 1 12021 fe_tok 12022 f = sub fe_findfield sid get f_tw 0 1 12023 fe_lval fe_lcst 5 mul ulong get f_sf_off f 8 5 12024 end 12025 fn fe_lstbits t ulong v uint to uint 12026 if eq t 1 12027 y = fe_lcst 5 1 12028 n = fe_lcst 5 0 12029 o = fe_lop 2 5 0 3 12030 ir_set o 0 v 12031 ir_set o 1 y 12032 ir_set o 2 n 12033 ret ir_res o 12034 end 12035 if eq t 11 12036 ret fe_lp1 37 5 0 v 12037 end 12038 if eq t 10 12039 ret fe_lp1 36 5 0 fe_lp1 37 4 0 v 12040 end 12041 if eq t 5 12042 ret v 12043 end 12044 ret fe_lp1 36 5 0 v 12045 end 12046 fn fe_lstval t ulong v uint to uint 12047 if eq t 1 12048 ret fe_lp2 31 1 v fe_lcst 5 0 12049 end 12050 if eq t 11 12051 ret fe_lp1 37 11 0 v 12052 end 12053 if eq t 10 12054 ret fe_lp1 37 10 0 fe_lp1 36 4 0 v 12055 end 12056 if eq t 5 12057 ret v 12058 end 12059 ret fe_lp1 36 t 0 v 12060 end 12061 fn fe_lstnew w ulong si ulong to void 12062 h = get f_lah 0 12063 if ge h get f_lan 0 12064 fe_lno 12065 end 12066 r = ar_u 85 h 12067 put f_lah 0 add h 1 12068 for j ulong ulong get f_st_nf si 12069 f = add ulong get f_stfoff si j 12070 fe_lstinit r f 12071 end 12072 fe_ladd w 6 add si 16 r ulong get f_stcell si 12073 end 12074 fn fe_lstinit r uint f ulong to void 12075 t = ulong get f_sftype f 12076 fe_lx t 12077 v = fe_lstbits t get f_lrv 0 12078 n = ulong get f_sf_len f 12079 if eq n 0 12080 n = ulong 1 12081 end 12082 for k ulong n 12083 ix = fe_lcst 5 add ulong get f_sf_off f k 12084 fe_lck3 79 r ix fe_lcst 5 1 12085 o = fe_lop 43 0 0 4 12086 ir_set o 1 r 12087 ir_set o 2 ix 12088 ir_set o 3 v 12089 end 12090 end 12091 fn fe_lstfield i ulong to void 12092 si = sub ar_w 70 i 16 12093 fe_tok 12094 f = sub fe_findfield si get f_tw 0 1 12095 ix = fe_lcst 5 0 12096 if ne get f_sf_len f 0 12097 fe_lx 5 12098 ix = fe_lidx 12099 end 12100 put f_lat 0 ulong get f_sftype f 12101 put f_lfo 0 ulong get f_sf_off f 12102 put f_lfc 0 ulong get f_sf_len f 12103 put f_lfi 0 ix 12104 end 12105 fn fe_lstindex ix uint off ulong cnt ulong to uint 12106 if ne cnt 0 12107 fe_lck1 82 3 fe_lp2 32 1 ix fe_lcst 5 cnt 12108 end 12109 ret fe_lp2 10 5 ix fe_lcst 5 off 12110 end 12111 fn fe_lstget i ulong to void 12112 r = fe_laref0 i 12113 fe_lstfield i 12114 t = get f_lat 0 12115 ix = fe_lstindex get f_lfi 0 get f_lfo 0 get f_lfc 0 12116 fe_lck3 79 r ix fe_lcst 5 1 12117 o = fe_lop 42 5 0 3 12118 ir_set o 1 r 12119 ir_set o 2 ix 12120 fe_lval fe_lstval t ir_res o t 12121 end 12122 fn fe_lstput i ulong to void 12123 r = fe_laref0 i 12124 fe_lstfield i 12125 t = get f_lat 0 12126 ix = get f_lfi 0 12127 off = get f_lfo 0 12128 cnt = get f_lfc 0 12129 fe_lx t 12130 v = fe_lstbits t get f_lrv 0 12131 ix = fe_lstindex ix off cnt 12132 fe_lck3 79 r ix fe_lcst 5 1 12133 o = fe_lop 43 0 0 4 12134 ir_set o 1 r 12135 ir_set o 2 ix 12136 ir_set o 3 v 12137 fe_eol 12138 end 12139 12140 note Layout parameters remain uchar slices. Fields assemble bytes in their declared order. 12141 note A field lookup that misses rewinds: ordinary raw byte indexing still works on a layout parameter. 12142 fn fe_llyfield i ulong to ulong 12143 p = get f_cur 0 12144 l = get f_line 0 12145 fe_tok 12146 f = fe_findlf sub ar_w 70 i 128 get f_tw 0 12147 if eq f 0 12148 put f_cur 0 p 12149 put f_line 0 l 12150 ret 0 12151 end 12152 j = sub f 1 12153 ix = fe_lcst 5 0 12154 if ne get f_lf_cnt j 0 12155 fe_lx 5 12156 ix = fe_lidx 12157 end 12158 put f_lfi 0 ix 12159 ret f 12160 end 12161 fn fe_llyindex f ulong ix uint to uint 12162 cnt = get f_lf_cnt f 12163 if ne cnt 0 12164 fe_lck1 82 3 fe_lp2 32 1 ix fe_lcst 5 cnt 12165 end 12166 n = shl ulong 1 fe_tlog ulong get f_lftype f 12167 v = fe_lp2 12 5 ix fe_lcst 5 n 12168 ret fe_lp2 10 5 v fe_lcst 5 get f_lf_off f 12169 end 12170 fn fe_llyget i ulong to bool 12171 f = fe_llyfield i 12172 if eq f 0 12173 ret false 12174 end 12175 f = sub f 1 12176 r = fe_laref0 i 12177 ix = fe_llyindex f get f_lfi 0 12178 t = ulong get f_lftype f 12179 n = shl ulong 1 fe_tlog t 12180 fe_lck3 79 r ix fe_lcst 5 n 12181 v = fe_lcst 5 0 12182 for j ulong n 12183 v = fe_llybyte r ix f j v 12184 end 12185 fe_lval fe_lstval t v t 12186 ret true 12187 end 12188 fn fe_llybyte r uint ix uint f ulong j ulong v uint to uint 12189 atp = fe_lp2 10 5 ix fe_lcst 5 j 12190 fe_lck3 79 r atp fe_lcst 5 1 12191 o = fe_lop 42 2 0 3 12192 ir_set o 1 r 12193 ir_set o 2 atp 12194 b = fe_lp1 36 5 0 ir_res o 12195 k = j 12196 if ne get f_lf_big f 0 12197 n = shl ulong 1 fe_tlog ulong get f_lftype f 12198 k = sub sub n 1 j 12199 end 12200 b = fe_lp2 20 5 b fe_lcst 5 mul k 8 12201 ret fe_lp2 17 5 v b 12202 end 12203 fn fe_llyput i ulong to bool 12204 f = fe_llyfield i 12205 if eq f 0 12206 ret false 12207 end 12208 f = sub f 1 12209 ix = get f_lfi 0 12210 t = ulong get f_lftype f 12211 fe_lx t 12212 v = fe_lstbits t get f_lrv 0 12213 r = fe_laref0 i 12214 ix = fe_llyindex f ix 12215 n = shl ulong 1 fe_tlog t 12216 fe_lck3 79 r ix fe_lcst 5 n 12217 for j ulong n 12218 fe_llystore r ix f j v 12219 end 12220 ret true 12221 end 12222 fn fe_llystore r uint ix uint f ulong j ulong v uint to void 12223 k = j 12224 if ne get f_lf_big f 0 12225 n = shl ulong 1 fe_tlog ulong get f_lftype f 12226 k = sub sub n 1 j 12227 end 12228 b = fe_lp2 21 5 v fe_lcst 5 mul k 8 12229 b = fe_lp1 36 2 0 b 12230 atp = fe_lp2 10 5 ix fe_lcst 5 j 12231 fe_lck3 79 r atp fe_lcst 5 1 12232 o = fe_lop 43 0 0 4 12233 ir_set o 1 r 12234 ir_set o 2 atp 12235 ir_set o 3 b 12236 end 12237 12238 note ---- statements ---- 12239 note lfns: one ΩIR function per unit function, in order (handle = index + 1); main is the export 12240 fn fe_lfns to void 12241 mw = or or or ulong 109 shl ulong 97 8 shl ulong 105 16 shl ulong 110 24 12242 mf = fe_findfn mw 4 0 12243 if eq mf 0 12244 fe_lno 12245 end 12246 if or ne ar_c 22 sub mf 1 0 ne ar_c 21 sub mf 1 8 12247 fe_lno 12248 end 12249 note A `target macos` unit may define `fn libback k ulong a ulong b ulong c ulong d ulong e ulong to ulong`: the 12250 note function library code calls back (a64/DESIGN.md s14). It gets flags bit 1; any other signature is refused. 12251 bf = ulong 0 12252 if eq get f_mac 0 1 12253 bf = fe_findfn `30227092421634412` 7 0 12254 end 12255 if ne bf 0 12256 jb = sub bf 1 12257 if or ne ar_c 22 jb 6 ne ar_c 21 jb 5 12258 fe_lno 12259 end 12260 for p ulong 6 12261 q = add mul jb 6 p 12262 if or ne ar_c 35 q 0 ne ar_c 33 q 5 12263 fe_lno 12264 end 12265 end 12266 end 12267 for j ulong get f_nf 0 bound `16777217` 12268 k = uint 0 12269 if eq add j 1 mf 12270 k = uint 2 12271 end 12272 fl = uint 0 12273 if eq add j 1 bf 12274 fl = uint 2 12275 end 12276 fe_lfpar j ir_fnew k fl fe_lty ulong uchar get ar_m add get ar_rb 21 j 12277 end 12278 end 12279 12280 note lfpar: the parameters of unit function j (index) on ΩIR function f: a scalar, or a SLICE of an array 12281 note parameter, sized or unsized (access 0 view, 1 edit) 12282 fn fe_lfpar j ulong f uint to void 12283 np = ulong ar_c 22 j 12284 for p ulong np bound 6 12285 q = add mul j 6 p 12286 pk = ar_c 35 q 12287 t = ulong ar_c 33 q 12288 if eq pk 0 12289 v = ir_fpar f fe_lty t 12290 else 12291 if ge pk 6 12292 a = uint 0 12293 if eq pk 7 12294 a = uint 1 12295 end 12296 v = ir_fpar f ir_tslc 5 a 0 12297 else 12298 if gt pk 3 12299 fe_lno 12300 end 12301 a = uint 0 12302 if eq pk 3 12303 a = uint 1 12304 end 12305 v = ir_fpar f ir_tslc fe_lty t a 0 12306 end 12307 end 12308 end 12309 end 12310 12311 note lout: lower the accepted unit, write the ΩIR binary (ir_wr) to stdout; the exit status (27 when 12312 note stdout fails) 12313 fn fe_lout to int 12314 if eq get f_progmo 0 0 12315 fe_lno 12316 end 12317 if ne get f_chkmod 0 0 12318 fe_lno 12319 end 12320 ir_init 12321 fe_lnm_set 0 12322 put f_lntop 0 0 12323 put f_lfn 0 0 12324 put f_lbk 0 0 12325 put f_lsd 0 0 12326 put f_lsp 0 0 12327 put f_lcp 0 0 12328 put f_lan 0 0 12329 put f_lah 0 0 12330 fe_lfns 12331 put f_cur 0 get f_lcur0 0 12332 put f_line 0 1 12333 done = false 12334 while not done 12335 m = ulong 0 12336 while and not done lt m 999999 12337 if ne fe_lstmt 0 12338 done = true 12339 end 12340 m = add m 1 12341 end 12342 end 12343 n = ir_wr 12344 if eq ar_out 1 1 0 n 0 12345 ret 27 12346 end 12347 if eq get f_om2m 0 1 12348 fe_sitesout 12349 end 12350 ret 0 12351 end 12352 12353 fn fe_lstmt to ulong 12354 fe_tok 12355 k = get f_tk 0 12356 if eq k 0 12357 ret 0 12358 end 12359 if eq k 3 12360 ret 1 12361 end 12362 if ne k 1 12363 fe_lno 12364 end 12365 if and ne get f_om2 0 0 eq get f_line 0 get f_om2ln 0 12366 fe_skipnl 12367 ret 0 12368 end 12369 if ne fe_cp_kind 0 12370 fe_lno 12371 end 12372 if gt get f_tl 0 8 12373 fe_lname get f_tw 0 12374 ret 0 12375 end 12376 w = get f_tw 0 12377 c = fe_kw w 12378 if eq c 83 12379 fe_skipnl 12380 ret 0 12381 end 12382 if eq c 64 12383 fe_lfn 12384 ret 0 12385 end 12386 if eq get f_lfn 0 0 12387 fe_ltop c 12388 ret 0 12389 end 12390 if eq c 66 12391 fe_lend 12392 ret 0 12393 end 12394 if eq c 68 12395 fe_lelse 12396 ret 0 12397 end 12398 if eq c 0 12399 fe_lname w 12400 ret 0 12401 end 12402 fe_lkw c 12403 ret 0 12404 end 12405 12406 fn fe_lkw c ulong to void 12407 note cpufence 199, cpurelax 200: `host` with ty 0 and no operand (IR.md s7.11 class cpu) 12408 if or eq c 199 eq c 200 12409 o = fe_lop 110 0 c 1 12410 fe_eol 12411 ret 12412 end 12413 if eq c 67 12414 fe_lif 12415 ret 12416 end 12417 if eq c 69 12418 fe_lwhile 12419 ret 12420 end 12421 if eq c 71 12422 fe_lfor 12423 ret 12424 end 12425 if eq c 72 12426 fe_lret 12427 ret 12428 end 12429 if eq c 80 12430 fe_lput 12431 ret 12432 end 12433 if eq c 82 12434 fe_lx 8 12435 v = get f_lrv 0 12436 o = fe_lop 66 0 0 2 12437 ir_set o 1 v 12438 put f_lbk 0 0 12439 fe_eol 12440 ret 12441 end 12442 if eq c 86 12443 d = fe_lloop 12444 fe_lbr fe_lgete d get ar_m add get ar_rb 76 d 12445 fe_eol 12446 ret 12447 end 12448 if eq c 87 12449 n = fe_llen 12450 o = fe_lop 65 0 n 1 12451 put f_lbk 0 0 12452 fe_eol 12453 ret 12454 end 12455 if eq c 97 12456 d = fe_lloop 12457 if eq ar_c 75 d 4 12458 fe_lbr fe_lgetl d get ar_m add get ar_rb 77 d 12459 else 12460 fe_lbr uint get ar_m add get ar_rb 79 d get ar_m add get ar_rb 77 d 12461 end 12462 fe_eol 12463 ret 12464 end 12465 fe_lno 12466 end 12467 12468 note ltop: global, text and const lines 12469 fn fe_ltop c ulong to void 12470 if eq c 188 12471 fe_tok 12472 li = sub fe_findlay get f_tw 0 1 12473 put f_cur 0 get f_ly_ec li 12474 put f_line 0 get f_ly_el li 12475 ret 12476 end 12477 if eq get f_tw 0 `127970521019507` 12478 fe_skipnl 12479 ret 12480 end 12481 if or eq c 184 eq c 187 12482 fe_skipnl 12483 ret 12484 end 12485 if eq c 78 12486 fe_tok 12487 w = get f_tw 0 12488 t = fe_ltyw 12489 if ne fe_peekstar 0 12490 fe_tok 12491 g = ir_glob fe_lty t 2 12492 fe_ladd w 9 t g 0 12493 else 12494 n = fe_llen 12495 g = ir_glob ir_tarr fe_lty t uint n 0 12496 fe_ladd w 2 t g n 12497 end 12498 else 12499 if eq c 79 12500 fe_ltext 12501 else 12502 if eq c 152 12503 fe_lconst 12504 else 12505 fe_lno 12506 end 12507 end 12508 end 12509 put f_lntop 0 get f_lnn 0 12510 fe_eol 12511 end 12512 12513 note ltxb: decode the text bytes [p0, e) (escapes as fe_s_text), appended to global g when g is not 0; count. 12514 note Each pass takes at least one input byte, and the input is in the arena (at most `134217728` bytes). 12515 fn fe_ltxb p0 ulong e ulong g uint to ulong 12516 p = p0 12517 n = ulong 0 12518 while lt p e bound `134217729` 12519 b = ar_ib p 12520 p = add p 1 12521 if eq b 92 12522 b = ar_ib p 12523 p = add p 1 12524 if eq b 110 12525 b = uchar 10 12526 end 12527 if eq b 116 12528 b = uchar 9 12529 end 12530 end 12531 if ne g 0 12532 ir_gbyt g uint b 12533 end 12534 n = add n 1 12535 end 12536 ret n 12537 end 12538 12539 fn fe_ltext to void 12540 fe_tok 12541 w = get f_tw 0 12542 fe_tok 12543 p = get f_tw 0 12544 e = add p get f_tl 0 12545 n = fe_ltxb p e 0 12546 c = n 12547 if eq c 0 12548 c = 1 12549 end 12550 g = ir_glob ir_tarr 2 uint c 1 12551 if eq n 0 12552 ir_gbyt g 0 12553 else 12554 x = fe_ltxb p e g 12555 end 12556 fe_ladd w 4 2 g n 12557 end 12558 12559 fn fe_lconst to void 12560 fe_tok 12561 w = get f_tw 0 12562 note const NAME bool 0|1 (omc admits 0 and 1 only, error 8 otherwise: the check pass refused it already) 12563 t = ulong 1 12564 if eq fe_peekw 1 12565 fe_tok 12566 else 12567 t = fe_ltyw 12568 end 12569 fe_tok 12570 v = get f_tw 0 12571 if eq get f_tk 0 5 12572 v = fe_fspan t add mul get f_ts 0 `16777216` get f_tl 0 12573 end 12574 fe_ladd w 3 t 0 fe_lcan t v 12575 end 12576 12577 note lfn: fn line: entry block, parameters bound to their names, then the function's allocas (lalc) 12578 fn fe_lfn to void 12579 fe_tok 12580 f = fe_findfn get f_tw 0 get f_tl 0 get f_ts 0 12581 j = sub f 1 12582 put f_lfn 0 uint f 12583 fe_lnm_set get f_lntop 0 12584 put f_lsd 0 0 12585 put f_lsp 0 0 12586 put f_lcret 0 ulong uchar get ar_m add get ar_rb 21 j 12587 b = ir_blk uint f 12588 put f_lbk 0 b 12589 put f_ltk 0 ir_ftok uint f 12590 v = get i_fp1 uint f 12591 for p ulong ulong ar_c 22 j bound 6 12592 fe_tok 12593 pw = get f_tw 0 12594 q = add mul j 6 p 12595 if eq ar_c 35 q 0 12596 fe_tok 12597 fe_ladd pw 0 ulong uchar get ar_m add get ar_rb 33 q v 0 12598 else 12599 if ge ar_c 35 q 6 12600 fe_tok 12601 fe_tok 12602 fe_ladd pw 7 ulong ar_c 33 q v ulong sub ar_c 35 q 6 12603 else 12604 if ne ar_c 36 q 0 12605 fe_tok 12606 fe_tok 12607 fe_ladd pw 8 add 127 ulong ar_c 36 q v ulong sub ar_c 35 q 2 12608 else 12609 fe_tok 12610 t = fe_ltyw 12611 fe_tok 12612 a = ulong 0 12613 if eq ar_c 35 q 3 12614 a = ulong 1 12615 end 12616 fe_ladd pw 5 t v a 12617 note OM-2 `fresh` after an edit parameter's length: a check-pass rule only (error 27), nothing to lower 12618 if eq fe_peekw 183 12619 fe_tok 12620 end 12621 end 12622 end 12623 end 12624 v = get i_vnx v 12625 end 12626 fe_tok 12627 if or gt get f_tl 0 8 ne fe_kw get f_tw 0 65 12628 fe_lno 12629 end 12630 fe_tok 12631 fe_tok 12632 if and ne get f_tk 0 0 ne get f_tk 0 3 12633 if ne fe_lkw0 182 12634 fe_lno 12635 end 12636 fe_eol 12637 end 12638 fe_lalc 12639 put f_lcpos 0 get f_cur 0 12640 put f_lclin 0 get f_line 0 12641 put f_lclim 0 get f_lnn 0 12642 put f_lctyp 0 12 12643 fe_lcscan 1 12644 end 12645 12646 note lcscan: consume the checked function prefix. Entry executes requires; returns execute ensures. 12647 note Release clauses are consumed without evaluating any predicate or adding optimizer assumptions. 12648 fn fe_lcscan which ulong to void 12649 if eq get f_om2 0 0 12650 ret 12651 end 12652 put f_lcact 0 1 12653 k = fe_cp_next 12654 while ne k 0 12655 if eq k 3 12656 fe_lno 12657 end 12658 if and eq k which eq get f_crel 0 0 12659 fe_lx 1 12660 code = ulong 9 12661 if eq k 2 12662 code = ulong 10 12663 end 12664 fe_lck1 82 code get f_lrv 0 12665 fe_eol 12666 else 12667 fe_skipnl 12668 end 12669 k = fe_cp_next 12670 end 12671 put f_lcact 0 0 12672 end 12673 12674 note lcpost: replay only ensures, using current entry-visible bindings and the saved SSA return value. 12675 fn fe_lcpost v uint t ulong to void 12676 p = get f_cur 0 12677 l = get f_line 0 12678 put f_lcval 0 v 12679 put f_lctyp 0 t 12680 put f_cur 0 get f_lcpos 0 12681 put f_line 0 get f_lclin 0 12682 fe_lcscan 2 12683 put f_cur 0 p 12684 put f_line 0 l 12685 end 12686 12687 note lcinv: emit the loop prefix at its head, before even the condition, and consume it in source. 12688 fn fe_lcinv to void 12689 if eq get f_om2 0 0 12690 ret 12691 end 12692 k = fe_cp_next 12693 while eq k 3 12694 if eq get f_crel 0 0 12695 fe_lx 1 12696 fe_lck1 82 10 get f_lrv 0 12697 fe_eol 12698 else 12699 fe_skipnl 12700 end 12701 k = fe_cp_next 12702 end 12703 if ne k 0 12704 fe_lno 12705 end 12706 end 12707 12708 note lalc: every `NAME = new T N v` of the function's outermost block, read ahead from the current 12709 note place, becomes an alloca in the entry block (IR.md s7.5: entry block only), queued in source order. 12710 note Passes are at most the input bytes plus a few (measured: a blank line one pass, a line with a word two, and 12711 note such a line is at least 2 bytes); the input is in the arena (at most `134217728` bytes). 12712 fn fe_lalc to void 12713 sc = get f_cur 0 12714 sl = get f_line 0 12715 put f_lan 0 0 12716 put f_lah 0 0 12717 dp = ulong 0 12718 go = true 12719 while go bound `134217729` 12720 fe_tok 12721 k = get f_tk 0 12722 if eq k 3 12723 go = false 12724 end 12725 if eq k 1 12726 c = fe_lkw0 12727 if or or eq c 67 eq c 69 eq c 71 12728 dp = add dp 1 12729 end 12730 if eq c 66 12731 if eq dp 0 12732 go = false 12733 else 12734 dp = sub dp 1 12735 end 12736 end 12737 if and eq c 0 eq dp 0 12738 fe_lalc1 12739 end 12740 fe_skipnl 12741 end 12742 end 12743 put f_cur 0 sc 12744 put f_line 0 sl 12745 end 12746 12747 fn fe_lalc1 to void 12748 fe_tok 12749 if or ne get f_tk 0 1 gt get f_tl 0 8 12750 ret 12751 end 12752 if eq fe_kw get f_tw 0 73 12753 fe_tok 12754 if or ne get f_tk 0 1 gt get f_tl 0 8 12755 ret 12756 end 12757 end 12758 if ne fe_kw get f_tw 0 84 12759 ret 12760 end 12761 sid = fe_peek_struct 12762 t = ulong 5 12763 n = ulong 0 12764 if ne sid 0 12765 n = ulong get f_stcell sub sid 1 12766 else 12767 t = fe_ltyw 12768 n = fe_llen 12769 end 12770 a = get f_lan 0 12771 fe_need 22 a 12772 o = fe_lop 50 fe_lref t n 1 0 1 12773 ar_pu 85 a ir_res o 12774 put f_lan 0 add a 1 12775 end 12776 12777 note lname: a line starting with a short name: a void call, or name [=] value (new or existing scalar, 12778 note or a new array) 12779 fn fe_lname w ulong to void 12780 x = fe_lfind w 12781 if eq x 0 12782 f = fe_findfn w get f_tl 0 0 12783 if ne f 0 12784 fe_lcall f 12785 fe_eol 12786 ret 12787 end 12788 end 12789 fe_tok 12790 if and eq get f_tk 0 1 le get f_tl 0 8 12791 if eq fe_kw get f_tw 0 73 12792 fe_tok 12793 end 12794 end 12795 if and eq get f_tk 0 1 eq get f_tw 0 `28542713606205029` 12796 fe_lpoolgrow w x 12797 ret 12798 end 12799 if ne x 0 12800 i = sub x 1 12801 if ne ar_c 69 i 0 12802 fe_lno 12803 end 12804 fe_lxt get ar_m add get ar_rb 70 i 12805 ar_pu 71 i get f_lrv 0 12806 fe_eol 12807 ret 12808 end 12809 if and eq get f_tk 0 1 le get f_tl 0 8 12810 if eq fe_kw get f_tw 0 84 12811 fe_lnew w 12812 fe_eol 12813 ret 12814 end 12815 end 12816 fe_lxt 0 12817 if ne get f_lrk 0 0 12818 fe_lno 12819 end 12820 fe_ladd w 0 get f_lrt 0 get f_lrv 0 0 12821 fe_eol 12822 end 12823 12824 fn fe_lnew w ulong to void 12825 sid = fe_peek_struct 12826 if ne sid 0 12827 fe_lstnew w sub sid 1 12828 ret 12829 end 12830 t = fe_ltyw 12831 n = fe_llen 12832 fe_lx t 12833 h = get f_lah 0 12834 if ge h get f_lan 0 12835 fe_lno 12836 end 12837 r = uint get ar_m add get ar_rb 85 h 12838 put f_lah 0 add h 1 12839 o = fe_lop 51 0 0 3 12840 ir_set o 1 r 12841 ir_set o 2 get f_lrv 0 12842 fe_ladd w 1 t r n 12843 end 12844 12845 fn fe_lput to void 12846 ni = fe_lanm 12847 if eq ar_c 69 ni 9 12848 fe_lpoolput ni 12849 ret 12850 end 12851 if eq ar_c 69 ni 8 12852 if fe_llyput ni 12853 fe_eol 12854 ret 12855 end 12856 put f_lat 0 2 12857 else 12858 if ge ar_c 69 ni 6 12859 fe_lstput ni 12860 ret 12861 end 12862 end 12863 r = fe_laref0 ni 12864 t = get f_lat 0 12865 fe_lx 5 12866 i = get f_lrv 0 12867 it = get f_lrt 0 12868 fe_lx t 12869 v = get f_lrv 0 12870 put f_lrv 0 i 12871 put f_lrt 0 it 12872 ix = fe_lidx 12873 fe_lck3 79 r ix fe_lcst 5 1 12874 o = fe_lop 43 0 0 4 12875 ir_set o 1 r 12876 ir_set o 2 ix 12877 ir_set o 3 v 12878 fe_eol 12879 end 12880 12881 fn fe_lret to void 12882 t = get f_lcret 0 12883 if eq t 12 12884 fe_lcpost 0 t 12885 o = fe_lop 62 0 0 1 12886 else 12887 fe_lx t 12888 v = get f_lrv 0 12889 fe_lcpost v t 12890 o2 = fe_lop 63 0 0 2 12891 ir_set o2 1 v 12892 end 12893 put f_lbk 0 0 12894 fe_eol 12895 end 12896 12897 note lfend: the end of a function: a void one that reaches it returns 12898 fn fe_lfend to void 12899 if ne get f_lbk 0 0 12900 if ne get f_lcret 0 12 12901 fe_lno 12902 end 12903 fe_lcpost 0 12 12904 o = fe_lop 62 0 0 1 12905 end 12906 if ne get f_lah 0 get f_lan 0 12907 fe_lno 12908 end 12909 put f_lfn 0 0 12910 put f_lbk 0 0 12911 fe_lnm_set get f_lntop 0 12912 end 12913 12914 fn fe_lif to void 12915 fe_lx 1 12916 c = get f_lrv 0 12917 tb = ir_blk get f_lfn 0 12918 fb = ir_blk get f_lfn 0 12919 o = fe_lop 61 0 0 4 12920 ir_set o 1 c 12921 ir_set o 2 tb 12922 ir_set o 3 fb 12923 n0 = get f_lnn 0 12924 fe_lpshb 1 n0 n0 0 fb 12925 fe_lpush n0 12926 fe_lgo tb 12927 fe_eol 12928 end 12929 12930 fn fe_lelse to void 12931 d = sub get f_lsd 0 1 12932 n0 = get ar_m add get ar_rb 76 d 12933 if ne get f_lbk 0 0 12934 fe_lbr fe_lgetj d n0 12935 end 12936 fe_lrest get ar_m add get ar_rb 83 d n0 12937 fe_lnm_set n0 12938 fe_lgo uint get ar_m add get ar_rb 80 d 12939 ar_pc 75 d 2 12940 fe_eol 12941 end 12942 12943 fn fe_lend to void 12944 dd = get f_lsd 0 12945 if eq dd 0 12946 fe_lfend 12947 fe_eol 12948 ret 12949 end 12950 d = sub dd 1 12951 k = uchar get ar_m add get ar_rb 75 d 12952 n0 = get ar_m add get ar_rb 76 d 12953 if ge k 3 12954 fe_lendl d 12955 else 12956 if ne get f_lbk 0 0 12957 fe_lbr fe_lgetj d n0 12958 end 12959 if eq k 1 12960 fe_lrest get ar_m add get ar_rb 83 d n0 12961 fe_lnm_set n0 12962 fe_lgo uint get ar_m add get ar_rb 80 d 12963 fe_lbr fe_lgetj d n0 12964 end 12965 fe_lnm_set n0 12966 j = uint get ar_m add get ar_rb 78 d 12967 if ne j 0 12968 fe_lenter j n0 12969 end 12970 end 12971 put f_lsp 0 get ar_m add get ar_rb 83 d 12972 put f_lsd 0 d 12973 fe_eol 12974 end 12975 12976 note lbnd: the rest of a loop line: nothing (bound df) or bound N 12977 fn fe_lbnd df ulong to ulong 12978 fe_tok 12979 if eq get f_tk 0 0 12980 ret df 12981 end 12982 if and eq get f_tk 0 1 le get f_tl 0 8 12983 if eq fe_kw get f_tw 0 181 12984 fe_eol 12985 ret df 12986 end 12987 if eq fe_kw get f_tw 0 70 12988 n = fe_llen 12989 if eq n 0 12990 fe_lno 12991 end 12992 fe_eol 12993 ret n 12994 end 12995 end 12996 fe_lno 12997 ret 0 12998 end 12999 13000 note lhead: in the loop head h (condition c computed): cbr to the body or the exit; in the body the fuel 13001 note check on the hidden counter (the last name, when nb is not 0) and its increment 13002 fn fe_lhead n0 ulong n1 ulong h uint c uint nb ulong k ulong to void 13003 b = ir_blk get f_lfn 0 13004 x = ir_blk get f_lfn 0 13005 o = fe_lop 61 0 0 4 13006 ir_set o 1 c 13007 ir_set o 2 b 13008 ir_set o 3 x 13009 fe_lgo b 13010 if ne nb 0 13011 s = sub n1 1 13012 kv = ar_u 71 s 13013 fe_lck2 81 4 kv fe_lcst 5 nb 13014 ar_pu 71 s fe_lp2 10 5 kv fe_lcst 5 1 13015 end 13016 fe_lpshb k n0 n1 h x 13017 end 13018 13019 fn fe_lwhile to void 13020 n0 = get f_lnn 0 13021 fe_ladd 0 0 5 fe_lcst 5 0 0 13022 n1 = get f_lnn 0 13023 h = fe_ljoin n1 13024 fe_lbr h n1 13025 fe_lenter h n1 13026 p = get f_cur 0 13027 l = get f_line 0 13028 fe_skipnl 13029 fe_lcinv 13030 bp = get f_cur 0 13031 bl = get f_line 0 13032 put f_cur 0 p 13033 put f_line 0 l 13034 fe_lx 1 13035 c = get f_lrv 0 13036 nb = fe_lbnd `1000000` 13037 put f_cur 0 bp 13038 put f_line 0 bl 13039 fe_lhead n0 n1 h c nb 3 13040 end 13041 13042 note lfor: for i T K [bound N]: K a number or constant (no fuel unless bound), a scalar name (read again 13043 note in every pass) or another value (read once here); fuel `1000000` by default for the last two 13044 fn fe_lfor to void 13045 fe_tok 13046 put f_lqw 0 get f_tw 0 13047 put f_lqt 0 fe_ltyw 13048 t = get f_lqt 0 13049 fe_tok 13050 put f_lqm 0 0 13051 k = get f_tk 0 13052 if eq k 2 13053 put f_lqb 0 fe_lcan t get f_tw 0 13054 else 13055 x = ulong 0 13056 if and eq k 1 le get f_tl 0 8 13057 x = fe_lfind get f_tw 0 13058 end 13059 if ne x 0 13060 if eq ar_c 69 sub x 1 3 13061 put f_lqb 0 get ar_m add get ar_rb 72 sub x 1 13062 else 13063 if eq ar_c 69 sub x 1 0 13064 put f_lqm 0 1 13065 put f_lqb 0 sub x 1 13066 else 13067 fe_lno 13068 end 13069 end 13070 else 13071 fe_lxt t 13072 put f_lqm 0 2 13073 put f_lqv 0 get f_lrv 0 13074 end 13075 end 13076 df = ulong 0 13077 if ne get f_lqm 0 0 13078 df = ulong `1000000` 13079 end 13080 put f_lqn 0 fe_lbnd df 13081 fe_lfor2 13082 end 13083 13084 fn fe_lfor2 to void 13085 t = get f_lqt 0 13086 nb = get f_lqn 0 13087 n0 = get f_lnn 0 13088 fe_ladd get f_lqw 0 0 t fe_lcst t 0 0 13089 if ne nb 0 13090 fe_ladd 0 0 5 fe_lcst 5 0 0 13091 end 13092 n1 = get f_lnn 0 13093 h = fe_ljoin n1 13094 fe_lbr h n1 13095 fe_lenter h n1 13096 fe_lcinv 13097 m = get f_lqm 0 13098 kv = get f_lqv 0 13099 if eq m 0 13100 kv = fe_lcst t get f_lqb 0 13101 end 13102 if eq m 1 13103 kv = uint get ar_m add get ar_rb 71 get f_lqb 0 13104 end 13105 c = fe_lp2 32 1 uint get ar_m add get ar_rb 71 n0 kv 13106 fe_lhead n0 n1 h c nb 4 13107 end 13108 13109 note lendl: a loop's end: the back edge (through the latch for a for, which adds 1 to i), then the exit 13110 note block, which joins the break target when there is one. A signed i is added under chk.add (trap 1, as 13111 note omc's latch binop 33 at s_end): a body that writes i = max must trap, never wrap to min and go on. 13112 fn fe_lendl d ulong to void 13113 n0 = get ar_m add get ar_rb 76 d 13114 n1 = get ar_m add get ar_rb 77 d 13115 h = uint get ar_m add get ar_rb 79 d 13116 if eq ar_c 75 d 4 13117 if ne get f_lbk 0 0 13118 fe_lbr fe_lgetl d n1 13119 end 13120 l = uint get ar_m add get ar_rb 82 d 13121 if ne l 0 13122 fe_lenter l n1 13123 iv = uint get ar_m add get ar_rb 71 n0 13124 t = get ar_m add get ar_rb 70 n0 13125 if fe_lsg t 13126 fe_lck2 70 1 iv fe_lcst t 1 13127 end 13128 ar_pu 71 n0 fe_lp2 10 t iv fe_lcst t 1 13129 fe_lbr h n1 13130 end 13131 else 13132 if ne get f_lbk 0 0 13133 fe_lbr h n1 13134 end 13135 end 13136 fe_lgo uint get ar_m add get ar_rb 80 d 13137 fe_lbind h n0 13138 fe_lnm_set n0 13139 e = uint get ar_m add get ar_rb 81 d 13140 if ne e 0 13141 fe_lbr e n0 13142 fe_lenter e n0 13143 end 13144 end 13145 13146 13147 fn fe_lpoolget ni ulong to void 13148 t = ar_w 70 ni 13149 fe_lx 5 13150 ix = fe_lidx 13151 o = fe_lop 113 fe_lty t ar_w 71 ni 2 13152 ir_set o 1 ix 13153 fe_lval ir_res o t 13154 end 13155 13156 note Native pool stores evaluate index and value before resolving the current descriptor and checking bounds. 13157 fn fe_lpoolput ni ulong to void 13158 t = ar_w 70 ni 13159 fe_lx 5 13160 ix = fe_lidx 13161 fe_lx t 13162 o = fe_lop 114 0 ar_w 71 ni 3 13163 ir_set o 1 ix 13164 ir_set o 2 get f_lrv 0 13165 fe_eol 13166 end 13167 13168 fn fe_lpoolgrow w ulong x ulong to void 13169 ni = fe_lanm 13170 if ne ar_c 69 ni 9 13171 fe_lno 13172 end 13173 fe_lx 5 13174 o = fe_lop 111 9 ar_w 71 ni 2 13175 ir_set o 1 get f_lrv 0 13176 if eq x 0 13177 fe_ladd w 0 9 ir_res o 0 13178 else 13179 ar_pu 71 sub x 1 ir_res o 13180 end 13181 fe_eol 13182 end 13183 13184 fn fe_lpoolio c ulong fd uint ni ulong to void 13185 fe_lx 5 13186 start = get f_lrv 0 13187 fe_lx 5 13188 count = get f_lrv 0 13189 o = fe_lop uint add 62 c 9 ar_w 71 ni 4 13190 ir_set o 1 fd 13191 ir_set o 2 start 13192 ir_set o 3 count 13193 fe_lval ir_res o 9 13194 end