From 2ece0e4993c838f620e5c19dfa04a86d9d35df49 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Thu, 2 Mar 2023 18:01:34 -0500 Subject: major compliance refactor; undo packed literals for now --- alee.cpp | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) (limited to 'alee.cpp') diff --git a/alee.cpp b/alee.cpp index c5b0a95..d3e4c4c 100644 --- a/alee.cpp +++ b/alee.cpp @@ -19,6 +19,7 @@ #include "alee.hpp" #include "memdict.hpp" +#include #include #include #include @@ -35,11 +36,7 @@ int main(int argc, char *argv[]) State state (dict, readchar); Parser parser; - dict.write(Dictionary::Base, 10); - dict.write(Dictionary::Here, Dictionary::Begin); - dict.write(Dictionary::Latest, Dictionary::Begin); - dict.write(Dictionary::Compiling, 0); - dict.write(Dictionary::Postpone, 0); + dict.initialize(); std::vector args (argv + 1, argv + argc); for (const auto& a : args) { @@ -63,6 +60,8 @@ static void readchar(State& state) state.dict.writebyte(addr, state.dict.readbyte(addr + 1)); auto c = std::cin.get(); + if (isupper(c)) + c += 32; state.dict.writebyte(addr, c ? c : ' '); state.dict.write(Dictionary::Input, len + 1); } @@ -88,19 +87,31 @@ static void load(State& state) void user_sys(State& state) { + char buf[32] = {0}; + switch (state.pop()) { - case 0: - std::cout << state.pop() << ' '; + case 0: // . + std::to_chars(buf, buf + sizeof(buf), state.pop(), + state.dict.read(Dictionary::Base)); + std::cout << buf << ' '; break; - case 1: + case 1: // emit std::cout << static_cast(state.pop()); break; - case 2: + case 2: // save save(state); break; - case 3: + case 3: // load load(state); break; + case 4: // u. + { + Addr ucell = static_cast(state.pop()); + std::to_chars(buf, buf + sizeof(buf), ucell, + state.dict.read(Dictionary::Base)); + std::cout << buf << ' '; + } + break; } } @@ -132,6 +143,12 @@ void parseLine(Parser& parser, State& state, const std::string& line) std::cout << "error: " << r << std::endl; break; } + + while (state.size()) + state.pop(); + while (state.rsize()) + state.popr(); + state.dict.write(Dictionary::Compiling, 0); } } @@ -140,6 +157,7 @@ void parseFile(Parser& parser, State& state, std::istream& file) while (file.good()) { std::string line; std::getline(file, line); + if (line == "bye") exit(0); -- cgit v1.2.3