aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2023-11-17 20:27:33 -0500
committerClyne Sullivan <clyne@bitgloo.com>2023-11-17 20:27:33 -0500
commite4f1fba4e8cc3991a6b6f40570c096c01f7c302d (patch)
tree501a5c03f5a495ab9c5940840a6edfa49a008175
parent22a89e994939824015a2ee23ac8a4d544a0882b6 (diff)
add native definition bit
-rw-r--r--forth/tools.fth4
-rw-r--r--libalee/corewords.cpp2
-rw-r--r--libalee/dictionary.cpp6
-rw-r--r--libalee/dictionary.hpp6
4 files changed, 11 insertions, 7 deletions
diff --git a/forth/tools.fth b/forth/tools.fth
index b27955d..3cee2bf 100644
--- a/forth/tools.fth
+++ b/forth/tools.fth
@@ -6,8 +6,8 @@
: words _latest @ begin
dup @ dup 31 &
2 pick cell+ \ lt l len ws
- 2 pick 6 >> 1023 < if \ lt l len ws
- rot 6 >> else \ lt len ws adv
+ 2 pick 7 >> 1023 < if \ lt l len ws
+ rot 7 >> else \ lt len ws adv
>r cell+ rot drop r> @ then
-rot swap type space \ lt adv
over _begin <> while - repeat 2drop ;
diff --git a/libalee/corewords.cpp b/libalee/corewords.cpp
index d47e092..8ff7ac6 100644
--- a/libalee/corewords.cpp
+++ b/libalee/corewords.cpp
@@ -241,7 +241,7 @@ void CoreWords::word_semic(State& state) { // Concludes word definition.
dcell = Dictionary::MaxDistance;
}
state.dict.write(cell,
- (state.dict.read(cell) & 0x1F) | static_cast<Cell>(dcell << 6));
+ (state.dict.read(cell) & 0x1F) | static_cast<Cell>(dcell << Dictionary::DistancePos));
state.dict.latest(cell);
}
void CoreWords::word_jmp0(State& state) { // Jump if popped value equals zero.
diff --git a/libalee/dictionary.cpp b/libalee/dictionary.cpp
index b1cbc5f..e4f6761 100644
--- a/libalee/dictionary.cpp
+++ b/libalee/dictionary.cpp
@@ -91,14 +91,14 @@ Addr Dictionary::find(Word word) noexcept
const Addr len = l & 0x1F;
Word lw;
- if ((l >> 6) < 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 >> 6;
+ lt -= l >> DistancePos;
} else {
lw = Word::fromLength(lt + 2 * sizeof(Cell), len);
if (equal(word, lw))
@@ -120,7 +120,7 @@ Addr Dictionary::getexec(Addr addr) noexcept
const Addr len = l & 0x1Fu;
addr += sizeof(Cell);
- if ((l >> 6) == MaxDistance)
+ if ((l >> DistancePos) == MaxDistance)
addr += sizeof(Cell);
addr += len;
diff --git a/libalee/dictionary.hpp b/libalee/dictionary.hpp
index ad1ee02..092026b 100644
--- a/libalee/dictionary.hpp
+++ b/libalee/dictionary.hpp
@@ -73,8 +73,12 @@ public:
/** "Immediate" marker bit for a word's definition. */
constexpr static Cell Immediate = (1 << 5);
+ /** TODO */
+ constexpr static Cell Native = (1 << 6);
+ /** TODO */
+ constexpr static Cell DistancePos = 7;
/** Maximum "short" distance between two definitions. */
- constexpr static Cell MaxDistance = (1 << (sizeof(Cell) * 8 - 6)) - 1;
+ constexpr static Cell MaxDistance = (1 << (sizeof(Cell) * 8 - DistancePos)) - 1;
/** Returns the value of the cell at the given address. */
virtual Cell read(Addr) const noexcept = 0;