Skip to content

Commit

Permalink
kernel: add Require(Small)Int(MayReplace) helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Oct 30, 2018
1 parent 0f2d63d commit 8b99f68
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 186 deletions.
36 changes: 36 additions & 0 deletions src/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,42 @@ extern Obj RACErrorHelper(int mayReturn,
} while (0)


/****************************************************************************
**
*F RequireInt
*/
#define RequireInt(funcname, op, argname) \
RequireArgumentCondition(funcname, op, argname, IS_INT(op), \
"must be an integer")


/****************************************************************************
**
*F RequireIntMayReplace
*/
#define RequireIntMayReplace(funcname, op, argname) \
RequireArgumentConditionMayReplace(funcname, op, argname, IS_INT(op), \
"must be an integer")


/****************************************************************************
**
*F RequireSmallInt
*/
#define RequireSmallInt(funcname, op, argname) \
RequireArgumentCondition(funcname, op, argname, IS_INTOBJ(op), \
"must be an integer")


/****************************************************************************
**
*F RequireSmallIntMayReplace
*/
#define RequireSmallIntMayReplace(funcname, op, argname) \
RequireArgumentConditionMayReplace(funcname, op, argname, IS_INTOBJ(op), \
"must be an integer")


/****************************************************************************
**
*F RequirePositiveSmallInt
Expand Down
6 changes: 1 addition & 5 deletions src/integer.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,7 @@ static Obj ObjInt_UIntInv( UInt i );

#define SIZE_INT_OR_INTOBJ(obj) (IS_INTOBJ(obj) ? 1 : SIZE_INT(obj))

#define REQUIRE_INT_ARG(funcname, argname, op) \
if ( !IS_INT(op) ) { \
ErrorMayQuit( funcname ": <" argname "> must be an integer (not a %s)", \
(Int)TNAM_OBJ(op), 0L ); \
}
#define REQUIRE_INT_ARG(funcname, argname, op) RequireInt(funcname, op, argname)

GAP_STATIC_ASSERT( sizeof(mp_limb_t) == sizeof(UInt), "gmp limb size incompatible with GAP word size");

Expand Down
14 changes: 2 additions & 12 deletions src/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,20 +512,10 @@ static ALWAYS_INLINE UInt ExecForRangeHelper(Stat stat, UInt nr)
/* evaluate the range */
VisitStatIfHooked(READ_STAT(stat, 1));
elm = EVAL_EXPR(READ_EXPR(READ_STAT(stat, 1), 0));
while ( ! IS_INTOBJ(elm) ) {
elm = ErrorReturnObj(
"Range: <first> must be an integer (not a %s)",
(Int)TNAM_OBJ(elm), 0L,
"you can replace <first> via 'return <first>;'" );
}
RequireSmallIntMayReplace("Range", elm, "first");
first = INT_INTOBJ(elm);
elm = EVAL_EXPR(READ_EXPR(READ_STAT(stat, 1), 1));
while ( ! IS_INTOBJ(elm) ) {
elm = ErrorReturnObj(
"Range: <last> must be an integer (not a %s)",
(Int)TNAM_OBJ(elm), 0L,
"you can replace <last> via 'return <last>;'" );
}
RequireSmallIntMayReplace("Range", elm, "last");
last = INT_INTOBJ(elm);

/* get the body */
Expand Down
Loading

0 comments on commit 8b99f68

Please sign in to comment.