Files
carbon-lang/executable_semantics/syntax/syntax_helpers.cpp
T
Jon Meow acb33932cb Migrate Declaration to variant (#644)
Note this makes some structural choices that I'm not sure how popular they'll be... Most notably, I could remove `DeclarationKind` because I'm using `std::visit` and `Declaration::Visitor` in reality. I could go to `switch(tag())` instead, but I'm wondering if this approach will be well received for the separation of ownership. Alternatively, I could move `Declaration` around so that it actually implements the things like `TopLevel` -- I did feel weird with the old structure of typecheck.cpp implementing members of declaration.h, though.
2021-07-15 16:22:56 -07:00

44 lines
1.4 KiB
C++

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include "executable_semantics/syntax/syntax_helpers.h"
#include <iostream>
#include "executable_semantics/interpreter/interpreter.h"
#include "executable_semantics/interpreter/typecheck.h"
#include "executable_semantics/tracing_flag.h"
namespace Carbon {
void ExecProgram(std::list<Declaration>* fs) {
if (tracing_output) {
std::cout << "********** source program **********" << std::endl;
for (const auto& decl : *fs) {
decl.Print();
}
std::cout << "********** type checking **********" << std::endl;
}
state = new State(); // Compile-time state.
TypeCheckContext p = TopLevel(fs);
TypeEnv top = p.types;
Env ct_top = p.values;
std::list<Declaration> new_decls;
for (const auto& decl : *fs) {
new_decls.push_back(MakeTypeChecked(decl, top, ct_top));
}
if (tracing_output) {
std::cout << std::endl;
std::cout << "********** type checking complete **********" << std::endl;
for (const auto& decl : new_decls) {
decl.Print();
}
std::cout << "********** starting execution **********" << std::endl;
}
int result = InterpProgram(&new_decls);
std::cout << "result: " << result << std::endl;
}
} // namespace Carbon