X-Git-Url: https://code.kerkeslager.com/?a=blobdiff_plain;ds=sidebyside;f=templates%2Ffunction_definition.c;h=ccf3e7596923a252cb4142c2906b350b958781aa;hb=d28e140fd317ef3d63286ba6d87eb0418ee536c9;hp=9ebac36d4213e60de2d5b66b54a005864c6a3453;hpb=4c47216656579a0e5b81cc3fbab17362ffde3e94;p=fur diff --git a/templates/function_definition.c b/templates/function_definition.c index 9ebac36..ccf3e75 100644 --- a/templates/function_definition.c +++ b/templates/function_definition.c @@ -1,38 +1,38 @@ -Object user${{name}}$implementation(EnvironmentPool* environmentPool, Environment* parent, size_t argc, Stack* parentStack, jmp_buf parent_jump) +Object user${{name}}${{index}}$implementation( + EnvironmentPool* environmentPool, + Environment* environment, + size_t argc, + Stack* stack, + const unsigned long line, + jmp_buf parentJump) { - Environment* environment = EnvironmentPool_allocate(environmentPool); - Environment_initialize(environment, parent); + environment = Environment_construct(environmentPool, environment); - Stack stackMemory; - Stack* stack = &stackMemory; - Stack_initialize(stack); + StackSnapshot stackSnapshot = Stack_takeSnapshot(stack); jmp_buf jump; if(setjmp(jump) != 0) { - fprintf(stderr, "\tin {{name}}\n"); + fprintf(stderr, "\tin {{name}} on line %zu\n", line); - while(Stack_any(stack)) - { - Object item = Stack_pop(stack); - Object_deinitialize(&item); - } + Stack_rewind(stack, stackSnapshot); Environment_setLive(environment, false); - longjmp(parent_jump, 1); + longjmp(parentJump, 1); } Object result = builtin$nil; {% for argument_name in argument_name_list|reverse %} - Environment_set(environment, "{{ argument_name }}", Stack_pop(parentStack)); + Environment_set(environment, "{{ argument_name }}", Stack_pop(stack)); {% endfor %} {% for statement in statement_list %} {{ statement }} {% endfor %} + // TODO Set the environment back to the parent environment Environment_setLive(environment, false); return result; }