Lines Matching refs:dictionary

3  * Forth Inspired Command Language - dictionary methods
6 * $Id: dictionary.c,v 1.2 2010/09/12 15:14:52 asau Exp $
9 * This file implements the dictionary -- Ficl's model of
11 * dictionary. A word is a named chunk of data with its
58 #define FICL_SAFE_SYSTEM_FROM_DICTIONARY(dictionary) \
59 (((dictionary) != NULL) ? (dictionary)->system : NULL)
60 #define FICL_DICTIONARY_ASSERT(dictionary, expression) \
61 FICL_SYSTEM_ASSERT(FICL_SAFE_SYSTEM_FROM_DICTIONARY(dictionary), \
67 * from the dictionary list. Assumes that there is a smudged
75 ficlDictionaryAbortDefinition(ficlDictionary *dictionary)
78 ficlDictionaryLock(dictionary, FICL_TRUE);
79 word = dictionary->smudge;
82 dictionary->here = (ficlCell *)word->name;
84 ficlDictionaryLock(dictionary, FICL_FALSE);
89 * Align the dictionary's free space pointer
92 ficlDictionaryAlign(ficlDictionary *dictionary)
94 dictionary->here = ficlAlignPointer(dictionary->here);
99 * Allocate or remove n chars of dictionary space, with
103 ficlDictionaryAllot(ficlDictionary *dictionary, int n)
105 char *here = (char *)dictionary->here;
107 dictionary->here = FICL_POINTER_TO_CELL(here);
113 * dictionary. If nficlCells < 0 , removes space from the dictionary.
116 ficlDictionaryAllotCells(ficlDictionary *dictionary, int nficlCells)
118 dictionary->here += nficlCells;
123 * Append the specified ficlCell to the dictionary
126 ficlDictionaryAppendCell(ficlDictionary *dictionary, ficlCell c)
128 *dictionary->here++ = c;
133 * Append the specified char to the dictionary
136 ficlDictionaryAppendCharacter(ficlDictionary *dictionary, char c)
138 char *here = (char *)dictionary->here;
140 dictionary->here = FICL_POINTER_TO_CELL(here);
145 * Append the specified ficlUnsigned to the dictionary
148 ficlDictionaryAppendUnsigned(ficlDictionary *dictionary, ficlUnsigned u)
153 ficlDictionaryAppendCell(dictionary, c);
157 ficlDictionaryAppendData(ficlDictionary *dictionary, void *data,
160 char *here = (char *)dictionary->here;
165 ficlDictionaryAlign(dictionary);
166 return ((char *)dictionary->here);
176 dictionary->here = FICL_POINTER_TO_CELL(here);
177 ficlDictionaryAlign(dictionary);
184 * the dictionary starting at "here", then NULL-terminate the name,
192 ficlDictionaryAppendString(ficlDictionary *dictionary, ficlString s)
200 return (ficlDictionaryAppendData(dictionary, data, length));
204 ficlDictionaryAppendConstantInstruction(ficlDictionary *dictionary,
207 ficlWord *word = ficlDictionaryAppendWord(dictionary, name,
211 ficlDictionaryAppendUnsigned(dictionary, value);
216 ficlDictionaryAppend2ConstantInstruction(ficlDictionary *dictionary,
219 ficlWord *word = ficlDictionaryAppendWord(dictionary, name,
223 ficlDictionaryAppendUnsigned(dictionary,
225 ficlDictionaryAppendUnsigned(dictionary,
232 ficlDictionaryAppendConstant(ficlDictionary *dictionary, char *name,
237 return (ficlDictionaryAppendConstantInstruction(dictionary, s,
242 ficlDictionaryAppend2Constant(ficlDictionary *dictionary, char *name,
247 return (ficlDictionaryAppend2ConstantInstruction(dictionary, s,
252 ficlDictionarySetConstantInstruction(ficlDictionary *dictionary,
255 ficlWord *word = ficlDictionaryLookup(dictionary, name);
259 word = ficlDictionaryAppendConstantInstruction(dictionary,
270 ficlDictionarySetConstant(ficlDictionary *dictionary, char *name,
275 return (ficlDictionarySetConstantInstruction(dictionary, s,
280 ficlDictionarySet2ConstantInstruction(ficlDictionary *dictionary, ficlString s,
284 word = ficlDictionaryLookup(dictionary, s);
303 word = ficlDictionaryAppend2ConstantInstruction(dictionary, s,
311 ficlDictionarySet2Constant(ficlDictionary *dictionary, char *name,
317 return (ficlDictionarySet2ConstantInstruction(dictionary, s,
322 ficlDictionarySetConstantString(ficlDictionary *dictionary, char *name,
330 return (ficlDictionarySet2ConstantInstruction(dictionary, s,
336 * Create a new word in the dictionary with the specified
341 ficlDictionaryAppendWord(ficlDictionary *dictionary, ficlString name,
348 ficlDictionaryLock(dictionary, FICL_TRUE);
354 nameCopy = ficlDictionaryAppendString(dictionary, name);
355 word = (ficlWord *)dictionary->here;
356 dictionary->smudge = word;
367 dictionary->here = word->param;
370 ficlDictionaryUnsmudge(dictionary);
372 ficlDictionaryLock(dictionary, FICL_FALSE);
378 * Create a new word in the dictionary with the specified
382 ficlDictionaryAppendPrimitive(ficlDictionary *dictionary, char *name,
388 return (ficlDictionaryAppendWord(dictionary, s, code, flags));
392 ficlDictionarySetPrimitive(ficlDictionary *dictionary, char *name,
399 word = ficlDictionaryLookup(dictionary, s);
402 word = ficlDictionaryAppendPrimitive(dictionary, name,
412 ficlDictionaryAppendInstruction(ficlDictionary *dictionary, char *name,
415 return (ficlDictionaryAppendPrimitive(dictionary, name,
420 ficlDictionarySetInstruction(ficlDictionary *dictionary, char *name,
423 return (ficlDictionarySetPrimitive(dictionary, name,
429 * Returns the number of empty ficlCells left in the dictionary
432 ficlDictionaryCellsAvailable(ficlDictionary *dictionary)
434 return (dictionary->size - ficlDictionaryCellsUsed(dictionary));
442 ficlDictionaryCellsUsed(ficlDictionary *dictionary)
444 return (dictionary->here - dictionary->base);
449 * Create and initialize a dictionary with the specified number
462 ficlDictionary *dictionary;
468 dictionary = ficlMalloc(nAlloc);
469 FICL_SYSTEM_ASSERT(system, dictionary != NULL);
471 dictionary->size = size;
472 dictionary->system = system;
474 ficlDictionaryEmpty(dictionary, bucketCount);
475 return (dictionary);
483 ficlDictionaryCreateWordlist(ficlDictionary *dictionary, int bucketCount)
487 ficlDictionaryAlign(dictionary);
488 hash = (ficlHash *)dictionary->here;
489 ficlDictionaryAllot(dictionary,
499 * Free all memory allocated for the given dictionary
502 ficlDictionaryDestroy(ficlDictionary *dictionary)
504 FICL_DICTIONARY_ASSERT(dictionary, dictionary != NULL);
505 ficlFree(dictionary);
510 * Empty the dictionary, reset its hash table, and reset its search order.
514 ficlDictionaryEmpty(ficlDictionary *dictionary, unsigned bucketCount)
518 dictionary->here = dictionary->base;
520 ficlDictionaryAlign(dictionary);
521 hash = (ficlHash *)dictionary->here;
522 ficlDictionaryAllot(dictionary,
528 dictionary->forthWordlist = hash;
529 dictionary->smudge = NULL;
530 ficlDictionaryResetSearchOrder(dictionary);
538 * like it's in the dictionary address range.
542 ficlDictionaryIsAWord(ficlDictionary *dictionary, ficlWord *word)
548 if (!ficlDictionaryIncludes(dictionary, word))
551 if (!ficlDictionaryIncludes(dictionary, word->name))
555 !ficlDictionaryIncludes(dictionary, word->link))
570 * dictionary. If so, search backwards until we find something that looks
571 * like a dictionary header. If successful, return the address of the
578 ficlDictionaryFindEnclosingWord(ficlDictionary *dictionary, ficlCell *cell)
583 if (!ficlDictionaryIncludes(dictionary, (void *)cell))
589 if (ficlDictionaryIsAWord(dictionary, word))
599 * the dictionary.
602 ficlDictionaryIncludes(ficlDictionary *dictionary, void *p)
604 return ((p >= (void *) &dictionary->base) &&
605 (p < (void *)(&dictionary->base + dictionary->size)));
615 ficlDictionaryLookup(ficlDictionary *dictionary, ficlString name)
622 FICL_DICTIONARY_ASSERT(dictionary, dictionary != NULL);
624 ficlDictionaryLock(dictionary, FICL_TRUE);
626 for (i = (int)dictionary->wordlistCount - 1; (i >= 0) && (!word); --i) {
627 hash = dictionary->wordlists[i];
631 ficlDictionaryLock(dictionary, FICL_FALSE);
658 ficlDictionarySee(ficlDictionary *dictionary, ficlWord *word,
676 if (ficlDictionaryIsAWord(dictionary, word)) {
702 if (ficlDictionaryIsAWord(dictionary, c.p) &&
803 * Initialize the dictionary search order list to sane state
806 ficlDictionaryResetSearchOrder(ficlDictionary *dictionary)
808 FICL_DICTIONARY_ASSERT(dictionary, dictionary);
809 dictionary->compilationWordlist = dictionary->forthWordlist;
810 dictionary->wordlistCount = 1;
811 dictionary->wordlists[0] = dictionary->forthWordlist;
820 ficlDictionarySetFlags(ficlDictionary *dictionary, ficlUnsigned8 set)
822 FICL_DICTIONARY_ASSERT(dictionary, dictionary->smudge);
823 dictionary->smudge->flags |= set;
833 ficlDictionaryClearFlags(ficlDictionary *dictionary, ficlUnsigned8 clear)
835 FICL_DICTIONARY_ASSERT(dictionary, dictionary->smudge);
836 dictionary->smudge->flags &= ~clear;
844 ficlDictionarySetImmediate(ficlDictionary *dictionary)
846 FICL_DICTIONARY_ASSERT(dictionary, dictionary->smudge);
847 dictionary->smudge->flags |= FICL_WORD_IMMEDIATE;
856 ficlDictionaryUnsmudge(ficlDictionary *dictionary)
858 ficlWord *word = dictionary->smudge;
859 ficlHash *hash = dictionary->compilationWordlist;
861 FICL_DICTIONARY_ASSERT(dictionary, hash);
862 FICL_DICTIONARY_ASSERT(dictionary, word);
875 * of the next free ficlCell in the dictionary
878 ficlDictionaryWhere(ficlDictionary *dictionary)
880 return (dictionary->here);