mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-11-29 07:58:28 +00:00
Simplify byte-compiler assuming cconv normalisations
* lisp/emacs-lisp/byte-opt.el (byte-optimize-form-code-walker) (byte-optimize-let-form, byte-optimize-letX): * lisp/emacs-lisp/bytecomp.el (byte-compile-unwind-protect): Simplify source optimisation and codegen code that can now rely on normalised let/let* and unwind-protect forms.
This commit is contained in:
parent
d6600481ae
commit
1ac74e2862
@ -422,7 +422,7 @@ for speeding up processing.")
|
||||
(byte-optimize-body (cdr clause) for-effect))))
|
||||
clauses)))
|
||||
|
||||
(`(unwind-protect ,exp . ,exps)
|
||||
(`(unwind-protect ,exp :fun-body ,f)
|
||||
;; The unwinding part of an unwind-protect is compiled (and thus
|
||||
;; optimized) as a top-level form, but run the optimizer for it here
|
||||
;; anyway for lexical variable usage and substitution. But the
|
||||
@ -430,13 +430,7 @@ for speeding up processing.")
|
||||
;; unwind-protect itself. (The unwinding part is always for effect,
|
||||
;; but that isn't handled properly yet.)
|
||||
(let ((bodyform (byte-optimize-form exp for-effect)))
|
||||
(pcase exps
|
||||
(`(:fun-body ,f)
|
||||
`(,fn ,bodyform
|
||||
:fun-body ,(byte-optimize-form f nil)))
|
||||
(_
|
||||
`(,fn ,bodyform
|
||||
. ,(byte-optimize-body exps t))))))
|
||||
`(,fn ,bodyform :fun-body ,(byte-optimize-form f nil))))
|
||||
|
||||
(`(catch ,tag . ,exps)
|
||||
`(,fn ,(byte-optimize-form tag nil)
|
||||
@ -695,13 +689,8 @@ for speeding up processing.")
|
||||
(let ((byte-optimize--lexvars nil))
|
||||
(cons
|
||||
(mapcar (lambda (binding)
|
||||
(if (symbolp binding)
|
||||
binding
|
||||
(when (or (atom binding) (cddr binding))
|
||||
(byte-compile-warn-x
|
||||
binding "malformed let binding: `%S'" binding))
|
||||
(list (car binding)
|
||||
(byte-optimize-form (nth 1 binding) nil))))
|
||||
(list (car binding)
|
||||
(byte-optimize-form (nth 1 binding) nil)))
|
||||
(car form))
|
||||
(byte-optimize-body (cdr form) for-effect)))))
|
||||
|
||||
@ -1253,28 +1242,17 @@ See Info node `(elisp) Integer Basics'."
|
||||
;; Body is empty or just contains a constant.
|
||||
(`(,head ,bindings . ,(or '() `(,(and const (pred macroexp-const-p)))))
|
||||
(if (eq head 'let)
|
||||
`(progn ,@(mapcar (lambda (binding)
|
||||
(and (consp binding) (cadr binding)))
|
||||
bindings)
|
||||
,const)
|
||||
`(,head ,(butlast bindings)
|
||||
,@(and (consp (car (last bindings)))
|
||||
(cdar (last bindings)))
|
||||
,const)))
|
||||
`(progn ,@(mapcar #'cadr bindings) ,const)
|
||||
`(,head ,(butlast bindings) ,(cadar (last bindings)) ,const)))
|
||||
|
||||
;; Body is last variable.
|
||||
(`(,head ,(and bindings
|
||||
(let last-var (let ((last (car (last bindings))))
|
||||
(if (consp last) (car last) last))))
|
||||
(let last-var (caar (last bindings))))
|
||||
,(and last-var ; non-linear pattern
|
||||
(pred symbolp) (pred (not keywordp)) (pred (not booleanp))))
|
||||
(if (eq head 'let)
|
||||
`(progn ,@(mapcar (lambda (binding)
|
||||
(and (consp binding) (cadr binding)))
|
||||
bindings))
|
||||
`(,head ,(butlast bindings)
|
||||
,@(and (consp (car (last bindings)))
|
||||
(cdar (last bindings))))))
|
||||
`(progn ,@(mapcar #'cadr bindings))
|
||||
`(,head ,(butlast bindings) ,(cadar (last bindings)))))
|
||||
|
||||
(_ form)))
|
||||
|
||||
|
@ -4806,11 +4806,8 @@ binding slots have been popped."
|
||||
(byte-compile-out-tag endtag)))
|
||||
|
||||
(defun byte-compile-unwind-protect (form)
|
||||
(pcase (cddr form)
|
||||
(`(:fun-body ,f)
|
||||
(byte-compile-form f))
|
||||
(handlers
|
||||
(byte-compile-form `#'(lambda () ,@handlers))))
|
||||
(cl-assert (eq (caddr form) :fun-body))
|
||||
(byte-compile-form (nth 3 form))
|
||||
(byte-compile-out 'byte-unwind-protect 0)
|
||||
(byte-compile-form-do-effect (car (cdr form)))
|
||||
(byte-compile-out 'byte-unbind 1))
|
||||
|
Loading…
Reference in New Issue
Block a user