From 2aaec63b91a822d4d3d538e6c058deca0507b605 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Thu, 23 Feb 2023 18:28:38 -0500 Subject: [PATCH] try dict save/load; prevent execute recursion --- alee.cpp | 27 +++++++++++++++++++++++++++ corewords.cpp | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) 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(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();