Require mangled names for global variables.
This commit is contained in:
parent
6b8d3b0f8a
commit
6080094c41
|
@ -55,15 +55,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);
|
|
||||||
|
|
||||||
// Local names shouldn't need mangling.
|
|
||||||
assert(!(mangled_name != id && !this->env->is_global(id)));
|
|
||||||
|
|
||||||
into.push_back(instruction_ptr(
|
into.push_back(instruction_ptr(
|
||||||
(env->has_variable(mangled_name) && !this->env->is_global(id)) ?
|
(this->env->is_global(id)) ?
|
||||||
(instruction*) new instruction_push(env->get_offset(id)) :
|
(instruction*) new instruction_pushglobal(id) :
|
||||||
(instruction*) new instruction_pushglobal(mangled_name)));
|
(instruction*) new instruction_push(
|
||||||
|
env->get_offset(this->env->get_mangled_name(id)))));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ast_uid::print(int indent, std::ostream& to) const {
|
void ast_uid::print(int indent, std::ostream& to) const {
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
int env_var::get_offset(const std::string& name) const {
|
int env_var::get_offset(const std::string& name) const {
|
||||||
if(name == this->name) return 0;
|
if(name == this->name) return 0;
|
||||||
assert(parent);
|
assert(parent != nullptr);
|
||||||
return parent->get_offset(name) + 1;
|
return parent->get_offset(name) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ bool env_var::has_variable(const std::string& name) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
int env_offset::get_offset(const std::string& name) const {
|
int env_offset::get_offset(const std::string& name) const {
|
||||||
assert(parent);
|
assert(parent != nullptr);
|
||||||
return parent->get_offset(name) + offset;
|
return parent->get_offset(name) + offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,8 +46,8 @@ const std::string& type_env::get_mangled_name(const std::string& name) const {
|
||||||
auto it = names.find(name);
|
auto it = names.find(name);
|
||||||
if(it != names.end())
|
if(it != names.end())
|
||||||
return (it->second.mangled_name != "") ? it->second.mangled_name : name;
|
return (it->second.mangled_name != "") ? it->second.mangled_name : name;
|
||||||
if(parent) return parent->get_mangled_name(name);
|
assert(parent != nullptr);
|
||||||
return name;
|
return parent->get_mangled_name(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
type_ptr type_env::lookup_type(const std::string& name) const {
|
type_ptr type_env::lookup_type(const std::string& name) const {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user