1 \
FLK basic dictionary management
3 \
Copyright (C) 1998 Lars Krueger
5 \
This file is
part of FLK.
7 \
FLK is
free software
; you
can redistribute
it and/or
8 \ modify
it under the
terms of the
GNU General Public License
9 \
as published by the
Free Software Foundation; either version
2
10 \
of the
License, or (at
your option) any later version
.
12 \
This program is
distributed in the
hope that
it will
be useful
,
13 \ but
WITHOUT ANY WARRANTY; without
even the
implied warranty
of
14 \
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 \
GNU General Public License for more
details.
17 \
You should have
received a copy
of the GNU General Public License
18 \ along
with this
program; if not
, write
to the Free Software
19 \
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 \ $
Id: flkdict
.fs
,v
1.18 1998/08/30 10:50:59 root
Exp $
22 \ $
Log: flkdict
.fs
,v $
23 \
Revision 1.18 1998/08/30 10:50:59 root
24 \
new optimizing algorithm
26 \
Revision 1.17 1998/07/05 18:45:25 root
27 \ bugs
corrected, added
X forms
routines, .faulty
-word added
29 \
Revision 1.16 1998/07/03 20:57:50 root
30 \ level
2 optimimizer added
32 \
Revision 1.15 1998/07/03 09:09:28 root
33 \ support
for level
2 optimizer
35 \
Revision 1.14 1998/06/01 17:51:42 root
36 \
SEE shows
the sourcefile
using VIEW
38 \
Revision 1.13 1998/05/27 18:52:12 root
39 \ \
: commants
added for SEE and HELP
41 \
Revision 1.12 1998/05/21 19:24:49 root
44 \
Revision 1.11 1998/05/09 21:47:05 root
45 \ relocation
-drop fixed
(corrects
a bug
in "r, does>" )
47 \
Revision 1.10 1998/05/03 12:06:37 root
50 \
Revision 1.9 1998/05/01 18:11:25 root
51 \
GNU license
text added
54 \
Revision 1.8 1998/04/30 09:42:25 root
57 \
Revision 1.7 1998/04/29 18:20:30 root
58 \ better hash
function
60 \
Revision 1.6 1998/04/24 16:47:39 root
61 \
float support corrected
63 \
Revision 1.5 1998/04/15 18:15:30 root
64 \ align changed
for float support
66 \
Revision 1.4 1998/04/11 11:55:44 root
67 \
FORGET/MARKER support added
69 \
Revision 1.3 1998/04/10 14:42:50 root
72 \
Revision 1.2 1998/04/09 11:35:03 root
73 \ fixed
SEARCH-WORDLIST (visibility check
added)
75 \
Revision 1.1 1998/04/07 20:10:33 root
79 #BUCKETS CONSTANT #BUCKETS
81 \
Calculate the dictionary hash
function from
the given string. The return
82 \ hash is
limited to 0..#BUCKETS-1.
83 : (calc
-hash
) ( ca u
-- hash
)
85 OVER C@ 2* \ ca u
hash
86 OVER 1 > IF \ ca u
hash
87 ROT CHAR+ C@ + DUP 2* + \ u
hash
94 [META] HF-IMMEDIATE [PREVIOUS] CONSTANT HF-IMMEDIATE
95 [META] HF-OIMMEDIATE [PREVIOUS] CONSTANT HF-OIMMEDIATE
96 [META] HF-VISIBLE [PREVIOUS] CONSTANT HF-VISIBLE
97 [META] HF-CREATED [PREVIOUS] CONSTANT HF-CREATED
99 \
Are we case
insensitive?
102 \
Case sensitive/insensitive compare depending on
the value in CAPS.
111 \
Print the name
of the wordlist wid
.
114 DUP #BUCKETS CELLS + CELL+ COUNT \ wid addr len
115 DUP 0= IF \ wid add len
116 2DROP ." unnamed(" .addr
." ) "
121 \
Which wordlists
are known
?
123 ." Known wordlists: " CR
125 DUP .VOC #BUCKETS CELLS + @
131 : DEPTH SP-BASE SP@ - 2 RSHIFT 1- ;
140 DUP ." <" 1 .R ." > " \ depth
141 8 MIN DUP 0 ?DO \ ind
148 : SEARCH-WORDLIST ( c
-addr u
wid -- 0 | xt 1 | xt -1 )
151 2DUP (calc
-hash) \
wid ca u
hash
152 CELLS \
wid ca u
offs
159 DUP >NAME COUNT \ ca u
xt na nl
160 ROT >R \ ca u
na nl
/ r
: xt
161 2OVER \ ca u
na nl
ca u
/ r
: xt
162 (swl
-COMPARE) 0= IF \
ca u
/ r
: xt
164 DUP >FLAGS C@ \
ca u
xt flags
165 DUP HF-VISIBLE AND IF \
ca u
xt flags
166 2SWAP 2DROP \
xt flags
175 REPEAT \
ca u
image-base
178 \
Storage area for wid's.
179 #IN-ORDER CONSTANT #IN-ORDER
180 CREATE ((order-field)) #IN-ORDER CELLS ALLOT
181 VARIABLE ((order-cnt))
183 CREATE ((unique-order)) #IN-ORDER CELLS ALLOT
184 VARIABLE ((unique-cnt))
186 \ Put the given wordlist-id into ((unique-order)) if it is not in it yet.
187 : (unique-set-order) ( wid -- )
188 ((unique-cnt)) @ 0 ?DO
189 I CELLS ((unique-order)) + @ \ wid wid-u
194 ((unique-order)) ((unique-cnt)) @ CELLS + !
199 : SET-ORDER ( widn ... wid1 n -- )
201 DUP #IN-ORDER \ ... n n max
202 < INVERT IF -49 THROW THEN \ .. n
203 DUP 0= IF -50 THROW THEN \ .. n
207 DUP (unique-set-order)
213 : GET-ORDER ( -- widn ... wid1 n )
217 ((order-cnt)) @ 1- I - CELLS
222 \ Which wordlist is searched first?
230 : SET-CURRENT ( wid -- )
235 : GET-CURRENT ( -- wid )
243 GET-ORDER 0 DO .VOC LOOP CR
245 GET-CURRENT .VOC CR ;
247 \ Same function as FIND, just more useful interface ( and faster too ).
248 : SEARCH-WORDLISTS ( c-addr u -- 0 / xt 1 / xt -1 )
250 ((unique-cnt)) @ 0 DO \ c u
252 I CELLS ((unique-order)) + @ \ c u c u wid
253 SEARCH-WORDLIST \ c u ( 0 / xt imm ? )
254 ?DUP IF \ c u xt imm?
255 2SWAP 2DROP \ xt imm?
262 : FIND ( c-addr -- c-addr 0 | xt 1 | xt -1 )
266 SEARCH-WORDLISTS \ co ( 0 / xt flag )
271 ' NOOP RVALUE ALLOT-HOOK
272 ' NOOP RVALUE CALLOT-HOOK
278 DUP UNUSED < INVERT IF
282 +TO HERE ALLOT-HOOK EXECUTE ;
284 \ Store one item into the relocation table.
285 : relocation! ( x -- )
287 RELOCATION-TABLE@ SWAP IMAGE-BASE - []+= RELOCATION-TABLE! ;
289 \ remove all entries higher than addr but only in code area
290 : relocation-drop ( addr -- )
291 IMAGE-BASE - \ rel-addr
292 RELOCATION-TABLE@ \ ra rt
295 1- 2DUP \ ra rt ind rt ind
297 FLOCK OVER \ ra rt ind cont ra cont
299 WHILE \ ra rt ind cont
300 HA-CODESIZE @ < IF \ ra rt ind
301 ( cont is in code area )
304 REPEAT \ ra rt ind cont
310 HERE 1 CELLS ALLOT ! ;
315 HERE 1 CHARS ALLOT C! ;
317 \ Same as , but relocate the value.
322 \ Same as ALLOT but in code area.
326 DUP CUNUSED < INVERT IF
330 +TO CHERE CALLOT-HOOK EXECUTE ;
332 \ Same as , but in code area.
335 CHERE 1 CELLS CALLOT ! ;
337 \ Same as C, but in code area.
340 CHERE 1 CHARS CALLOT C! ;
342 \ Same as r, but in code area.
345 CHERE relocation! c-, ;
347 \ The assembler uses different names.
350 \ The assembler uses different names.
353 \ The assembler uses different names.
356 \ The assembler uses different names.
359 \ The assembler uses different names.
362 \ The assembler uses different names.
365 \ Align primitive. Used as an short-cut for the various ALIGNs (FLOATING POINT
367 : (align) ( new-here -- )
368 DUP HERE-LIMIT >= IF -8 THROW THEN
374 HERE ALIGNED (align) ;
377 : WORDLIST ( -- wid )
390 GET-ORDER OVER SWAP 1+ SET-ORDER ;
404 FORTH-WORDLIST 1 SET-ORDER ;
409 GET-ORDER NIP FORTH-WORDLIST SWAP SET-ORDER ;
414 GET-ORDER NIP ASSEMBLER-WORDLIST SWAP SET-ORDER ;
419 GET-ORDER NIP EDITOR-WORDLIST SWAP SET-ORDER ;
421 \ Put the environment wordlist on top of the search order. This is not allowed
422 \ in a standard program and is only nessesary whenever new environment query
426 GET-ORDER NIP ENVIRONMENT-WORDLIST SWAP SET-ORDER ;
428 \ Drop n items and n too.
438 TOP-VOC SET-CURRENT ;