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