Use mangled names in variable environments.
This commit is contained in:
parent
522d196446
commit
33f8040886
11
12/ast.cpp
11
12/ast.cpp
|
@ -50,10 +50,11 @@ void ast_lid::translate(global_scope& scope) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ast_lid::compile(const env_ptr& env, std::vector<instruction_ptr>& into) const {
|
void ast_lid::compile(const env_ptr& env, std::vector<instruction_ptr>& into) const {
|
||||||
|
auto mangled_name = this->env->get_mangled_name(id);
|
||||||
into.push_back(instruction_ptr(
|
into.push_back(instruction_ptr(
|
||||||
(env->has_variable(id) && !this->env->is_global(id)) ?
|
(env->has_variable(mangled_name) && !this->env->is_global(id)) ?
|
||||||
(instruction*) new instruction_push(env->get_offset(id)) :
|
(instruction*) new instruction_push(env->get_offset(mangled_name)) :
|
||||||
(instruction*) new instruction_pushglobal(this->env->get_mangled_name(id))));
|
(instruction*) new instruction_pushglobal(mangled_name)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ast_uid::print(int indent, std::ostream& to) const {
|
void ast_uid::print(int indent, std::ostream& to) const {
|
||||||
|
@ -238,7 +239,7 @@ void ast_case::compile(const env_ptr& env, std::vector<instruction_ptr>& into) c
|
||||||
} else if((cpat = dynamic_cast<pattern_constr*>(branch->pat.get()))) {
|
} else if((cpat = dynamic_cast<pattern_constr*>(branch->pat.get()))) {
|
||||||
env_ptr new_env = env;
|
env_ptr new_env = env;
|
||||||
for(auto it = cpat->params.rbegin(); it != cpat->params.rend(); it++) {
|
for(auto it = cpat->params.rbegin(); it != cpat->params.rend(); it++) {
|
||||||
new_env = env_ptr(new env_var(*it, new_env));
|
new_env = env_ptr(new env_var(branch->expr->env->get_mangled_name(*it), new_env));
|
||||||
}
|
}
|
||||||
|
|
||||||
branch_instructions.push_back(instruction_ptr(new instruction_split(
|
branch_instructions.push_back(instruction_ptr(new instruction_split(
|
||||||
|
@ -319,7 +320,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(def.first, std::move(new_env)));
|
new_env = env_ptr(new env_var(definitions.env->get_mangled_name(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) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user