Maybe finish the let/in code?

This commit is contained in:
2020-06-01 00:23:41 -07:00
parent baf7427737
commit 522d196446
10 changed files with 241 additions and 158 deletions

View File

@@ -39,8 +39,8 @@ void typecheck_program(
env->bind("/", binop_type, visibility::global);
std::set<std::string> free;
defs.find_free(mgr, env, free);
defs.typecheck(mgr);
defs.find_free(free);
defs.typecheck(mgr, env);
for(auto& pair : defs.env->names) {
std::cout << pair.first << ": ";
@@ -49,15 +49,16 @@ void typecheck_program(
}
}
void compile_program(const std::map<std::string, definition_defn_ptr>& defs_defn) {
for(auto& def_defn : defs_defn) {
def_defn.second->compile();
for(auto& instruction : def_defn.second->instructions) {
instruction->print(0, std::cout);
}
std::cout << std::endl;
global_scope translate_program(definition_group& group) {
global_scope scope;
for(auto& data : group.defs_data) {
data.second->into_globals(scope);
}
for(auto& defn : group.defs_defn) {
auto& function = defn.second->into_global(scope);
function.body->env->parent->set_mangled_name(defn.first, function.name);
}
return scope;
}
void gen_llvm_internal_op(llvm_context& ctx, binop op) {
@@ -117,24 +118,14 @@ void output_llvm(llvm_context& ctx, const std::string& filename) {
}
}
void gen_llvm(
const std::map<std::string, definition_data_ptr>& defs_data,
const std::map<std::string, definition_defn_ptr>& defs_defn) {
void gen_llvm(global_scope& scope) {
llvm_context ctx;
gen_llvm_internal_op(ctx, PLUS);
gen_llvm_internal_op(ctx, MINUS);
gen_llvm_internal_op(ctx, TIMES);
gen_llvm_internal_op(ctx, DIVIDE);
for(auto& def_data : defs_data) {
def_data.second->generate_llvm(ctx);
}
for(auto& def_defn : defs_defn) {
def_defn.second->declare_llvm(ctx);
}
for(auto& def_defn : defs_defn) {
def_defn.second->generate_llvm(ctx);
}
scope.generate_llvm(ctx);
ctx.module.print(llvm::outs(), nullptr);
output_llvm(ctx, "program.o");
@@ -155,8 +146,9 @@ int main() {
}
try {
typecheck_program(global_defs, mgr, env);
compile_program(global_defs.defs_defn);
gen_llvm(global_defs.defs_data, global_defs.defs_defn);
global_scope scope = translate_program(global_defs);
scope.compile();
gen_llvm(scope);
} catch(unification_error& err) {
std::cout << "failed to unify types: " << std::endl;
std::cout << " (1) \033[34m";