From 68c09c6b741be5005b90152c59e781cb0f80704d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mattias=20Engdeg=C3=A5rd?= Date: Tue, 30 Nov 2021 11:32:20 +0100 Subject: [PATCH] Better CPS conversion of multi-binding `let` * lisp/emacs-lisp/generator.el (cps--transform-1): Don't translate single-binding `let` into `let*` with an extra temporary variable; it just adds two more useless states. --- lisp/emacs-lisp/generator.el | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lisp/emacs-lisp/generator.el b/lisp/emacs-lisp/generator.el index 2075ac472d1..4e286ed7ec4 100644 --- a/lisp/emacs-lisp/generator.el +++ b/lisp/emacs-lisp/generator.el @@ -291,8 +291,15 @@ DYNAMIC-VAR bound to STATIC-VAR." (cps--transform-1 `(progn ,@rest) next-state))) - ;; Process `let' in a helper function that transforms it into a - ;; let* with temporaries. + (`(,(or 'let 'let*) () . ,body) + (cps--transform-1 `(progn ,@body) next-state)) + + (`(let (,binding) . ,body) + (cps--transform-1 `(let* (,binding) ,@body) next-state)) + + ;; Transform multi-variable `let' into `let*': + ;; (let ((v1 e1) ... (vN eN)) BODY) + ;; -> (let* ((t1 e1) ... (tN eN) (v1 t1) (vN tN)) BODY) (`(let ,bindings . ,body) (let* ((bindings (cl-loop for binding in bindings @@ -315,9 +322,6 @@ DYNAMIC-VAR bound to STATIC-VAR." ;; Process `let*' binding: process one binding at a time. Flatten ;; lexical bindings. - (`(let* () . ,body) - (cps--transform-1 `(progn ,@body) next-state)) - (`(let* (,binding . ,more-bindings) . ,body) (let* ((var (if (symbolp binding) binding (car binding))) (value-form (car (cdr-safe binding))) -- 2.39.5