From b47a0017d1dbfda8e8bae7989fff9ccb31897a28 Mon Sep 17 00:00:00 2001 From: David Kerkeslager Date: Tue, 12 Dec 2017 18:44:15 -0500 Subject: [PATCH] Allocate Fur stacks on the C heap --- templates/function_definition.c | 8 +++++--- templates/program.c | 12 ++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/templates/function_definition.c b/templates/function_definition.c index c483bda..d20eba6 100644 --- a/templates/function_definition.c +++ b/templates/function_definition.c @@ -3,9 +3,7 @@ Object user${{name}}$implementation(EnvironmentPool* environmentPool, Environmen { environment = Environment_construct(environmentPool, environment); - Stack stackMemory; - Stack* stack = &stackMemory; - Stack_initialize(stack); + Stack* stack = Stack_construct(); jmp_buf jump; if(setjmp(jump) != 0) @@ -19,6 +17,8 @@ Object user${{name}}$implementation(EnvironmentPool* environmentPool, Environmen } Environment_setLive(environment, false); + Stack_destruct(stack); + longjmp(parentJump, 1); } @@ -34,5 +34,7 @@ Object user${{name}}$implementation(EnvironmentPool* environmentPool, Environmen // TODO Set the environment back to the parent environment Environment_setLive(environment, false); + + Stack_destruct(stack); return result; } diff --git a/templates/program.c b/templates/program.c index f2fc244..b25f7dc 100644 --- a/templates/program.c +++ b/templates/program.c @@ -163,6 +163,18 @@ void Stack_initialize(Stack* self) self->length = 0; } +Stack* Stack_construct() +{ + Stack* result = malloc(sizeof(Stack)); + Stack_initialize(result); + return result; +} + +void Stack_destruct(Stack* self) +{ + free(self); +} + bool Stack_any(Stack* self) { return self->length > 0; -- 2.20.1