harec

[hare] Hare compiler, written in C11 for POSIX OSs
Log | Files | Refs | README | LICENSE

commit 42f5397633678bf55c57a86190e310a88d81ee8e
parent bedd275fb46fd85919b64e1bc6d97663ce408168
Author: Bor Grošelj Simić <bgs@turminal.net>
Date:   Tue,  7 Feb 2023 05:03:06 +0100

eval_binarithm: reuse BIN_LEQUAL branch for BIN_NEQUAL

Signed-off-by: Bor Grošelj Simić <bgs@turminal.net>

Diffstat:
Msrc/eval.c | 26+++++---------------------
1 file changed, 5 insertions(+), 21 deletions(-)

diff --git a/src/eval.c b/src/eval.c @@ -192,6 +192,7 @@ eval_binarithm(struct context *ctx, struct expression *in, struct expression *ou // Type promotion is lowered in check assert(lvalue.result->storage == rvalue.result->storage); + bool neg = false; switch (in->binarithm.op) { case BIN_BAND: assert(type_is_integer(lvalue.result)); @@ -323,6 +324,9 @@ eval_binarithm(struct context *ctx, struct expression *in, struct expression *ou && type_dealias(rvalue.result)->storage == STORAGE_BOOL); bval = blval && brval; break; + case BIN_NEQUAL: + neg = true; + /* fallthrough */ case BIN_LEQUAL: if (type_is_float(lvalue.result)) { bval = ftrunc(lvalue.result, flval) == ftrunc(rvalue.result, frval); @@ -343,6 +347,7 @@ eval_binarithm(struct context *ctx, struct expression *in, struct expression *ou lvalue.constant.string.len) == 0; } } + bval = bval != neg; break; case BIN_LESS: if (type_is_float(lvalue.result)) { @@ -374,27 +379,6 @@ eval_binarithm(struct context *ctx, struct expression *in, struct expression *ou && type_dealias(rvalue.result)->storage == STORAGE_BOOL); bval = blval != brval; break; - case BIN_NEQUAL: - if (type_is_float(lvalue.result)) { - bval = ftrunc(lvalue.result, flval) != ftrunc(rvalue.result, frval); - } else if (type_is_signed(lvalue.result)) { - bval = itrunc(lvalue.result, ilval) != itrunc(rvalue.result, irval); - } else if (type_is_integer(lvalue.result) - || type_dealias(lvalue.result)->storage == STORAGE_POINTER) { - bval = itrunc(lvalue.result, ulval) != itrunc(rvalue.result, urval); - } else if (lvalue.result->storage == STORAGE_BOOL) { - bval = lvalue.constant.bval != rvalue.constant.bval; - } else { - assert(type_dealias(lvalue.result)->storage == STORAGE_STRING); - if (lvalue.constant.string.len != rvalue.constant.string.len) { - bval = true; - } else { - bval = memcmp(lvalue.constant.string.value, - rvalue.constant.string.value, - lvalue.constant.string.len) != 0; - } - } - break; } if (type_is_float(in->result)) { out->constant.fval = ftrunc(in->result, fval);