37 lines
1.1 KiB
C++
37 lines
1.1 KiB
C++
#pragma once
|
|
#include <memory>
|
|
#include <map>
|
|
#include <vector>
|
|
#include "type.hpp"
|
|
#include "gmachine.hpp"
|
|
|
|
namespace lily {
|
|
class type_env;
|
|
|
|
class type_manager {
|
|
private:
|
|
int next_id;
|
|
std::vector<std::unique_ptr<type>> types;
|
|
std::map<std::string, type*> type_names;
|
|
public:
|
|
type_manager();
|
|
|
|
type_internal* create_int_type();
|
|
type_internal* create_str_type();
|
|
type_data* create_data_type(const std::string& name);
|
|
template <typename T, typename ... Args>
|
|
T* create_type(Args...as) {
|
|
auto new_type = std::make_unique<T>(as...);
|
|
T* raw_ptr = new_type.get();
|
|
types.push_back(std::move(new_type));
|
|
return raw_ptr;
|
|
}
|
|
|
|
type* require_type(const std::string& name) const;
|
|
|
|
void register_constructors(std::shared_ptr<type_env> env);
|
|
void register_constructor_supercombs(instruction_manager& mgr, std::map<std::string, std::vector<instruction*>>& into);
|
|
int constructor_arity(const std::string& name);
|
|
};
|
|
}
|