Factored FIND.
[forth.jl.git] / src / lib_7_printwords.4th
1 \ Display dictionary contents
2
3 : .NAME
4         DUP @           ( get the flags/length byte )
5         F_LENMASK AND   ( mask out the flags - just want the length )
6
7         BEGIN
8                 DUP 0>          ( length > 0? )
9         WHILE
10                 SWAP 1+         ( addr len -- len addr+1 )
11                 DUP @           ( len addr -- len addr char | get the next character)
12                 DUP 32 >= OVER 127 <= AND IF
13                         EMIT    ( len addr char -- len addr | and print it)
14                 ELSE
15                         BASE @ SWAP HEX
16                         ." \x" 0 .R
17                         BASE !
18                 THEN
19                 SWAP 1-         ( len addr -- addr len-1    | subtract one from length )
20         REPEAT
21         2DROP           ( len addr -- )
22 ;
23
24 : ?HIDDEN
25         1+              ( skip over the link pointer )
26         @               ( get the flags/length byte )
27         F_HIDDEN AND    ( mask the F_HIDDEN flag and return it (as a truth value) )
28 ;
29 : ?IMMEDIATE
30         1+              ( skip over the link pointer )
31         @               ( get the flags/length byte )
32         F_IMMED AND     ( mask the F_IMMED flag and return it (as a truth value) )
33 ;
34
35 : WORDS
36         CR
37         LATEST @        ( start at LATEST dictionary entry )
38         BEGIN
39                 ?DUP            ( while link pointer is not null )
40         WHILE
41                 DUP ?HIDDEN NOT IF      ( ignore hidden words )
42                         DUP 1+ .NAME         ( but if not hidden, print the word )
43                         SPACE
44                 THEN
45                 @               ( dereference the link pointer - go to previous word )
46         REPEAT
47         CR
48 ;