aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMustafa Quraish <[email protected]>2022-02-07 03:02:39 -0500
committerMustafa Quraish <[email protected]>2022-02-07 03:18:08 -0500
commit3817688851fae07b1d6a13ba2ce1906fc9811f8f (patch)
treebb936b224cada39dc7ede856d9f15a4000950526 /src
parentAdd missing files to self-hosted directory (diff)
downloadcup-3817688851fae07b1d6a13ba2ce1906fc9811f8f.tar.xz
cup-3817688851fae07b1d6a13ba2ce1906fc9811f8f.zip
[cup] Self-hosting is now possible! Make some tweaks to match C output
A bit of a chonky commit, but this ports over the remaining (well, almost) everything from the C implementation to the self-hosted compiler. The only things that really remain right now are (1) defer support and (2) support for constants in local scopes. There were used barely enough so for now their uses have been removed, but I'll implement them back later. Not sure how useful (2) is though.
Diffstat (limited to 'src')
-rw-r--r--src/builtins.c4
-rw-r--r--src/generator.c1
2 files changed, 2 insertions, 3 deletions
diff --git a/src/builtins.c b/src/builtins.c
index 58e907e..3caf753 100644
--- a/src/builtins.c
+++ b/src/builtins.c
@@ -102,7 +102,7 @@ static void generate_custom_builtins(FILE *out)
" mov rdi, [rsp+8]\n"
" mov r9, -3689348814741910323\n"
" sub rsp, 40\n"
- " mov BYTE [rsp+31], 10\n"
+ " mov byte [rsp+31], 10\n"
" lea rcx, [rsp+30]\n"
" mov qword rbx, 0\n"
".L2:\n"
@@ -116,7 +116,7 @@ static void generate_custom_builtins(FILE *out)
" add rsi, rsi\n"
" sub rax, rsi\n"
" add eax, 48\n"
- " mov BYTE [rcx], al\n"
+ " mov byte [rcx], al\n"
" mov rax, rdi\n"
" mov rdi, rdx\n"
" mov rdx, rcx\n"
diff --git a/src/generator.c b/src/generator.c
index 59a193e..c52817c 100644
--- a/src/generator.c
+++ b/src/generator.c
@@ -317,7 +317,6 @@ void generate_expr_into_rax(Node *expr, FILE *out)
generate_expr_into_rax(expr->conditional.do_then, out);
fprintf(out, " jmp .cond_end_%d\n", cur_label);
fprintf(out, ".cond_else_%d:\n", cur_label);
- generate_expr_into_rax(expr->binary.right, out);
// Booleanize the result
generate_expr_into_rax(expr->conditional.do_else, out);
fprintf(out, ".cond_end_%d:\n", cur_label);