]> code.bitgloo.com Git - bitgloo/alee-forth.git/commitdiff
make parser static; tested msp430 build
authorClyne Sullivan <clyne@bitgloo.com>
Fri, 10 Mar 2023 12:14:09 +0000 (07:14 -0500)
committerClyne Sullivan <clyne@bitgloo.com>
Fri, 10 Mar 2023 12:14:09 +0000 (07:14 -0500)
alee-msp430.cpp
alee-standalone.cpp
alee.cpp
libalee/parser.hpp

index e9fe19d5a8bfb9e7a8d106a2d962b575774803bb..4116118ff7c07079f267ca03dd97f8627bbf4061 100644 (file)
@@ -52,7 +52,6 @@ int main()
 
     static SplitMemDict<alee_dat_len> 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;
     }
index 16026412a5d7b28e6dea87b34fce0b0e553db96d..3c4eb3de50f832e5a6da01a3506b2689cbc9f17a 100644 (file)
 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);
     }
 }
 
index 77c2995b0a4b883921d014b7fb44c79ad2c35fa5..e222363d052ff7c6264d1e9be20fe43f02d6ffca 100644 (file)
--- a/alee.cpp
+++ b/alee.cpp
 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);
     }
 }
 
index 4b14d6429b4e79dc71909a8cccec5b11a6dd793d..f2117815eac94ea651961bd55f98683921b1439f 100644 (file)
@@ -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