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_DFA
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_DFA
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_ifbreak,'IFBREAK',fasm,IMMEDIATE
89 ;; Lays out a (1BRANCH 0) cell pair and marks the current
90 ;; address for later resolution
91 mov rax,qword [p_here_DFA]
92 mov qword [rax],p_true_branch_DFA
95 mov qword [p_here_DFA],rax
99 WORD p_ifagain,'IFAGAIN',fasm,IMMEDIATE
100 ;; ( a 0 * -- a 0 * )
101 ;; Lays out a (1BRANCH ?) cell pair to conditionally repeat
102 ;; from the prior BEGIN.
103 mov rax,qword [p_here_DFA]
104 mov qword [rax],p_true_branch_DFA
107 mov qword [p_here_DFA],rax
115 mov rbx,qword [rbx+8]
117 mov qword [rax-8],rbx
120 WORD p_end,'END',fasm,IMMEDIATE
121 ;; Compiling: ( a 0 * -- )
122 ;; Resolves all open branches for the preceding BEGIN and
123 ;; optional several IFBREAK
130 mov rax,qword [rax+8] ; address of BEGIN
137 mov qword [rbx-8],rcx