Skip to content

Commit

Permalink
make C interop fully work
Browse files Browse the repository at this point in the history
  • Loading branch information
yeti0904 committed Nov 20, 2024
1 parent 0ff6d9c commit 086e2af
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion source/backends/rm86.d
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ class BackendRM86 : CompilerBackend {
output ~= format("jne __func__%s\n", Sanitise("__rm86_exception"));
}
else {
output ~= "mov si, di\n";
output ~= "mov si, di\n";
CompileReturn(node);
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/backends/uxn.d
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ class BackendUXN : CompilerBackend {
output ~= format(";func__%s JCN2\n", Sanitise("__uxn_exception"));
}
else {
output ~= ".temp LDZ .System/wst DEO\n";
output ~= ".temp LDZ .System/wst DEO\n";
CompileReturn(node);
}
}
Expand Down
17 changes: 15 additions & 2 deletions source/backends/x86_64.d
Original file line number Diff line number Diff line change
Expand Up @@ -510,11 +510,24 @@ class BackendX86_64 : CompilerBackend {
"mov r9, [r15 - %d]\n", (word.params.length - 5) * 8
);
}
output ~= format("sub r15, %d\n", word.params.length * 8);

// TODO: support more than 6 parameters
// align stack pointer
output ~= "mov rbp, rsp\n";
output ~= "and rsp, 0xFFFFFFFFFFFFFFF0\n";

if (word.params.length > 6) {
// push parameters
foreach_reverse (i ; 6 .. word.params.length) {
output ~= format(
"push qword [r15 - %d]\n", (word.params.length - i) * 8
);
}
}
// remove parameters
output ~= format("sub r15, %d\n", word.params.length * 8);

output ~= format("call %s\n", ExternSymbol(word.symbolName));
output ~= "mov rsp, rbp\n";

if (!word.isVoid) {
output ~= "mov [r15], rax\n";
Expand Down

0 comments on commit 086e2af

Please sign in to comment.