Imported Upstream version 0.1beta
[debian/yforth] / yfvinit.c
1 /* yForth? - Written by Luca Padovani (C) 1996/97
2  * ------------------------------------------------------------------------
3  * This software is FreeWare as long as it comes with this header in each
4  * source file, anyway you can use it or any part of it whatever
5  * you want. It comes without any warranty, so use it at your own risk.
6  * ------------------------------------------------------------------------
7  * Module name:     yfvinit.c
8  * Abstract:        Initialize the vocabulary.
9  */
10
11 #include <string.h>
12 #include "yforth.h"
13 #include "core.h"
14 #include "ycore.h"
15 #if COREE_DEF
16 #       include "coree.h"
17 #endif
18 #if DOUBLE_DEF
19 #       include "double.h"
20 #endif
21 #if DOUBLEE_DEF
22 #       include "doublee.h"
23 #endif
24 #if FLOAT_DEF
25 #       if !COREE_DEF
26 #               include "coree.h"
27 #       endif
28 #       include "float.h"
29 #endif
30 #if FLOATE_DEF
31 #       include "floate.h"
32 #endif
33 #if MEMALL_DEF
34 #       include "memall.h"
35 #endif
36 #if SEARCH_DEF
37 #       include "search.h"
38 #endif
39 #if SEARCHE_DEF
40 #       include "searche.h"
41 #endif
42 #if TOOLS_DEF
43 #       include "tools.h"
44 #endif
45 #if TOOLSE_DEF
46 #       if !COREE_DEF
47 #               include "coree.h"
48 #       endif
49 #       include "toolse.h"
50 #endif
51 #if LOCALS_DEF
52 #       include "locals.h"
53 #endif
54 #if LOCALSE_DEF
55 #       include "localse.h"
56 #endif
57 #if FACILITY_DEF
58 #       include "facility.h"
59 #endif
60 #if FACILITYE_DEF
61 #       include "facilite.h"
62 #endif
63 #if STRING_DEF
64 #       include "string.h"
65 #endif
66 #if FILE_DEF
67 #       include "file.h"
68 #endif
69 #if     FILEE_DEF
70 #       include "filee.h"
71 #endif
72 #if BLOCK_DEF
73 #       include "block.h"
74 #endif
75 #if BLOCKE_DEF
76 #       include "blocke.h"
77 #endif
78 #if EXCEPTION_DEF
79 #       include "exceptio.h"
80 #endif
81 #if EXCEPTIONE_DEF
82 #       include "excepte.h"
83 #endif
84
85 static struct raw_voc iv[] = {
86 #define DECLARE_WORDS
87
88 #include "core.h"
89 #include "ycore.h"
90 #if COREE_DEF
91 #       include "coree.h"
92 #endif
93 #if DOUBLE_DEF
94 #       include "double.h"
95 #endif
96 #if DOUBLEE_DEF
97 #       include "doublee.h"
98 #endif
99 #if FLOAT_DEF
100 #       include "float.h"
101 #endif
102 #if FLOATE_DEF
103 #       include "floate.h"
104 #endif
105 #if MEMALL_DEF
106 #       include "memall.h"
107 #endif
108 #if SEARCH_DEF
109 #       include "search.h"
110 #endif
111 #if SEARCHE_DEF
112 #       include "searche.h"
113 #endif
114 #if TOOLS_DEF
115 #       include "tools.h"
116 #endif
117 #if TOOLSE_DEF
118 #       include "toolse.h"
119 #endif
120 #if LOCALS_DEF
121 #       include "locals.h"
122 #endif
123 #if LOCALSE_DEF
124 #       include "localse.h"
125 #endif
126 #if FACILITY_DEF
127 #       include "facility.h"
128 #endif
129 #if FACILITYE_DEF
130 #       include "facilite.h"
131 #endif
132 #ifdef STRING_DEF
133 #       include "string.h"
134 #endif
135 #if FILE_DEF
136 #       include "file.h"
137 #endif
138 #if     FILEE_DEF
139 #       include "filee.h"
140 #endif
141 #if BLOCK_DEF
142 #       include "block.h"
143 #endif
144 #if BLOCKE_DEF
145 #       include "blocke.h"
146 #endif
147 #if EXCEPTION_DEF
148 #       include "exceptio.h"
149 #endif
150 #if EXCEPTIONE_DEF
151 #       include "excepte.h"
152 #endif
153
154         { 0, 0, 0 },
155 };
156
157 #undef DECLARE_WORDS
158
159 /* init_vocabulary: loads words into the real dictionary from the table
160  * builded by including all the header files after the declaration of
161  * DECLARE_WORDS. See the header files such as "core.h" and the macro
162  * file "macro.h" for the implementation of this.
163  * This function returns the dictionary pointer after loading.
164  */
165 void init_vocabulary(Char **dp) {
166         struct word_def *w;
167         Char *name;
168         int i = 0;
169     while (iv[i].name) {                /* Last name is a NULL (see table above) */
170         name = *dp;                     /* "name" is a ptr to the name */
171         **dp = strlen(iv[i].name);      /* first copy length... */
172         strcpy(*dp + 1, iv[i].name);    /* ...and then the actual name */
173         *dp = (Char *) WORD_PTR(*dp);   /* advance "dp" */
174         w = (struct word_def *) *dp;    /* here begins the structure */
175         w->name = name;                 /* adjust pointer... */
176         w->class = iv[i].class;         /* ...and the class of the word */
177         ins_word(w);                    /* Finally adjust the link field... */
178         mark_word(w);                   /* ...accordingly with the hash function
179                                            and make the word visible */
180         *dp += sizeof(struct word_def); /* advance "dp" */
181         switch (iv[i].class & A_WORD) {     /* The last field must be adjusted here */
182                         case A_PRIMITIVE:
183                                 w->func[0] = iv[i].func;
184                                 break;
185                         case A_USER:
186                                 w->func[0] = (pfp) iv[i].func;
187                                 break;
188                 }
189                 i++;
190         }
191 }
192