aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-11-16 20:32:43 +0100
committerBad Diode <bd@badd10de.dev>2021-11-16 20:32:43 +0100
commit3481ac42896ae7c5a7b40bf456cd203edeeefe4a (patch)
tree782cfbddfbd05b03592a2dd7eb88eead60884920
parent0acaf0c98601e7dc8fd401a144ac85b46d040763 (diff)
downloadbdl-3481ac42896ae7c5a7b40bf456cd203edeeefe4a.tar.gz
bdl-3481ac42896ae7c5a7b40bf456cd203edeeefe4a.zip
Replace `call` with `jmp` in preparation for TCO
-rw-r--r--src/compiler.h11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/compiler.h b/src/compiler.h
index 3d61833..d1952ed 100644
--- a/src/compiler.h
+++ b/src/compiler.h
@@ -379,11 +379,15 @@ compile_call(Object *obj) {
379 compile_object(obj->head); 379 compile_object(obj->head);
380 } 380 }
381 381
382 char *lab_end = generate_label("BDLL");
382 context_printf(" mov rax, [rsp + %zu]\n", 8 * offset); 383 context_printf(" mov rax, [rsp + %zu]\n", 8 * offset);
383 context_printf(" call rax\n"); 384 context_printf(" lea rcx, [%s]\n", lab_end);
385 context_printf(" push rcx\n");
386 context_printf(" jmp rax\n");
387 context_printf("%s:\n", lab_end);
384 388
385 // Restore stack to previous location and store the result on top. 389 // Restore stack to previous location and store the result on top.
386 context_printf(" add rsp, %zu\n", 8 * (offset + 1)); 390 context_printf(" add rsp, %zu\n", 8 * (offset + 2));
387 context_printf(" push rax\n"); 391 context_printf(" push rax\n");
388 context_printf(" ;; <-- compile_call\n"); 392 context_printf(" ;; <-- compile_call\n");
389} 393}
@@ -531,10 +535,11 @@ compile_lambda(Object *obj) {
531 context_printf(" pop rax\n"); 535 context_printf(" pop rax\n");
532 536
533 // Restore the previous call frame. 537 // Restore the previous call frame.
538 context_printf(" mov rdi, [rbp + 8]\n");
534 context_printf(" mov rsp, rbp\n"); 539 context_printf(" mov rsp, rbp\n");
535 context_printf(" add rsp, %zu\n", 8 * array_size(current_env->locals)); 540 context_printf(" add rsp, %zu\n", 8 * array_size(current_env->locals));
536 context_printf(" pop rbp\n"); 541 context_printf(" pop rbp\n");
537 context_printf(" ret\n"); 542 context_printf(" jmp rdi\n");
538 context_printf("\n"); 543 context_printf("\n");
539 544
540 // Restore previous compilation context. 545 // Restore previous compilation context.