|
|
@ -36,7 +36,7 @@ void ast_lid::find_free(type_mgr& mgr, type_env_ptr& env, std::set<std::string>& |
|
|
|
} |
|
|
|
|
|
|
|
type_ptr ast_lid::typecheck(type_mgr& mgr) { |
|
|
|
return env->lookup(id); |
|
|
|
return env->lookup(id)->instantiate(mgr); |
|
|
|
} |
|
|
|
|
|
|
|
void ast_lid::compile(const env_ptr& env, std::vector<instruction_ptr>& into) const { |
|
|
@ -56,7 +56,7 @@ void ast_uid::find_free(type_mgr& mgr, type_env_ptr& env, std::set<std::string>& |
|
|
|
} |
|
|
|
|
|
|
|
type_ptr ast_uid::typecheck(type_mgr& mgr) { |
|
|
|
return env->lookup(id); |
|
|
|
return env->lookup(id)->instantiate(mgr); |
|
|
|
} |
|
|
|
|
|
|
|
void ast_uid::compile(const env_ptr& env, std::vector<instruction_ptr>& into) const { |
|
|
@ -79,7 +79,7 @@ void ast_binop::find_free(type_mgr& mgr, type_env_ptr& env, std::set<std::string |
|
|
|
type_ptr ast_binop::typecheck(type_mgr& mgr) { |
|
|
|
type_ptr ltype = left->typecheck(mgr); |
|
|
|
type_ptr rtype = right->typecheck(mgr); |
|
|
|
type_ptr ftype = env->lookup(op_name(op)); |
|
|
|
type_ptr ftype = env->lookup(op_name(op))->instantiate(mgr); |
|
|
|
if(!ftype) throw type_error(std::string("unknown binary operator ") + op_name(op)); |
|
|
|
|
|
|
|
type_ptr return_type = mgr.new_type(); |
|
|
@ -232,7 +232,7 @@ void pattern_var::insert_bindings(type_mgr& mgr, type_env_ptr& env) const { |
|
|
|
} |
|
|
|
|
|
|
|
void pattern_var::typecheck(type_ptr t, type_mgr& mgr, type_env_ptr& env) const { |
|
|
|
mgr.unify(env->lookup(var), t); |
|
|
|
mgr.unify(env->lookup(var)->instantiate(mgr), t); |
|
|
|
} |
|
|
|
|
|
|
|
void pattern_constr::print(std::ostream& to) const { |
|
|
@ -249,7 +249,7 @@ void pattern_constr::insert_bindings(type_mgr& mgr, type_env_ptr& env) const { |
|
|
|
} |
|
|
|
|
|
|
|
void pattern_constr::typecheck(type_ptr t, type_mgr& mgr, type_env_ptr& env) const { |
|
|
|
type_ptr constructor_type = env->lookup(constr); |
|
|
|
type_ptr constructor_type = env->lookup(constr)->instantiate(mgr); |
|
|
|
if(!constructor_type) { |
|
|
|
throw type_error(std::string("pattern using unknown constructor ") + constr); |
|
|
|
} |
|
|
@ -258,7 +258,7 @@ void pattern_constr::typecheck(type_ptr t, type_mgr& mgr, type_env_ptr& env) con |
|
|
|
type_arr* arr = dynamic_cast<type_arr*>(constructor_type.get()); |
|
|
|
if(!arr) throw type_error("too many parameters in constructor pattern"); |
|
|
|
|
|
|
|
mgr.unify(env->lookup(param), arr->left); |
|
|
|
mgr.unify(env->lookup(param)->instantiate(mgr), arr->left); |
|
|
|
constructor_type = arr->right; |
|
|
|
} |
|
|
|
|
|
|
|