@@ -483,14 +483,22 @@ class BackendARM64 : CompilerBackend {
483483 output ~= " mov sp, x9\n " ;
484484 }
485485 else {
486- if (word.error) {
487- output ~= " str x19, [x20, #-8]!\n " ;
486+ if (word.error && words[thisFunc].error) {
487+ size_t paramSize = word.params.length * 8 ;
488+
489+ if (paramSize != 0 ) {
490+ output ~= format(" sub x15, x19, #%d" , paramSize);
491+ output ~= " str x15, [x20, #-8]!\n " ;
492+ }
493+ else {
494+ output ~= " str x19, [x20, #-8]!\n " ;
495+ }
488496 }
489497
490498 output ~= format(" bl __func__%s\n " , node.name.Sanitise());
491499
492- if (word.error) {
493- output ~= " ldr x19 , [x20], #8\n " ;
500+ if (word.error && words[thisFunc].error ) {
501+ output ~= " ldr x15 , [x20], #8\n " ;
494502 }
495503 }
496504 }
@@ -513,6 +521,7 @@ class BackendARM64 : CompilerBackend {
513521 output ~= format(" bne __func__%s\n " , Sanitise(" __arm64_exception" ));
514522 }
515523 else {
524+ output ~= " mov x19, x15\n " ;
516525 CompileReturn(node);
517526 }
518527 }
@@ -1235,8 +1244,8 @@ class BackendARM64 : CompilerBackend {
12351244 size_t paramSize = word.params.length * 8 ;
12361245
12371246 if (paramSize != 0 ) {
1238- output ~= format(" sub x21 , x19, #%d\n " , paramSize);
1239- output ~= " str x21 , [x20, #-8]!\n " ;
1247+ output ~= format(" sub x15 , x19, #%d\n " , paramSize);
1248+ output ~= " str x15 , [x20, #-8]!\n " ;
12401249 }
12411250 else {
12421251 output ~= " str x19, [x20, #-8]!\n " ;
@@ -1251,15 +1260,17 @@ class BackendARM64 : CompilerBackend {
12511260 output ~= format(" bl __func__%s\n " , node.func.Sanitise());
12521261 }
12531262
1254- output ~= " ldr x19 , [x20], #8\n " ;
1263+ output ~= " ldr x15 , [x20], #8\n " ;
12551264
12561265 ++ blockCounter;
12571266
12581267 LoadAddress(" x9" , " __global_" ~ Sanitise(" _cal_exception" ));
12591268 output ~= " ldr x9, [x9]\n " ;
12601269 output ~= " cmp x9, #0\n " ;
12611270 output ~= format(" beq __catch_%d_end\n " , blockCounter);
1262- output ~= " mov x19, x21\n " ;
1271+
1272+ // function errored, assume that all it did was consume parameters
1273+ output ~= " mov x19, x15\n " ;
12631274
12641275 // create scope
12651276 auto oldVars = variables.dup ;
0 commit comments