From c5e01140d570f2712a6ad77028477ed789ffb0b6 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Wed, 2 Oct 2019 18:37:10 -0400 Subject: more eval (boolean ops) --- eval.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/eval.c b/eval.c index 3d4404a..0348fa2 100644 --- a/eval.c +++ b/eval.c @@ -155,6 +155,31 @@ static void eval_expr(Evaluator *ev, Expression *e, Value *v) { eval_binary_op_nums(builtin, op); \ default: assert(0); break; \ } + + +#define eval_binary_bool_op_one(low, up, op) \ + case BUILTIN_##up: \ + v->boolv = lhs.low op rhs.low; break + +#define eval_binary_bool_op_nums(builtin, op) \ + eval_binary_bool_op_one(i8, I8, op); \ + eval_binary_bool_op_one(i16, I16, op); \ + eval_binary_bool_op_one(i32, I32, op); \ + eval_binary_bool_op_one(i64, I64, op); \ + eval_binary_bool_op_one(u8, U8, op); \ + eval_binary_bool_op_one(u16, U16, op); \ + eval_binary_bool_op_one(u32, U32, op); \ + eval_binary_bool_op_one(u64, U64, op); \ + eval_binary_bool_op_one(f32, F32, op); \ + eval_binary_bool_op_one(f64, F64, op); + +#define eval_binary_bool_op_nums_only(op) \ + switch (builtin) { \ + eval_binary_bool_op_nums(builtin, op); \ + default: assert(0); break; \ + } + + switch (e->kind) { case EXPR_UNARY_OP: { @@ -187,6 +212,18 @@ static void eval_expr(Evaluator *ev, Expression *e, Value *v) { eval_binary_op_nums_only(*); break; case BINARY_DIV: eval_binary_op_nums_only(/); break; + case BINARY_LT: + eval_binary_bool_op_nums_only(<); break; + case BINARY_LE: + eval_binary_bool_op_nums_only(<=); break; + case BINARY_GT: + eval_binary_bool_op_nums_only(>); break; + case BINARY_GE: + eval_binary_bool_op_nums_only(>=); break; + case BINARY_EQ: + eval_binary_bool_op_nums_only(==); break; + case BINARY_NE: + eval_binary_bool_op_nums_only(!=); break; } } break; case EXPR_LITERAL_INT: -- cgit v1.2.3