summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arith.c82
1 files changed, 47 insertions, 35 deletions
diff --git a/arith.c b/arith.c
index 5d990268..157d33d8 100644
--- a/arith.c
+++ b/arith.c
@@ -1954,6 +1954,24 @@ static void seq_lt_compat_check(seq_iter_t *ita, seq_iter_t *itb,
}
}
+static NORETURN void arg_type_error_1(val a, val self)
+{
+ uw_throwf(error_s, lit("~a: unsupported operand type: ~s"),
+ self, a, nao);
+}
+
+static NORETURN void arg_type_error_2(val a, val b, val self)
+{
+ uw_throwf(error_s, lit("~a: unsupported operand types: ~s ~s"),
+ self, a, b, nao);
+}
+
+static NORETURN void arg_type_error_3(val a, val b, val c, val self)
+{
+ uw_throwf(error_s, lit("~a: unsupported operand types: ~s ~s ~s"),
+ self, a, b, c, nao);
+}
+
static val seq_lt(val self, val aseq, val bseq)
{
seq_iter_t ita, itb;
@@ -2579,8 +2597,7 @@ inval:
if (cobjp(base))
return do_ternary_method(self, self, base, exp, mod);
- uw_throwf(error_s, lit("~a: non-integral operands ~s ~s ~s"),
- self, base, exp, mod, nao);
+ arg_type_error_3(base, exp, mod, self);
bad:
do_mp_error(self, mpe);
}
@@ -2624,7 +2641,8 @@ val isqrt(val anum)
break;
}
- uw_throwf(error_s, lit("~s: non-integer operand ~s"), self, anum, nao);
+ arg_type_error_1(anum, self);
+
negop:
uw_throwf(error_s, lit("~s: negative operand"), self, nao);
}
@@ -2681,7 +2699,7 @@ val square(val anum)
break;
}
- uw_throwf(error_s, lit("~a: invalid operand ~s"), self, anum, nao);
+ arg_type_error_1(anum, self);
}
val gcd(val anum, val bnum)
@@ -2760,12 +2778,11 @@ val gcd(val anum, val bnum)
return normalize(n);
}
default:
- uw_throwf(error_s, lit("gcd: non-integral operands ~s ~s"),
- anum, bnum, nao);
+ arg_type_error_2(anum, bnum, self);
}
- uw_throwf(error_s, lit("gcd: operation failed on ~s ~s"),
- anum, bnum, nao);
+ uw_throwf(error_s, lit("~s: operation failed on ~s ~s"),
+ self, anum, bnum, nao);
}
val lcm(val anum, val bnum)
@@ -2781,17 +2798,17 @@ val lcm(val anum, val bnum)
val divides(val d, val n)
{
+ val self = lit("divides");
+
if (n == zero) {
if (!integerp(d))
- uw_throwf(error_s, lit("divides: ~s isn't an integer"),
- d, nao);
+ arg_type_error_1(d, self);
return tnil(!zerop(d));
}
if (d == one) {
if (!integerp(n))
- uw_throwf(error_s, lit("divides: ~s isn't an integer"),
- n, nao);
+ arg_type_error_1(n, self);
return t;
}
@@ -3614,7 +3631,7 @@ val logand(val a, val b)
case TYPE_PAIR(BUF, BUF):
return buf_and(a, b);
default:
- uw_throwf(error_s, lit("~a: non-integral operands ~s ~s"), self, a, b, nao);
+ arg_type_error_2(a, b, self);
}
bad:
@@ -3672,7 +3689,7 @@ val logior(val a, val b)
case TYPE_PAIR(BUF, BUF):
return buf_or(b, a);
default:
- uw_throwf(error_s, lit("~a: non-integral operands ~s ~s"), self, a, b, nao);
+ arg_type_error_2(a, b, self);
}
bad:
@@ -3730,7 +3747,7 @@ val logxor(val a, val b)
case TYPE_PAIR(BUF, BUF):
return buf_xor(b, a);
default:
- uw_throwf(error_s, lit("~a: non-integral operands ~s ~s"), self, a, b, nao);
+ arg_type_error_2(a, b, self);
}
bad:
@@ -3739,6 +3756,7 @@ bad:
val logxor_old(val a, val b)
{
+ val self = lit("logxor");
val c;
if (zerop(a) && zerop(b))
@@ -3787,11 +3805,11 @@ val logxor_old(val a, val b)
goto bad;
return normalize(c);
default:
- uw_throwf(error_s, lit("logxor: non-integral operands ~s ~s"), a, b, nao);
+ arg_type_error_2(a, b, self);
}
bad:
- uw_throwf(error_s, lit("logxor: operation failed on ~s ~s"), a, b, nao);
+ uw_throwf(error_s, lit("~s: operation failed on ~s ~s"), a, b, nao);
}
val logtest(val a, val b)
@@ -3851,7 +3869,7 @@ bad2:
uw_throwf(error_s, lit("~a: bits value ~s is not a fixnum"), bits, nao);
bad3:
- uw_throwf(error_s, lit("~a: non-integral operand ~s"), self, a, nao);
+ arg_type_error_1(a, self);
}
val lognot(val a, val bits)
@@ -3875,7 +3893,7 @@ val lognot(val a, val bits)
case COBJ:
return do_unary_method(self, self, a);
default:
- uw_throwf(error_s, lit("~a: non-integral operand ~s"), self, a, nao);
+ arg_type_error_1(a, self);
}
bad:
@@ -3930,7 +3948,7 @@ bad2:
uw_throwf(error_s, lit("~a: bits value ~s is not a fixnum"), self, bits, nao);
bad3:
- uw_throwf(error_s, lit("~a: non-integral operand ~s"), self, a, nao);
+ arg_type_error_1(a, self);
}
val sign_extend(val n, val nbits)
@@ -4064,7 +4082,7 @@ bad2:
uw_throwf(error_s, lit("~a: bits value ~s is not a fixnum"), self, bits, nao);
bad3:
- uw_throwf(error_s, lit("~a: non-integral operand ~s"), self, a, nao);
+ arg_type_error_1(a, self);
bad4:
uw_throwf(error_s, lit("~a: bit value too large ~s"), self, bits, nao);
@@ -4126,7 +4144,7 @@ bad:
uw_throwf(error_s, lit("~a: bit position ~s is not a fixnum"), self, bit, nao);
bad2:
- uw_throwf(error_s, lit("~a: non-integral operand ~s"), self, a, nao);
+ arg_type_error_1(a, self);
bad3:
do_mp_error(self, mpe);
@@ -4218,7 +4236,7 @@ val bitset(val n)
case COBJ:
return do_unary_method(self, self, n);
default:
- uw_throwf(error_s, lit("~a: non-integral operand ~s"), self, n, nao);
+ arg_type_error_1(n, self);
}
}
@@ -4265,7 +4283,7 @@ val logcount(val n)
case COBJ:
return do_unary_method(self, self, n);
default:
- uw_throwf(error_s, lit("~a: non-integral operand ~s"), self, n, nao);
+ arg_type_error_1(n, self);
}
}
@@ -4531,7 +4549,7 @@ val width(val obj)
default:
break;
}
- uw_throwf(error_s, lit("~a: ~s isn't an integer"), self, obj, nao);
+ arg_type_error_1(obj, self);
}
val bits(val obj)
@@ -4595,8 +4613,7 @@ val poly(val x, val seq)
seq_info_t si = seq_info(seq);
if (!numberp(x))
- uw_throwf(error_s, lit("~a: bad argument ~s; number required"),
- self, x, nao);
+ arg_type_error_1(x, self);
switch (si.kind) {
case SEQ_NIL:
@@ -4621,9 +4638,7 @@ val poly(val x, val seq)
return acc;
}
default:
- uw_throwf(error_s, lit("~a: bad argument ~s; poly wants a list or vector!"),
- self, seq, nao);
-
+ arg_type_error_1(seq, self);
}
}
@@ -4635,8 +4650,7 @@ val rpoly(val x, val seq)
seq_info_t si = seq_info(seq);
if (!numberp(x))
- uw_throwf(error_s, lit("~a: bad argument ~s; poly wants a number!"),
- self, x, nao);
+ arg_type_error_1(x, self);
switch (si.kind) {
case SEQ_NIL:
@@ -4666,9 +4680,7 @@ val rpoly(val x, val seq)
return acc;
}
default:
- uw_throwf(error_s, lit("~a: bad argument ~s; poly wants a list or vector!"),
- self, seq, nao);
-
+ arg_type_error_1(seq, self);
}
return acc;