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 / rung4 / om4.s

4768 lines · 95147 bytes Raw Blame History
1; om4.s -- rung 4 of the Omega seed chain: om3 (seed/rung3/om3.s) grown into the systems subset a compiler
2; needs, written in asm2's language and built by asm2:
3; cat seed/rung2/table.s2 seed/rung3/table3.s2 seed/rung4/om4.s | seed/rung2/asm2.bin > om4.bin
4; Use: om4.bin < program.omegese > out. Two kinds of output (docs/one_layer/OMEGESE.md section 9 has the words):
5; - function mode (no `fn main`): the functions' words only, entry = word 0, to be called under the OSC-1
6; native rules (docs/osc/OSC-1-DESIGN.md section 7): parameters in x0..x5, result in x0 in canonical
7; form, OscRt * in x7, a trap calls OscRt.trap (offset 16) with x0 = rt, x1 = code. With more than one
8; function, word 0 is a B to the last one (the entry is still written last). A call may name any
9; function in the unit, earlier or later.
10; - program mode (a line `fn main`): a whole AArch64 Linux program (ELF file header laid out by hand, no
11; linker). Its start code sets the stack to a fixed 8 MiB pool, calls main, and exits with main's value;
12; a trap exits with status 100 + code.
13;
14; What om4 adds to om3: many functions, calls to any function in the unit (a names pass collects every
15; signature first; a later function is a call, never a new scalar), mutual recursion in program mode,
16; a call cycle in function mode refused as error 9 (the same refusal a function calling itself already
17; had), assigning to a function name refused as error 10; void functions and ret without a value;
18; signed div, rem and shl; for with a value as count;
19; true and false; local arrays (new, on the stack, only in a function's outermost block), array parameters
20; (view / edit), global arrays (global, fixed pools in the program's memory image, no heap), text literals
21; (text, read-only bytes with their length), get, put, len; read and write (Linux system calls on a
22; checked part of an array) and exit; note lines. Every array carries its length; every index is checked
23; (trap 3) unless it is a number, which is checked when om4 reads it.
24; Semantics follow the C path's interpreter (src/compiler/osc_interp.c): unsigned ops wrap to the width,
25; signed add/sub/mul/neg/div/shl trap 1 out of range, div/rem trap 2 on zero, a loop bound trap 4, a
26; conversion out of range trap 5, a shift amount outside 0..width-1 trap 7; om4 adds trap 3 (index or
27; system call range outside the array) and trap 6 (the stack pool is used up, program mode).
28;
29; Code generation (as om3): every name lives in its own register for its whole scope; temporaries are
30; registers freed at the end of each statement. Registers handed out: x0..x6 not taken by parameters,
31; x8..x15, x17 (never x7 = rt, x16 = scratch, x18, x19..x30; x28 = stack pool floor in program mode).
32; A call saves every register in use and x30 on the stack, loads the arguments into x0..x5 from that save
33; area, branches with BL, and loads the registers back; so a function needs no entry or exit code beyond
34; giving back the stack of its local arrays.
35;
36; Every machine word om4 writes is built from a fixed part read from the encoding diagram of the Arm ARM
37; DDI 0487 M.d section named beside it, ORed with register and number fields.
38;
39; om4's own registers: x18 input end, x19 input cursor, x20 output cursor, x21 output buffer start, x22 line
40; number, x23 names in scope, x24 next free pool slot, x25 block stack top, x26 trap list end, x27 return
41; type (0 outside a function, 10 void), x28 pool slots held by names, x29 pool start.
42; Memory: input 0x800000 (under 8 MiB), output 0x1000000 (8 MiB: 176-byte file header, 1 entry word, then
43; text bytes and functions), names 0x1800000 (32 bytes: packed name 8, register 4, type 4, length 4, kind
44; 4, address 8), blocks 0x1810000 (128 bytes), trap list 0x1820000 (8 bytes: site, code), message
45; 0x1830000, 0x1840000 unused (the 512-entry function table until it moved), state 0x1850000 (8-byte
46; slots: 1 globals and texts in the name table, 2 functions, 4 stack bytes of local arrays, 5 the path
47; has ended, 6 program mode, 7 global pool bytes, 9 last function, 10 value nesting depth, 11 a number
48; written as 2^63 or more, 12 recorded calls, 13 namescan phase: 0 not started, 1 collecting signatures,
49; 2 emitting). Call records, 24 bytes each (site, callee entry, caller entry), sit at 0x1860000, 65536 of
50; them. Function-mode cycle marks, one byte per function, sit at 0x19e0000. Functions, 4096 entries of
51; 128 bytes (name 8, address 8, return type 4, parameter count 4, then per parameter 16 bytes: type 4,
52; length 4, kind 4), sit at 0x19f0000 up to 0x1a70000. All three are past the file and zeroed with the
53; rest of the mapping.
54; Name kinds: 0 scalar, 1 local array, 2 view parameter, 3 edit parameter, 4 global array, 5 text, 10 run-time
55; pool (global NAME T *, program mode: a 16-byte slot, base then length in elements, in the global pool area).
56; Run-time pools (docs/RUNTIME-POOLS.md s6, OMEGESE 9.15): om4 knows the subset seed/omc/omc.om uses, get, put,
57; len and r = enlarge P n, and emits for them the words omc emits for an OM-1 unit (gate5 compares them); any
58; other use of a pool (read, write, a pool as an argument) is refused. State slot 14 is the address of the
59; unit's omc_enlarge helper once emitted (0 before); slot 15 is 1 once a unit uses envcnt or envread (the start
60; code then keeps the initial stack in X27, MOV X27, SP, as omc does).
61; Errors: "om4: line N: error E" on stderr, exit E: 1 read, 2 write, 3 unknown name, 4 line ends too
62; early, 5 extra words, 6 bad number, 7 type mismatch, 8 number out of range for its type, 9 not in the
63; subset, 10 name defined twice, 11 number with no type, 12 out of registers, 13 word over 8 characters,
64; 14 table or buffer full, 15 block structure, 16 syntax, 17 a line after ret or exit in the same block,
65; 18 a function that needs a value can reach its end, 19 one array passed twice in a call (aliasing),
66; 20 writing through a read-only array, 21 a number index outside the array, 22 bad text literal,
67; 23 array or pool too large.
68;
69; ---- ELF-64 file header (words as in seed/rung0/seed0.hex) ----
70 .w 0x464c457f
71 .w 0x00010102
72 .w 0x00000000
73 .w 0x00000000
74 .w 0x00b70002
75 .w 0x00000001
76 .w 0x00400078
77 .w 0x00000000
78 .w 0x00000040
79 .w 0x00000000
80 .w 0x00000000
81 .w 0x00000000
82 .w 0x00000000
83 .w 0x00380040
84 .w 0x00000001
85 .w 0x00000000
86; ---- program header: one PT_LOAD, read/write/execute, file at 0x400000 ----
87 .w 0x00000001
88 .w 0x00000007
89 .w 0x00000000
90 .w 0x00000000
91 .w 0x00400000
92 .w 0x00000000
93 .w 0x00400000
94 .w 0x00000000
95 .w 0x00003f48 ; p_filesz = the size of om4.bin, 16200 bytes (asm2 has no size arithmetic; gate4.sh checks it)
96 .w 0x00000000
97 .w 0x01670000 ; p_memsz: through the function table at 0x19f0000, which ends at 0x1a70000
98 .w 0x00000000
99 .w 0x00001000
100 .w 0x00000000
101; ---- 0x400078: entry ----
102 b START
103 .w 0
104; ---- keyword table, 16 bytes per entry: packed word (8), code (4), 0 (4); made with
105; evidence/SEED-0/rung4-worksheet.sh. Codes: 1..9 types, 33..58 values, 64.. statements, 77 not in subset.
106:KWTAB
107 .w 0x6c6f6f62
108 .w 0x00000000
109 .w 1
110 .w 0
111 .w 0x61686375
112 .w 0x00000072
113 .w 2
114 .w 0
115 .w 0x00003875
116 .w 0x00000000
117 .w 2
118 .w 0
119 .w 0x6f687375
120 .w 0x00007472
121 .w 3
122 .w 0
123 .w 0x00363175
124 .w 0x00000000
125 .w 3
126 .w 0
127 .w 0x746e6975
128 .w 0x00000000
129 .w 4
130 .w 0
131 .w 0x00323375
132 .w 0x00000000
133 .w 4
134 .w 0
135 .w 0x6e6f6c75
136 .w 0x00000067
137 .w 5
138 .w 0
139 .w 0x00343675
140 .w 0x00000000
141 .w 5
142 .w 0
143 .w 0x65747962
144 .w 0x00000000
145 .w 6
146 .w 0
147 .w 0x00003869
148 .w 0x00000000
149 .w 6
150 .w 0
151 .w 0x726f6873
152 .w 0x00000074
153 .w 7
154 .w 0
155 .w 0x00363169
156 .w 0x00000000
157 .w 7
158 .w 0
159 .w 0x00746e69
160 .w 0x00000000
161 .w 8
162 .w 0
163 .w 0x00323369
164 .w 0x00000000
165 .w 8
166 .w 0
167 .w 0x676e6f6c
168 .w 0x00000000
169 .w 9
170 .w 0
171 .w 0x00343669
172 .w 0x00000000
173 .w 9
174 .w 0
175 .w 0x00646461
176 .w 0x00000000
177 .w 33
178 .w 0
179 .w 0x00627573
180 .w 0x00000000
181 .w 34
182 .w 0
183 .w 0x006c756d
184 .w 0x00000000
185 .w 35
186 .w 0
187 .w 0x00766964
188 .w 0x00000000
189 .w 36
190 .w 0
191 .w 0x006d6572
192 .w 0x00000000
193 .w 37
194 .w 0
195 .w 0x00646e61
196 .w 0x00000000
197 .w 38
198 .w 0
199 .w 0x0000726f
200 .w 0x00000000
201 .w 39
202 .w 0
203 .w 0x00726f78
204 .w 0x00000000
205 .w 40
206 .w 0
207 .w 0x006c6873
208 .w 0x00000000
209 .w 41
210 .w 0
211 .w 0x00726873
212 .w 0x00000000
213 .w 42
214 .w 0
215 .w 0x00007165
216 .w 0x00000000
217 .w 43
218 .w 0
219 .w 0x0000656e
220 .w 0x00000000
221 .w 44
222 .w 0
223 .w 0x0000746c
224 .w 0x00000000
225 .w 45
226 .w 0
227 .w 0x0000656c
228 .w 0x00000000
229 .w 46
230 .w 0
231 .w 0x00007467
232 .w 0x00000000
233 .w 47
234 .w 0
235 .w 0x00006567
236 .w 0x00000000
237 .w 48
238 .w 0
239 .w 0x0067656e
240 .w 0x00000000
241 .w 49
242 .w 0
243 .w 0x00746f6e
244 .w 0x00000000
245 .w 50
246 .w 0
247 .w 0x00746567
248 .w 0x00000000
249 .w 51
250 .w 0
251 .w 0x006e656c
252 .w 0x00000000
253 .w 52
254 .w 0
255 .w 0x64616572
256 .w 0x00000000
257 .w 53
258 .w 0
259 .w 0x74697277
260 .w 0x00000065
261 .w 54
262 .w 0
263 .w 0x65757274
264 .w 0x00000000
265 .w 55
266 .w 0
267 .w 0x736c6166
268 .w 0x00000065
269 .w 56
270 .w 0
271 .w 0x77656976
272 .w 0x00000000
273 .w 57
274 .w 0
275 .w 0x74696465
276 .w 0x00000000
277 .w 58
278 .w 0
279 .w 0x00006e66
280 .w 0x00000000
281 .w 64
282 .w 0
283 .w 0x00006f74
284 .w 0x00000000
285 .w 65
286 .w 0
287 .w 0x00646e65
288 .w 0x00000000
289 .w 66
290 .w 0
291 .w 0x00006669
292 .w 0x00000000
293 .w 67
294 .w 0
295 .w 0x65736c65
296 .w 0x00000000
297 .w 68
298 .w 0
299 .w 0x6c696877
300 .w 0x00000065
301 .w 69
302 .w 0
303 .w 0x6e756f62
304 .w 0x00000064
305 .w 70
306 .w 0
307 .w 0x00726f66
308 .w 0x00000000
309 .w 71
310 .w 0
311 .w 0x00746572
312 .w 0x00000000
313 .w 72
314 .w 0
315 .w 0x0000003d
316 .w 0x00000000
317 .w 73
318 .w 0
319 .w 0x00000028
320 .w 0x00000000
321 .w 74
322 .w 0
323 .w 0x00000029
324 .w 0x00000000
325 .w 75
326 .w 0
327 .w 0x64696f76
328 .w 0x00000000
329 .w 76
330 .w 0
331 .w 0x626f6c67
332 .w 0x00006c61
333 .w 78
334 .w 0
335 .w 0x74786574
336 .w 0x00000000
337 .w 79
338 .w 0
339 .w 0x00747570
340 .w 0x00000000
341 .w 80
342 .w 0
343 .w 0x65657266
344 .w 0x00000000
345 .w 81
346 .w 0
347 .w 0x74697865
348 .w 0x00000000
349 .w 82
350 .w 0
351 .w 0x65746f6e
352 .w 0x00000000
353 .w 83
354 .w 0
355 .w 0x0077656e
356 .w 0x00000000
357 .w 84
358 .w 0
359 .w 0x61657262
360 .w 0x0000006b
361 .w 77
362 .w 0
363 .w 0x70617274
364 .w 0x00000000
365 .w 77
366 .w 0
367 .w 0x006e776f
368 .w 0x00000000
369 .w 77
370 .w 0
371; envcnt (code 86) and envread (code 87): host words of a program (VT_ENVCNT, VT_ENVREAD)
372 .w 0x63766e65
373 .w 0x0000746e
374 .w 86
375 .w 0
376 .w 0x72766e65
377 .w 0x00646165
378 .w 87
379 .w 0
380; enlarge (code 85): only as the whole of an assignment, r = enlarge P n (S_ENL); in a value error 9
381 .w 0x616c6e65
382 .w 0x00656772
383 .w 85
384 .w 0
385 .w 0
386 .w 0
387 .w 0
388 .w 0
389; ---- messages ("om4: line ", ": error "), each with its length ----
390:MSG1
391 .w 0x3a346d6f
392 .w 0x6e696c20
393 .w 0x00002065
394:MSG2
395 .w 0x7265203a
396 .w 0x20726f72
397 .w 0x00000000
398; ---- register pool: x0..x6, x8..x15, x17; the pool starts after the parameter registers ----
399:POOLC
400 .b 0
401 .b 1
402 .b 2
403 .b 3
404 .b 4
405 .b 5
406 .b 6
407 .b 8
408 .b 9
409 .b 10
410 .b 11
411 .b 12
412 .b 13
413 .b 14
414 .b 15
415 .b 17
416:POOLEND
417; ---- the pool index of each register x0..x17 (255: not in the pool) ----
418:REGIDX
419 .b 0
420 .b 1
421 .b 2
422 .b 3
423 .b 4
424 .b 5
425 .b 6
426 .b 255
427 .b 7
428 .b 8
429 .b 9
430 .b 10
431 .b 11
432 .b 12
433 .b 13
434 .b 14
435 .b 255
436 .b 15
437; ---- width in bits by type code 0..9 (bool 1) ----
438:TWID
439 .b 0
440 .b 1
441 .b 8
442 .b 16
443 .b 32
444 .b 64
445 .b 8
446 .b 16
447 .b 32
448 .b 64
449; ---- log2 of the element size by type code 0..9 ----
450:TLOG
451 .b 0
452 .b 0
453 .b 0
454 .b 1
455 .b 2
456 .b 3
457 .b 0
458 .b 1
459 .b 2
460 .b 3
461; ---- condition for eq ne lt le gt ge, unsigned then signed (Arm ARM Table C1-1, C1.2.4):
462; EQ 0, NE 1, LO 3 / LT 11, LS 9 / LE 13, HI 8 / GT 12, HS 2 / GE 10. The opposite condition is cond ^ 1.
463:CONDS
464 .b 0
465 .b 0
466 .b 1
467 .b 1
468 .b 3
469 .b 11
470 .b 9
471 .b 13
472 .b 8
473 .b 12
474 .b 2
475 .b 10
476 .b 0 ; pad to a word boundary (16 + 18 + 10 + 10 + 12 bytes of tables above)
477 .b 0
478; ---- load by element type 0..9, register offset scaled by the element size (LSL #log2 size; S = 1
479; except for bytes): uchar LDRB C6.2.221, ushort LDRH C6.2.223, uint LDR (32-bit) C6.2.218, ulong and
480; long LDR (64-bit) C6.2.218, byte LDRSB (64-bit) C6.2.225, short LDRSH (64-bit) C6.2.227, int LDRSW
481; C6.2.230. Fixed part: option 011 (LSL), Rm Rn Rt zero.
482:LDOP
483 .w 0
484 .w 0
485 .w 0x38606800
486 .w 0x78607800
487 .w 0xb8607800
488 .w 0xf8607800
489 .w 0x38a06800
490 .w 0x78a07800
491 .w 0xb8a07800
492 .w 0xf8607800
493; ---- store by element type: STRB C6.2.418, STRH C6.2.420, STR (32-bit, 64-bit) C6.2.416 ----
494:STOP
495 .w 0
496 .w 0
497 .w 0x38206800
498 .w 0x78207800
499 .w 0xb8207800
500 .w 0xf8207800
501 .w 0x38206800
502 .w 0x78207800
503 .w 0xb8207800
504 .w 0xf8207800
505; ---- the file header om4 writes in program mode: ELF-64 header and two PT_LOAD program headers
506; (the file at 0x400000 read/execute; the stack and global pools at 0x10000000 read/write, no file
507; bytes). Words 24, 26 (file size) and 40 (pool size) are filled in at the end. ----
508:ELFHDR
509 .w 0x464c457f
510 .w 0x00010102
511 .w 0x00000000
512 .w 0x00000000
513 .w 0x00b70002
514 .w 0x00000001
515 .w 0x004000b0 ; e_entry: the word after the header
516 .w 0x00000000
517 .w 0x00000040
518 .w 0x00000000
519 .w 0x00000000
520 .w 0x00000000
521 .w 0x00000000
522 .w 0x00380040
523 .w 0x00000002 ; e_phnum 2
524 .w 0x00000000
525 .w 0x00000001 ; PT_LOAD
526 .w 0x00000005 ; PF_R | PF_X
527 .w 0x00000000
528 .w 0x00000000
529 .w 0x00400000
530 .w 0x00000000
531 .w 0x00400000
532 .w 0x00000000
533 .w 0x00000000 ; p_filesz (filled in)
534 .w 0x00000000
535 .w 0x00000000 ; p_memsz (filled in)
536 .w 0x00000000
537 .w 0x00001000
538 .w 0x00000000
539 .w 0x00000001 ; PT_LOAD
540 .w 0x00000006 ; PF_R | PF_W
541 .w 0x00000000
542 .w 0x00000000
543 .w 0x10000000 ; the stack pool from 0x10000000, the global pools from 0x10800000
544 .w 0x00000000
545 .w 0x10000000
546 .w 0x00000000
547 .w 0x00000000 ; p_filesz 0
548 .w 0x00000000
549 .w 0x00000000 ; p_memsz (filled in: 8 MiB stack + global pools)
550 .w 0x00000000
551 .w 0x00001000
552 .w 0x00000000
553; ======================================================================================================
554; start: read all of stdin to 0x800000 (at most 8 MiB - 1 bytes); x18 = its end (no end byte is written)
555:START
556 movz.x x19 0x80 1
557 movz.x x12 0 0
558:RD
559 movz.x x0 0 0
560 add.x x1 x19 x12
561 movz.x x2 0x80 1
562 sub.x x2 x2 x12
563 cbz.x x2 E_FULL
564 movz.x x8 63 0
565 svc 0
566 cmp.x.i x0 0
567 b.eq RDDONE
568 b.lt E_READ
569 add.x x12 x12 x0
570 b RD
571:RDDONE
572 add.x x18 x19 x12
573 movz.x x9 0x185 1
574 movz.x x10 0 0
575:ST0
576 str.x xzr x9 0
577 add.x.i x9 x9 8
578 add.x.i x10 x10 1
579 cmp.x.i x10 16
580 b.lo ST0
581; ---- program mode when some line is `fn main` (blanks, fn, blanks, main, then a blank or the end) ----
582 mov.x x10 x19
583:PS_LINE
584 cmp.x x10 x18
585 b.hs PS_DONE
586 ldrb w0 x10 0
587 cmp.w.i w0 32
588 b.eq PS_ADV
589 cmp.w.i w0 9
590 b.eq PS_ADV
591 cmp.w.i w0 102
592 b.ne PS_SKIP
593 add.x.i x12 x10 1
594 cmp.x x12 x18
595 b.hs PS_DONE
596 ldrb w0 x12 0
597 cmp.w.i w0 110
598 b.ne PS_SKIP
599 add.x.i x12 x12 1
600 mov.x x13 x12
601:PS_B
602 cmp.x x12 x18
603 b.hs PS_DONE
604 ldrb w0 x12 0
605 cmp.w.i w0 32
606 b.eq PS_B1
607 cmp.w.i w0 9
608 b.ne PS_M
609:PS_B1
610 add.x.i x12 x12 1
611 b PS_B
612:PS_M
613 cmp.x x12 x13
614 b.eq PS_SKIP
615 add.x.i x13 x12 4
616 cmp.x x13 x18
617 b.hi PS_SKIP
618 ldrb w0 x12 0
619 cmp.w.i w0 109
620 b.ne PS_SKIP
621 ldrb w0 x12 1
622 cmp.w.i w0 97
623 b.ne PS_SKIP
624 ldrb w0 x12 2
625 cmp.w.i w0 105
626 b.ne PS_SKIP
627 ldrb w0 x12 3
628 cmp.w.i w0 110
629 b.ne PS_SKIP
630 cmp.x x13 x18
631 b.hs PS_YES
632 ldrb w0 x13 0
633 cmp.w.i w0 32
634 b.hi PS_SKIP
635:PS_YES
636 movz.x x9 0x185 1
637 movz.x x0 1 0
638 str.x x0 x9 6
639 b PS_DONE
640:PS_ADV
641 add.x.i x10 x10 1
642 b PS_LINE
643:PS_SKIP
644 cmp.x x10 x18
645 b.hs PS_DONE
646 ldrb w0 x10 0
647 add.x.i x10 x10 1
648 cmp.w.i w0 10
649 b.ne PS_SKIP
650 b PS_LINE
651:PS_DONE
652 movz.x x21 0x100 1
653 add.x.i x20 x21 180
654 movz.x x22 1 0
655 movz.x x23 0 0
656 movz.x x24 0 0
657 movz.x x25 0x181 1
658 movz.x x26 0x182 1
659 movz.x x27 0 0
660 movz.x x28 0 0
661 adr x29 POOLC
662; ---- one statement per line ----
663:STMT
664 movz.x x9 0x185 1
665 ldr.x x10 x9 13
666 cbz.x x10 NS_INIT
667 cmp.x.i x10 1
668 b.eq NS_LINE
669 b BODY_LINE
670:NS_INIT
671 movz.x x10 1 0
672 str.x x10 x9 13
673:NS_LINE
674 bl TOK
675 cbz.x x0 NS_LINE
676 cmp.x.i x0 3
677 b.eq NS_DONE
678 cmp.x.i x0 1
679 b.ne S_NOTE
680 cmp.x.i x2 2
681 b.ne S_NOTE
682 movz.x x9 0x6e66 0
683 cmp.x x1 x9
684 b.eq S_FN
685 b S_NOTE
686:NS_DONE
687 movz.x x9 0x185 1
688 movz.x x10 2 0
689 str.x x10 x9 13
690 str.x xzr x9 3
691 movz.x x19 0x80 1
692 b PS_DONE
693:BODY_LINE
694 mov.x x24 x28
695 bl TOK
696 cbz.x x0 STMT
697 cmp.x.i x0 3
698 b.eq S_EOF
699 cmp.x.i x0 1
700 b.ne E_SYNTAX
701 cmp.x.i x2 8
702 b.hi S_LONG
703 mov.x x12 x1
704 bl KW
705 cmp.x.i x0 83
706 b.eq S_NOTE
707 cmp.x.i x0 64
708 b.eq S_FN
709 cbz.x x27 S_TOP
710 cmp.x.i x0 66
711 b.eq S_END
712 cmp.x.i x0 68
713 b.eq S_ELSE
714 movz.x x9 0x185 1
715 ldr.x x10 x9 5
716 cbnz.x x10 E_DEAD
717 cbz.x x0 S_NAME
718 cmp.x.i x0 67
719 b.eq S_IF
720 cmp.x.i x0 69
721 b.eq S_WHILE
722 cmp.x.i x0 71
723 b.eq S_FOR
724 cmp.x.i x0 72
725 b.eq S_RET
726 cmp.x.i x0 80
727 b.eq S_PUT
728 cmp.x.i x0 81
729 b.eq E_SUBSET ; free: no heap and nothing to give back (decision 24), so not a word
730 cmp.x.i x0 82
731 b.eq S_EXIT
732 cmp.x.i x0 77
733 b.eq E_SUBSET
734 cmp.x.i x0 78
735 b.eq E_SUBSET
736 cmp.x.i x0 79
737 b.eq E_SUBSET
738 b E_SYNTAX
739:S_TOP
740 cmp.x.i x0 78
741 b.eq S_GLOBAL
742 cmp.x.i x0 79
743 b.eq S_TEXT
744 b E_SYNTAX
745; ---- note ...: the rest of the line is not read ----
746:S_NOTE
747 cmp.x x19 x18
748 b.hs STMT
749 ldrb w0 x19 0
750 cmp.w.i w0 10
751 b.eq STMT
752 add.x.i x19 x19 1
753 b S_NOTE
754; ---- a name at the start of a line: a call of a void function, or name [=] value ----
755:S_NAME
756 mov.x x1 x12
757 bl FINDNAME
758 cbnz.x x0 S_ASSIGN
759 mov.x x1 x12
760 bl FINDFN
761 cbz.x x0 S_ASSIGN
762 ldr.w w9 x0 4
763 cmp.x.i x9 10
764 b.ne E_TYPE
765 movz.x x1 255 0
766 bl CALL
767 bl EOL
768 b STMT
769; ---- fn name (param type | param view T N | param edit T N)* to type | void ----
770:S_FN
771 cbnz.x x27 E_BLOCK
772 bl TOK
773 cmp.x.i x0 1
774 b.ne E_SYNTAX
775 cmp.x.i x2 63
776 b.hi E_LONG
777 mov.x x12 x1
778 bl KW
779 cbnz.x x0 E_SYNTAX
780 mov.x x1 x12
781 sub.x x3 x19 x2
782 movz.x x9 0x185 1
783 ldr.x x10 x9 13
784 cmp.x.i x10 2
785 b.eq FN_KNOWN
786 bl NEWNAME
787 movz.x x9 0x185 1
788 ldr.x x10 x9 2
789
790 cmp.x.i x10 4095
791 b.hi E_FULL
792 add.x.i x11 x10 1
793 str.x x11 x9 2
794 movz.x x11 0x19f 1
795 ubfm.x x10 x10 57 56
796 add.x x11 x11 x10
797 str.x x11 x9 3
798 str.x x11 x9 9
799 str.x x12 x11 0
800 str.x x20 x11 1
801 str.x xzr x11 2
802 str.w w2 x11 30
803 movz.x x16 0x80 1
804 sub.x x16 x3 x16
805 str.w w16 x11 31
806 b FN_SCOPE
807:FN_KNOWN
808 bl FINDFN
809 cbz.x x0 E_SYNTAX
810 movz.x x9 0x185 1
811 str.x x0 x9 3
812 str.x x0 x9 9
813 str.x x20 x0 1
814:FN_SCOPE
815 ldr.x x23 x9 1
816
817 movz.x x13 0 0
818:FN_P
819 bl TOK
820 cbz.x x0 E_FEW
821 cmp.x.i x0 1
822 b.ne E_SYNTAX
823 cmp.x.i x2 8
824 b.hi E_LONG
825 mov.x x12 x1
826 bl KW
827 cmp.x.i x0 65
828 b.eq FN_TO
829 cbnz.x x0 E_SYNTAX
830 mov.x x1 x12
831 bl NEWNAME
832 cmp.x.i x13 6
833 b.hs E_SUBSET
834 sub.x.i sp sp 48
835 str.x x12 sp 0
836 bl TOK
837 cmp.x.i x0 1
838 b.ne E_SYNTAX
839 cmp.x.i x2 8
840 b.hi E_SYNTAX
841 bl KW
842 cmp.x.i x0 57
843 b.eq FN_ARR
844 cmp.x.i x0 58
845 b.eq FN_ARR
846 sub.x.i x9 x0 1
847 cmp.x.i x9 8
848 b.hi E_SYNTAX
849 str.x x0 sp 1
850 str.x xzr sp 2
851 str.x xzr sp 3
852 b FN_ADD
853; an array parameter: view (kind 2) or edit (kind 3), element type, length (a number 1..2^24)
854:FN_ARR
855 sub.x.i x0 x0 55
856 str.x x0 sp 3
857 bl TYPEWORD
858 bl ELEMTYPE
859 str.x x0 sp 1
860 bl TOK
861 cbz.x x0 E_FEW
862 cmp.x.i x0 2
863 b.ne E_SYNTAX
864 bl ARRLEN
865 str.x x1 sp 2
866:FN_ADD
867 adr x9 POOLC
868 ldrb.r w2 x9 x13
869 ldr.x x1 sp 0
870 ldr.x x3 sp 1
871 ldr.x x4 sp 2
872 ldr.x x5 sp 3
873 movz.x x6 0 0
874 bl ADDNAME
875 movz.x x9 0x185 1
876 ldr.x x11 x9 3
877 ubfm.x x10 x13 60 59
878 add.x x11 x11 x10
879 ldr.x x0 sp 1
880 str.w w0 x11 6
881 ldr.x x0 sp 2
882 str.w w0 x11 7
883 ldr.x x0 sp 3
884 str.w w0 x11 8
885 add.x.i sp sp 48
886 add.x.i x13 x13 1
887 b FN_P
888:FN_TO
889 bl TOK
890 cbz.x x0 E_FEW
891 cmp.x.i x0 1
892 b.ne E_SYNTAX
893 cmp.x.i x2 8
894 b.hi E_SYNTAX
895 bl KW
896 cmp.x.i x0 76
897 b.eq FN_VOID
898 sub.x.i x9 x0 1
899 cmp.x.i x9 8
900 b.hi E_SYNTAX
901 mov.x x27 x0
902 b FN_T2
903:FN_VOID
904 movz.x x27 10 0
905:FN_T2
906 movz.x x9 0x185 1
907 ldr.x x11 x9 3
908 str.w w27 x11 4
909 str.w w13 x11 5
910 str.x xzr x9 4
911 str.x xzr x9 5
912 adr x29 POOLC
913 add.x x29 x29 x13
914 movz.x x24 0 0
915 movz.x x28 0 0
916 movz.x x25 0x181 1
917 movz.x x26 0x182 1
918 bl EOL
919 movz.x x9 0x185 1
920 ldr.x x10 x9 13
921 cmp.x.i x10 1
922 b.ne STMT
923 movz.x x27 0 0
924 movz.x x23 0 0
925 b STMT
926; ---- name [=] value, or name = new T N v (a local array) ----
927:S_ASSIGN
928 sub.x.i sp sp 64
929 str.x x12 sp 0
930 bl TOK
931 mov.x x3 x0
932 mov.x x4 x1
933 mov.x x5 x2
934 cmp.x.i x3 1
935 b.ne SA1
936 cmp.x.i x5 8
937 b.hi SA1
938 mov.x x1 x4
939 bl KW
940 cmp.x.i x0 73
941 b.ne SA1
942 bl TOK
943 mov.x x3 x0
944 mov.x x4 x1
945 mov.x x5 x2
946:SA1
947 cmp.x.i x3 1
948 b.ne SA1B
949 cmp.x.i x5 8
950 b.hi SA1B
951 mov.x x1 x4
952 bl KW
953 cmp.x.i x0 85
954 b.eq S_ENL
955:SA1B
956 ldr.x x1 sp 0
957 bl FINDNAME
958 cbz.x x0 SA_NEW
959 ldr.w w9 x0 5
960 cbnz.x x9 E_TYPE
961 ldr.w w1 x0 2
962 str.x x1 sp 1
963 ldr.w w0 x0 3
964 str.x x0 sp 2
965 bl VALTOK
966 ldr.x x9 sp 2
967 cmp.x x2 x9
968 b.ne E_TYPE
969 ldr.x x3 sp 1
970 bl FORCE
971 b SA_END
972:SA_NEW
973 ldr.x x1 sp 0
974 movz.x x2 0 0
975 bl FINDFN
976 cbnz.x x0 E_TWICE
977 cmp.x.i x3 1
978 b.ne SA2
979 cmp.x.i x5 8
980 b.hi SA2
981 mov.x x1 x4
982 bl KW
983 cmp.x.i x0 84
984 b.eq SA_ARR
985:SA2
986 bl ALLOC
987 mov.x x28 x24
988 str.x x0 sp 1
989 mov.x x1 x0
990 movz.x x0 0 0
991 bl VALTOK
992 cmp.x.i x0 2
993 b.eq E_BARE
994 str.x x2 sp 2
995 ldr.x x3 sp 1
996 bl FORCE
997 ldr.x x1 sp 0
998 ldr.x x2 sp 1
999 ldr.x x3 sp 2
1000 movz.x x4 0 0
1001 movz.x x5 0 0
1002 movz.x x6 0 0
1003 bl ADDNAME
1004:SA_END
1005 add.x.i sp sp 64
1006 bl EOL
1007 b STMT
1008; r = enlarge P n (omc.om s_enlarge): r an existing long scalar or a new one (error 7, error 10 for a function's
1009; name), P a run-time pool (error 7), n a ulong (error 7; a bare number error 11). The helper is emitted at the
1010; unit's first enlarge (ENHELP); then the registers in use are saved, X1 = n, X0 = P's slot, X2 = log2 of the
1011; element size, BL omc_enlarge (C6.2.43), and the result goes to r as the registers come back.
1012; Frame (S_ASSIGN's): 0 name, 1 entry (0 new), 2 r, 3 P, 4 pool slot before, 5 n, 6 saved count, 7 save bytes.
1013:S_ENL
1014 ldr.x x1 sp 0
1015 bl FINDNAME
1016 str.x x0 sp 1
1017 cbz.x x0 SE_NEW
1018 ldr.w w9 x0 5
1019 cbnz.x x9 E_TYPE
1020 ldr.w w9 x0 3
1021 cmp.x.i x9 9
1022 b.ne E_TYPE
1023 ldr.w w9 x0 2
1024 str.x x9 sp 2
1025 b SE_HELP
1026:SE_NEW
1027 ldr.x x1 sp 0
1028 movz.x x2 0 0
1029 bl FINDFN
1030 cbnz.x x0 E_TWICE
1031 bl ALLOC
1032 str.x x0 sp 2
1033 mov.x x28 x24
1034:SE_HELP
1035 bl ENHELP
1036 bl ARRNAME
1037 ldr.w w9 x0 5
1038 cmp.x.i x9 10
1039 b.ne E_TYPE
1040 str.x x0 sp 3
1041 str.x x24 sp 4
1042 movz.x x0 5 0
1043 movz.x x1 255 0
1044 bl VAL
1045 cmp.x.i x0 2
1046 b.eq E_BARE
1047 cmp.x.i x2 5
1048 b.ne E_TYPE
1049 bl MATREG
1050 str.x x0 sp 5
1051 bl SAVE
1052 str.x x0 sp 6
1053 str.x x1 sp 7
1054 movz.x x0 1 0
1055 movz.x x1 1 0
1056 ldr.x x2 sp 5
1057 bl LOADARG
1058 movz.x x0 0 0
1059 ldr.x x9 sp 3
1060 ldr.x x1 x9 3
1061 bl MATCONST
1062 ldr.x x9 sp 3
1063 ldr.w w9 x9 3
1064 adr x10 TLOG
1065 ldrb.r w1 x10 x9
1066 movz.x x0 2 0
1067 bl MATCONST
1068 movz.x x9 0x185 1
1069 ldr.x x10 x9 14
1070 sub.x x10 x10 x20
1071 ubfm.x x10 x10 2 27
1072 movz.x x0 0 0
1073 movk.x x0 0x9400 1 ; BL omc_enlarge (behind: a negative imm26), C6.2.43
1074 orr.x x0 x0 x10
1075 bl EMIT
1076 ldr.x x0 sp 2
1077 ldr.x x1 sp 4
1078 ldr.x x2 sp 6
1079 ldr.x x3 sp 7
1080 movz.x x4 1 0
1081 bl RESTORE
1082 str.x x0 sp 2
1083 ldr.x x9 sp 1
1084 cbnz.x x9 SA_END
1085 ldr.x x1 sp 0
1086 ldr.x x2 sp 2
1087 movz.x x3 9 0
1088 movz.x x4 0 0
1089 movz.x x5 0 0
1090 movz.x x6 0 0
1091 bl ADDNAME
1092 b SA_END
1093; ---- envcnt / envread (OMEGESE 10; omc.om hostval and hargs, c 136 and 137): program mode only (error 9).
1094; X27 holds the initial stack (argc, argv, 0, envp..., 0): the start code keeps it when state slot 15 is set.
1095; envcnt: SAVE, walk envp to its null (words ENVCNTW), RESTORE: a long. envread index A off capacity: index a
1096; ulong, A a writable uchar array (error 7 or 20), off and capacity ulong; capacity <= len A and off <= len A -
1097; capacity (CMP, B.HI trap 3, as read); then SAVE, X0 = index, the scan (an index at or past the count traps 3),
1098; the entry's length (an entry of 1 MiB or more traps 3), the copy, or -105 when capacity is short; RESTORE.
1099; Frame (VALTOK's): 2 dest, 4/5 index, 6 A, 7/8 off, 9/10 capacity, 11 small, 12/13 SAVE, 14 pool slot, 15 endbr.
1100:VT_ENVCNT
1101 movz.x x9 0x185 1
1102 ldr.x x10 x9 6
1103 cbz.x x10 E_SUBSET
1104 movz.x x10 1 0
1105 str.x x10 x9 15
1106 str.x x24 sp 14
1107 bl SAVE
1108 str.x x0 sp 12
1109 str.x x1 sp 13
1110 adr x10 ENVCNTW
1111 movz.x x11 11 0
1112 bl EMITN
1113 b VE_RET
1114:VT_ENVREAD
1115 movz.x x9 0x185 1
1116 ldr.x x10 x9 6
1117 cbz.x x10 E_SUBSET
1118 movz.x x10 1 0
1119 str.x x10 x9 15
1120 str.x x24 sp 14
1121 movz.x x0 5 0
1122 movz.x x1 255 0
1123 bl VAL
1124 cmp.x.i x2 5
1125 b.ne E_TYPE
1126 str.x x0 sp 4
1127 str.x x1 sp 5
1128 bl ARRNAME
1129 ldr.w w9 x0 5
1130 cmp.x.i x9 10
1131 b.eq E_TYPE
1132 ldr.w w9 x0 3
1133 cmp.x.i x9 2
1134 b.ne E_TYPE
1135 ldr.w w9 x0 5
1136 cmp.x.i x9 2
1137 b.eq E_RDONLY
1138 cmp.x.i x9 5
1139 b.eq E_RDONLY
1140 str.x x0 sp 6
1141 movz.x x0 5 0
1142 movz.x x1 255 0
1143 bl VAL
1144 cmp.x.i x2 5
1145 b.ne E_TYPE
1146 str.x x0 sp 7
1147 str.x x1 sp 8
1148 movz.x x0 5 0
1149 movz.x x1 255 0
1150 bl VAL
1151 cmp.x.i x2 5
1152 b.ne E_TYPE
1153 str.x x0 sp 9
1154 str.x x1 sp 10
1155 ldr.x x0 sp 7
1156 ldr.x x1 sp 8
1157 movz.x x2 5 0
1158 bl MATREG
1159 str.x x0 sp 7
1160 ldr.x x0 sp 9
1161 ldr.x x1 sp 10
1162 movz.x x2 5 0
1163 bl MATREG
1164 str.x x0 sp 9
1165 bl ALLOC
1166 str.x x0 sp 11
1167 ldr.x x9 sp 6
1168 ldr.w w1 x9 4
1169 bl MATCONST
1170 movz.x x0 0x001f 0
1171 movk.x x0 0xeb00 1 ; CMP Xcap, Xt, C6.2.97
1172 ldr.x x1 sp 9
1173 ubfm.x x1 x1 59 58
1174 orr.x x0 x0 x1
1175 ldr.x x1 sp 11
1176 ubfm.x x1 x1 48 47
1177 orr.x x0 x0 x1
1178 bl EMIT
1179 movz.x x0 8 0
1180 movz.x x1 3 0
1181 bl TRAPC
1182 movz.x x0 0 0
1183 movk.x x0 0xcb00 1 ; SUB Xt, Xt, Xcap, C6.2.458
1184 ldr.x x1 sp 11
1185 ldr.x x2 sp 11
1186 ldr.x x3 sp 9
1187 bl E3
1188 movz.x x0 0x001f 0
1189 movk.x x0 0xeb00 1 ; CMP Xoff, Xt, C6.2.97
1190 ldr.x x1 sp 7
1191 ubfm.x x1 x1 59 58
1192 orr.x x0 x0 x1
1193 ldr.x x1 sp 11
1194 ubfm.x x1 x1 48 47
1195 orr.x x0 x0 x1
1196 bl EMIT
1197 movz.x x0 8 0
1198 movz.x x1 3 0
1199 bl TRAPC
1200 bl SAVE
1201 str.x x0 sp 12
1202 str.x x1 sp 13
1203 movz.x x0 0 0
1204 ldr.x x1 sp 4
1205 ldr.x x2 sp 5
1206 bl LOADARG
1207 adr x10 ENVR1
1208 movz.x x11 10 0
1209 bl EMITN
1210 movz.x x0 0 0
1211 movz.x x1 3 0
1212 bl TRAPC
1213 adr x10 ENVR2
1214 movz.x x11 5 0
1215 bl EMITN
1216 movz.x x0 0 0
1217 movz.x x1 3 0
1218 bl TRAPC
1219 adr x10 ENVR3
1220 movz.x x11 9 0
1221 bl EMITN
1222 movz.x x0 2 0
1223 movz.x x1 3 0
1224 bl TRAPC
1225 adr x10 ENVR4
1226 movz.x x11 1 0
1227 bl EMITN
1228 movz.x x0 2 0
1229 movz.x x1 1 0
1230 ldr.x x2 sp 9
1231 bl LOADARG
1232 adr x10 ENVR5
1233 movz.x x11 2 0
1234 bl EMITN
1235 sub.x.i x9 x20 4
1236 str.x x9 sp 11
1237 movz.x x0 0 0
1238 ldr.x x9 sp 6
1239 bl BASEARG
1240 movz.x x0 16 0
1241 movz.x x1 1 0
1242 ldr.x x2 sp 7
1243 bl LOADARG
1244 adr x10 ENVR6
1245 movz.x x11 12 0
1246 bl EMITN
1247 sub.x.i x9 x20 4
1248 str.x x9 sp 15
1249 ldr.x x0 sp 11
1250 mov.x x1 x20
1251 bl PATCH19
1252 movz.x x0 0 0
1253 movz.x x1 0xff97 0
1254 movk.x x1 0xffff 1
1255 movk.x x1 0xffff 2
1256 movk.x x1 0xffff 3 ; -105
1257 bl MATCONST
1258 ldr.x x0 sp 15
1259 sub.x x10 x20 x0
1260 ubfm.x x10 x10 2 63
1261 ldr.w w11 x0 0
1262 orr.x x11 x11 x10
1263 str.w w11 x0 0
1264:VE_RET
1265 ldr.x x0 sp 2
1266 ldr.x x1 sp 14
1267 ldr.x x2 sp 12
1268 ldr.x x3 sp 13
1269 movz.x x4 1 0
1270 bl RESTORE
1271 mov.x x1 x0
1272 movz.x x0 1 0
1273 movz.x x2 9 0
1274 b VT_RET
1275; EMITN: x11 words from x10 to the output. Clobbers x0, x9..x12.
1276:EMITN
1277 str.x.pre x30 sp -16
1278 mov.x x12 x10
1279:EN1
1280 cbz.x x11 EN2
1281 ldr.w w0 x12 0
1282 bl EMIT
1283 add.x.i x12 x12 4
1284 sub.x.i x11 x11 1
1285 b EN1
1286:EN2
1287 ldr.x.post x30 sp 16
1288 ret
1289:ENVCNTW
1290 .w 0xf9400361
1291 .w 0x91000821
1292 .w 0xd37df021
1293 .w 0x8b010360
1294 .w 0xd2800002
1295 .w 0xf9400003
1296 .w 0xb4000083
1297 .w 0x91000442
1298 .w 0x91002000
1299 .w 0x17fffffc
1300 .w 0xaa0203e0
1301:ENVR1
1302 .w 0xaa0003e2
1303 .w 0xf9400361
1304 .w 0x91000821
1305 .w 0xaa0103e0
1306 .w 0xd2800110
1307 .w 0x9b107c00
1308 .w 0x8b000363
1309 .w 0xb40000e2
1310 .w 0xf9400064
1311 .w 0xf100009f
1312:ENVR2
1313 .w 0x91002063
1314 .w 0xd1000442
1315 .w 0x17fffffa
1316 .w 0xf9400063
1317 .w 0xf100007f
1318:ENVR3
1319 .w 0xaa0303e4
1320 .w 0xd2800005
1321 .w 0x39400086
1322 .w 0xf10000df
1323 .w 0x540000e0
1324 .w 0x91000484
1325 .w 0x910004a5
1326 .w 0xd2a00210
1327 .w 0xeb1000bf
1328:ENVR4
1329 .w 0x17fffff8
1330:ENVR5
1331 .w 0xeb0200bf
1332 .w 0x54000008
1333:ENVR6
1334 .w 0x8b100000
1335 .w 0xaa0503e2
1336 .w 0xf10000bf
1337 .w 0x540000e0
1338 .w 0x39400066
1339 .w 0x39000006
1340 .w 0x91000463
1341 .w 0x91000400
1342 .w 0xd10004a5
1343 .w 0x17fffff9
1344 .w 0xaa0203e0
1345 .w 0x14000000
1346; ENHELP: the unit's omc_enlarge helper, emitted once at the unit's first enlarge behind a B over it (C6.2.35),
1347; word for word omc.om en_help (docs/RUNTIME-POOLS.md s4: X0 the slot, X1 n, X2 log2 of the element size; out
1348; X0 0, -22 or the host's -errno). State slot 14 keeps the address of its first word. Clobbers x0, x9..x11.
1349:ENHELP
1350 movz.x x9 0x185 1
1351 ldr.x x10 x9 14
1352 cbnz.x x10 EH2
1353 str.x.pre x30 sp -16
1354 movz.x x11 0 0
1355:EH1
1356 adr x10 ENWORDS
1357 ldr.w.r w0 x10 x11
1358 bl EMIT
1359 cbnz.x x11 EH3
1360 movz.x x9 0x185 1
1361 str.x x20 x9 14
1362:EH3
1363 add.x.i x11 x11 1
1364 cmp.x.i x11 42
1365 b.lo EH1
1366 ldr.x.post x30 sp 16
1367:EH2
1368 ret
1369; ENWORDS: the B over the helper (+42 words), then the helper's 41 words (omc.om en_help)
1370:ENWORDS
1371 .w 0x1400002a
1372 .w 0xaa0003e9
1373 .w 0xaa0103ea
1374 .w 0xf9400523
1375 .w 0xeb03015f
1376 .w 0x54000429
1377 .w 0xd28007e4
1378 .w 0xcb020084
1379 .w 0x9ac42545
1380 .w 0xb50003e5
1381 .w 0x9ac22145
1382 .w 0x913ffca5
1383 .w 0x9274cca5
1384 .w 0x9ac22066
1385 .w 0x913ffcc6
1386 .w 0x9274ccc6
1387 .w 0xeb0600bf
1388 .w 0x54000289
1389 .w 0xb4000106
1390 .w 0xf9400120
1391 .w 0xaa0603e1
1392 .w 0xaa0503e2
1393 .w 0xd2800023
1394 .w 0xd2801b08
1395 .w 0xd4000001
1396 .w 0x14000009
1397 .w 0xd2800000
1398 .w 0xaa0503e1
1399 .w 0xd2800062
1400 .w 0xd2800443
1401 .w 0x92800004
1402 .w 0xd2800005
1403 .w 0xd2801bc8
1404 .w 0xd4000001
1405 .w 0xb13ffc1f
1406 .w 0x54000082
1407 .w 0xf9000120
1408 .w 0xf900052a
1409 .w 0xd2800000
1410 .w 0xd65f03c0
1411 .w 0x928002a0
1412 .w 0xd65f03c0
1413; x = new T N v: N elements of type T on the stack, each set to v; only in the function's outermost block,
1414; so the stack held by local arrays is known at every ret. SUB SP (C6.2.457); program mode: CMP SP, X28
1415; (SUBS extended, C6.2.463), B.LO trap 6; MOV Xb, SP (ADD immediate, C6.2.5); then the fill loop.
1416:SA_ARR
1417 movz.x x9 0x181 1
1418 cmp.x x25 x9
1419 b.ne E_SUBSET
1420 bl TYPEWORD
1421 bl ELEMTYPE
1422 str.x x0 sp 2
1423 bl TOK
1424 cmp.x.i x0 2
1425 b.ne E_SYNTAX
1426 bl ARRLEN
1427 str.x x1 sp 3
1428 ldr.x x2 sp 2
1429 adr x9 TLOG
1430 ldrb.r w9 x9 x2
1431 lslv.x x1 x1 x9
1432 add.x.i x1 x1 15
1433 ubfm.x x1 x1 4 63
1434 ubfm.x x1 x1 60 59
1435 str.x x1 sp 4
1436 movz.x x9 0x185 1
1437 ldr.x x10 x9 4
1438 add.x x10 x10 x1
1439 movz.x x11 0x40 1
1440 cmp.x x10 x11
1441 b.hi E_TOOBIG
1442 str.x x10 x9 4
1443 bl ALLOC
1444 mov.x x28 x24
1445 str.x x0 sp 1
1446 ldr.x x0 sp 2
1447 movz.x x1 255 0
1448 bl VAL
1449 ldr.x x9 sp 2
1450 cmp.x x2 x9
1451 b.ne E_TYPE
1452 bl MATREG
1453 str.x x0 sp 5
1454 ldr.x x1 sp 4
1455 bl SPSUB
1456 bl STKCHK
1457 movz.x x0 0x03e0 0
1458 movk.x x0 0x9100 1 ; MOV Xb, SP = ADD Xb, SP, #0, C6.2.5 / C6.2.278
1459 ldr.x x1 sp 1
1460 orr.x x0 x0 x1
1461 bl EMIT
1462 bl ALLOC
1463 str.x x0 sp 6
1464 movz.x x9 0xd280 1 ; MOVZ Xi, #0, C6.2.285
1465 orr.x x0 x0 x9
1466 bl EMIT
1467 ldr.x x1 sp 3
1468 movz.x x9 4095 0
1469 cmp.x x1 x9
1470 b.ls SAA1
1471 bl ALLOC
1472 str.x x0 sp 7
1473 ldr.x x1 sp 3
1474 bl MATCONST
1475:SAA1
1476 str.x x20 sp 4
1477 ldr.x x9 sp 2
1478 adr x10 STOP
1479 ldr.w.r w0 x10 x9
1480 ldr.x x1 sp 5
1481 orr.x x0 x0 x1
1482 ldr.x x1 sp 1
1483 ubfm.x x1 x1 59 58
1484 orr.x x0 x0 x1
1485 ldr.x x1 sp 6
1486 ubfm.x x1 x1 48 47
1487 orr.x x0 x0 x1
1488 bl EMIT
1489 movz.x x0 0x0400 0
1490 movk.x x0 0x9100 1 ; ADD Xi, Xi, #1, C6.2.5
1491 ldr.x x1 sp 6
1492 orr.x x0 x0 x1
1493 ubfm.x x1 x1 59 58
1494 orr.x x0 x0 x1
1495 bl EMIT
1496 ldr.x x1 sp 3
1497 movz.x x9 4095 0
1498 cmp.x x1 x9
1499 b.hi SAA2
1500 movz.x x0 0x001f 0
1501 movk.x x0 0xf100 1 ; CMP Xi, #N, C6.2.96
1502 ubfm.x x1 x1 54 53
1503 orr.x x0 x0 x1
1504 b SAA3
1505:SAA2
1506 movz.x x0 0x001f 0
1507 movk.x x0 0xeb00 1 ; CMP Xi, Xn, C6.2.97
1508 ldr.x x1 sp 7
1509 ubfm.x x1 x1 48 47
1510 orr.x x0 x0 x1
1511:SAA3
1512 ldr.x x1 sp 6
1513 ubfm.x x1 x1 59 58
1514 orr.x x0 x0 x1
1515 bl EMIT
1516 ldr.x x0 sp 4
1517 sub.x x2 x0 x20
1518 ubfm.x x2 x2 2 20
1519 ubfm.x x2 x2 59 58
1520 movz.x x0 0x0003 0
1521 movk.x x0 0x5400 1 ; B.LO back to the store, C6.2.34
1522 orr.x x0 x0 x2
1523 bl EMIT
1524 ldr.x x1 sp 0
1525 ldr.x x2 sp 1
1526 ldr.x x3 sp 2
1527 ldr.x x4 sp 3
1528 movz.x x5 1 0
1529 movz.x x6 0 0
1530 bl ADDNAME
1531 b SA_END
1532; ---- ret [value]: the value into x0, give back the local arrays' stack, RET ----
1533:S_RET
1534 cmp.x.i x27 10
1535 b.eq SR_V
1536 mov.x x0 x27
1537 movz.x x1 0 0
1538 bl VAL
1539 cmp.x x2 x27
1540 b.ne E_TYPE
1541 movz.x x3 0 0
1542 bl FORCE
1543 bl EPI
1544 bl DEAD1
1545 bl EOL
1546 b STMT
1547:SR_V
1548 bl EOL
1549 bl EPI
1550 bl DEAD1
1551 b STMT
1552; ---- exit value (int): Linux exit (system call 93, C6.2.466 SVC); the path ends ----
1553:S_EXIT
1554 movz.x x0 8 0
1555 movz.x x1 255 0
1556 bl VAL
1557 cmp.x.i x2 8
1558 b.ne E_TYPE
1559 movz.x x3 0 0
1560 bl FORCE
1561 movz.x x0 0x0ba8 0
1562 movk.x x0 0xd280 1 ; MOVZ X8, #93, C6.2.285
1563 bl EMIT
1564 movz.x x0 0x0001 0
1565 movk.x x0 0xd400 1 ; SVC #0, C6.2.466
1566 bl EMIT
1567 bl DEAD1
1568 bl EOL
1569 b STMT
1570; ---- put A i v: index, then value, then the checked store ----
1571:S_PUT
1572 sub.x.i sp sp 64
1573 bl ARRNAME
1574 str.x x0 sp 0
1575 ldr.w w9 x0 5
1576 cmp.x.i x9 2
1577 b.eq E_RDONLY
1578 cmp.x.i x9 5
1579 b.eq E_RDONLY
1580 movz.x x0 5 0
1581 movz.x x1 255 0
1582 bl VAL
1583 str.x x0 sp 1
1584 str.x x1 sp 2
1585 str.x x2 sp 3
1586 ldr.x x9 sp 0
1587 ldr.w w0 x9 3
1588 movz.x x1 255 0
1589 bl VAL
1590 ldr.x x9 sp 0
1591 ldr.w w9 x9 3
1592 cmp.x x2 x9
1593 b.ne E_TYPE
1594 bl MATREG
1595 str.x x0 sp 4
1596 ldr.x x0 sp 0
1597 ldr.x x1 sp 1
1598 ldr.x x2 sp 2
1599 ldr.x x3 sp 3
1600 bl ELEMADDR
1601 ldr.x x9 sp 0
1602 ldr.w w9 x9 3
1603 adr x10 STOP
1604 ldr.w.r w2 x10 x9
1605 ldr.x x3 sp 4
1606 orr.x x2 x2 x3
1607 ubfm.x x0 x0 59 58
1608 orr.x x2 x2 x0
1609 ubfm.x x1 x1 48 47
1610 orr.x x0 x2 x1
1611 bl EMIT
1612 add.x.i sp sp 64
1613 bl EOL
1614 b STMT
1615; ---- global NAME T N: a fixed pool of N elements, zero at start, in the read/write part of the program
1616; image after the 8 MiB stack pool (address 0x10800000 + pool bytes so far); at most 1 GiB of pools ----
1617:S_GLOBAL
1618 bl TOPNAME
1619 bl TYPEWORD
1620 bl ELEMTYPE
1621 mov.x x13 x0
1622 bl TOK
1623 cmp.x.i x0 1
1624 b.ne SG1
1625 cmp.x.i x2 1
1626 b.ne SG1
1627 cmp.x.i x1 42
1628 b.eq SG_POOL
1629:SG1
1630 cmp.x.i x0 2
1631 b.ne E_SYNTAX
1632 bl ARRLEN
1633 mov.x x14 x1
1634 adr x9 TLOG
1635 ldrb.r w9 x9 x13
1636 lslv.x x1 x1 x9
1637 add.x.i x1 x1 15
1638 ubfm.x x1 x1 4 63
1639 ubfm.x x1 x1 60 59
1640 movz.x x9 0x185 1
1641 ldr.x x10 x9 7
1642 movz.x x6 0x1080 1
1643 add.x x6 x6 x10
1644 add.x x10 x10 x1
1645 movz.x x11 0x4000 1
1646 cmp.x x10 x11
1647 b.hi E_TOOBIG
1648 str.x x10 x9 7
1649 mov.x x1 x12
1650 movz.x x2 0 0
1651 mov.x x3 x13
1652 mov.x x4 x14
1653 movz.x x5 4 0
1654 bl ADDNAME
1655 movz.x x9 0x185 1
1656 str.x x23 x9 1
1657 bl EOL
1658 b STMT
1659; global NAME T *: a run-time pool (kind 10, length 0 at start), program mode only (error 9); its 16-byte
1660; slot (base, length) is taken from the global pool area like any global's elements (omc.om sg_pool)
1661:SG_POOL
1662 movz.x x9 0x185 1
1663 ldr.x x10 x9 6
1664 cbz.x x10 E_SUBSET
1665 ldr.x x10 x9 7
1666 movz.x x6 0x1080 1
1667 add.x x6 x6 x10
1668 add.x.i x10 x10 16
1669 movz.x x11 0x4000 1
1670 cmp.x x10 x11
1671 b.hi E_TOOBIG
1672 str.x x10 x9 7
1673 mov.x x1 x12
1674 movz.x x2 0 0
1675 mov.x x3 x13
1676 movz.x x4 0 0
1677 movz.x x5 10 0
1678 bl ADDNAME
1679 movz.x x9 0x185 1
1680 str.x x23 x9 1
1681 bl EOL
1682 b STMT
1683; ---- text NAME "...": read-only bytes in the program image (escapes \n \t \\ \"), with their length ----
1684:S_TEXT
1685 bl TOPNAME
1686 bl TOK
1687 cmp.x.i x0 4
1688 b.ne E_SYNTAX
1689 sub.x x6 x20 x21
1690 movz.x x9 0x40 1
1691 add.x x6 x6 x9
1692 add.x x2 x1 x2
1693 movz.x x14 0 0
1694:TX1
1695 cmp.x x1 x2
1696 b.hs TX4
1697 ldrb w0 x1 0
1698 add.x.i x1 x1 1
1699 cmp.w.i w0 92
1700 b.ne TX3
1701 ldrb w0 x1 0
1702 add.x.i x1 x1 1
1703 cmp.w.i w0 110
1704 b.ne TXa
1705 movz.x x0 10 0
1706 b TX3
1707:TXa
1708 cmp.w.i w0 116
1709 b.ne TXb
1710 movz.x x0 9 0
1711 b TX3
1712:TXb
1713 cmp.w.i w0 92
1714 b.eq TX3
1715 cmp.w.i w0 34
1716 b.ne E_TEXT
1717:TX3
1718 bl EMITB
1719 add.x.i x14 x14 1
1720 b TX1
1721:TX4
1722 ubfm.x x9 x20 0 1
1723 cbz.x x9 TX5
1724 movz.x x0 0 0
1725 bl EMITB
1726 b TX4
1727:TX5
1728 mov.x x1 x12
1729 movz.x x2 0 0
1730 movz.x x3 2 0
1731 mov.x x4 x14
1732 movz.x x5 5 0
1733 bl ADDNAME
1734 movz.x x9 0x185 1
1735 str.x x23 x9 1
1736 bl EOL
1737 b STMT
1738:S_IF
1739 bl COND
1740 movz.x x1 1 0
1741 movz.x x2 0 0
1742 movz.x x3 0 0
1743 movz.x x4 0 0
1744 mov.x x5 x23
1745 mov.x x6 x28
1746 bl PUSHB
1747 bl EOL
1748 b STMT
1749; ---- else: jump over the else part; the if's false branch lands after that jump ----
1750:S_ELSE
1751 movz.x x9 0x181 1
1752 cmp.x x25 x9
1753 b.eq E_BLOCK
1754 sub.x.i x10 x25 128
1755 ldr.x x0 x10 0
1756 cmp.x.i x0 1
1757 b.ne E_BLOCK
1758 mov.x x11 x20
1759 movz.x x0 0x1400 1 ; B (distance filled at end), C6.2.35
1760 bl EMIT
1761 ldr.x x0 x10 1
1762 mov.x x1 x20
1763 bl PATCH19
1764 movz.x x0 2 0
1765 str.x x0 x10 0
1766 str.x x11 x10 1
1767 ldr.x x23 x10 5
1768 ldr.x x28 x10 6
1769 movz.x x9 0x185 1
1770 ldr.x x11 x9 5
1771 str.x x11 x10 7
1772 str.x xzr x9 5
1773 bl EOL
1774 b STMT
1775; ---- while cond [bound N]: hidden counter = 0; head: cond false -> exit; counter >= N -> trap 4;
1776; counter = counter + 1; body; B head ----
1777:S_WHILE
1778 sub.x.i sp sp 64
1779 str.x x23 sp 0
1780 str.x x28 sp 1
1781 bl ALLOC
1782 mov.x x28 x24
1783 str.x x0 sp 2
1784 movz.x x9 0xd280 1 ; MOVZ Xc, #0, C6.2.285
1785 orr.x x0 x0 x9
1786 bl EMIT
1787 str.x x20 sp 3
1788 bl COND
1789 str.x x0 sp 4
1790 movz.x x9 0x4240 0
1791 movk.x x9 0x000f 1
1792 str.x x9 sp 5
1793 bl TOK
1794 cbz.x x0 SW_NOB
1795 cmp.x.i x0 3
1796 b.eq SW_NOB
1797 cmp.x.i x0 1
1798 b.ne E_EXTRA
1799 cmp.x.i x2 8
1800 b.hi E_EXTRA
1801 bl KW
1802 cmp.x.i x0 70
1803 b.ne E_EXTRA
1804 bl TOK
1805 cbz.x x0 E_FEW
1806 cmp.x.i x0 2
1807 b.ne E_SYNTAX
1808 sub.x.i x9 x1 1
1809 movz.x x10 0x423f 0
1810 movk.x x10 0x000f 1
1811 cmp.x x9 x10
1812 b.hs E_RANGE
1813 str.x x1 sp 5
1814 bl EOL
1815:SW_NOB
1816 ldr.x x1 sp 5
1817 movz.x x9 4095 0
1818 cmp.x x1 x9
1819 b.hi SW_BIG
1820 movz.x x0 0x001f 0
1821 movk.x x0 0xf100 1 ; CMP Xc, #N = SUBS XZR, Xc, #N, C6.2.96
1822 ubfm.x x1 x1 54 53
1823 orr.x x0 x0 x1
1824 ldr.x x1 sp 2
1825 ubfm.x x1 x1 59 58
1826 orr.x x0 x0 x1
1827 bl EMIT
1828 b SW_G
1829:SW_BIG
1830 bl ALLOC
1831 mov.x x13 x0
1832 ldr.x x1 sp 5
1833 bl MATCONST
1834 movz.x x0 0x001f 0
1835 movk.x x0 0xeb00 1 ; CMP Xc, Xn = SUBS XZR, Xc, Xn, C6.2.97
1836 ldr.x x1 sp 2
1837 ubfm.x x1 x1 59 58
1838 orr.x x0 x0 x1
1839 ubfm.x x1 x13 48 47
1840 orr.x x0 x0 x1
1841 bl EMIT
1842:SW_G
1843 movz.x x0 2 0
1844 movz.x x1 4 0
1845 bl TRAPC
1846 movz.x x0 0x0400 0
1847 movk.x x0 0x9100 1 ; ADD Xc, Xc, #1, C6.2.5
1848 ldr.x x1 sp 2
1849 orr.x x0 x0 x1
1850 ubfm.x x1 x1 59 58
1851 orr.x x0 x0 x1
1852 bl EMIT
1853 ldr.x x0 sp 4
1854 movz.x x1 3 0
1855 ldr.x x2 sp 3
1856 ldr.x x3 sp 2
1857 movz.x x4 0 0
1858 ldr.x x5 sp 0
1859 ldr.x x6 sp 1
1860 bl PUSHB
1861 add.x.i sp sp 64
1862 b STMT
1863; ---- for i T K (K a number): i = 0; head: not i < K -> exit; body; latch i = add i 1; B head ----
1864; ---- for i T K: i = 0; head: not i < K -> exit; body; latch i = add i 1; B head. K a number, or a value
1865; of type T: a name is read at every pass, another value once before the loop; then the hidden counter
1866; guard of a while with no bound (trap 4 after 1000000 passes) ----
1867:S_FOR
1868 sub.x.i sp sp 80
1869 str.x x23 sp 0
1870 str.x x28 sp 1
1871 bl TOK
1872 cbz.x x0 E_FEW
1873 cmp.x.i x0 1
1874 b.ne E_SYNTAX
1875 cmp.x.i x2 8
1876 b.hi E_LONG
1877 str.x x1 sp 2
1878 bl KW
1879 cbnz.x x0 E_SYNTAX
1880 ldr.x x1 sp 2
1881 bl NEWNAME
1882 bl TYPEWORD
1883 str.x x0 sp 3
1884 cmp.x.i x0 1
1885 b.eq E_TYPE
1886 bl TOK
1887 cbz.x x0 E_FEW
1888 cmp.x.i x0 2
1889 b.ne SF_VAL
1890 ldr.x x2 sp 3
1891 movz.x x9 0x185 1
1892 ldr.x x3 x9 11
1893 bl RANGE
1894 str.x x1 sp 4
1895:SF_NUM
1896 bl EOL
1897 bl ALLOC
1898 mov.x x28 x24
1899 str.x x0 sp 5
1900 mov.x x2 x0
1901 ldr.x x1 sp 2
1902 ldr.x x3 sp 3
1903 movz.x x4 0 0
1904 movz.x x5 0 0
1905 movz.x x6 0 0
1906 bl ADDNAME
1907 ldr.x x0 sp 5
1908 movz.x x9 0xd280 1 ; MOVZ Xi, #0, C6.2.285
1909 orr.x x0 x0 x9
1910 bl EMIT
1911 str.x x20 sp 6
1912 ldr.x x1 sp 4
1913 movz.x x9 4095 0
1914 cmp.x x1 x9
1915 b.hi SF_BIG
1916 movz.x x0 0x001f 0
1917 movk.x x0 0xf100 1 ; CMP Xi, #K, C6.2.96
1918 ubfm.x x1 x1 54 53
1919 orr.x x0 x0 x1
1920 ldr.x x1 sp 5
1921 ubfm.x x1 x1 59 58
1922 orr.x x0 x0 x1
1923 bl EMIT
1924 b SF_B
1925:SF_BIG
1926 bl ALLOC
1927 mov.x x13 x0
1928 ldr.x x1 sp 4
1929 bl MATCONST
1930 mov.x x1 x13
1931 b SF_CMPR
1932; a value count
1933:SF_VAL
1934 mov.x x3 x0
1935 mov.x x4 x1
1936 mov.x x5 x2
1937 ldr.x x0 sp 3
1938 movz.x x1 255 0
1939 bl VALTOK
1940 cmp.x.i x0 3
1941 b.eq SF_TYPED
1942 ldr.x x9 sp 3
1943 cmp.x x2 x9
1944 b.ne E_TYPE
1945 bl MATREG
1946 str.x x0 sp 7
1947 bl EOL
1948 bl ALLOC
1949 mov.x x28 x24
1950 str.x x0 sp 5
1951 mov.x x2 x0
1952 ldr.x x1 sp 2
1953 ldr.x x3 sp 3
1954 movz.x x4 0 0
1955 movz.x x5 0 0
1956 movz.x x6 0 0
1957 bl ADDNAME
1958 ldr.x x0 sp 5
1959 movz.x x9 0xd280 1 ; MOVZ Xi, #0, C6.2.285
1960 orr.x x0 x0 x9
1961 bl EMIT
1962 bl ALLOC
1963 mov.x x28 x24
1964 str.x x0 sp 8
1965 movz.x x9 0xd280 1 ; MOVZ Xc, #0 (the hidden counter), C6.2.285
1966 orr.x x0 x0 x9
1967 bl EMIT
1968 str.x x20 sp 6
1969 ldr.x x1 sp 7
1970 movz.x x0 0x001f 0
1971 movk.x x0 0xeb00 1 ; CMP Xi, Xn, C6.2.97
1972 ubfm.x x1 x1 48 47
1973 orr.x x0 x0 x1
1974 ldr.x x1 sp 5
1975 ubfm.x x1 x1 59 58
1976 orr.x x0 x0 x1
1977 bl EMIT
1978 bl SF_BR
1979 str.x x0 sp 9
1980 bl ALLOC
1981 mov.x x13 x0
1982 movz.x x1 0x4240 0
1983 movk.x x1 0x000f 1
1984 bl MATCONST
1985 movz.x x0 0x001f 0
1986 movk.x x0 0xeb00 1 ; CMP Xc, Xm (the counter against 1000000), C6.2.97
1987 ldr.x x1 sp 8
1988 ubfm.x x1 x1 59 58
1989 orr.x x0 x0 x1
1990 ubfm.x x1 x13 48 47
1991 orr.x x0 x0 x1
1992 bl EMIT
1993 movz.x x0 2 0
1994 movz.x x1 4 0
1995 bl TRAPC
1996 movz.x x0 0x0400 0
1997 movk.x x0 0x9100 1 ; ADD Xc, Xc, #1, C6.2.5
1998 ldr.x x1 sp 8
1999 orr.x x0 x0 x1
2000 ubfm.x x1 x1 59 58
2001 orr.x x0 x0 x1
2002 bl EMIT
2003 ldr.x x0 sp 9
2004 b SF_PUSH
2005:SF_TYPED
2006 ldr.x x9 sp 3
2007 cmp.x x2 x9
2008 b.ne E_TYPE
2009 str.x x1 sp 4
2010 b SF_NUM
2011:SF_CMPR
2012 movz.x x0 0x001f 0
2013 movk.x x0 0xeb00 1 ; CMP Xi, Xk, C6.2.97
2014 ldr.x x9 sp 5
2015 ubfm.x x9 x9 59 58
2016 orr.x x0 x0 x9
2017 ubfm.x x1 x1 48 47
2018 orr.x x0 x0 x1
2019 bl EMIT
2020:SF_B
2021 bl SF_BR
2022:SF_PUSH
2023 movz.x x1 4 0
2024 ldr.x x2 sp 6
2025 ldr.x x3 sp 5
2026 ldr.x x4 sp 3
2027 ldr.x x5 sp 0
2028 ldr.x x6 sp 1
2029 bl PUSHB
2030 add.x.i sp sp 80
2031 b STMT
2032; SF_BR: B.HS (unsigned) or B.GE (signed) to the loop exit, C6.2.34 (distance filled at end); x0 = its place
2033; (the loop type is the caller frame slot 3, at sp + 40 once this routine has pushed 16 bytes)
2034:SF_BR
2035 str.x.pre x30 sp -16
2036 mov.x x13 x20
2037 movz.x x0 0x5400 1 ; B.cond, C6.2.34
2038 ldr.x x9 sp 5
2039 movz.x x1 2 0
2040 cmp.x.i x9 6
2041 b.lo SFB1
2042 movz.x x1 10 0
2043:SFB1
2044 orr.x x0 x0 x1
2045 bl EMIT
2046 mov.x x0 x13
2047 ldr.x.post x30 sp 16
2048 ret
2049; ---- end: close the innermost block, or the function ----
2050:S_END
2051 movz.x x9 0x181 1
2052 cmp.x x25 x9
2053 b.eq FINISH
2054 sub.x.i x25 x25 128
2055 movz.x x9 0x185 1
2056 ldr.x x0 x25 0
2057 cmp.x.i x0 2
2058 b.eq SE_D
2059 str.x xzr x9 5
2060 b SE_D2
2061:SE_D
2062 ldr.x x10 x9 5
2063 ldr.x x11 x25 7
2064 and.x x10 x10 x11
2065 str.x x10 x9 5
2066:SE_D2
2067 cmp.x.i x0 1
2068 b.eq SE_IF
2069 cmp.x.i x0 2
2070 b.eq SE_ELSE
2071 cmp.x.i x0 3
2072 b.eq SE_WHILE
2073 sub.x.i sp sp 48
2074 movz.x x0 1 0
2075 str.x x0 sp 0
2076 ldr.x x0 x25 3
2077 str.x x0 sp 1
2078 ldr.x x0 x25 4
2079 str.x x0 sp 2
2080 movz.x x0 3 0
2081 str.x x0 sp 3
2082 movz.x x0 1 0
2083 str.x x0 sp 4
2084 ldr.x x0 x25 4
2085 str.x x0 sp 5
2086 movz.x x0 33 0
2087 ldr.x x1 x25 3
2088 add.x.i x2 sp 0
2089 bl BINOP
2090 add.x.i sp sp 48
2091:SE_WHILE
2092 ldr.x x0 x25 2
2093 bl BACK
2094:SE_IF
2095 ldr.x x0 x25 1
2096 mov.x x1 x20
2097 bl PATCH19
2098 b SE_X
2099:SE_ELSE
2100 ldr.x x0 x25 1
2101 mov.x x1 x20
2102 bl PATCH26
2103:SE_X
2104 ldr.x x23 x25 5
2105 ldr.x x28 x25 6
2106 bl EOL
2107 b STMT
2108; ---- end of a function: a void function that can reach its end returns; trap stubs ----
2109; shared tail, function mode: MOV X0, X7; LDR X16, [X7, #16]; BR X16 (OscRt.trap); program mode:
2110; ADD X0, X1, #100; MOVZ X8, #93; SVC #0 (exit 100 + code). Per trap code used: MOVZ X1, #code; B tail.
2111:FINISH
2112 bl EOL
2113 movz.x x9 0x185 1
2114 ldr.x x10 x9 5
2115 cbnz.x x10 FI_0
2116 cmp.x.i x27 10
2117 b.ne E_NORET
2118 bl EPI
2119:FI_0
2120 movz.x x9 0x182 1
2121 cmp.x x26 x9
2122 b.eq FI_T
2123 mov.x x13 x20
2124 movz.x x9 0x185 1
2125 ldr.x x10 x9 6
2126 cbnz.x x10 FI_PT
2127 movz.x x0 0x03e0 0
2128 movk.x x0 0xaa07 1 ; MOV X0, X7 = ORR X0, XZR, X7, C6.2.282
2129 bl EMIT
2130 movz.x x0 0x08f0 0
2131 movk.x x0 0xf940 1 ; LDR X16, [X7, #16], unsigned offset imm12 = 2, C6.2.216
2132 bl EMIT
2133 movz.x x0 0x0200 0
2134 movk.x x0 0xd61f 1 ; BR X16, C6.2.46
2135 bl EMIT
2136 b FI_C0
2137:FI_PT
2138 movz.x x0 0x9020 0
2139 movk.x x0 0x9101 1 ; ADD X0, X1, #100, C6.2.5
2140 bl EMIT
2141 movz.x x0 0x0ba8 0
2142 movk.x x0 0xd280 1 ; MOVZ X8, #93, C6.2.285
2143 bl EMIT
2144 movz.x x0 0x0001 0
2145 movk.x x0 0xd400 1 ; SVC #0, C6.2.466
2146 bl EMIT
2147:FI_C0
2148 movz.x x14 1 0
2149:FI_C
2150 movz.x x15 0 0
2151 movz.x x12 0x182 1
2152:FI_S
2153 cmp.x x12 x26
2154 b.hs FI_N
2155 ldr.w w0 x12 1
2156 cmp.x x0 x14
2157 b.ne FI_NX
2158 cbnz.x x15 FI_P
2159 mov.x x15 x20
2160 movz.x x0 0x0001 0
2161 movk.x x0 0xd280 1 ; MOVZ X1, #code, C6.2.285
2162 ubfm.x x1 x14 59 58
2163 orr.x x0 x0 x1
2164 bl EMIT
2165 mov.x x0 x13
2166 bl BACK
2167:FI_P
2168 ldr.w w0 x12 0
2169 mov.x x1 x15
2170 bl PATCH19
2171:FI_NX
2172 add.x.i x12 x12 8
2173 b FI_S
2174:FI_N
2175 add.x.i x14 x14 1
2176 cmp.x.i x14 14
2177 b.ls FI_C
2178:FI_T
2179 movz.x x27 0 0
2180 movz.x x9 0x185 1
2181 ldr.x x23 x9 1
2182 str.x xzr x9 3
2183 b STMT
2184; ---- end of input: write the output ----
2185:S_EOF
2186 cbnz.x x27 E_BLOCK
2187 bl RESOLVE
2188 movz.x x9 0x185 1
2189 ldr.x x10 x9 2
2190 cbz.x x10 E_SYNTAX
2191 ldr.x x11 x9 6
2192 cbnz.x x11 EOF_PROG
2193 ldr.x x11 x9 1
2194 cbnz.x x11 E_SUBSET
2195 add.x.i x12 x21 180
2196 cmp.x.i x10 1
2197 b.eq WRITEOUT
2198 ldr.x x0 x9 9
2199 ldr.x x0 x0 1
2200 add.x.i x12 x21 176
2201 sub.x x2 x0 x12
2202 ubfm.x x2 x2 2 27
2203 movz.x x3 0x1400 1 ; B to the last function, C6.2.35
2204 orr.x x3 x3 x2
2205 str.w w3 x12 0
2206 b WRITEOUT
2207; program mode: start code = MOVZ X28, #0x1000, LSL 16 (stack pool floor); MOVZ X16, #0x1080, LSL 16;
2208; MOV SP, X16 (ADD immediate, C6.2.5); BL main (C6.2.43); [MOVZ X0, #0 for a void main]; MOVZ X8, #93;
2209; SVC #0. The entry word after the header is a B to it.
2210:EOF_PROG
2211 movz.x x2 4 0
2212 movz.x x1 0x616d 0
2213 movk.x x1 0x6e69 1
2214 bl FINDFN
2215 cbz.x x0 E_SYNTAX
2216 ldr.w w9 x0 5
2217 cbnz.x x9 E_SUBSET
2218 mov.x x14 x0
2219 add.x.i x12 x21 176
2220 sub.x x2 x20 x12
2221 ubfm.x x2 x2 2 27
2222 movz.x x3 0x1400 1 ; B, C6.2.35
2223 orr.x x3 x3 x2
2224 str.w w3 x12 0
2225 movz.x x9 0x185 1
2226 ldr.x x10 x9 15
2227 cbz.x x10 EP_NOARG
2228 movz.x x0 0x03fb 0
2229 movk.x x0 0x9100 1 ; MOV X27, SP (ADD, C6.2.5): the initial argument stack, for envcnt / envread
2230 bl EMIT
2231:EP_NOARG
2232 movz.x x0 0x001c 0
2233 movk.x x0 0xd2a2 1 ; MOVZ X28, #0x1000, LSL #16, C6.2.285
2234 bl EMIT
2235 movz.x x0 0x1010 0
2236 movk.x x0 0xd2a2 1 ; MOVZ X16, #0x1080, LSL #16, C6.2.285
2237 bl EMIT
2238 movz.x x0 0x021f 0
2239 movk.x x0 0x9100 1 ; MOV SP, X16 = ADD SP, X16, #0, C6.2.5
2240 bl EMIT
2241 ldr.x x0 x14 1
2242 sub.x x2 x0 x20
2243 ubfm.x x2 x2 2 27
2244 movz.x x0 0x9400 1 ; BL main, C6.2.43
2245 orr.x x0 x0 x2
2246 bl EMIT
2247 ldr.w w9 x14 4
2248 cmp.x.i x9 10
2249 b.ne EP1
2250 movz.x x0 0xd280 1 ; MOVZ X0, #0, C6.2.285
2251 bl EMIT
2252:EP1
2253 movz.x x0 0x0ba8 0
2254 movk.x x0 0xd280 1 ; MOVZ X8, #93, C6.2.285
2255 bl EMIT
2256 movz.x x0 0x0001 0
2257 movk.x x0 0xd400 1 ; SVC #0, C6.2.466
2258 bl EMIT
2259 adr x10 ELFHDR
2260 mov.x x11 x21
2261 movz.x x12 0 0
2262:EP2
2263 ldr.w.post w0 x10 4
2264 str.w.post w0 x11 4
2265 add.x.i x12 x12 1
2266 cmp.x.i x12 44
2267 b.lo EP2
2268 sub.x x0 x20 x21
2269 str.w w0 x21 24
2270 str.w w0 x21 26
2271 movz.x x9 0x185 1
2272 ldr.x x0 x9 7
2273 movz.x x1 0x80 1
2274 add.x x0 x0 x1
2275 str.w w0 x21 40
2276 mov.x x12 x21
2277:WRITEOUT
2278 sub.x x2 x20 x12
2279 cbz.x x2 EXIT0
2280 movz.x x0 1 0
2281 mov.x x1 x12
2282 movz.x x8 64 0
2283 svc 0
2284 cmp.x.i x0 0
2285 b.le E_WRITE
2286 add.x x12 x12 x0
2287 b WRITEOUT
2288:EXIT0
2289 movz.x x0 0 0
2290 movz.x x8 93 0
2291 svc 0
2292; VAL: read one value. x0 expected type (0 none), x1 destination register (255 none).
2293; Out: x0 kind (1 register, 2 bare number, 3 typed number, 4 flags), x1 register / number / condition,
2294; x2 type. Only the outermost op writes the destination. Clobbers x0..x17.
2295:VAL
2296 str.x.pre x30 sp -32
2297 str.x x0 sp 1
2298 str.x x1 sp 2
2299 bl TOK
2300 mov.x x3 x0
2301 mov.x x4 x1
2302 mov.x x5 x2
2303 ldr.x x0 sp 1
2304 ldr.x x1 sp 2
2305 ldr.x.post x30 sp 32
2306; VALTOK: the same with the first word already read (x3 kind, x4 word or number, x5 length).
2307; Frame (8-byte slots): 0 x30, 1 expected, 2 dest, 3 op, 4..6 a, 7..9 b, 10 type of a conversion.
2308:VALTOK
2309 str.x.pre x30 sp -128
2310 str.x x0 sp 1
2311 str.x x1 sp 2
2312 movz.x x9 0x185 1 ; nesting depth (state slot 10): at most 1024 values inside one another, else error 14
2313 ldr.x x10 x9 10
2314 add.x.i x10 x10 1
2315 str.x x10 x9 10
2316 cmp.x.i x10 1024
2317 b.hi E_FULL
2318 cbz.x x3 E_FEW
2319 cmp.x.i x3 3
2320 b.eq E_FEW
2321 cmp.x.i x3 4
2322 b.eq E_SYNTAX
2323 cmp.x.i x3 2
2324 b.ne VT_W
2325 mov.x x1 x4
2326 movz.x x9 0x185 1 ; a bare number: x2 = 1 when written as 2^63 or more (RANGE needs it later)
2327 ldr.x x2 x9 11
2328 movz.x x0 2 0
2329 ldr.x x9 sp 1
2330 cbz.x x9 VT_RET
2331 mov.x x3 x2
2332 mov.x x2 x9
2333 bl RANGE
2334 movz.x x0 3 0
2335 b VT_RET
2336:VT_W
2337 cmp.x.i x5 8
2338 b.hi VT_LONG
2339 mov.x x1 x4
2340 bl KW
2341 cbnz.x x0 VT_K
2342 str.x x1 sp 4
2343 bl FINDNAME
2344 cbz.x x0 VT_FN
2345 ldr.w w9 x0 5
2346 cbnz.x x9 E_TYPE
2347 ldr.w w1 x0 2
2348 ldr.w w2 x0 3
2349 movz.x x0 1 0
2350 b VT_RET
2351; a call of a function that gives a value
2352:VT_FN
2353 ldr.x x1 sp 4
2354 movz.x x2 0 0
2355 bl FINDFN
2356 cbz.x x0 E_UNDEF
2357:VT_FN2
2358 ldr.w w9 x0 4
2359 cmp.x.i x9 10
2360 b.eq E_TYPE
2361 ldr.x x1 sp 2
2362 bl CALL
2363 b VT_RET
2364:VT_K
2365 sub.x.i x9 x0 1
2366 cmp.x.i x9 8
2367 b.ls VT_TYPE
2368 cmp.x.i x0 74
2369 b.eq VT_PAREN
2370 cmp.x.i x0 77
2371 b.eq E_SUBSET
2372 cmp.x.i x0 85
2373 b.eq E_SUBSET
2374 cmp.x.i x0 86
2375 b.eq VT_ENVCNT
2376 cmp.x.i x0 87
2377 b.eq VT_ENVREAD
2378 str.x x0 sp 3
2379 cmp.x.i x0 51
2380 b.eq VT_GET
2381 cmp.x.i x0 52
2382 b.eq VT_LEN
2383 cmp.x.i x0 53
2384 b.eq VT_SYS
2385 cmp.x.i x0 54
2386 b.eq VT_SYS
2387 cmp.x.i x0 55
2388 b.eq VT_TRUE
2389 cmp.x.i x0 56
2390 b.eq VT_FALSE
2391 sub.x.i x9 x0 33
2392 cmp.x.i x9 17
2393 b.hi E_SYNTAX
2394 str.x x0 sp 3
2395 cmp.x.i x0 49
2396 b.hs VT_UN
2397; binary op: a, then b; a comparison used as a value is turned into a register at once (flags would not
2398; survive the next value)
2399 movz.x x0 0 0
2400 movz.x x1 255 0
2401 bl VAL
2402 cmp.x.i x0 4
2403 b.ne VB1
2404 bl MATREG
2405 mov.x x1 x0
2406 movz.x x0 1 0
2407 movz.x x2 1 0
2408:VB1
2409 str.x x0 sp 4
2410 str.x x1 sp 5
2411 str.x x2 sp 6
2412 movz.x x0 0 0
2413 movz.x x1 255 0
2414 bl VAL
2415 cmp.x.i x0 4
2416 b.ne VB2
2417 bl MATREG
2418 mov.x x1 x0
2419 movz.x x0 1 0
2420 movz.x x2 1 0
2421:VB2
2422 str.x x0 sp 7
2423 str.x x1 sp 8
2424 str.x x2 sp 9
2425; a bare number takes the type of the other value (in a shift too: shl 1 sh)
2426 ldr.x x10 sp 4
2427 ldr.x x11 sp 7
2428 cmp.x.i x10 2
2429 b.ne VB3
2430 cmp.x.i x11 2
2431 b.eq E_BARE
2432 ldr.x x1 sp 5
2433 ldr.x x2 sp 9
2434 ldr.x x3 sp 6
2435 bl RANGE
2436 str.x x2 sp 6
2437 movz.x x0 3 0
2438 str.x x0 sp 4
2439:VB3
2440 cmp.x.i x11 2
2441 b.ne VB4
2442 ldr.x x1 sp 8
2443 ldr.x x2 sp 6
2444 ldr.x x3 sp 9
2445 bl RANGE
2446 str.x x2 sp 9
2447 movz.x x0 3 0
2448 str.x x0 sp 7
2449:VB4
2450 ldr.x x0 sp 3
2451 cmp.x.i x0 41
2452 b.eq VB5
2453 cmp.x.i x0 42
2454 b.eq VB5
2455 ldr.x x1 sp 6
2456 ldr.x x2 sp 9
2457 cmp.x x1 x2
2458 b.ne E_TYPE
2459:VB5
2460 ldr.x x0 sp 3
2461 ldr.x x1 sp 2
2462 add.x.i x2 sp 32
2463 bl BINOP
2464:VT_RET
2465 movz.x x9 0x185 1
2466 ldr.x x10 x9 10
2467 sub.x.i x10 x10 1
2468 str.x x10 x9 10
2469 ldr.x.post x30 sp 128
2470 ret
2471; ( value )
2472:VT_PAREN
2473 ldr.x x0 sp 1
2474 ldr.x x1 sp 2
2475 bl VAL
2476 str.x x0 sp 4
2477 str.x x1 sp 5
2478 str.x x2 sp 6
2479 bl TOK
2480 cmp.x.i x0 1
2481 b.ne E_SYNTAX
2482 cmp.x.i x2 8
2483 b.hi E_SYNTAX
2484 bl KW
2485 cmp.x.i x0 75
2486 b.ne E_SYNTAX
2487 ldr.x x0 sp 4
2488 ldr.x x1 sp 5
2489 ldr.x x2 sp 6
2490 b VT_RET
2491; neg a, not a (a bare number takes the expected type)
2492:VT_UN
2493 ldr.x x0 sp 1
2494 movz.x x1 255 0
2495 bl VAL
2496 ldr.x x9 sp 3
2497 cmp.x.i x9 50
2498 b.ne VU1
2499 cmp.x.i x0 4
2500 b.ne VU1
2501 movz.x x9 1 0
2502 eor.x x1 x1 x9
2503 b VT_RET
2504:VU1
2505 cmp.x.i x0 2
2506 b.eq E_BARE
2507 str.x x2 sp 6
2508 bl MATREG
2509 str.x x0 sp 5
2510 ldr.x x0 sp 2
2511 bl DESTREG
2512 str.x x0 sp 7
2513 ldr.x x9 sp 3
2514 cmp.x.i x9 50
2515 b.eq VU_NOT
2516 ldr.x x9 sp 6
2517 cmp.x.i x9 1
2518 b.eq E_TYPE
2519 cmp.x.i x9 9
2520 b.eq VN64
2521 movz.x x0 0x03e0 0
2522 movk.x x0 0xcb00 1 ; NEG Xd, Xm = SUB Xd, XZR, Xm, C6.2.458
2523 cmp.x.i x9 4
2524 b.ne VN1
2525 movz.x x0 0x03e0 0
2526 movk.x x0 0x4b00 1 ; NEG Wd, Wm (32-bit SUB, C6.2.458): the u32 result comes zero-extended
2527 bl VU_E
2528 b VU_R
2529:VN1
2530 bl VU_E
2531 ldr.x x0 sp 7
2532 ldr.x x1 sp 6
2533 cmp.x.i x1 6
2534 b.hs VN2
2535 bl CANON
2536 b VU_R
2537:VN2
2538 movz.x x2 1 0
2539 bl CHKEXT
2540 b VU_R
2541:VN64
2542 movz.x x0 0x03e0 0
2543 movk.x x0 0xeb00 1 ; NEGS Xd, Xm = SUBS Xd, XZR, Xm, C6.2.465
2544 bl VU_E
2545 movz.x x0 6 0
2546 movz.x x1 1 0
2547 bl TRAPC
2548 b VU_R
2549:VU_NOT
2550 ldr.x x9 sp 6
2551 cmp.x.i x9 1
2552 b.ne VNT1
2553 movz.x x0 0 0
2554 movk.x x0 0xd240 1 ; EOR Xd, Xn, #1 (immediate, N=1 immr=0 imms=0), C6.2.155
2555 ldr.x x1 sp 7
2556 ldr.x x2 sp 5
2557 movz.x x3 0 0
2558 bl E3
2559 b VU_R
2560:VNT1
2561 movz.x x0 0x03e0 0
2562 movk.x x0 0xaa20 1 ; MVN Xd, Xm = ORN Xd, XZR, Xm, C6.2.300
2563 cmp.x.i x9 4
2564 b.ne VNT2
2565 movz.x x0 0x03e0 0
2566 movk.x x0 0x2a20 1 ; MVN Wd, Wm (32-bit ORN, C6.2.300)
2567 bl VU_E
2568 b VU_R
2569:VNT2
2570 bl VU_E
2571 ldr.x x0 sp 7
2572 ldr.x x1 sp 6
2573 cmp.x.i x1 6
2574 b.hs VU_R
2575 bl CANON
2576:VU_R
2577 movz.x x0 1 0
2578 ldr.x x1 sp 7
2579 ldr.x x2 sp 6
2580 b VT_RET
2581:VU_E
2582 ldr.x x1 sp 7
2583 movz.x x2 0 0
2584 ldr.x x3 sp 5
2585 b E3
2586; a type word: a typed number (uint 5) or a conversion of the next value
2587:VT_TYPE
2588 str.x x0 sp 10
2589 bl TOK
2590 cmp.x.i x0 2
2591 b.ne VTT1
2592 ldr.x x2 sp 10
2593 movz.x x9 0x185 1 ; x3 = the number was written as 2^63 or more
2594 ldr.x x3 x9 11
2595 bl RANGE
2596 movz.x x0 3 0
2597 b VT_RET
2598:VTT1
2599 mov.x x3 x0
2600 mov.x x4 x1
2601 mov.x x5 x2
2602 movz.x x0 0 0
2603 movz.x x1 255 0
2604 bl VALTOK
2605 cmp.x.i x0 2
2606 b.eq E_BARE
2607 str.x x2 sp 6
2608 bl MATREG
2609 str.x x0 sp 5
2610 ldr.x x1 sp 6
2611 ldr.x x2 sp 10
2612 cmp.x.i x1 1
2613 b.eq E_SUBSET
2614 cmp.x.i x2 1
2615 b.eq E_SUBSET
2616 adr x9 TWID
2617 ldrb.r w3 x9 x1
2618 ldrb.r w4 x9 x2
2619 cmp.x.i x1 6
2620 b.hs VC_SS
2621 cmp.x.i x2 6
2622 b.hs VC_US
2623 cmp.x x3 x4
2624 b.ls VC_OK
2625 mov.x x5 x4
2626 b VC_LSR
2627:VC_US
2628 cmp.x x3 x4
2629 b.lo VC_OK
2630 sub.x.i x5 x4 1
2631 b VC_LSR
2632:VC_SS
2633 cmp.x.i x2 6
2634 b.hs VC_S2
2635 mov.x x5 x4
2636 cmp.x.i x5 63
2637 b.ls VC_LSR
2638 movz.x x5 63 0
2639 b VC_LSR
2640:VC_S2
2641 cmp.x x3 x4
2642 b.ls VC_OK
2643 ldr.x x0 sp 5
2644 ldr.x x1 sp 10
2645 movz.x x2 5 0
2646 bl CHKEXT
2647 b VC_OK
2648; out of range when any bit at or above x5 is set: LSR Xt, Xa, #x5 = UBFM Xt, Xa, #x5, #63 (C6.2.487);
2649; CBNZ Xt -> trap 5 (C6.2.77)
2650:VC_LSR
2651 bl ALLOC
2652 str.x x0 sp 7
2653 movz.x x1 0xfc00 0
2654 movk.x x1 0xd340 1
2655 orr.x x1 x1 x0
2656 ubfm.x x5 x5 48 47
2657 orr.x x1 x1 x5
2658 ldr.x x2 sp 5
2659 ubfm.x x2 x2 59 58
2660 orr.x x0 x1 x2
2661 bl EMIT
2662 ldr.x x0 sp 7
2663 movz.x x9 0xb500 1 ; CBNZ Xt, C6.2.77
2664 orr.x x0 x0 x9
2665 movz.x x1 5 0
2666 bl TRAPSITE
2667:VC_OK
2668 movz.x x0 1 0
2669 ldr.x x1 sp 5
2670 ldr.x x2 sp 10
2671 b VT_RET
2672; ======================================================================================================
2673; BINOP: x0 op (33..48), x1 destination (255 none), x2 address of two values (kind, number/register,
2674; type) a then b, types already settled. Out: as VAL. Frame: 0 x30, 1 op, 2 rd, 3 values, 4 ra,
2675; 5 rb or immediate, 6 type, 7 1 if b is an immediate, 8 temporary.
2676:BINOP
2677 str.x.pre x30 sp -80
2678 str.x x0 sp 1
2679 str.x x1 sp 2
2680 str.x x2 sp 3
2681 ldr.x x9 x2 2
2682 str.x x9 sp 6
2683 ldr.x x0 x2 0
2684 ldr.x x1 x2 1
2685 ldr.x x2 x2 2
2686 bl MATREG
2687 str.x x0 sp 4
2688 movz.x x9 0 0
2689 str.x x9 sp 7
2690 ldr.x x10 sp 3
2691 ldr.x x0 x10 3
2692 cmp.x.i x0 3
2693 b.ne BO_BREG
2694 ldr.x x1 x10 4
2695 ldr.x x11 sp 1
2696 cmp.x.i x11 41
2697 b.eq BO_IS
2698 cmp.x.i x11 42
2699 b.eq BO_IS
2700 cmp.x.i x11 35
2701 b.lo BO_II
2702 cmp.x.i x11 43
2703 b.lo BO_BREG
2704:BO_II
2705 movz.x x9 4095 0
2706 cmp.x x1 x9
2707 b.hi BO_BREG
2708 b BO_IMM
2709:BO_IS
2710 ldr.x x9 sp 6
2711 adr x12 TWID
2712 ldrb.r w9 x12 x9
2713 cmp.x x1 x9
2714 b.hs BO_BREG
2715:BO_IMM
2716 str.x x1 sp 5
2717 movz.x x9 1 0
2718 str.x x9 sp 7
2719 b BO_OPS
2720:BO_BREG
2721 ldr.x x10 sp 3
2722 ldr.x x0 x10 3
2723 ldr.x x1 x10 4
2724 ldr.x x2 x10 5
2725 bl MATREG
2726 str.x x0 sp 5
2727:BO_OPS
2728 ldr.x x0 sp 1
2729 cmp.x.i x0 43
2730 b.hs BO_CMP
2731 ldr.x x9 sp 6
2732 cmp.x.i x9 1
2733 b.ne BO_NB
2734 sub.x.i x10 x0 38
2735 cmp.x.i x10 2
2736 b.hi E_TYPE
2737:BO_NB
2738 ldr.x x0 sp 2
2739 bl DESTREG
2740 str.x x0 sp 2
2741 ldr.x x0 sp 1
2742 cmp.x.i x0 35
2743 b.lo BO_ADD
2744 b.eq BO_MUL
2745 cmp.x.i x0 38
2746 b.lo BO_DIV
2747 cmp.x.i x0 41
2748 b.lo BO_LOG
2749 b.eq BO_SHL
2750 b BO_SHR
2751; add, sub. u32: 32-bit form (zero-extends); i64: flag-setting form + B.VS trap 1; u8/u16: wrap with
2752; UBFM; i8/i16/i32: exact in 64 bits, then the sign-extension check (trap 1)
2753:BO_ADD
2754 ldr.x x9 sp 1
2755 ldr.x x10 sp 7
2756 cbnz.x x10 BA_I
2757 movz.x x0 0x8b00 1 ; ADD (shifted register) 64-bit, C6.2.6
2758 cmp.x.i x9 33
2759 b.eq BA_S
2760 movz.x x0 0xcb00 1 ; SUB (shifted register) 64-bit, C6.2.458
2761 b BA_S
2762:BA_I
2763 movz.x x0 0x9100 1 ; ADD (immediate) 64-bit, C6.2.5
2764 cmp.x.i x9 33
2765 b.eq BA_S
2766 movz.x x0 0xd100 1 ; SUB (immediate) 64-bit, C6.2.457
2767:BA_S
2768 ldr.x x9 sp 6
2769 cmp.x.i x9 4
2770 b.ne BA2
2771 movz.x x10 0x8000 1 ; sf (bit 31) = 0: the 32-bit form
2772 eor.x x0 x0 x10
2773 bl BO_W3
2774 b BO_RET
2775:BA2
2776 cmp.x.i x9 9
2777 b.ne BA3
2778 movz.x x10 0x2000 1 ; S (bit 29) = 1: ADDS/SUBS, C6.2.10, C6.2.11, C6.2.464, C6.2.465
2779 orr.x x0 x0 x10
2780 bl BO_W3
2781 movz.x x0 6 0
2782 movz.x x1 1 0
2783 bl TRAPC
2784 b BO_RET
2785:BA3
2786 bl BO_W3
2787 bl BO_FIX
2788 b BO_RET
2789; mul. i64: SMULH t (C6.2.379), MUL, CMP t, rd, ASR #63 (C6.2.97), B.NE trap 1
2790:BO_MUL
2791 ldr.x x9 sp 6
2792 cmp.x.i x9 9
2793 b.eq BM64
2794 movz.x x0 0x7c00 0
2795 movk.x x0 0x9b00 1 ; MUL 64-bit = MADD Xd, Xn, Xm, XZR, C6.2.293 / C6.2.275
2796 cmp.x.i x9 4
2797 b.ne BM1
2798 movz.x x10 0x8000 1
2799 eor.x x0 x0 x10
2800 bl BO_W3
2801 b BO_RET
2802:BM1
2803 bl BO_W3
2804 bl BO_FIX
2805 b BO_RET
2806:BM64
2807 bl ALLOC
2808 str.x x0 sp 8
2809 movz.x x0 0x7c00 0
2810 movk.x x0 0x9b40 1 ; SMULH, C6.2.379
2811 ldr.x x1 sp 8
2812 ldr.x x2 sp 4
2813 ldr.x x3 sp 5
2814 bl E3
2815 movz.x x0 0x7c00 0
2816 movk.x x0 0x9b00 1 ; MUL, C6.2.293
2817 bl BO_W3
2818 movz.x x0 0xfc1f 0
2819 movk.x x0 0xeb80 1 ; CMP Xt, Xd, ASR #63 = SUBS XZR, Xt, Xd, ASR #63, C6.2.465
2820 movz.x x1 0 0
2821 ldr.x x2 sp 8
2822 ldr.x x3 sp 2
2823 bl E3
2824 movz.x x0 1 0
2825 movz.x x1 1 0
2826 bl TRAPC
2827 b BO_RET
2828; div, rem (unsigned): CBZ Xb -> trap 2 (C6.2.78), unless b is a number other than 0; UDIV (C6.2.490);
2829; rem: t = a / b; rd = a - t * b (MSUB Xd, Xt, Xb, Xa, C6.2.291)
2830:BO_DIV
2831 ldr.x x9 sp 6
2832 cmp.x.i x9 6
2833 b.hs BO_SDIV
2834 ldr.x x10 sp 3
2835 ldr.x x0 x10 3
2836 cmp.x.i x0 3
2837 b.ne BD1
2838 ldr.x x0 x10 4
2839 cbnz.x x0 BD2
2840:BD1
2841 ldr.x x0 sp 5
2842 movz.x x9 0xb400 1 ; CBZ Xb, C6.2.78
2843 orr.x x0 x0 x9
2844 movz.x x1 2 0
2845 bl TRAPSITE
2846:BD2
2847 ldr.x x9 sp 1
2848 cmp.x.i x9 37
2849 b.eq BD_REM
2850 movz.x x0 0x0800 0
2851 movk.x x0 0x9ac0 1 ; UDIV 64-bit, C6.2.490
2852 bl BO_W3
2853 b BO_RET
2854:BD_REM
2855 bl ALLOC
2856 str.x x0 sp 8
2857 movz.x x0 0x0800 0
2858 movk.x x0 0x9ac0 1 ; UDIV, C6.2.490
2859 ldr.x x1 sp 8
2860 ldr.x x2 sp 4
2861 ldr.x x3 sp 5
2862 bl E3
2863 movz.x x0 0x8000 0
2864 movk.x x0 0x9b00 1 ; MSUB 64-bit, C6.2.291 (Ra at bit 10)
2865 ldr.x x1 sp 4
2866 ubfm.x x1 x1 54 53
2867 orr.x x0 x0 x1
2868 ldr.x x1 sp 2
2869 ldr.x x2 sp 8
2870 ldr.x x3 sp 5
2871 bl E3
2872 b BO_RET
2873; and, or, xor: canonical in, canonical out
2874:BO_LOG
2875 movz.x x0 0x8a00 1 ; AND (shifted register) 64-bit, C6.2.15
2876 ldr.x x9 sp 1
2877 cmp.x.i x9 39
2878 b.lo BL1
2879 movz.x x0 0xaa00 1 ; ORR (shifted register) 64-bit, C6.2.302
2880 b.eq BL1
2881 movz.x x0 0xca00 1 ; EOR (shifted register) 64-bit, C6.2.156
2882:BL1
2883 bl BO_W3
2884 b BO_RET
2885; shl (unsigned): by a number s: LSL #s = UBFM Xd, Xn, #(64-s) mod 64, #(63-s) (C6.2.487), then wrap;
2886; by a register: CMP Xb, #w; B.HS trap 7; LSLV (C6.2.271; 32-bit for u32)
2887:BO_SHL
2888 ldr.x x9 sp 6
2889 cmp.x.i x9 9
2890 b.eq BS_64
2891 ldr.x x10 sp 7
2892 cbnz.x x10 BS_IL
2893 bl BO_SCHK
2894 movz.x x0 0x2000 0
2895 movk.x x0 0x9ac0 1 ; LSLV 64-bit, C6.2.271
2896 ldr.x x9 sp 6
2897 cmp.x.i x9 4
2898 b.ne BS1
2899 movz.x x10 0x8000 1
2900 eor.x x0 x0 x10
2901 bl BO_W3
2902 b BO_RET
2903:BS1
2904 bl BO_W3
2905 bl BO_FIX
2906 b BO_RET
2907:BS_IL
2908 ldr.x x1 sp 5
2909 movz.x x2 64 0
2910 sub.x x2 x2 x1
2911 ubfm.x x2 x2 0 5
2912 movz.x x3 63 0
2913 sub.x x3 x3 x1
2914 movz.x x0 0xd340 1 ; UBFM 64-bit, C6.2.487
2915 ubfm.x x2 x2 48 47
2916 orr.x x0 x0 x2
2917 ubfm.x x3 x3 54 53
2918 orr.x x0 x0 x3
2919 ldr.x x1 sp 4
2920 ubfm.x x1 x1 59 58
2921 orr.x x0 x0 x1
2922 ldr.x x1 sp 2
2923 orr.x x0 x0 x1
2924 bl EMIT
2925 bl BO_FIX
2926 b BO_RET
2927; shr: unsigned LSR, signed ASR. By a number s: UBFM/SBFM Xd, Xn, #s, #63 (C6.2.487, C6.2.355);
2928; by a register: the amount check, then LSRV (C6.2.274) / ASRV (C6.2.21)
2929:BO_SHR
2930 ldr.x x10 sp 7
2931 cbnz.x x10 BR_I
2932 bl BO_SCHK
2933 movz.x x0 0x2400 0
2934 movk.x x0 0x9ac0 1 ; LSRV 64-bit, C6.2.274
2935 ldr.x x9 sp 6
2936 cmp.x.i x9 6
2937 b.lo BR1
2938 movz.x x0 0x2800 0
2939 movk.x x0 0x9ac0 1 ; ASRV 64-bit, C6.2.21
2940:BR1
2941 bl BO_W3
2942 b BO_RET
2943:BR_I
2944 movz.x x0 0xfc00 0
2945 movk.x x0 0xd340 1 ; UBFM Xd, Xn, #s, #63 = LSR, C6.2.487
2946 ldr.x x9 sp 6
2947 cmp.x.i x9 6
2948 b.lo BR2
2949 movz.x x0 0xfc00 0
2950 movk.x x0 0x9340 1 ; SBFM Xd, Xn, #s, #63 = ASR, C6.2.355
2951:BR2
2952 ldr.x x1 sp 5
2953 ubfm.x x1 x1 48 47
2954 orr.x x0 x0 x1
2955 ldr.x x1 sp 4
2956 ubfm.x x1 x1 59 58
2957 orr.x x0 x0 x1
2958 ldr.x x1 sp 2
2959 orr.x x0 x0 x1
2960 bl EMIT
2961 b BO_RET
2962; comparisons: CMP Xa, #imm (C6.2.96) or CMP Xa, Xb (C6.2.97); the result is the flags and a condition
2963:BO_CMP
2964 ldr.x x10 sp 7
2965 cbnz.x x10 BC_I
2966 movz.x x0 0x001f 0
2967 movk.x x0 0xeb00 1 ; CMP (shifted register) = SUBS XZR, Xa, Xb, C6.2.97
2968 ldr.x x1 sp 5
2969 ubfm.x x1 x1 48 47
2970 orr.x x0 x0 x1
2971 b BC_E
2972:BC_I
2973 movz.x x0 0x001f 0
2974 movk.x x0 0xf100 1 ; CMP (immediate) = SUBS XZR, Xa, #imm, C6.2.96
2975 ldr.x x1 sp 5
2976 ubfm.x x1 x1 54 53
2977 orr.x x0 x0 x1
2978:BC_E
2979 ldr.x x1 sp 4
2980 ubfm.x x1 x1 59 58
2981 orr.x x0 x0 x1
2982 bl EMIT
2983 ldr.x x9 sp 1
2984 sub.x.i x9 x9 43
2985 add.x x9 x9 x9
2986 ldr.x x10 sp 6
2987 cmp.x.i x10 6
2988 b.lo BC1
2989 add.x.i x9 x9 1
2990:BC1
2991 adr x10 CONDS
2992 ldrb.r w1 x10 x9
2993 movz.x x0 4 0
2994 movz.x x2 1 0
2995 b BO_RET2
2996:BO_RET
2997 movz.x x0 1 0
2998 ldr.x x1 sp 2
2999 ldr.x x2 sp 6
3000:BO_RET2
3001 ldr.x.post x30 sp 80
3002 ret
3003; BO_W3: x0 fixed part; emit it | rd | ra << 5 | (imm12 << 10, or rb << 16), fields from the BINOP frame
3004:BO_W3
3005 ldr.x x1 sp 2
3006 orr.x x0 x0 x1
3007 ldr.x x1 sp 4
3008 ubfm.x x1 x1 59 58
3009 orr.x x0 x0 x1
3010 ldr.x x1 sp 5
3011 ldr.x x2 sp 7
3012 cbnz.x x2 BW_I
3013 ubfm.x x1 x1 48 47
3014 orr.x x0 x0 x1
3015 b EMIT
3016:BW_I
3017 ubfm.x x1 x1 54 53
3018 orr.x x0 x0 x1
3019 b EMIT
3020; BO_FIX: after a 64-bit op on rd: u8/u16/u32 wrap (CANON), i8/i16/i32 overflow check (trap 1)
3021:BO_FIX
3022 ldr.x x1 sp 6
3023 ldr.x x0 sp 2
3024 cmp.x.i x1 6
3025 b.lo CANON
3026 cmp.x.i x1 9
3027 b.eq BF_X
3028 movz.x x2 1 0
3029 b CHKEXT
3030:BF_X
3031 ret
3032; BO_SCHK: shift amount in a register must be below the width: CMP Xb, #w (C6.2.96); B.HS trap 7
3033:BO_SCHK
3034 ldr.x x1 sp 6
3035 adr x9 TWID
3036 ldrb.r w1 x9 x1
3037 ldr.x x2 sp 5
3038 movz.x x0 0x001f 0
3039 movk.x x0 0xf100 1 ; CMP Xb, #w, C6.2.96
3040 ubfm.x x1 x1 54 53
3041 orr.x x0 x0 x1
3042 ubfm.x x2 x2 59 58
3043 orr.x x0 x0 x2
3044 str.x.pre x30 sp -16
3045 bl EMIT
3046 movz.x x0 2 0
3047 movz.x x1 7 0
3048 bl TRAPC
3049 ldr.x.post x30 sp 16
3050 ret
3051; ======================================================================================================
3052; COND: read a condition (a bool value); emit a branch taken when it is false; x0 = that branch's address
3053:COND
3054 str.x.pre x30 sp -16
3055 movz.x x0 1 0
3056 movz.x x1 255 0
3057 bl VAL
3058 cmp.x.i x2 1
3059 b.ne E_TYPE
3060 cmp.x.i x0 4
3061 b.ne CO1
3062 movz.x x9 1 0
3063 eor.x x1 x1 x9
3064 movz.x x0 0x5400 1 ; B.cond with the opposite condition, C6.2.34
3065 orr.x x0 x0 x1
3066 b CO2
3067:CO1
3068 bl MATREG
3069 movz.x x9 0xb400 1 ; CBZ Xr, C6.2.78
3070 orr.x x0 x0 x9
3071:CO2
3072 mov.x x10 x20
3073 bl EMIT
3074 mov.x x0 x10
3075 ldr.x.post x30 sp 16
3076 ret
3077; MATREG: x0 kind, x1 number/register/condition, x2 type -> x0 a register holding the value
3078:MATREG
3079 cmp.x.i x0 1
3080 b.ne MR1
3081 mov.x x0 x1
3082 ret
3083:MR1
3084 str.x.pre x30 sp -32
3085 str.x x0 sp 1
3086 str.x x1 sp 2
3087 str.x x2 sp 3
3088 bl ALLOC
3089 mov.x x3 x0
3090 ldr.x x0 sp 1
3091 ldr.x x1 sp 2
3092 ldr.x x2 sp 3
3093 str.x x3 sp 1
3094 bl FORCE
3095 ldr.x x0 sp 1
3096 ldr.x.post x30 sp 32
3097 ret
3098; FORCE: x0 kind, x1 number/register/condition, x2 type, x3 register: put the value in that register
3099:FORCE
3100 str.x.pre x30 sp -16
3101 cmp.x.i x0 1
3102 b.eq FO_R
3103 cmp.x.i x0 3
3104 b.eq FO_C
3105 cmp.x.i x0 4
3106 b.ne E_BARE
3107 mov.x x0 x3
3108 bl CSET
3109 b FO_X
3110:FO_R
3111 cmp.x x1 x3
3112 b.eq FO_X
3113 movz.x x0 0x03e0 0
3114 movk.x x0 0xaa00 1 ; MOV Xd, Xm = ORR Xd, XZR, Xm, C6.2.282
3115 orr.x x0 x0 x3
3116 ubfm.x x1 x1 48 47
3117 orr.x x0 x0 x1
3118 bl EMIT
3119 b FO_X
3120:FO_C
3121 mov.x x0 x3
3122 bl MATCONST
3123:FO_X
3124 ldr.x.post x30 sp 16
3125 ret
3126; CSET Xd, cond = CSINC Xd, XZR, XZR, opposite cond (C6.2.141). x0 register, x1 condition
3127:CSET
3128 movz.x x9 0x07e0 0
3129 movk.x x9 0x9a9f 1 ; CSINC 64-bit, Rm = Rn = 31, C6.2.141
3130 orr.x x9 x9 x0
3131 movz.x x0 1 0
3132 eor.x x1 x1 x0
3133 ubfm.x x1 x1 52 51
3134 orr.x x0 x9 x1
3135 b EMIT
3136; MATCONST: x0 register, x1 64-bit value: MOVZ (C6.2.285) or, for a negative value, MOVN (C6.2.284) with
3137; the first halfword that differs from the fill, then MOVK (C6.2.283) for each other such halfword
3138:MATCONST
3139 str.x.pre x30 sp -16
3140 mov.x x3 x0
3141 mov.x x4 x1
3142 movz.x x5 0 0
3143 movz.x x6 0 0
3144 movz.x x7 0xd280 1 ; MOVZ 64-bit, C6.2.285
3145 movz.x x8 0 0
3146 cmp.x.i x4 0
3147 b.ge MC2
3148 movz.x x6 0xffff 0
3149 movz.x x7 0x9280 1 ; MOVN 64-bit, C6.2.284
3150:MC2
3151 ubfm.x x2 x5 60 59
3152 lsrv.x x1 x4 x2
3153 ubfm.x x1 x1 0 15
3154 cmp.x x1 x6
3155 b.eq MC4
3156 movz.x x0 0xf280 1 ; MOVK 64-bit, C6.2.283
3157 cbnz.x x8 MC3
3158 eor.x x1 x1 x6
3159 mov.x x0 x7
3160 movz.x x8 1 0
3161:MC3
3162 ubfm.x x1 x1 59 58
3163 orr.x x0 x0 x1
3164 ubfm.x x2 x5 43 42
3165 orr.x x0 x0 x2
3166 orr.x x0 x0 x3
3167 bl EMIT
3168:MC4
3169 add.x.i x5 x5 1
3170 cmp.x.i x5 4
3171 b.lo MC2
3172 cbnz.x x8 MC5
3173 orr.x x0 x7 x3
3174 bl EMIT
3175:MC5
3176 ldr.x.post x30 sp 16
3177 ret
3178; CANON: x0 register, x1 type: u8/u16/u32 UBFM Xr, Xr, #0, #w-1 (C6.2.487); i8/i16/i32 SBFM (C6.2.355)
3179:CANON
3180 cmp.x.i x1 2
3181 b.lo CN_X
3182 cmp.x.i x1 5
3183 b.lo CN_U
3184 cmp.x.i x1 6
3185 b.lo CN_X
3186 cmp.x.i x1 9
3187 b.lo CN_S
3188:CN_X
3189 ret
3190:CN_U
3191 movz.x x9 0xd340 1 ; UBFM 64-bit, C6.2.487
3192 b CN_GO
3193:CN_S
3194 movz.x x9 0x9340 1 ; SBFM 64-bit, C6.2.355
3195:CN_GO
3196 adr x10 TWID
3197 ldrb.r w10 x10 x1
3198 sub.x.i x10 x10 1
3199 ubfm.x x10 x10 54 53
3200 orr.x x9 x9 x10
3201 orr.x x9 x9 x0
3202 ubfm.x x0 x0 59 58
3203 orr.x x0 x9 x0
3204 b EMIT
3205; CHKEXT: x0 register, x1 type (i8 i16 i32), x2 trap code: CMP Xr, Wr, SXTB/SXTH/SXTW (SUBS extended,
3206; option 100/101/110, C6.2.463), then B.NE trap
3207:CHKEXT
3208 sub.x.i x3 x1 2
3209 ubfm.x x3 x3 51 50
3210 movz.x x9 0x001f 0
3211 movk.x x9 0xeb20 1 ; SUBS (extended register) 64-bit, Rd 31 = CMP, C6.2.463
3212 orr.x x3 x3 x9
3213 ubfm.x x9 x0 48 47
3214 orr.x x3 x3 x9
3215 ubfm.x x9 x0 59 58
3216 orr.x x0 x3 x9
3217 str.x.pre x30 sp -16
3218 bl EMIT
3219 movz.x x0 1 0
3220 mov.x x1 x2
3221 bl TRAPC
3222 ldr.x.post x30 sp 16
3223 ret
3224; RANGE: x1 number, x2 type, x3 1 when the number was written as 2^63 or more (TK_NUM, state slot 11):
3225; error 8 unless the number is a value of that type
3226:RANGE
3227 adr x9 TWID
3228 ldrb.r w9 x9 x2
3229 cmp.x.i x9 64
3230 b.eq RG_64
3231 cbnz.x x3 E_RANGE
3232 movz.x x10 1 0
3233 lslv.x x10 x10 x9
3234 cmp.x.i x2 6
3235 b.hs RG_S
3236 cmp.x x1 x10
3237 b.hs E_RANGE
3238 ret
3239:RG_S
3240 ubfm.x x10 x10 1 63
3241 add.x x11 x1 x10
3242 add.x x10 x10 x10
3243 cmp.x x11 x10
3244 b.hs E_RANGE
3245 ret
3246:RG_64
3247 cmp.x.i x2 9
3248 b.eq RG_L
3249 cbnz.x x3 RG_OK
3250 cmp.x.i x1 0
3251 b.lt E_RANGE
3252:RG_OK
3253 ret
3254:RG_L
3255 cbnz.x x3 E_RANGE
3256 ret
3257; ======================================================================================================
3258; TOK: next word. x0 kind (0 end of line, 1 word, 2 number, 3 end of input), x1 packed word (first 8
3259; characters, first in the low byte) or number, x2 length. Clobbers x0..x7.
3260:TOK
3261 cmp.x x19 x18
3262 b.hs TK_EOF
3263 ldrb w0 x19 0
3264 cmp.w.i w0 32
3265 b.eq TK_SKIP
3266 cmp.w.i w0 9
3267 b.eq TK_SKIP
3268 cmp.w.i w0 13
3269 b.eq TK_SKIP
3270 cmp.w.i w0 10
3271 b.eq TK_NL
3272 cmp.w.i w0 34
3273 b.eq TK_TEXT
3274 cmp.w.i w0 32
3275 b.lo E_SYNTAX
3276 b TK_WORD
3277; a text literal: kind 4, x1 its first byte, x2 its length in the source (escapes not yet read); it ends
3278; at the next " that is not after a \, on the same line, and is followed by a blank, a line end or the end
3279:TK_TEXT
3280 add.x.i x19 x19 1
3281 mov.x x1 x19
3282:TT1
3283 cmp.x x19 x18
3284 b.hs E_TEXT
3285 ldrb w0 x19 0
3286 cmp.w.i w0 10
3287 b.eq E_TEXT
3288 cmp.w.i w0 34
3289 b.eq TT_END
3290 add.x.i x19 x19 1
3291 cmp.w.i w0 92
3292 b.ne TT1
3293 cmp.x x19 x18
3294 b.hs E_TEXT
3295 ldrb w0 x19 0
3296 cmp.w.i w0 10
3297 b.eq E_TEXT
3298 add.x.i x19 x19 1
3299 b TT1
3300:TT_END
3301 sub.x x2 x19 x1
3302 add.x.i x19 x19 1
3303 movz.x x0 4 0
3304 cmp.x x19 x18
3305 b.hs TT_OK
3306 ldrb w3 x19 0
3307 cmp.w.i w3 32
3308 b.hi E_TEXT
3309:TT_OK
3310 ret
3311:TK_NL
3312 add.x.i x19 x19 1
3313 add.x.i x22 x22 1
3314 movz.x x0 0 0
3315 ret
3316:TK_SKIP
3317 add.x.i x19 x19 1
3318 b TOK
3319:TK_EOF
3320 movz.x x0 3 0
3321 ret
3322:TK_WORD
3323 movz.x x1 0 0
3324 movz.x x2 0 0
3325 movz.x x3 0 0
3326:TK_CH
3327 cmp.x x19 x18
3328 b.hs TK_END
3329 ldrb w0 x19 0
3330 cmp.w.i w0 32
3331 b.ls TK_END
3332 cmp.x.i x2 8
3333 b.hs TK_LONG
3334 lslv.x x4 x0 x3
3335 orr.x x1 x1 x4
3336 add.x.i x3 x3 8
3337:TK_LONG
3338 add.x.i x2 x2 1
3339 add.x.i x19 x19 1
3340 b TK_CH
3341:TK_END
3342 ubfm.x x4 x1 0 7
3343 cmp.x.i x4 45
3344 b.eq TK_NUM
3345 sub.x.i x4 x4 48
3346 cmp.x.i x4 9
3347 b.ls TK_NUM
3348 movz.x x0 1 0
3349 ret
3350; a number: [-]decimal, at most 20 digits, a value of some whole-number type: -2^63 .. 2^64 - 1, error 8
3351; outside. State slot 11 = 1 when it is 2^63 or more (only ulong holds such a number), else 0.
3352:TK_NUM
3353 sub.x x5 x19 x2
3354 movz.x x6 0 0
3355 ldrb w0 x5 0
3356 cmp.w.i w0 45
3357 b.ne TK_N1
3358 movz.x x6 1 0
3359 add.x.i x5 x5 1
3360:TK_N1
3361 sub.x x0 x19 x5
3362 cbz.x x0 E_NUM
3363 cmp.x.i x0 20
3364 b.hi E_NUM
3365 movz.x x1 0 0
3366 movz.x x7 10 0
3367 movz.x x3 0x9999 0 ; x3 = 0x1999999999999999 = (2^64 - 1) / 10 rounded down: x1 * 10 + digit fits
3368 movk.x x3 0x9999 1 ; unless x1 > x3, or x1 = x3 and digit > 5
3369 movk.x x3 0x9999 2
3370 movk.x x3 0x1999 3
3371:TK_N2
3372 cmp.x x5 x19
3373 b.hs TK_N3
3374 ldrb w0 x5 0
3375 sub.x.i x0 x0 48
3376 cmp.x.i x0 9
3377 b.hi E_NUM
3378 cmp.x x1 x3
3379 b.hi E_RANGE
3380 b.lo TK_N2A
3381 cmp.x.i x0 5
3382 b.hi E_RANGE
3383:TK_N2A
3384 mul.x x1 x1 x7
3385 add.x x1 x1 x0
3386 add.x.i x5 x5 1
3387 b TK_N2
3388:TK_N3
3389 movz.x x7 0x8000 3
3390 movz.x x4 0x185 1
3391 str.x xzr x4 11
3392 cbnz.x x6 TK_NEG
3393 cmp.x x1 x7
3394 b.lo TK_N4
3395 movz.x x3 1 0
3396 str.x x3 x4 11
3397:TK_N4
3398 movz.x x0 2 0
3399 ret
3400:TK_NEG
3401 cmp.x x1 x7
3402 b.hi E_RANGE
3403 sub.x x1 xzr x1
3404 movz.x x0 2 0
3405 ret
3406; KW: x1 packed word -> x0 keyword code (0 none). Clobbers x9..x11.
3407:KW
3408 adr x9 KWTAB
3409:KW1
3410 ldr.w w0 x9 2
3411 cbz.w w0 KW2
3412 ldr.x x10 x9 0
3413 cmp.x x10 x1
3414 b.eq KW2
3415 add.x.i x9 x9 16
3416 b KW1
3417:KW2
3418 ret
3419; TYPEWORD: read a type name -> x0 type 1..9
3420:TYPEWORD
3421 str.x.pre x30 sp -16
3422 bl TOK
3423 cbz.x x0 E_FEW
3424 cmp.x.i x0 1
3425 b.ne E_SYNTAX
3426 cmp.x.i x2 8
3427 b.hi E_SYNTAX
3428 bl KW
3429 cmp.x.i x0 76
3430 b.eq E_SUBSET
3431 sub.x.i x9 x0 1
3432 cmp.x.i x9 8
3433 b.hi E_SYNTAX
3434 ldr.x.post x30 sp 16
3435 ret
3436; EOL: the line must end here
3437:EOL
3438 str.x.pre x30 sp -16
3439 bl TOK
3440 cbz.x x0 EOL1
3441 cmp.x.i x0 3
3442 b.ne E_EXTRA
3443:EOL1
3444 ldr.x.post x30 sp 16
3445 ret
3446; ALLOC: -> x0 the next free register of the pool. Clobbers x9.
3447:ALLOC
3448 add.x x0 x29 x24
3449 adr x9 POOLEND
3450 cmp.x x0 x9
3451 b.hs E_REGS
3452 ldrb w0 x0 0
3453 add.x.i x24 x24 1
3454 ret
3455; DESTREG: x0 destination register, or 255 for a new temporary
3456:DESTREG
3457 cmp.x.i x0 255
3458 b.eq ALLOC
3459 ret
3460; EMIT: x0 word -> output. Clobbers x9.
3461:EMIT
3462 movz.x x9 0x180 1
3463 cmp.x x20 x9
3464 b.hs E_FULL
3465 str.w.post w0 x20 4
3466 ret
3467; E3: emit x0 | x1 | x2 << 5 | x3 << 16. Clobbers x0..x3, x9.
3468:E3
3469 orr.x x0 x0 x1
3470 ubfm.x x2 x2 59 58
3471 orr.x x0 x0 x2
3472 ubfm.x x3 x3 48 47
3473 orr.x x0 x0 x3
3474 b EMIT
3475; TRAPC: x0 condition, x1 trap code: B.cond (C6.2.34) to the trap stub, distance filled at the end
3476:TRAPC
3477 movz.x x9 0x5400 1
3478 orr.x x0 x0 x9
3479; TRAPSITE: x0 branch word, x1 trap code: note the place, emit the word
3480:TRAPSITE
3481 movz.x x9 0x183 1
3482 cmp.x x26 x9
3483 b.hs E_FULL
3484 str.w w20 x26 0
3485 str.w w1 x26 1
3486 add.x.i x26 x26 8
3487 b EMIT
3488; PATCH19: x0 address of a B.cond/CBZ/CBNZ, x1 target: the word distance into bits 5..23
3489:PATCH19
3490 sub.x x2 x1 x0
3491 ubfm.x x2 x2 2 20
3492 ubfm.x x2 x2 59 58
3493 ldr.w w1 x0 0
3494 orr.x x1 x1 x2
3495 str.w w1 x0 0
3496 ret
3497; PATCH26: x0 address of a B, x1 target: the word distance into bits 0..25
3498:PATCH26
3499 sub.x x2 x1 x0
3500 ubfm.x x2 x2 2 27
3501 ldr.w w1 x0 0
3502 orr.x x1 x1 x2
3503 str.w w1 x0 0
3504 ret
3505; BACK: x0 earlier address: emit B to it (C6.2.35)
3506:BACK
3507 sub.x x2 x0 x20
3508 ubfm.x x2 x2 2 27
3509 movz.x x0 0x1400 1 ; B, C6.2.35
3510 orr.x x0 x0 x2
3511 b EMIT
3512; ======================================================================================================
3513; errors
3514:E_READ
3515 movz.x x0 1 0
3516 b FAIL
3517:E_WRITE
3518 movz.x x0 2 0
3519 b FAIL
3520:E_UNDEF
3521 movz.x x0 3 0
3522 b FAIL
3523:E_FEW
3524 movz.x x0 4 0
3525 b FAIL
3526:E_EXTRA
3527 movz.x x0 5 0
3528 b FAIL
3529:E_NUM
3530 movz.x x0 6 0
3531 b FAIL
3532:E_TYPE
3533 movz.x x0 7 0
3534 b FAIL
3535:E_RANGE
3536 movz.x x0 8 0
3537 b FAIL
3538:E_SUBSET
3539 movz.x x0 9 0
3540 b FAIL
3541:E_TWICE
3542 movz.x x0 10 0
3543 b FAIL
3544:E_BARE
3545 movz.x x0 11 0
3546 b FAIL
3547:E_REGS
3548 movz.x x0 12 0
3549 b FAIL
3550:E_LONG
3551 movz.x x0 13 0
3552 b FAIL
3553:E_FULL
3554 movz.x x0 14 0
3555 b FAIL
3556:E_BLOCK
3557 movz.x x0 15 0
3558 b FAIL
3559:E_SYNTAX
3560 movz.x x0 16 0
3561 b FAIL
3562; PUTDEC: x0 number: its decimal digits at x9 (x9 moves on)
3563:PUTDEC
3564 movz.x x1 10 0
3565 add.x.i x2 x9 40
3566 mov.x x3 x2
3567:PD1
3568 udiv.x x4 x0 x1
3569 msub.x x5 x4 x1 x0
3570 add.x.i x5 x5 48
3571 sub.x.i x3 x3 1
3572 strb w5 x3 0
3573 mov.x x0 x4
3574 cbnz.x x0 PD1
3575:PD2
3576 ldrb w5 x3 0
3577 strb w5 x9 0
3578 add.x.i x9 x9 1
3579 add.x.i x3 x3 1
3580 cmp.x x3 x2
3581 b.lo PD2
3582 ret
3583; div, rem (signed): CBZ Xb -> trap 2 unless b is a number other than 0; SDIV (C6.2.357); i64 div also
3584; traps 1 for MIN / -1: CMN Xb, #1 (ADDS immediate, C6.2.10); B.NE over the next two (C6.2.34);
3585; NEGS XZR, Xa (SUBS shifted register, C6.2.465) sets V only for MIN; B.VS trap 1. i8/i16/i32: the
3586; quotient is exact in 64 bits, then the sign-extension check (trap 1). rem: t = a / b; rd = a - t * b
3587; (MSUB, C6.2.291), always in range (MIN rem -1 = 0).
3588:BO_SDIV
3589 ldr.x x10 sp 3
3590 ldr.x x0 x10 3
3591 cmp.x.i x0 3
3592 b.ne SD1
3593 ldr.x x0 x10 4
3594 cbnz.x x0 SD2
3595:SD1
3596 ldr.x x0 sp 5
3597 movz.x x9 0xb400 1 ; CBZ Xb, C6.2.78
3598 orr.x x0 x0 x9
3599 movz.x x1 2 0
3600 bl TRAPSITE
3601:SD2
3602 ldr.x x9 sp 1
3603 cmp.x.i x9 37
3604 b.eq SD_REM
3605 ldr.x x9 sp 6
3606 cmp.x.i x9 9
3607 b.ne SD4
3608 ldr.x x10 sp 3
3609 ldr.x x0 x10 3
3610 cmp.x.i x0 3
3611 b.ne SD3
3612 ldr.x x0 x10 4
3613 cmn.x.i x0 1
3614 b.ne SD4
3615:SD3
3616 movz.x x0 0x041f 0
3617 movk.x x0 0xb100 1 ; CMN Xb, #1 = ADDS XZR, Xb, #1, C6.2.10
3618 ldr.x x1 sp 5
3619 ubfm.x x1 x1 59 58
3620 orr.x x0 x0 x1
3621 bl EMIT
3622 movz.x x0 0x0061 0
3623 movk.x x0 0x5400 1 ; B.NE +3 words, C6.2.34
3624 bl EMIT
3625 movz.x x0 0x03ff 0
3626 movk.x x0 0xeb00 1 ; NEGS XZR, Xa = SUBS XZR, XZR, Xa, C6.2.465
3627 ldr.x x1 sp 4
3628 ubfm.x x1 x1 48 47
3629 orr.x x0 x0 x1
3630 bl EMIT
3631 movz.x x0 6 0
3632 movz.x x1 1 0
3633 bl TRAPC
3634:SD4
3635 movz.x x0 0x0c00 0
3636 movk.x x0 0x9ac0 1 ; SDIV 64-bit, C6.2.357
3637 bl BO_W3
3638 ldr.x x9 sp 6
3639 cmp.x.i x9 9
3640 b.eq BO_RET
3641 bl BO_FIX
3642 b BO_RET
3643:SD_REM
3644 bl ALLOC
3645 str.x x0 sp 8
3646 movz.x x0 0x0c00 0
3647 movk.x x0 0x9ac0 1 ; SDIV, C6.2.357
3648 ldr.x x1 sp 8
3649 ldr.x x2 sp 4
3650 ldr.x x3 sp 5
3651 bl E3
3652 movz.x x0 0x8000 0
3653 movk.x x0 0x9b00 1 ; MSUB 64-bit, C6.2.291 (Ra at bit 10)
3654 ldr.x x1 sp 4
3655 ubfm.x x1 x1 54 53
3656 orr.x x0 x0 x1
3657 ldr.x x1 sp 2
3658 ldr.x x2 sp 8
3659 ldr.x x3 sp 5
3660 bl E3
3661 b BO_RET
3662; shl (i64): t = a << s (LSLV C6.2.271, or UBFM C6.2.487 for a number); X16 = t >> s arithmetic (ASRV
3663; C6.2.21, or SBFM C6.2.355); CMP X16, Xa (C6.2.97); B.NE trap 1 (a bit left the value); MOV Xd, Xt.
3664; (i8/i16/i32 shift in 64 bits exactly and take the sign-extension check of BO_FIX, as unsigned types
3665; take their wrap.)
3666:BS_64
3667 bl ALLOC
3668 str.x x0 sp 8
3669 ldr.x x10 sp 7
3670 cbnz.x x10 BS64_I
3671 bl BO_SCHK
3672 movz.x x0 0x2000 0
3673 movk.x x0 0x9ac0 1 ; LSLV Xt, Xa, Xb, C6.2.271
3674 ldr.x x1 sp 8
3675 ldr.x x2 sp 4
3676 ldr.x x3 sp 5
3677 bl E3
3678 movz.x x0 0x2810 0
3679 movk.x x0 0x9ac0 1 ; ASRV X16, Xt, Xb, C6.2.21
3680 movz.x x1 0 0
3681 ldr.x x2 sp 8
3682 ldr.x x3 sp 5
3683 bl E3
3684 b BS64_C
3685:BS64_I
3686 ldr.x x1 sp 5
3687 movz.x x2 64 0
3688 sub.x x2 x2 x1
3689 ubfm.x x2 x2 0 5
3690 movz.x x3 63 0
3691 sub.x x3 x3 x1
3692 movz.x x0 0xd340 1 ; UBFM Xt, Xa, #(64-s) mod 64, #63-s = LSL, C6.2.487
3693 ubfm.x x2 x2 48 47
3694 orr.x x0 x0 x2
3695 ubfm.x x3 x3 54 53
3696 orr.x x0 x0 x3
3697 ldr.x x1 sp 4
3698 ubfm.x x1 x1 59 58
3699 orr.x x0 x0 x1
3700 ldr.x x1 sp 8
3701 orr.x x0 x0 x1
3702 bl EMIT
3703 movz.x x0 0xfc10 0
3704 movk.x x0 0x9340 1 ; SBFM X16, Xt, #s, #63 = ASR, C6.2.355
3705 ldr.x x1 sp 5
3706 ubfm.x x1 x1 48 47
3707 orr.x x0 x0 x1
3708 ldr.x x1 sp 8
3709 ubfm.x x1 x1 59 58
3710 orr.x x0 x0 x1
3711 bl EMIT
3712:BS64_C
3713 movz.x x0 0x021f 0
3714 movk.x x0 0xeb00 1 ; CMP X16, Xa = SUBS XZR, X16, Xa, C6.2.97
3715 ldr.x x1 sp 4
3716 ubfm.x x1 x1 48 47
3717 orr.x x0 x0 x1
3718 bl EMIT
3719 movz.x x0 1 0
3720 movz.x x1 1 0
3721 bl TRAPC
3722 movz.x x0 0x03e0 0
3723 movk.x x0 0xaa00 1 ; MOV Xd, Xt = ORR Xd, XZR, Xt, C6.2.282
3724 ldr.x x1 sp 2
3725 orr.x x0 x0 x1
3726 ldr.x x1 sp 8
3727 ubfm.x x1 x1 48 47
3728 orr.x x0 x0 x1
3729 bl EMIT
3730 b BO_RET
3731; ======================================================================================================
3732; values new in om4 (inside VALTOK's frame: 0 x30, 1 expected, 2 dest, 3 op, 4.. free)
3733; true, false: bool numbers
3734:VT_TRUE
3735 movz.x x0 3 0
3736 movz.x x1 1 0
3737 movz.x x2 1 0
3738 b VT_RET
3739:VT_FALSE
3740 movz.x x0 3 0
3741 movz.x x1 0 0
3742 movz.x x2 1 0
3743 b VT_RET
3744; len A: the length of A, a ulong number
3745:VT_LEN
3746 bl ARRNAME
3747 ldr.w w9 x0 5
3748 cmp.x.i x9 10
3749 b.eq VL_POOL
3750 ldr.w w1 x0 4
3751 movz.x x0 3 0
3752 movz.x x2 5 0
3753 b VT_RET
3754; len P of a run-time pool: a run-time load of the slot's length, LDR Xd, [Xd, #8] (C6.2.214; omc.om pl_len)
3755:VL_POOL
3756 str.x x0 sp 4
3757 ldr.x x0 sp 2
3758 bl DESTREG
3759 str.x x0 sp 7
3760 ldr.x x9 sp 4
3761 ldr.x x1 x9 3
3762 bl MATCONST
3763 ldr.x x1 sp 7
3764 movz.x x0 0x0400 0
3765 movk.x x0 0xf940 1 ; LDR Xt, [Xn, #8], C6.2.214
3766 orr.x x0 x0 x1
3767 ubfm.x x1 x1 59 58
3768 orr.x x0 x0 x1
3769 bl EMIT
3770 movz.x x0 1 0
3771 ldr.x x1 sp 7
3772 movz.x x2 5 0
3773 b VT_RET
3774; get A i: the checked load (the load of the element type, register offset, LDOP table)
3775:VT_GET
3776 bl ARRNAME
3777 str.x x0 sp 4
3778 movz.x x0 5 0
3779 movz.x x1 255 0
3780 bl VAL
3781 mov.x x3 x2
3782 mov.x x2 x1
3783 mov.x x1 x0
3784 ldr.x x0 sp 4
3785 bl ELEMADDR
3786 str.x x0 sp 5
3787 str.x x1 sp 6
3788 ldr.x x0 sp 2
3789 bl DESTREG
3790 str.x x0 sp 7
3791 ldr.x x9 sp 4
3792 ldr.w w9 x9 3
3793 adr x10 LDOP
3794 ldr.w.r w0 x10 x9
3795 ldr.x x1 sp 7
3796 orr.x x0 x0 x1
3797 ldr.x x1 sp 5
3798 ubfm.x x1 x1 59 58
3799 orr.x x0 x0 x1
3800 ldr.x x1 sp 6
3801 ubfm.x x1 x1 48 47
3802 orr.x x0 x0 x1
3803 bl EMIT
3804 movz.x x0 1 0
3805 ldr.x x1 sp 7
3806 ldr.x x9 sp 4
3807 ldr.w w2 x9 3
3808 b VT_RET
3809; read fd A off n / write fd A off n: a long (bytes moved, or minus the Linux error number). fd int, off
3810; and n ulong; n <= len A and off <= len A - n, else trap 3 (CMP C6.2.97, B.HI C6.2.34, SUB C6.2.458).
3811; Then as a call: save the registers in use, X0 = fd, X1 = A + off (ADD through X16, C6.2.6), X2 = n,
3812; X8 = 63 (read) or 64 (write), SVC #0 (C6.2.466), the result from X0, the registers back.
3813; Frame: 4/5 fd, 6 A, 7/8 off, 9/10 n, 11 t, 12 saved count, 13 save bytes, 14 pool slot before.
3814:VT_SYS
3815 str.x x24 sp 14
3816 movz.x x0 8 0
3817 movz.x x1 255 0
3818 bl VAL
3819 cmp.x.i x2 8
3820 b.ne E_TYPE
3821 str.x x0 sp 4
3822 str.x x1 sp 5
3823 bl ARRNAME
3824 ldr.w w9 x0 5
3825 cmp.x.i x9 10
3826 b.eq E_SUBSET ; read / write on a run-time pool: omc only
3827 str.x x0 sp 6
3828 ldr.x x9 sp 3
3829 cmp.x.i x9 53
3830 b.ne VS1
3831 ldr.w w9 x0 5
3832 cmp.x.i x9 2
3833 b.eq E_RDONLY
3834 cmp.x.i x9 5
3835 b.eq E_RDONLY
3836:VS1
3837 movz.x x0 5 0
3838 movz.x x1 255 0
3839 bl VAL
3840 cmp.x.i x2 5
3841 b.ne E_TYPE
3842 bl MATREG
3843 str.x x0 sp 8
3844 movz.x x0 5 0
3845 movz.x x1 255 0
3846 bl VAL
3847 cmp.x.i x2 5
3848 b.ne E_TYPE
3849 bl MATREG
3850 str.x x0 sp 10
3851 bl ALLOC
3852 str.x x0 sp 11
3853 ldr.x x9 sp 6
3854 ldr.w w1 x9 4
3855 bl MATCONST
3856 movz.x x0 0x001f 0
3857 movk.x x0 0xeb00 1 ; CMP Xn, Xt, C6.2.97
3858 ldr.x x1 sp 10
3859 ubfm.x x1 x1 59 58
3860 orr.x x0 x0 x1
3861 ldr.x x1 sp 11
3862 ubfm.x x1 x1 48 47
3863 orr.x x0 x0 x1
3864 bl EMIT
3865 movz.x x0 8 0
3866 movz.x x1 3 0
3867 bl TRAPC
3868 movz.x x0 0 0
3869 movk.x x0 0xcb00 1 ; SUB Xt, Xt, Xn, C6.2.458
3870 ldr.x x1 sp 11
3871 ldr.x x2 sp 11
3872 ldr.x x3 sp 10
3873 bl E3
3874 movz.x x0 0x001f 0
3875 movk.x x0 0xeb00 1 ; CMP Xoff, Xt, C6.2.97
3876 ldr.x x1 sp 8
3877 ubfm.x x1 x1 59 58
3878 orr.x x0 x0 x1
3879 ldr.x x1 sp 11
3880 ubfm.x x1 x1 48 47
3881 orr.x x0 x0 x1
3882 bl EMIT
3883 movz.x x0 8 0
3884 movz.x x1 3 0
3885 bl TRAPC
3886 bl SAVE
3887 str.x x0 sp 12
3888 str.x x1 sp 13
3889 movz.x x0 0 0
3890 ldr.x x1 sp 4
3891 ldr.x x2 sp 5
3892 bl LOADARG
3893 movz.x x0 1 0
3894 ldr.x x9 sp 6
3895 bl BASEARG
3896 movz.x x0 16 0
3897 movz.x x1 1 0
3898 ldr.x x2 sp 8
3899 bl LOADARG
3900 movz.x x0 0x0021 0
3901 movk.x x0 0x8b10 1 ; ADD X1, X1, X16, C6.2.6
3902 bl EMIT
3903 movz.x x0 2 0
3904 movz.x x1 1 0
3905 ldr.x x2 sp 10
3906 bl LOADARG
3907 ldr.x x9 sp 3
3908 add.x.i x9 x9 10
3909 ubfm.x x9 x9 59 58
3910 movz.x x0 0x0008 0
3911 movk.x x0 0xd280 1 ; MOVZ X8, #63 or #64, C6.2.285
3912 orr.x x0 x0 x9
3913 bl EMIT
3914 movz.x x0 0x0001 0
3915 movk.x x0 0xd400 1 ; SVC #0, C6.2.466
3916 bl EMIT
3917 ldr.x x0 sp 2
3918 ldr.x x1 sp 14
3919 ldr.x x2 sp 12
3920 ldr.x x3 sp 13
3921 movz.x x4 1 0
3922 bl RESTORE
3923 mov.x x1 x0
3924 movz.x x0 1 0
3925 movz.x x2 9 0
3926 b VT_RET
3927; ======================================================================================================
3928; CALL: x0 function entry, x1 destination (255 none). Reads the arguments, then: SAVE; each argument into
3929; X0..X5 from the save area (LOADARG); BL (C6.2.43); RESTORE. Out: x0 1, x1 result register, x2 type.
3930; Frame: 0 x30, 1 entry, 2 dest, 3 pool slot before, 4 i, 5 parameter count, 6.. 3 per argument (kind,
3931; register/number, name entry of an array), 24 saved count, 25 save bytes.
3932:CALL
3933 sub.x.i sp sp 224
3934 str.x x30 sp 0
3935 str.x x0 sp 1
3936 str.x x1 sp 2
3937 str.x x24 sp 3
3938 str.x xzr sp 4
3939 ldr.w w9 x0 5
3940 str.x x9 sp 5
3941 movz.x x9 0x185 1
3942 ldr.x x10 x9 6
3943 cbnz.x x10 CA_ARG
3944 ldr.x x10 x9 3
3945 cmp.x x10 x0
3946 b.eq E_SUBSET
3947:CA_ARG
3948 ldr.x x9 sp 4
3949 ldr.x x10 sp 5
3950 cmp.x x9 x10
3951 b.hs CA_DONE
3952 ldr.x x11 sp 1
3953 ubfm.x x12 x9 60 59
3954 add.x x11 x11 x12
3955 ldr.w w12 x11 8
3956 cbnz.x x12 CA_ARR
3957 ldr.w w0 x11 6
3958 movz.x x1 255 0
3959 bl VAL
3960 cmp.x.i x0 4
3961 b.ne CA1
3962 bl MATREG
3963 mov.x x1 x0
3964 movz.x x0 1 0
3965 movz.x x2 1 0
3966:CA1
3967 ldr.x x9 sp 4
3968 ldr.x x11 sp 1
3969 ubfm.x x12 x9 60 59
3970 add.x x11 x11 x12
3971 ldr.w w12 x11 6
3972 cmp.x x2 x12
3973 b.ne E_TYPE
3974 movz.x x3 0 0
3975 b CA_PUT
3976:CA_ARR
3977 bl ARRARG
3978 mov.x x3 x2
3979 ldr.x x9 sp 4
3980 movz.x x10 0 0
3981:CA2
3982 cmp.x x10 x9
3983 b.hs CA_PUT
3984 movz.x x11 3 0
3985 mul.x x11 x11 x10
3986 add.x.i x11 x11 8
3987 ldr.x.r x12 sp x11
3988 cmp.x x12 x3
3989 b.eq E_ALIAS
3990 add.x.i x10 x10 1
3991 b CA2
3992:CA_PUT
3993 ldr.x x9 sp 4
3994 movz.x x11 3 0
3995 mul.x x11 x11 x9
3996 add.x.i x11 x11 6
3997 str.x.r x0 sp x11
3998 add.x.i x11 x11 1
3999 str.x.r x1 sp x11
4000 add.x.i x11 x11 1
4001 str.x.r x3 sp x11
4002 add.x.i x9 x9 1
4003 str.x x9 sp 4
4004 b CA_ARG
4005:CA_DONE
4006 bl SAVE
4007 str.x x0 sp 24
4008 str.x x1 sp 25
4009 movz.x x13 0 0
4010:CA3
4011 ldr.x x10 sp 5
4012 cmp.x x13 x10
4013 b.hs CA4
4014 movz.x x11 3 0
4015 mul.x x11 x11 x13
4016 add.x.i x11 x11 6
4017 ldr.x.r x1 sp x11
4018 add.x.i x11 x11 1
4019 ldr.x.r x2 sp x11
4020 mov.x x0 x13
4021 bl LOADARG
4022 add.x.i x13 x13 1
4023 b CA3
4024:CA4
4025 movz.x x9 0x185 1
4026 ldr.x x10 x9 12
4027 movz.x x11 1 1
4028 cmp.x x10 x11
4029 b.hs E_FULL
4030 movz.x x11 24 0
4031 mul.x x11 x11 x10
4032 movz.x x12 0x186 1
4033 add.x x11 x11 x12
4034 str.x x20 x11 0
4035 ldr.x x12 sp 1
4036 str.x x12 x11 1
4037 ldr.x x12 x9 3
4038 str.x x12 x11 2
4039 add.x.i x10 x10 1
4040 str.x x10 x9 12
4041 ldr.x x9 sp 1
4042
4043 ldr.x x0 x9 1
4044 sub.x x2 x0 x20
4045 ubfm.x x2 x2 2 27
4046 movz.x x0 0x9400 1 ; BL, C6.2.43
4047 orr.x x0 x0 x2
4048 bl EMIT
4049 ldr.x x9 sp 1
4050 ldr.w w9 x9 4
4051 movz.x x4 1 0
4052 cmp.x.i x9 10
4053 b.ne CA5
4054 movz.x x4 0 0
4055:CA5
4056 ldr.x x0 sp 2
4057 ldr.x x1 sp 3
4058 ldr.x x2 sp 24
4059 ldr.x x3 sp 25
4060 bl RESTORE
4061 mov.x x1 x0
4062 movz.x x0 1 0
4063 ldr.x x9 sp 1
4064 ldr.w w2 x9 4
4065 ldr.x x30 sp 0
4066 add.x.i sp sp 224
4067 ret
4068; ARRARG: an array argument for the parameter at x11 (type +24, length +28, kind +32): [view | edit] NAME.
4069; Its type and length must equal the parameter's; an edit parameter needs a writable array (local or edit,
4070; error 20); a global is never passed (error 19: only so is every pair of live references disjoint).
4071; Out: x0 5 (register x1) or 6 (address x1, a text), x2 the name entry.
4072:ARRARG
4073 str.x.pre x30 sp -32
4074 str.x x11 sp 1
4075 str.x xzr sp 2
4076 bl TOK
4077 cbz.x x0 E_FEW
4078 cmp.x.i x0 1
4079 b.ne E_SYNTAX
4080 cmp.x.i x2 8
4081 b.hi E_LONG
4082 str.x x1 sp 3
4083 bl KW
4084 cbz.x x0 AA1
4085 cmp.x.i x0 57
4086 b.lo E_SYNTAX
4087 cmp.x.i x0 58
4088 b.hi E_SYNTAX
4089 str.x x0 sp 2
4090 bl TOK
4091 cbz.x x0 E_FEW
4092 cmp.x.i x0 1
4093 b.ne E_SYNTAX
4094 cmp.x.i x2 8
4095 b.hi E_LONG
4096 str.x x1 sp 3
4097:AA1
4098 ldr.x x1 sp 3
4099 bl FINDNAME
4100 cbz.x x0 E_UNDEF
4101 ldr.w w9 x0 5
4102 cbz.x x9 E_TYPE
4103 cmp.x.i x9 4
4104 b.eq E_ALIAS
4105 cmp.x.i x9 10
4106 b.eq E_ALIAS
4107 ldr.x x11 sp 1
4108 ldr.w w10 x11 8
4109 cmp.x.i x10 3
4110 b.ne AA2
4111 ldr.x x12 sp 2
4112 cmp.x.i x12 57
4113 b.eq E_RDONLY ; view A to an edit parameter: passing a view as edit is error 20 (OMEGESE.md 9.4)
4114 cmp.x.i x9 1
4115 b.eq AA3
4116 cmp.x.i x9 3
4117 b.ne E_RDONLY
4118 b AA3
4119:AA2
4120 ldr.x x12 sp 2
4121 cmp.x.i x12 58
4122 b.eq E_TYPE
4123:AA3
4124 ldr.w w12 x0 3
4125 ldr.w w13 x11 6
4126 cmp.x x12 x13
4127 b.ne E_TYPE
4128 ldr.w w12 x0 4
4129 ldr.w w13 x11 7
4130 cmp.x x12 x13
4131 b.ne E_TYPE
4132 mov.x x2 x0
4133 cmp.x.i x9 5
4134 b.eq AA4
4135 ldr.w w1 x0 2
4136 movz.x x0 5 0
4137 b AA5
4138:AA4
4139 ldr.x x1 x0 3
4140 movz.x x0 6 0
4141:AA5
4142 ldr.x.post x30 sp 32
4143 ret
4144; SAVE: n = registers in use (parameters + pool slots), A = 8 (n + 1) rounded up to 16: SUB SP, SP, #A
4145; (C6.2.457); program mode: CMP SP, X28 (C6.2.463), B.LO trap 6; STR Xr, [SP, #8j] for each (C6.2.415,
4146; unsigned offset); STR X30, [SP, #8n]. Out: x0 n, x1 A.
4147:SAVE
4148 str.x.pre x30 sp -32
4149 adr x9 POOLC
4150 sub.x x10 x29 x9
4151 add.x x10 x10 x24
4152 str.x x10 sp 1
4153 add.x.i x11 x10 2
4154 ubfm.x x11 x11 1 63
4155 ubfm.x x11 x11 60 59
4156 str.x x11 sp 2
4157 mov.x x1 x11
4158 bl SPSUB
4159 bl STKCHK
4160 movz.x x13 0 0
4161:SV1
4162 ldr.x x10 sp 1
4163 cmp.x x13 x10
4164 b.hs SV2
4165 adr x9 POOLC
4166 ldrb.r w0 x9 x13
4167 movz.x x9 0x03e0 0
4168 movk.x x9 0xf900 1 ; STR Xr, [SP, #8j], C6.2.415
4169 orr.x x0 x0 x9
4170 ubfm.x x1 x13 54 53
4171 orr.x x0 x0 x1
4172 bl EMIT
4173 add.x.i x13 x13 1
4174 b SV1
4175:SV2
4176 movz.x x0 0x03fe 0
4177 movk.x x0 0xf900 1 ; STR X30, [SP, #8n], C6.2.415
4178 ubfm.x x1 x13 54 53
4179 orr.x x0 x0 x1
4180 bl EMIT
4181 ldr.x x0 sp 1
4182 ldr.x x1 sp 2
4183 ldr.x.post x30 sp 32
4184 ret
4185; LOADARG: x0 target register, x1 kind (1 or 5: register x2, read back from its save slot: LDR Xt, [SP,
4186; #8 slot], C6.2.216; 3 or 6: the number or address x2, MATCONST)
4187:LOADARG
4188 cmp.x.i x1 3
4189 b.eq MATCONST_X
4190 cmp.x.i x1 6
4191 b.eq MATCONST_X
4192 adr x9 REGIDX
4193 ldrb.r w9 x9 x2
4194 movz.x x10 0x03e0 0
4195 movk.x x10 0xf940 1 ; LDR Xt, [SP, #8j], C6.2.216
4196 orr.x x0 x0 x10
4197 ubfm.x x9 x9 54 53
4198 orr.x x0 x0 x9
4199 b EMIT
4200:MATCONST_X
4201 mov.x x1 x2
4202 b MATCONST
4203; BASEARG: x0 target register, x9 an array's name entry: its register from the save area, or its address
4204:BASEARG
4205 ldr.w w10 x9 5
4206 cmp.x.i x10 4
4207 b.hs BA_ADDR
4208 movz.x x1 1 0
4209 ldr.w w2 x9 2
4210 b LOADARG
4211:BA_ADDR
4212 ldr.x x1 x9 3
4213 b MATCONST
4214; RESTORE: x0 destination (255: a new temporary at pool slot x1), x1 pool slot before the arguments, x2
4215; saved count, x3 save bytes, x4 1 if there is a result in X0. MOV Xd, X0 (C6.2.282); LDR each register
4216; in use before the arguments except Xd (C6.2.216); LDR X30; ADD SP, SP, #A (C6.2.5). Out: x0 Xd.
4217:RESTORE
4218 str.x.pre x30 sp -64
4219 str.x x2 sp 2
4220 str.x x3 sp 3
4221 mov.x x24 x1
4222 str.x x1 sp 4
4223 movz.x x9 255 0
4224 str.x x9 sp 1
4225 cbz.x x4 RS2
4226 cmp.x.i x0 255
4227 b.ne RS1
4228 bl ALLOC
4229:RS1
4230 str.x x0 sp 1
4231 cbz.x x0 RS2
4232 movz.x x9 0x03e0 0
4233 movk.x x9 0xaa00 1 ; MOV Xd, X0 = ORR Xd, XZR, X0, C6.2.282
4234 orr.x x0 x0 x9
4235 bl EMIT
4236:RS2
4237 movz.x x13 0 0
4238 adr x9 POOLC
4239 sub.x x14 x29 x9
4240 ldr.x x9 sp 4
4241 add.x x14 x14 x9
4242:RS3
4243 cmp.x x13 x14
4244 b.hs RS4
4245 adr x9 POOLC
4246 ldrb.r w0 x9 x13
4247 ldr.x x9 sp 1
4248 cmp.x x0 x9
4249 b.eq RS5
4250 movz.x x9 0x03e0 0
4251 movk.x x9 0xf940 1 ; LDR Xr, [SP, #8j], C6.2.216
4252 orr.x x0 x0 x9
4253 ubfm.x x1 x13 54 53
4254 orr.x x0 x0 x1
4255 bl EMIT
4256:RS5
4257 add.x.i x13 x13 1
4258 b RS3
4259:RS4
4260 movz.x x0 0x03fe 0
4261 movk.x x0 0xf940 1 ; LDR X30, [SP, #8n], C6.2.216
4262 ldr.x x1 sp 2
4263 ubfm.x x1 x1 54 53
4264 orr.x x0 x0 x1
4265 bl EMIT
4266 ldr.x x1 sp 3
4267 bl SPADD
4268 ldr.x x0 sp 1
4269 ldr.x.post x30 sp 64
4270 ret
4271; ======================================================================================================
4272; ELEMADDR: x0 array name entry, index x1 kind, x2 number or register, x3 type. A number index must be
4273; inside the array (error 21) and needs no check; a register index: CMP Xi, #len (C6.2.96) or CMP Xi, Xt
4274; (C6.2.97), B.HS trap 3 (unsigned, so a negative signed index traps too). Out: x0 base register (the
4275; array's register, or a new one holding its address), x1 index register.
4276:ELEMADDR
4277 str.x.pre x30 sp -48
4278 str.x x0 sp 1
4279 cmp.x.i x3 1
4280 b.eq E_TYPE
4281 ldr.w w9 x0 5
4282 cmp.x.i x9 10
4283 b.eq EA_POOL
4284 cmp.x.i x1 3
4285 b.ne EA_R
4286 ldr.w w9 x0 4
4287 cmp.x x2 x9
4288 b.hs E_BOUNDS
4289 str.x x2 sp 2
4290 bl ALLOC
4291 str.x x0 sp 3
4292 ldr.x x1 sp 2
4293 bl MATCONST
4294 b EA_B
4295:EA_R
4296 str.x x2 sp 3
4297 ldr.w w1 x0 4
4298 movz.x x9 4095 0
4299 cmp.x x1 x9
4300 b.hi EA_BIG
4301 movz.x x0 0x001f 0
4302 movk.x x0 0xf100 1 ; CMP Xi, #len, C6.2.96
4303 ubfm.x x1 x1 54 53
4304 orr.x x0 x0 x1
4305 b EA_C
4306:EA_BIG
4307 bl ALLOC
4308 str.x x0 sp 4
4309 bl MATCONST
4310 movz.x x0 0x001f 0
4311 movk.x x0 0xeb00 1 ; CMP Xi, Xt, C6.2.97
4312 ldr.x x1 sp 4
4313 ubfm.x x1 x1 48 47
4314 orr.x x0 x0 x1
4315:EA_C
4316 ldr.x x1 sp 3
4317 ubfm.x x1 x1 59 58
4318 orr.x x0 x0 x1
4319 bl EMIT
4320 movz.x x0 2 0
4321 movz.x x1 3 0
4322 bl TRAPC
4323:EA_B
4324 ldr.x x9 sp 1
4325 ldr.w w10 x9 5
4326 cmp.x.i x10 4
4327 b.hs EA_A
4328 ldr.w w0 x9 2
4329 b EA_X
4330:EA_A
4331 bl ALLOC
4332 str.x x0 sp 4
4333 ldr.x x9 sp 1
4334 ldr.x x1 x9 3
4335 bl MATCONST
4336 ldr.x x0 sp 4
4337:EA_X
4338 ldr.x x1 sp 3
4339 ldr.x.post x30 sp 48
4340 ret
4341; a run-time pool (omc.om ea_pool): the index in a register, the slot loaded after every operand (LDP Xb, Xl,
4342; [Xb], C6.2.163), CMP Xi, Xl (C6.2.97), B.HS trap 3; a number index too is checked at run time (no error 21)
4343:EA_POOL
4344 mov.x x0 x1
4345 mov.x x1 x2
4346 mov.x x2 x3
4347 bl MATREG
4348 str.x x0 sp 3
4349 bl ALLOC
4350 str.x x0 sp 4
4351 bl ALLOC
4352 str.x x0 sp 5
4353 ldr.x x0 sp 4
4354 ldr.x x9 sp 1
4355 ldr.x x1 x9 3
4356 bl MATCONST
4357 movz.x x0 0 0
4358 movk.x x0 0xa940 1 ; LDP Xb, Xl, [Xb], C6.2.163
4359 ldr.x x1 sp 4
4360 orr.x x0 x0 x1
4361 ubfm.x x1 x1 59 58
4362 orr.x x0 x0 x1
4363 ldr.x x1 sp 5
4364 ubfm.x x1 x1 54 53
4365 orr.x x0 x0 x1
4366 bl EMIT
4367 movz.x x0 0x001f 0
4368 movk.x x0 0xeb00 1 ; CMP Xi, Xl, C6.2.97
4369 ldr.x x1 sp 3
4370 ubfm.x x1 x1 59 58
4371 orr.x x0 x0 x1
4372 ldr.x x1 sp 5
4373 ubfm.x x1 x1 48 47
4374 orr.x x0 x0 x1
4375 bl EMIT
4376 movz.x x0 2 0
4377 movz.x x1 3 0
4378 bl TRAPC
4379 ldr.x x0 sp 4
4380 ldr.x x1 sp 3
4381 ldr.x.post x30 sp 48
4382 ret
4383; ARRNAME: read an array name -> x0 its entry
4384:ARRNAME
4385 str.x.pre x30 sp -16
4386 bl TOK
4387 cbz.x x0 E_FEW
4388 cmp.x.i x0 3
4389 b.eq E_FEW
4390 cmp.x.i x0 1
4391 b.ne E_SYNTAX
4392 cmp.x.i x2 8
4393 b.hi E_LONG
4394 bl FINDNAME
4395 cbz.x x0 E_UNDEF
4396 ldr.w w9 x0 5
4397 cbz.x x9 E_TYPE
4398 ldr.x.post x30 sp 16
4399 ret
4400; TOPNAME: read a new name for a global or a text -> x12
4401:TOPNAME
4402 str.x.pre x30 sp -16
4403 bl TOK
4404 cmp.x.i x0 1
4405 b.ne E_SYNTAX
4406 cmp.x.i x2 8
4407 b.hi E_LONG
4408 mov.x x12 x1
4409 bl KW
4410 cbnz.x x0 E_SYNTAX
4411 mov.x x1 x12
4412 bl NEWNAME
4413 ldr.x.post x30 sp 16
4414 ret
4415; FINDNAME: x1 packed name -> x0 its entry (0 none). Clobbers x9..x11.
4416:FINDNAME
4417 movz.x x9 0x180 1
4418 movz.x x10 0 0
4419:FD1
4420 cmp.x x10 x23
4421 b.hs FD0
4422 ldr.x x11 x9 0
4423 cmp.x x11 x1
4424 b.eq FDF
4425 add.x.i x9 x9 32
4426 add.x.i x10 x10 1
4427 b FD1
4428:FD0
4429 movz.x x0 0 0
4430 ret
4431:FDF
4432 mov.x x0 x9
4433 ret
4434; ADDNAME: x1 packed name, x2 register, x3 type, x4 length, x5 kind, x6 address. Clobbers x9, x10.
4435:ADDNAME
4436 cmp.x.i x23 1024
4437 b.hs E_FULL
4438 movz.x x9 0x180 1
4439 ubfm.x x10 x23 59 58
4440 add.x x9 x9 x10
4441 str.x x1 x9 0
4442 str.w w2 x9 2
4443 str.w w3 x9 3
4444 str.w w4 x9 4
4445 str.w w5 x9 5
4446 str.x x6 x9 3
4447 add.x.i x23 x23 1
4448 ret
4449; PUSHB: x0 branch to patch, x1 kind (1 if, 2 else, 3 while, 4 for), x2 head, x3 loop register,
4450; x4 its type, x5 names and x6 pool slots to restore at end; slot 7 = the then-part ended (for else)
4451:PUSHB
4452 movz.x x9 0x182 1
4453 cmp.x x25 x9
4454 b.hs E_FULL
4455 str.x x1 x25 0
4456 str.x x0 x25 1
4457 str.x x2 x25 2
4458 str.x x3 x25 3
4459 str.x x4 x25 4
4460 str.x x5 x25 5
4461 str.x x6 x25 6
4462 str.x xzr x25 7
4463 add.x.i x25 x25 128
4464 ret
4465; ELEMTYPE: x0 a type that an array may hold (uchar .. long, not bool)
4466:ELEMTYPE
4467 cmp.x.i x0 2
4468 b.lo E_SUBSET
4469 ret
4470; ARRLEN: x1 an array length: 1 .. 16777216 (error 8 below, 23 above; a number written as 2^63 or more,
4471; state slot 11, is above)
4472:ARRLEN
4473 movz.x x9 0x185 1
4474 ldr.x x9 x9 11
4475 cbnz.x x9 E_TOOBIG
4476 cmp.x.i x1 1
4477 b.lt E_RANGE
4478 movz.x x9 0x100 1
4479 cmp.x x1 x9
4480 b.hi E_TOOBIG
4481 ret
4482; EPI: ADD SP, SP, #stack of the local arrays (if any), then RET (C6.2.338)
4483:EPI
4484 str.x.pre x30 sp -16
4485 movz.x x9 0x185 1
4486 ldr.x x1 x9 4
4487 bl SPADD
4488 movz.x x0 0x03c0 0
4489 movk.x x0 0xd65f 1 ; RET (X30), C6.2.338
4490 bl EMIT
4491 ldr.x.post x30 sp 16
4492 ret
4493; SPADD / SPSUB: x1 bytes (a multiple of 16, below 2^24): ADD (C6.2.5) / SUB (C6.2.457) SP, SP, #low 12
4494; bits, then #high 12 bits LSL 12 (sh = 1, bit 22); nothing for a zero part
4495:SPADD
4496 movz.x x2 0x9100 1
4497 b SPOP
4498:SPSUB
4499 movz.x x2 0xd100 1
4500:SPOP
4501 str.x.pre x30 sp -32
4502 str.x x1 sp 1
4503 str.x x2 sp 2
4504 ubfm.x x3 x1 0 11
4505 cbz.x x3 SPO1
4506 movz.x x9 0x03ff 0
4507 orr.x x0 x2 x9
4508 ubfm.x x3 x3 54 53
4509 orr.x x0 x0 x3
4510 bl EMIT
4511:SPO1
4512 ldr.x x1 sp 1
4513 ubfm.x x3 x1 12 23
4514 cbz.x x3 SPO2
4515 ldr.x x2 sp 2
4516 movz.x x9 0x03ff 0
4517 movk.x x9 0x0040 1
4518 orr.x x0 x2 x9
4519 ubfm.x x3 x3 54 53
4520 orr.x x0 x0 x3
4521 bl EMIT
4522:SPO2
4523 ldr.x.post x30 sp 32
4524 ret
4525; STKCHK: program mode only: CMP SP, X28 (SUBS extended register, UXTX, Rn = SP, C6.2.463); B.LO trap 6
4526:STKCHK
4527 movz.x x9 0x185 1
4528 ldr.x x10 x9 6
4529 cbz.x x10 SK1
4530 str.x.pre x30 sp -16
4531 movz.x x0 0x63ff 0
4532 movk.x x0 0xeb3c 1 ; CMP SP, X28, C6.2.463
4533 bl EMIT
4534 movz.x x0 3 0
4535 movz.x x1 6 0
4536 bl TRAPC
4537 ldr.x.post x30 sp 16
4538:SK1
4539 ret
4540; DEAD1: the path has ended (ret, exit)
4541:DEAD1
4542 movz.x x9 0x185 1
4543 movz.x x10 1 0
4544 str.x x10 x9 5
4545 ret
4546; EMITB: x0 one byte -> output. Clobbers x9.
4547:EMITB
4548 movz.x x9 0x180 1
4549 cmp.x x20 x9
4550 b.hs E_FULL
4551 strb w0 x20 0
4552 add.x.i x20 x20 1
4553 ret
4554; ======================================================================================================
4555; errors new in om4, and FAIL
4556:E_DEAD
4557 movz.x x0 17 0
4558 b FAIL
4559:E_NORET
4560 movz.x x0 18 0
4561 b FAIL
4562:E_ALIAS
4563 movz.x x0 19 0
4564 b FAIL
4565:E_RDONLY
4566 movz.x x0 20 0
4567 b FAIL
4568:E_BOUNDS
4569 movz.x x0 21 0
4570 b FAIL
4571:E_TEXT
4572 movz.x x0 22 0
4573 b FAIL
4574:E_TOOBIG
4575 movz.x x0 23 0
4576 b FAIL
4577; FAIL: x0 code: "om4: line N: error E" and a newline on stderr (fd 2), exit E
4578:FAIL
4579 mov.x x12 x0
4580 movz.x x9 0x183 1
4581 adr x10 MSG1
4582 movz.x x11 10 0
4583 bl COPYN
4584 mov.x x0 x22
4585 bl PUTDEC
4586 adr x10 MSG2
4587 movz.x x11 8 0
4588 bl COPYN
4589 mov.x x0 x12
4590 bl PUTDEC
4591 movz.x x0 10 0
4592 strb w0 x9 0
4593 add.x.i x9 x9 1
4594 movz.x x0 2 0
4595 movz.x x1 0x183 1
4596 sub.x x2 x9 x1
4597 movz.x x8 64 0
4598 svc 0
4599 mov.x x0 x12
4600 movz.x x8 93 0
4601 svc 0
4602; COPYN: copy x11 bytes at x10 to x9 (x9 moves on)
4603:COPYN
4604 cbz.x x11 CN1
4605 ldrb w13 x10 0
4606 strb w13 x9 0
4607 add.x.i x9 x9 1
4608 add.x.i x10 x10 1
4609 sub.x.i x11 x11 1
4610 b COPYN
4611:CN1
4612 ret
4613; ======================================================================================================
4614; NEWNAME: x1 packed name, x2 its length, x3 its first byte: the name must not be in use (a name in scope,
4615; when 8 characters or fewer, or a function: error 10). Keeps x1..x8, x12..x14. Clobbers x0, x9..x11, x15..x17.
4616:NEWNAME
4617 str.x.pre x30 sp -16
4618 str.x x1 sp 1
4619 cmp.x.i x2 8
4620 b.hi NN1
4621 bl FINDNAME
4622 cbnz.x x0 E_TWICE
4623:NN1
4624 ldr.x x1 sp 1
4625 bl FINDFN
4626 cbnz.x x0 E_TWICE
4627 ldr.x x1 sp 1
4628 ldr.x.post x30 sp 16
4629 ret
4630; FINDFN: x1 packed name (first 8 characters), x2 length (any value up to 8 for a short name), x3 first
4631; byte (read only for a name over 8 characters) -> x0 its function entry (0 none). A function entry keeps
4632; its name's length at +120 and the name's place in the input at +124. Clobbers x9..x11, x15..x17.
4633:FINDFN
4634 movz.x x9 0x185 1
4635 ldr.x x10 x9 2
4636 movz.x x9 0x19f 1
4637:FF1
4638 cbz.x x10 FD0
4639 ldr.x x11 x9 0
4640 cmp.x x11 x1
4641 b.ne FF2
4642 ldr.w w11 x9 30
4643 cmp.x.i x2 8
4644 b.hi FF_LONG
4645 cmp.x.i x11 8
4646 b.ls FDF
4647 b FF2
4648:FF_LONG
4649 cmp.x x11 x2
4650 b.ne FF2
4651 ldr.w w15 x9 31
4652 movz.x x16 0x80 1
4653 add.x x15 x15 x16
4654 movz.x x16 8 0
4655:FF3
4656 cmp.x x16 x2
4657 b.hs FDF
4658 ldrb.r w17 x15 x16
4659 ldrb.r w11 x3 x16
4660 cmp.x x17 x11
4661 b.ne FF2
4662 add.x.i x16 x16 1
4663 b FF3
4664:FF2
4665 add.x.i x9 x9 128
4666 sub.x.i x10 x10 1
4667 b FF1
4668; S_LONG: a word over 8 characters at the start of a line: only a call of a void function
4669:S_LONG
4670 cbz.x x27 E_LONG
4671 movz.x x9 0x185 1
4672 ldr.x x10 x9 5
4673 cbnz.x x10 E_DEAD
4674 sub.x x3 x19 x2
4675 bl FINDFN
4676 cbz.x x0 E_LONG
4677 ldr.w w9 x0 4
4678 cmp.x.i x9 10
4679 b.ne E_TYPE
4680 movz.x x1 255 0
4681 bl CALL
4682 bl EOL
4683 b STMT
4684; VT_LONG: a word over 8 characters as a value: only a call of a function that gives a value
4685:VT_LONG
4686 mov.x x1 x4
4687 mov.x x2 x5
4688 sub.x x3 x19 x5
4689 bl FINDFN
4690 cbz.x x0 E_LONG
4691 b VT_FN2
4692; Resolve recorded BL sites; function mode must have an acyclic call graph.
4693; 65536 fixed records at 0x1860000: site, callee entry, caller entry. State slot 12 is count.
4694:RESOLVE
4695 movz.x x9 0x185 1
4696 ldr.x x10 x9 12
4697 movz.x x11 0x186 1
4698 movz.x x12 0 0
4699:RS_PATCH
4700 cmp.x x12 x10
4701 b.hs RS_GRAPH
4702 ldr.x x0 x11 0
4703 ldr.x x1 x11 1
4704 ldr.x x1 x1 1
4705 sub.x x1 x1 x0
4706 ubfm.x x1 x1 2 27
4707 movz.x x2 0x9400 1
4708 orr.x x1 x1 x2
4709 str.w w1 x0 0
4710 add.x.i x11 x11 24
4711 add.x.i x12 x12 1
4712 b RS_PATCH
4713:RS_GRAPH
4714 ldr.x x0 x9 6
4715 cbnz.x x0 RS_DONE
4716 ldr.x x1 x9 2
4717 movz.x x2 0 0
4718 movz.x x3 0x19e 1
4719 movz.x x4 0x19f 1
4720:RS_PASS
4721 cmp.x x2 x1
4722 b.hs RS_CHECK
4723 movz.x x5 0 0
4724:RS_FN
4725 cmp.x x5 x1
4726 b.hs RS_NEXT
4727 ldrb.r w0 x3 x5
4728 cbnz.x x0 RS_FNEXT
4729 ubfm.x x6 x5 57 56
4730 add.x x6 x6 x4
4731 movz.x x7 0 0
4732 movz.x x11 0x186 1
4733:RS_EDGE
4734 cmp.x x7 x10
4735 b.hs RS_MARK
4736 ldr.x x0 x11 2
4737 cmp.x x0 x6
4738 b.ne RS_ENEXT
4739 ldr.x x0 x11 1
4740 sub.x x0 x0 x4
4741 ubfm.x x0 x0 7 63
4742 ldrb.r w0 x3 x0
4743 cbz.x x0 RS_FNEXT
4744:RS_ENEXT
4745 add.x.i x7 x7 1
4746 add.x.i x11 x11 24
4747 b RS_EDGE
4748:RS_MARK
4749 movz.x x0 1 0
4750 add.x x6 x3 x5
4751 strb w0 x6 0
4752:RS_FNEXT
4753 add.x.i x5 x5 1
4754 b RS_FN
4755:RS_NEXT
4756 add.x.i x2 x2 1
4757 b RS_PASS
4758:RS_CHECK
4759 movz.x x5 0 0
4760:RS_CHECK1
4761 cmp.x x5 x1
4762 b.hs RS_DONE
4763 ldrb.r w0 x3 x5
4764 cbz.x x0 E_SUBSET
4765 add.x.i x5 x5 1
4766 b RS_CHECK1
4767:RS_DONE
4768 ret