1 ;;; Words for adding words
3 WORD p_here,'HERE',dovariable
7 WORD p_create,'CREATE',fasm
8 ;; CREATE ( chars* n -- tfa )
9 ;; Add the pstring as a new word in the current wordlist.
11 mov rdx,qword [p_wordlist_DFA] ; Current word list
12 mov rbx,qword [p_here_DFA]
13 mov rax,qword [rdx] ; set up tfa linking to previous word
15 mov qword [rbx+16],0 ; flags field
18 mov qword [rbx+24],rcx ; PFA (length)
19 pop rsi ; chars* (source)
20 lea rdi,[rbx+32] ; (dest)
26 mov byte [rdi],0 ; extra NUL
28 mov qword [rdi],rbx ; pTFA
30 mov qword [rdi],0 ; OFF
32 mov qword [rbx+8],rdi ; pCFA
34 mov qword [rdi],dovariable ; CFA
36 mov qword [p_here_DFA],rdi ; allocate the space
37 mov qword [rdx],rbx ; Install new word (rdx still wordlist ptr)
42 WORD p_allot,'ALLOT',fasm
44 ;; Allocate n bytes on the heap
46 add qword [p_here_DFA],rax
51 ;; Find the following word and push its cfa, or 0
53 DOFORTH p_stdin, p_read_word, p_find
67 WORD p_bracketed_quote,"[']",doforth,IMMEDIATE
68 ;; Compilation ( "word" -- cfa )
69 ;; Find the following word and push its cfa, or 0
79 ;; Put cell value onto the heap and advance "HERE"
80 mov rax,qword [p_here_DFA]
84 mov qword [p_here_DFA],rax
87 WORD p_Ccomma,'C,',fasm
89 ;; Put byte value onto the heap and advance "HERE"
90 mov rax,qword [p_here_DFA]
94 mov qword [p_here_DFA],rax
97 WORD p_does,"DOES>",fasm,IMMEDIATE
99 ;; Change the "DOES offset" of most recent word and assign it
100 ;; the "dodoes" execution semantics that follows.
103 tfa2does rax ; *rax is the DOES offset field
105 mov rcx,qword [p_here_DFA]
107 mov qword [rax],rcx ; save offset from DFA to HERE
108 mov qword [rax+8],dodoes
111 WORD p_literal,'LIT',fasm
113 ;; Push the value of successor cell onto stack, and skip it.
114 ;; not for interactive use!!
119 WORD p_literal_string,'S"',fasm ;; " (fool emacs)
121 ;; Save string on heap to make available at interpretation
122 ;; not for interactive use!!
130 WORD p_state,'STATE',dovariable
131 ;; Interpretation state (0=interpreting, 1=compiling)
134 WORD p_left_bracket,'[',fasm,IMMEDIATE
136 ;; Change state to interpreting state.
137 mov qword[p_state_DFA],0
140 WORD p_right_bracket,']',fasm
142 ;; Change state to compilation state.
143 mov qword[p_state_DFA],1
146 WORD p_base,'BASE',dovariable
149 WORD p_decimal,'DECIMAL',fasm
152 mov qword [p_base_DFA],10
155 WORD p_hex,'HEX',fasm
158 mov qword [p_base_DFA],16
161 WORD p_number,'NUMBER',fasm
162 ;; ( chars* n -- [ 0 ]/[ v 1 ] )
164 pop rcx ; ( -- chars* )
167 mov rbx,1 ; sign (byte 0=0 means negative)
168 cmp qword [p_base_DFA],10
179 xor rax,rax ; clearing
189 mul qword [p_base_DFA] ; uses rdx:rax
213 jne p_numper_POSITIVE
221 WORD p_this_word,'THIS-WORD',dovariable
222 dq 0,0 ; ( n chars* )
224 WORD p_evaluate_stream,'EVALUATE-STREAM'
225 ;; ( stream* -- *?* flag )
226 ;; Execute the words from the given stream
227 ;; returns 1 if stream ends and 0 if an unknown word is found
228 dq p_ltR ; Keep the stream on the return stack.
229 p_evaluate_stream_PROMPT:
237 p_evaluate_stream_LOOP:
241 BRANCH 0,p_evaluate_stream_END ; branch if 0 on TOP
247 BRANCH 0,p_evaluate_stream_NOTWORD ; branch if 0 on TOP
250 BRANCH 0,p_evaluate_stream_INTERPRET
256 BRANCH 0,p_evaluate_stream_INTERPRET
258 BRANCH ,p_evaluate_stream_AFTER
259 p_evaluate_stream_INTERPRET:
261 BRANCH ,p_evaluate_stream_AFTER
262 p_evaluate_stream_NOTWORD:
265 BRANCH 0,p_evaluate_stream_BAD ; branch if 0
266 p_evaluate_stream_AFTER:
269 BRANCH 0,p_evaluate_stream_PROMPT
270 BRANCH ,p_evaluate_stream_LOOP
271 p_evaluate_stream_END:
274 p_evaluate_stream_BAD:
281 ;; Read next word as a new word into current wordlist, set it
282 ;; to be a doforth word, and set compiling mode.
283 dq p_literal, doforth
294 ;; Lay out p_exit, and set interpreting mode