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

21 lines
451 B
C++

#pragma once
#include <map>
#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_ptr> names;
type_env(type_env_ptr p) : parent(std::move(p)) {}
type_env() : type_env(nullptr) {}
type_ptr lookup(const std::string& name) const;
void bind(const std::string& name, type_ptr t);
};
type_env_ptr type_scope(type_env_ptr parent);