harec

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

commit e7dce90c1bcded8c6df2945eb5820e77632a172f
parent 5abd8e6b0525b1c6be004bca38b41e5f5cb36459
Author: Ember Sawady <ecs@d2evs.net>
Date:   Mon,  6 Feb 2023 16:34:21 +0000

Fix compile-time == and != for bools

Signed-off-by: Ember Sawady <ecs@d2evs.net>

Diffstat:
Msrc/eval.c | 4++++
Mtests/26-regression.ha | 1+
2 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/src/eval.c b/src/eval.c @@ -321,6 +321,8 @@ eval_binarithm(struct context *ctx, struct expression *in, struct expression *ou } 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) { @@ -370,6 +372,8 @@ eval_binarithm(struct context *ctx, struct expression *in, struct expression *ou } 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) { diff --git a/tests/26-regression.ha b/tests/26-regression.ha @@ -93,4 +93,5 @@ export fn main() void = { assert(rt::compile("let a = &0;") as rt::exited != rt::EXIT_SUCCESS); assert(rt::compile("def A: a = 1 % 1;") as rt::exited != rt::EXIT_SUCCESS); assert(rt::compile("def A: b = void;") as rt::exited != rt::EXIT_SUCCESS); + static assert(true == true && true != false); };