]> code.bitgloo.com Git - bitgloo/alee-forth.git/commitdiff
try dict save/load; prevent execute recursion
authorClyne Sullivan <clyne@bitgloo.com>
Thu, 23 Feb 2023 23:28:38 +0000 (18:28 -0500)
committerClyne Sullivan <clyne@bitgloo.com>
Thu, 23 Feb 2023 23:28:38 +0000 (18:28 -0500)
alee.cpp
corewords.cpp

index d8a0cc89c87fb47a8265372e016a651f7b3d92da..6c2c1357a10f1326383865347b687fce04e547a9 100644 (file)
--- a/alee.cpp
+++ b/alee.cpp
@@ -65,6 +65,27 @@ int main(int argc, char *argv[])
     return 0;
 }
 
+static void save(State& state)
+{
+    std::ofstream file ("alee.dat", std::ios::binary);
+
+    if (file.good()) {
+        for (Addr i = 0; i < state.dict.here; ++i)
+            file.put(state.dict.readbyte(i));
+    }
+}
+
+static void load(State& state)
+{
+    std::ifstream file ("alee.dat", std::ios::binary);
+
+    Addr i = 0;
+    while (file.good())
+        state.dict.writebyte(i++, file.get());
+
+    state.dict.here = i - 1;
+}
+
 void user_sys(State& state)
 {
     switch (state.pop()) {
@@ -74,6 +95,12 @@ void user_sys(State& state)
     case 1:
         std::cout << static_cast<char>(state.pop());
         break;
+    case 2:
+        save(state);
+        break;
+    case 3:
+        load(state);
+        break;
     }
 }
 
index 64708e9a250bf4c71f9696d9ab834d4e07d240a9..2d981170dd6dac966e33ca4104c83584e9675b68 100644 (file)
@@ -146,7 +146,7 @@ void CoreWords::run(unsigned int index, State& state)
         tick(getword());
         break;
     case 24: // execute
-        state.execute(state.pop());
+        run(state.pop(), state);
         break;
     case 25: // exit
         state.ip = state.popr();