changeset 3653:974055b516d9

* bytecomp.el: Bring it up to version 2.10 of the Zawinski-Furuseth compiler. Changes from David Gillespie.
author Jim Blandy <jimb@redhat.com>
date Fri, 11 Jun 1993 16:19:49 +0000
parents 31e55359fcdb
children d9313b9a63ad
files lisp/emacs-lisp/bytecomp.el
diffstat 1 files changed, 82 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/emacs-lisp/bytecomp.el	Fri Jun 11 16:02:27 1993 +0000
+++ b/lisp/emacs-lisp/bytecomp.el	Fri Jun 11 16:19:49 1993 +0000
@@ -8,9 +8,9 @@
 
 ;; Subsequently modified by RMS.
 
-;;; This version incorporates changes up to version 2.08 of the 
+;;; This version incorporates changes up to version 2.10 of the 
 ;;; Zawinski-Furuseth compiler.
-(defconst byte-compile-version "FSF 2.08")
+(defconst byte-compile-version "FSF 2.10")
 
 ;; This file is part of GNU Emacs.
 
@@ -38,8 +38,9 @@
 
 ;;; ========================================================================
 ;;; Entry points:
-;;;	byte-recompile-directory, byte-compile-file, batch-byte-compile,
-;;;	byte-compile, compile-defun
+;;;	byte-recompile-directory, byte-compile-file,
+;;;     batch-byte-compile, batch-byte-recompile-directory,
+;;;	byte-compile, compile-defun,
 ;;;	display-call-tree
 ;;; (byte-compile-buffer and byte-compile-and-load-file were turned off
 ;;;  because they are not terribly useful and get in the way of completion.)
@@ -101,16 +102,8 @@
 ;;; byte-compile-compatibility	Whether the compiler should
 ;;;				generate .elc files which can be loaded into
 ;;;				generic emacs 18.
-;;; byte-compile-single-version	Normally the byte-compiler will consult the
-;;;				above two variables at runtime, but if this 
-;;;				is true before the compiler itself is loaded/
-;;;				compiled, then the runtime checks will not be
-;;;				made, and compilation will be slightly faster.
-;;;				To use this, start up a fresh emacs, set this
-;;;				to t, reload the compiler's .el files, and
-;;;				recompile.  Don't do this in an emacs that has
-;;;				already had the compiler loaded.
-;;; byte-compile-overwrite-file	If nil, delete old .elc files before saving.
+;;; emacs-lisp-file-regexp	Regexp for the extension of elisp source-files;
+;;;				see also the function byte-compile-dest-file.
 
 ;;; New Features:
 ;;;
@@ -151,12 +144,20 @@
 ;;;	the whole form is evalled both at compile-time and at run-time.
 ;;;
 ;;;  o  The command Meta-X byte-compile-and-load-file does what you'd think.
+;;;     (This command has been discontinued.)
 ;;;
 ;;;  o  The command compile-defun is analogous to eval-defun.
 ;;;
 ;;;  o  If you run byte-compile-file on a filename which is visited in a 
 ;;;     buffer, and that buffer is modified, you are asked whether you want
 ;;;     to save the buffer before compiling.
