aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2023-02-23 18:28:38 -0500
committerClyne Sullivan <clyne@bitgloo.com>2023-02-23 18:28:38 -0500
commit2aaec63b91a822d4d3d538e6c058deca0507b605 (patch)
tree0942b562e3fab636fa21ab28ee787887c98ed6a7
parent9f0127c3c82203d308e4230a4b32304e155d05c7 (diff)
try dict save/load; prevent execute recursion
-rw-r--r--alee.cpp27
-rw-r--r--corewords.cpp2
2 files changed, 28 insertions, 1 deletions
diff --git a/alee.cpp b/alee.cpp
index d8a0cc8..6c2c135 100644
--- 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;
}
}
diff --git a/corewords.cpp b/corewords.cpp
index 64708e9..2d98117 100644
--- a/corewords.cpp
+++ b/corewords.cpp
@@ -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();