add native definition bit

native
Clyne 1 year ago
parent 22a89e9949
commit e4f1fba4e8
Signed by: clyne
GPG Key ID: 1B74EE6C49C96795

@ -6,8 +6,8 @@
: words _latest @ begin : words _latest @ begin
dup @ dup 31 & dup @ dup 31 &
2 pick cell+ \ lt l len ws 2 pick cell+ \ lt l len ws
2 pick 6 >> 1023 < if \ lt l len ws 2 pick 7 >> 1023 < if \ lt l len ws
rot 6 >> else \ lt len ws adv rot 7 >> else \ lt len ws adv
>r cell+ rot drop r> @ then >r cell+ rot drop r> @ then
-rot swap type space \ lt adv -rot swap type space \ lt adv
over _begin <> while - repeat 2drop ; over _begin <> while - repeat 2drop ;

@ -241,7 +241,7 @@ void CoreWords::word_semic(State& state) { // Concludes word definition.
dcell = Dictionary::MaxDistance; dcell = Dictionary::MaxDistance;
} }
state.dict.write(cell, 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); state.dict.latest(cell);
} }
void CoreWords::word_jmp0(State& state) { // Jump if popped value equals zero. void CoreWords::word_jmp0(State& state) { // Jump if popped value equals zero.

@ -91,14 +91,14 @@ Addr Dictionary::find(Word word) noexcept
const Addr len = l & 0x1F; const Addr len = l & 0x1F;
Word lw; Word lw;
if ((l >> 6) < MaxDistance) { if ((l >> DistancePos) < MaxDistance) {
lw = Word::fromLength(lt + sizeof(Cell), len); lw = Word::fromLength(lt + sizeof(Cell), len);
if (equal(word, lw)) if (equal(word, lw))
return lt; return lt;
else if (lt == Begin) else if (lt == Begin)
break; break;
else else
lt -= l >> 6; lt -= l >> DistancePos;
} else { } else {
lw = Word::fromLength(lt + 2 * sizeof(Cell), len); lw = Word::fromLength(lt + 2 * sizeof(Cell), len);
if (equal(word, lw)) if (equal(word, lw))
@ -120,7 +120,7 @@ Addr Dictionary::getexec(Addr addr) noexcept
const Addr len = l & 0x1Fu; const Addr len = l & 0x1Fu;
addr += sizeof(Cell); addr += sizeof(Cell);
if ((l >> 6) == MaxDistance) if ((l >> DistancePos) == MaxDistance)
addr += sizeof(Cell); addr += sizeof(Cell);
addr += len; addr += len;

@ -73,8 +73,12 @@ public:
/** "Immediate" marker bit for a word's definition. */ /** "Immediate" marker bit for a word's definition. */
constexpr static Cell Immediate = (1 << 5); 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. */ /** 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. */ /** Returns the value of the cell at the given address. */
virtual Cell read(Addr) const noexcept = 0; virtual Cell read(Addr) const noexcept = 0;

Loading…
Cancel
Save