1 ;;; Words for stack manipulations
5 ;; Push the address of the n:th cell below n onto the stack
12 WORD p_depth,'DEPTH',fasm
14 ;; Push stack depth (before push)
21 WORD p_dup, 'DUP',fasm
23 ;; Duplicate top ov stack value.
24 ;; push qword [rsp] ??
29 WORD p_2dup, '2DUP',fasm
30 ;; ( x1 x2 -- x1 x2 x1 x2 )
31 ;; Duplicate cell pair x1 x2.
36 WORD p_drop, 'DROP',fasm
38 ;; Remove x from the stack.
42 WORD p_2drop, '2DROP',fasm
44 ;; Drop cell pair x1 x2 from the stack.
48 WORD p_over, 'OVER',fasm
49 ;; ( x1 x2 -- x1 x2 x1 )
50 ;; Place a copy of x1 on top of the stack.
54 WORD p_2over, '2OVER',fasm
55 ;; ( x1 x2 x3 x4 -- x1 x2 x3 x4 x1 x2 )
56 ;; Copy cell pair x1 x2 to the top of the stack.
61 WORD p_swap, 'SWAP',fasm
63 ;; Exchange the top two stack items.
70 WORD p_2swap, '2SWAP',fasm
71 ;; ( x1 x2 x3 x4 -- x3 x4 x1 x2 )
72 ;; Exchange the top two cell pairs.
74 mov rbx,qword [rsp+16]
76 mov qword [rsp+16],rax
78 mov rbx,qword [rsp+24]
79 mov qword [rsp+8], rbx
80 mov qword [rsp+24],rax
83 WORD p_rot, 'ROT',fasm
84 ;; ( x1 x2 x3 -- x2 x3 x1 )
85 ;; Rotate the top three stack entries.
86 mov rax,qword [rsp+16]
88 mov qword [rsp+16],rbx
94 ;; ( xu xu-1 ... x0 u -- xu-1 ... x0 xu )
95 ;; Remove u. Rotate u+1 items on the top of the stack. An
96 ;; ambiguous condition exists if there are less than u+2 items
97 ;; on the stack before ROLL is executed.
98 WORD p_roll, 'ROLL',fasm
114 WORD p_nip, 'NIP',fasm
116 ;; Discard the second stack item.
121 WORD p_pick, 'PICK',fasm
122 ;; ( xu...x1 x0 u -- xu...x1 x0 xu )
123 ;; Remove u. Copy the xu to the top of the stack. An ambiguous
124 ;; condition exists if there are less than u+2 items on the
125 ;; stack before PICK is executed.
127 shl rax,3 ; 8 bytes per index
131 WORD p_tuck, 'TUCK',fasm
132 ;; ( x1 x2 -- x2 x1 x2 )
133 ;; copy the top stack value into below second stack value.
141 ;;; ========================================
142 ;;; Return stack operations
144 WORD p_gtR, '>R',fasm
145 ;; ( x -- ) ( R: -- x )
146 ;; Move x to the return stack.
151 WORD p_Rgt, 'R>',fasm
152 ;; ( -- x ) ( R: x -- )
153 ;; Move x from the return stack to the data stack.
158 WORD p_Rget, 'R@',fasm
159 ;; ( -- x ) ( R: x -- x )
160 ;; Copy x from the return stack to the data stack.
164 WORD p_rbp,'RSP',fasm
165 ;; Push the return stack pointer to the data stack
169 WORD p_rbpn,'R[n]',fasm
171 ;; push the address of the n:th cell on the return stack