summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorLars Hansen <larsh@soem.dk>2005-10-23 07:33:45 +0000
committerLars Hansen <larsh@soem.dk>2005-10-23 07:33:45 +0000
commit4ec5239cc90673a066fa12caffb1ac9461f2dd2f (patch)
tree7de4f3466444a020088a14d00a3316a028ccb748 /lisp/emacs-lisp
parent02c583a44ca5f1f7f9ba7eb32c0e2f5781a37f91 (diff)
downloademacs-4ec5239cc90673a066fa12caffb1ac9461f2dd2f.tar.gz
emacs-4ec5239cc90673a066fa12caffb1ac9461f2dd2f.tar.bz2
emacs-4ec5239cc90673a066fa12caffb1ac9461f2dd2f.zip
(byte-compile-lambda): Add parameter add-lambda.
(byte-compile-file-form-defmumble, byte-compile-defun, byte-compile-defmacro): Use it. (byte-compile-form): Don't call byte-compile-set-symbol-position when a byte-compile handler is called.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/bytecomp.el34
1 files changed, 22 insertions, 12 deletions
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index 559d2bd86c6..47bcbbcae6c 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -908,6 +908,13 @@ Each function's symbol gets added to `byte-compile-noruntime-functions'."
;; list. If our current position is after the symbol's position, we
;; assume we've already passed that point, and look for the next
;; occurrence of the symbol.
+;;
+;; This function should not be called twice for the same occurrence of
+;; a symbol, and it should not be called for symbols generated by the
+;; byte compiler itself; because rather than just fail looking up the
+;; symbol, we may find an occurrence of the symbol further ahead, and
+;; then `byte-compile-last-position' as advanced too far.
+;;
;; So your're probably asking yourself: Isn't this function a
;; gross hack? And the answer, of course, would be yes.
(defun byte-compile-set-symbol-position (sym &optional allow-previous)
@@ -2304,7 +2311,7 @@ list that represents a doc string reference.
',name ',declaration))
outbuffer)))))
- (let* ((new-one (byte-compile-lambda (cons 'lambda (nthcdr 2 form))))
+ (let* ((new-one (byte-compile-lambda (nthcdr 2 form) t))
(code (byte-compile-byte-code-maker new-one)))
(if this-one
(setcdr this-one new-one)
@@ -2500,10 +2507,16 @@ If FORM is a lambda or a macro, byte-compile it as a function."
;; Byte-compile a lambda-expression and return a valid function.
;; The value is usually a compiled function but may be the original
;; lambda-expression.
-(defun byte-compile-lambda (fun)
- (unless (eq 'lambda (car-safe fun))
- (error "Not a lambda list: %S" fun))
- (byte-compile-set-symbol-position 'lambda)
+;; When ADD-LAMBDA is non-nil, the symbol `lambda' is added as head
+;; of the list FUN and `byte-compile-set-symbol-position' is not called.
+;; Use this feature to avoid calling `byte-compile-set-symbol-position'
+;; for symbols generated by the byte compiler itself.
+(defun byte-compile-lambda (fun &optional add-lambda)
+ (if add-lambda
+ (setq fun (cons 'lambda fun))
+ (unless (eq 'lambda (car-safe fun))
+ (error "Not a lambda list: %S" fun))
+ (byte-compile-set-symbol-position 'lambda))
(byte-compile-check-lambda-list (nth 1 fun))
(let* ((arglist (nth 1 fun))
(byte-compile-bound-variables
@@ -2755,9 +2768,7 @@ That command is designed for interactive use only" fn))
(or (not (byte-compile-version-cond
byte-compile-compatibility))
(not (get (get fn 'byte-opcode) 'emacs19-opcode))))
- (progn
- (byte-compile-set-symbol-position fn)
- (funcall handler form))
+ (funcall handler form)
(when (memq 'callargs byte-compile-warnings)
(if (memq fn '(custom-declare-group custom-declare-variable custom-declare-face))
(byte-compile-nogroup-warn form))
@@ -3671,7 +3682,7 @@ that suppresses all warnings during execution of BODY."
(list 'fset
(list 'quote (nth 1 form))
(byte-compile-byte-code-maker
- (byte-compile-lambda (cons 'lambda (cdr (cdr form)))))))
+ (byte-compile-lambda (cdr (cdr form)) t))))
(byte-compile-discard))
;; We prefer to generate a defalias form so it will record the function
;; definition just like interpreting a defun.
@@ -3679,7 +3690,7 @@ that suppresses all warnings during execution of BODY."
(list 'defalias
(list 'quote (nth 1 form))
(byte-compile-byte-code-maker
- (byte-compile-lambda (cons 'lambda (cdr (cdr form))))))
+ (byte-compile-lambda (cdr (cdr form)) t)))
t))
(byte-compile-constant (nth 1 form)))
@@ -3688,8 +3699,7 @@ that suppresses all warnings during execution of BODY."
(byte-compile-body-do-effect
(list (list 'fset (list 'quote (nth 1 form))
(let ((code (byte-compile-byte-code-maker
- (byte-compile-lambda
- (cons 'lambda (cdr (cdr form)))))))
+ (byte-compile-lambda (cdr (cdr form)) t))))
(if (eq (car-safe code) 'make-byte-code)
(list 'cons ''macro code)
(list 'quote (cons 'macro (eval code))))))