Function: byte-compile-bind
byte-compile-bind is a byte-compiled function defined in
bytecomp.el.gz.
Signature
(byte-compile-bind VAR INIT-LEXENV)
Documentation
Emit byte-codes to bind VAR and update byte-compile--lexical-environment.
INIT-LEXENV should be a lexical-environment alist describing the positions of the init value that have been pushed on the stack. Return non-nil if the TOS value was popped.
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/bytecomp.el.gz
(defun byte-compile-bind (var init-lexenv)
"Emit byte-codes to bind VAR and update `byte-compile--lexical-environment'.
INIT-LEXENV should be a lexical-environment alist describing the
positions of the init value that have been pushed on the stack.
Return non-nil if the TOS value was popped."
;; The mix of lexical and dynamic bindings mean that we may have to
;; juggle things on the stack, to move them to TOS for
;; dynamic binding.
(if (not (cconv--not-lexical-var-p var byte-compile-bound-variables))
;; VAR is a simple stack-allocated lexical variable.
(progn (push (assq var init-lexenv)
byte-compile--lexical-environment)
(when (assq var byte-compile--known-dynamic-vars)
(byte-compile--warn-lexical-dynamic var 'let))
nil)
;; VAR should be dynamically bound.
(while (assq var byte-compile--lexical-environment)
;; This dynamic binding shadows a lexical binding.
(setq byte-compile--lexical-environment
(remq (assq var byte-compile--lexical-environment)
byte-compile--lexical-environment)))
(cond
((eq var (caar init-lexenv))
;; VAR is dynamic and is on the top of the
;; stack, so we can just bind it like usual.
(byte-compile-dynamic-variable-bind var)
t)
(t
;; VAR is dynamic, but we have to get its
;; value out of the middle of the stack.
(let ((stack-pos (cdr (assq var init-lexenv))))
(byte-compile-stack-ref stack-pos)
(byte-compile-dynamic-variable-bind var)
;; Now we have to store nil into its temporary
;; stack position so it doesn't prevent the value from being GC'd.
;; FIXME: Not worth the trouble.
;; (byte-compile-push-constant nil)
;; (byte-compile-stack-set stack-pos)
)
nil))))