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_strncmp,'STRNCMP',fasm
42 ;; ( chars1 chars2 n -- flag )
43 ;; Compare bytes until one is NUL, return <0, =0 or >0 to
44 ;; indicate that chars1 is lesser, they are equal, or chars2
45 ;; is lesser in ascii ordering respectively.
50 ;; rax = chars1, rbx = chars2, cl = byte acc, rdx = length
64 WORD p_find,'FIND',fasm
65 ;; ( chars* length -- [ chars* length 0 ]|[ tfa ] )
66 ;; Search the current wordlists for the given pname
68 mov rcx,[p_wordlist_DFA] ; the current top word list
69 mov rdx,qword [rcx+8] ; successor word list
71 mov rcx,qword [rcx] ; use rcx for word list traversing
72 mov rbx,qword [rsp] ; rbx is input length
73 mov rsi,qword [rsp+8] ; rsi is input chars*
76 je p_find_notfound ; jump at end of word list
77 cmp rbx,qword [rcx+24] ; compare lengths
78 jne p_find_nextword ; jump on length mismatch
79 push rcx ; save tfa for later
81 push rsi ; input chars
85 DOFORTH p_strncmp ; ( s1* s2 n -- v )
86 pop rax ; return value v
96 mov rcx,qword [rbp] ; successor word list
104 add rbp,8 ; discard word list link
108 add rsp,8 ; drop one stack entry
109 mov qword [rsp],rcx ; replace with tfa / 0
110 add rbp,8 ; discard word list link