diff --git a/README.md b/README.md index d262a87..d57ae3a 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,6 @@ Running Alee without `core.fth` or `core-ext.fth` passed as arguments will leave * Pictured numeric output conversion (e.g. `<# #>`) * Words for unsigned integers: `U. U< UM* UM/MOD` * `>NUMBER` -* `FIND` **Missing** core extensions: ``` diff --git a/compat.txt b/compat.txt index 890871a..2410bd5 100644 --- a/compat.txt +++ b/compat.txt @@ -78,7 +78,7 @@ yes 6.1.1360 EVALUATE yes 6.1.1370 EXECUTE yes 6.1.1380 EXIT yes 6.1.1540 FILL - 6.1.1550 FIND +yes 6.1.1550 FIND yes 6.1.1561 FM/MOD yes 6.1.1650 HERE 6.1.1670 HOLD diff --git a/forth/test/core.fr b/forth/test/core.fr index 2d8b8e4..d2724e1 100644 --- a/forth/test/core.fr +++ b/forth/test/core.fr @@ -647,8 +647,8 @@ T{ : GT2 ['] GT1 ; IMMEDIATE -> }T T{ GT2 EXECUTE -> 123 }T HERE 3 C, CHAR G C, CHAR T C, CHAR 1 C, CONSTANT GT1STRING HERE 3 C, CHAR G C, CHAR T C, CHAR 2 C, CONSTANT GT2STRING -\ T{ GT1STRING FIND -> ' GT1 -1 }T -\ T{ GT2STRING FIND -> ' GT2 1 }T +T{ GT1STRING FIND -> ' GT1 -1 }T +T{ GT2STRING FIND -> ' GT2 1 }T \ ( HOW TO SEARCH FOR NON-EXISTENT WORD? ) T{ : GT3 GT2 LITERAL ; -> }T T{ GT3 -> ' GT1 }T diff --git a/libalee/corewords.cpp b/libalee/corewords.cpp index 1a09936..f22772c 100644 --- a/libalee/corewords.cpp +++ b/libalee/corewords.cpp @@ -39,9 +39,8 @@ void newdef(State& state, Word word) dict.addDefinition(word); state.push(addr); }; -void tick(State& state) +void find(State& state, Word word) { - auto word = getword(state); if (auto j = state.dict.find(word); j > 0) { state.push(state.dict.getexec(j)); auto imm = state.dict.read(j) & Dictionary::Immediate; @@ -165,7 +164,7 @@ execute: state.compiling(true); break; case 23: // tick - tick(state); + find(state, getword(state)); break; case 24: // execute index = state.pop(); @@ -213,6 +212,16 @@ execute: state.load(st); } break; + case 33: // find + { + const Addr caddr = state.pop(); + const Word word { + static_cast(caddr + 1), + static_cast(caddr + 1 + state.dict.readbyte(caddr)) + }; + find(state, word); + } + break; default: state.push(index - WordCount); break; diff --git a/libalee/corewords.hpp b/libalee/corewords.hpp index 5798f59..684b94b 100644 --- a/libalee/corewords.hpp +++ b/libalee/corewords.hpp @@ -31,7 +31,7 @@ void user_sys(State&); class CoreWords { public: - constexpr static std::size_t WordCount = 33; + constexpr static std::size_t WordCount = 34; constexpr static int Semicolon = 26; /** @@ -53,7 +53,7 @@ public: "<\0&\0|\0^\0" "<<\0>>\0:\0_'\0execute\0" "exit\0;\0_jmp0\0_jmp\0" - "depth\0_rdepth\0_in\0_ev\0"; + "depth\0_rdepth\0_in\0_ev\0find\0"; }; #endif // ALEEFORTH_COREWORDS_HPP