Add finishing touches to code for part 6 of compiler series

This commit is contained in:
2019-10-10 13:14:00 -07:00
parent e9cd4a915b
commit 463db16df7
5 changed files with 44 additions and 5 deletions

View File

@@ -42,6 +42,19 @@ void typecheck_program(
}
}
void compile_program(const std::vector<definition_ptr>& prog) {
for(auto& def : prog) {
def->compile();
definition_defn* defn = dynamic_cast<definition_defn*>(def.get());
if(!defn) continue;
for(auto& instruction : defn->instructions) {
instruction->print(0, std::cout);
}
std::cout << std::endl;
}
}
int main() {
yy::parser parser;
type_mgr mgr;
@@ -60,6 +73,7 @@ int main() {
}
try {
typecheck_program(program, mgr, env);
compile_program(program);
} catch(unification_error& err) {
std::cout << "failed to unify types: " << std::endl;
std::cout << " (1) \033[34m";