|
|
@ -19,7 +19,7 @@
|
|
|
|
#include "corewords.hpp"
|
|
|
|
#include "corewords.hpp"
|
|
|
|
#include "parser.hpp"
|
|
|
|
#include "parser.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
#include <charconv>
|
|
|
|
#include <cctype>
|
|
|
|
#include <cstring>
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
|
|
|
|
int Parser::parse(State& state, const char *str)
|
|
|
|
int Parser::parse(State& state, const char *str)
|
|
|
@ -79,18 +79,35 @@ int Parser::parseWord(State& state, Word word)
|
|
|
|
|
|
|
|
|
|
|
|
int Parser::parseNumber(State& state, Word word)
|
|
|
|
int Parser::parseNumber(State& state, Word word)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
char buf[MaxCellNumberChars + 1];
|
|
|
|
const auto base = state.dict.read(Dictionary::Base);
|
|
|
|
unsigned i;
|
|
|
|
DoubleCell result = 0;
|
|
|
|
for (i = 0; i < std::min(MaxCellNumberChars, word.size()); ++i)
|
|
|
|
auto i = word.start;
|
|
|
|
buf[i] = state.dict.readbyte(word.start + i);
|
|
|
|
bool inv;
|
|
|
|
buf[i] = '\0';
|
|
|
|
char c;
|
|
|
|
|
|
|
|
|
|
|
|
auto base = state.dict.read(0);
|
|
|
|
c = state.dict.readbyte(i);
|
|
|
|
DoubleCell dl;
|
|
|
|
if (inv = c == '-'; inv)
|
|
|
|
auto [ptr, ec] = std::from_chars(buf, buf + i, dl, base);
|
|
|
|
c = state.dict.readbyte(++i);
|
|
|
|
Cell l = static_cast<Cell>(dl);
|
|
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (ec == std::errc() && ptr == buf + i) {
|
|
|
|
if (isdigit(c)) {
|
|
|
|
|
|
|
|
result *= base;
|
|
|
|
|
|
|
|
result += c - '0';
|
|
|
|
|
|
|
|
} else if (isalpha(c) && base > 10) {
|
|
|
|
|
|
|
|
result *= base;
|
|
|
|
|
|
|
|
result += 10 + (c > 'a' ? c - 'a' : c - 'A');
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return UnknownWord;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (++i < word.end)
|
|
|
|
|
|
|
|
c = state.dict.readbyte(i);
|
|
|
|
|
|
|
|
} while (i < word.end);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (inv)
|
|
|
|
|
|
|
|
result *= -1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Cell value = static_cast<Cell>(result);
|
|
|
|
if (state.compiling()) {
|
|
|
|
if (state.compiling()) {
|
|
|
|
auto ins = CoreWords::findi("_lit");
|
|
|
|
auto ins = CoreWords::findi("_lit");
|
|
|
|
|
|
|
|
|
|
|
@ -98,15 +115,12 @@ int Parser::parseNumber(State& state, Word word)
|
|
|
|
// state.dict.add(ins | ((l + 1) << 8));
|
|
|
|
// state.dict.add(ins | ((l + 1) << 8));
|
|
|
|
//} else {
|
|
|
|
//} else {
|
|
|
|
state.dict.add(ins);
|
|
|
|
state.dict.add(ins);
|
|
|
|
state.dict.add(l);
|
|
|
|
state.dict.add(value);
|
|
|
|
//}
|
|
|
|
//}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
state.push(l);
|
|
|
|
state.push(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return UnknownWord;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|