Stop using mangled names for local variables.

This commit is contained in:
Danila Fedorin 2020-09-10 15:14:19 -07:00
parent 688463570c
commit e7afa126c8
2 changed files with 9 additions and 4 deletions

View File

@ -340,7 +340,7 @@ struct case_strategy_data {
std::vector<instruction_ptr>& into) { std::vector<instruction_ptr>& into) {
env_ptr new_env = env; env_ptr new_env = env;
for(auto it = repr.second->rbegin(); it != repr.second->rend(); it++) { for(auto it = repr.second->rbegin(); it != repr.second->rend(); it++) {
new_env = env_ptr(new env_var(branch->expr->env->get_mangled_name(*it), new_env)); new_env = env_ptr(new env_var(*it, new_env));
} }
into.push_back(instruction_ptr(new instruction_split(repr.second->size()))); into.push_back(instruction_ptr(new instruction_split(repr.second->size())));
@ -392,7 +392,7 @@ void compile_case(const ast_case& node, const env_ptr& env, const type* type, st
if(cases.defined_cases_count() == strategy.case_count(type)) if(cases.defined_cases_count() == strategy.case_count(type))
throw type_error("redundant catch-all pattern", branch->pat->loc); throw type_error("redundant catch-all pattern", branch->pat->loc);
auto& branch_into = cases.make_default_case(); auto& branch_into = cases.make_default_case();
env_ptr new_env(new env_var(branch->expr->env->get_mangled_name(vpat->var), env)); env_ptr new_env(new env_var(vpat->var, env));
branch->expr->compile(new_env, branch_into); branch->expr->compile(new_env, branch_into);
branch_into.push_back(instruction_ptr(new instruction_slide(1))); branch_into.push_back(instruction_ptr(new instruction_slide(1)));
} else { } else {
@ -484,7 +484,7 @@ void ast_let::compile(const env_ptr& env, std::vector<instruction_ptr>& into) co
into.push_back(instruction_ptr(new instruction_alloc(translated_definitions.size()))); into.push_back(instruction_ptr(new instruction_alloc(translated_definitions.size())));
env_ptr new_env = env; env_ptr new_env = env;
for(auto& def : translated_definitions) { for(auto& def : translated_definitions) {
new_env = env_ptr(new env_var(definitions.env->get_mangled_name(def.first), std::move(new_env))); new_env = env_ptr(new env_var(def.first, std::move(new_env)));
} }
int offset = translated_definitions.size() - 1; int offset = translated_definitions.size() - 1;
for(auto& def : translated_definitions) { for(auto& def : translated_definitions) {

View File

@ -34,7 +34,12 @@ bool type_env::is_global(const std::string& name) const {
void type_env::set_mangled_name(const std::string& name, const std::string& mangled) { void type_env::set_mangled_name(const std::string& name, const std::string& mangled) {
auto it = names.find(name); auto it = names.find(name);
if(it != names.end()) it->second.mangled_name = mangled; if(it != names.end()) {
// Local names shouldn't need mangling.
assert(it->second.vis == visibility::global);
it->second.mangled_name = mangled;
}
} }
const std::string& type_env::get_mangled_name(const std::string& name) const { const std::string& type_env::get_mangled_name(const std::string& name) const {