Function: byte-compile-defvar
byte-compile-defvar is a byte-compiled function defined in
bytecomp.el.gz.
Signature
(byte-compile-defvar FORM &optional TOPLEVEL)
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/bytecomp.el.gz
(defun byte-compile-defvar (form &optional toplevel)
(let* ((fun (nth 0 form))
(var (nth 1 form))
(value (nth 2 form))
(string (nth 3 form)))
(byte-compile--declare-var var (not toplevel))
(if (eq fun 'defconst)
(push var byte-compile-const-variables))
(cond
((stringp string)
(setq string (byte-compile--docstring string fun var 'is-a-value)))
(string
(byte-compile-warn-x
string
"third arg to `%s %s' is not a string: %s"
fun var string)))
(if toplevel
;; At top-level we emit calls to defvar/defconst.
(if (and (null (cddr form)) ;No `value' provided.
(eq (car form) 'defvar)) ;Just a declaration.
nil
(let ((tail (nthcdr 4 form)))
(when (or tail string) (push string tail))
(when (cddr form)
(push (if (not (consp value)) value
(byte-compile-top-level value nil 'file))
tail))
`(,fun ,var ,@tail)))
;; At non-top-level, since there is no byte code for
;; defvar/defconst, we delegate the actual work to the function
;; version of the special form, named with a "-1" suffix.
(byte-compile-form-do-effect
(cond
((eq fun 'defconst)
`(defconst-1 ',var ,@(byte-compile--list-with-n
(nthcdr 2 form) 1 (macroexp-quote string))))
((not (cddr form)) `',var) ; A simple (defvar foo) just returns foo.
(t `(defvar-1 ',var
;; Don't eval `value' if `defvar' wouldn't eval it either.
,(if (macroexp-const-p value) value
`(if (boundp ',var) nil ,value))
,@(byte-compile--list-with-n
(nthcdr 3 form) 0 (macroexp-quote string)))))))))