aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-02-20 13:22:05 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-02-20 13:22:05 -0500
commitd915c5f5a256dcfa80444e0175a327570935b000 (patch)
treece559590d4d8045d872c4d51fda9431250ed3d75
parentf9cc44f145dd0c165010765791054666f973eff3 (diff)
Adjustments to 'not' behavior
-rw-r--r--nextlang.h7
1 files changed, 6 insertions, 1 deletions
diff --git a/nextlang.h b/nextlang.h
index f59ae272..a2baec57 100644
--- a/nextlang.h
+++ b/nextlang.h
@@ -44,7 +44,12 @@ CORD as_cord(void *x, bool use_color, const char *fmt, ...);
$obj.$tag == $tag$##type_name##$##tag_name ? &$obj.tag_name : NULL; })
-#define not(x) _Generic(x, bool: (bool)!(x), default: ~(x))
+#define not(x) _Generic(x, bool: (bool)!(x), int64_t: ~(x), int32_t: ~(x), int16_t: ~(x), int8_t: ~(x), \
+ array_t: ((x).length == 0), table_t: ((x).entries.length == 0), CORD: ((x) == CORD_EMPTY), \
+ default: _Static_assert(0, "Not supported"))
+#define Bool(x) _Generic(x, bool: (bool)(x), int64_t: (x != 0), int32_t: (x != 0), int16_t: (x != 0), int8_t: (x != 0), CORD: ((x) == CORD_EMPTY), \
+ array_t: ((x).length > 0), table_t: ((x).entries.length > 0), CORD: ((x) != CORD_EMPTY), \
+ default: _Static_assert(0, "Not supported"))
#define and(x, y) _Generic(x, bool: (bool)((x) && (y)), default: ((x) & (y)))
#define or(x, y) _Generic(x, bool: (bool)((x) || (y)), default: ((x) | (y)))
#define xor(x, y) _Generic(x, bool: (bool)((x) ^ (y)), default: ((x) ^ (y)))