1 ;;; This file contains words dealing with word lists (aka vocabularies)
3 ;;; CURRENT-WORDLIST (variable) points out "the current wordlist"
4 ;;; FORTH is a word list
7 ;; FORTH is the last word of WORDLIST FORTH
8 WORD p_forth,'FORTH',dovariable
10 dq last_forth_word ; tfa of last FORTH word
11 dq 0 ; successor word list dfa
13 WORD p_wordlist,'CURRENT-WORDLIST',dovariable
14 ;; CURRENT-WORDLIST points to dfa of the currently active wordlist.
15 dq p_forth_DFA ; compilation word list
17 WORD p_definitions,'DEFINITIONS',fasm
19 ;; Change CURRENT-WORDLIST to use the given word list
20 pop qword [p_wordlist_DFA]
24 ;; ( wordlist "name" -- cfa )
25 ;; Read next word using the given wordlist
27 mov rax,qword [p_wordlist_DFA]
29 pop qword [p_wordlist_DFA]
30 DOFORTH p_input, p_get, p_read_word, p_find
32 mov qword [p_wordlist_DFA],rax
41 WORD p_words,'WORDS',fasm
43 ;; Dump all words of the word list w (the dfa of a word list)
47 mov rax,qword [rax] ; Next word
53 pushpname rax ; ( pfa* -- chars* length )
55 pop rax ; ignore errors
57 DOFORTH p_emit ; ( c -- )
65 WORD p_strlen,'STRLEN',fasm
67 ;; Determine length of NUL terminated byte sequence
82 WORD p_strncpy,'STRNCPY',fasm
83 ;; ( chars1 chars2 n -- )
84 ;; Copy n bytes from chars1 to chars2.
95 std ; Direction is decrementing
104 cld ; Restore default direction as incrementing
108 WORD p_strncmp,'STRNCMP',fasm
109 ;; ( chars1 chars2 n -- flag )
110 ;; Compare bytes until one is NUL, return <0, =0 or >0 to
111 ;; indicate that chars1 is lesser, they are equal, or chars2
112 ;; is lesser in ascii ordering respectively.
120 ;; rax = chars1, rbx = chars2, cl = byte acc, rdx = length
136 WORD p_find,'FIND',fasm
137 ;; ( chars* length -- [ chars* length 0 ]|[ tfa ] )
138 ;; Search the current wordlists for the given pname
140 mov rcx,[p_wordlist_DFA] ; the current top word list
141 mov rdx,qword [rcx+8] ; successor word list
143 mov rcx,qword [rcx] ; use rcx for word list traversing
144 mov rbx,qword [rsp] ; rbx is input length
145 mov rsi,qword [rsp+8] ; rsi is input chars*
148 je p_find_notfound ; jump at end of word list
149 cmp rbx,qword [rcx+24] ; compare lengths
150 jne p_find_nextword ; jump on length mismatch
151 push rcx ; save tfa for later
153 push rsi ; input chars
155 push rcx ; word pname
157 DOFORTH p_strncmp ; ( s1* s2 n -- v )
158 pop rax ; return value v
159 pop rcx ; restore tfa
163 mov rsi,qword [rsp+8]
168 mov rcx,qword [rbp] ; successor word list
176 add rbp,8 ; discard word list link
180 add rsp,8 ; drop one stack entry
181 mov qword [rsp],rcx ; replace with tfa / 0
182 add rbp,8 ; discard word list link