interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / seed / ng / src / front.om

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