1 \ tag
: vocabulary implementation
for openbios
3 \
Copyright (C) 2003 Stefan Reinauer
5 \
See the file
"COPYING" for further information about
6 \
the copyright and warranty status
of this
work.
10 \ this
is an implementation
of DPANS94 wordlists
(SEARCH EXT)
15 create
vocabularies #vocs cells allot \ word lists
16 ['] vocabularies to context
18 : search-wordlist ( c-addr u wid -- 0 | xt 1 | xt -1 )
19 \ Find the definition identified by the string c-addr u in the word
20 \ list identified by wid. If the definition is not found, return zero.
21 \ If the definition is found, return its execution token xt and
22 \ one (1) if the definition is immediate, minus-one (-1) otherwise.
25 true over immediate? if
34 \ Creates a new empty word list, returning its word list identifier
35 \ wid. The new word list may be returned from a pool of preallocated
36 \ word lists or may be dynamically allocated in data space. A system
37 \ shall allow the creation of at least 8 new word lists in addition
38 \ to any provided as part of the system.
42 : get-order ( -- wid1 .. widn n )
44 #order @ i - 1- cells context + @
49 : set-order ( wid1 .. widn n -- )
51 drop forth-last 1 \ push system default word list and number of lists
60 \ display word lists in the search order in their search order sequence
61 \ from the first searched to last searched. Also display word list into
62 \ which new definitions will be placed.
65 ." wordlist " i (.) type 2e emit space u. cr
67 cr ." definitions: " current @ u. cr
72 \ Transform the search order consisting of widn, ... wid2, wid1 (where
73 \ wid1 is searched first) into widn, ... wid2. An ambiguous condition
74 \ exists if the search order was empty before PREVIOUS was executed.
75 get-order nip 1- set-order
79 : do-vocabulary ( -- ) \ implementation factor
81 @ >r ( ) ( R: widnew )
82 get-order swap drop ( wid1 ... widn-1 n )
86 : discard ( x1 .. xu u - ) \ implementation factor
92 : vocabulary ( >name -- )
93 wordlist create , do-vocabulary
97 get-order over swap 1+ set-order
106 \ create forth forth-wordlist , do-vocabulary
107 create forth get-order over , discard do-vocabulary
109 : findw ( c-addr -- c-addr 0 | w 1 | w -1 )
112 over count ( c-addr 0 c-addr' u )
113 i
cells context + @ ( c
-addr
0 c
-addr
' u wid )
114 search-wordlist ( c-addr 0; 0 | w 1 | w -1 )
115 ?dup if ( c-addr 0; w 1 | w -1 )
116 2swap 2drop leave ( w 1 | w -1 )
118 loop ( c-addr 0 | w 1 | w -1 )
121 : get-current ( -- wid )
125 : set-current ( wid -- )
130 \ Make the compilation word list the same as the first word list in
131 \ the search order. Specifies that the names of subsequent definitions
132 \ will be placed in the compilation word list.
133 \ Subsequent changes in the search order will not affect the
134 \ compilation word list.
135 context @ set-current
138 : forth-wordlist ( -- wid )
153 true to vocabularies?