Factored FIND.
[forth.jl.git] / src / lib_9_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 : ALSO
18         context #context @ + dup 1- @ swap !
19         1 #context +!
20 ;
21
22 \ Create new vocabulary
23 : VOCABULARY
24         create 0 ,
25 does>
26         body> context #context @ 1- + !
27 ;
28
29 : DEFINITIONS
30         context #context @ 1- + @ current !
31 ;
32
33 \ Display search order and compilation dictionary
34 : ORDER
35
36         \ Search order
37         context #context @ 1- + context swap
38         do
39             i @ >name .name space
40         -1 +loop
41
42         \ Current (definitions)
43         5 spaces
44         current @ >name .name
45 ;
46
47 \ Define root vocabulary (always available)
48 vocabulary ROOT
49
50 : ONLY
51         1 #context !
52         root 
53         2 #context !
54         root 
55 ;
56
57 : PREVIOUS
58         1 #context -!
59 ;
60
61 also root definitions
62
63 : FORTH forth ;
64 : ALSO  also ;
65 : WORDS words ;
66 : ORDER order ;
67
68 only forth also definitions