From 5db864881ab2ddd2a475ef40b026b523edb0e50d Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Thu, 17 Sep 2020 22:55:27 -0700 Subject: [PATCH] Fix use of wrong environment for name mangling. --- code/compiler/13/compiler.cpp | 2 +- content/blog/13_compiler_cleanup/index.md | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/code/compiler/13/compiler.cpp b/code/compiler/13/compiler.cpp index 7250ab5..397e178 100644 --- a/code/compiler/13/compiler.cpp +++ b/code/compiler/13/compiler.cpp @@ -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); } } diff --git a/content/blog/13_compiler_cleanup/index.md b/content/blog/13_compiler_cleanup/index.md index 0ef18be..f43bef1 100644 --- a/content/blog/13_compiler_cleanup/index.md +++ b/content/blog/13_compiler_cleanup/index.md @@ -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