diff --git a/alee-msp430.cpp b/alee-msp430.cpp index e9fe19d..4116118 100644 --- a/alee-msp430.cpp +++ b/alee-msp430.cpp @@ -52,7 +52,6 @@ int main() static SplitMemDict dict (alee_dat); State state (dict, readchar); - Parser parser; serputs("alee forth\n\r"); @@ -67,7 +66,7 @@ int main() serputs("\n\r"); - if (auto r = parser.parse(state, strbuf); r == 0) { + if (auto r = Parser::parse(state, strbuf); r == 0) { serputs(state.compiling() ? " compiled" : " ok"); } else { switch (r) { @@ -148,6 +147,13 @@ void user_sys(State& state) case 1: serput(state.pop()); break; + case 2: + { auto addr = state.pop(); + *((uint8_t *)addr) = state.pop(); } + break; + case 3: + state.push(*((uint8_t *)state.pop())); + break; default: break; } diff --git a/alee-standalone.cpp b/alee-standalone.cpp index 1602641..3c4eb3d 100644 --- a/alee-standalone.cpp +++ b/alee-standalone.cpp @@ -29,10 +29,8 @@ static bool okay = false; static void readchar(State& state); -static void parseLine(Parser&, State&, const std::string&); -static void parseFile(Parser&, State&, std::istream&); - -static Parser parser; +static void parseLine(State&, const std::string&); +static void parseFile(State&, std::istream&); int main(int argc, char *argv[]) { @@ -42,11 +40,11 @@ int main(int argc, char *argv[]) std::vector args (argv + 1, argv + argc); for (const auto& a : args) { std::ifstream file (a); - parseFile(parser, state, file); + parseFile(state, file); } okay = true; - parseFile(parser, state, std::cin); + parseFile(state, std::cin); return 0; } @@ -115,7 +113,7 @@ void user_sys(State& state) std::jmp_buf oldjb; memcpy(oldjb, state.jmpbuf, sizeof(std::jmp_buf)); state.ip = 0; - parser.parseSource(state); + Parser::parseSource(state); memcpy(state.jmpbuf, oldjb, sizeof(std::jmp_buf)); state.ip = oldip; } @@ -123,9 +121,9 @@ void user_sys(State& state) } } -void parseLine(Parser& parser, State& state, const std::string& line) +void parseLine(State& state, const std::string& line) { - if (auto r = parser.parse(state, line.c_str()); r == 0) { + if (auto r = Parser::parse(state, line.c_str()); r == 0) { if (okay) std::cout << (state.compiling() ? "compiled" : "ok") << std::endl; } else { @@ -161,7 +159,7 @@ void parseLine(Parser& parser, State& state, const std::string& line) } } -void parseFile(Parser& parser, State& state, std::istream& file) +void parseFile(State& state, std::istream& file) { while (file.good()) { std::string line; @@ -170,7 +168,7 @@ void parseFile(Parser& parser, State& state, std::istream& file) if (line == "bye") exit(0); - parseLine(parser, state, line); + parseLine(state, line); } } diff --git a/alee.cpp b/alee.cpp index 77c2995..e222363 100644 --- a/alee.cpp +++ b/alee.cpp @@ -27,10 +27,8 @@ static bool okay = false; static void readchar(State& state); -static void parseLine(Parser&, State&, const std::string&); -static void parseFile(Parser&, State&, std::istream&); - -static Parser parser; +static void parseLine(State&, const std::string&); +static void parseFile(State&, std::istream&); int main(int argc, char *argv[]) { @@ -43,12 +41,12 @@ int main(int argc, char *argv[]) std::vector args (argv + 1, argv + argc); for (const auto& a : args) { std::ifstream file (a); - parseFile(parser, state, file); + parseFile(state, file); } } okay = true; - parseFile(parser, state, std::cin); + parseFile(state, std::cin); return 0; } @@ -117,7 +115,7 @@ void user_sys(State& state) std::jmp_buf oldjb; memcpy(oldjb, state.jmpbuf, sizeof(std::jmp_buf)); state.ip = 0; - parser.parseSource(state); + Parser::parseSource(state); memcpy(state.jmpbuf, oldjb, sizeof(std::jmp_buf)); state.ip = oldip; } @@ -125,9 +123,9 @@ void user_sys(State& state) } } -void parseLine(Parser& parser, State& state, const std::string& line) +void parseLine(State& state, const std::string& line) { - if (auto r = parser.parse(state, line.c_str()); r == 0) { + if (auto r = Parser::parse(state, line.c_str()); r == 0) { if (okay) std::cout << (state.compiling() ? "compiled" : "ok") << std::endl; } else { @@ -163,7 +161,7 @@ void parseLine(Parser& parser, State& state, const std::string& line) } } -void parseFile(Parser& parser, State& state, std::istream& file) +void parseFile(State& state, std::istream& file) { while (file.good()) { std::string line; @@ -172,7 +170,7 @@ void parseFile(Parser& parser, State& state, std::istream& file) if (line == "bye") exit(0); - parseLine(parser, state, line); + parseLine(state, line); } } diff --git a/libalee/parser.hpp b/libalee/parser.hpp index 4b14d64..f211781 100644 --- a/libalee/parser.hpp +++ b/libalee/parser.hpp @@ -28,12 +28,12 @@ class Parser public: constexpr static int UnknownWord = -1; - int parse(State&, const char *); - int parseSource(State&); + static int parse(State&, const char *); + static int parseSource(State&); private: - int parseWord(State&, Word); - int parseNumber(State&, Word); + static int parseWord(State&, Word); + static int parseNumber(State&, Word); }; #endif // ALEEFORTH_PARSER_HPP