CompiledWord[] buildWordList() { CompiledWord[] words = new CompiledWord[context.cp]; System.arraycopy(context.compiling, 0, words, 0, context.cp); context.cp = 0; return(words); }
//////////////////////////////////////////////////////// private void storeWord( string name, int type, long integer, Object data) { CompiledWord word = (CompiledWord)getStore(name); bool changed = true; if (word != null) { changed = copyWord(word, type, integer, data); } else { word = createWord(name, type, integer, data); putStore(name, word); } if (word.trigger != null && changed) { runWordList(word.trigger); } if (word.last_trigger != null && changed) { runWordList(word.last_trigger); } }
// public void remove(string name) { deleteStore(name); } // public bool trigger_word_on_update(string trigger, string data) { // CompiledWord triggerWord = (CompiledWord) getStore(trigger); // CompiledWord dataWord = (CompiledWord) getStore(data); // if(triggerWord == null || dataWord == null) return false; // dataWord.trigger = triggerWord; // return true; // } public void runWord(CompiledWord word) { if (context.debugging) { dumpWord(word); } if (empty(word)) { return; } context.runningWords[context.rwsp++ & 31] = context.currentWord = word; switch (word.type) { case TYPE_DATA: context.oStack[context.osp++ & 63] = word.data; context.iStack[context.isp++ & 63] = nan; break; case TYPE_INT: context.iStack[context.isp++ & 63] = word.integer; break; case TYPE_RUNNABLE: ((Runnable)word.data).run(); break; case TYPE_WORD_LIST: runWordList((CompiledWord[])word.data); break; } context.rwsp--; }
public void runWord(string name) { CompiledWord word = (CompiledWord)getStore(name); if (word != null) { runWord(word); } }
private CompiledWord fillWord( CompiledWord word, string name, int type, long integer, Object data) { word.type = type; word.name = name; word.data = data; word.integer = integer; return(word); }
createWord(string name, int type, long integer, Object data) { CompiledWord word = (CompiledWord)getStore(name); if (word == null) { word = newWord(); } return(fillWord(word, name, type, integer, data)); }
public long getInt(string name) { CompiledWord word = (CompiledWord)getStore(name); if (word != null && word.type == TYPE_INT) { return(word.integer); } return(nan); }
private bool copyWord(CompiledWord to, int type, long val, Object data) { if (to.type != type || to.integer != val || !cmp(to.data, data)) { to.type = type; to.integer = val; to.data = data; return(true); } return(false); }
public Object get(string name) { CompiledWord word = (CompiledWord)getStore(name); if (word == null) { return(null); } switch (word.type) { case TYPE_DATA: return(word.data); case TYPE_INT: return(newInteger(word.integer)); default: return(null); } }
private bool compile() { string name; while ((name = getSourceWord()) != null) { context.isCompileMode = true; CompiledWord word = (CompiledWord)getStore(name); if (word != null) { if (word.type == TYPE_IMMEDIATE) { ((Runnable)word.data).run(); } else { context.compiling[context.cp++] = word; } } else if (!compileLiteral(name)) { word = createWord(name, TYPE_WORD_LIST, nan, new CompiledWord[0]); putStore(name, word); context.compiling[context.cp++] = word; } context.isCompileMode = false; if (context.abort) { return(false); } if (context.cp > 32 && context.ctlsp == 1) { return(true); } if (context.cp > 48) { return(true); } } return(false); }