diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2024-01-01 10:16:16 -0500 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2024-01-01 10:16:16 -0500 |
commit | e8c9f97f4fa9502b88c8c3a44c5d5f5f1c98d506 (patch) | |
tree | 37936d41a6e595d5fdf4b9d1f74a007b6832985f /libalee/dictionary.cpp | |
parent | 2261914a6b291bf4073cddf30a862df3c3a341e9 (diff) | |
parent | 6e4c0430de5ade2c8375ddcdeec93d4df3b163b1 (diff) |
Merge branch 'native' of ssh://code.bitgloo.com:222/bitgloo/alee-forth into native
Diffstat (limited to 'libalee/dictionary.cpp')
-rw-r--r-- | libalee/dictionary.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/libalee/dictionary.cpp b/libalee/dictionary.cpp index 0abc038..e946c59 100644 --- a/libalee/dictionary.cpp +++ b/libalee/dictionary.cpp @@ -29,6 +29,22 @@ void Dictionary::initialize() } LIBALEE_SECTION +void Dictionary::addNativeWord(const char *s, void (*func)(State&)) +{ + const Addr h = read(Here); + Addr n = h + sizeof(Cell); + for (; *s; ++s, ++n) + writebyte(n, *s); + addDefinition(Word(h + sizeof(Cell), n)); + add(CoreWords::token("_nx")); + add((Cell)func); + + const auto dcell = h - latest(); + write(h, (read(h) & 0x1F) | Native | static_cast<Cell>(dcell << DistancePos)); + latest(h); +} + +LIBALEE_SECTION Addr Dictionary::allot(Cell amount) noexcept { Addr old = here(); @@ -91,14 +107,14 @@ Addr Dictionary::find(Word word) noexcept const Addr len = l & 0x1F; Word lw; - if ((l >> Dictionary::DistancePos) < MaxDistance) { + if ((l >> DistancePos) < MaxDistance) { lw = Word::fromLength(lt + sizeof(Cell), len); if (equal(word, lw)) return lt; else if (lt == Begin) break; else - lt -= l >> Dictionary::DistancePos; + lt -= l >> DistancePos; } else { lw = Word::fromLength(lt + 2 * sizeof(Cell), len); if (equal(word, lw)) @@ -120,7 +136,7 @@ Addr Dictionary::getexec(Addr addr) noexcept const Addr len = l & 0x1Fu; addr += sizeof(Cell); - if ((l >> Dictionary::DistancePos) == MaxDistance) + if ((l >> DistancePos) == MaxDistance) addr += sizeof(Cell); addr += len; |