syntax_helpers.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. #include "executable_semantics/syntax/syntax_helpers.h"
  5. #include "common/ostream.h"
  6. #include "executable_semantics/common/arena.h"
  7. #include "executable_semantics/common/tracing_flag.h"
  8. #include "executable_semantics/interpreter/interpreter.h"
  9. #include "executable_semantics/interpreter/typecheck.h"
  10. namespace Carbon {
  11. void ExecProgram(std::list<Declaration>* fs) {
  12. if (tracing_output) {
  13. llvm::outs() << "********** source program **********\n";
  14. for (const auto& decl : *fs) {
  15. llvm::outs() << decl;
  16. }
  17. llvm::outs() << "********** type checking **********\n";
  18. }
  19. state = global_arena->New<State>(); // Compile-time state.
  20. TypeCheckContext p = TopLevel(fs);
  21. TypeEnv top = p.types;
  22. Env ct_top = p.values;
  23. std::list<Declaration> new_decls;
  24. for (const auto& decl : *fs) {
  25. new_decls.push_back(MakeTypeChecked(decl, top, ct_top));
  26. }
  27. if (tracing_output) {
  28. llvm::outs() << "\n";
  29. llvm::outs() << "********** type checking complete **********\n";
  30. for (const auto& decl : new_decls) {
  31. llvm::outs() << decl;
  32. }
  33. llvm::outs() << "********** starting execution **********\n";
  34. }
  35. int result = InterpProgram(&new_decls);
  36. llvm::outs() << "result: " << result << "\n";
  37. }
  38. } // namespace Carbon