Function: byte-compile
byte-compile is an autoloaded and byte-compiled function defined in
bytecomp.el.gz.
Signature
(byte-compile FORM)
Documentation
If FORM is a symbol, byte-compile its function definition.
If FORM is a lambda or a macro, byte-compile it as a function.
Probably introduced at or before Emacs version 18.
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/bytecomp.el.gz
;;;###autoload
(defun byte-compile (form)
"If FORM is a symbol, byte-compile its function definition.
If FORM is a lambda or a macro, byte-compile it as a function."
(displaying-byte-compile-warnings
(byte-compile-close-variables
(let* ((lexical-binding lexical-binding)
(fun (if (symbolp form)
(symbol-function form)
form))
(macro (eq (car-safe fun) 'macro))
(need-a-value nil))
(when macro
(setq need-a-value t)
(setq fun (cdr fun)))
(cond
;; Up until Emacs-24.1, byte-compile silently did nothing
;; when asked to compile something invalid. So let's tone
;; down the complaint from an error to a simple message for
;; the known case where signaling an error causes problems.
((compiled-function-p fun)
(message "Function %s is already compiled"
(if (symbolp form) form "provided"))
fun)
(t
(when (or (symbolp form) (interpreted-function-p fun))
;; `fun' is a function *value*, so try to recover its
;; corresponding source code.
(if (not (interpreted-function-p fun))
(setq lexical-binding nil)
(setq lexical-binding (not (null (aref fun 2))))
(setq fun (byte-compile--reify-function fun)))
(setq need-a-value t))
;; Expand macros.
(setq fun (byte-compile-preprocess fun))
(setq fun (byte-compile-top-level fun nil 'eval))
(when need-a-value
;; `byte-compile-top-level' returns an *expression* equivalent to
;; the `fun' expression, so we need to evaluate it, tho normally
;; this is not needed because the expression is just a constant
;; byte-code object, which is self-evaluating.
(setq fun (eval fun lexical-binding)))
(if macro (push 'macro fun))
(if (symbolp form) (fset form fun))
fun))))))