]> code.bitgloo.com Git - bitgloo/alee-forth.git/commitdiff
fix indentation
authorClyne Sullivan <clyne@bitgloo.com>
Thu, 9 Feb 2023 19:12:26 +0000 (14:12 -0500)
committerClyne Sullivan <clyne@bitgloo.com>
Thu, 9 Feb 2023 19:12:26 +0000 (14:12 -0500)
alee.cpp
corewords.cpp
corewords.hpp
dictionary.hpp
executor.hpp
parser.hpp
state.hpp

index 265982cdf2c64e377ca681c5c91fdb4b594095af..b7858e67e1d0cd42b0f57d2c646b53ca25a60f87 100644 (file)
--- a/alee.cpp
+++ b/alee.cpp
@@ -35,7 +35,7 @@ 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(parser, state, file);
     }
 
     //std::cout << state.size() << ' ' << state.compiling << "> ";
@@ -49,7 +49,7 @@ int user_sys(State& state)
     switch (state.pop()) {
     case 0:
         std::cout << state.pop() << std::endl;
-       break;
+        break;
     }
 
     return 0;
index 6595e41adc9d941fae8e2472b2f51a5083359c37..8fbcfbd669377c3db82da003b4b22308fe89e5fa 100644 (file)
@@ -193,13 +193,13 @@ int CoreWords::op_shr(State& state) {
 }
 
 int CoreWords::op_comment(State& state) {
-       state.pass = Pass::Comment;
+    state.pass = Pass::Comment;
     return 0;
 }
 
 int CoreWords::op_colon(State& state) {
     state.pass = Pass::Colon;
-    state.pushr(state.dict.here); // this is for EXIT
+    state.pushr(state.dict.here);
     return 0;
 }
 
