Set the environment to the same variable name
authorDavid Kerkeslager <kerkeslager@gmail.com>
Tue, 12 Dec 2017 23:37:37 +0000 (18:37 -0500)
committerDavid Kerkeslager <kerkeslager@gmail.com>
Tue, 12 Dec 2017 23:37:37 +0000 (18:37 -0500)
templates/function_definition.c
templates/program.c

index 4635e9c..c483bda 100644 (file)
@@ -1,8 +1,7 @@
 
-Object user${{name}}$implementation(EnvironmentPool* environmentPool, Environment* parent, size_t argc, Stack* parentStack, jmp_buf parentJump)
+Object user${{name}}$implementation(EnvironmentPool* environmentPool, Environment* environment, size_t argc, Stack* parentStack, jmp_buf parentJump)
 {
-  Environment* environment = EnvironmentPool_allocate(environmentPool);
-  Environment_initialize(environment, parent);
+  environment = Environment_construct(environmentPool, environment);
 
   Stack stackMemory;
   Stack* stack = &stackMemory;
@@ -33,6 +32,7 @@ Object user${{name}}$implementation(EnvironmentPool* environmentPool, Environmen
   {{ statement }}
   {% endfor %}
 
+  // TODO Set the environment back to the parent environment
   Environment_setLive(environment, false);
   return result;
 }
index 6b49881..f2fc244 100644 (file)
@@ -522,6 +522,13 @@ Environment* EnvironmentPool_allocate(EnvironmentPool* self)
   return EnvironmentPool_allocate(previous->overflow);
 }
 
+Environment* Environment_construct(EnvironmentPool* environmentPool, Environment* parent)
+{
+  Environment* environment = EnvironmentPool_allocate(environmentPool);
+  Environment_initialize(environment, parent);
+  return environment;
+}
+
 Object integerLiteral(int32_t literal)
 {
   Object result;