Skip to content

Commit 086e2af

Browse files
committed
make C interop fully work
1 parent 0ff6d9c commit 086e2af

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

source/backends/rm86.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ class BackendRM86 : CompilerBackend {
320320
output ~= format("jne __func__%s\n", Sanitise("__rm86_exception"));
321321
}
322322
else {
323-
output ~= "mov si, di\n";
323+
output ~= "mov si, di\n";
324324
CompileReturn(node);
325325
}
326326
}

source/backends/uxn.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ class BackendUXN : CompilerBackend {
275275
output ~= format(";func__%s JCN2\n", Sanitise("__uxn_exception"));
276276
}
277277
else {
278-
output ~= ".temp LDZ .System/wst DEO\n";
278+
output ~= ".temp LDZ .System/wst DEO\n";
279279
CompileReturn(node);
280280
}
281281
}

source/backends/x86_64.d

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,11 +510,24 @@ class BackendX86_64 : CompilerBackend {
510510
"mov r9, [r15 - %d]\n", (word.params.length - 5) * 8
511511
);
512512
}
513-
output ~= format("sub r15, %d\n", word.params.length * 8);
514513

515-
// TODO: support more than 6 parameters
514+
// align stack pointer
515+
output ~= "mov rbp, rsp\n";
516+
output ~= "and rsp, 0xFFFFFFFFFFFFFFF0\n";
517+
518+
if (word.params.length > 6) {
519+
// push parameters
520+
foreach_reverse (i ; 6 .. word.params.length) {
521+
output ~= format(
522+
"push qword [r15 - %d]\n", (word.params.length - i) * 8
523+
);
524+
}
525+
}
526+
// remove parameters
527+
output ~= format("sub r15, %d\n", word.params.length * 8);
516528

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

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

0 commit comments

Comments
 (0)