Просмотр исходного кода

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`.
Geoff Romer 4 лет назад
Родитель
Сommit
d71f5b1784

+ 0 - 3
executable_semantics/interpreter/action.cpp

@@ -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) {

+ 0 - 15
executable_semantics/interpreter/action.h

@@ -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_

Разница между файлами не показана из-за своего большого размера
+ 259 - 349
executable_semantics/interpreter/interpreter.cpp


+ 2 - 0
executable_semantics/interpreter/interpreter.h

@@ -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;

Некоторые файлы не были показаны из-за большого количества измененных файлов