aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2023-02-27 08:39:21 -0500
committerClyne Sullivan <clyne@bitgloo.com>2023-02-27 08:39:21 -0500
commitf63c4dec8ae2ae7e460a5ac00fd55cdc7972008a (patch)
treef7bcdf05cbb31b0bbf6c2f238a58877292f17292
parentc5db61d59fd75b786bd3e5a57a163d37df20a8b9 (diff)
key in forth; abort"; draft find
-rw-r--r--compat.txt2
-rw-r--r--core.fth6
-rw-r--r--corewords.cpp30
-rw-r--r--corewords.hpp2
4 files changed, 25 insertions, 15 deletions
diff --git a/compat.txt b/compat.txt
index a4c6326..91e2931 100644
--- a/compat.txt
+++ b/compat.txt
@@ -43,7 +43,7 @@ yes 6.1.0580 >R
yes 6.1.0630 ?DUP
yes 6.1.0650 @
yes 6.1.0670 ABORT
- 6.1.0680 ABORT"
+yes 6.1.0680 ABORT"
yes 6.1.0690 ABS
yes 6.1.0695 ACCEPT
yes 6.1.0705 ALIGN
diff --git a/core.fth b/core.fth
index 1475224..178a5d2 100644
--- a/core.fth
+++ b/core.fth
@@ -123,6 +123,9 @@
: 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 +! ;
@@ -181,6 +184,9 @@
: 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
diff --git a/corewords.cpp b/corewords.cpp
index 1ee7928..49a757a 100644
--- a/corewords.cpp
+++ b/corewords.cpp
@@ -49,6 +49,21 @@ void tick(State& state)
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)
{
@@ -191,19 +206,8 @@ execute:
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;
}
diff --git a/corewords.hpp b/corewords.hpp
index 56f7703..9546ac1 100644
--- a/corewords.hpp
+++ b/corewords.hpp
@@ -45,7 +45,7 @@ private:
"<\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