From: David Kerkeslager Date: Tue, 12 Dec 2017 23:44:15 +0000 (-0500) Subject: Allocate Fur stacks on the C heap X-Git-Url: https://code.kerkeslager.com/?a=commitdiff_plain;h=b47a0017d1dbfda8e8bae7989fff9ccb31897a28;p=fur Allocate Fur stacks on the C heap --- 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;