Skip to content

Commit 0d6c513

Browse files
committed
* lisp/emacs-lisp/cl-macs.el: More care with eval and with cl-typep
(cl-eval-when, cl--compile-time-too, cl-load-time-value): Obey lexical-binding. (cl-check-type): Prefer the predicate rather than the type in the error signal when it's easy to do (as is done outside of CL). (cl-deftype-satisfies): Add definitions for standard types.
1 parent efe85a5 commit 0d6c513

File tree

1 file changed

+37
-20
lines changed

1 file changed

+37
-20
lines changed

lisp/emacs-lisp/cl-macs.el

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
;; one, you may want to amend the other, too.
7676
;;;###autoload
7777
(define-obsolete-function-alias 'cl--compiler-macro-cXXr
78-
'internal--compiler-macro-cXXr "25.1")
78+
#'internal--compiler-macro-cXXr "25.1")
7979

8080
;;; Some predicates for analyzing Lisp forms.
8181
;; These are used by various
@@ -714,9 +714,9 @@ If `eval' is in WHEN, BODY is evaluated when interpreted or at non-top-level.
714714
(let ((comp (or (memq 'compile when) (memq :compile-toplevel when)))
715715
(cl--not-toplevel t))
716716
(if (or (memq 'load when) (memq :load-toplevel when))
717-
(if comp (cons 'progn (mapcar 'cl--compile-time-too body))
717+
(if comp (cons 'progn (mapcar #'cl--compile-time-too body))
718718
`(if nil nil ,@body))
719-
(progn (if comp (eval (cons 'progn body))) nil)))
719+
(progn (if comp (eval (cons 'progn body) lexical-binding)) nil)))
720720
(and (or (memq 'eval when) (memq :execute when))
721721
(cons 'progn body))))
722722

@@ -725,13 +725,13 @@ If `eval' is in WHEN, BODY is evaluated when interpreted or at non-top-level.
725725
(setq form (macroexpand
726726
form (cons '(cl-eval-when) byte-compile-macro-environment))))
727727
(cond ((eq (car-safe form) 'progn)
728-
(cons 'progn (mapcar 'cl--compile-time-too (cdr form))))
728+
(cons 'progn (mapcar #'cl--compile-time-too (cdr form))))
729729
((eq (car-safe form) 'cl-eval-when)
730730
(let ((when (nth 1 form)))
731731
(if (or (memq 'eval when) (memq :execute when))
732732
`(cl-eval-when (compile ,@when) ,@(cddr form))
733733
form)))
734-
(t (eval form) form)))
734+
(t (eval form lexical-binding) form)))
735735

736736
;;;###autoload
737737
(defmacro cl-load-time-value (form &optional _read-only)
@@ -757,7 +757,7 @@ The result of the body appears to the compiler as a quoted constant."
757757
;; temp is set before we use it.
758758
(print set byte-compile--outbuffer))
759759
temp)
760-
`',(eval form)))
760+
`',(eval form lexical-binding)))
761761

762762

763763
;;; Conditional control structures.
@@ -1495,16 +1495,16 @@ For more details, see Info node `(cl)Loop Facility'.
14951495
(pop cl--loop-args))
14961496
(if (and ands loop-for-bindings)
14971497
(push (nreverse loop-for-bindings) cl--loop-bindings)
1498-
(setq cl--loop-bindings (nconc (mapcar 'list loop-for-bindings)
1499-
cl--loop-bindings)))
1498+
(setq cl--loop-bindings (nconc (mapcar #'list loop-for-bindings)
1499+
cl--loop-bindings)))
15001500
(if loop-for-sets
15011501
(push `(progn
15021502
,(cl--loop-let (nreverse loop-for-sets) 'setq ands)
15031503
t)
15041504
cl--loop-body))
15051505
(when loop-for-steps
15061506
(push (cons (if ands 'cl-psetq 'setq)
1507-
(apply 'append (nreverse loop-for-steps)))
1507+
(apply #'append (nreverse loop-for-steps)))
15081508
cl--loop-steps))))
15091509

15101510
((eq word 'repeat)
@@ -1697,7 +1697,7 @@ If BODY is `setq', then use SPECS for assignments rather than for bindings."
16971697
(push binding new))))
16981698
(if (eq body 'setq)
16991699
(let ((set (cons (if par 'cl-psetq 'setq)
1700-
(apply 'nconc (nreverse new)))))
1700+
(apply #'nconc (nreverse new)))))
17011701
(if temps `(let* ,(nreverse temps) ,set) set))
17021702
`(,(if par 'let 'let*)
17031703
,(nconc (nreverse temps) (nreverse new)) ,@body))))
@@ -1823,7 +1823,7 @@ For more details, see `cl-do*' description in Info node `(cl) Iteration'.
18231823
(and sets
18241824
(list (cons (if (or star (not (cdr sets)))
18251825
'setq 'cl-psetq)
1826-
(apply 'append sets))))))
1826+
(apply #'append sets))))))
18271827
,@(or (cdr endtest) '(nil)))))
18281828

18291829
;;;###autoload
@@ -2468,7 +2468,7 @@ Each PLACE may be a symbol, or any generalized variable allowed by `setf'.
24682468

24692469
\(fn PLACE...)"
24702470
(declare (debug (&rest place)))
2471-
(if (not (memq nil (mapcar 'symbolp args)))
2471+
(if (not (memq nil (mapcar #'symbolp args)))
24722472
(and (cdr args)
24732473
(let ((sets nil)
24742474
(first (car args)))
@@ -3128,13 +3128,27 @@ Of course, we really can't know that for sure, so it's just a heuristic."
31283128
(or (cdr (assq sym byte-compile-function-environment))
31293129
(cdr (assq sym byte-compile-macro-environment))))))
31303130

3131-
(put 'null 'cl-deftype-satisfies #'null)
3132-
(put 'atom 'cl-deftype-satisfies #'atom)
3133-
(put 'real 'cl-deftype-satisfies #'numberp)
3134-
(put 'fixnum 'cl-deftype-satisfies #'integerp)
3135-
(put 'base-char 'cl-deftype-satisfies #'characterp)
3136-
(put 'character 'cl-deftype-satisfies #'natnump)
3137-
3131+
(pcase-dolist (`(,type . ,pred)
3132+
'((null . null)
3133+
(atom . atom)
3134+
(real . numberp)
3135+
(fixnum . integerp)
3136+
(base-char . characterp)
3137+
(character . natnump)
3138+
;; "Obvious" mappings.
3139+
(string . stringp)
3140+
(list . listp)
3141+
(symbol . symbolp)
3142+
(function . functionp)
3143+
(integer . integerp)
3144+
(float . floatp)
3145+
(boolean . booleanp)
3146+
(vector . vectorp)
3147+
(array . arrayp)
3148+
;; FIXME: Do we really want to consider this a type?
3149+
(integer-or-marker . integer-or-marker-p)
3150+
))
3151+
(put type 'cl-deftype-satisfies pred))
31383152

31393153
;;;###autoload
31403154
(define-inline cl-typep (val type)
@@ -3203,7 +3217,10 @@ STRING is an optional description of the desired type."
32033217
(macroexp-let2 macroexp-copyable-p temp form
32043218
`(progn (or (cl-typep ,temp ',type)
32053219
(signal 'wrong-type-argument
3206-
(list ,(or string `',type) ,temp ',form)))
3220+
(list ,(or string `',(if (eq 'satisfies
3221+
(car-safe type))
3222+
(cadr type) type))
3223+
,temp ',form)))
32073224
nil))))
32083225

32093226
;;;###autoload

0 commit comments

Comments
 (0)