-Object user${{name}}$implementation(EnvironmentPool* environmentPool, Environment* parent, size_t argc, Stack* stack, jmp_buf parent_jump)
+Object user${{name}}$implementation(EnvironmentPool* environmentPool, Environment* parent, size_t argc, Stack* parentStack, jmp_buf parent_jump)
{
Environment* environment = EnvironmentPool_allocate(environmentPool);
Environment_initialize(environment, parent);
+ Stack stackMemory;
+ Stack* stack = &stackMemory;
+ Stack_initialize(stack);
+
jmp_buf jump;
if(setjmp(jump) != 0)
{
- Environment_setLive(environment, false);
fprintf(stderr, "\tin {{name}}\n");
+
+ while(Stack_any(stack))
+ {
+ Object item = Stack_pop(stack);
+ Object_deinitialize(&item);
+ }
+ Environment_setLive(environment, false);
+
longjmp(parent_jump, 1);
}
Object result = builtin$nil;
{% for argument_name in argument_name_list|reverse %}
- Environment_set(environment, "{{ argument_name }}", Stack_pop(stack));
+ Environment_set(environment, "{{ argument_name }}", Stack_pop(parentStack));
{% endfor %}
{% for statement in statement_list %}
self->length = 0;
}
+bool Stack_any(Stack* self)
+{
+ return self->length > 0;
+}
+
void Stack_push(Stack* self, Object item)
{
assert(self->length < 256);
if(setjmp(jump) != 0)
{
fprintf(stderr, "\tin __main__\n");
+
+ while(Stack_any(stack))
+ {
+ Object item = Stack_pop(stack);
+ Object_deinitialize(&item);
+ }
Environment_setLive(environment, false);
EnvironmentPool_destruct(environmentPool);