interpreter.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 <optional>
  7. #include <utility>
  8. #include <vector>
  9. #include "common/ostream.h"
  10. #include "executable_semantics/ast/ast.h"
  11. #include "executable_semantics/ast/declaration.h"
  12. #include "executable_semantics/ast/expression.h"
  13. #include "executable_semantics/ast/pattern.h"
  14. #include "executable_semantics/interpreter/action.h"
  15. #include "executable_semantics/interpreter/action_stack.h"
  16. #include "executable_semantics/interpreter/heap.h"
  17. #include "executable_semantics/interpreter/value.h"
  18. #include "llvm/ADT/ArrayRef.h"
  19. namespace Carbon {
  20. // Interprets the program defined by `ast`, allocating values on `arena` and
  21. // printing traces if `trace` is true.
  22. auto InterpProgram(const AST& ast, Nonnull<Arena*> arena, bool trace) -> int;
  23. // Interprets `e` at compile-time, allocating values on `arena` and
  24. // printing traces if `trace` is true. The caller must ensure that all the
  25. // code this evaluates has been typechecked.
  26. auto InterpExp(Nonnull<const Expression*> e, Nonnull<Arena*> arena, bool trace)
  27. -> Nonnull<const Value*>;
  28. // Interprets `p` at compile-time, allocating values on `arena` and
  29. // printing traces if `trace` is true. The caller must ensure that all the
  30. // code this evaluates has been typechecked.
  31. auto InterpPattern(Nonnull<const Pattern*> p, Nonnull<Arena*> arena, bool trace)
  32. -> Nonnull<const Value*>;
  33. // Attempts to match `v` against the pattern `p`, returning whether matching
  34. // is successful. If it is, populates **bindings with the variables bound by
  35. // the match; `bindings` should only be nullopt in contexts where `p`
  36. // is not permitted to bind variables. **bindings may be modified even if the
  37. // match is unsuccessful, so it should typically be created for the
  38. // PatternMatch call and then merged into an existing scope on success.
  39. // TODO: consider moving this to a separate header.
  40. [[nodiscard]] auto PatternMatch(Nonnull<const Value*> p,
  41. Nonnull<const Value*> v,
  42. SourceLocation source_loc,
  43. std::optional<Nonnull<RuntimeScope*>> bindings)
  44. -> bool;
  45. } // namespace Carbon
  46. #endif // EXECUTABLE_SEMANTICS_INTERPRETER_INTERPRETER_H_