key in forth; abort"; draft find

llvm
Clyne 2 years ago
parent c5db61d59f
commit f63c4dec8a

@ -43,7 +43,7 @@ yes 6.1.0580 >R
yes 6.1.0630 ?DUP yes 6.1.0630 ?DUP
yes 6.1.0650 @ yes 6.1.0650 @
yes 6.1.0670 ABORT yes 6.1.0670 ABORT
6.1.0680 ABORT" yes 6.1.0680 ABORT"
yes 6.1.0690 ABS yes 6.1.0690 ABS
yes 6.1.0695 ACCEPT yes 6.1.0695 ACCEPT
yes 6.1.0705 ALIGN yes 6.1.0705 ALIGN

@ -123,6 +123,9 @@
: min 2dup <= if drop else nip then ; : min 2dup <= if drop else nip then ;
: max 2dup <= if nip else drop 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 : word here -1 cells over ! dup cell+ rot begin key 2dup <> while
2 pick c! swap char+ swap repeat 2 pick c! swap char+ swap repeat
2drop over - over +! ; 2drop over - over +! ;
@ -181,6 +184,9 @@
: quit begin _rdepth 1 > while r> drop repeat postpone [ ; : quit begin _rdepth 1 > while r> drop repeat postpone [ ;
: abort begin depth 0 > while drop repeat quit ; : 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 : recurse _latword , ; imm

@ -49,6 +49,21 @@ void tick(State& state)
else else
state.push(0); 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) void CoreWords::run(unsigned int index, State& state)
{ {
@ -191,19 +206,8 @@ execute:
case 30: // _rdepth case 30: // _rdepth
state.push(state.rsize()); state.push(state.rsize());
break; break;
case 31: // key case 31: // _in
cell = state.dict.read(Dictionary::Input); state.input(state);
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));
break; break;
} }

@ -45,7 +45,7 @@ private:
"<\0&\0|\0^\0" "<\0&\0|\0^\0"
"<<\0>>\0:\0'\0execute\0" "<<\0>>\0:\0'\0execute\0"
"exit\0;\0_jmp0\0_jmp\0" "exit\0;\0_jmp0\0_jmp\0"
"depth\0_rdepth\0key\0"; "depth\0_rdepth\0_in\0";
}; };
#endif // ALEEFORTH_COREWORDS_HPP #endif // ALEEFORTH_COREWORDS_HPP

Loading…
Cancel
Save