Finalize draft of polymorphism post

This commit is contained in:
2020-03-25 03:22:21 -07:00
parent de435d6c80
commit 08246f1474
8 changed files with 40 additions and 117 deletions

View File

@@ -3,6 +3,7 @@
#include "ast.hpp"
#include "instruction.hpp"
#include "llvm_context.hpp"
#include "type.hpp"
#include "type_env.hpp"
#include <llvm/IR/DerivedTypes.h>
#include <llvm/IR/Function.h>
@@ -57,11 +58,12 @@ void definition_defn::generate_llvm(llvm_context& ctx) {
void definition_data::insert_types(type_mgr& mgr, type_env_ptr& env) {
this->env = env;
env->bind_type(name, type_ptr(new type_data(name)));
}
void definition_data::insert_constructors() const {
type_data* this_type = new type_data(name);
type_ptr return_type = type_ptr(this_type);
type_ptr return_type = env->lookup_type(name);
type_data* this_type = static_cast<type_data*>(return_type.get());
int next_tag = 0;
for(auto& constructor : constructors) {
@@ -70,7 +72,8 @@ void definition_data::insert_constructors() const {
type_ptr full_type = return_type;
for(auto it = constructor->types.rbegin(); it != constructor->types.rend(); it++) {
type_ptr type = type_ptr(new type_base(*it));
type_ptr type = env->lookup_type(*it);
if(!type) throw 0;
full_type = type_ptr(new type_arr(type, full_type));
}