Mercurial > hg > xemacs-beta
comparison src/data.c @ 4957:db2db229ee82
merge
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Thu, 28 Jan 2010 02:48:45 -0600 |
parents | 19a72041c5ed 6772ce4d982b |
children | e813cf16c015 |
comparison
equal
deleted
inserted
replaced
4956:3461165c79be | 4957:db2db229ee82 |
---|---|
63 Lisp_Object Qbit_vectorp, Qbitp, Qcdr; | 63 Lisp_Object Qbit_vectorp, Qbitp, Qcdr; |
64 | 64 |
65 Lisp_Object Qerror_lacks_explanatory_string; | 65 Lisp_Object Qerror_lacks_explanatory_string; |
66 Lisp_Object Qfloatp; | 66 Lisp_Object Qfloatp; |
67 | 67 |
68 Fixnum Vmost_negative_fixnum, Vmost_positive_fixnum; | |
69 | |
68 #ifdef DEBUG_XEMACS | 70 #ifdef DEBUG_XEMACS |
69 | 71 |
70 int debug_issue_ebola_notices; | 72 int debug_issue_ebola_notices; |
71 | 73 |
72 Fixnum debug_ebola_backtrace_length; | 74 Fixnum debug_ebola_backtrace_length; |
418 determine whether this is the case. If the integer cannot be converted, | 420 determine whether this is the case. If the integer cannot be converted, |
419 nil is returned. | 421 nil is returned. |
420 */ | 422 */ |
421 (integer)) | 423 (integer)) |
422 { | 424 { |
423 CHECK_INT (integer); | 425 CHECK_INTEGER (integer); |
424 if (CHAR_INTP (integer)) | 426 if (CHAR_INTP (integer)) |
425 return make_char (XINT (integer)); | 427 return make_char (XINT (integer)); |
426 else | 428 else |
427 return Qnil; | 429 return Qnil; |
428 } | 430 } |
454 (object)) | 456 (object)) |
455 { | 457 { |
456 return CHAR_OR_CHAR_INTP (object) || STRINGP (object) ? Qt : Qnil; | 458 return CHAR_OR_CHAR_INTP (object) || STRINGP (object) ? Qt : Qnil; |
457 } | 459 } |
458 | 460 |
459 #ifdef HAVE_BIGNUM | |
460 /* In this case, integerp is defined in number.c. */ | |
461 DEFUN ("fixnump", Ffixnump, 1, 1, 0, /* | 461 DEFUN ("fixnump", Ffixnump, 1, 1, 0, /* |
462 Return t if OBJECT is a fixnum. | 462 Return t if OBJECT is a fixnum. |
463 | |
464 In this implementation, a fixnum is an immediate integer, and has a | |
465 maximum value described by the constant `most-positive-fixnum'. This | |
466 contrasts with bignums, integers where the values are limited by your | |
467 available memory. | |
463 */ | 468 */ |
464 (object)) | 469 (object)) |
465 { | 470 { |
466 return INTP (object) ? Qt : Qnil; | 471 return INTP (object) ? Qt : Qnil; |
467 } | 472 } |
468 #else | |
469 DEFUN ("integerp", Fintegerp, 1, 1, 0, /* | 473 DEFUN ("integerp", Fintegerp, 1, 1, 0, /* |
470 Return t if OBJECT is an integer. | 474 Return t if OBJECT is an integer, nil otherwise. |
475 | |
476 On builds without bignum support, this function is identical to `fixnump'. | |
471 */ | 477 */ |
472 (object)) | 478 (object)) |
473 { | 479 { |
474 return INTP (object) ? Qt : Qnil; | 480 return INTEGERP (object) ? Qt : Qnil; |
475 } | 481 } |
476 #endif | |
477 | 482 |
478 DEFUN ("integer-or-marker-p", Finteger_or_marker_p, 1, 1, 0, /* | 483 DEFUN ("integer-or-marker-p", Finteger_or_marker_p, 1, 1, 0, /* |
479 Return t if OBJECT is an integer or a marker (editor pointer). | 484 Return t if OBJECT is an integer or a marker (editor pointer). |
480 */ | 485 */ |
481 (object)) | 486 (object)) |
482 { | 487 { |
483 return INTP (object) || MARKERP (object) ? Qt : Qnil; | 488 return INTEGERP (object) || MARKERP (object) ? Qt : Qnil; |
484 } | 489 } |
485 | 490 |
486 DEFUN ("integer-or-char-p", Finteger_or_char_p, 1, 1, 0, /* | 491 DEFUN ("integer-or-char-p", Finteger_or_char_p, 1, 1, 0, /* |
487 Return t if OBJECT is an integer or a character. | 492 Return t if OBJECT is an integer or a character. |
488 */ | 493 */ |
489 (object)) | 494 (object)) |
490 { | 495 { |
491 return INTP (object) || CHARP (object) ? Qt : Qnil; | 496 return INTEGERP (object) || CHARP (object) ? Qt : Qnil; |
492 } | 497 } |
493 | 498 |
494 DEFUN ("integer-char-or-marker-p", Finteger_char_or_marker_p, 1, 1, 0, /* | 499 DEFUN ("integer-char-or-marker-p", Finteger_char_or_marker_p, 1, 1, 0, /* |
495 Return t if OBJECT is an integer, character or a marker (editor pointer). | 500 Return t if OBJECT is an integer, character or a marker (editor pointer). |
496 */ | 501 */ |
497 (object)) | 502 (object)) |
498 { | 503 { |
499 return INTP (object) || CHARP (object) || MARKERP (object) ? Qt : Qnil; | 504 return INTEGERP (object) || CHARP (object) || MARKERP (object) ? Qt : Qnil; |
500 } | 505 } |
501 | 506 |
502 DEFUN ("natnump", Fnatnump, 1, 1, 0, /* | 507 DEFUN ("natnump", Fnatnump, 1, 1, 0, /* |
503 Return t if OBJECT is a nonnegative integer. | 508 Return t if OBJECT is a nonnegative integer. |
504 */ | 509 */ |
540 DEFUN ("numberp", Fnumberp, 1, 1, 0, /* | 545 DEFUN ("numberp", Fnumberp, 1, 1, 0, /* |
541 Return t if OBJECT is a number (floating point or integer). | 546 Return t if OBJECT is a number (floating point or integer). |
542 */ | 547 */ |
543 (object)) | 548 (object)) |
544 { | 549 { |
545 #ifdef WITH_NUMBER_TYPES | |
546 return NUMBERP (object) ? Qt : Qnil; | 550 return NUMBERP (object) ? Qt : Qnil; |
547 #else | |
548 return INT_OR_FLOATP (object) ? Qt : Qnil; | |
549 #endif | |
550 } | 551 } |
551 | 552 |
552 DEFUN ("number-or-marker-p", Fnumber_or_marker_p, 1, 1, 0, /* | 553 DEFUN ("number-or-marker-p", Fnumber_or_marker_p, 1, 1, 0, /* |
553 Return t if OBJECT is a number or a marker. | 554 Return t if OBJECT is a number or a marker. |
554 */ | 555 */ |
555 (object)) | 556 (object)) |
556 { | 557 { |
557 return INT_OR_FLOATP (object) || MARKERP (object) ? Qt : Qnil; | 558 return NUMBERP (object) || MARKERP (object) ? Qt : Qnil; |
558 } | 559 } |
559 | 560 |
560 DEFUN ("number-char-or-marker-p", Fnumber_char_or_marker_p, 1, 1, 0, /* | 561 DEFUN ("number-char-or-marker-p", Fnumber_char_or_marker_p, 1, 1, 0, /* |
561 Return t if OBJECT is a number, character or a marker. | 562 Return t if OBJECT is a number, character or a marker. |
562 */ | 563 */ |
563 (object)) | 564 (object)) |
564 { | 565 { |
565 return (INT_OR_FLOATP (object) || | 566 return (NUMBERP (object) || CHARP (object) || MARKERP (object)) |
566 CHARP (object) || | |
567 MARKERP (object)) | |
568 ? Qt : Qnil; | 567 ? Qt : Qnil; |
569 } | 568 } |
570 | 569 |
571 DEFUN ("floatp", Ffloatp, 1, 1, 0, /* | 570 DEFUN ("floatp", Ffloatp, 1, 1, 0, /* |
572 Return t if OBJECT is a floating point number. | 571 Return t if OBJECT is a floating point number. |
738 | 737 |
739 retry: | 738 retry: |
740 | 739 |
741 if (INTP (index_)) idx = XINT (index_); | 740 if (INTP (index_)) idx = XINT (index_); |
742 else if (CHARP (index_)) idx = XCHAR (index_); /* yuck! */ | 741 else if (CHARP (index_)) idx = XCHAR (index_); /* yuck! */ |
742 #ifdef HAVE_BIGNUM | |
743 else if (BIGNUMP (index_)) | |
744 { | |
745 Lisp_Object canon = Fcanonicalize_number (index_); | |
746 if (EQ (canon, index_)) | |
747 { | |
748 /* We don't support non-fixnum indices. */ | |
749 goto range_error; | |
750 } | |
751 index_ = canon; | |
752 goto retry; | |
753 } | |
754 #endif | |
743 else | 755 else |
744 { | 756 { |
745 index_ = wrong_type_argument (Qinteger_or_char_p, index_); | 757 index_ = wrong_type_argument (Qinteger_or_char_p, index_); |
746 goto retry; | 758 goto retry; |
747 } | 759 } |
793 | 805 |
794 retry: | 806 retry: |
795 | 807 |
796 if (INTP (index_)) idx = XINT (index_); | 808 if (INTP (index_)) idx = XINT (index_); |
797 else if (CHARP (index_)) idx = XCHAR (index_); /* yuck! */ | 809 else if (CHARP (index_)) idx = XCHAR (index_); /* yuck! */ |
810 #ifdef HAVE_BIGNUM | |
811 else if (BIGNUMP (index_)) | |
812 { | |
813 Lisp_Object canon = Fcanonicalize_number (index_); | |
814 if (EQ (canon, index_)) | |
815 { | |
816 /* We don't support non-fixnum indices. */ | |
817 goto range_error; | |
818 } | |
819 index_ = canon; | |
820 goto retry; | |
821 } | |
822 #endif | |
798 else | 823 else |
799 { | 824 { |
800 index_ = wrong_type_argument (Qinteger_or_char_p, index_); | 825 index_ = wrong_type_argument (Qinteger_or_char_p, index_); |
801 goto retry; | 826 goto retry; |
802 } | 827 } |
882 } | 907 } |
883 } | 908 } |
884 #endif /* WITH_NUMBER_TYPES */ | 909 #endif /* WITH_NUMBER_TYPES */ |
885 | 910 |
886 static EMACS_INT | 911 static EMACS_INT |
887 integer_char_or_marker_to_int (Lisp_Object obj) | 912 fixnum_char_or_marker_to_int (Lisp_Object obj) |
888 { | 913 { |
889 retry: | 914 retry: |
890 if (INTP (obj)) return XINT (obj); | 915 if (INTP (obj)) return XINT (obj); |
891 else if (CHARP (obj)) return XCHAR (obj); | 916 else if (CHARP (obj)) return XCHAR (obj); |
892 else if (MARKERP (obj)) return marker_position (obj); | 917 else if (MARKERP (obj)) return marker_position (obj); |
893 else | 918 else |
894 { | 919 { |
920 /* On bignum builds, we can only be called from #'lognot, which | |
921 protects against this happening: */ | |
922 assert (!BIGNUMP (obj)); | |
895 obj = wrong_type_argument (Qinteger_char_or_marker_p, obj); | 923 obj = wrong_type_argument (Qinteger_char_or_marker_p, obj); |
896 goto retry; | 924 goto retry; |
897 } | 925 } |
898 } | 926 } |
899 | 927 |
1190 NUMBER may be an integer or a floating point number. | 1218 NUMBER may be an integer or a floating point number. |
1191 If supported, it may also be a ratio. | 1219 If supported, it may also be a ratio. |
1192 */ | 1220 */ |
1193 (number)) | 1221 (number)) |
1194 { | 1222 { |
1195 #ifdef WITH_NUMBER_TYPES | |
1196 CHECK_NUMBER (number); | 1223 CHECK_NUMBER (number); |
1197 #else | |
1198 CHECK_INT_OR_FLOAT (number); | |
1199 #endif | |
1200 | 1224 |
1201 if (FLOATP (number)) | 1225 if (FLOATP (number)) |
1202 { | 1226 { |
1203 Ascbyte pigbuf[350]; /* see comments in float_to_string */ | 1227 Ascbyte pigbuf[350]; /* see comments in float_to_string */ |
1204 | 1228 |
2130 #else /* !HAVE_BIGNUM */ | 2154 #else /* !HAVE_BIGNUM */ |
2131 EMACS_INT bits = ~0; | 2155 EMACS_INT bits = ~0; |
2132 Lisp_Object *args_end = args + nargs; | 2156 Lisp_Object *args_end = args + nargs; |
2133 | 2157 |
2134 while (args < args_end) | 2158 while (args < args_end) |
2135 bits &= integer_char_or_marker_to_int (*args++); | 2159 bits &= fixnum_char_or_marker_to_int (*args++); |
2136 | 2160 |
2137 return make_int (bits); | 2161 return make_int (bits); |
2138 #endif /* HAVE_BIGNUM */ | 2162 #endif /* HAVE_BIGNUM */ |
2139 } | 2163 } |
2140 | 2164 |
2182 #else /* !HAVE_BIGNUM */ | 2206 #else /* !HAVE_BIGNUM */ |
2183 EMACS_INT bits = 0; | 2207 EMACS_INT bits = 0; |
2184 Lisp_Object *args_end = args + nargs; | 2208 Lisp_Object *args_end = args + nargs; |
2185 | 2209 |
2186 while (args < args_end) | 2210 while (args < args_end) |
2187 bits |= integer_char_or_marker_to_int (*args++); | 2211 bits |= fixnum_char_or_marker_to_int (*args++); |
2188 | 2212 |
2189 return make_int (bits); | 2213 return make_int (bits); |
2190 #endif /* HAVE_BIGNUM */ | 2214 #endif /* HAVE_BIGNUM */ |
2191 } | 2215 } |
2192 | 2216 |
2204 | 2228 |
2205 if (nargs == 0) | 2229 if (nargs == 0) |
2206 return make_int (0); | 2230 return make_int (0); |
2207 | 2231 |
2208 while (!(CHARP (args[0]) || MARKERP (args[0]) || INTEGERP (args[0]))) | 2232 while (!(CHARP (args[0]) || MARKERP (args[0]) || INTEGERP (args[0]))) |
2209 args[0] = wrong_type_argument (Qnumber_char_or_marker_p, args[0]); | 2233 args[0] = wrong_type_argument (Qinteger_char_or_marker_p, args[0]); |
2210 | 2234 |
2211 result = args[0]; | 2235 result = args[0]; |
2212 if (CHARP (result)) | 2236 if (CHARP (result)) |
2213 result = make_int (XCHAR (result)); | 2237 result = make_int (XCHAR (result)); |
2214 else if (MARKERP (result)) | 2238 else if (MARKERP (result)) |
2215 result = make_int (marker_position (result)); | 2239 result = make_int (marker_position (result)); |
2216 for (i = 1; i < nargs; i++) | 2240 for (i = 1; i < nargs; i++) |
2217 { | 2241 { |
2218 while (!(CHARP (args[i]) || MARKERP (args[i]) || INTEGERP (args[i]))) | 2242 while (!(CHARP (args[i]) || MARKERP (args[i]) || INTEGERP (args[i]))) |
2219 args[i] = wrong_type_argument (Qnumber_char_or_marker_p, args[i]); | 2243 args[i] = wrong_type_argument (Qinteger_char_or_marker_p, args[i]); |
2220 other = args[i]; | 2244 other = args[i]; |
2221 if (promote_args (&result, &other) == FIXNUM_T) | 2245 if (promote_args (&result, &other) == FIXNUM_T) |
2222 { | 2246 { |
2223 result = make_int (XREALINT (result) ^ XREALINT (other)); | 2247 result = make_int (XREALINT (result) ^ XREALINT (other)); |
2224 } | 2248 } |
2233 #else /* !HAVE_BIGNUM */ | 2257 #else /* !HAVE_BIGNUM */ |
2234 EMACS_INT bits = 0; | 2258 EMACS_INT bits = 0; |
2235 Lisp_Object *args_end = args + nargs; | 2259 Lisp_Object *args_end = args + nargs; |
2236 | 2260 |
2237 while (args < args_end) | 2261 while (args < args_end) |
2238 bits ^= integer_char_or_marker_to_int (*args++); | 2262 bits ^= fixnum_char_or_marker_to_int (*args++); |
2239 | 2263 |
2240 return make_int (bits); | 2264 return make_int (bits); |
2241 #endif /* !HAVE_BIGNUM */ | 2265 #endif /* !HAVE_BIGNUM */ |
2242 } | 2266 } |
2243 | 2267 |
2245 Return the bitwise complement of NUMBER. | 2269 Return the bitwise complement of NUMBER. |
2246 NUMBER may be an integer, marker or character converted to integer. | 2270 NUMBER may be an integer, marker or character converted to integer. |
2247 */ | 2271 */ |
2248 (number)) | 2272 (number)) |
2249 { | 2273 { |
2274 while (!(CHARP (number) || MARKERP (number) || INTEGERP (number))) | |
2275 number = wrong_type_argument (Qinteger_char_or_marker_p, number); | |
2276 | |
2250 #ifdef HAVE_BIGNUM | 2277 #ifdef HAVE_BIGNUM |
2251 if (BIGNUMP (number)) | 2278 if (BIGNUMP (number)) |
2252 { | 2279 { |
2253 bignum_not (scratch_bignum, XBIGNUM_DATA (number)); | 2280 bignum_not (scratch_bignum, XBIGNUM_DATA (number)); |
2254 return make_bignum_bg (scratch_bignum); | 2281 return make_bignum_bg (scratch_bignum); |
2255 } | 2282 } |
2256 #endif /* HAVE_BIGNUM */ | 2283 #endif /* HAVE_BIGNUM */ |
2257 return make_int (~ integer_char_or_marker_to_int (number)); | 2284 |
2285 return make_int (~ fixnum_char_or_marker_to_int (number)); | |
2258 } | 2286 } |
2259 | 2287 |
2260 DEFUN ("%", Frem, 2, 2, 0, /* | 2288 DEFUN ("%", Frem, 2, 2, 0, /* |
2261 Return remainder of first arg divided by second. | 2289 Return remainder of first arg divided by second. |
2262 Both must be integers, characters or markers. | 2290 Both must be integers, characters or markers. |
2282 bignum_mod (scratch_bignum, XBIGNUM_DATA (number1), | 2310 bignum_mod (scratch_bignum, XBIGNUM_DATA (number1), |
2283 XBIGNUM_DATA (number2)); | 2311 XBIGNUM_DATA (number2)); |
2284 return Fcanonicalize_number (make_bignum_bg (scratch_bignum)); | 2312 return Fcanonicalize_number (make_bignum_bg (scratch_bignum)); |
2285 } | 2313 } |
2286 #else /* !HAVE_BIGNUM */ | 2314 #else /* !HAVE_BIGNUM */ |
2287 EMACS_INT ival1 = integer_char_or_marker_to_int (number1); | 2315 EMACS_INT ival1 = fixnum_char_or_marker_to_int (number1); |
2288 EMACS_INT ival2 = integer_char_or_marker_to_int (number2); | 2316 EMACS_INT ival2 = fixnum_char_or_marker_to_int (number2); |
2289 | 2317 |
2290 if (ival2 == 0) | 2318 if (ival2 == 0) |
2291 Fsignal (Qarith_error, Qnil); | 2319 Fsignal (Qarith_error, Qnil); |
2292 | 2320 |
2293 return make_int (ival1 % ival2); | 2321 return make_int (ival1 % ival2); |
3548 DEFSUBR (Fcharacterp); | 3576 DEFSUBR (Fcharacterp); |
3549 DEFSUBR (Fchar_int_p); | 3577 DEFSUBR (Fchar_int_p); |
3550 DEFSUBR (Fchar_to_int); | 3578 DEFSUBR (Fchar_to_int); |
3551 DEFSUBR (Fint_to_char); | 3579 DEFSUBR (Fint_to_char); |
3552 DEFSUBR (Fchar_or_char_int_p); | 3580 DEFSUBR (Fchar_or_char_int_p); |
3553 #ifdef HAVE_BIGNUM | |
3554 DEFSUBR (Ffixnump); | 3581 DEFSUBR (Ffixnump); |
3555 #else | |
3556 DEFSUBR (Fintegerp); | 3582 DEFSUBR (Fintegerp); |
3557 #endif | |
3558 DEFSUBR (Finteger_or_marker_p); | 3583 DEFSUBR (Finteger_or_marker_p); |
3559 DEFSUBR (Finteger_or_char_p); | 3584 DEFSUBR (Finteger_or_char_p); |
3560 DEFSUBR (Finteger_char_or_marker_p); | 3585 DEFSUBR (Finteger_char_or_marker_p); |
3561 DEFSUBR (Fnumberp); | 3586 DEFSUBR (Fnumberp); |
3562 DEFSUBR (Fnumber_or_marker_p); | 3587 DEFSUBR (Fnumber_or_marker_p); |
3642 staticpro (&Vfinalize_list); | 3667 staticpro (&Vfinalize_list); |
3643 | 3668 |
3644 Vall_weak_boxes = Qnil; | 3669 Vall_weak_boxes = Qnil; |
3645 dump_add_weak_object_chain (&Vall_weak_boxes); | 3670 dump_add_weak_object_chain (&Vall_weak_boxes); |
3646 | 3671 |
3672 DEFVAR_CONST_INT ("most-negative-fixnum", &Vmost_negative_fixnum /* | |
3673 The fixnum closest in value to negative infinity. | |
3674 */); | |
3675 Vmost_negative_fixnum = EMACS_INT_MIN; | |
3676 | |
3677 DEFVAR_CONST_INT ("most-positive-fixnum", &Vmost_positive_fixnum /* | |
3678 The fixnum closest in value to positive infinity. | |
3679 */); | |
3680 Vmost_positive_fixnum = EMACS_INT_MAX; | |
3681 | |
3647 #ifdef DEBUG_XEMACS | 3682 #ifdef DEBUG_XEMACS |
3648 DEFVAR_BOOL ("debug-issue-ebola-notices", &debug_issue_ebola_notices /* | 3683 DEFVAR_BOOL ("debug-issue-ebola-notices", &debug_issue_ebola_notices /* |
3649 If non-zero, note when your code may be suffering from char-int confoundance. | 3684 If non-zero, note when your code may be suffering from char-int confoundance. |
3650 That is to say, if XEmacs encounters a usage of `eq', `memq', `equal', | 3685 That is to say, if XEmacs encounters a usage of `eq', `memq', `equal', |
3651 etc. where an int and a char with the same value are being compared, | 3686 etc. where an int and a char with the same value are being compared, |