@@ -207,13 +207,13 @@ int CoreWords::op_semic(State& state) {
     if (!state.compiling) {
         state.ip = state.popr();
     } else {
-       auto begin = state.popr();
+        auto begin = state.popr();
 
-       state.dict.write(begin,
-           (state.dict.read(begin) & 0x1F) |
-           ((begin - state.dict.latest) << 6));
+        state.dict.write(begin,
+            (state.dict.read(begin) & 0x1F) |
+            ((begin - state.dict.latest) << 6));
 
-       state.dict.latest = begin;
+        state.dict.latest = begin;
         state.compiling = false;
     }
 
@@ -221,7 +221,7 @@ int CoreWords::op_semic(State& state) {
 }
 
 int CoreWords::op_here(State& state) {
-       state.push(state.dict.here);
+    state.push(state.dict.here);
     return 0;
 }
 
@@ -266,7 +266,7 @@ int CoreWords::findi(std::string_view str)
 
     std::string_view words (wordsarr, sizeof(wordsarr));
 
-       for (i = 0; i < words.size();) {
+    for (i = 0; i < words.size();) {
         const auto end = words.find('\0', i);
 
         if (words.compare(i, end - i, str) == 0)
index 08f172b946132a7eeb78c474c75713050128e040..ff9d84dd2200c74dc7a41852227ac4a5f8ce6452 100644 (file)
@@ -41,11 +41,11 @@ public:
 private:
     constexpr static char wordsarr[] =
         "drop\0dup\0swap\0pick\0sys\0"
-       "+\0-\0*\0/\0%\0"
-       "@\0!\0rot\0>r\0r>\0"
-       "=\0<\0allot\0&\0|\0"
-       "^\0<<\0>>\0(\0:\0"
-       ";\0here\0exit\0imm\0const\0";
+        "+\0-\0*\0/\0%\0"
+        "@\0!\0rot\0>r\0r>\0"
+        "=\0<\0allot\0&\0|\0"
+        "^\0<<\0>>\0(\0:\0"
+        ";\0here\0exit\0imm\0const\0";
     // lit, jmp, jmp0, ', lits
 
     static Func get(int index);
index c527603776700834331078a565382475b8a5c950..880b8a50c7eff64429691910f15c7136117e94a6 100644 (file)
@@ -33,58 +33,57 @@ struct Dictionary
     virtual int write(Addr, Cell) = 0;
 
     Addr allot(Cell amount) {
-       Addr old = here;
-       here += amount;
-       return old;
+        Addr old = here;
+        here += amount;
+        return old;
     }
 
     void add(Cell value) {
-       write(here++, value);
+        write(here++, value);
     }
 
     void addDefinition(std::string_view str) {
         add(str.size());
-       for (char c : str)
-           add(c);
+        for (char c : str)
+            add(c);
 
-       if (here & 1)
-           allot(1);
+        if (here & 1)
+            allot(1);
     }
 
     bool issame(Addr addr, std::string_view str, std::size_t n) {
-       if (str.size() != n)
-           return false;
+        if (str.size() != n)
+            return false;
 
         for (char c : str) {
-           if (read(addr++) != c)
-               return false;
-       }
-           
-       return true;
+            if (read(addr++) != c)
+                return false;
+        }
+    
+        return true;
     }
 
     Addr find(std::string_view str) {
         if (latest == 0)
-           return 0;
+            return 0;
 
-       auto lt = latest;
-       do {
+        auto lt = latest;
+        do {
             const auto l = read(lt);
-           const auto len = l & 0x1F;
+            const auto len = l & 0x1F;
 
-           if (issame(lt + 1, str, len)) {
-               return lt;
-           } else {
-               lt -= l >> 6;
-           }
-       } while (lt);
+            if (issame(lt + 1, str, len))
+                return lt;
+            else
+                lt -= l >> 6;
+        } while (lt);
 
-       return 0;
+        return 0;
     }
 
     Addr getexec(Addr addr) {
-       const auto len = read(addr) & 0x1F;
-       return ((addr + 1 + len) + 1) & ~1;
+        const auto len = read(addr) & 0x1F;
+        return ((addr + 1 + len) + 1) & ~1;
     }
 };
 
index 485e82ab02f48dbc079caaaa3160203d6b625103..62afe5fc8afa8d7eb8b33c396a3ec664433985ee 100644 (file)
 
 #include "corewords.hpp"
 
-//#include <iostream>
-
 class Executor
 {
 public:
     static int fullexec(State& state, Addr addr) {
         state.pushr(0);
-       state.ip = addr - 1;
-
-       do {
-           ++state.ip;
-           //std::cout << "-- " << state.rsize() << "e " << state.ip << std::endl;
-           CoreWords::run(state.dict.read(state.ip), state);
-       } while (state.ip);
-
-       return 0;
+        state.ip = addr - 1;
+
+        do {
+            ++state.ip;
+            CoreWords::run(state.dict.read(state.ip), state);
+        } while (state.ip);
+        
+        return 0;
     }
 };
 
index 588315d917d4fce2d80af90a950fa7f64ce85082..c136990ee7a5ea66e0da1b50c9601fb01a3757c0 100644 (file)
@@ -26,83 +26,84 @@ class Parser
 public:
     ParseStatus parse(State& state, std::string_view& str) {
         const auto end = str.find_first_of(" \t\n\r");
-       const auto sub = str.substr(0, end);
+        const auto sub = str.substr(0, end);
         if (sub.empty())
             return ParseStatus::Finished;
 
-       if (state.pass != Pass::None) {
-           switch (state.pass) {
-           case Pass::Comment:
+        if (state.pass != Pass::None) {
+            switch (state.pass) {
+            case Pass::Comment:
                 if (str.front() == ')')
-                   state.pass = Pass::None;
+                    state.pass = Pass::None;
 
-               str = str.substr(1);
-               break;
-           case Pass::Colon:
-               state.pass = Pass::None;
-                state.compiling = true;
-               state.dict.addDefinition(sub);
-               break;
-           case Pass::Constant:
-               state.pass = Pass::None;
+                str = str.substr(1);
+                break;
+            case Pass::Colon:
+                state.pass = Pass::None;
+                    state.compiling = true;
+                state.dict.addDefinition(sub);
+                break;
+            case Pass::Constant:
+                state.pass = Pass::None;
                 state.compiling = true;
-               state.dict.addDefinition(sub);
-               state.dict.add(CoreWords::HiddenWordLiteral);
-               state.dict.add(state.pop());
+                state.dict.addDefinition(sub);
+                state.dict.add(CoreWords::HiddenWordLiteral);
+                state.dict.add(state.pop());
                 state.dict.add(CoreWords::findi(";"));
-               CoreWords::run(CoreWords::findi(";"), state);
+                CoreWords::run(CoreWords::findi(";"), state);
                 break;
-           default:
-               break;
-           }
-       } else {
-           if (auto i = CoreWords::findi(sub); i >= 0) {
-               if (state.compiling)
+            default:
+                break;
+            }
+        } else {
+            if (auto i = CoreWords::findi(sub); i >= 0) {
+                if (state.compiling)
                     state.dict.add(i);
-               if (!state.compiling || sub.front() == ';')
-                   CoreWords::run(i, state);
-           } else if (auto j = state.dict.find(sub); j > 0) {
-               auto e = state.dict.getexec(j);
-               if (state.compiling) {
-                   if (state.dict.read(j) & CoreWords::Immediate) {
-                       state.compiling = false;
-                       Executor::fullexec(state, e);
-                       state.compiling = true;
-                   } else {
-                       state.dict.add(CoreWords::HiddenWordJump);
-                       state.dict.add(e);
-                   }
-               } else {
-                   Executor::fullexec(state, e);
-               }
-           } else {
-               char *p;
-               const auto l = static_cast<Cell>(std::strtol(sub.data(), &p, 10));
+                if (!state.compiling || sub.front() == ';')
+                    CoreWords::run(i, state);
+            } else if (auto j = state.dict.find(sub); j > 0) {
+                auto e = state.dict.getexec(j);
+
+                if (state.compiling) {
+                    if (state.dict.read(j) & CoreWords::Immediate) {
+                        state.compiling = false;
+                        Executor::fullexec(state, e);
+                        state.compiling = true;
+                    } else {
+                        state.dict.add(CoreWords::HiddenWordJump);
+                        state.dict.add(e);
+                    }
+                } else {
+                    Executor::fullexec(state, e);
+                }
+            } else {
+                char *p;
+                const auto l = static_cast<Cell>(std::strtol(sub.data(), &p, 10));
 
-               if (p != sub.data()) {
-                   if (state.compiling) {
-                       state.dict.add(CoreWords::HiddenWordLiteral);
-                       state.dict.add(l);
-                   } else {
-                       state.push(l);
-                   }
-               } else {
-                   return ParseStatus::Error;
-               }
-           }
+                if (p != sub.data()) {
+                    if (state.compiling) {
+                        state.dict.add(CoreWords::HiddenWordLiteral);
+                        state.dict.add(l);
+                    } else {
+                        state.push(l);
+                    }
+                } else {
+                    return ParseStatus::Error;
+                }
+            }
 
-           if (end == std::string_view::npos)
+            if (end == std::string_view::npos)
                 return ParseStatus::Finished;
         }
 
-       const auto next = str.find_first_not_of(" \t\n\r", end);
+        const auto next = str.find_first_not_of(" \t\n\r", end);
 
-       if (next == std::string_view::npos) {
+        if (next == std::string_view::npos) {
             return ParseStatus::Finished;
-       } else {
-           str = str.substr(next);
-           return ParseStatus::Continue;
-       }
+        } else {
+            str = str.substr(next);
+            return ParseStatus::Continue;
+        }
     }
 };
 
index 03d00844d7113aaad44b04ff980729e31138f231..e1788773b8377a0b93a144cddacd08551a1ce9e6 100644 (file)
--- a/state.hpp
+++ b/state.hpp
@@ -44,51 +44,51 @@ public:
     constexpr State(Dictionary& d): dict(d) {}
 
     Cell beyondip() const {
-       return dict.read(ip + 1);
+        return dict.read(ip + 1);
     }
 
     void pushr(Cell value) {
-       if (rsize() == ReturnStackSize)
+        if (rsize() == ReturnStackSize)
             throw;
         *++rsp = value;
     }
 
     Cell popr() {
-       if (rsize() == 0)
+        if (rsize() == 0)
             throw;
-       return *rsp--;
+        return *rsp--;
     }
 
     void push(Cell value) {
-       if (size() == DataStackSize)
+        if (size() == DataStackSize)
             throw;
         *++dsp = value;
     }
 
     Cell pop() {
-       if (size() == 0)
+        if (size() == 0)
             throw;
-       return *dsp--;
+        return *dsp--;
     }
 
     Cell& top() {
-       if (size() == 0)
+        if (size() == 0)
             throw;
-       return *dsp;
+        return *dsp;
     }
 
     Cell& pick(std::size_t i) {
-       if (i >= size())
-           throw;
-       return *(dsp - i);
+        if (i >= size())
+            throw;
+        return *(dsp - i);
     }
 
     std::size_t size() const noexcept {
-       return std::distance(dstack, static_cast<const Cell *>(dsp)) + 1;
+        return std::distance(dstack, static_cast<const Cell *>(dsp)) + 1;
     }
 
     std::size_t rsize() const noexcept {
-       return std::distance(rstack, static_cast<const Cell *>(rsp)) + 1;
+        return std::distance(rstack, static_cast<const Cell *>(rsp)) + 1;
     }
 };