aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.c
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-06-28 18:45:34 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-06-28 18:45:34 +0200
commit8e9ae1c325533818f43efa9577d15cc17295d9ee (patch)
treecd67e9e4d1e34014186c8e426a1729fd8ef6e9f7 /src/codegen.c
parent22c735178dc4126295e9ce376661bf2b38d3af0f (diff)
Try to properly support remainder
Diffstat (limited to 'src/codegen.c')
-rw-r--r--src/codegen.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/codegen.c b/src/codegen.c
index 2f07442..188275b 100644
--- a/src/codegen.c
+++ b/src/codegen.c
@@ -150,13 +150,11 @@ codegentypedexpr(struct cgctx ctx, idx_t i, type_t type, LLVMValueRef *outv)
if (!type.issigned && mpq_sgn(ctx.folds[i]) == -1)
err("Cannot convert negative value to unsigned type");
- mpz_ptr num, den;
- num = mpq_numref(ctx.folds[i]);
- den = mpq_denref(ctx.folds[i]);
- if (mpz_cmp_ui(den, 1) != 0)
- err("Invalid integer");
+ if (!MPQ_IS_WHOLE(ctx.folds[i]))
+ err("codegen: Invalid integer");
int cmp;
+ mpz_ptr num = mpq_numref(ctx.folds[i]);
assert(type.size != 0);
/* TODO: Can we make the first branch work when the type has the
same size as an unsigned long? */
@@ -243,7 +241,8 @@ codegentypedexpr(struct cgctx ctx, idx_t i, type_t type, LLVMValueRef *outv)
case ASTBINADD:
case ASTBINSUB:
case ASTBINMUL:
- case ASTBINDIV: {
+ case ASTBINDIV:
+ case ASTBINMOD: {
typedef LLVMValueRef llbfn(LLVMBuilderRef, LLVMValueRef, LLVMValueRef,
const char *);
static const struct binop {