diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2023-02-23 18:28:38 -0500 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2023-02-23 18:28:38 -0500 |
commit | 2aaec63b91a822d4d3d538e6c058deca0507b605 (patch) | |
tree | 0942b562e3fab636fa21ab28ee787887c98ed6a7 | |
parent | 9f0127c3c82203d308e4230a4b32304e155d05c7 (diff) |
try dict save/load; prevent execute recursion
-rw-r--r-- | alee.cpp | 27 | ||||
-rw-r--r-- | corewords.cpp | 2 |
2 files changed, 28 insertions, 1 deletions
@@ -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(); |