+;;;
+;;;  o  You can add this to /etc/magic to make file(1) recognise the files
+;;;     generated by this compiler:
+;;;
+;;;	  0	string		;ELC		GNU Emacs Lisp compiled file,
+;;;	  >4	byte		x		version %d
+;;;
 
 (require 'backquote)
 
@@ -203,13 +204,15 @@
 You may want to redefine `byte-compile-dest-file' if you change this.")
 
 (or (fboundp 'byte-compile-dest-file)
-    ;; The user may want to redefine this,
+    ;; The user may want to redefine this along with emacs-lisp-file-regexp,
     ;; so only define it if it is undefined.
     (defun byte-compile-dest-file (filename)
       "Convert an Emacs Lisp source file name to a compiled file name."
       (setq filename (file-name-sans-versions filename))
       (cond ((eq system-type 'vax-vms)
 	     (concat (substring filename 0 (string-match ";" filename)) "c"))
+	    ((string-match emacs-lisp-file-regexp filename)
+	     (concat (substring filename 0 (match-beginning 0)) ".elc"))
 	    (t (concat filename "c")))))
 
 ;; This can be the 'byte-compile property of any symbol.
@@ -339,7 +342,7 @@
 (defvar byte-compile-macro-environment byte-compile-initial-macro-environment
   "Alist of macros defined in the file being compiled.
 Each element looks like (MACRONAME . DEFINITION).  It is
-\(MACRONAME . nil) when a function is redefined as a function.")
+\(MACRONAME . nil) when a macro is redefined as a function.")
 
 (defvar byte-compile-function-environment nil
   "Alist of functions defined in the file being compiled.
@@ -1067,8 +1070,10 @@
   (interactive "DByte recompile directory: \nP")
   (if arg
       (setq arg (prefix-numeric-value arg)))
-  (save-some-buffers)
-  (set-buffer-modified-p (buffer-modified-p)) ;Update the mode line.
+  (if noninteractive
+      nil
+    (save-some-buffers)
+    (set-buffer-modified-p (buffer-modified-p))) ;Update the mode line.
   (let ((directories (list (expand-file-name directory)))
 	(file-count 0)
 	(dir-count 0)
@@ -1076,7 +1081,7 @@
     (displaying-byte-compile-warnings
      (while directories
        (setq directory (car directories))
-       (message "Checking %s..." directory)
+       (or noninteractive (message "Checking %s..." directory))
        (let ((files (directory-files directory))
 	     source dest)
 	 (while files
@@ -1096,7 +1101,9 @@
 			(and arg
 			     (or (eq 0 arg)
 				 (y-or-n-p (concat "Compile " source "? "))))))
-		 (progn (byte-compile-file source)
+		 (progn (if (and noninteractive (not byte-compile-verbose))
+			    (message "Compiling %s..." source))
+			(byte-compile-file source)
 			(setq file-count (1+ file-count))
 			(if (not (eq last-dir directory))
 			    (setq last-dir directory
@@ -1126,7 +1133,7 @@
      (list (read-file-name (if current-prefix-arg
 			       "Byte compile and load file: "
 			     "Byte compile file: ")
-			   file-dir file-name nil)
+			   file-dir nil nil file-name)
 	   current-prefix-arg)))
   ;; Expand now so we get the current buffer's defaults
   (setq filename (expand-file-name filename))
@@ -1309,6 +1316,22 @@
   (save-excursion
     (set-buffer outbuffer)
     (goto-char 1)
+    ;;
+    ;; The magic number of .elc files is ";ELC", or 0x3B454C43.  After that is
+    ;; the file-format version number (18 or 19) as a byte, followed by some
+    ;; nulls.  The primary motivation for doing this is to get some binary
+    ;; characters up in the first line of the file so that `diff' will simply
+    ;; say "Binary files differ" instead of actually doing a diff of two .elc
+    ;; files.  An extra benefit is that you can add this to /etc/magic:
+    ;;
+    ;; 0	string		;ELC		GNU Emacs Lisp compiled file,
+    ;; >4	byte		x		version %d
+    ;;
+    (insert
+     ";ELC"
+     (if (byte-compile-version-cond byte-compile-compatibility) 18 19)
+     "\000\000\000\n"
+     )
     (insert ";;; compiled by " (user-login-name) "@" (system-name) " on "
 	    (current-time-string) "\n;;; from file " filename "\n")
     (insert ";;; emacs version " emacs-version ".\n")
@@ -1893,8 +1916,8 @@
 	   (if (memq fn '(t nil))
 	       (byte-compile-warn "%s called as a function" fn))
 	   (if (and handler
-		    (or (byte-compile-version-cond
-			 byte-compile-compatibility)
+		    (or (not (byte-compile-version-cond
+			      byte-compile-compatibility))
 			(not (get (get fn 'byte-opcode) 'emacs19-opcode))))
 	       (funcall handler form)
 	     (if (memq 'callargs byte-compile-warnings)
@@ -2015,9 +2038,9 @@
 
 (defmacro byte-defop-compiler19 (function &optional compile-handler)
   ;; Just like byte-defop-compiler, but defines an opcode that will only
-  ;; be used when byte-compile-compatibility is true.
+  ;; be used when byte-compile-compatibility is false.
   (if (and (byte-compile-single-version)
-	   (not byte-compile-compatibility))
+	   byte-compile-compatibility)
       ;; #### instead of doing nothing, this should do some remprops,
       ;; #### to protect against the case where a single-version compiler
       ;; #### is loaded into a world that has contained a multi-version one.
@@ -2234,8 +2257,8 @@
 	   (mapcar 'byte-compile-form (cdr form))
 	   (byte-compile-out
 	    (aref [byte-list1 byte-list2 byte-list3 byte-list4] (1- count)) 0))
-	  ((and (< count 256) (byte-compile-version-cond
-			       byte-compile-compatibility))
+	  ((and (< count 256) (not (byte-compile-version-cond
+				    byte-compile-compatibility)))
 	   (mapcar 'byte-compile-form (cdr form))
 	   (byte-compile-out 'byte-listN count))
 	  (t (byte-compile-normal-call form)))))
@@ -2250,8 +2273,8 @@
 	  ;; Concat of one arg is not a no-op if arg is not a string.
 	  ((= count 0)
 	   (byte-compile-form ""))
-	  ((and (< count 256) (byte-compile-version-cond
-			       byte-compile-compatibility))
+	  ((and (< count 256) (not (byte-compile-version-cond
+				    byte-compile-compatibility)))
 	   (mapcar 'byte-compile-form (cdr form))
 	   (byte-compile-out 'byte-concatN count))
 	  ((byte-compile-normal-call form)))))
@@ -2350,8 +2373,8 @@
 (defun byte-compile-insert (form)
   (cond ((null (cdr form))
 	 (byte-compile-constant nil))
-	((and (byte-compile-version-cond
-	       byte-compile-compatibility)
+	((and (not (byte-compile-version-cond
+		    byte-compile-compatibility))
 	      (<= (length form) 256))
 	 (mapcar 'byte-compile-form (cdr form))
 	 (if (cdr (cdr form))
@@ -2649,9 +2672,20 @@
     (let ((clauses (cdr (cdr (cdr form))))
 	  compiled-clauses)
       (while clauses
-	(let ((clause (car clauses)))
+	(let* ((clause (car clauses))
+               (condition (car clause)))
+          (cond ((not (symbolp condition))
+                 (byte-compile-warn
+                   "%s is not a symbol naming a condition (in condition-case)"
+                   (prin1-to-string condition)))
+                ((not (or (eq condition 't)
+			  (and (stringp (get condition 'error-message))
+			       (consp (get condition 'error-conditions)))))
+                 (byte-compile-warn
+                   "%s is not a known condition name (in condition-case)" 
+                   condition)))
 	  (setq compiled-clauses
-		(cons (cons (car clause)
+		(cons (cons condition
 			    (byte-compile-top-level-body
 			     (cdr clause) for-effect))
 		      compiled-clauses)))
@@ -2992,6 +3026,21 @@
 	      (prin1-to-string (cdr err)))
      nil)))
 
+(defun batch-byte-recompile-directory ()
+  "Runs `byte-recompile-directory' on the dirs remaining on the command line.
+Must be used only with -batch, and kills emacs on completion.
+For example, invoke \"emacs -batch -f batch-byte-recompile-directory .\""
+  ;; command-line-args-left is what is left of the command line (startup.el)
+  (defvar command-line-args-left)	;Avoid 'free variable' warning
+  (if (not noninteractive)
+      (error "batch-byte-recompile-directory is to be used only with -batch"))
+  (or command-line-args-left
+      (setq command-line-args-left '(".")))
+  (while command-line-args-left
+    (byte-recompile-directory (car command-line-args-left))
+    (setq command-line-args-left (cdr command-line-args-left)))
+  (kill-emacs 0))
+
 
 (make-obsolete 'mod '%)
 (make-obsolete 'dot 'point)