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.

View in manual

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)))
      (if macro
	  (setq fun (cdr fun)))
      (prog1
          (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
            (let (final-eval)
              (when (or (symbolp form) (eq (car-safe fun) 'closure))
                ;; `fun' is a function *value*, so try to recover its corresponding
                ;; source code.
                (setq lexical-binding (eq (car fun) 'closure))
                (setq fun (byte-compile--reify-function fun))
                (setq final-eval t))
              ;; Expand macros.
              (setq fun (byte-compile-preprocess fun))
              (setq fun (byte-compile-top-level fun nil 'eval))
              (if (symbolp form)
                  ;; 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 t)))
              (if final-eval
                  (setq fun (eval fun t)))
              (if macro (push 'macro fun))
              (if (symbolp form) (fset form fun))
              fun))))))))