: min 2dup <= if drop else nip then ;
: max 2dup <= if nip else drop then ;
+: key begin _input @ dup 0 <= while drop _in repeat
+ dup 1- _input !
+ _input cell+ 80 chars + swap - c@ ;
: word here -1 cells over ! dup cell+ rot begin key 2dup <> while
2 pick c! swap char+ swap repeat
2drop over - over +! ;
: quit begin _rdepth 1 > while r> drop repeat postpone [ ;
: abort begin depth 0 > while drop repeat quit ;
+: abort" postpone s" ['] rot ,
+ postpone if ['] type , ['] abort ,
+ postpone else ['] 2drop , postpone then ; imm
: recurse _latword , ; imm
else
state.push(0);
}
+// auto addr = state.pop();
+// auto count = state.dict.read(addr++);
+// Word word (addr, addr + count);
+//
+// if (auto j = state.dict.find(word); j > 0) {
+// state.push(state.dict.getexec(j));
+// auto imm = state.dict.read(ins) & CoreWords::Immediate;
+// state.push(imm ? 1 : -1);
+// } else if (auto i = CoreWords::findi(state, word); i >= 0) {
+// state.push(((i & ~CoreWords::Immediate) << 1) | 1);
+// state.push((i & CoreWords::Immediate) ? 1 : -1);
+// } else {
+// state.push(addr);
+// state.push(0);
+// }
void CoreWords::run(unsigned int index, State& state)
{
case 30: // _rdepth
state.push(state.rsize());
break;
- case 31: // key
- cell = state.dict.read(Dictionary::Input);
- while (cell <= 0) {
- state.input(state);
- cell = state.dict.read(Dictionary::Input);
- }
-
- state.dict.write(Dictionary::Input, cell - 1);
-
- state.push(
- state.dict.readbyte(
- Dictionary::Input + sizeof(Cell) +
- Dictionary::InputCells - cell));
+ case 31: // _in
+ state.input(state);
break;
}
"<\0&\0|\0^\0"
"<<\0>>\0:\0'\0execute\0"
"exit\0;\0_jmp0\0_jmp\0"
- "depth\0_rdepth\0key\0";
+ "depth\0_rdepth\0_in\0";
};
#endif // ALEEFORTH_COREWORDS_HPP