Finalize draft of polymorphism post
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user