|
|
|
@ -43,7 +43,7 @@ void CoreWords::run(unsigned int index, State& state)
|
|
|
|
|
if (auto j = state.dict.find(word); j > 0)
|
|
|
|
|
state.push(state.dict.getexec(j));
|
|
|
|
|
else if (auto i = CoreWords::findi(state, word); i >= 0)
|
|
|
|
|
state.push(i & ~CoreWords::Compiletime);
|
|
|
|
|
state.push(i & ~CoreWords::Immediate);
|
|
|
|
|
else
|
|
|
|
|
state.push(0);
|
|
|
|
|
};
|
|
|
|
@ -57,77 +57,77 @@ void CoreWords::run(unsigned int index, State& state)
|
|
|
|
|
state.pushr(state.ip);
|
|
|
|
|
state.ip = index - sizeof(Cell);
|
|
|
|
|
break;
|
|
|
|
|
case 0: // drop
|
|
|
|
|
case 0: // _lit
|
|
|
|
|
state.push(state.beyondip());
|
|
|
|
|
break;
|
|
|
|
|
case 1: // drop
|
|
|
|
|
state.pop();
|
|
|
|
|
break;
|
|
|
|
|
case 1: // dup
|
|
|
|
|
case 2: // dup
|
|
|
|
|
state.push(state.top());
|
|
|
|
|
break;
|
|
|
|
|
case 2: // swap
|
|
|
|
|
case 3: // swap
|
|
|
|
|
std::swap(state.top(), state.pick(1));
|
|
|
|
|
break;
|
|
|
|
|
case 3: // pick
|
|
|
|
|
case 4: // pick
|
|
|
|
|
state.push(state.pick(state.pop()));
|
|
|
|
|
break;
|
|
|
|
|
case 4: // sys
|
|
|
|
|
case 5: // sys
|
|
|
|
|
user_sys(state);
|
|
|
|
|
break;
|
|
|
|
|
case 5: // add
|
|
|
|
|
case 6: // add
|
|
|
|
|
cell = state.pop();
|
|
|
|
|
state.top() += cell;
|
|
|
|
|
break;
|
|
|
|
|
case 6: // sub
|
|
|
|
|
case 7: // sub
|
|
|
|
|
cell = state.pop();
|
|
|
|
|
state.top() -= cell;
|
|
|
|
|
break;
|
|
|
|
|
case 7: // mul ( n n -- d )
|
|
|
|
|
case 8: // mul ( n n -- d )
|
|
|
|
|
cell = state.pop();
|
|
|
|
|
dcell = state.pop() * cell;
|
|
|
|
|
state.push(dcell);
|
|
|
|
|
state.push(dcell >> (sizeof(Cell) * 8));
|
|
|
|
|
break;
|
|
|
|
|
case 8: // div ( d n -- n )
|
|
|
|
|
case 9: // div ( d n -- n )
|
|
|
|
|
cell = state.pop();
|
|
|
|
|
dcell = state.pop() << (sizeof(Cell) * 8);
|
|
|
|
|
dcell |= state.pop();
|
|
|
|
|
state.push(dcell / cell);
|
|
|
|
|
break;
|
|
|
|
|
case 9: // mod ( d n -- n )
|
|
|
|
|
case 10: // mod ( d n -- n )
|
|
|
|
|
cell = state.pop();
|
|
|
|
|
dcell = state.pop() << (sizeof(Cell) * 8);
|
|
|
|
|
dcell |= state.pop();
|
|
|
|
|
state.push(dcell % cell);
|
|
|
|
|
break;
|
|
|
|
|
case 10: // peek
|
|
|
|
|
case 11: // peek
|
|
|
|
|
if (state.pop())
|
|
|
|
|
state.push(state.dict.read(state.pop()));
|
|
|
|
|
else
|
|
|
|
|
state.push(state.dict.readbyte(state.pop()));
|
|
|
|
|
break;
|
|
|
|
|
case 11: // poke
|
|
|
|
|
case 12: // poke
|
|
|
|
|
cell = state.pop();
|
|
|
|
|
if (auto addr = state.pop(); cell)
|
|
|
|
|
state.dict.write(addr, state.pop());
|
|
|
|
|
else
|
|
|
|
|
state.dict.writebyte(addr, state.pop());
|
|
|
|
|
break;
|
|
|
|
|
case 12: // pushr
|
|
|
|
|
case 13: // pushr
|
|
|
|
|
state.pushr(state.pop());
|
|
|
|
|
break;
|
|
|
|
|
case 13: // popr
|
|
|
|
|
case 14: // popr
|
|
|
|
|
state.push(state.popr());
|
|
|
|
|
break;
|
|
|
|
|
case 14: // equal
|
|
|
|
|
case 15: // equal
|
|
|
|
|
cell = state.pop();
|
|
|
|
|
state.top() = state.top() == cell;
|
|
|
|
|
break;
|
|
|
|
|
case 15: // lt
|
|
|
|
|
case 16: // lt
|
|
|
|
|
cell = state.pop();
|
|
|
|
|
state.top() = state.top() < cell;
|
|
|
|
|
break;
|
|
|
|
|
case 16: // allot
|
|
|
|
|
state.dict.allot(state.pop());
|
|
|
|
|
break;
|
|
|
|
|
case 17: // and
|
|
|
|
|
cell = state.pop();
|
|
|
|
|
state.top() &= cell;
|
|
|
|
@ -165,32 +165,22 @@ void CoreWords::run(unsigned int index, State& state)
|
|
|
|
|
state.dict.add(findi("exit"));
|
|
|
|
|
state.compiling(false);
|
|
|
|
|
break;
|
|
|
|
|
case 27: // here
|
|
|
|
|
state.push(state.dict.here);
|
|
|
|
|
break;
|
|
|
|
|
case 28: // _lit
|
|
|
|
|
state.push(state.beyondip());
|
|
|
|
|
break;
|
|
|
|
|
case 29: // literal
|
|
|
|
|
state.dict.add(findi("_lit"));
|
|
|
|
|
state.dict.add(state.pop());
|
|
|
|
|
break;
|
|
|
|
|
case 30: // _jmp
|
|
|
|
|
case 27: // _jmp
|
|
|
|
|
state.ip = state.beyondip() - sizeof(Cell);
|
|
|
|
|
break;
|
|
|
|
|
case 31: // _jmp0
|
|
|
|
|
case 28: // _jmp0
|
|
|
|
|
if (state.pop())
|
|
|
|
|
state.beyondip();
|
|
|
|
|
else
|
|
|
|
|
state.ip = state.beyondip() - sizeof(Cell);
|
|
|
|
|
break;
|
|
|
|
|
case 32: // depth
|
|
|
|
|
case 29: // depth
|
|
|
|
|
state.push(state.size());
|
|
|
|
|
break;
|
|
|
|
|
case 33: // _rdepth
|
|
|
|
|
case 30: // _rdepth
|
|
|
|
|
state.push(state.rsize());
|
|
|
|
|
break;
|
|
|
|
|
case 34: // key
|
|
|
|
|
case 31: // key
|
|
|
|
|
cell = state.dict.read(Dictionary::Input);
|
|
|
|
|
while (cell <= 0) {
|
|
|
|
|
state.input(state);
|
|
|
|
@ -219,7 +209,7 @@ int CoreWords::findi(const char *word)
|
|
|
|
|
++end;
|
|
|
|
|
|
|
|
|
|
if (size == end - i && !std::strncmp(word, wordsarr + i, size))
|
|
|
|
|
return wordsarr[end] == '\0' ? wordsi : (wordsi | Compiletime);
|
|
|
|
|
return wordsarr[end] == '\0' ? wordsi : (wordsi | Immediate);
|
|
|
|
|
|
|
|
|
|
++wordsi;
|
|
|
|
|
i = end + 1;
|
|
|
|
@ -239,7 +229,7 @@ int CoreWords::findi(State& state, Word word)
|
|
|
|
|
++end;
|
|
|
|
|
|
|
|
|
|
if (state.dict.equal(word, wordsarr + i, end - i))
|
|
|
|
|
return wordsarr[end] == '\0' ? wordsi : (wordsi | Compiletime);
|
|
|
|
|
return wordsarr[end] == '\0' ? wordsi : (wordsi | Immediate);
|
|
|
|
|
|
|
|
|
|
++wordsi;
|
|
|
|
|
i = end + 1;
|
|
|
|
|