From 81a0df76cbcd46799134e688dabb8dc870da5351 Mon Sep 17 00:00:00 2001 From: Mustafa Quraish Date: Sat, 5 Feb 2022 01:38:34 -0500 Subject: Add support for some more binary ops: |, &, ^ --- src/generator.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/generator.c') 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 -- cgit v1.2.3