Function: byte-compile--reify-function

byte-compile--reify-function is a byte-compiled function defined in bytecomp.el.gz.

Signature

(byte-compile--reify-function FUN)

Documentation

Return an expression which will evaluate to a function value FUN.

FUN should be either a lambda value or a closure value.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/bytecomp.el.gz
(defun byte-compile--reify-function (fun)
  "Return an expression which will evaluate to a function value FUN.
FUN should be either a `lambda' value or a `closure' value."
  (pcase-let* (((or (and `(lambda ,args . ,body) (let env nil))
                    `(closure ,env ,args . ,body))
                fun)
               (preamble nil)
               (renv ()))
    ;; Split docstring and `interactive' form from body.
    (when (stringp (car body))
      (push (pop body) preamble))
    (when (eq (car-safe (car body)) 'interactive)
      (push (pop body) preamble))
    (setq preamble (nreverse preamble))
    ;; Turn the function's closed vars (if any) into local let bindings.
    (dolist (binding env)
      (cond
       ((consp binding)
        (push `(,(car binding) ',(cdr binding)) renv))
       ((eq binding t))
       (t (push `(defvar ,binding) body))))
    (if (null renv)
        `(lambda ,args ,@preamble ,@body)
      `(let ,renv (lambda ,args ,@preamble ,@body)))))