diff options
| author | Mattias EngdegÄrd | 2024-03-10 13:18:22 +0100 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2024-03-29 11:39:38 +0100 |
| commit | 1232ab31c656b8564984a758957466f90ac10501 (patch) | |
| tree | 38a7774207a5ac8dba2612bef9a6a39f3cd0d658 /src/data.c | |
| parent | c3684b97885c5a1f4d0713ff45c7395e9a4c6e8a (diff) | |
| download | emacs-1232ab31c656b8564984a758957466f90ac10501.tar.gz emacs-1232ab31c656b8564984a758957466f90ac10501.zip | |
Add `value<` (bug#69709)
It's a general-purpose polymorphic ordering function, like `<` but
for any two values of the same type.
* src/data.c (syms_of_data): Add the `type-mismatch` error.
(bits_word_to_host_endian): Move...
* src/lisp.h (bits_word_to_host_endian): ...here, and declare inline.
* src/fns.c (Fstring_lessp): Extract the bulk of this function to...
(string_cmp): ...this 3-way comparison function, for use elsewhere.
(bool_vector_cmp, value_cmp, Fvaluelt): New.
* lisp/emacs-lisp/byte-opt.el (side-effect-free-fns, pure-fns):
Add `value<`, which is pure and side-effect-free.
* test/src/fns-tests.el (fns-value<-ordered, fns-value<-unordered)
(fns-value<-type-mismatch, fns-value<-symbol-with-pos)
(fns-value<-circle, ert-deftest fns-value<-bool-vector): New tests.
* doc/lispref/sequences.texi (Sequence Functions):
* doc/lispref/numbers.texi (Comparison of Numbers):
* doc/lispref/strings.texi (Text Comparison):
Document the new value< function.
* etc/NEWS: Announce.
Diffstat (limited to 'src/data.c')
| -rw-r--r-- | src/data.c | 26 |
1 files changed, 2 insertions, 24 deletions
diff --git a/src/data.c b/src/data.c index 69b990bed76..a86f86c52f5 100644 --- a/src/data.c +++ b/src/data.c | |||
| @@ -3835,30 +3835,6 @@ count_trailing_zero_bits (bits_word val) | |||
| 3835 | } | 3835 | } |
| 3836 | } | 3836 | } |
| 3837 | 3837 | ||
| 3838 | static bits_word | ||
| 3839 | bits_word_to_host_endian (bits_word val) | ||
| 3840 | { | ||
| 3841 | #ifndef WORDS_BIGENDIAN | ||
| 3842 | return val; | ||
| 3843 | #else | ||
| 3844 | if (BITS_WORD_MAX >> 31 == 1) | ||
| 3845 | return bswap_32 (val); | ||
| 3846 | if (BITS_WORD_MAX >> 31 >> 31 >> 1 == 1) | ||
| 3847 | return bswap_64 (val); | ||
| 3848 | { | ||
| 3849 | int i; | ||
| 3850 | bits_word r = 0; | ||
| 3851 | for (i = 0; i < sizeof val; i++) | ||
| 3852 | { | ||
| 3853 | r = ((r << 1 << (CHAR_BIT - 1)) | ||
| 3854 | | (val & ((1u << 1 << (CHAR_BIT - 1)) - 1))); | ||
| 3855 | val = val >> 1 >> (CHAR_BIT - 1); | ||
| 3856 | } | ||
| 3857 | return r; | ||
| 3858 | } | ||
| 3859 | #endif | ||
| 3860 | } | ||
| 3861 | |||
| 3862 | DEFUN ("bool-vector-exclusive-or", Fbool_vector_exclusive_or, | 3838 | DEFUN ("bool-vector-exclusive-or", Fbool_vector_exclusive_or, |
| 3863 | Sbool_vector_exclusive_or, 2, 3, 0, | 3839 | Sbool_vector_exclusive_or, 2, 3, 0, |
| 3864 | doc: /* Return A ^ B, bitwise exclusive or. | 3840 | doc: /* Return A ^ B, bitwise exclusive or. |
| @@ -4072,6 +4048,7 @@ syms_of_data (void) | |||
| 4072 | DEFSYM (Qminibuffer_quit, "minibuffer-quit"); | 4048 | DEFSYM (Qminibuffer_quit, "minibuffer-quit"); |
| 4073 | DEFSYM (Qwrong_length_argument, "wrong-length-argument"); | 4049 | DEFSYM (Qwrong_length_argument, "wrong-length-argument"); |
| 4074 | DEFSYM (Qwrong_type_argument, "wrong-type-argument"); | 4050 | DEFSYM (Qwrong_type_argument, "wrong-type-argument"); |
| 4051 | DEFSYM (Qtype_mismatch, "type-mismatch") | ||
| 4075 | DEFSYM (Qargs_out_of_range, "args-out-of-range"); | 4052 | DEFSYM (Qargs_out_of_range, "args-out-of-range"); |
| 4076 | DEFSYM (Qvoid_function, "void-function"); | 4053 | DEFSYM (Qvoid_function, "void-function"); |
| 4077 | DEFSYM (Qcyclic_function_indirection, "cyclic-function-indirection"); | 4054 | DEFSYM (Qcyclic_function_indirection, "cyclic-function-indirection"); |
| @@ -4163,6 +4140,7 @@ syms_of_data (void) | |||
| 4163 | PUT_ERROR (Quser_error, error_tail, ""); | 4140 | PUT_ERROR (Quser_error, error_tail, ""); |
| 4164 | PUT_ERROR (Qwrong_length_argument, error_tail, "Wrong length argument"); | 4141 | PUT_ERROR (Qwrong_length_argument, error_tail, "Wrong length argument"); |
| 4165 | PUT_ERROR (Qwrong_type_argument, error_tail, "Wrong type argument"); | 4142 | PUT_ERROR (Qwrong_type_argument, error_tail, "Wrong type argument"); |
| 4143 | PUT_ERROR (Qtype_mismatch, error_tail, "Types do not match"); | ||
| 4166 | PUT_ERROR (Qargs_out_of_range, error_tail, "Args out of range"); | 4144 | PUT_ERROR (Qargs_out_of_range, error_tail, "Args out of range"); |
| 4167 | PUT_ERROR (Qvoid_function, error_tail, | 4145 | PUT_ERROR (Qvoid_function, error_tail, |
| 4168 | "Symbol's function definition is void"); | 4146 | "Symbol's function definition is void"); |