/* ** Compile a word into the dictionary that invokes the specified ficlParseStep ** function. It is up to the user (as usual in Forth) to make sure the stack ** preconditions are valid (there needs to be a counted string on top of the stack) ** before using the resulting word. */ void ficlSystemAddPrimitiveParseStep(ficlSystem *system, char *name, ficlParseStep pStep) { ficlDictionary *dictionary = system->dictionary; ficlWord *word = ficlDictionaryAppendPrimitive(dictionary, name, ficlPrimitiveParseStepParen, FICL_WORD_DEFAULT); ficlDictionaryAppendCell(dictionary, FICL_LVALUE_TO_CELL(pStep)); ficlSystemAddParseStep(system, word); }
ficlWord * ficlDictionaryAppendInstruction(ficlDictionary *dictionary, char *name, ficlInstruction i, ficlUnsigned8 flags) { return (ficlDictionaryAppendPrimitive(dictionary, name, (ficlPrimitive)i, (ficlUnsigned8)(FICL_WORD_INSTRUCTION | flags))); }
/* * Initialise the Forth interpreter, create all our commands as words. */ void bf_init(char *rc) { struct bootblk_command **cmdp; char create_buf[41]; /* 31 characters-long builtins */ int fd, rv; ficlDictionary *dict; ficlDictionary *env; fsi = malloc(sizeof (ficlSystemInformation)); ficlSystemInformationInitialize(fsi); fsi->dictionarySize = BF_DICTSIZE; bf_sys = ficlSystemCreate(fsi); bf_vm = ficlSystemCreateVm(bf_sys); /* Put all private definitions in a "builtins" vocabulary */ rv = ficlVmEvaluate(bf_vm, "vocabulary builtins also builtins definitions"); if (rv != FICL_VM_STATUS_OUT_OF_TEXT) { panic("error interpreting forth: %d", rv); } /* Builtin constructor word */ rv = ficlVmEvaluate(bf_vm, BUILTIN_CONSTRUCTOR); if (rv != FICL_VM_STATUS_OUT_OF_TEXT) { panic("error interpreting forth: %d", rv); } /* make all commands appear as Forth words */ dict = ficlSystemGetDictionary(bf_sys); SET_FOREACH(cmdp, Xcommand_set) { ficlDictionaryAppendPrimitive(dict, (char *)(*cmdp)->c_name, bf_command, FICL_WORD_DEFAULT); rv = ficlVmEvaluate(bf_vm, "forth definitions builtins"); if (rv != FICL_VM_STATUS_OUT_OF_TEXT) { panic("error interpreting forth: %d", rv); } sprintf(create_buf, "builtin: %s", (*cmdp)->c_name); rv = ficlVmEvaluate(bf_vm, create_buf); if (rv != FICL_VM_STATUS_OUT_OF_TEXT) { panic("error interpreting forth: %d", rv); } rv = ficlVmEvaluate(bf_vm, "builtins definitions"); if (rv != FICL_VM_STATUS_OUT_OF_TEXT) { panic("error interpreting forth: %d", rv); } }
ficlWord * ficlDictionarySetPrimitive(ficlDictionary *dictionary, char *name, ficlPrimitive code, ficlUnsigned8 flags) { ficlString s; ficlWord *word; FICL_STRING_SET_FROM_CSTRING(s, name); word = ficlDictionaryLookup(dictionary, s); if (word == NULL) { word = ficlDictionaryAppendPrimitive(dictionary, name, code, flags); } else { word->code = (ficlPrimitive)code; word->flags = flags; } return (word); }
FICL_PLATFORM_EXTERN ficlWord *dictAppendWord (ficlDictionary *dictionary, char *name, ficlPrimitive code, ficlUnsigned8 flags) { return ficlDictionaryAppendPrimitive(dictionary, name, code, flags); }
FICL_PLATFORM_EXTERN int ficlBuild(ficlSystem *system, char *name, ficlPrimitive code, char flags) { ficlDictionary *dictionary = ficlSystemGetDictionary(system); ficlDictionaryLock(dictionary, FICL_TRUE); ficlDictionaryAppendPrimitive(dictionary, name, code, flags); ficlDictionaryLock(dictionary, FICL_FALSE); return 0; }