X-Git-Url: https://code.kerkeslager.com/?a=blobdiff_plain;f=templates%2Ffunction_definition.c;h=ccf3e7596923a252cb4142c2906b350b958781aa;hb=268127b1e817f0dfe298d66e6cacdb0bb83139fb;hp=4635e9ccb929cbe460bbd7055a4629e5bcc4330d;hpb=3eef27fe9f504e67ec74e330587007eb7b28946f;p=fur diff --git a/templates/function_definition.c b/templates/function_definition.c index 4635e9c..ccf3e75 100644 --- a/templates/function_definition.c +++ b/templates/function_definition.c @@ -1,23 +1,22 @@ -Object user${{name}}$implementation(EnvironmentPool* environmentPool, Environment* parent, size_t argc, Stack* parentStack, jmp_buf parentJump) +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(parentJump, 1); @@ -26,13 +25,14 @@ Object user${{name}}$implementation(EnvironmentPool* environmentPool, Environmen 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; }