commit 6baaac7d96c00edf9270affd321a9c624af49a36
parent e73537ad005511f07573d10522a6e7403b2b81f2
Author: m21c <ho*******@gmail.com>
Date: Mon, 22 Jun 2026 23:15:48 +0200
added islogicaltype based on isarithtype
Diffstat:
| M | compiler.c | | | 38 | ++++++++++++++++++++++++++++++++++---- |
1 file changed, 34 insertions(+), 4 deletions(-)
diff --git a/compiler.c b/compiler.c
@@ -4166,6 +4166,36 @@ isarithtype(Type *ty)
}
}
+/* @note essentially arithmetic + reference type */
+static bool
+islogicaltype(Type *ty)
+{
+ switch (ty->kind) {
+ case TBOOL:
+ case TINFER: case TUINFER:
+ case TS8: case TU8:
+ case TS16: case TU16:
+ case TS32: case TU32:
+ case TS64: case TU64:
+ case TF32: case TF64:
+ case TPTR:
+ /* @todo add ranges ? */
+ case TERRTYPE: /* avoiding error-reporting on error-type */
+ return true;
+
+ /* FIXME(m21c): This *just* tests wether a tuple only contains types of
+ * certain kinds. In order to check wether two tuple-types
+ * are compatible (for casting), another function has to
+ * be implemented. */
+ case TTUPLE:
+ return islogicaltype(ty->target)
+ && islogicaltype(ty->u.rtarget);
+
+ default:
+ return false;
+ }
+}
+
static bool
isunsignedtype(Type *ty)
{
@@ -4817,8 +4847,8 @@ typecheck(Env *env, Node *expr)
return expr;
case OLNOT:
- reporton(!isarithtype(lhs->type),
- &lhs->loc, "expression is not of arithmetic type");
+ reporton(!islogicaltype(lhs->type),
+ &lhs->loc, "expression is not of logical type");
expr->type = primitive(TBOOL);
expr->lhs = conv(env, lhs); /* cannot be wrap(expr->type, lhs) */
@@ -4886,8 +4916,8 @@ typecheck(Env *env, Node *expr)
return expr;
case OLAND: case OLOR:
- reporton(!isarithtype(lhs->type) || !isarithtype(rhs->type),
- &expr->loc, "expression is not of arithmetic type");
+ reporton(!islogicaltype(lhs->type) || !islogicaltype(rhs->type),
+ &expr->loc, "expression is not of logical type");
expr->type = primitive(TBOOL);
expr->lhs = wrap(env, expr->type, lhs);