Refactor Interpreter/TypeChecker to classes to remove interpreter globals (#790)

Along with #789 this addresses most of #769 although global_arena is still a TODO (that's widespread and overlaps with other changes so I wanted to do it after these are in).
This commit is contained in:
Jon Meow
2021-08-30 15:21:40 -07:00
committed by GitHub
parent 00779b60a8
commit 32f5845e7b
9 changed files with 400 additions and 333 deletions
@@ -9,7 +9,7 @@
#include "executable_semantics/common/arena.h"
#include "executable_semantics/common/tracing_flag.h"
#include "executable_semantics/interpreter/interpreter.h"
#include "executable_semantics/interpreter/typecheck.h"
#include "executable_semantics/interpreter/type_checker.h"
namespace Carbon {
@@ -46,13 +46,13 @@ void ExecProgram(std::list<Ptr<const Declaration>> fs) {
}
llvm::outs() << "********** type checking **********\n";
}
state = global_arena->RawNew<State>(); // Compile-time state.
TypeCheckContext p = TopLevel(fs);
TypeChecker type_checker;
TypeChecker::TypeCheckContext p = type_checker.TopLevel(fs);
TypeEnv top = p.types;
Env ct_top = p.values;
std::list<Ptr<const Declaration>> new_decls;
for (const auto decl : fs) {
new_decls.push_back(MakeTypeChecked(decl, top, ct_top));
new_decls.push_back(type_checker.MakeTypeChecked(decl, top, ct_top));
}
if (tracing_output) {
llvm::outs() << "\n";
@@ -62,7 +62,7 @@ void ExecProgram(std::list<Ptr<const Declaration>> fs) {
}
llvm::outs() << "********** starting execution **********\n";
}
int result = InterpProgram(new_decls);
int result = Interpreter().InterpProgram(new_decls);
llvm::outs() << "result: " << result << "\n";
}