aboutsummaryrefslogtreecommitdiffstats
path: root/alee-standalone.cpp
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2023-03-11 07:36:11 -0500
committerClyne Sullivan <clyne@bitgloo.com>2023-03-11 07:36:11 -0500
commitbc3e952b487365fdf5e60e9fcfa0841c23972e30 (patch)
treecc53facc2a62db4dc93a25c772f521786305ead8 /alee-standalone.cpp
parentf8270776e79f4d2edb7c2a19c1ecd3bf3b2bf153 (diff)
common error enum; eval to _ev
Diffstat (limited to 'alee-standalone.cpp')
-rw-r--r--alee-standalone.cpp39
1 files changed, 12 insertions, 27 deletions
diff --git a/alee-standalone.cpp b/alee-standalone.cpp
index 3c4eb3d..2c971ce 100644
--- a/alee-standalone.cpp
+++ b/alee-standalone.cpp
@@ -79,7 +79,6 @@ static void load(State& state)
state.dict.writebyte(i++, file.get());
}
-#include <cstring>
void user_sys(State& state)
{
char buf[32] = {0};
@@ -107,55 +106,41 @@ void user_sys(State& state)
std::cout << buf << ' ';
}
break;
- case 5: // eval
- {
- auto oldip = state.ip;
- std::jmp_buf oldjb;
- memcpy(oldjb, state.jmpbuf, sizeof(std::jmp_buf));
- state.ip = 0;
- Parser::parseSource(state);
- memcpy(state.jmpbuf, oldjb, sizeof(std::jmp_buf));
- state.ip = oldip;
- }
+ default:
break;
}
}
void parseLine(State& state, const std::string& line)
{
- if (auto r = Parser::parse(state, line.c_str()); r == 0) {
+ if (auto r = Parser::parse(state, line.c_str()); r == Error::none) {
if (okay)
- std::cout << (state.compiling() ? "compiled" : "ok") << std::endl;
+ std::cout << (state.compiling() ? " compiled" : " ok") << std::endl;
} else {
switch (r) {
- case Parser::UnknownWord:
+ case Error::noword:
std::cout << "word not found in: " << line << std::endl;
break;
- case static_cast<int>(State::Error::push):
+ case Error::push:
std::cout << "stack overflow" << std::endl;
break;
- case static_cast<int>(State::Error::pushr):
+ case Error::pushr:
std::cout << "return stack overflow" << std::endl;
break;
- case static_cast<int>(State::Error::popr):
+ case Error::popr:
std::cout << "return stack underflow" << std::endl;
break;
- case static_cast<int>(State::Error::pop):
- case static_cast<int>(State::Error::top):
- case static_cast<int>(State::Error::pick):
+ case Error::pop:
+ case Error::top:
+ case Error::pick:
std::cout << "stack underflow" << std::endl;
break;
default:
- std::cout << "error: " << r << std::endl;
+ std::cout << "unknown error" << std::endl;
break;
}
- while (state.size())
- state.pop();
- while (state.rsize())
- state.popr();
- state.dict.write(Dictionary::Compiling, 0);
- state.ip = 0;
+ state.reset();
}
}