aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/emacs-lisp/bytecomp.el115
1 files changed, 82 insertions, 33 deletions
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index d1f03516f7c..a78e70dd7bd 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -8,9 +8,9 @@
8 8
9;; Subsequently modified by RMS. 9;; Subsequently modified by RMS.
10 10
11;;; This version incorporates changes up to version 2.08 of the 11;;; This version incorporates changes up to version 2.10 of the
12;;; Zawinski-Furuseth compiler. 12;;; Zawinski-Furuseth compiler.
13(defconst byte-compile-version "FSF 2.08") 13(defconst byte-compile-version "FSF 2.10")
14 14
15;; This file is part of GNU Emacs. 15;; This file is part of GNU Emacs.
16 16
@@ -38,8 +38,9 @@
38 38
39;;; ======================================================================== 39;;; ========================================================================
40;;; Entry points: 40;;; Entry points:
41;;; byte-recompile-directory, byte-compile-file, batch-byte-compile, 41;;; byte-recompile-directory, byte-compile-file,
42;;; byte-compile, compile-defun 42;;; batch-byte-compile, batch-byte-recompile-directory,
43;;; byte-compile, compile-defun,
43;;; display-call-tree 44;;; display-call-tree
44;;; (byte-compile-buffer and byte-compile-and-load-file were turned off 45;;; (byte-compile-buffer and byte-compile-and-load-file were turned off
45;;; because they are not terribly useful and get in the way of completion.) 46;;; because they are not terribly useful and get in the way of completion.)
@@ -101,16 +102,8 @@
101;;; byte-compile-compatibility Whether the compiler should 102;;; byte-compile-compatibility Whether the compiler should
102;;; generate .elc files which can be loaded into 103;;; generate .elc files which can be loaded into
103;;; generic emacs 18. 104;;; generic emacs 18.
104;;; byte-compile-single-version Normally the byte-compiler will consult the 105;;; emacs-lisp-file-regexp Regexp for the extension of elisp source-files;
105;;; above two variables at runtime, but if this 106;;; see also the function byte-compile-dest-file.
106;;; is true before the compiler itself is loaded/
107;;; compiled, then the runtime checks will not be
108;;; made, and compilation will be slightly faster.
109;;; To use this, start up a fresh emacs, set this
110;;; to t, reload the compiler's .el files, and
111;;; recompile. Don't do this in an emacs that has
112;;; already had the compiler loaded.
113;;; byte-compile-overwrite-file If nil, delete old .elc files before saving.
114 107
115;;; New Features: 108;;; New Features:
116;;; 109;;;
@@ -151,12 +144,20 @@
151;;; the whole form is evalled both at compile-time and at run-time. 144;;; the whole form is evalled both at compile-time and at run-time.
152;;; 145;;;
153;;; o The command Meta-X byte-compile-and-load-file does what you'd think. 146;;; o The command Meta-X byte-compile-and-load-file does what you'd think.
147;;; (This command has been discontinued.)
154;;; 148;;;
155;;; o The command compile-defun is analogous to eval-defun. 149;;; o The command compile-defun is analogous to eval-defun.
156;;; 150;;;
157;;; o If you run byte-compile-file on a filename which is visited in a 151;;; o If you run byte-compile-file on a filename which is visited in a
158;;; buffer, and that buffer is modified, you are asked whether you want 152;;; buffer, and that buffer is modified, you are asked whether you want
159;;; to save the buffer before compiling. 153;;; to save the buffer before compiling.
154;;;
155;;; o You can add this to /etc/magic to make file(1) recognise the files
156;;; generated by this compiler:
157;;;
158;;; 0 string ;ELC GNU Emacs Lisp compiled file,
159;;; >4 byte x version %d
160;;;
160 161
161(require 'backquote) 162(require 'backquote)
162 163
@@ -203,13 +204,15 @@
203You may want to redefine `byte-compile-dest-file' if you change this.") 204You may want to redefine `byte-compile-dest-file' if you change this.")
204 205
205(or (fboundp 'byte-compile-dest-file) 206(or (fboundp 'byte-compile-dest-file)
206 ;; The user may want to redefine this, 207 ;; The user may want to redefine this along with emacs-lisp-file-regexp,
207 ;; so only define it if it is undefined. 208 ;; so only define it if it is undefined.
208 (defun byte-compile-dest-file (filename) 209 (defun byte-compile-dest-file (filename)
209 "Convert an Emacs Lisp source file name to a compiled file name." 210 "Convert an Emacs Lisp source file name to a compiled file name."
210 (setq filename (file-name-sans-versions filename)) 211 (setq filename (file-name-sans-versions filename))
211 (cond ((eq system-type 'vax-vms) 212 (cond ((eq system-type 'vax-vms)
212 (concat (substring filename 0 (string-match ";" filename)) "c")) 213 (concat (substring filename 0 (string-match ";" filename)) "c"))
214 ((string-match emacs-lisp-file-regexp filename)
215 (concat (substring filename 0 (match-beginning 0)) ".elc"))
213 (t (concat filename "c"))))) 216 (t (concat filename "c")))))
214 217
215;; This can be the 'byte-compile property of any symbol. 218;; This can be the 'byte-compile property of any symbol.
@@ -339,7 +342,7 @@ expanded by the compiler as when expanded by the interpreter.")
339(defvar byte-compile-macro-environment byte-compile-initial-macro-environment 342(defvar byte-compile-macro-environment byte-compile-initial-macro-environment
340 "Alist of macros defined in the file being compiled. 343 "Alist of macros defined in the file being compiled.
341Each element looks like (MACRONAME . DEFINITION). It is 344Each element looks like (MACRONAME . DEFINITION). It is
342\(MACRONAME . nil) when a function is redefined as a function.") 345\(MACRONAME . nil) when a macro is redefined as a function.")
343 346
344(defvar byte-compile-function-environment nil 347(defvar byte-compile-function-environment nil
345 "Alist of functions defined in the file being compiled. 348 "Alist of functions defined in the file being compiled.
@@ -1067,8 +1070,10 @@ don't ask and compile the file anyway."
1067 (interactive "DByte recompile directory: \nP") 1070 (interactive "DByte recompile directory: \nP")
1068 (if arg 1071 (if arg
1069 (setq arg (prefix-numeric-value arg))) 1072 (setq arg (prefix-numeric-value arg)))
1070 (save-some-buffers) 1073 (if noninteractive
1071 (set-buffer-modified-p (buffer-modified-p)) ;Update the mode line. 1074 nil
1075 (save-some-buffers)
1076 (set-buffer-modified-p (buffer-modified-p))) ;Update the mode line.
1072 (let ((directories (list (expand-file-name directory))) 1077 (let ((directories (list (expand-file-name directory)))
1073 (file-count 0) 1078 (file-count 0)
1074 (dir-count 0) 1079 (dir-count 0)
@@ -1076,7 +1081,7 @@ don't ask and compile the file anyway."
1076 (displaying-byte-compile-warnings 1081 (displaying-byte-compile-warnings
1077 (while directories 1082 (while directories
1078 (setq directory (car directories)) 1083 (setq directory (car directories))
1079 (message "Checking %s..." directory) 1084 (or noninteractive (message "Checking %s..." directory))
1080 (let ((files (directory-files directory)) 1085 (let ((files (directory-files directory))
1081 source dest) 1086 source dest)
1082 (while files 1087 (while files
@@ -1096,7 +1101,9 @@ don't ask and compile the file anyway."
1096 (and arg 1101 (and arg
1097 (or (eq 0 arg) 1102 (or (eq 0 arg)
1098 (y-or-n-p (concat "Compile " source "? ")))))) 1103 (y-or-n-p (concat "Compile " source "? "))))))
1099 (progn (byte-compile-file source) 1104 (progn (if (and noninteractive (not byte-compile-verbose))
1105 (message "Compiling %s..." source))
1106 (byte-compile-file source)
1100 (setq file-count (1+ file-count)) 1107 (setq file-count (1+ file-count))
1101 (if (not (eq last-dir directory)) 1108 (if (not (eq last-dir directory))
1102 (setq last-dir directory 1109 (setq last-dir directory
@@ -1126,7 +1133,7 @@ With prefix arg (noninteractively: 2nd arg), load the file after compiling."
1126 (list (read-file-name (if current-prefix-arg 1133 (list (read-file-name (if current-prefix-arg
1127 "Byte compile and load file: " 1134 "Byte compile and load file: "
1128 "Byte compile file: ") 1135 "Byte compile file: ")
1129 file-dir file-name nil) 1136 file-dir nil nil file-name)
1130 current-prefix-arg))) 1137 current-prefix-arg)))
1131 ;; Expand now so we get the current buffer's defaults 1138 ;; Expand now so we get the current buffer's defaults
1132 (setq filename (expand-file-name filename)) 1139 (setq filename (expand-file-name filename))
@@ -1309,6 +1316,22 @@ With argument, insert value in current buffer after the form."
1309 (save-excursion 1316 (save-excursion
1310 (set-buffer outbuffer) 1317 (set-buffer outbuffer)
1311 (goto-char 1) 1318 (goto-char 1)
1319 ;;
1320 ;; The magic number of .elc files is ";ELC", or 0x3B454C43. After that is
1321 ;; the file-format version number (18 or 19) as a byte, followed by some
1322 ;; nulls. The primary motivation for doing this is to get some binary
1323 ;; characters up in the first line of the file so that `diff' will simply
1324 ;; say "Binary files differ" instead of actually doing a diff of two .elc
1325 ;; files. An extra benefit is that you can add this to /etc/magic:
1326 ;;
1327 ;; 0 string ;ELC GNU Emacs Lisp compiled file,
1328 ;; >4 byte x version %d
1329 ;;
1330 (insert
1331 ";ELC"
1332 (if (byte-compile-version-cond byte-compile-compatibility) 18 19)
1333 "\000\000\000\n"
1334 )
1312 (insert ";;; compiled by " (user-login-name) "@" (system-name) " on " 1335 (insert ";;; compiled by " (user-login-name) "@" (system-name) " on "
1313 (current-time-string) "\n;;; from file " filename "\n") 1336 (current-time-string) "\n;;; from file " filename "\n")
1314 (insert ";;; emacs version " emacs-version ".\n") 1337 (insert ";;; emacs version " emacs-version ".\n")
@@ -1893,8 +1916,8 @@ If FORM is a lambda or a macro, byte-compile it as a function."
1893 (if (memq fn '(t nil)) 1916 (if (memq fn '(t nil))
1894 (byte-compile-warn "%s called as a function" fn)) 1917 (byte-compile-warn "%s called as a function" fn))
1895 (if (and handler 1918 (if (and handler
1896 (or (byte-compile-version-cond 1919 (or (not (byte-compile-version-cond
1897 byte-compile-compatibility) 1920 byte-compile-compatibility))
1898 (not (get (get fn 'byte-opcode) 'emacs19-opcode)))) 1921 (not (get (get fn 'byte-opcode) 'emacs19-opcode))))
1899 (funcall handler form) 1922 (funcall handler form)
1900 (if (memq 'callargs byte-compile-warnings) 1923 (if (memq 'callargs byte-compile-warnings)
@@ -2015,9 +2038,9 @@ If FORM is a lambda or a macro, byte-compile it as a function."
2015 2038
2016(defmacro byte-defop-compiler19 (function &optional compile-handler) 2039(defmacro byte-defop-compiler19 (function &optional compile-handler)
2017 ;; Just like byte-defop-compiler, but defines an opcode that will only 2040 ;; Just like byte-defop-compiler, but defines an opcode that will only
2018 ;; be used when byte-compile-compatibility is true. 2041 ;; be used when byte-compile-compatibility is false.
2019 (if (and (byte-compile-single-version) 2042 (if (and (byte-compile-single-version)
2020 (not byte-compile-compatibility)) 2043 byte-compile-compatibility)
2021 ;; #### instead of doing nothing, this should do some remprops, 2044 ;; #### instead of doing nothing, this should do some remprops,
2022 ;; #### to protect against the case where a single-version compiler 2045 ;; #### to protect against the case where a single-version compiler
2023 ;; #### is loaded into a world that has contained a multi-version one. 2046 ;; #### is loaded into a world that has contained a multi-version one.
@@ -2234,8 +2257,8 @@ If FORM is a lambda or a macro, byte-compile it as a function."
2234 (mapcar 'byte-compile-form (cdr form)) 2257 (mapcar 'byte-compile-form (cdr form))
2235 (byte-compile-out 2258 (byte-compile-out
2236 (aref [byte-list1 byte-list2 byte-list3 byte-list4] (1- count)) 0)) 2259 (aref [byte-list1 byte-list2 byte-list3 byte-list4] (1- count)) 0))
2237 ((and (< count 256) (byte-compile-version-cond 2260 ((and (< count 256) (not (byte-compile-version-cond
2238 byte-compile-compatibility)) 2261 byte-compile-compatibility)))
2239 (mapcar 'byte-compile-form (cdr form)) 2262 (mapcar 'byte-compile-form (cdr form))
2240 (byte-compile-out 'byte-listN count)) 2263 (byte-compile-out 'byte-listN count))
2241 (t (byte-compile-normal-call form))))) 2264 (t (byte-compile-normal-call form)))))
@@ -2250,8 +2273,8 @@ If FORM is a lambda or a macro, byte-compile it as a function."
2250 ;; Concat of one arg is not a no-op if arg is not a string. 2273 ;; Concat of one arg is not a no-op if arg is not a string.
2251 ((= count 0) 2274 ((= count 0)
2252 (byte-compile-form "")) 2275 (byte-compile-form ""))
2253 ((and (< count 256) (byte-compile-version-cond 2276 ((and (< count 256) (not (byte-compile-version-cond
2254 byte-compile-compatibility)) 2277 byte-compile-compatibility)))
2255 (mapcar 'byte-compile-form (cdr form)) 2278 (mapcar 'byte-compile-form (cdr form))
2256 (byte-compile-out 'byte-concatN count)) 2279 (byte-compile-out 'byte-concatN count))
2257 ((byte-compile-normal-call form))))) 2280 ((byte-compile-normal-call form)))))
@@ -2350,8 +2373,8 @@ If FORM is a lambda or a macro, byte-compile it as a function."
2350(defun byte-compile-insert (form) 2373(defun byte-compile-insert (form)
2351 (cond ((null (cdr form)) 2374 (cond ((null (cdr form))
2352 (byte-compile-constant nil)) 2375 (byte-compile-constant nil))
2353 ((and (byte-compile-version-cond 2376 ((and (not (byte-compile-version-cond
2354 byte-compile-compatibility) 2377 byte-compile-compatibility))
2355 (<= (length form) 256)) 2378 (<= (length form) 256))
2356 (mapcar 'byte-compile-form (cdr form)) 2379 (mapcar 'byte-compile-form (cdr form))
2357 (if (cdr (cdr form)) 2380 (if (cdr (cdr form))
@@ -2649,9 +2672,20 @@ If FORM is a lambda or a macro, byte-compile it as a function."
2649 (let ((clauses (cdr (cdr (cdr form)))) 2672 (let ((clauses (cdr (cdr (cdr form))))
2650 compiled-clauses) 2673 compiled-clauses)
2651 (while clauses 2674 (while clauses
2652 (let ((clause (car clauses))) 2675 (let* ((clause (car clauses))
2676 (condition (car clause)))
2677 (cond ((not (symbolp condition))
2678 (byte-compile-warn
2679 "%s is not a symbol naming a condition (in condition-case)"
2680 (prin1-to-string condition)))
2681 ((not (or (eq condition 't)
2682 (and (stringp (get condition 'error-message))
2683 (consp (get condition 'error-conditions)))))
2684 (byte-compile-warn
2685 "%s is not a known condition name (in condition-case)"
2686 condition)))
2653 (setq compiled-clauses 2687 (setq compiled-clauses
2654 (cons (cons (car clause) 2688 (cons (cons condition
2655 (byte-compile-top-level-body 2689 (byte-compile-top-level-body
2656 (cdr clause) for-effect)) 2690 (cdr clause) for-effect))
2657 compiled-clauses))) 2691 compiled-clauses)))
@@ -2992,6 +3026,21 @@ For example, invoke \"emacs -batch -f batch-byte-compile $emacs/ ~/*.el\""
2992 (prin1-to-string (cdr err))) 3026 (prin1-to-string (cdr err)))
2993 nil))) 3027 nil)))
2994 3028
3029(defun batch-byte-recompile-directory ()
3030 "Runs `byte-recompile-directory' on the dirs remaining on the command line.
3031Must be used only with -batch, and kills emacs on completion.
3032For example, invoke \"emacs -batch -f batch-byte-recompile-directory .\""
3033 ;; command-line-args-left is what is left of the command line (startup.el)
3034 (defvar command-line-args-left) ;Avoid 'free variable' warning
3035 (if (not noninteractive)
3036 (error "batch-byte-recompile-directory is to be used only with -batch"))
3037 (or command-line-args-left
3038 (setq command-line-args-left '(".")))
3039 (while command-line-args-left
3040 (byte-recompile-directory (car command-line-args-left))
3041 (setq command-line-args-left (cdr command-line-args-left)))
3042 (kill-emacs 0))
3043
2995 3044
2996(make-obsolete 'mod '%) 3045(make-obsolete 'mod '%)
2997(make-obsolete 'dot 'point) 3046(make-obsolete 'dot 'point)