1 ;;; This file defines execution control words
3 WORD p_branch,'BRANCH',fasm
5 ;; Using subsequent inline cell as branch offset, branch
11 WORD p_zero_branch,'0BRANCH',fasm
13 ;; Using subsequent inline cell as branch offset, branch
14 ;; accordingly if the stacked value is zero, otherwise just
15 ;; skip over the branch offset
18 jne p_zero_branch_SKIP
24 WORD p_true_branch,'1BRANCH',fasm
26 ;; Using subsequent inline cell as branch offset, branch
27 ;; accordingly if the stacked value is non-zero, otherwise
28 ;; just skip over the branch offset
37 WORD p_if,'IF',fasm,IMMEDIATE
38 ;; Compiling: ( -- a )
39 ;; Adds a (0BRANCH 0) cell pair into the current definition,
40 ;; and the address for the subsequent cell on the datastack.
41 ;; This prepares for a subsequent THEN to resolve the
42 ;; conditional branch length.
43 mov rax,qword [p_here_DFA]
44 mov qword [rax],p_zero_branch_CFA
47 mov qword [p_here_DFA],rax
51 WORD p_then,'THEN',fasm,IMMEDIATE
52 ;; Compiling: ( a -- )
53 ;; Computes the byte difference from address a and current
54 ;; "HERE", and writes that at [a].
56 mov rbx,qword [p_here_DFA]
61 WORD p_else,'ELSE',fasm,IMMEDIATE
62 ;; Compiling: ( a1 -- a2 )
63 ;; To be used between IF and THEN to lay out an unresolved
64 ;; (BRANCH 0) cell pair that ends the "then-part", and resolve
65 ;; the pending (0BRANCH 0) distance to egin the "else-part" of
67 mov rax,qword [p_here_DFA]
68 mov qword [rax],p_branch_CFA
71 mov qword [p_here_DFA],rax
73 mov rbx,qword [p_here_DFA]
79 WORD p_begin,'BEGIN',fasm,IMMEDIATE
80 ;; Compiling: ( -- a 0 )
81 ;; Pushes current address as a return point, and a 0 to mark
83 push qword [p_here_DFA]
87 WORD p_break,'BREAK',fasm,IMMEDIATE
89 ;; Lays out a (BRANCH 0) cell pair and marks the current
90 ;; address for later resolution
91 mov rax,qword [p_here_DFA]
92 mov qword [rax],p_branch_CFA
95 mov qword [p_here_DFA],rax
98 WORD p_ifbreak,'IFBREAK',fasm,IMMEDIATE
100 ;; Lays out a (1BRANCH 0) cell pair and marks the current
101 ;; address for later resolution
102 mov rax,qword [p_here_DFA]
103 mov qword [rax],p_true_branch_CFA
106 mov qword [p_here_DFA],rax
107 ;; Elevate stack entries until a 0 is found. This places the
108 ;; IFBREAK pointer below any IF-THEN block pointers
117 mov qword [rbx-8],rcx
120 mov qword [rbx-8],rax
123 WORD p_ifagain,'IFAGAIN',fasm,IMMEDIATE
124 ;; ( a 0 * -- a 0 * )
125 ;; Lays out a (1BRANCH ?) cell pair to conditionally repeat
126 ;; from the prior BEGIN.
127 mov rax,qword [p_here_DFA]
128 mov qword [rax],p_true_branch_CFA
131 mov qword [p_here_DFA],rax
139 mov rbx,qword [rbx+8]
141 mov qword [rax-8],rbx
144 WORD p_end,'END',fasm,IMMEDIATE
145 ;; Compiling: ( a 0 * -- )
146 ;; Resolves all open branches for the preceding BEGIN and
147 ;; optional several IFBREAK
155 mov rax,qword [rax+8] ; address of BEGIN
160 mov rcx,qword [p_here_DFA]
162 mov qword [rbx-8],rcx
168 WORD p_again,'AGAIN',fasm,IMMEDIATE
169 ;; Compiling: ( a 0 * -- )
170 ;; Lay out unconditional loop-back, then perform END action
171 mov rax,qword [p_here_DFA]
172 mov qword [rax],p_branch_CFA
175 mov qword [p_here_DFA],rax
183 mov rbx,qword [rbx+8]
185 mov qword [rax-8],rbx