Fix use of wrong environment for name mangling.

This commit is contained in:
Danila Fedorin 2020-09-17 22:55:27 -07:00
parent d3b1047d37
commit 5db864881a
2 changed files with 7 additions and 6 deletions

View File

@ -54,7 +54,7 @@ void compiler::translate() {
}
for(auto& defn : global_defs.defs_defn) {
auto& function = defn.second->into_global(global_scp);
global_env->set_mangled_name(defn.first, function.name);
defn.second->env->set_mangled_name(defn.first, function.name);
}
}

View File

@ -1,8 +1,8 @@
---
title: Compiling a Functional Language Using C++, Part 13 - More Improvements
title: Compiling a Functional Language Using C++, Part 13 - Cleanup
date: 2020-09-10T18:50:02-07:00
tags: ["C and C++", "Functional Languages", "Compilers"]
description: "In this post, we clean up our compiler and add some basic optimizations."
description: "In this post, we clean up our compiler."
---
In [part 12]({{< relref "12_compiler_let_in_lambda" >}}), we added `let/in`
@ -809,9 +809,10 @@ And here's what it is now:
{{< codelines "C++" "compiler/13/compiler.cpp" 55 58 >}}
We always declare the `definition_defn` function in
the `global_env`. Thus, that's the only environment
we need to know about to update the mangled name.
Rather than traversing the chain of environments from
the body of the definition, we just use the definition's
own `env_ptr`. This is cleaner and more explicit, and
it helps us not use the private members of `type_env`!
The deal with `env` is about as simple. We just make
it and its two descendants classes, and mark their