interpreter.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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_INTERPRETER_H_
  5. #define EXECUTABLE_SEMANTICS_INTERPRETER_INTERPRETER_H_
  6. #include <list>
  7. #include <utility>
  8. #include <vector>
  9. #include "common/ostream.h"
  10. #include "executable_semantics/ast/declaration.h"
  11. #include "executable_semantics/ast/expression.h"
  12. #include "executable_semantics/ast/pattern.h"
  13. #include "executable_semantics/interpreter/frame.h"
  14. #include "executable_semantics/interpreter/heap.h"
  15. #include "executable_semantics/interpreter/stack.h"
  16. #include "executable_semantics/interpreter/value.h"
  17. namespace Carbon {
  18. using Env = Dictionary<std::string, Address>;
  19. struct State {
  20. Stack<Frame*> stack;
  21. Heap heap;
  22. };
  23. extern State* state;
  24. void InitEnv(const Declaration& d, Env* env);
  25. void PrintStack(const Stack<Frame*>& ls, llvm::raw_ostream& out);
  26. void PrintEnv(Env values);
  27. /***** Interpreters *****/
  28. auto InterpProgram(const std::list<const Declaration*>& fs) -> int;
  29. auto InterpExp(Env values, const Expression* e) -> const Value*;
  30. auto InterpPattern(Env values, const Pattern* p) -> const Value*;
  31. } // namespace Carbon
  32. #endif // EXECUTABLE_SEMANTICS_INTERPRETER_INTERPRETER_H_