aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2009-07-23 02:53:29 +0000
committerGlenn Morris2009-07-23 02:53:29 +0000
commita2b3fdbf3aa02c3798201d9f80ce012f27878cf2 (patch)
tree9749361ab65a8061ab7d3f4efb66eabc85035a79
parent324a4f6ad822bbbdb56f2ec94e70c99997d4a304 (diff)
downloademacs-a2b3fdbf3aa02c3798201d9f80ce012f27878cf2.tar.gz
emacs-a2b3fdbf3aa02c3798201d9f80ce012f27878cf2.zip
(byte-compile-from-buffer, byte-compile-output-file-form)
(byte-compile-output-docform, byte-compile-file-form-defmumble) (byte-compile-output-as-comment): Give some more local variables with common names a "bytecomp-" prefix, so as not to shadow things during compilation.
-rw-r--r--lisp/emacs-lisp/bytecomp.el113
1 files changed, 63 insertions, 50 deletions
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index 7f0387d7ed1..f0edda4ee6e 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -1864,10 +1864,10 @@ With argument ARG, insert value in current buffer after the form."
1864 ((message "%s" (prin1-to-string value))))))) 1864 ((message "%s" (prin1-to-string value)))))))
1865 1865
1866 1866
1867(defun byte-compile-from-buffer (inbuffer &optional filename) 1867(defun byte-compile-from-buffer (bytecomp-inbuffer &optional bytecomp-filename)
1868 ;; Filename is used for the loading-into-Emacs-18 error message. 1868 ;; Filename is used for the loading-into-Emacs-18 error message.
1869 (let (outbuffer 1869 (let (bytecomp-outbuffer
1870 (byte-compile-current-buffer inbuffer) 1870 (byte-compile-current-buffer bytecomp-inbuffer)
1871 (byte-compile-read-position nil) 1871 (byte-compile-read-position nil)
1872 (byte-compile-last-position nil) 1872 (byte-compile-last-position nil)
1873 ;; Prevent truncation of flonums and lists as we read and print them 1873 ;; Prevent truncation of flonums and lists as we read and print them
@@ -1888,14 +1888,14 @@ With argument ARG, insert value in current buffer after the form."
1888 (byte-compile-output nil) 1888 (byte-compile-output nil)
1889 ;; This allows us to get the positions of symbols read; it's 1889 ;; This allows us to get the positions of symbols read; it's
1890 ;; new in Emacs 22.1. 1890 ;; new in Emacs 22.1.
1891 (read-with-symbol-positions inbuffer) 1891 (read-with-symbol-positions bytecomp-inbuffer)
1892 (read-symbol-positions-list nil) 1892 (read-symbol-positions-list nil)
1893 ;; #### This is bound in b-c-close-variables. 1893 ;; #### This is bound in b-c-close-variables.
1894 ;; (byte-compile-warnings byte-compile-warnings) 1894 ;; (byte-compile-warnings byte-compile-warnings)
1895 ) 1895 )
1896 (byte-compile-close-variables 1896 (byte-compile-close-variables
1897 (with-current-buffer 1897 (with-current-buffer
1898 (setq outbuffer (get-buffer-create " *Compiler Output*")) 1898 (setq bytecomp-outbuffer (get-buffer-create " *Compiler Output*"))
1899 (set-buffer-multibyte t) 1899 (set-buffer-multibyte t)
1900 (erase-buffer) 1900 (erase-buffer)
1901 ;; (emacs-lisp-mode) 1901 ;; (emacs-lisp-mode)
@@ -1908,8 +1908,10 @@ With argument ARG, insert value in current buffer after the form."
1908 ;; need to be written carefully. 1908 ;; need to be written carefully.
1909 (setq overwrite-mode 'overwrite-mode-binary)) 1909 (setq overwrite-mode 'overwrite-mode-binary))
1910 (displaying-byte-compile-warnings 1910 (displaying-byte-compile-warnings
1911 (and filename (byte-compile-insert-header filename inbuffer outbuffer)) 1911 (and bytecomp-filename
1912 (with-current-buffer inbuffer 1912 (byte-compile-insert-header bytecomp-filename bytecomp-inbuffer
1913 bytecomp-outbuffer))
1914 (with-current-buffer bytecomp-inbuffer
1913 (goto-char (point-min)) 1915 (goto-char (point-min))
1914 ;; Should we always do this? When calling multiple files, it 1916 ;; Should we always do this? When calling multiple files, it
1915 ;; would be useful to delay this warning until all have been 1917 ;; would be useful to delay this warning until all have been
@@ -1926,7 +1928,7 @@ With argument ARG, insert value in current buffer after the form."
1926 (setq byte-compile-read-position (point) 1928 (setq byte-compile-read-position (point)
1927 byte-compile-last-position byte-compile-read-position) 1929 byte-compile-last-position byte-compile-read-position)
1928 (let* ((old-style-backquotes nil) 1930 (let* ((old-style-backquotes nil)
1929 (form (read inbuffer))) 1931 (form (read bytecomp-inbuffer)))
1930 ;; Warn about the use of old-style backquotes. 1932 ;; Warn about the use of old-style backquotes.
1931 (when old-style-backquotes 1933 (when old-style-backquotes
1932 (byte-compile-warn "!! The file uses old-style backquotes !! 1934 (byte-compile-warn "!! The file uses old-style backquotes !!
@@ -1941,8 +1943,10 @@ and will be removed soon. See (elisp)Backquote in the manual."))
1941 (byte-compile-warn-about-unresolved-functions)) 1943 (byte-compile-warn-about-unresolved-functions))
1942 ;; Fix up the header at the front of the output 1944 ;; Fix up the header at the front of the output
1943 ;; if the buffer contains multibyte characters. 1945 ;; if the buffer contains multibyte characters.
1944 (and filename (byte-compile-fix-header filename inbuffer outbuffer)))) 1946 (and bytecomp-filename
1945 outbuffer)) 1947 (byte-compile-fix-header bytecomp-filename bytecomp-inbuffer
1948 bytecomp-outbuffer))))
1949 bytecomp-outbuffer))
1946 1950
1947(defun byte-compile-fix-header (filename inbuffer outbuffer) 1951(defun byte-compile-fix-header (filename inbuffer outbuffer)
1948 (with-current-buffer outbuffer 1952 (with-current-buffer outbuffer
@@ -2064,6 +2068,10 @@ and will be removed soon. See (elisp)Backquote in the manual."))
2064 (insert "(or (boundp 'current-load-list) (setq current-load-list nil))\n" 2068 (insert "(or (boundp 'current-load-list) (setq current-load-list nil))\n"
2065 "\n"))))) 2069 "\n")))))
2066 2070
2071;; Dynamically bound in byte-compile-from-buffer.
2072;; NB also used in cl.el and cl-macs.el.
2073(defvar bytecomp-outbuffer)
2074
2067(defun byte-compile-output-file-form (form) 2075(defun byte-compile-output-file-form (form)
2068 ;; writes the given form to the output buffer, being careful of docstrings 2076 ;; writes the given form to the output buffer, being careful of docstrings
2069 ;; in defun, defmacro, defvar, defconst, autoload and 2077 ;; in defun, defmacro, defvar, defconst, autoload and
@@ -2084,8 +2092,8 @@ and will be removed soon. See (elisp)Backquote in the manual."))
2084 (print-gensym t) 2092 (print-gensym t)
2085 (print-circle ; handle circular data structures 2093 (print-circle ; handle circular data structures
2086 (not byte-compile-disable-print-circle))) 2094 (not byte-compile-disable-print-circle)))
2087 (princ "\n" outbuffer) 2095 (princ "\n" bytecomp-outbuffer)
2088 (prin1 form outbuffer) 2096 (prin1 form bytecomp-outbuffer)
2089 nil))) 2097 nil)))
2090 2098
2091(defvar print-gensym-alist) ;Used before print-circle existed. 2099(defvar print-gensym-alist) ;Used before print-circle existed.
@@ -2104,7 +2112,7 @@ list that represents a doc string reference.
2104 ;; We need to examine byte-compile-dynamic-docstrings 2112 ;; We need to examine byte-compile-dynamic-docstrings
2105 ;; in the input buffer (now current), not in the output buffer. 2113 ;; in the input buffer (now current), not in the output buffer.
2106 (let ((dynamic-docstrings byte-compile-dynamic-docstrings)) 2114 (let ((dynamic-docstrings byte-compile-dynamic-docstrings))
2107 (with-current-buffer outbuffer 2115 (with-current-buffer bytecomp-outbuffer
2108 (let (position) 2116 (let (position)
2109 2117
2110 ;; Insert the doc string, and make it a comment with #@LENGTH. 2118 ;; Insert the doc string, and make it a comment with #@LENGTH.
@@ -2129,7 +2137,7 @@ list that represents a doc string reference.
2129 (if preface 2137 (if preface
2130 (progn 2138 (progn
2131 (insert preface) 2139 (insert preface)
2132 (prin1 name outbuffer))) 2140 (prin1 name bytecomp-outbuffer)))
2133 (insert (car info)) 2141 (insert (car info))
2134 (let ((print-escape-newlines t) 2142 (let ((print-escape-newlines t)
2135 (print-quoted t) 2143 (print-quoted t)
@@ -2144,7 +2152,7 @@ list that represents a doc string reference.
2144 (print-continuous-numbering t) 2152 (print-continuous-numbering t)
2145 print-number-table 2153 print-number-table
2146 (index 0)) 2154 (index 0))
2147 (prin1 (car form) outbuffer) 2155 (prin1 (car form) bytecomp-outbuffer)
2148 (while (setq form (cdr form)) 2156 (while (setq form (cdr form))
2149 (setq index (1+ index)) 2157 (setq index (1+ index))
2150 (insert " ") 2158 (insert " ")
@@ -2165,21 +2173,21 @@ list that represents a doc string reference.
2165 (cons (car form) (nth 1 form)) 2173 (cons (car form) (nth 1 form))
2166 t))) 2174 t)))
2167 (setq position (- (position-bytes position) (point-min) -1)) 2175 (setq position (- (position-bytes position) (point-min) -1))
2168 (princ (format "(#$ . %d) nil" position) outbuffer) 2176 (princ (format "(#$ . %d) nil" position) bytecomp-outbuffer)
2169 (setq form (cdr form)) 2177 (setq form (cdr form))
2170 (setq index (1+ index)))) 2178 (setq index (1+ index))))
2171 ((= index (nth 1 info)) 2179 ((= index (nth 1 info))
2172 (if position 2180 (if position
2173 (princ (format (if quoted "'(#$ . %d)" "(#$ . %d)") 2181 (princ (format (if quoted "'(#$ . %d)" "(#$ . %d)")
2174 position) 2182 position)
2175 outbuffer) 2183 bytecomp-outbuffer)
2176 (let ((print-escape-newlines nil)) 2184 (let ((print-escape-newlines nil))
2177 (goto-char (prog1 (1+ (point)) 2185 (goto-char (prog1 (1+ (point))
2178 (prin1 (car form) outbuffer))) 2186 (prin1 (car form) bytecomp-outbuffer)))
2179 (insert "\\\n") 2187 (insert "\\\n")
2180 (goto-char (point-max))))) 2188 (goto-char (point-max)))))
2181 (t 2189 (t
2182 (prin1 (car form) outbuffer))))) 2190 (prin1 (car form) bytecomp-outbuffer)))))
2183 (insert (nth 2 info))))) 2191 (insert (nth 2 info)))))
2184 nil) 2192 nil)
2185 2193
@@ -2342,29 +2350,32 @@ list that represents a doc string reference.
2342 (byte-compile-file-form-defmumble form t)) 2350 (byte-compile-file-form-defmumble form t))
2343 2351
2344(defun byte-compile-file-form-defmumble (form macrop) 2352(defun byte-compile-file-form-defmumble (form macrop)
2345 (let* ((name (car (cdr form))) 2353 (let* ((bytecomp-name (car (cdr form)))
2346 (this-kind (if macrop 'byte-compile-macro-environment 2354 (bytecomp-this-kind (if macrop 'byte-compile-macro-environment
2347 'byte-compile-function-environment)) 2355 'byte-compile-function-environment))
2348 (that-kind (if macrop 'byte-compile-function-environment 2356 (bytecomp-that-kind (if macrop 'byte-compile-function-environment
2349 'byte-compile-macro-environment)) 2357 'byte-compile-macro-environment))
2350 (this-one (assq name (symbol-value this-kind))) 2358 (bytecomp-this-one (assq bytecomp-name
2351 (that-one (assq name (symbol-value that-kind))) 2359 (symbol-value bytecomp-this-kind)))
2360 (bytecomp-that-one (assq bytecomp-name
2361 (symbol-value bytecomp-that-kind)))
2352 (byte-compile-free-references nil) 2362 (byte-compile-free-references nil)
2353 (byte-compile-free-assignments nil)) 2363 (byte-compile-free-assignments nil))
2354 (byte-compile-set-symbol-position name) 2364 (byte-compile-set-symbol-position bytecomp-name)
2355 ;; When a function or macro is defined, add it to the call tree so that 2365 ;; When a function or macro is defined, add it to the call tree so that
2356 ;; we can tell when functions are not used. 2366 ;; we can tell when functions are not used.
2357 (if byte-compile-generate-call-tree 2367 (if byte-compile-generate-call-tree
2358 (or (assq name byte-compile-call-tree) 2368 (or (assq bytecomp-name byte-compile-call-tree)
2359 (setq byte-compile-call-tree 2369 (setq byte-compile-call-tree
2360 (cons (list name nil nil) byte-compile-call-tree)))) 2370 (cons (list bytecomp-name nil nil) byte-compile-call-tree))))
2361 2371
2362 (setq byte-compile-current-form name) ; for warnings 2372 (setq byte-compile-current-form bytecomp-name) ; for warnings
2363 (if (byte-compile-warning-enabled-p 'redefine) 2373 (if (byte-compile-warning-enabled-p 'redefine)
2364 (byte-compile-arglist-warn form macrop)) 2374 (byte-compile-arglist-warn form macrop))
2365 (if byte-compile-verbose 2375 (if byte-compile-verbose
2366 (message "Compiling %s... (%s)" (or filename "") (nth 1 form))) 2376 ;; bytecomp-filename is from byte-compile-from-buffer.
2367 (cond (that-one 2377 (message "Compiling %s... (%s)" (or bytecomp-filename "") (nth 1 form)))
2378 (cond (bytecomp-that-one
2368 (if (and (byte-compile-warning-enabled-p 'redefine) 2379 (if (and (byte-compile-warning-enabled-p 'redefine)
2369 ;; don't warn when compiling the stubs in byte-run... 2380 ;; don't warn when compiling the stubs in byte-run...
2370 (not (assq (nth 1 form) 2381 (not (assq (nth 1 form)
@@ -2372,8 +2383,8 @@ list that represents a doc string reference.
2372 (byte-compile-warn 2383 (byte-compile-warn
2373 "`%s' defined multiple times, as both function and macro" 2384 "`%s' defined multiple times, as both function and macro"
2374 (nth 1 form))) 2385 (nth 1 form)))
2375 (setcdr that-one nil)) 2386 (setcdr bytecomp-that-one nil))
2376 (this-one 2387 (bytecomp-this-one
2377 (when (and (byte-compile-warning-enabled-p 'redefine) 2388 (when (and (byte-compile-warning-enabled-p 'redefine)
2378 ;; hack: don't warn when compiling the magic internal 2389 ;; hack: don't warn when compiling the magic internal
2379 ;; byte-compiler macros in byte-run.el... 2390 ;; byte-compiler macros in byte-run.el...
@@ -2382,8 +2393,8 @@ list that represents a doc string reference.
2382 (byte-compile-warn "%s `%s' defined multiple times in this file" 2393 (byte-compile-warn "%s `%s' defined multiple times in this file"
2383 (if macrop "macro" "function") 2394 (if macrop "macro" "function")
2384 (nth 1 form)))) 2395 (nth 1 form))))
2385 ((and (fboundp name) 2396 ((and (fboundp bytecomp-name)
2386 (eq (car-safe (symbol-function name)) 2397 (eq (car-safe (symbol-function bytecomp-name))
2387 (if macrop 'lambda 'macro))) 2398 (if macrop 'lambda 'macro)))
2388 (when (byte-compile-warning-enabled-p 'redefine) 2399 (when (byte-compile-warning-enabled-p 'redefine)
2389 (byte-compile-warn "%s `%s' being redefined as a %s" 2400 (byte-compile-warn "%s `%s' being redefined as a %s"
@@ -2391,8 +2402,9 @@ list that represents a doc string reference.
2391 (nth 1 form) 2402 (nth 1 form)
2392 (if macrop "macro" "function"))) 2403 (if macrop "macro" "function")))
2393 ;; shadow existing definition 2404 ;; shadow existing definition
2394 (set this-kind 2405 (set bytecomp-this-kind
2395 (cons (cons name nil) (symbol-value this-kind)))) 2406 (cons (cons bytecomp-name nil)
2407 (symbol-value bytecomp-this-kind))))
2396 ) 2408 )
2397 (let ((body (nthcdr 3 form))) 2409 (let ((body (nthcdr 3 form)))
2398 (when (and (stringp (car body)) 2410 (when (and (stringp (car body))
@@ -2415,20 +2427,21 @@ list that represents a doc string reference.
2415 (setcdr tail (cdr (cdr tail))) 2427 (setcdr tail (cdr (cdr tail)))
2416 (prin1 `(if macro-declaration-function 2428 (prin1 `(if macro-declaration-function
2417 (funcall macro-declaration-function 2429 (funcall macro-declaration-function
2418 ',name ',declaration)) 2430 ',bytecomp-name ',declaration))
2419 outbuffer))))) 2431 bytecomp-outbuffer)))))
2420 2432
2421 (let* ((new-one (byte-compile-lambda (nthcdr 2 form) t)) 2433 (let* ((new-one (byte-compile-lambda (nthcdr 2 form) t))
2422 (code (byte-compile-byte-code-maker new-one))) 2434 (code (byte-compile-byte-code-maker new-one)))
2423 (if this-one 2435 (if bytecomp-this-one
2424 (setcdr this-one new-one) 2436 (setcdr bytecomp-this-one new-one)
2425 (set this-kind 2437 (set bytecomp-this-kind
2426 (cons (cons name new-one) (symbol-value this-kind)))) 2438 (cons (cons bytecomp-name new-one)
2439 (symbol-value bytecomp-this-kind))))
2427 (if (and (stringp (nth 3 form)) 2440 (if (and (stringp (nth 3 form))
2428 (eq 'quote (car-safe code)) 2441 (eq 'quote (car-safe code))
2429 (eq 'lambda (car-safe (nth 1 code)))) 2442 (eq 'lambda (car-safe (nth 1 code))))
2430 (cons (car form) 2443 (cons (car form)
2431 (cons name (cdr (nth 1 code)))) 2444 (cons bytecomp-name (cdr (nth 1 code))))
2432 (byte-compile-flush-pending) 2445 (byte-compile-flush-pending)
2433 (if (not (stringp (nth 3 form))) 2446 (if (not (stringp (nth 3 form)))
2434 ;; No doc string. Provide -1 as the "doc string index" 2447 ;; No doc string. Provide -1 as the "doc string index"
@@ -2436,7 +2449,7 @@ list that represents a doc string reference.
2436 (byte-compile-output-docform 2449 (byte-compile-output-docform
2437 (if (byte-compile-version-cond byte-compile-compatibility) 2450 (if (byte-compile-version-cond byte-compile-compatibility)
2438 "\n(fset '" "\n(defalias '") 2451 "\n(fset '" "\n(defalias '")
2439 name 2452 bytecomp-name
2440 (cond ((atom code) 2453 (cond ((atom code)
2441 (if macrop '(" '(macro . #[" -1 "])") '(" #[" -1 "]"))) 2454 (if macrop '(" '(macro . #[" -1 "])") '(" #[" -1 "]")))
2442 ((eq (car code) 'quote) 2455 ((eq (car code) 'quote)
@@ -2452,7 +2465,7 @@ list that represents a doc string reference.
2452 (byte-compile-output-docform 2465 (byte-compile-output-docform
2453 (if (byte-compile-version-cond byte-compile-compatibility) 2466 (if (byte-compile-version-cond byte-compile-compatibility)
2454 "\n(fset '" "\n(defalias '") 2467 "\n(fset '" "\n(defalias '")
2455 name 2468 bytecomp-name
2456 (cond ((atom code) 2469 (cond ((atom code)
2457 (if macrop '(" '(macro . #[" 4 "])") '(" #[" 4 "]"))) 2470 (if macrop '(" '(macro . #[" 4 "])") '(" #[" 4 "]")))
2458 ((eq (car code) 'quote) 2471 ((eq (car code) 'quote)
@@ -2463,7 +2476,7 @@ list that represents a doc string reference.
2463 (and (atom code) byte-compile-dynamic 2476 (and (atom code) byte-compile-dynamic
2464 1) 2477 1)
2465 nil)) 2478 nil))
2466 (princ ")" outbuffer) 2479 (princ ")" bytecomp-outbuffer)
2467 nil)))) 2480 nil))))
2468 2481
2469;; Print Lisp object EXP in the output file, inside a comment, 2482;; Print Lisp object EXP in the output file, inside a comment,
@@ -2471,13 +2484,13 @@ list that represents a doc string reference.
2471;; If QUOTED is non-nil, print with quoting; otherwise, print without quoting. 2484;; If QUOTED is non-nil, print with quoting; otherwise, print without quoting.
2472(defun byte-compile-output-as-comment (exp quoted) 2485(defun byte-compile-output-as-comment (exp quoted)
2473 (let ((position (point))) 2486 (let ((position (point)))
2474 (with-current-buffer outbuffer 2487 (with-current-buffer bytecomp-outbuffer
2475 2488
2476 ;; Insert EXP, and make it a comment with #@LENGTH. 2489 ;; Insert EXP, and make it a comment with #@LENGTH.
2477 (insert " ") 2490 (insert " ")
2478 (if quoted 2491 (if quoted
2479 (prin1 exp outbuffer) 2492 (prin1 exp bytecomp-outbuffer)
2480 (princ exp outbuffer)) 2493 (princ exp bytecomp-outbuffer))
2481 (goto-char position) 2494 (goto-char position)
2482 ;; Quote certain special characters as needed. 2495 ;; Quote certain special characters as needed.
2483 ;; get_doc_string in doc.c does the unquoting. 2496 ;; get_doc_string in doc.c does the unquoting.
@@ -3973,7 +3986,7 @@ that suppresses all warnings during execution of BODY."
3973 (push (cons (nth 1 (nth 1 form)) 3986 (push (cons (nth 1 (nth 1 form))
3974 (if constant (nth 1 (nth 2 form)) t)) 3987 (if constant (nth 1 (nth 2 form)) t))
3975 byte-compile-function-environment))) 3988 byte-compile-function-environment)))
3976 ;; We used to jus do: (byte-compile-normal-call form) 3989 ;; We used to just do: (byte-compile-normal-call form)
3977 ;; But it turns out that this fails to optimize the code. 3990 ;; But it turns out that this fails to optimize the code.
3978 ;; So instead we now do the same as what other byte-hunk-handlers do, 3991 ;; So instead we now do the same as what other byte-hunk-handlers do,
3979 ;; which is to call back byte-compile-file-form and then return nil. 3992 ;; which is to call back byte-compile-file-form and then return nil.