From 1f2895250c61aeb81c0f0ba7efed156c9386dfac Mon Sep 17 00:00:00 2001 From: David Kerkeslager Date: Tue, 12 Dec 2017 18:37:37 -0500 Subject: [PATCH] Set the environment to the same variable name --- templates/function_definition.c | 6 +++--- templates/program.c | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/templates/function_definition.c b/templates/function_definition.c index 4635e9c..c483bda 100644 --- a/templates/function_definition.c +++ b/templates/function_definition.c @@ -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; } diff --git a/templates/program.c b/templates/program.c index 6b49881..f2fc244 100644 --- a/templates/program.c +++ b/templates/program.c @@ -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; -- 2.20.1