Executable Semantics: 1st-class stacks (#296)

Replaces low-level uses of `Cons` with a first-class `Stack` data structure.  Also removes an unused algorithm.
Co-authored-by: Jeremy Siek <jsiek@indiana.edu>

Possible next step: use `std::stack` instead.
This commit is contained in:
Dave Abrahams
2021-02-26 09:46:32 -08:00
committed by GitHub
parent 21917095a3
commit 29a59944fa
11 changed files with 352 additions and 204 deletions
+6 -5
View File
@@ -12,6 +12,7 @@
#include "executable_semantics/ast/expression.h"
#include "executable_semantics/ast/function_definition.h"
#include "executable_semantics/interpreter/interpreter.h"
#include "executable_semantics/interpreter/stack.h"
#include "executable_semantics/interpreter/typecheck.h"
namespace Carbon {
@@ -48,12 +49,12 @@ void PrintAct(Action* act, std::ostream& out) {
}
}
void PrintActList(Cons<Action*>* ls, std::ostream& out) {
if (ls) {
PrintAct(ls->curr, out);
if (ls->next) {
void PrintActList(Stack<Action*> ls, std::ostream& out) {
if (!ls.IsEmpty()) {
PrintAct(ls.Pop(), out);
if (!ls.IsEmpty()) {
out << " :: ";
PrintActList(ls->next, out);
PrintActList(ls, out);
}
}
}