blog-static/code/compiler/10/type_env.hpp

27 lines
770 B
C++
Raw Normal View History

#pragma once
#include <map>
2020-04-09 16:26:10 -07:00
#include <string>
#include "type.hpp"
struct type_env;
using type_env_ptr = std::shared_ptr<type_env>;
struct type_env {
type_env_ptr parent;
std::map<std::string, type_scheme_ptr> names;
2020-03-25 03:22:21 -07:00
std::map<std::string, type_ptr> type_names;
type_env(type_env_ptr p) : parent(std::move(p)) {}
type_env() : type_env(nullptr) {}
type_scheme_ptr lookup(const std::string& name) const;
2020-03-25 03:22:21 -07:00
type_ptr lookup_type(const std::string& name) const;
void bind(const std::string& name, type_ptr t);
void bind(const std::string& name, type_scheme_ptr t);
2020-03-25 03:22:21 -07:00
void bind_type(const std::string& type_name, type_ptr t);
void generalize(const std::string& name, type_mgr& mgr);
};
type_env_ptr type_scope(type_env_ptr parent);