|
|
@ -52,47 +52,37 @@ ParseStatus Parser::parseSource(State& state)
|
|
|
|
|
|
|
|
|
|
|
|
ParseStatus Parser::parseWord(State& state, Word word)
|
|
|
|
ParseStatus Parser::parseWord(State& state, Word word)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// TODO unify core-word and defined-word parsing/execution.
|
|
|
|
int ins, imm;
|
|
|
|
|
|
|
|
|
|
|
|
if (auto i = CoreWords::findi(state, word); i >= 0) {
|
|
|
|
ins = CoreWords::findi(state, word);
|
|
|
|
auto p = state.dict.read(Dictionary::Postpone);
|
|
|
|
if (ins < 0) {
|
|
|
|
auto imm = (i & CoreWords::Compiletime);
|
|
|
|
ins = state.dict.find(word);
|
|
|
|
|
|
|
|
|
|
|
|
if (state.compiling() || p) {
|
|
|
|
if (ins <= 0) {
|
|
|
|
if (p || !imm) {
|
|
|
|
return parseNumber(state, word);
|
|
|
|
state.dict.add(i & ~CoreWords::Compiletime);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
imm = state.dict.read(ins) & CoreWords::Immediate;
|
|
|
|
if (p)
|
|
|
|
ins = state.dict.getexec(ins);
|
|
|
|
state.dict.write(Dictionary::Postpone, 0);
|
|
|
|
|
|
|
|
} else if (imm) {
|
|
|
|
|
|
|
|
CoreWords::run(i & ~CoreWords::Compiletime, state);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (state.dict.equal(word, ":"))
|
|
|
|
imm = ins & CoreWords::Compiletime;
|
|
|
|
state.compiling(true);
|
|
|
|
ins &= ~CoreWords::Compiletime;
|
|
|
|
|
|
|
|
|
|
|
|
CoreWords::run(i & ~CoreWords::Compiletime, state);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (auto j = state.dict.find(word); j > 0) {
|
|
|
|
|
|
|
|
auto e = state.dict.getexec(j);
|
|
|
|
|
|
|
|
auto p = state.dict.read(Dictionary::Postpone);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (state.compiling() || p) {
|
|
|
|
|
|
|
|
auto imm = state.dict.read(j) & CoreWords::Immediate;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (p || !imm) {
|
|
|
|
if (state.dict.read(Dictionary::Postpone)) {
|
|
|
|
state.dict.add(CoreWords::HiddenWordJump);
|
|
|
|
state.dict.add(ins);
|
|
|
|
state.dict.add(e);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (p)
|
|
|
|
|
|
|
|
state.dict.write(Dictionary::Postpone, 0);
|
|
|
|
state.dict.write(Dictionary::Postpone, 0);
|
|
|
|
} else if (imm) {
|
|
|
|
} else if (state.compiling() && !imm) {
|
|
|
|
state.execute(e);
|
|
|
|
state.dict.add(ins);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
state.execute(e);
|
|
|
|
state.execute(ins);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
|
return ParseStatus::Finished;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ParseStatus Parser::parseNumber(State& state, Word word)
|
|
|
|
|
|
|
|
{
|
|
|
|
char buf[word.size() + 1];
|
|
|
|
char buf[word.size() + 1];
|
|
|
|
for (unsigned i = 0; i < word.size(); ++i)
|
|
|
|
for (unsigned i = 0; i < word.size(); ++i)
|
|
|
|
buf[i] = state.dict.readbyte(word.start + i);
|
|
|
|
buf[i] = state.dict.readbyte(word.start + i);
|
|
|
@ -109,12 +99,11 @@ ParseStatus Parser::parseWord(State& state, Word word)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
state.push(l);
|
|
|
|
state.push(l);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ParseStatus::Finished;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
std::cout << "word not found: " << buf << std::endl;
|
|
|
|
std::cout << "word not found: " << buf << std::endl;
|
|
|
|
return ParseStatus::NotAWord;
|
|
|
|
return ParseStatus::NotAWord;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return ParseStatus::Finished;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|