ficlWord *ficlSystemLookupLocal(ficlSystem *system, ficlString name) { ficlWord *word = NULL; ficlDictionary *dictionary = system->dictionary; ficlHash *hash = ficlSystemGetLocals(system)->forthWordlist; int i; ficlUnsigned16 hashCode = ficlHashCode(name); FICL_SYSTEM_ASSERT(system, hash); FICL_SYSTEM_ASSERT(system, dictionary); ficlDictionaryLock(dictionary, FICL_TRUE); /* ** check the locals dictionary first... */ word = ficlHashLookup(hash, name, hashCode); /* ** If no joy, (!word) ------------------------------v ** iterate over the search list in the main dictionary */ for (i = (int)dictionary->wordlistCount - 1; (i >= 0) && (!word); --i) { hash = dictionary->wordlists[i]; word = ficlHashLookup(hash, name, hashCode); } ficlDictionaryLock(dictionary, FICL_FALSE); return word; }
/* * f i c l C o m p i l e S e a r c h * Builds the primitive wordset and the environment-query namespace. */ void ficlSystemCompileSearch(ficlSystem *system) { ficlDictionary *dictionary = ficlSystemGetDictionary(system); ficlDictionary *environment = ficlSystemGetEnvironment(system); FICL_SYSTEM_ASSERT(system, dictionary); FICL_SYSTEM_ASSERT(system, environment); /* * optional SEARCH-ORDER word set */ (void) ficlDictionarySetPrimitive(dictionary, ">search", ficlPrimitiveSearchPush, FICL_WORD_DEFAULT); (void) ficlDictionarySetPrimitive(dictionary, "search>", ficlPrimitiveSearchPop, FICL_WORD_DEFAULT); (void) ficlDictionarySetPrimitive(dictionary, "definitions", ficlPrimitiveDefinitions, FICL_WORD_DEFAULT); (void) ficlDictionarySetPrimitive(dictionary, "forth-wordlist", ficlPrimitiveForthWordlist, FICL_WORD_DEFAULT); (void) ficlDictionarySetPrimitive(dictionary, "get-current", ficlPrimitiveGetCurrent, FICL_WORD_DEFAULT); (void) ficlDictionarySetPrimitive(dictionary, "get-order", ficlPrimitiveGetOrder, FICL_WORD_DEFAULT); (void) ficlDictionarySetPrimitive(dictionary, "search-wordlist", ficlPrimitiveSearchWordlist, FICL_WORD_DEFAULT); (void) ficlDictionarySetPrimitive(dictionary, "set-current", ficlPrimitiveSetCurrent, FICL_WORD_DEFAULT); (void) ficlDictionarySetPrimitive(dictionary, "set-order", ficlPrimitiveSetOrder, FICL_WORD_DEFAULT); (void) ficlDictionarySetPrimitive(dictionary, "ficl-wordlist", ficlPrimitiveFiclWordlist, FICL_WORD_DEFAULT); /* * Set SEARCH environment query values */ (void) ficlDictionarySetConstant(environment, "search-order", FICL_TRUE); (void) ficlDictionarySetConstant(environment, "search-order-ext", FICL_TRUE); (void) ficlDictionarySetConstant(environment, "wordlists", FICL_MAX_WORDLISTS); (void) ficlDictionarySetPrimitive(dictionary, "wid-get-name", ficlPrimitiveWidGetName, FICL_WORD_DEFAULT); (void) ficlDictionarySetPrimitive(dictionary, "wid-set-name", ficlPrimitiveWidSetName, FICL_WORD_DEFAULT); (void) ficlDictionarySetPrimitive(dictionary, "wid-set-super", ficlPrimitiveSetParentWid, FICL_WORD_DEFAULT); }
void ficlSystemCompileFile(ficlSystem *system) { #if !FICL_WANT_FILE FICL_IGNORE(system); #else ficlDictionary *dictionary = ficlSystemGetDictionary(system); ficlDictionary *environment = ficlSystemGetEnvironment(system); FICL_SYSTEM_ASSERT(system, dictionary); FICL_SYSTEM_ASSERT(system, environment); ficlDictionarySetPrimitive(dictionary, "create-file", ficlPrimitiveCreateFile, FICL_WORD_DEFAULT); ficlDictionarySetPrimitive(dictionary, "open-file", ficlPrimitiveOpenFile, FICL_WORD_DEFAULT); ficlDictionarySetPrimitive(dictionary, "close-file", ficlPrimitiveCloseFile, FICL_WORD_DEFAULT); ficlDictionarySetPrimitive(dictionary, "include-file", ficlPrimitiveIncludeFile, FICL_WORD_DEFAULT); ficlDictionarySetPrimitive(dictionary, "read-file", ficlPrimitiveReadFile, FICL_WORD_DEFAULT); ficlDictionarySetPrimitive(dictionary, "read-line", ficlPrimitiveReadLine, FICL_WORD_DEFAULT); ficlDictionarySetPrimitive(dictionary, "write-file", ficlPrimitiveWriteFile, FICL_WORD_DEFAULT); ficlDictionarySetPrimitive(dictionary, "write-line", ficlPrimitiveWriteLine, FICL_WORD_DEFAULT); ficlDictionarySetPrimitive(dictionary, "file-position", ficlPrimitiveFilePosition, FICL_WORD_DEFAULT); ficlDictionarySetPrimitive(dictionary, "file-size", ficlPrimitiveFileSize, FICL_WORD_DEFAULT); ficlDictionarySetPrimitive(dictionary, "reposition-file", ficlPrimitiveRepositionFile, FICL_WORD_DEFAULT); ficlDictionarySetPrimitive(dictionary, "file-status", ficlPrimitiveFileStatus, FICL_WORD_DEFAULT); ficlDictionarySetPrimitive(dictionary, "flush-file", ficlPrimitiveFlushFile, FICL_WORD_DEFAULT); ficlDictionarySetPrimitive(dictionary, "delete-file", ficlPrimitiveDeleteFile, FICL_WORD_DEFAULT); ficlDictionarySetPrimitive(dictionary, "rename-file", ficlPrimitiveRenameFile, FICL_WORD_DEFAULT); #if FICL_PLATFORM_HAS_FTRUNCATE ficlDictionarySetPrimitive(dictionary, "resize-file", ficlPrimitiveResizeFile, FICL_WORD_DEFAULT); ficlDictionarySetConstant(environment, "file", FICL_TRUE); ficlDictionarySetConstant(environment, "file-ext", FICL_TRUE); #else /* FICL_PLATFORM_HAS_FTRUNCATE */ ficlDictionarySetConstant(environment, "file", FICL_FALSE); ficlDictionarySetConstant(environment, "file-ext", FICL_FALSE); #endif /* FICL_PLATFORM_HAS_FTRUNCATE */ #endif /* !FICL_WANT_FILE */ }
ficlDictionary * ficlDictionaryCreateHashed(ficlSystem *system, unsigned size, unsigned bucketCount) { ficlDictionary *dictionary; size_t nAlloc; nAlloc = sizeof (ficlDictionary) + (size * sizeof (ficlCell)) + sizeof (ficlHash) + (bucketCount - 1) * sizeof (ficlWord *); dictionary = ficlMalloc(nAlloc); FICL_SYSTEM_ASSERT(system, dictionary != NULL); dictionary->size = size; dictionary->system = system; ficlDictionaryEmpty(dictionary, bucketCount); return (dictionary); }