mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 20:40:11 +01:00
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:
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user