aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-11-09 17:42:59 +0100
committerBad Diode <bd@badd10de.dev>2021-11-09 17:42:59 +0100
commited96e5e915c5380f0a073ed49d6786b07db68439 (patch)
treeb6c547806196844c8a5be5b9ae5db765327b24b7
parent12ae1f331e79f769f01d2aa70608868f16667516 (diff)
downloadbdl-ed96e5e915c5380f0a073ed49d6786b07db68439.tar.gz
bdl-ed96e5e915c5380f0a073ed49d6786b07db68439.zip
Add display functionality for lambda objects
-rw-r--r--src/compiler.h17
-rw-r--r--src/x86_64/prelude.asm18
2 files changed, 28 insertions, 7 deletions
diff --git a/src/compiler.h b/src/compiler.h
index 897b7bb..0223269 100644
--- a/src/compiler.h
+++ b/src/compiler.h
@@ -509,8 +509,15 @@ emit_bss_section(void) {
509void 509void
510emit_data_section(void) { 510emit_data_section(void) {
511 printf("section .data\n"); 511 printf("section .data\n");
512 printf("true_str: db \"true\", 10, 0, 0, 0\n"); 512 printf("true_str:\n db \"true\", 10\n");
513 printf("false_str: db \"false\", 10, 0, 0\n"); 513 printf(" alignb 8\n");
514 printf("false_str:\n db \"false\", 10\n");
515 printf(" alignb 8\n");
516 printf("lambda_str:\n");
517 char lambda_str[] = "#{lambda}";
518 printf(" dq %ld\n", sizeof(lambda_str));
519 printf(" db \"%s\", 10\n", lambda_str);
520 printf(" alignb 8\n");
514 for (size_t i = 0; i < array_size(constants); i++) { 521 for (size_t i = 0; i < array_size(constants); i++) {
515 // NOTE: Only supporting string constants for now. 522 // NOTE: Only supporting string constants for now.
516 Constant c = constants[i]; 523 Constant c = constants[i];
@@ -520,11 +527,7 @@ emit_data_section(void) {
520 printf("%s:\n", c.label); 527 printf("%s:\n", c.label);
521 printf(" dq %d\n", n + 1); 528 printf(" dq %d\n", n + 1);
522 printf(" db \"%.*s\", 10\n", n, c.obj->text.start); 529 printf(" db \"%.*s\", 10\n", n, c.obj->text.start);
523 // Ensure alignment to 8 bytes. 530 printf(" alignb 8\n");
524 int remainder = (n + 1) % 8;
525 if (remainder != 0) {
526 printf(" times %d db 0\n", 8 - (n + 1) % 8);
527 }
528 } 531 }
529 printf("\n"); 532 printf("\n");
530} 533}
diff --git a/src/x86_64/prelude.asm b/src/x86_64/prelude.asm
index abb069b..81a2633 100644
--- a/src/x86_64/prelude.asm
+++ b/src/x86_64/prelude.asm
@@ -82,6 +82,15 @@ printstring:
82 syscall 82 syscall
83 ret 83 ret
84 84
85printlambda:
86 mov rsi, lambda_str
87 mov rdx, [rsi]
88 add rsi, 8
89 mov rax, 1
90 mov rdi, 1
91 syscall
92 ret
93
85display: 94display:
86 ;; is nil? 95 ;; is nil?
87 mov rax, rdi 96 mov rax, rdi
@@ -106,6 +115,15 @@ not_bool:
106 ret 115 ret
107not_string: 116not_string:
108 117
118 ;; is lambda?
119 mov rax, rdi
120 and rax, LAMBDA_MASK
121 cmp rax, LAMBDA_TAG
122 jne not_lambda
123 call printlambda
124 ret
125not_lambda:
126
109 ;; is fixnum? 127 ;; is fixnum?
110 mov rax, rdi 128 mov rax, rdi
111 and rax, FIXNUM_MASK 129 and rax, FIXNUM_MASK