From d7b9015cc5ee159f3e00738ca4624623dba91287 Mon Sep 17 00:00:00 2001 From: MESYETI Date: Fri, 15 Nov 2024 10:24:52 +0000 Subject: [PATCH] fix arm64 maybe --- source/backends/arm64.d | 27 +++++++++++++++++++-------- source/backends/lua.d | 10 +++++++--- source/backends/rm86.d | 4 ++-- source/backends/uxn.d | 26 ++++++++++++++++++++++++-- source/backends/x86_64.d | 7 ++++--- 5 files changed, 56 insertions(+), 18 deletions(-) diff --git a/source/backends/arm64.d b/source/backends/arm64.d index 990af47..833c01e 100644 --- a/source/backends/arm64.d +++ b/source/backends/arm64.d @@ -483,14 +483,22 @@ class BackendARM64 : CompilerBackend { output ~= "mov sp, x9\n"; } else { - if (word.error) { - output ~= "str x19, [x20, #-8]!\n"; + if (word.error && words[thisFunc].error) { + size_t paramSize = word.params.length * 8; + + if (paramSize != 0) { + output ~= format("sub x15, x19, #%d", paramSize); + output ~= "str x15, [x20, #-8]!\n"; + } + else { + output ~= "str x19, [x20, #-8]!\n"; + } } output ~= format("bl __func__%s\n", node.name.Sanitise()); - if (word.error) { - output ~= "ldr x19, [x20], #8\n"; + if (word.error && words[thisFunc].error) { + output ~= "ldr x15, [x20], #8\n"; } } } @@ -513,6 +521,7 @@ class BackendARM64 : CompilerBackend { output ~= format("bne __func__%s\n", Sanitise("__arm64_exception")); } else { + output ~= "mov x19, x15\n"; CompileReturn(node); } } @@ -1235,8 +1244,8 @@ class BackendARM64 : CompilerBackend { size_t paramSize = word.params.length * 8; if (paramSize != 0) { - output ~= format("sub x21, x19, #%d\n", paramSize); - output ~= "str x21, [x20, #-8]!\n"; + output ~= format("sub x15, x19, #%d\n", paramSize); + output ~= "str x15, [x20, #-8]!\n"; } else { output ~= "str x19, [x20, #-8]!\n"; @@ -1251,7 +1260,7 @@ class BackendARM64 : CompilerBackend { output ~= format("bl __func__%s\n", node.func.Sanitise()); } - output ~= "ldr x19, [x20], #8\n"; + output ~= "ldr x15, [x20], #8\n"; ++ blockCounter; @@ -1259,7 +1268,9 @@ class BackendARM64 : CompilerBackend { output ~= "ldr x9, [x9]\n"; output ~= "cmp x9, #0\n"; output ~= format("beq __catch_%d_end\n", blockCounter); - output ~= "mov x19, x21\n"; + + // function errored, assume that all it did was consume parameters + output ~= "mov x19, x15\n"; // create scope auto oldVars = variables.dup; diff --git a/source/backends/lua.d b/source/backends/lua.d index 7381eda..9f1bdfe 100644 --- a/source/backends/lua.d +++ b/source/backends/lua.d @@ -216,14 +216,14 @@ class BackendLua : CompilerBackend { } } else { - if (word.error) { + if (word.error && words[thisFunc].error) { output ~= "vsp = vsp - 1\n"; - output ~= "mem[vsp] = dsp\n"; + output ~= format("mem[vsp] = dsp - %d\n", word.params.length); } output ~= format("func__%s();\n", node.name.Sanitise()); - if (word.error) { + if (word.error && words[thisFunc].error) { output ~= "dsp = mem[vsp]\n"; output ~= "vsp = vsp + 1\n"; } @@ -888,6 +888,7 @@ class BackendLua : CompilerBackend { output ~= format("func__%s()\n", node.func.Sanitise()); } + output ~= "regA = mem[vsp]\n"; output ~= "vsp = vsp + 1\n"; ++ blockCounter; @@ -899,6 +900,9 @@ class BackendLua : CompilerBackend { output ~= format("goto catch_%d_end\n", blockCounter); output ~= "end\n"; + // function errored, assume that all it did was consume parameters + output ~= "dsp = regA\n"; + // create scope auto oldVars = variables.dup; auto oldSize = GetStackSize(); diff --git a/source/backends/rm86.d b/source/backends/rm86.d index ba48965..f8fa571 100644 --- a/source/backends/rm86.d +++ b/source/backends/rm86.d @@ -282,7 +282,7 @@ class BackendRM86 : CompilerBackend { output ~= format("call %s\n", node.name); } else { - if (words[thisFunc].error) { + if (word.error && words[thisFunc].error) { size_t paramSize = word.params.length * 2; if (paramSize != 0) { @@ -296,7 +296,7 @@ class BackendRM86 : CompilerBackend { output ~= format("call __func__%s\n", node.name.Sanitise()); - if (words[thisFunc].error) { + if (word.error && words[thisFunc].error) { output ~= "pop si\n"; } } diff --git a/source/backends/uxn.d b/source/backends/uxn.d index e8714a8..277037f 100644 --- a/source/backends/uxn.d +++ b/source/backends/uxn.d @@ -120,7 +120,7 @@ class BackendUXN : CompilerBackend { } override void Init() { - output ~= "|0 @vsp $2 @arraySrc $2 @arrayDest $2\n"; + output ~= "|0 @vsp $2 @arraySrc $2 @arrayDest $2 @temp $2\n"; output ~= "|100\n"; output ~= "@on-reset\n"; output ~= " #ffff .vsp STZ2\n"; @@ -237,7 +237,24 @@ class BackendUXN : CompilerBackend { output ~= format("%s\n", node.name); } else { + if (word.error && words[thisFunc].error) { + size_t paramSize = word.params.length * 2; + + if (paramSize != 0) { + output ~= format( + "LITr -System/wst DEIr LITr %.2x SUBr\n", paramSize + ); + } + else { + output ~= "LITr -System/wst DEIr\n"; + } + } + output ~= format("func__%s\n", node.name.Sanitise()); + + if (word.error && words[thisFunc].error) { + output ~= "LITr -System/wst DEOr\n"; + } } } @@ -918,6 +935,8 @@ class BackendUXN : CompilerBackend { Error(node.error, "Non-callisto functions can't throw"); } + size_t paramSize = word.params.length * 2; + if (word.params.length > 0) { output ~= format( "LITr -System/wst DEIr LITr %.2x SUBr\n", word.params.length * 2 @@ -936,12 +955,15 @@ class BackendUXN : CompilerBackend { output ~= format("func__%s\n", node.func.Sanitise()); } + output ~= "LITr -temp STZr\n"; ++ blockCounter; output ~= format(";global_%s LDA2 #0000 EQU2\n", Sanitise("_cal_exception")); output ~= format(";catch_%d_end JCN2\n", blockCounter); - output ~= "LITr -System/wst DEOr\n"; + + // function errored, assume that all it did was consume parameters + output ~= ".temp LDZ .System/wst DEO\n"; // create scope auto oldVars = variables.dup; diff --git a/source/backends/x86_64.d b/source/backends/x86_64.d index 8efe0f7..ef3ca84 100644 --- a/source/backends/x86_64.d +++ b/source/backends/x86_64.d @@ -522,7 +522,7 @@ class BackendX86_64 : CompilerBackend { } } else { - if (words[thisFunc].error) { + if (word.error && words[thisFunc].error) { size_t paramSize = word.params.length * 8; if (paramSize != 0) { @@ -536,8 +536,8 @@ class BackendX86_64 : CompilerBackend { output ~= format("call __func__%s\n", node.name.Sanitise()); - if (words[thisFunc].error) { - output ~= "pop r15\n"; + if (word.error && words[thisFunc].error) { + output ~= "pop r14\n"; } } } @@ -559,6 +559,7 @@ class BackendX86_64 : CompilerBackend { output ~= format("jne __func__%s\n", Sanitise("__x86_64_exception")); } else { + output ~= "mov r15, r14\n"; CompileReturn(node); } }