Reuse the parent stack in current stack frame
[fur] / templates / function_definition.c
1
2 Object user${{name}}$implementation(EnvironmentPool* environmentPool, Environment* environment, size_t argc, Stack* stack, jmp_buf parentJump)
3 {
4   environment = Environment_construct(environmentPool, environment);
5
6   StackSnapshot stackSnapshot = Stack_takeSnapshot(stack);
7
8   jmp_buf jump;
9   if(setjmp(jump) != 0)
10   {
11     fprintf(stderr, "\tin {{name}}\n");
12
13     Stack_rewind(stack, stackSnapshot);
14     Environment_setLive(environment, false);
15
16     longjmp(parentJump, 1);
17   }
18
19   Object result = builtin$nil;
20
21   {% for argument_name in argument_name_list|reverse %}
22   Environment_set(environment, "{{ argument_name }}", Stack_pop(stack));
23   {% endfor %}
24
25   {% for statement in statement_list %}
26   {{ statement }}
27   {% endfor %}
28
29   // TODO Set the environment back to the parent environment
30   Environment_setLive(environment, false);
31   return result;
32 }