aboutsummaryrefslogtreecommitdiff
path: root/src/generator.c
diff options
context:
space:
mode:
authorMustafa Quraish <[email protected]>2022-02-05 01:38:34 -0500
committerMustafa Quraish <[email protected]>2022-02-05 08:56:15 -0500
commit81a0df76cbcd46799134e688dabb8dc870da5351 (patch)
treec272607d270b3ae8f1ba95cb6f6b28c9d0bc6075 /src/generator.c
parentMiscellaneous stdlib additions (diff)
downloadcup-81a0df76cbcd46799134e688dabb8dc870da5351.tar.xz
cup-81a0df76cbcd46799134e688dabb8dc870da5351.zip
Add support for some more binary ops: |, &, ^
Diffstat (limited to 'src/generator.c')
-rw-r--r--src/generator.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/generator.c b/src/generator.c
index f5ae850..23cc315 100644
--- a/src/generator.c
+++ b/src/generator.c
@@ -256,6 +256,27 @@ void generate_expr_into_rax(Node *expr, FILE *out)
fprintf(out, " setge al\n");
fprintf(out, " movzx rax, al\n");
+ } else if (expr->type == OP_BWAND) {
+ generate_expr_into_rax(expr->binary.right, out);
+ fprintf(out, " push rax\n");
+ generate_expr_into_rax(expr->binary.left, out);
+ fprintf(out, " pop rbx\n");
+ fprintf(out, " and rax, rbx\n");
+
+ } else if (expr->type == OP_BWOR) {
+ generate_expr_into_rax(expr->binary.right, out);
+ fprintf(out, " push rax\n");
+ generate_expr_into_rax(expr->binary.left, out);
+ fprintf(out, " pop rbx\n");
+ fprintf(out, " or rax, rbx\n");
+
+ } else if (expr->type == OP_XOR) {
+ generate_expr_into_rax(expr->binary.right, out);
+ fprintf(out, " push rax\n");
+ generate_expr_into_rax(expr->binary.left, out);
+ fprintf(out, " pop rbx\n");
+ fprintf(out, " xor rax, rbx\n");
+
// Note: These are different because of short-circuit evaluation!
} else if (expr->type == OP_OR) {
generate_expr_into_rax(expr->binary.left, out);
@@ -287,7 +308,7 @@ void generate_expr_into_rax(Node *expr, FILE *out)
fprintf(out, ".and_end_%d:\n", label_counter);
label_counter++;
- } else if (expr->type == AST_CONDITIONAL) {
+ } else if (expr->type == AST_CONDITIONAL) {
int cur_label = label_counter++;
generate_expr_into_rax(expr->conditional.cond, out);
// If left is false, we can short-circuit