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_words,'WORDS',fasm
19 ;; Dump all words of the word list w (the dfa of a word list)
23 mov rax,qword [rax] ; Next word
29 pushpname rax ; ( pfa* -- chars* length )
31 pop rax ; ignore errors
33 DOFORTH p_emit ; ( c -- )
41 WORD p_strlen,'STRLEN',fasm
43 ;; Determine length of NUL terminated byte sequence
58 WORD p_strncpy,'STRNCPY',fasm
59 ;; ( chars1 chars2 n -- )
60 ;; Copy n bytes from chars1 to chars2.
76 WORD p_strncmp,'STRNCMP',fasm
77 ;; ( chars1 chars2 n -- flag )
78 ;; Compare bytes until one is NUL, return <0, =0 or >0 to
79 ;; indicate that chars1 is lesser, they are equal, or chars2
80 ;; is lesser in ascii ordering respectively.
88 ;; rax = chars1, rbx = chars2, cl = byte acc, rdx = length
104 WORD p_find,'FIND',fasm
105 ;; ( chars* length -- [ chars* length 0 ]|[ tfa ] )
106 ;; Search the current wordlists for the given pname
108 mov rcx,[p_wordlist_DFA] ; the current top word list
109 mov rdx,qword [rcx+8] ; successor word list
111 mov rcx,qword [rcx] ; use rcx for word list traversing
112 mov rbx,qword [rsp] ; rbx is input length
113 mov rsi,qword [rsp+8] ; rsi is input chars*
116 je p_find_notfound ; jump at end of word list
117 cmp rbx,qword [rcx+24] ; compare lengths
118 jne p_find_nextword ; jump on length mismatch
119 push rcx ; save tfa for later
121 push rsi ; input chars
123 push rcx ; word pname
125 DOFORTH p_strncmp ; ( s1* s2 n -- v )
126 pop rax ; return value v
127 pop rcx ; restore tfa
131 mov rsi,qword [rsp+8]
136 mov rcx,qword [rbp] ; successor word list
144 add rbp,8 ; discard word list link
148 add rsp,8 ; drop one stack entry
149 mov qword [rsp],rcx ; replace with tfa / 0
150 add rbp,8 ; discard word list link