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 rax,qword [p_wordlist_DFA] ; Current word list
12 mov rax,[rax] ; last word of current wordlist
13 mov rbx,qword [p_here_DFA]
14 mov [rbx],rax ; TFA of new 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],rbx ; OFF
32 mov qword [rbx+8],rdi ; pCFA
34 mov qword [rdi],dovalue ;CFA
36 mov qword [rax],rbx ; Install new word
37 mov qword [p_here_DFA],rdi ; allocate the space
42 WORD p_allot,'ALLOT',fasm
44 ;; Allocate n bytes on the heap
46 add rax,qword [p_here_DFA]
47 mov qword [p_here_DFA],rax
52 ;; Put cell value onto the heap and advance "HERE"
53 mov rax,qword [p_here_DFA]
57 mov qword [p_here_DFA],rax
60 WORD p_Ccomma,'C,',fasm
62 ;; Put byte value onto the heap and advance "HERE"
63 mov rax,qword [p_here_DFA]
67 mov qword [p_here_DFA],rax
70 WORD p_does,'DOES>',fasm,IMMEDIATE
72 ;; Change the "DOES offset" of latest compilation and assign
73 ;; it the "dodoes" execution semantics,
74 mov rax,qword [p_wordlist_DFA]
75 mov rax,[rax] ; last word of current wordlist
76 tfa2does rax ; *rax is the DOES offset field
77 ;; offset = qword [p_here_DFA]) - (rax+2*8)
78 mov rbx,qword [p_here_DFA]
82 mov qword [rax+8],dodoes
85 WORD p_literal,'LIT',fasm
87 ;; Push the value of successor cell onto stack, and skip it
92 WORD p_literal_string,'S"',fasm
95 ;; Push the value of successor cell onto stack, and skip it
103 ;;; ========================================
104 ;;; The text interpreter
106 WORD p_state,'STATE',dovariable
107 ;; Interpretation state (0=interpreting, 1=compiling)
110 WORD p_left_bracket,'[',fasm,IMMEDIATE
112 ;; Change state to interpretation state.
113 mov qword[p_state_DFA],0
116 WORD p_right_bracket,']',fasm
118 ;; Change state to compilation state.
119 mov qword[p_state_DFA],1
122 WORD p_base,'BASE',dovariable
125 WORD p_decimal,'DECIMAL',fasm
128 mov qword [p_base_DFA],10
131 WORD p_hex,'HEX',fasm
134 mov qword [p_base_DFA],16
137 WORD p_number,'NUMBER',fasm
138 ;; ( chars* n -- [ 0 ]/[ v 1 ] )
157 mul qword [p_base_DFA]
185 WORD p_this_word,'THIS-WORD',dovariable
186 dq 0,0 ; ( n chars* )
188 WORD p_evaluate_stream,'EVALUATE-STREAM'
189 ;; ( stream -- *?* flag )
190 ;; Execute the words from the given stream
191 ;; returns 1 if stream ends and 0 if an unknown word is found
192 p_evaluate_stream_LOOP:
193 dq p_read_word ; ( -- chars* n )
195 BRANCH 0,p_evaluate_stream_END
196 dq p_2dup ; ( -- chars* n chars* n )
197 dq p_this_word ; ( -- chars* n chars* n p )
198 dq p_2put ; ( -- chars* n )
199 dq p_2dup ; ( -- chars* n chars* n )
200 dq p_find ; ( -- chars* n tfa/0 )
201 dq p_dup ; ( -- chars* n tfa/0 tfa/0 )
202 BRANCH 0,p_evaluate_stream_NOTWORD ; ( -- chars* n tfa/0 )
203 dq p_execute ; ( -- chars* n tfa/0 )
204 BRANCH ,p_evaluate_stream_LOOP
205 p_evaluate_stream_NOTWORD:
206 dq p_this_word ; ( -- chars* n tfa/0 )
210 BRANCH 0,p_evaluate_stream_LOOP
214 p_evaluate_stream_END: