Allocate Fur stacks on the C heap
authorDavid Kerkeslager <kerkeslager@gmail.com>
Tue, 12 Dec 2017 23:44:15 +0000 (18:44 -0500)
committerDavid Kerkeslager <kerkeslager@gmail.com>
Tue, 12 Dec 2017 23:44:15 +0000 (18:44 -0500)
templates/function_definition.c
templates/program.c

index c483bda..d20eba6 100644 (file)
@@ -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;
 }
index f2fc244..b25f7dc 100644 (file)
@@ -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;