@@ -25,14 +25,11 @@ private struct Word {
2525 Node[] inlineNodes;
2626 bool error;
2727 Type[] params;
28- size_t numReturns;
2928
3029 // for C words
3130 Type ret;
3231 bool isVoid;
3332 string symbolName;
34-
35- int StackEffect () => (- (cast (int ) params.length) + (cast (int ) numReturns));
3633}
3734
3835class BackendX86_64 : CompilerBackend {
@@ -525,7 +522,23 @@ class BackendX86_64 : CompilerBackend {
525522 }
526523 }
527524 else {
525+ if (words[thisFunc].error) {
526+ size_t paramSize = word.params.length * 8 ;
527+
528+ if (paramSize != 0 ) {
529+ output ~= format(" lea r14, [r15 - %d]\n " , paramSize);
530+ output ~= " push r14\n " ;
531+ }
532+ else {
533+ output ~= " push r15\n " ;
534+ }
535+ }
536+
528537 output ~= format(" call __func__%s\n " , node.name.Sanitise());
538+
539+ if (words[thisFunc].error) {
540+ output ~= " pop r15\n " ;
541+ }
529542 }
530543 }
531544
@@ -622,7 +635,7 @@ class BackendX86_64 : CompilerBackend {
622635 }
623636
624637 words[node.name] = Word(
625- WordType.Callisto, true , node.nodes, node.errors, params, node.returnTypes.length
638+ WordType.Callisto, true , node.nodes, node.errors, params
626639 );
627640 }
628641 else {
@@ -631,7 +644,7 @@ class BackendX86_64 : CompilerBackend {
631644
632645 words[node.name] = Word(
633646 node.raw? WordType.Raw : WordType.Callisto , false , [], node.errors,
634- params, node.returnTypes.length
647+ params
635648 );
636649
637650 string symbol =
@@ -1290,10 +1303,10 @@ class BackendX86_64 : CompilerBackend {
12901303 Error(node.error, " Non-callisto functions can't throw" );
12911304 }
12921305
1293- int stackEffect = word.StackEffect() * 8 ;
1306+ size_t paramSize = word.params.length * 8 ;
12941307
1295- if (stackEffect != 0 ) {
1296- output ~= format(" lea r14, [r15 + %d]\n " , stackEffect );
1308+ if (paramSize != 0 ) {
1309+ output ~= format(" lea r14, [r15 - %d]\n " , paramSize );
12971310 output ~= " push r14\n " ;
12981311 }
12991312 else {
@@ -1309,7 +1322,7 @@ class BackendX86_64 : CompilerBackend {
13091322 output ~= format(" call __func__%s\n " , node.func.Sanitise());
13101323 }
13111324
1312- output ~= " pop r15 \n " ;
1325+ output ~= " pop r14 \n " ;
13131326
13141327 ++ blockCounter;
13151328
@@ -1318,7 +1331,7 @@ class BackendX86_64 : CompilerBackend {
13181331 output ~= format(" je __catch_%d_end\n " , blockCounter);
13191332
13201333 // function errored, assume that all it did was consume parameters
1321- output ~= format( " lea r15, [r15 - %d] \n " , stackEffect) ;
1334+ output ~= " mov r15, r14 \n " ;
13221335
13231336 // create scope
13241337 auto oldVars = variables.dup ;
0 commit comments