Skip to content

Commit

Permalink
fix arm64 maybe
Browse files Browse the repository at this point in the history
  • Loading branch information
MESYETI committed Nov 15, 2024
1 parent f5f69f4 commit d7b9015
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 18 deletions.
27 changes: 19 additions & 8 deletions source/backends/arm64.d
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
}
Expand All @@ -513,6 +521,7 @@ class BackendARM64 : CompilerBackend {
output ~= format("bne __func__%s\n", Sanitise("__arm64_exception"));
}
else {
output ~= "mov x19, x15\n";
CompileReturn(node);
}
}
Expand Down Expand Up @@ -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";
Expand All @@ -1251,15 +1260,17 @@ 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;

LoadAddress("x9", "__global_" ~ Sanitise("_cal_exception"));
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;
Expand Down
10 changes: 7 additions & 3 deletions source/backends/lua.d
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions source/backends/rm86.d
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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";
}
}
Expand Down
26 changes: 24 additions & 2 deletions source/backends/uxn.d
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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";
}
}
}

Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions source/backends/x86_64.d
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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";
}
}
}
Expand All @@ -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);
}
}
Expand Down

0 comments on commit d7b9015

Please sign in to comment.