Express stack updates using return values. (#747)

This enables the interpreter logic to express its intent more directly, especially in the common cases, and enables us to get rid of ValAction. It's also a step toward simplifying and encapsulating `state->stack`.
This commit is contained in:
Geoff Romer
2021-08-19 13:35:47 -07:00
committed by GitHub
parent 0619b4ce6a
commit d71f5b1784
4 changed files with 360 additions and 389 deletions
@@ -35,9 +35,6 @@ void Action::Print(llvm::raw_ostream& out) const {
case Action::Kind::StatementAction:
cast<StatementAction>(*this).Stmt()->PrintDepth(1, out);
break;
case Action::Kind::ValAction:
out << *cast<ValAction>(*this).Val();
break;
}
out << "<" << pos << ">";
if (results.size() > 0) {
-15
View File
@@ -24,7 +24,6 @@ class Action {
ExpressionAction,
PatternAction,
StatementAction,
ValAction,
};
Action(const Value&) = delete;
@@ -131,20 +130,6 @@ class StatementAction : public Action {
const Statement* stmt;
};
class ValAction : public Action {
public:
explicit ValAction(const Value* val) : Action(Kind::ValAction), val(val) {}
static auto classof(const Action* action) -> bool {
return action->Tag() == Kind::ValAction;
}
auto Val() const -> const Value* { return val; }
private:
const Value* val;
};
} // namespace Carbon
#endif // EXECUTABLE_SEMANTICS_INTERPRETER_ACTION_H_
File diff suppressed because it is too large Load Diff
@@ -6,6 +6,7 @@
#define EXECUTABLE_SEMANTICS_INTERPRETER_INTERPRETER_H_
#include <list>
#include <optional>
#include <utility>
#include <vector>
@@ -25,6 +26,7 @@ using Env = Dictionary<std::string, Address>;
struct State {
Stack<Ptr<Frame>> stack;
Heap heap;
std::optional<const Value*> program_value;
};
extern State* state;