aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--builtins/macros.h3
-rw-r--r--builtins/tomo.h20
-rw-r--r--compile.c15
3 files changed, 14 insertions, 24 deletions
diff --git a/builtins/macros.h b/builtins/macros.h
index c6f474ec..6f9af8c9 100644
--- a/builtins/macros.h
+++ b/builtins/macros.h
@@ -16,9 +16,6 @@
$obj.$tag == $tag$##type_name##$##tag_name ? &$obj.tag_name : NULL; })
-#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"))
diff --git a/builtins/tomo.h b/builtins/tomo.h
index dd00c628..2676037f 100644
--- a/builtins/tomo.h
+++ b/builtins/tomo.h
@@ -27,24 +27,4 @@
#include "text.h"
#include "types.h"
-#define $heap(x) (__typeof(x)*)memcpy(GC_MALLOC(sizeof(x)), (__typeof(x)[1]){x}, sizeof(x))
-#define $stack(x) (__typeof(x)*)((__typeof(x)[1]){x})
-#define $tagged(obj_expr, type_name, tag_name) ({ __typeof(obj_expr) $obj = obj_expr; \
- $obj.$tag == $tag$##type_name##$##tag_name ? &$obj.tag_name : NULL; })
-
-
-#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)))
-#define mod(x, n) ((x) % (n))
-#define mod1(x, n) (((x) % (n)) + (__typeof(x))1)
-#define $cmp(x, y, info) (_Generic(x, int8_t: (x>0)-(y>0), int16_t: (x>0)-(y>0), int32_t: (x>0)-(y>0), int64_t: (x>0)-(y>0), bool: (x>0)-(y>0), \
- CORD: CORD_cmp((CORD)x, (CORD)y), char*: strcmp((char*)x, (char*)y), default: generic_compare($stack(x), $stack(y), info)))
-
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/compile.c b/compile.c
index bf0e7955..5f30d815 100644
--- a/compile.c
+++ b/compile.c
@@ -783,7 +783,20 @@ CORD compile(env_t *env, ast_t *ast)
}
break;
}
- case Not: return CORD_asprintf("not(%r)", compile(env, Match(ast, Not)->value));
+ case Not: {
+ type_t *t = get_type(env, ast);
+ ast_t *value = Match(ast, Not)->value;
+ if (t->tag == BoolType)
+ return CORD_all("!(", compile(env, value), ")");
+ else if (t->tag == IntType)
+ return CORD_all("~(", compile(env, value), ")");
+ else if (t->tag == ArrayType || t->tag == TableType)
+ return CORD_all("!(", compile(env, WrapAST(ast, Length, value)), ")");
+ else if (t->tag == TextType)
+ return CORD_all("!(", compile(env, value), ")");
+ else
+ code_err(ast, "I don't know how to negate values of type %T", t);
+ }
case Negative: return CORD_asprintf("-(%r)", compile(env, Match(ast, Negative)->value));
case HeapAllocate: return CORD_asprintf("$heap(%r)", compile(env, Match(ast, HeapAllocate)->value));
case StackReference: {