From 0810456e9c5c19a47511a682eeabc71008632a2c Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Thu, 9 Nov 2023 06:39:02 -0500 Subject: MaxDistance constant; some .cpp comments --- libalee/parser.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'libalee/parser.cpp') diff --git a/libalee/parser.cpp b/libalee/parser.cpp index 328198a..3699d5f 100644 --- a/libalee/parser.cpp +++ b/libalee/parser.cpp @@ -29,14 +29,17 @@ Error Parser::parse(State& state, const char *str) { auto addr = Dictionary::Input; + // Set source and input length const auto len = static_cast(std::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'); @@ -56,8 +59,10 @@ Error Parser::parseSource(State& state) 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); @@ -121,6 +126,9 @@ void Parser::processLiteral(State& state, Cell value) if (state.compiling()) { 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; -- cgit v1.2.3