diff options
| author | Stefan Monnier | 2025-05-07 13:54:47 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2025-05-07 13:54:47 -0400 |
| commit | 9f50fdf1e75040d7feaa1edb235377a33da94781 (patch) | |
| tree | 744b772ac65caef61cb6955f4bd64c0e766c8fb3 | |
| parent | d7459da58de8bf317d7669f001c35244ba38d17b (diff) | |
| download | emacs-scratch/cl-types.tar.gz emacs-scratch/cl-types.zip | |
(cl-deftype): Don't set `cl-deftype-handler` directlyscratch/cl-types
In order to make it easier to change that in the future, let
`cl--define-derived-type` take care of storing the derived
type's function into `cl-deftype-handler`.
* lisp/emacs-lisp/cl-preloaded.el (cl--define-derived-type):
Change calling convention. Set `cl-deftype-handler`.
* lisp/emacs-lisp/cl-macs.el (cl-deftype): Don't set `cl-deftype-handler`,
instead pass the function to `cl--define-derived-type`.
| -rw-r--r-- | lisp/emacs-lisp/cl-macs.el | 13 | ||||
| -rw-r--r-- | lisp/emacs-lisp/cl-preloaded.el | 13 |
2 files changed, 12 insertions, 14 deletions
diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el index 0fc791890aa..c45effbb9b6 100644 --- a/lisp/emacs-lisp/cl-macs.el +++ b/lisp/emacs-lisp/cl-macs.el | |||
| @@ -3803,9 +3803,6 @@ If PARENTS is non-nil, ARGLIST must be nil." | |||
| 3803 | (declare (debug cl-defmacro) (doc-string 3) (indent 2)) | 3803 | (declare (debug cl-defmacro) (doc-string 3) (indent 2)) |
| 3804 | (pcase-let* | 3804 | (pcase-let* |
| 3805 | ((`(,decls . ,forms) (macroexp-parse-body body)) | 3805 | ((`(,decls . ,forms) (macroexp-parse-body body)) |
| 3806 | (docstring (if (stringp (car decls)) | ||
| 3807 | (car decls) | ||
| 3808 | (cadr (assq :documentation decls)))) | ||
| 3809 | (declares (assq 'declare decls)) | 3806 | (declares (assq 'declare decls)) |
| 3810 | (parent-decl (assq 'parents (cdr declares))) | 3807 | (parent-decl (assq 'parents (cdr declares))) |
| 3811 | (parents (cdr parent-decl))) | 3808 | (parents (cdr parent-decl))) |
| @@ -3817,12 +3814,10 @@ If PARENTS is non-nil, ARGLIST must be nil." | |||
| 3817 | (and parents arglist | 3814 | (and parents arglist |
| 3818 | (error "Parents specified, but arglist not empty")) | 3815 | (error "Parents specified, but arglist not empty")) |
| 3819 | `(eval-and-compile | 3816 | `(eval-and-compile |
| 3820 | (cl--define-derived-type ',name ',parents ',arglist ,docstring) | 3817 | (cl--define-derived-type |
| 3821 | (define-symbol-prop ',name 'cl-deftype-handler | 3818 | ',name |
| 3822 | (cl-function | 3819 | (cl-function (lambda (&cl-defs ('*) ,@arglist) ,@decls ,@forms)) |
| 3823 | (lambda (&cl-defs ('*) ,@arglist) | 3820 | ',parents)))) |
| 3824 | ,@decls | ||
| 3825 | ,@forms)))))) | ||
| 3826 | 3821 | ||
| 3827 | (static-if (not (fboundp 'cl--define-derived-type)) | 3822 | (static-if (not (fboundp 'cl--define-derived-type)) |
| 3828 | nil ;; Can't define it yet! | 3823 | nil ;; Can't define it yet! |
diff --git a/lisp/emacs-lisp/cl-preloaded.el b/lisp/emacs-lisp/cl-preloaded.el index 7dac0519681..8956245f24c 100644 --- a/lisp/emacs-lisp/cl-preloaded.el +++ b/lisp/emacs-lisp/cl-preloaded.el | |||
| @@ -491,10 +491,11 @@ The fields are used as follows: | |||
| 491 | (:copier nil)) | 491 | (:copier nil)) |
| 492 | "Type descriptors for derived types, i.e. defined by `cl-deftype'.") | 492 | "Type descriptors for derived types, i.e. defined by `cl-deftype'.") |
| 493 | 493 | ||
| 494 | (defun cl--define-derived-type (name parents arglist &optional docstring) | 494 | (defun cl--define-derived-type (name expander &optional parents) |
| 495 | "Register derived type with NAME for method dispatching. | 495 | "Register derived type with NAME for method dispatching. |
| 496 | PARENTS is a list of types NAME is a subtype of, or nil. | 496 | EXPANDER is the function that computes the type specifier from |
| 497 | DOCSTRING is an optional documentation string." | 497 | the arguments passed to the derived type. |
| 498 | PARENTS is a list of types NAME is a subtype of, or nil." | ||
| 498 | (let* ((class (cl--find-class name))) | 499 | (let* ((class (cl--find-class name))) |
| 499 | (when class | 500 | (when class |
| 500 | (or (cl-derived-type-class-p class) | 501 | (or (cl-derived-type-class-p class) |
| @@ -505,7 +506,9 @@ DOCSTRING is an optional documentation string." | |||
| 505 | (error "Type in another class: %S" (type-of class)))) | 506 | (error "Type in another class: %S" (type-of class)))) |
| 506 | ;; Setup a type descriptor for NAME. | 507 | ;; Setup a type descriptor for NAME. |
| 507 | (setf (cl--find-class name) | 508 | (setf (cl--find-class name) |
| 508 | (cl--derived-type-class-make name docstring parents)) | 509 | (cl--derived-type-class-make name (function-documentation expander) |
| 510 | parents)) | ||
| 511 | (define-symbol-prop name 'cl-deftype-handler expander) | ||
| 509 | ;; Record new type. The constructor of the class | 512 | ;; Record new type. The constructor of the class |
| 510 | ;; `cl-type-class' already ensures that parent types must be | 513 | ;; `cl-type-class' already ensures that parent types must be |
| 511 | ;; defined before their "child" types (i.e. already added to | 514 | ;; defined before their "child" types (i.e. already added to |
| @@ -527,7 +530,7 @@ DOCSTRING is an optional documentation string." | |||
| 527 | (or (memq name cl--derived-type-list) | 530 | (or (memq name cl--derived-type-list) |
| 528 | ;; Exclude types that can't be used without arguments. | 531 | ;; Exclude types that can't be used without arguments. |
| 529 | ;; They'd signal errors in `cl-types-of'! | 532 | ;; They'd signal errors in `cl-types-of'! |
| 530 | (not (memq (car arglist) '(nil &rest &optional &keys))) | 533 | (not (ignore-errors (funcall expander))) |
| 531 | (push name cl--derived-type-list)))) | 534 | (push name cl--derived-type-list)))) |
| 532 | 535 | ||
| 533 | ;; Make sure functions defined with cl-defsubst can be inlined even in | 536 | ;; Make sure functions defined with cl-defsubst can be inlined even in |