1afc2ba1dSToomas Soome /*
2afc2ba1dSToomas Soome * s e a r c h . c
3afc2ba1dSToomas Soome * Forth Inspired Command Language
4afc2ba1dSToomas Soome * ANS Forth SEARCH and SEARCH-EXT word-set written in C
5afc2ba1dSToomas Soome * Author: John Sadler (john_sadler@alum.mit.edu)
6afc2ba1dSToomas Soome * Created: 6 June 2000
7afc2ba1dSToomas Soome * $Id: search.c,v 1.10 2010/08/12 13:57:22 asau Exp $
8afc2ba1dSToomas Soome */
9afc2ba1dSToomas Soome /*
10afc2ba1dSToomas Soome * Copyright (c) 1997-2001 John Sadler (john_sadler@alum.mit.edu)
11afc2ba1dSToomas Soome * All rights reserved.
12afc2ba1dSToomas Soome *
13afc2ba1dSToomas Soome * Get the latest Ficl release at http://ficl.sourceforge.net
14afc2ba1dSToomas Soome *
15afc2ba1dSToomas Soome * I am interested in hearing from anyone who uses Ficl. If you have
16afc2ba1dSToomas Soome * a problem, a success story, a defect, an enhancement request, or
17afc2ba1dSToomas Soome * if you would like to contribute to the Ficl release, please
18afc2ba1dSToomas Soome * contact me by email at the address above.
19afc2ba1dSToomas Soome *
20afc2ba1dSToomas Soome * L I C E N S E and D I S C L A I M E R
21afc2ba1dSToomas Soome *
22afc2ba1dSToomas Soome * Redistribution and use in source and binary forms, with or without
23afc2ba1dSToomas Soome * modification, are permitted provided that the following conditions
24afc2ba1dSToomas Soome * are met:
25afc2ba1dSToomas Soome * 1. Redistributions of source code must retain the above copyright
26afc2ba1dSToomas Soome * notice, this list of conditions and the following disclaimer.
27afc2ba1dSToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
28afc2ba1dSToomas Soome * notice, this list of conditions and the following disclaimer in the
29afc2ba1dSToomas Soome * documentation and/or other materials provided with the distribution.
30afc2ba1dSToomas Soome *
31afc2ba1dSToomas Soome * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
32afc2ba1dSToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33afc2ba1dSToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34afc2ba1dSToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
35afc2ba1dSToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36afc2ba1dSToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37afc2ba1dSToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38afc2ba1dSToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
39afc2ba1dSToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
40afc2ba1dSToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41afc2ba1dSToomas Soome * SUCH DAMAGE.
42afc2ba1dSToomas Soome */
43afc2ba1dSToomas Soome
44afc2ba1dSToomas Soome #include <string.h>
45afc2ba1dSToomas Soome #include "ficl.h"
46afc2ba1dSToomas Soome
47afc2ba1dSToomas Soome /*
48afc2ba1dSToomas Soome * d e f i n i t i o n s
49afc2ba1dSToomas Soome * SEARCH ( -- )
50afc2ba1dSToomas Soome * Make the compilation word list the same as the first word list in the
51afc2ba1dSToomas Soome * search order. Specifies that the names of subsequent definitions will
52afc2ba1dSToomas Soome * be placed in the compilation word list. Subsequent changes in the search
53afc2ba1dSToomas Soome * order will not affect the compilation word list.
54afc2ba1dSToomas Soome */
55afc2ba1dSToomas Soome static void
ficlPrimitiveDefinitions(ficlVm * vm)56afc2ba1dSToomas Soome ficlPrimitiveDefinitions(ficlVm *vm)
57afc2ba1dSToomas Soome {
58afc2ba1dSToomas Soome ficlDictionary *dictionary = ficlVmGetDictionary(vm);
59afc2ba1dSToomas Soome
60afc2ba1dSToomas Soome FICL_VM_ASSERT(vm, dictionary);
61afc2ba1dSToomas Soome if (dictionary->wordlistCount < 1) {
62afc2ba1dSToomas Soome ficlVmThrowError(vm, "DEFINITIONS error - empty search order");
63afc2ba1dSToomas Soome }
64afc2ba1dSToomas Soome
65afc2ba1dSToomas Soome dictionary->compilationWordlist =
66afc2ba1dSToomas Soome dictionary->wordlists[dictionary->wordlistCount-1];
67afc2ba1dSToomas Soome }
68afc2ba1dSToomas Soome
69afc2ba1dSToomas Soome /*
70afc2ba1dSToomas Soome * f o r t h - w o r d l i s t
71afc2ba1dSToomas Soome * SEARCH ( -- wid )
72afc2ba1dSToomas Soome * Return wid, the identifier of the word list that includes all standard
73afc2ba1dSToomas Soome * words provided by the implementation. This word list is initially the
74afc2ba1dSToomas Soome * compilation word list and is part of the initial search order.
75afc2ba1dSToomas Soome */
76afc2ba1dSToomas Soome static void
ficlPrimitiveForthWordlist(ficlVm * vm)77afc2ba1dSToomas Soome ficlPrimitiveForthWordlist(ficlVm *vm)
78afc2ba1dSToomas Soome {
79afc2ba1dSToomas Soome ficlHash *hash = ficlVmGetDictionary(vm)->forthWordlist;
80afc2ba1dSToomas Soome ficlStackPushPointer(vm->dataStack, hash);
81afc2ba1dSToomas Soome }
82afc2ba1dSToomas Soome
83afc2ba1dSToomas Soome
84afc2ba1dSToomas Soome /*
85afc2ba1dSToomas Soome * g e t - c u r r e n t
86afc2ba1dSToomas Soome * SEARCH ( -- wid )
87afc2ba1dSToomas Soome * Return wid, the identifier of the compilation word list.
88afc2ba1dSToomas Soome */
89afc2ba1dSToomas Soome static void
ficlPrimitiveGetCurrent(ficlVm * vm)90afc2ba1dSToomas Soome ficlPrimitiveGetCurrent(ficlVm *vm)
91afc2ba1dSToomas Soome {
92afc2ba1dSToomas Soome ficlDictionary *dictionary = ficlVmGetDictionary(vm);
93afc2ba1dSToomas Soome ficlDictionaryLock(dictionary, FICL_TRUE);
94afc2ba1dSToomas Soome ficlStackPushPointer(vm->dataStack, dictionary->compilationWordlist);
95afc2ba1dSToomas Soome ficlDictionaryLock(dictionary, FICL_FALSE);
96afc2ba1dSToomas Soome }
97afc2ba1dSToomas Soome
98afc2ba1dSToomas Soome /*
99afc2ba1dSToomas Soome * g e t - o r d e r
100afc2ba1dSToomas Soome * SEARCH ( -- widn ... wid1 n )
101afc2ba1dSToomas Soome * Returns the number of word lists n in the search order and the word list
102afc2ba1dSToomas Soome * identifiers widn ... wid1 identifying these word lists. wid1 identifies
103afc2ba1dSToomas Soome * the word list that is searched first, and widn the word list that is
104afc2ba1dSToomas Soome * searched last. The search order is unaffected.
105afc2ba1dSToomas Soome */
106afc2ba1dSToomas Soome static void
ficlPrimitiveGetOrder(ficlVm * vm)107afc2ba1dSToomas Soome ficlPrimitiveGetOrder(ficlVm *vm)
108afc2ba1dSToomas Soome {
109afc2ba1dSToomas Soome ficlDictionary *dictionary = ficlVmGetDictionary(vm);
110afc2ba1dSToomas Soome int wordlistCount = dictionary->wordlistCount;
111afc2ba1dSToomas Soome int i;
112afc2ba1dSToomas Soome
113afc2ba1dSToomas Soome ficlDictionaryLock(dictionary, FICL_TRUE);
114afc2ba1dSToomas Soome for (i = 0; i < wordlistCount; i++) {
115afc2ba1dSToomas Soome ficlStackPushPointer(vm->dataStack, dictionary->wordlists[i]);
116afc2ba1dSToomas Soome }
117afc2ba1dSToomas Soome
118afc2ba1dSToomas Soome ficlStackPushUnsigned(vm->dataStack, wordlistCount);
119afc2ba1dSToomas Soome ficlDictionaryLock(dictionary, FICL_FALSE);
120afc2ba1dSToomas Soome }
121afc2ba1dSToomas Soome
122afc2ba1dSToomas Soome /*
123afc2ba1dSToomas Soome * s e a r c h - w o r d l i s t
124afc2ba1dSToomas Soome * SEARCH ( c-addr u wid -- 0 | xt 1 | xt -1 )
125afc2ba1dSToomas Soome * Find the definition identified by the string c-addr u in the word list
126afc2ba1dSToomas Soome * identified by wid. If the definition is not found, return zero. If the
127afc2ba1dSToomas Soome * definition is found, return its execution token xt and one (1) if the
128afc2ba1dSToomas Soome * definition is immediate, minus-one (-1) otherwise.
129afc2ba1dSToomas Soome */
130afc2ba1dSToomas Soome static void
ficlPrimitiveSearchWordlist(ficlVm * vm)131afc2ba1dSToomas Soome ficlPrimitiveSearchWordlist(ficlVm *vm)
132afc2ba1dSToomas Soome {
133afc2ba1dSToomas Soome ficlString name;
134afc2ba1dSToomas Soome ficlUnsigned16 hashCode;
135afc2ba1dSToomas Soome ficlWord *word;
136afc2ba1dSToomas Soome ficlHash *hash = ficlStackPopPointer(vm->dataStack);
137afc2ba1dSToomas Soome
138afc2ba1dSToomas Soome name.length = (ficlUnsigned8)ficlStackPopUnsigned(vm->dataStack);
139afc2ba1dSToomas Soome name.text = ficlStackPopPointer(vm->dataStack);
140afc2ba1dSToomas Soome hashCode = ficlHashCode(name);
141afc2ba1dSToomas Soome
142afc2ba1dSToomas Soome ficlDictionaryLock(ficlVmGetDictionary(vm), FICL_TRUE);
143afc2ba1dSToomas Soome word = ficlHashLookup(hash, name, hashCode);
144afc2ba1dSToomas Soome ficlDictionaryLock(ficlVmGetDictionary(vm), FICL_FALSE);
145afc2ba1dSToomas Soome
146afc2ba1dSToomas Soome if (word) {
147afc2ba1dSToomas Soome ficlStackPushPointer(vm->dataStack, word);
148afc2ba1dSToomas Soome ficlStackPushInteger(vm->dataStack,
149afc2ba1dSToomas Soome (ficlWordIsImmediate(word) ? 1 : -1));
150afc2ba1dSToomas Soome } else {
151afc2ba1dSToomas Soome ficlStackPushUnsigned(vm->dataStack, 0);
152afc2ba1dSToomas Soome }
153afc2ba1dSToomas Soome }
154afc2ba1dSToomas Soome
155afc2ba1dSToomas Soome /*
156afc2ba1dSToomas Soome * s e t - c u r r e n t
157afc2ba1dSToomas Soome * SEARCH ( wid -- )
158afc2ba1dSToomas Soome * Set the compilation word list to the word list identified by wid.
159afc2ba1dSToomas Soome */
160afc2ba1dSToomas Soome static void
ficlPrimitiveSetCurrent(ficlVm * vm)161afc2ba1dSToomas Soome ficlPrimitiveSetCurrent(ficlVm *vm)
162afc2ba1dSToomas Soome {
163afc2ba1dSToomas Soome ficlHash *hash = ficlStackPopPointer(vm->dataStack);
164afc2ba1dSToomas Soome ficlDictionary *dictionary = ficlVmGetDictionary(vm);
165afc2ba1dSToomas Soome ficlDictionaryLock(dictionary, FICL_TRUE);
166afc2ba1dSToomas Soome dictionary->compilationWordlist = hash;
167afc2ba1dSToomas Soome ficlDictionaryLock(dictionary, FICL_FALSE);
168afc2ba1dSToomas Soome }
169afc2ba1dSToomas Soome
170afc2ba1dSToomas Soome /*
171afc2ba1dSToomas Soome * s e t - o r d e r
172afc2ba1dSToomas Soome * SEARCH ( widn ... wid1 n -- )
173afc2ba1dSToomas Soome * Set the search order to the word lists identified by widn ... wid1.
174afc2ba1dSToomas Soome * Subsequently, word list wid1 will be searched first, and word list
175afc2ba1dSToomas Soome * widn searched last. If n is zero, empty the search order. If n is minus
176afc2ba1dSToomas Soome * one, set the search order to the implementation-defined minimum
177afc2ba1dSToomas Soome * search order. The minimum search order shall include the words
178afc2ba1dSToomas Soome * FORTH-WORDLIST and SET-ORDER. A system shall allow n to
179afc2ba1dSToomas Soome * be at least eight.
180afc2ba1dSToomas Soome */
181afc2ba1dSToomas Soome static void
ficlPrimitiveSetOrder(ficlVm * vm)182afc2ba1dSToomas Soome ficlPrimitiveSetOrder(ficlVm *vm)
183afc2ba1dSToomas Soome {
184afc2ba1dSToomas Soome int i;
185afc2ba1dSToomas Soome int wordlistCount = ficlStackPopInteger(vm->dataStack);
186afc2ba1dSToomas Soome ficlDictionary *dictionary = ficlVmGetDictionary(vm);
187afc2ba1dSToomas Soome
188afc2ba1dSToomas Soome if (wordlistCount > FICL_MAX_WORDLISTS) {
189afc2ba1dSToomas Soome ficlVmThrowError(vm,
190afc2ba1dSToomas Soome "set-order error: list would be too large");
191afc2ba1dSToomas Soome }
192afc2ba1dSToomas Soome
193afc2ba1dSToomas Soome ficlDictionaryLock(dictionary, FICL_TRUE);
194afc2ba1dSToomas Soome
195afc2ba1dSToomas Soome if (wordlistCount >= 0) {
196afc2ba1dSToomas Soome dictionary->wordlistCount = wordlistCount;
197afc2ba1dSToomas Soome for (i = wordlistCount-1; i >= 0; --i) {
198afc2ba1dSToomas Soome dictionary->wordlists[i] =
199afc2ba1dSToomas Soome ficlStackPopPointer(vm->dataStack);
200afc2ba1dSToomas Soome }
201afc2ba1dSToomas Soome } else {
202afc2ba1dSToomas Soome ficlDictionaryResetSearchOrder(dictionary);
203afc2ba1dSToomas Soome }
204afc2ba1dSToomas Soome
205afc2ba1dSToomas Soome ficlDictionaryLock(dictionary, FICL_FALSE);
206afc2ba1dSToomas Soome }
207afc2ba1dSToomas Soome
208afc2ba1dSToomas Soome /*
209afc2ba1dSToomas Soome * f i c l - w o r d l i s t
210afc2ba1dSToomas Soome * SEARCH ( -- wid )
211afc2ba1dSToomas Soome * Create a new empty word list, returning its word list identifier wid.
212afc2ba1dSToomas Soome * The new word list may be returned from a pool of preallocated word
213afc2ba1dSToomas Soome * lists or may be dynamically allocated in data space. A system shall
214afc2ba1dSToomas Soome * allow the creation of at least 8 new word lists in addition to any
215afc2ba1dSToomas Soome * provided as part of the system.
216afc2ba1dSToomas Soome * Notes:
217afc2ba1dSToomas Soome * 1. Ficl creates a new single-list hash in the dictionary and returns
218afc2ba1dSToomas Soome * its address.
219afc2ba1dSToomas Soome * 2. ficl-wordlist takes an arg off the stack indicating the number of
220afc2ba1dSToomas Soome * hash entries in the wordlist. Ficl 2.02 and later define WORDLIST as
221afc2ba1dSToomas Soome * : wordlist 1 ficl-wordlist ;
222afc2ba1dSToomas Soome */
223afc2ba1dSToomas Soome static void
ficlPrimitiveFiclWordlist(ficlVm * vm)224afc2ba1dSToomas Soome ficlPrimitiveFiclWordlist(ficlVm *vm)
225afc2ba1dSToomas Soome {
226afc2ba1dSToomas Soome ficlDictionary *dictionary = ficlVmGetDictionary(vm);
227afc2ba1dSToomas Soome ficlHash *hash;
228afc2ba1dSToomas Soome ficlUnsigned nBuckets;
229afc2ba1dSToomas Soome
230afc2ba1dSToomas Soome FICL_STACK_CHECK(vm->dataStack, 1, 1);
231afc2ba1dSToomas Soome
232afc2ba1dSToomas Soome nBuckets = ficlStackPopUnsigned(vm->dataStack);
233afc2ba1dSToomas Soome hash = ficlDictionaryCreateWordlist(dictionary, nBuckets);
234afc2ba1dSToomas Soome ficlStackPushPointer(vm->dataStack, hash);
235afc2ba1dSToomas Soome }
236afc2ba1dSToomas Soome
237afc2ba1dSToomas Soome /*
238afc2ba1dSToomas Soome * S E A R C H >
239afc2ba1dSToomas Soome * Ficl ( -- wid )
240afc2ba1dSToomas Soome * Pop wid off the search order. Error if the search order is empty
241afc2ba1dSToomas Soome */
242afc2ba1dSToomas Soome static void
ficlPrimitiveSearchPop(ficlVm * vm)243afc2ba1dSToomas Soome ficlPrimitiveSearchPop(ficlVm *vm)
244afc2ba1dSToomas Soome {
245afc2ba1dSToomas Soome ficlDictionary *dictionary = ficlVmGetDictionary(vm);
246afc2ba1dSToomas Soome int wordlistCount;
247afc2ba1dSToomas Soome
248afc2ba1dSToomas Soome ficlDictionaryLock(dictionary, FICL_TRUE);
249afc2ba1dSToomas Soome wordlistCount = dictionary->wordlistCount;
250afc2ba1dSToomas Soome if (wordlistCount == 0) {
251afc2ba1dSToomas Soome ficlVmThrowError(vm, "search> error: empty search order");
252afc2ba1dSToomas Soome }
253afc2ba1dSToomas Soome ficlStackPushPointer(vm->dataStack,
254afc2ba1dSToomas Soome dictionary->wordlists[--dictionary->wordlistCount]);
255afc2ba1dSToomas Soome ficlDictionaryLock(dictionary, FICL_FALSE);
256afc2ba1dSToomas Soome }
257afc2ba1dSToomas Soome
258afc2ba1dSToomas Soome /*
259afc2ba1dSToomas Soome * > S E A R C H
260afc2ba1dSToomas Soome * Ficl ( wid -- )
261afc2ba1dSToomas Soome * Push wid onto the search order. Error if the search order is full.
262afc2ba1dSToomas Soome */
263afc2ba1dSToomas Soome static void
ficlPrimitiveSearchPush(ficlVm * vm)264afc2ba1dSToomas Soome ficlPrimitiveSearchPush(ficlVm *vm)
265afc2ba1dSToomas Soome {
266afc2ba1dSToomas Soome ficlDictionary *dictionary = ficlVmGetDictionary(vm);
267afc2ba1dSToomas Soome
268afc2ba1dSToomas Soome ficlDictionaryLock(dictionary, FICL_TRUE);
269afc2ba1dSToomas Soome if (dictionary->wordlistCount > FICL_MAX_WORDLISTS) {
270afc2ba1dSToomas Soome ficlVmThrowError(vm, ">search error: search order overflow");
271afc2ba1dSToomas Soome }
272afc2ba1dSToomas Soome dictionary->wordlists[dictionary->wordlistCount++] =
273afc2ba1dSToomas Soome ficlStackPopPointer(vm->dataStack);
274afc2ba1dSToomas Soome ficlDictionaryLock(dictionary, FICL_FALSE);
275afc2ba1dSToomas Soome }
276afc2ba1dSToomas Soome
277afc2ba1dSToomas Soome /*
278afc2ba1dSToomas Soome * W I D - G E T - N A M E
279afc2ba1dSToomas Soome * Ficl ( wid -- c-addr u )
280afc2ba1dSToomas Soome * Get wid's (optional) name and push onto stack as a counted string
281afc2ba1dSToomas Soome */
282afc2ba1dSToomas Soome static void
ficlPrimitiveWidGetName(ficlVm * vm)283afc2ba1dSToomas Soome ficlPrimitiveWidGetName(ficlVm *vm)
284afc2ba1dSToomas Soome {
285afc2ba1dSToomas Soome ficlHash *hash;
286afc2ba1dSToomas Soome char *name;
287afc2ba1dSToomas Soome ficlInteger length;
288afc2ba1dSToomas Soome ficlCell c;
289afc2ba1dSToomas Soome
290afc2ba1dSToomas Soome hash = ficlVmPop(vm).p;
291afc2ba1dSToomas Soome name = hash->name;
292afc2ba1dSToomas Soome
293afc2ba1dSToomas Soome if (name != NULL)
294afc2ba1dSToomas Soome length = strlen(name);
295afc2ba1dSToomas Soome else
296afc2ba1dSToomas Soome length = 0;
297afc2ba1dSToomas Soome
298afc2ba1dSToomas Soome c.p = name;
299afc2ba1dSToomas Soome ficlVmPush(vm, c);
300afc2ba1dSToomas Soome
301afc2ba1dSToomas Soome c.i = length;
302afc2ba1dSToomas Soome ficlVmPush(vm, c);
303afc2ba1dSToomas Soome }
304afc2ba1dSToomas Soome
305afc2ba1dSToomas Soome /*
306afc2ba1dSToomas Soome * W I D - S E T - N A M E
307afc2ba1dSToomas Soome * Ficl ( wid c-addr -- )
308afc2ba1dSToomas Soome * Set wid's name pointer to the \0 terminated string address supplied
309afc2ba1dSToomas Soome */
310afc2ba1dSToomas Soome static void
ficlPrimitiveWidSetName(ficlVm * vm)311afc2ba1dSToomas Soome ficlPrimitiveWidSetName(ficlVm *vm)
312afc2ba1dSToomas Soome {
313afc2ba1dSToomas Soome char *name = (char *)ficlVmPop(vm).p;
314afc2ba1dSToomas Soome ficlHash *hash = ficlVmPop(vm).p;
315afc2ba1dSToomas Soome hash->name = name;
316afc2ba1dSToomas Soome }
317afc2ba1dSToomas Soome
318afc2ba1dSToomas Soome /*
319afc2ba1dSToomas Soome * setParentWid
320afc2ba1dSToomas Soome * Ficl
321afc2ba1dSToomas Soome * setparentwid ( parent-wid wid -- )
322afc2ba1dSToomas Soome * Set WID's link field to the parent-wid. search-wordlist will
323afc2ba1dSToomas Soome * iterate through all the links when finding words in the child wid.
324afc2ba1dSToomas Soome */
325afc2ba1dSToomas Soome static void
ficlPrimitiveSetParentWid(ficlVm * vm)326afc2ba1dSToomas Soome ficlPrimitiveSetParentWid(ficlVm *vm)
327afc2ba1dSToomas Soome {
328afc2ba1dSToomas Soome ficlHash *parent, *child;
329afc2ba1dSToomas Soome
330afc2ba1dSToomas Soome FICL_STACK_CHECK(vm->dataStack, 2, 0);
331afc2ba1dSToomas Soome
332afc2ba1dSToomas Soome child = (ficlHash *)ficlStackPopPointer(vm->dataStack);
333afc2ba1dSToomas Soome parent = (ficlHash *)ficlStackPopPointer(vm->dataStack);
334afc2ba1dSToomas Soome
335afc2ba1dSToomas Soome child->link = parent;
336afc2ba1dSToomas Soome }
337afc2ba1dSToomas Soome
338afc2ba1dSToomas Soome /*
339afc2ba1dSToomas Soome * f i c l C o m p i l e S e a r c h
340afc2ba1dSToomas Soome * Builds the primitive wordset and the environment-query namespace.
341afc2ba1dSToomas Soome */
342afc2ba1dSToomas Soome void
ficlSystemCompileSearch(ficlSystem * system)343afc2ba1dSToomas Soome ficlSystemCompileSearch(ficlSystem *system)
344afc2ba1dSToomas Soome {
345afc2ba1dSToomas Soome ficlDictionary *dictionary = ficlSystemGetDictionary(system);
346afc2ba1dSToomas Soome ficlDictionary *environment = ficlSystemGetEnvironment(system);
347afc2ba1dSToomas Soome
348afc2ba1dSToomas Soome FICL_SYSTEM_ASSERT(system, dictionary);
349afc2ba1dSToomas Soome FICL_SYSTEM_ASSERT(system, environment);
350afc2ba1dSToomas Soome
351afc2ba1dSToomas Soome /*
352afc2ba1dSToomas Soome * optional SEARCH-ORDER word set
353afc2ba1dSToomas Soome */
354*c0bb4f73SToomas Soome (void) ficlDictionarySetPrimitive(dictionary, ">search",
355afc2ba1dSToomas Soome ficlPrimitiveSearchPush, FICL_WORD_DEFAULT);
356*c0bb4f73SToomas Soome (void) ficlDictionarySetPrimitive(dictionary, "search>",
357afc2ba1dSToomas Soome ficlPrimitiveSearchPop, FICL_WORD_DEFAULT);
358*c0bb4f73SToomas Soome (void) ficlDictionarySetPrimitive(dictionary, "definitions",
359afc2ba1dSToomas Soome ficlPrimitiveDefinitions, FICL_WORD_DEFAULT);
360*c0bb4f73SToomas Soome (void) ficlDictionarySetPrimitive(dictionary, "forth-wordlist",
361afc2ba1dSToomas Soome ficlPrimitiveForthWordlist, FICL_WORD_DEFAULT);
362*c0bb4f73SToomas Soome (void) ficlDictionarySetPrimitive(dictionary, "get-current",
363afc2ba1dSToomas Soome ficlPrimitiveGetCurrent, FICL_WORD_DEFAULT);
364*c0bb4f73SToomas Soome (void) ficlDictionarySetPrimitive(dictionary, "get-order",
365afc2ba1dSToomas Soome ficlPrimitiveGetOrder, FICL_WORD_DEFAULT);
366*c0bb4f73SToomas Soome (void) ficlDictionarySetPrimitive(dictionary, "search-wordlist",
367afc2ba1dSToomas Soome ficlPrimitiveSearchWordlist, FICL_WORD_DEFAULT);
368*c0bb4f73SToomas Soome (void) ficlDictionarySetPrimitive(dictionary, "set-current",
369afc2ba1dSToomas Soome ficlPrimitiveSetCurrent, FICL_WORD_DEFAULT);
370*c0bb4f73SToomas Soome (void) ficlDictionarySetPrimitive(dictionary, "set-order",
371afc2ba1dSToomas Soome ficlPrimitiveSetOrder, FICL_WORD_DEFAULT);
372*c0bb4f73SToomas Soome (void) ficlDictionarySetPrimitive(dictionary, "ficl-wordlist",
373afc2ba1dSToomas Soome ficlPrimitiveFiclWordlist, FICL_WORD_DEFAULT);
374afc2ba1dSToomas Soome
375afc2ba1dSToomas Soome /*
376afc2ba1dSToomas Soome * Set SEARCH environment query values
377afc2ba1dSToomas Soome */
378*c0bb4f73SToomas Soome (void) ficlDictionarySetConstant(environment, "search-order",
379*c0bb4f73SToomas Soome FICL_TRUE);
380*c0bb4f73SToomas Soome (void) ficlDictionarySetConstant(environment, "search-order-ext",
381*c0bb4f73SToomas Soome FICL_TRUE);
382*c0bb4f73SToomas Soome (void) ficlDictionarySetConstant(environment, "wordlists",
383*c0bb4f73SToomas Soome FICL_MAX_WORDLISTS);
384*c0bb4f73SToomas Soome (void) ficlDictionarySetPrimitive(dictionary, "wid-get-name",
385afc2ba1dSToomas Soome ficlPrimitiveWidGetName, FICL_WORD_DEFAULT);
386*c0bb4f73SToomas Soome (void) ficlDictionarySetPrimitive(dictionary, "wid-set-name",
387afc2ba1dSToomas Soome ficlPrimitiveWidSetName, FICL_WORD_DEFAULT);
388*c0bb4f73SToomas Soome (void) ficlDictionarySetPrimitive(dictionary, "wid-set-super",
389afc2ba1dSToomas Soome ficlPrimitiveSetParentWid, FICL_WORD_DEFAULT);
390afc2ba1dSToomas Soome }
391