|
1 |
| -\ ( |
2 |
| -\ loop -> begin |
3 |
| -\ block -> noop |
4 |
| - |
5 |
| - |
6 |
| -\ br x if x is loop -> |
7 |
| -\ [ x cs-pick ] again |
8 |
| -\ br x if x is block -> if |
9 |
| - |
10 |
| -\ end loop -> |
11 |
| -\ [ x cs-roll cs-drop ] |
12 |
| -\ x = ... |
13 |
| -\ end block -> |
14 |
| -\ [ x cs-roll ] ahead |
15 |
| -\ x = ... |
16 |
| - |
17 |
| - |
18 |
| -\ fn is implicit block |
19 |
| - |
20 |
| -\ TODO what about if/else/endif? |
21 |
| -\ if idx = block idx + br_if idx ? |
22 |
| - |
23 |
| -\ array for type |
24 |
| -\ push(block/loop/if/if-with-else) |
25 |
| -\ pop() |
26 |
| -\ peek() |
27 |
| -\ get(index) -> type |
28 |
| -\ stack for storing metadata about controlflow stack |
29 |
| -\ pushLoopBegin(index) |
30 |
| -\ pushBlockBranch(index) |
31 |
| -\ popOffsetsBlockBranches(index) -> -1 ...list-of-required-cs-roll-params... |
32 |
| -\ go through data, find positions of block branches of that index |
33 |
| -\ remove them from the stack |
34 |
| -\ (use for block branch) |
35 |
| -\ popOffsetLoopDest() -> cs-pick-param |
36 |
| -\ go through data, find topmost of begin |
37 |
| -\ remove them from the stack |
38 |
| -\ (use for dropping at loop end, and loop branch) |
39 |
| - |
40 |
| - |
41 |
| - |
42 |
| -\ how the "current" index is updated during traversal: |
43 |
| -\ block/loop -> +1 |
44 |
| -\ if -> +2 |
45 |
| -\ else -> -1 |
46 |
| -\ end(if) -> -2 |
47 |
| -\ end(block/loop/if-with-else) -> -1 |
48 |
| - |
49 |
| - |
50 |
| -\ instructions modifying stack: |
51 |
| -\ loop ( -- dest ) |
52 |
| -\ br in block ( -- orig ) |
53 |
| -\ end of loop ( dest -- ) |
54 |
| -\ end of block ( orig1 .. orign -- ) |
55 |
| - |
56 |
| - |
57 |
| - |
58 |
| -\ loop A ( begin ; dest ) |
59 |
| -\ br A ( 0 cs-pick again ; dest ) |
60 |
| -\ block B ( ; dest ) |
61 |
| -\ br A ( 0 cs-pick again ; dest ) |
62 |
| -\ br B ( if ; dest orig ) |
63 |
| -\ br A ( 1 cs-pick again ; dest orig ) |
64 |
| -\ br B ( if ; dest orig orig) |
65 |
| -\ end ( 0 cs-roll then 0 cs-roll then ; dest) |
66 |
| -\ end ( 0 cs-roll cs-drop ; ) |
67 |
| - |
68 |
| -\ ) |
69 |
| - |
70 |
| - |
71 |
| - |
72 |
| - |
73 | 1 | \ stack = [ size capacity ...data ]
|
74 | 2 | : stack.new ( -- stack )
|
75 | 3 | 16 cells allocate throw
|
|
0 commit comments