summaryrefslogtreecommitdiff
path: root/types.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2019-09-25 14:46:25 -0400
committerLeo Tenenbaum <pommicket@gmail.com>2019-09-25 14:46:25 -0400
commitb7fe781138c1a775cc44ec1448e94305b3b8a0dd (patch)
tree395f4d7a34d48ef0c8a8aa2de4a9ccfe53678d60 /types.c
parent53a2729e91e2df2672e01c15ba8cb24544843827 (diff)
added unary not
Diffstat (limited to 'types.c')
-rw-r--r--types.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/types.c b/types.c
index 5d1148b..1777f9b 100644
--- a/types.c
+++ b/types.c
@@ -257,9 +257,12 @@ static bool type_resolve(Typer *tr, Type *t) {
Value val;
Expression *n_expr = t->arr.n_expr;
if (!types_expr(tr, n_expr)) return false;
- if (n_expr->type.kind != TYPE_BUILTIN || !type_builtin_is_integer(n_expr->type.builtin))
+ if (n_expr->type.kind != TYPE_BUILTIN || !type_builtin_is_integer(n_expr->type.builtin)) {
+ char *s = type_to_str(&n_expr->type);
+ err_print(n_expr->where, "Cannot use type %s as the size of an array (it's not an integer type).", s);
+ free(s);
return false;
-
+ }
if (!eval_expr(n_expr, &val)) return false; /* resolve N */
Integer size = val.intv;
if (size < 0)
@@ -551,6 +554,15 @@ static bool types_expr(Typer *tr, Expression *e) {
}
*t = *of_type->ptr.of;
break;
+ case UNARY_NOT:
+ if (!type_can_be_truthy(of_type)) {
+ char *s = type_to_str(of_type);
+ err_print(e->where, "Type '%s' cannot be truthy, so the not operator cannot be applied to it.", s);
+ free(s);
+ return false;
+ }
+ t->kind = TYPE_BUILTIN;
+ t->builtin = BUILTIN_BOOL;
}
} break;
case EXPR_BINARY_OP: {