mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-29 09:44:56 +01:00
[executable semantics] class-ify Declaration (#307)
* [executable semantics] class-ify Declaration NFC (no functional change). Proof of concept that we can simplify code by replacing unions with safer, more regular types. Hand-rolled existentials (type-erasing CoW wrappers) are a follow-on step that will further simplify usage. Began adding `const` where possible, and replacing `std::string*` with `std::string`. Most `const`s can disappear as we replace reference semantics with value semantics, but in the meantime it's an important step in the right direction.
This commit is contained in:
@@ -20,22 +20,22 @@ void PrintSyntaxError(char* error, int line_num) {
|
||||
|
||||
void ExecProgram(std::list<Declaration*>* fs) {
|
||||
std::cout << "********** source program **********" << std::endl;
|
||||
for (const auto& decl : *fs) {
|
||||
PrintDecl(decl);
|
||||
for (const auto decl : *fs) {
|
||||
decl->Print();
|
||||
}
|
||||
std::cout << "********** type checking **********" << std::endl;
|
||||
state = new State(); // Compile-time state.
|
||||
std::pair<TypeEnv*, Env*> p = TopLevel(fs);
|
||||
TypeEnv* top = p.first;
|
||||
Env* ct_top = p.second;
|
||||
std::list<Declaration*> new_decls;
|
||||
for (const auto& i : *fs) {
|
||||
new_decls.push_back(TypeCheckDecl(i, top, ct_top));
|
||||
std::list<const Declaration*> new_decls;
|
||||
for (const auto i : *fs) {
|
||||
new_decls.push_back(i->TypeChecked(top, ct_top));
|
||||
}
|
||||
std::cout << std::endl;
|
||||
std::cout << "********** type checking complete **********" << std::endl;
|
||||
for (const auto& decl : new_decls) {
|
||||
PrintDecl(decl);
|
||||
for (const auto decl : new_decls) {
|
||||
decl->Print();
|
||||
}
|
||||
std::cout << "********** starting execution **********" << std::endl;
|
||||
int result = InterpProgram(&new_decls);
|
||||
|
||||
Reference in New Issue
Block a user