Simplify the API and implementation of Stack (#667)

This commit is contained in:
Geoff Romer
2021-07-20 14:27:41 -07:00
committed by GitHub
parent 8fccecadeb
commit 08a2d44570
6 changed files with 43 additions and 100 deletions
@@ -42,12 +42,13 @@ void PrintEnv(Env values, llvm::raw_ostream& out) {
// State Operations
//
void PrintStack(Stack<Frame*> ls, llvm::raw_ostream& out) {
if (!ls.IsEmpty()) {
out << *ls.Pop();
if (!ls.IsEmpty()) {
void PrintStack(const Stack<Frame*>& ls, llvm::raw_ostream& out) {
auto it = ls.begin();
while (it != ls.end()) {
out << **it;
++it;
if (it != ls.end()) {
out << " :: ";
PrintStack(ls, out);
}
}
}
@@ -228,8 +229,9 @@ void DeallocateScope(int line_num, Scope* scope) {
}
void DeallocateLocals(int line_num, Frame* frame) {
for (auto scope : frame->scopes) {
DeallocateScope(line_num, scope);
while (!frame->scopes.IsEmpty()) {
DeallocateScope(line_num, frame->scopes.Top());
frame->scopes.Pop();
}
}
@@ -1141,8 +1143,7 @@ auto InterpProgram(std::list<Declaration>* fs) -> int {
PrintState(llvm::outs());
}
while (state->stack.CountExceeds(1) ||
state->stack.Top()->todo.CountExceeds(1) ||
while (state->stack.Count() > 1 || state->stack.Top()->todo.Count() > 1 ||
state->stack.Top()->todo.Top()->tag() != ActionKind::ValAction) {
Step();
if (tracing_output) {
@@ -1160,8 +1161,7 @@ auto InterpExp(Env values, const Expression* e) -> const Value* {
auto* frame = new Frame("InterpExp", Stack(scope), todo);
state->stack = Stack(frame);
while (state->stack.CountExceeds(1) ||
state->stack.Top()->todo.CountExceeds(1) ||
while (state->stack.Count() > 1 || state->stack.Top()->todo.Count() > 1 ||
state->stack.Top()->todo.Top()->tag() != ActionKind::ValAction) {
Step();
}