2019-08-25 01:36:34 -07:00
|
|
|
#pragma once
|
|
|
|
#include <memory>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
struct type {
|
|
|
|
virtual ~type() = default;
|
|
|
|
};
|
|
|
|
|
|
|
|
using type_ptr = std::shared_ptr<type>;
|
|
|
|
|
|
|
|
struct type_var : public type {
|
|
|
|
std::string name;
|
|
|
|
|
|
|
|
type_var(std::string n)
|
|
|
|
: name(std::move(n)) {}
|
|
|
|
};
|
|
|
|
|
2019-08-25 16:42:23 -07:00
|
|
|
struct type_base : public type {
|
|
|
|
std::string name;
|
2019-08-25 01:36:34 -07:00
|
|
|
|
2019-08-25 16:42:23 -07:00
|
|
|
type_base(std::string n)
|
|
|
|
: name(std::move(n)) {}
|
2019-08-25 01:36:34 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct type_arr : public type {
|
|
|
|
type_ptr left;
|
|
|
|
type_ptr right;
|
|
|
|
|
|
|
|
type_arr(type_ptr l, type_ptr r)
|
|
|
|
: left(std::move(l)), right(std::move(r)) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct type_mgr {
|
|
|
|
int last_id = 0;
|
2019-08-25 16:42:23 -07:00
|
|
|
std::map<std::string, type_ptr> types;
|
2019-08-25 01:36:34 -07:00
|
|
|
|
|
|
|
std::string new_type_name();
|
|
|
|
type_ptr new_type();
|
|
|
|
type_ptr new_arrow_type();
|
2019-08-25 16:42:23 -07:00
|
|
|
|
|
|
|
void unify(type_ptr l, type_ptr r);
|
|
|
|
type_ptr resolve(type_ptr t, type_var*& var);
|
|
|
|
void bind(std::string s, type_ptr t);
|
2019-08-25 01:36:34 -07:00
|
|
|
};
|