From 9af602e30b26b33e5e2f8fdd0a51bc3304ef6cba Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Sun, 11 May 2025 01:30:01 -0400 Subject: [PATCH] lisp/emacs-lisp/cl-macs.el (cl--define-derived-type): Fix partial bootstrap (cherry picked from commit dfafe1830f06634ec779fd62f7081d4cc4f6d3e7) --- lisp/emacs-lisp/cl-macs.el | 66 ++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el index 4147ec25dbf..5ba10b8641e 100644 --- a/lisp/emacs-lisp/cl-macs.el +++ b/lisp/emacs-lisp/cl-macs.el @@ -3767,38 +3767,40 @@ If PARENTS is non-nil, ARGLIST must be nil." ;; loaded before `cl-preloaded.el' is defined. (put 'list 'cl-deftype-satisfies #'listp) -(static-if (not (fboundp 'cl--define-derived-type)) - nil ;; Can't define them yet! - (cl-deftype natnum () (declare (parents integer)) '(satisfies natnump)) - (cl-deftype character () (declare (parents fixnum natnum)) - '(and fixnum natnum)) - (cl-deftype base-char () (declare (parents character)) - '(satisfies characterp)) - (cl-deftype extended-char () (declare (parents character)) - '(and character (not base-char))) - (cl-deftype keyword () (declare (parents symbol)) '(satisfies keywordp)) - (cl-deftype command () - ;; FIXME: Can't use `function' as parent because of arrays as - ;; keyboard macros, which are redundant since `kmacro.el'!! - ;;(declare (parents function)) - '(satisfies commandp)) - - (eval-when-compile - (defmacro cl--defnumtype (type base) - `(cl-deftype ,type (&optional min max) - (list 'and ',base - (if (memq min '(* nil)) t - (if (consp min) - `(satisfies . ,(lambda (val) (> val (car min)))) - `(satisfies . ,(lambda (val) (>= val min))))) - (if (memq max '(* nil)) t - (if (consp max) - `(satisfies . ,(lambda (val) (< val (car max)))) - `(satisfies . ,(lambda (val) (<= val max))))))))) - ;;(cl--defnumtype integer ??) - ;;(cl--defnumtype float ??) - ;;(cl--defnumtype number ??) - (cl--defnumtype real number)) +;; Thanks to `eval-and-compile', `cl--define-derived-type' is needed +;; both at compile-time and at runtime, so we need to double-check. +(static-if (not (fboundp 'cl--define-derived-type)) nil + (unless (fboundp 'cl--define-derived-type) + (cl-deftype natnum () (declare (parents integer)) '(satisfies natnump)) + (cl-deftype character () (declare (parents fixnum natnum)) + '(and fixnum natnum)) + (cl-deftype base-char () (declare (parents character)) + '(satisfies characterp)) + (cl-deftype extended-char () (declare (parents character)) + '(and character (not base-char))) + (cl-deftype keyword () (declare (parents symbol)) '(satisfies keywordp)) + (cl-deftype command () + ;; FIXME: Can't use `function' as parent because of arrays as + ;; keyboard macros, which are redundant since `kmacro.el'!! + ;;(declare (parents function)) + '(satisfies commandp)) + + (eval-when-compile + (defmacro cl--defnumtype (type base) + `(cl-deftype ,type (&optional min max) + (list 'and ',base + (if (memq min '(* nil)) t + (if (consp min) + `(satisfies . ,(lambda (val) (> val (car min)))) + `(satisfies . ,(lambda (val) (>= val min))))) + (if (memq max '(* nil)) t + (if (consp max) + `(satisfies . ,(lambda (val) (< val (car max)))) + `(satisfies . ,(lambda (val) (<= val max))))))))) + ;;(cl--defnumtype integer ??) + ;;(cl--defnumtype float ??) + ;;(cl--defnumtype number ??) + (cl--defnumtype real number))) ;; Additional functions that we can now define because we've defined ;; `cl-defsubst' and `cl-typep'. -- 2.39.5