diff options
| author | Stefan Monnier | 2024-03-17 17:29:02 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2024-03-18 09:32:49 -0400 |
| commit | e624bc62752ceb2e60940c5fd9cb6e70611df71c (patch) | |
| tree | 43890e0601aacb600479590fb52ba5440e4fca91 | |
| parent | 706403f2aa3a306369a0150022da0cba1802ca2b (diff) | |
| download | emacs-e624bc62752ceb2e60940c5fd9cb6e70611df71c.tar.gz emacs-e624bc62752ceb2e60940c5fd9cb6e70611df71c.zip | |
(primitive-function): New type
The type hierarchy and `cl-type-of` code assumed that `subr-primitive`
only applies to functions, but since it also accepts special-forms it makes
it an unsuitable choice since it can't be a subtype of `compiled-function`.
So, use a new type `primitive-function` instead.
* lisp/subr.el (subr-primitive-p): Fix docstring (bug#69832).
(primitive-function-p): New function.
* lisp/emacs-lisp/cl-preloaded.el (primitive-function): Rename
from `subr-primitive` since `subr-primitive-p` means something else.
* src/data.c (Fcl_type_of): Return `primitive-function` instead
of `subr-primitive` for C functions.
(syms_of_data): Adjust accordingly.
* test/src/data-tests.el (data-tests--cl-type-of): Remove workaround.
| -rw-r--r-- | etc/NEWS | 4 | ||||
| -rw-r--r-- | lisp/emacs-lisp/cl-preloaded.el | 2 | ||||
| -rw-r--r-- | lisp/subr.el | 11 | ||||
| -rw-r--r-- | src/data.c | 4 | ||||
| -rw-r--r-- | test/src/data-tests.el | 4 |
5 files changed, 18 insertions, 7 deletions
| @@ -1652,6 +1652,10 @@ This function is like 'type-of' except that it sometimes returns | |||
| 1652 | a more precise type. For example, for nil and t it returns 'null' | 1652 | a more precise type. For example, for nil and t it returns 'null' |
| 1653 | and 'boolean' respectively, instead of just 'symbol'. | 1653 | and 'boolean' respectively, instead of just 'symbol'. |
| 1654 | 1654 | ||
| 1655 | ** New function `primitive-function-p`. | ||
| 1656 | This is like `subr-primitive-p` except that it returns t only if the | ||
| 1657 | argument is a function rather than a special-form. | ||
| 1658 | |||
| 1655 | ** Built-in types have now corresponding classes. | 1659 | ** Built-in types have now corresponding classes. |
| 1656 | At the Lisp level, this means that things like (cl-find-class 'integer) | 1660 | At the Lisp level, this means that things like (cl-find-class 'integer) |
| 1657 | will now return a class object, and at the UI level it means that | 1661 | will now return a class object, and at the UI level it means that |
diff --git a/lisp/emacs-lisp/cl-preloaded.el b/lisp/emacs-lisp/cl-preloaded.el index 3e89afea452..d11c97a3e3a 100644 --- a/lisp/emacs-lisp/cl-preloaded.el +++ b/lisp/emacs-lisp/cl-preloaded.el | |||
| @@ -436,7 +436,7 @@ For this build of Emacs it's %dbit." | |||
| 436 | "Type of the core syntactic elements of the Emacs Lisp language.") | 436 | "Type of the core syntactic elements of the Emacs Lisp language.") |
| 437 | (cl--define-built-in-type subr-native-elisp (subr compiled-function) | 437 | (cl--define-built-in-type subr-native-elisp (subr compiled-function) |
| 438 | "Type of functions that have been compiled by the native compiler.") | 438 | "Type of functions that have been compiled by the native compiler.") |
| 439 | (cl--define-built-in-type subr-primitive (subr compiled-function) | 439 | (cl--define-built-in-type primitive-function (subr compiled-function) |
| 440 | "Type of functions hand written in C.") | 440 | "Type of functions hand written in C.") |
| 441 | 441 | ||
| 442 | (unless (cl--class-parents (cl--find-class 'cl-structure-object)) | 442 | (unless (cl--class-parents (cl--find-class 'cl-structure-object)) |
diff --git a/lisp/subr.el b/lisp/subr.el index 38a3f6edb34..3de4412637f 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -312,11 +312,20 @@ value of last one, or nil if there are none." | |||
| 312 | cond '(empty-body unless) t))) | 312 | cond '(empty-body unless) t))) |
| 313 | 313 | ||
| 314 | (defsubst subr-primitive-p (object) | 314 | (defsubst subr-primitive-p (object) |
| 315 | "Return t if OBJECT is a built-in primitive function." | 315 | "Return t if OBJECT is a built-in primitive written in C. |
| 316 | Such objects can be functions or special forms." | ||
| 316 | (declare (side-effect-free error-free)) | 317 | (declare (side-effect-free error-free)) |
| 317 | (and (subrp object) | 318 | (and (subrp object) |
| 318 | (not (subr-native-elisp-p object)))) | 319 | (not (subr-native-elisp-p object)))) |
| 319 | 320 | ||
| 321 | (defsubst primitive-function-p (object) | ||
| 322 | "Return t if OBJECT is a built-in primitive function. | ||
| 323 | This excludes special forms, since they are not functions." | ||
| 324 | (declare (side-effect-free error-free)) | ||
| 325 | (and (subrp object) | ||
| 326 | (not (or (subr-native-elisp-p object) | ||
| 327 | (eq (cdr (subr-arity object)) 'unevalled))))) | ||
| 328 | |||
| 320 | (defsubst xor (cond1 cond2) | 329 | (defsubst xor (cond1 cond2) |
| 321 | "Return the boolean exclusive-or of COND1 and COND2. | 330 | "Return the boolean exclusive-or of COND1 and COND2. |
| 322 | If only one of the arguments is non-nil, return it; otherwise | 331 | If only one of the arguments is non-nil, return it; otherwise |
diff --git a/src/data.c b/src/data.c index 5d6b6e0ba9d..69b990bed76 100644 --- a/src/data.c +++ b/src/data.c | |||
| @@ -248,7 +248,7 @@ a fixed set of types. */) | |||
| 248 | case PVEC_SUBR: | 248 | case PVEC_SUBR: |
| 249 | return XSUBR (object)->max_args == UNEVALLED ? Qspecial_form | 249 | return XSUBR (object)->max_args == UNEVALLED ? Qspecial_form |
| 250 | : SUBR_NATIVE_COMPILEDP (object) ? Qsubr_native_elisp | 250 | : SUBR_NATIVE_COMPILEDP (object) ? Qsubr_native_elisp |
| 251 | : Qsubr_primitive; | 251 | : Qprimitive_function; |
| 252 | case PVEC_COMPILED: return Qcompiled_function; | 252 | case PVEC_COMPILED: return Qcompiled_function; |
| 253 | case PVEC_BUFFER: return Qbuffer; | 253 | case PVEC_BUFFER: return Qbuffer; |
| 254 | case PVEC_CHAR_TABLE: return Qchar_table; | 254 | case PVEC_CHAR_TABLE: return Qchar_table; |
| @@ -4245,7 +4245,7 @@ syms_of_data (void) | |||
| 4245 | DEFSYM (Qwindow, "window"); | 4245 | DEFSYM (Qwindow, "window"); |
| 4246 | DEFSYM (Qsubr, "subr"); | 4246 | DEFSYM (Qsubr, "subr"); |
| 4247 | DEFSYM (Qspecial_form, "special-form"); | 4247 | DEFSYM (Qspecial_form, "special-form"); |
| 4248 | DEFSYM (Qsubr_primitive, "subr-primitive"); | 4248 | DEFSYM (Qprimitive_function, "primitive-function"); |
| 4249 | DEFSYM (Qsubr_native_elisp, "subr-native-elisp"); | 4249 | DEFSYM (Qsubr_native_elisp, "subr-native-elisp"); |
| 4250 | DEFSYM (Qcompiled_function, "compiled-function"); | 4250 | DEFSYM (Qcompiled_function, "compiled-function"); |
| 4251 | DEFSYM (Qbuffer, "buffer"); | 4251 | DEFSYM (Qbuffer, "buffer"); |
diff --git a/test/src/data-tests.el b/test/src/data-tests.el index 9d76c58224d..daa49e671b5 100644 --- a/test/src/data-tests.el +++ b/test/src/data-tests.el | |||
| @@ -869,9 +869,7 @@ comparing the subr with a much slower Lisp implementation." | |||
| 869 | tree-sitter-node tree-sitter-parser | 869 | tree-sitter-node tree-sitter-parser |
| 870 | ;; `functionp' also matches things of type | 870 | ;; `functionp' also matches things of type |
| 871 | ;; `symbol' and `cons'. | 871 | ;; `symbol' and `cons'. |
| 872 | ;; FIXME: `subr-primitive-p' also matches | 872 | function)) |
| 873 | ;; special-forms. | ||
| 874 | function subr-primitive)) | ||
| 875 | (should-not (cl-typep val subtype))))))))) | 873 | (should-not (cl-typep val subtype))))))))) |
| 876 | 874 | ||
| 877 | 875 | ||