action.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #ifndef EXECUTABLE_SEMANTICS_INTERPRETER_ACTION_H_
  5. #define EXECUTABLE_SEMANTICS_INTERPRETER_ACTION_H_
  6. #include <iostream>
  7. #include <vector>
  8. #include "executable_semantics/ast/expression.h"
  9. #include "executable_semantics/ast/statement.h"
  10. #include "executable_semantics/interpreter/stack.h"
  11. #include "executable_semantics/interpreter/value.h"
  12. namespace Carbon {
  13. enum class ActionKind {
  14. LValAction,
  15. ExpressionAction,
  16. StatementAction,
  17. ValAction,
  18. ExpToLValAction,
  19. DeleteTmpAction
  20. };
  21. struct Action {
  22. ActionKind tag;
  23. union {
  24. const Expression* exp; // for LValAction and ExpressionAction
  25. const Statement* stmt;
  26. const Value* val; // for finished actions with a value (ValAction)
  27. Address delete_tmp;
  28. } u;
  29. int pos; // position or state of the action, starts at 0 and goes up to
  30. // the number of subexpressions.
  31. // pos indicates how many of the entries in the following `results` vector
  32. // will be filled in the next time this action is active.
  33. // For each i < pos, results[i] contains a pointer to a Value.
  34. std::vector<const Value*> results; // results from subexpression
  35. };
  36. void PrintAct(Action* act, std::ostream& out);
  37. void PrintActList(Stack<Action*> ls, std::ostream& out);
  38. auto MakeExpAct(const Expression* e) -> Action*;
  39. auto MakeLvalAct(const Expression* e) -> Action*;
  40. auto MakeStmtAct(const Statement* s) -> Action*;
  41. auto MakeValAct(const Value* v) -> Action*;
  42. auto MakeExpToLvalAct() -> Action*;
  43. auto MakeDeleteAct(Address a) -> Action*;
  44. } // namespace Carbon
  45. #endif // EXECUTABLE_SEMANTICS_INTERPRETER_ACTION_H_