* src/alloc.c (mark_object): Handle Lisp_Misc_Bignum.
(sweep_misc): Call mpz_clear for Lisp_Misc_Bignum.
* src/data.c (Ftype_of): Handle Lisp_Misc_Bignum.
(Fintegerp, Finteger_or_marker_p, Fnatnump, Fnumberp)
(Fnumber_or_marker_p): Update for bignum.
(Ffixnump, Fbignump): New defuns.
(syms_of_data): Update.
* src/emacs.c (xrealloc_for_gmp, xfree_for_gmp): New functions.
(main): Call mp_set_memory_functions.
* src/lisp.h (enum Lisp_Misc_Type) <Lisp_Misc_Bignum>: New constant.
(struct Lisp_Bignum): New.
(union Lisp_Misc): Add u_bignum.
(BIGNUMP, XBIGNUM, INTEGERP, NATNUMP, NUMBERP, CHECK_NUMBER)
(CHECK_INTEGER, CHECK_NUMBER_COERCE_MARKER): New functions.
* src/print.c (print_object): Handle Lisp_Misc_Bignum.
break;
case Lisp_Misc_Ptr:
+ case Lisp_Misc_Bignum:
XMISCANY (obj)->gcmarkbit = true;
break;
uptr->finalizer (uptr->p);
}
#endif
+ else if (mblk->markers[i].m.u_any.type == Lisp_Misc_Bignum)
+ mpz_clear (mblk->markers[i].m.u_bignum.value);
/* Set the type of the freed object to Lisp_Misc_Free.
We could leave the type alone, since nobody checks it,
but this might catch bugs faster. */
case Lisp_Misc_User_Ptr:
return Quser_ptr;
#endif
+ case Lisp_Misc_Bignum:
+ return Qinteger;
default:
emacs_abort ();
}
doc: /* Return t if OBJECT is an integer. */
attributes: const)
(Lisp_Object object)
+{
+ if (INTEGERP (object))
+ return Qt;
+ return Qnil;
+}
+
+DEFUN ("fixnump", Ffixnump, Sfixnump, 1, 1, 0,
+ doc: /* Return t if OBJECT is an fixnum. */
+ attributes: const)
+ (Lisp_Object object)
{
if (FIXNUMP (object))
return Qt;
doc: /* Return t if OBJECT is an integer or a marker (editor pointer). */)
(register Lisp_Object object)
{
- if (MARKERP (object) || FIXNUMP (object))
+ if (MARKERP (object) || INTEGERP (object))
return Qt;
return Qnil;
}
attributes: const)
(Lisp_Object object)
{
- if (FIXNATP (object))
+ if (NATNUMP (object))
return Qt;
return Qnil;
}
attributes: const)
(Lisp_Object object)
{
- if (FIXED_OR_FLOATP (object))
+ if (NUMBERP (object))
return Qt;
else
return Qnil;
doc: /* Return t if OBJECT is a number or a marker. */)
(Lisp_Object object)
{
- if (FIXED_OR_FLOATP (object) || MARKERP (object))
+ if (NUMBERP (object) || MARKERP (object))
return Qt;
return Qnil;
}
return Qt;
return Qnil;
}
+
+DEFUN ("bignump", Fbignump, Sbignump, 1, 1, 0,
+ doc: /* Return t if OBJECT is a bignum. */)
+ (Lisp_Object object)
+{
+ if (BIGNUMP (object))
+ return Qt;
+ return Qnil;
+}
\f
/* Extract and set components of lists. */
defsubr (&Sconsp);
defsubr (&Satom);
defsubr (&Sintegerp);
+ defsubr (&Sfixnump);
defsubr (&Sinteger_or_marker_p);
defsubr (&Snumberp);
defsubr (&Snumber_or_marker_p);
defsubr (&Sthreadp);
defsubr (&Smutexp);
defsubr (&Scondition_variable_p);
+ defsubr (&Sbignump);
defsubr (&Scar);
defsubr (&Scdr);
defsubr (&Scar_safe);
_exit (EXIT_FAILURE);
}
+/* Wrapper function for GMP. */
+static void *
+xrealloc_for_gmp (void *ptr, size_t ignore, size_t size)
+{
+ return xrealloc (ptr, size);
+}
+
+/* Wrapper function for GMP. */
+static void
+xfree_for_gmp (void *ptr, size_t ignore)
+{
+ xfree (ptr);
+}
+
/* ARGSUSED */
int
main (int argc, char **argv)
init_standard_fds ();
atexit (close_output_streams);
+ mp_set_memory_functions (xmalloc, xrealloc_for_gmp, xfree_for_gmp);
+
sort_args (argc, argv);
argc = 0;
while (argv[argc]) argc++;
#include <float.h>
#include <inttypes.h>
#include <limits.h>
+#ifdef HAVE_GMP
+#include <gmp.h>
+#else
+#include "mini-gmp.h"
+#endif
#include <intprops.h>
#include <verify.h>
#ifdef HAVE_MODULES
Lisp_Misc_User_Ptr,
#endif
+ Lisp_Misc_Bignum,
/* This is not a type code. It is for range checking. */
Lisp_Misc_Limit
};
union Lisp_Misc *chain;
};
+struct Lisp_Bignum
+ {
+ ENUM_BF (Lisp_Misc_Type) type : 16; /* = Lisp_Misc_Bignum */
+ bool_bf gcmarkbit : 1;
+ unsigned spacer : 15;
+ mpz_t value;
+ };
+
/* To get the type field of a union Lisp_Misc, use XMISCTYPE.
It uses one of these struct subtypes to get the type field. */
#ifdef HAVE_MODULES
struct Lisp_User_Ptr u_user_ptr;
#endif
+ struct Lisp_Bignum u_bignum;
};
INLINE union Lisp_Misc *
}
#endif
+INLINE bool
+BIGNUMP (Lisp_Object x)
+{
+ return MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Bignum;
+}
+
+INLINE struct Lisp_Bignum *
+XBIGNUM (Lisp_Object a)
+{
+ eassert (BIGNUMP (a));
+ return XUNTAG (a, Lisp_Misc, struct Lisp_Bignum);
+}
+
+INLINE bool
+INTEGERP (Lisp_Object x)
+{
+ return FIXNUMP (x) || BIGNUMP (x);
+}
+
\f
/* Forwarding pointer to an int variable.
This is allowed only in the value cell of a symbol,
{
return FIXNUMP (x) && 0 <= XINT (x);
}
+INLINE bool
+NATNUMP (Lisp_Object x)
+{
+ if (BIGNUMP (x))
+ return mpz_cmp_si (XBIGNUM (x)->value, 0) >= 0;
+ return FIXNUMP (x) && 0 <= XINT (x);
+}
+INLINE bool
+NUMBERP (Lisp_Object x)
+{
+ return INTEGERP (x) || FLOATP (x) || BIGNUMP (x);
+}
INLINE bool
RANGED_FIXNUMP (intmax_t lo, Lisp_Object x, intmax_t hi)
CHECK_TYPE (FIXED_OR_FLOATP (x), Qnumberp, x);
}
+INLINE void
+CHECK_NUMBER (Lisp_Object x)
+{
+ CHECK_TYPE (NUMBERP (x), Qnumberp, x);
+}
+
+INLINE void
+CHECK_INTEGER (Lisp_Object x)
+{
+ CHECK_TYPE (INTEGERP (x), Qnumberp, x);
+}
+
#define CHECK_FIXNUM_OR_FLOAT_COERCE_MARKER(x) \
do { \
if (MARKERP (x)) \
CHECK_TYPE (FIXED_OR_FLOATP (x), Qnumber_or_marker_p, x); \
} while (false)
+#define CHECK_NUMBER_COERCE_MARKER(x) \
+ do { \
+ if (MARKERP (x)) \
+ XSETFASTINT (x, marker_position (x)); \
+ else \
+ CHECK_TYPE (NUMBERP (x), Qnumber_or_marker_p, x); \
+ } while (false)
+
/* Since we can't assign directly to the CAR or CDR fields of a cons
cell, use these when checking that those fields contain numbers. */
INLINE void
}
break;
+ case Lisp_Misc_Bignum:
+ {
+ struct Lisp_Bignum *b = XBIGNUM (obj);
+ char *str = mpz_get_str (NULL, 10, b->value);
+ record_unwind_protect_ptr (xfree, str);
+ print_c_string (str, printcharfun);
+ }
+ break;
+
default:
goto badtype;
}