X-Git-Url: https://code.kerkeslager.com/?a=blobdiff_plain;f=templates%2Ffunction_definition.c;h=ccf3e7596923a252cb4142c2906b350b958781aa;hb=c4de9dca8a54bb5eb611a87b4d9fe36b0fe9a0b1;hp=24c73f801488bfea3154bb0591f4e23badc88c38;hpb=8d6f07b43d8b41473fb7d8779bbc7a5843adcd7b;p=fur diff --git a/templates/function_definition.c b/templates/function_definition.c index 24c73f8..ccf3e75 100644 --- a/templates/function_definition.c +++ b/templates/function_definition.c @@ -1,8 +1,27 @@ -Object user${{name}}$implementation(EnvironmentPool* environmentPool, Environment* parent, size_t argc, Stack* stack) +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); + + StackSnapshot stackSnapshot = Stack_takeSnapshot(stack); + + jmp_buf jump; + if(setjmp(jump) != 0) + { + fprintf(stderr, "\tin {{name}} on line %zu\n", line); + + Stack_rewind(stack, stackSnapshot); + Environment_setLive(environment, false); + + longjmp(parentJump, 1); + } + Object result = builtin$nil; {% for argument_name in argument_name_list|reverse %} @@ -13,6 +32,7 @@ Object user${{name}}$implementation(EnvironmentPool* environmentPool, Environmen {{ statement }} {% endfor %} + // TODO Set the environment back to the parent environment Environment_setLive(environment, false); return result; }