Start working on translation.

This commit is contained in:
2020-05-31 18:52:52 -07:00
parent 08c8aca144
commit e7229e644f
7 changed files with 92 additions and 27 deletions

View File

@@ -35,26 +35,16 @@ void definition_defn::typecheck(type_mgr& mgr) {
mgr.unify(return_type, body_type);
}
void definition_defn::compile() {
env_ptr new_env = env_ptr(new env_offset(0, nullptr));
for(auto it = params.rbegin(); it != params.rend(); it++) {
new_env = env_ptr(new env_var(*it, new_env));
}
body->compile(new_env, instructions);
instructions.push_back(instruction_ptr(new instruction_update(params.size())));
instructions.push_back(instruction_ptr(new instruction_pop(params.size())));
}
void definition_defn::declare_llvm(llvm_context& ctx) {
generated_function = ctx.create_custom_function(name, params.size());
}
void definition_defn::generate_llvm(llvm_context& ctx) {
ctx.builder.SetInsertPoint(&generated_function->getEntryBlock());
for(auto& instruction : instructions) {
instruction->gen_llvm(ctx, generated_function);
global_definition_ptr& definition_defn::into_global(global_scope& scope) {
std::vector<std::string> all_params;
for(auto& free : free_variables) {
if(env->is_global(free)) continue;
all_params.push_back(free);
}
ctx.builder.CreateRetVoid();
all_params.insert(all_params.end(), params.begin(), params.end());
translate(body, scope);
return scope.add_definition(name, std::move(all_params), std::move(body));
}
void definition_data::insert_types(type_env_ptr& env) {