diff options
| author | Paul Eggert | 2020-03-26 16:12:21 -0700 |
|---|---|---|
| committer | Paul Eggert | 2020-03-26 16:13:28 -0700 |
| commit | 57f5a63d85f6c3ea1d8b428b12a8db743de3b0bc (patch) | |
| tree | a13f3efe7f443b1235c9ad2ed987586b0bc394ed /src/data.c | |
| parent | d28b00476890f791a89b65007e5f20682b3eaa0d (diff) | |
| download | emacs-57f5a63d85f6c3ea1d8b428b12a8db743de3b0bc.tar.gz emacs-57f5a63d85f6c3ea1d8b428b12a8db743de3b0bc.zip | |
Refactor and fix typo in CHECK_*_COERCE_MARKER
* src/data.c (check_integer_coerce_marker)
(check_number_coerce_marker): New functions.
Also, fix a typo in the former, by having it use
Qinteger_or_marker_p not Qnumber_or_marker_p.
(arithcompare, floatop_arith_driver, bignum_arith_driver)
(arith_driver, Fplus, Fminus, Ftimes, Fquo, Frem, Fmod)
(minmax_driver, Flogand, Flogior, Flogxor, Fadd1, Fsub1):
Use them in place of the similarly-named macros.
* src/lisp.h (CHECK_NUMBER_COERCE_MARKER)
(CHECK_INTEGER_COERCE_MARKER): Remove; no longer used.
Diffstat (limited to 'src/data.c')
| -rw-r--r-- | src/data.c | 77 |
1 files changed, 41 insertions, 36 deletions
diff --git a/src/data.c b/src/data.c index b0d438e8b81..bce2e53cfb6 100644 --- a/src/data.c +++ b/src/data.c | |||
| @@ -2333,6 +2333,24 @@ bool-vector. IDX starts at 0. */) | |||
| 2333 | 2333 | ||
| 2334 | /* Arithmetic functions */ | 2334 | /* Arithmetic functions */ |
| 2335 | 2335 | ||
| 2336 | static Lisp_Object | ||
| 2337 | check_integer_coerce_marker (Lisp_Object x) | ||
| 2338 | { | ||
| 2339 | if (MARKERP (x)) | ||
| 2340 | return make_fixnum (marker_position (x)); | ||
| 2341 | CHECK_TYPE (INTEGERP (x), Qinteger_or_marker_p, x); | ||
| 2342 | return x; | ||
| 2343 | } | ||
| 2344 | |||
| 2345 | static Lisp_Object | ||
| 2346 | check_number_coerce_marker (Lisp_Object x) | ||
| 2347 | { | ||
| 2348 | if (MARKERP (x)) | ||
| 2349 | return make_fixnum (marker_position (x)); | ||
| 2350 | CHECK_TYPE (NUMBERP (x), Qnumber_or_marker_p, x); | ||
| 2351 | return x; | ||
| 2352 | } | ||
| 2353 | |||
| 2336 | Lisp_Object | 2354 | Lisp_Object |
| 2337 | arithcompare (Lisp_Object num1, Lisp_Object num2, | 2355 | arithcompare (Lisp_Object num1, Lisp_Object num2, |
| 2338 | enum Arith_Comparison comparison) | 2356 | enum Arith_Comparison comparison) |
| @@ -2341,8 +2359,8 @@ arithcompare (Lisp_Object num1, Lisp_Object num2, | |||
| 2341 | bool lt, eq = true, gt; | 2359 | bool lt, eq = true, gt; |
| 2342 | bool test; | 2360 | bool test; |
| 2343 | 2361 | ||
| 2344 | CHECK_NUMBER_COERCE_MARKER (num1); | 2362 | num1 = check_number_coerce_marker (num1); |
| 2345 | CHECK_NUMBER_COERCE_MARKER (num2); | 2363 | num2 = check_number_coerce_marker (num2); |
| 2346 | 2364 | ||
| 2347 | /* If the comparison is mostly done by comparing two doubles, | 2365 | /* If the comparison is mostly done by comparing two doubles, |
| 2348 | set LT, EQ, and GT to the <, ==, > results of that comparison, | 2366 | set LT, EQ, and GT to the <, ==, > results of that comparison, |
| @@ -2744,9 +2762,7 @@ floatop_arith_driver (enum arithop code, ptrdiff_t nargs, Lisp_Object *args, | |||
| 2744 | argnum++; | 2762 | argnum++; |
| 2745 | if (argnum == nargs) | 2763 | if (argnum == nargs) |
| 2746 | return make_float (accum); | 2764 | return make_float (accum); |
| 2747 | Lisp_Object val = args[argnum]; | 2765 | next = XFLOATINT (check_number_coerce_marker (args[argnum])); |
| 2748 | CHECK_NUMBER_COERCE_MARKER (val); | ||
| 2749 | next = XFLOATINT (val); | ||
| 2750 | } | 2766 | } |
| 2751 | } | 2767 | } |
| 2752 | 2768 | ||
| @@ -2808,8 +2824,7 @@ bignum_arith_driver (enum arithop code, ptrdiff_t nargs, Lisp_Object *args, | |||
| 2808 | argnum++; | 2824 | argnum++; |
| 2809 | if (argnum == nargs) | 2825 | if (argnum == nargs) |
| 2810 | return make_integer_mpz (); | 2826 | return make_integer_mpz (); |
| 2811 | val = args[argnum]; | 2827 | val = check_number_coerce_marker (args[argnum]); |
| 2812 | CHECK_NUMBER_COERCE_MARKER (val); | ||
| 2813 | if (FLOATP (val)) | 2828 | if (FLOATP (val)) |
| 2814 | return float_arith_driver (code, nargs, args, argnum, | 2829 | return float_arith_driver (code, nargs, args, argnum, |
| 2815 | mpz_get_d_rounded (*accum), val); | 2830 | mpz_get_d_rounded (*accum), val); |
| @@ -2838,8 +2853,7 @@ arith_driver (enum arithop code, ptrdiff_t nargs, Lisp_Object *args, | |||
| 2838 | argnum++; | 2853 | argnum++; |
| 2839 | if (argnum == nargs) | 2854 | if (argnum == nargs) |
| 2840 | return make_int (accum); | 2855 | return make_int (accum); |
| 2841 | val = args[argnum]; | 2856 | val = check_number_coerce_marker (args[argnum]); |
| 2842 | CHECK_NUMBER_COERCE_MARKER (val); | ||
| 2843 | 2857 | ||
| 2844 | /* Set NEXT to the next value if it fits, else exit the loop. */ | 2858 | /* Set NEXT to the next value if it fits, else exit the loop. */ |
| 2845 | intmax_t next; | 2859 | intmax_t next; |
| @@ -2886,8 +2900,7 @@ usage: (+ &rest NUMBERS-OR-MARKERS) */) | |||
| 2886 | { | 2900 | { |
| 2887 | if (nargs == 0) | 2901 | if (nargs == 0) |
| 2888 | return make_fixnum (0); | 2902 | return make_fixnum (0); |
| 2889 | Lisp_Object a = args[0]; | 2903 | Lisp_Object a = check_number_coerce_marker (args[0]); |
| 2890 | CHECK_NUMBER_COERCE_MARKER (a); | ||
| 2891 | return nargs == 1 ? a : arith_driver (Aadd, nargs, args, a); | 2904 | return nargs == 1 ? a : arith_driver (Aadd, nargs, args, a); |
| 2892 | } | 2905 | } |
| 2893 | 2906 | ||
| @@ -2900,8 +2913,7 @@ usage: (- &optional NUMBER-OR-MARKER &rest MORE-NUMBERS-OR-MARKERS) */) | |||
| 2900 | { | 2913 | { |
| 2901 | if (nargs == 0) | 2914 | if (nargs == 0) |
| 2902 | return make_fixnum (0); | 2915 | return make_fixnum (0); |
| 2903 | Lisp_Object a = args[0]; | 2916 | Lisp_Object a = check_number_coerce_marker (args[0]); |
| 2904 | CHECK_NUMBER_COERCE_MARKER (a); | ||
| 2905 | if (nargs == 1) | 2917 | if (nargs == 1) |
| 2906 | { | 2918 | { |
| 2907 | if (FIXNUMP (a)) | 2919 | if (FIXNUMP (a)) |
| @@ -2921,8 +2933,7 @@ usage: (* &rest NUMBERS-OR-MARKERS) */) | |||
| 2921 | { | 2933 | { |
| 2922 | if (nargs == 0) | 2934 | if (nargs == 0) |
| 2923 | return make_fixnum (1); | 2935 | return make_fixnum (1); |
| 2924 | Lisp_Object a = args[0]; | 2936 | Lisp_Object a = check_number_coerce_marker (args[0]); |
| 2925 | CHECK_NUMBER_COERCE_MARKER (a); | ||
| 2926 | return nargs == 1 ? a : arith_driver (Amult, nargs, args, a); | 2937 | return nargs == 1 ? a : arith_driver (Amult, nargs, args, a); |
| 2927 | } | 2938 | } |
| 2928 | 2939 | ||
| @@ -2934,8 +2945,7 @@ The arguments must be numbers or markers. | |||
| 2934 | usage: (/ NUMBER &rest DIVISORS) */) | 2945 | usage: (/ NUMBER &rest DIVISORS) */) |
| 2935 | (ptrdiff_t nargs, Lisp_Object *args) | 2946 | (ptrdiff_t nargs, Lisp_Object *args) |
| 2936 | { | 2947 | { |
| 2937 | Lisp_Object a = args[0]; | 2948 | Lisp_Object a = check_number_coerce_marker (args[0]); |
| 2938 | CHECK_NUMBER_COERCE_MARKER (a); | ||
| 2939 | if (nargs == 1) | 2949 | if (nargs == 1) |
| 2940 | { | 2950 | { |
| 2941 | if (FIXNUMP (a)) | 2951 | if (FIXNUMP (a)) |
| @@ -3017,10 +3027,10 @@ integer_remainder (Lisp_Object num, Lisp_Object den, bool modulo) | |||
| 3017 | DEFUN ("%", Frem, Srem, 2, 2, 0, | 3027 | DEFUN ("%", Frem, Srem, 2, 2, 0, |
| 3018 | doc: /* Return remainder of X divided by Y. | 3028 | doc: /* Return remainder of X divided by Y. |
| 3019 | Both must be integers or markers. */) | 3029 | Both must be integers or markers. */) |
| 3020 | (register Lisp_Object x, Lisp_Object y) | 3030 | (Lisp_Object x, Lisp_Object y) |
| 3021 | { | 3031 | { |
| 3022 | CHECK_INTEGER_COERCE_MARKER (x); | 3032 | x = check_integer_coerce_marker (x); |
| 3023 | CHECK_INTEGER_COERCE_MARKER (y); | 3033 | y = check_integer_coerce_marker (y); |
| 3024 | return integer_remainder (x, y, false); | 3034 | return integer_remainder (x, y, false); |
| 3025 | } | 3035 | } |
| 3026 | 3036 | ||
| @@ -3030,8 +3040,8 @@ The result falls between zero (inclusive) and Y (exclusive). | |||
| 3030 | Both X and Y must be numbers or markers. */) | 3040 | Both X and Y must be numbers or markers. */) |
| 3031 | (Lisp_Object x, Lisp_Object y) | 3041 | (Lisp_Object x, Lisp_Object y) |
| 3032 | { | 3042 | { |
| 3033 | CHECK_NUMBER_COERCE_MARKER (x); | 3043 | x = check_number_coerce_marker (x); |
| 3034 | CHECK_NUMBER_COERCE_MARKER (y); | 3044 | y = check_number_coerce_marker (y); |
| 3035 | if (FLOATP (x) || FLOATP (y)) | 3045 | if (FLOATP (x) || FLOATP (y)) |
| 3036 | return fmod_float (x, y); | 3046 | return fmod_float (x, y); |
| 3037 | return integer_remainder (x, y, true); | 3047 | return integer_remainder (x, y, true); |
| @@ -3041,12 +3051,10 @@ static Lisp_Object | |||
| 3041 | minmax_driver (ptrdiff_t nargs, Lisp_Object *args, | 3051 | minmax_driver (ptrdiff_t nargs, Lisp_Object *args, |
| 3042 | enum Arith_Comparison comparison) | 3052 | enum Arith_Comparison comparison) |
| 3043 | { | 3053 | { |
| 3044 | Lisp_Object accum = args[0]; | 3054 | Lisp_Object accum = check_number_coerce_marker (args[0]); |
| 3045 | CHECK_NUMBER_COERCE_MARKER (accum); | ||
| 3046 | for (ptrdiff_t argnum = 1; argnum < nargs; argnum++) | 3055 | for (ptrdiff_t argnum = 1; argnum < nargs; argnum++) |
| 3047 | { | 3056 | { |
| 3048 | Lisp_Object val = args[argnum]; | 3057 | Lisp_Object val = check_number_coerce_marker (args[argnum]); |
| 3049 | CHECK_NUMBER_COERCE_MARKER (val); | ||
| 3050 | if (!NILP (arithcompare (val, accum, comparison))) | 3058 | if (!NILP (arithcompare (val, accum, comparison))) |
| 3051 | accum = val; | 3059 | accum = val; |
| 3052 | else if (FLOATP (val) && isnan (XFLOAT_DATA (val))) | 3060 | else if (FLOATP (val) && isnan (XFLOAT_DATA (val))) |
| @@ -3081,8 +3089,7 @@ usage: (logand &rest INTS-OR-MARKERS) */) | |||
| 3081 | { | 3089 | { |
| 3082 | if (nargs == 0) | 3090 | if (nargs == 0) |
| 3083 | return make_fixnum (-1); | 3091 | return make_fixnum (-1); |
| 3084 | Lisp_Object a = args[0]; | 3092 | Lisp_Object a = check_integer_coerce_marker (args[0]); |
| 3085 | CHECK_INTEGER_COERCE_MARKER (a); | ||
| 3086 | return nargs == 1 ? a : arith_driver (Alogand, nargs, args, a); | 3093 | return nargs == 1 ? a : arith_driver (Alogand, nargs, args, a); |
| 3087 | } | 3094 | } |
| 3088 | 3095 | ||
| @@ -3094,8 +3101,7 @@ usage: (logior &rest INTS-OR-MARKERS) */) | |||
| 3094 | { | 3101 | { |
| 3095 | if (nargs == 0) | 3102 | if (nargs == 0) |
| 3096 | return make_fixnum (0); | 3103 | return make_fixnum (0); |
| 3097 | Lisp_Object a = args[0]; | 3104 | Lisp_Object a = check_integer_coerce_marker (args[0]); |
| 3098 | CHECK_INTEGER_COERCE_MARKER (a); | ||
| 3099 | return nargs == 1 ? a : arith_driver (Alogior, nargs, args, a); | 3105 | return nargs == 1 ? a : arith_driver (Alogior, nargs, args, a); |
| 3100 | } | 3106 | } |
| 3101 | 3107 | ||
| @@ -3107,8 +3113,7 @@ usage: (logxor &rest INTS-OR-MARKERS) */) | |||
| 3107 | { | 3113 | { |
| 3108 | if (nargs == 0) | 3114 | if (nargs == 0) |
| 3109 | return make_fixnum (0); | 3115 | return make_fixnum (0); |
| 3110 | Lisp_Object a = args[0]; | 3116 | Lisp_Object a = check_integer_coerce_marker (args[0]); |
| 3111 | CHECK_INTEGER_COERCE_MARKER (a); | ||
| 3112 | return nargs == 1 ? a : arith_driver (Alogxor, nargs, args, a); | 3117 | return nargs == 1 ? a : arith_driver (Alogxor, nargs, args, a); |
| 3113 | } | 3118 | } |
| 3114 | 3119 | ||
| @@ -3227,9 +3232,9 @@ expt_integer (Lisp_Object x, Lisp_Object y) | |||
| 3227 | DEFUN ("1+", Fadd1, Sadd1, 1, 1, 0, | 3232 | DEFUN ("1+", Fadd1, Sadd1, 1, 1, 0, |
| 3228 | doc: /* Return NUMBER plus one. NUMBER may be a number or a marker. | 3233 | doc: /* Return NUMBER plus one. NUMBER may be a number or a marker. |
| 3229 | Markers are converted to integers. */) | 3234 | Markers are converted to integers. */) |
| 3230 | (register Lisp_Object number) | 3235 | (Lisp_Object number) |
| 3231 | { | 3236 | { |
| 3232 | CHECK_NUMBER_COERCE_MARKER (number); | 3237 | number = check_number_coerce_marker (number); |
| 3233 | 3238 | ||
| 3234 | if (FIXNUMP (number)) | 3239 | if (FIXNUMP (number)) |
| 3235 | return make_int (XFIXNUM (number) + 1); | 3240 | return make_int (XFIXNUM (number) + 1); |
| @@ -3242,9 +3247,9 @@ Markers are converted to integers. */) | |||
| 3242 | DEFUN ("1-", Fsub1, Ssub1, 1, 1, 0, | 3247 | DEFUN ("1-", Fsub1, Ssub1, 1, 1, 0, |
| 3243 | doc: /* Return NUMBER minus one. NUMBER may be a number or a marker. | 3248 | doc: /* Return NUMBER minus one. NUMBER may be a number or a marker. |
| 3244 | Markers are converted to integers. */) | 3249 | Markers are converted to integers. */) |
| 3245 | (register Lisp_Object number) | 3250 | (Lisp_Object number) |
| 3246 | { | 3251 | { |
| 3247 | CHECK_NUMBER_COERCE_MARKER (number); | 3252 | number = check_number_coerce_marker (number); |
| 3248 | 3253 | ||
| 3249 | if (FIXNUMP (number)) | 3254 | if (FIXNUMP (number)) |
| 3250 | return make_int (XFIXNUM (number) - 1); | 3255 | return make_int (XFIXNUM (number) - 1); |