try dict save/load; prevent execute recursion

llvm
Clyne 2 years ago
parent 9f0127c3c8
commit 2aaec63b91

@ -65,6 +65,27 @@ int main(int argc, char *argv[])
return 0; 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) void user_sys(State& state)
{ {
switch (state.pop()) { switch (state.pop()) {
@ -74,6 +95,12 @@ void user_sys(State& state)
case 1: case 1:
std::cout << static_cast<char>(state.pop()); std::cout << static_cast<char>(state.pop());
break; break;
case 2:
save(state);
break;
case 3:
load(state);
break;
} }
} }

@ -146,7 +146,7 @@ void CoreWords::run(unsigned int index, State& state)
tick(getword()); tick(getword());
break; break;
case 24: // execute case 24: // execute
state.execute(state.pop()); run(state.pop(), state);
break; break;
case 25: // exit case 25: // exit
state.ip = state.popr(); state.ip = state.popr();

Loading…
Cancel
Save