environment = Environment_construct(environmentPool, environment);
Stack* stack = Stack_construct();
+ StackSnapshot stackSnapshot = Stack_takeSnapshot(stack);
jmp_buf jump;
if(setjmp(jump) != 0)
{
fprintf(stderr, "\tin {{name}}\n");
- while(Stack_any(stack))
- {
- Object item = Stack_pop(stack);
- Object_deinitialize(&item);
- }
+ Stack_rewind(stack, stackSnapshot);
Environment_setLive(environment, false);
Stack_destruct(stack);
}
}
+typedef uint32_t StackSnapshot;
+
+StackSnapshot Stack_takeSnapshot(Stack* self)
+{
+ return (StackSnapshot) self->length;
+}
+
+void Stack_rewind(Stack* self, StackSnapshot snapshot)
+{
+ while(self->length > snapshot)
+ {
+ Object item = Stack_pop(self);
+ Object_deinitialize(&item);
+ }
+}
+
void Environment_deinitialize(Environment* self)
{
EnvironmentNode* next;