diff options
Diffstat (limited to 'libalee/parser.cpp')
-rw-r--r-- | libalee/parser.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/libalee/parser.cpp b/libalee/parser.cpp index b3e8211..11aba38 100644 --- a/libalee/parser.cpp +++ b/libalee/parser.cpp @@ -25,14 +25,17 @@ Error Parser::parse(State& state, const char *str) { auto addr = Dictionary::Input; + // Set source and input length const auto len = static_cast<Cell>(strlen(str)); state.dict.write(addr, 0); state.dict.write(Dictionary::SourceLen, len); + // Fill input buffer with string contents addr += sizeof(Cell); while (*str) state.dict.writebyte(addr++, *str++); + // Zero the remaining input buffer while (addr < Dictionary::Input + Dictionary::InputCells) state.dict.writebyte(addr++, '\0'); @@ -54,8 +57,10 @@ LIBALEE_SECTION Error Parser::parseWord(State& state, Word word) { bool imm; - Addr ins = state.dict.find(word); + Addr ins; + // Search order: dictionary, core word-set, number, custom parse. + ins = state.dict.find(word); if (ins == 0) { auto cw = CoreWords::findi(state, word); @@ -67,7 +72,7 @@ Error Parser::parseWord(State& state, Word word) return r; } else { ins = cw; - imm = ins == CoreWords::Semicolon; + imm = ins == CoreWords::token(";"); } } else { imm = state.dict.read(ins) & Dictionary::Immediate; @@ -119,8 +124,11 @@ LIBALEE_SECTION void Parser::processLiteral(State& state, Cell value) { if (state.compiling()) { - constexpr auto ins = CoreWords::findi("_lit"); + constexpr auto ins = CoreWords::token("_lit"); + // Literal compression: opcodes between WordCount and Begin are unused, + // so we assign literals to them to save space. Opcode "WordCount" + // pushes zero to the stack, "WordCount + 1" pushes a one, etc. const Cell maxlit = Dictionary::Begin - CoreWords::WordCount; if (value >= 0 && value < maxlit) value += CoreWords::WordCount; |