syntax_helpers.cpp 1.3 KB

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