Skip to content

Commit d7b9015

Browse files
committed
fix arm64 maybe
1 parent f5f69f4 commit d7b9015

File tree

5 files changed

+56
-18
lines changed

5 files changed

+56
-18
lines changed

source/backends/arm64.d

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

source/backends/lua.d

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,14 @@ class BackendLua : CompilerBackend {
216216
}
217217
}
218218
else {
219-
if (word.error) {
219+
if (word.error && words[thisFunc].error) {
220220
output ~= "vsp = vsp - 1\n";
221-
output ~= "mem[vsp] = dsp\n";
221+
output ~= format("mem[vsp] = dsp - %d\n", word.params.length);
222222
}
223223

224224
output ~= format("func__%s();\n", node.name.Sanitise());
225225

226-
if (word.error) {
226+
if (word.error && words[thisFunc].error) {
227227
output ~= "dsp = mem[vsp]\n";
228228
output ~= "vsp = vsp + 1\n";
229229
}
@@ -888,6 +888,7 @@ class BackendLua : CompilerBackend {
888888
output ~= format("func__%s()\n", node.func.Sanitise());
889889
}
890890

891+
output ~= "regA = mem[vsp]\n";
891892
output ~= "vsp = vsp + 1\n";
892893

893894
++ blockCounter;
@@ -899,6 +900,9 @@ class BackendLua : CompilerBackend {
899900
output ~= format("goto catch_%d_end\n", blockCounter);
900901
output ~= "end\n";
901902

903+
// function errored, assume that all it did was consume parameters
904+
output ~= "dsp = regA\n";
905+
902906
// create scope
903907
auto oldVars = variables.dup;
904908
auto oldSize = GetStackSize();

source/backends/rm86.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ class BackendRM86 : CompilerBackend {
282282
output ~= format("call %s\n", node.name);
283283
}
284284
else {
285-
if (words[thisFunc].error) {
285+
if (word.error && words[thisFunc].error) {
286286
size_t paramSize = word.params.length * 2;
287287

288288
if (paramSize != 0) {
@@ -296,7 +296,7 @@ class BackendRM86 : CompilerBackend {
296296

297297
output ~= format("call __func__%s\n", node.name.Sanitise());
298298

299-
if (words[thisFunc].error) {
299+
if (word.error && words[thisFunc].error) {
300300
output ~= "pop si\n";
301301
}
302302
}

source/backends/uxn.d

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class BackendUXN : CompilerBackend {
120120
}
121121

122122
override void Init() {
123-
output ~= "|0 @vsp $2 @arraySrc $2 @arrayDest $2\n";
123+
output ~= "|0 @vsp $2 @arraySrc $2 @arrayDest $2 @temp $2\n";
124124
output ~= "|100\n";
125125
output ~= "@on-reset\n";
126126
output ~= " #ffff .vsp STZ2\n";
@@ -237,7 +237,24 @@ class BackendUXN : CompilerBackend {
237237
output ~= format("%s\n", node.name);
238238
}
239239
else {
240+
if (word.error && words[thisFunc].error) {
241+
size_t paramSize = word.params.length * 2;
242+
243+
if (paramSize != 0) {
244+
output ~= format(
245+
"LITr -System/wst DEIr LITr %.2x SUBr\n", paramSize
246+
);
247+
}
248+
else {
249+
output ~= "LITr -System/wst DEIr\n";
250+
}
251+
}
252+
240253
output ~= format("func__%s\n", node.name.Sanitise());
254+
255+
if (word.error && words[thisFunc].error) {
256+
output ~= "LITr -System/wst DEOr\n";
257+
}
241258
}
242259
}
243260

@@ -918,6 +935,8 @@ class BackendUXN : CompilerBackend {
918935
Error(node.error, "Non-callisto functions can't throw");
919936
}
920937

938+
size_t paramSize = word.params.length * 2;
939+
921940
if (word.params.length > 0) {
922941
output ~= format(
923942
"LITr -System/wst DEIr LITr %.2x SUBr\n", word.params.length * 2
@@ -936,12 +955,15 @@ class BackendUXN : CompilerBackend {
936955
output ~= format("func__%s\n", node.func.Sanitise());
937956
}
938957

958+
output ~= "LITr -temp STZr\n";
939959

940960
++ blockCounter;
941961

942962
output ~= format(";global_%s LDA2 #0000 EQU2\n", Sanitise("_cal_exception"));
943963
output ~= format(";catch_%d_end JCN2\n", blockCounter);
944-
output ~= "LITr -System/wst DEOr\n";
964+
965+
// function errored, assume that all it did was consume parameters
966+
output ~= ".temp LDZ .System/wst DEO\n";
945967

946968
// create scope
947969
auto oldVars = variables.dup;

source/backends/x86_64.d

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ class BackendX86_64 : CompilerBackend {
522522
}
523523
}
524524
else {
525-
if (words[thisFunc].error) {
525+
if (word.error && words[thisFunc].error) {
526526
size_t paramSize = word.params.length * 8;
527527

528528
if (paramSize != 0) {
@@ -536,8 +536,8 @@ class BackendX86_64 : CompilerBackend {
536536

537537
output ~= format("call __func__%s\n", node.name.Sanitise());
538538

539-
if (words[thisFunc].error) {
540-
output ~= "pop r15\n";
539+
if (word.error && words[thisFunc].error) {
540+
output ~= "pop r14\n";
541541
}
542542
}
543543
}
@@ -559,6 +559,7 @@ class BackendX86_64 : CompilerBackend {
559559
output ~= format("jne __func__%s\n", Sanitise("__x86_64_exception"));
560560
}
561561
else {
562+
output ~= "mov r15, r14\n";
562563
CompileReturn(node);
563564
}
564565
}

0 commit comments

Comments
 (0)