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 <iostream>
  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. std::cout << "********** source program **********" << std::endl;
  13. for (const auto& decl : *fs) {
  14. decl.Print();
  15. }
  16. std::cout << "********** type checking **********" << std::endl;
  17. }
  18. state = new State(); // Compile-time state.
  19. std::pair<TypeEnv, Env> p = TopLevel(fs);
  20. TypeEnv top = p.first;
  21. Env ct_top = p.second;
  22. std::list<Declaration> new_decls;
  23. for (const auto& decl : *fs) {
  24. new_decls.push_back(decl.TypeChecked(top, ct_top));
  25. }
  26. if (tracing_output) {
  27. std::cout << std::endl;
  28. std::cout << "********** type checking complete **********" << std::endl;
  29. for (const auto& decl : new_decls) {
  30. decl.Print();
  31. }
  32. std::cout << "********** starting execution **********" << std::endl;
  33. }
  34. int result = InterpProgram(&new_decls);
  35. std::cout << "result: " << result << std::endl;
  36. }
  37. } // namespace Carbon