WORDS now searches transient vocab only.
[forth.jl.git] / src / lib_8_vocab.4th
1 \ Vocabulary management
2
3 : FORGET
4         BL WORD FIND >LINK  ( find the word, gets the dictionary entry address )
5         DUP @ LATEST !      ( set LATEST to point to the previous word )
6         H !                 ( and store H with the dictionary address )
7 ;
8
9 : HIDE
10         BL WORD FIND DROP >NAME
11         DUP @ F_HIDDEN OR SWAP !
12 ;
13
14 : VOCAB>LATEST ( vcfa -- vlatest )
15         1+ @ @ ;
16
17 \ Create new vocabulary
18 : VOCABULARY
19         create 0 ,
20 does>
21         body> context #context @ 1- + !
22 ;
23
24 : DEFINITIONS
25         context #context @ 1- + @ current !
26 ;
27
28 \ Define root vocabulary (always available)
29 vocabulary ROOT
30
31 : ONLY
32         1 #context !
33         root 
34         2 #context !
35         root 
36 ;
37
38 : PREVIOUS
39         1 #context -!
40 ;
41
42 : ALSO
43         context #context @ + dup 1- @ swap !
44         1 #context +!
45 ;
46
47 also root definitions
48
49     : FORTH forth ;
50
51     \ Display search order and compilation dictionary
52     : ORDER
53
54             \ Search order
55             context #context @ 1- + context swap
56             do
57                 i @ >name .name space
58             -1 +loop
59
60             \ Current (definitions)
61             5 spaces
62             current @ >name .name
63     ;
64
65     \ Display transient vocabulary contents
66     : WORDS
67             cr
68             context #context @ 1- + @
69             1+ @
70             BEGIN
71                     ?DUP            ( while link pointer is not 0 )
72             WHILE
73                     DUP ?HIDDEN NOT IF      ( ignore hidden words )
74                             DUP 1+ .NAME         ( but if not hidden, print the word )
75                             SPACE
76                     THEN
77                     @               ( dereference the link pointer - go to previous word )
78             REPEAT
79             CR
80     ;
81
82 only forth also definitions