Make type_env a class.
This commit is contained in:
parent
0e3f16139d
commit
ba418d357f
|
@ -69,7 +69,7 @@ void compiler::translate() {
|
||||||
}
|
}
|
||||||
for(auto& defn : global_defs.defs_defn) {
|
for(auto& defn : global_defs.defs_defn) {
|
||||||
auto& function = defn.second->into_global(global_scp);
|
auto& function = defn.second->into_global(global_scp);
|
||||||
function.body->env->parent->set_mangled_name(defn.first, function.name);
|
function.body->env->get_parent()->set_mangled_name(defn.first, function.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
#include "type.hpp"
|
#include "type.hpp"
|
||||||
#include "error.hpp"
|
#include "error.hpp"
|
||||||
|
|
||||||
|
type_env_ptr type_env::get_parent() {
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
void type_env::find_free(const type_mgr& mgr, std::set<std::string>& into) const {
|
void type_env::find_free(const type_mgr& mgr, std::set<std::string>& into) const {
|
||||||
if(parent != nullptr) parent->find_free(mgr, into);
|
if(parent != nullptr) parent->find_free(mgr, into);
|
||||||
for(auto& binding : names) {
|
for(auto& binding : names) {
|
||||||
|
|
|
@ -10,39 +10,42 @@ using type_env_ptr = std::shared_ptr<type_env>;
|
||||||
|
|
||||||
enum class visibility { global,local };
|
enum class visibility { global,local };
|
||||||
|
|
||||||
struct type_env {
|
class type_env {
|
||||||
struct variable_data {
|
private:
|
||||||
type_scheme_ptr type;
|
struct variable_data {
|
||||||
visibility vis;
|
type_scheme_ptr type;
|
||||||
std::string mangled_name;
|
visibility vis;
|
||||||
|
std::string mangled_name;
|
||||||
|
|
||||||
variable_data()
|
variable_data()
|
||||||
: variable_data(nullptr, visibility::local, "") {}
|
: variable_data(nullptr, visibility::local, "") {}
|
||||||
variable_data(type_scheme_ptr t, visibility v, std::string n)
|
variable_data(type_scheme_ptr t, visibility v, std::string n)
|
||||||
: type(std::move(t)), vis(v), mangled_name(std::move(n)) {}
|
: type(std::move(t)), vis(v), mangled_name(std::move(n)) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
type_env_ptr parent;
|
type_env_ptr parent;
|
||||||
std::map<std::string, variable_data> names;
|
std::map<std::string, variable_data> names;
|
||||||
std::map<std::string, type_ptr> type_names;
|
std::map<std::string, type_ptr> type_names;
|
||||||
|
|
||||||
type_env(type_env_ptr p) : parent(std::move(p)) {}
|
public:
|
||||||
type_env() : type_env(nullptr) {}
|
type_env(type_env_ptr p) : parent(std::move(p)) {}
|
||||||
|
type_env() : type_env(nullptr) {}
|
||||||
|
|
||||||
void find_free(const type_mgr& mgr, std::set<std::string>& into) const;
|
type_env_ptr get_parent();
|
||||||
void find_free_except(const type_mgr& mgr, const group& avoid,
|
void find_free(const type_mgr& mgr, std::set<std::string>& into) const;
|
||||||
std::set<std::string>& into) const;
|
void find_free_except(const type_mgr& mgr, const group& avoid,
|
||||||
type_scheme_ptr lookup(const std::string& name) const;
|
std::set<std::string>& into) const;
|
||||||
bool is_global(const std::string& name) const;
|
type_scheme_ptr lookup(const std::string& name) const;
|
||||||
void set_mangled_name(const std::string& name, const std::string& mangled);
|
bool is_global(const std::string& name) const;
|
||||||
const std::string& get_mangled_name(const std::string& name) const;
|
void set_mangled_name(const std::string& name, const std::string& mangled);
|
||||||
type_ptr lookup_type(const std::string& name) const;
|
const std::string& get_mangled_name(const std::string& name) const;
|
||||||
void bind(const std::string& name, type_ptr t,
|
type_ptr lookup_type(const std::string& name) const;
|
||||||
visibility v = visibility::local);
|
void bind(const std::string& name, type_ptr t,
|
||||||
void bind(const std::string& name, type_scheme_ptr t,
|
visibility v = visibility::local);
|
||||||
visibility v = visibility::local);
|
void bind(const std::string& name, type_scheme_ptr t,
|
||||||
void bind_type(const std::string& type_name, type_ptr t);
|
visibility v = visibility::local);
|
||||||
void generalize(const std::string& name, const group& grp, type_mgr& mgr);
|
void bind_type(const std::string& type_name, type_ptr t);
|
||||||
|
void generalize(const std::string& name, const group& grp, type_mgr& mgr);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user