comparison lisp/emacs-lisp/bytecomp.el @ 83676:27d11c1d4e46

Merge from emacs--devo--0 Patches applied: * emacs--devo--0 (patch 857-862) - Update from CVS - Merge from emacs--rel--22 - Update from CVS: lisp/emacs-lisp/avl-tree.el: New file. * emacs--rel--22 (patch 97-100) - Update from CVS - Merge from gnus--rel--5.10 * gnus--rel--5.10 (patch 246-247) - Update from CVS Revision: emacs@sv.gnu.org/emacs--multi-tty--0--patch-38
author Miles Bader <miles@gnu.org>
date Mon, 27 Aug 2007 09:21:49 +0000
parents 92ccd83174e6
children cbeb8c965cdb b83d0dadb2a7
comparison
equal deleted inserted replaced
83675:67601f702028 83676:27d11c1d4e46
383 x) 383 x)
384 x)))) 384 x))))
385 385
386 (defvar byte-compile-interactive-only-functions 386 (defvar byte-compile-interactive-only-functions
387 '(beginning-of-buffer end-of-buffer replace-string replace-regexp 387 '(beginning-of-buffer end-of-buffer replace-string replace-regexp
388 insert-file insert-buffer insert-file-literally) 388 insert-file insert-buffer insert-file-literally previous-line next-line)
389 "List of commands that are not meant to be called from Lisp.") 389 "List of commands that are not meant to be called from Lisp.")
390 390
391 (defvar byte-compile-not-obsolete-var nil 391 (defvar byte-compile-not-obsolete-var nil
392 "If non-nil, this is a variable that shouldn't be reported as obsolete.") 392 "If non-nil, this is a variable that shouldn't be reported as obsolete.")
393 393
1008 ;; Return the position of the start of the page in the log buffer. 1008 ;; Return the position of the start of the page in the log buffer.
1009 ;; But do nothing in batch mode. 1009 ;; But do nothing in batch mode.
1010 (defun byte-compile-log-file () 1010 (defun byte-compile-log-file ()
1011 (and (not (equal byte-compile-current-file byte-compile-last-logged-file)) 1011 (and (not (equal byte-compile-current-file byte-compile-last-logged-file))
1012 (not noninteractive) 1012 (not noninteractive)
1013 (save-excursion 1013 (with-current-buffer (get-buffer-create "*Compile-Log*")
1014 (set-buffer (get-buffer-create "*Compile-Log*"))
1015 (goto-char (point-max)) 1014 (goto-char (point-max))
1016 (let* ((inhibit-read-only t) 1015 (let* ((inhibit-read-only t)
1017 (dir (and byte-compile-current-file 1016 (dir (and byte-compile-current-file
1018 (file-name-directory byte-compile-current-file))) 1017 (file-name-directory byte-compile-current-file)))
1019 (was-same (equal default-directory dir)) 1018 (was-same (equal default-directory dir))
1546 (setq arg (prefix-numeric-value arg))) 1545 (setq arg (prefix-numeric-value arg)))
1547 (if noninteractive 1546 (if noninteractive
1548 nil 1547 nil
1549 (save-some-buffers) 1548 (save-some-buffers)
1550 (force-mode-line-update)) 1549 (force-mode-line-update))
1551 (save-current-buffer 1550 (with-current-buffer (get-buffer-create "*Compile-Log*")
1552 (set-buffer (get-buffer-create "*Compile-Log*"))
1553 (setq default-directory (expand-file-name directory)) 1551 (setq default-directory (expand-file-name directory))
1554 ;; compilation-mode copies value of default-directory. 1552 ;; compilation-mode copies value of default-directory.
1555 (unless (eq major-mode 'compilation-mode) 1553 (unless (eq major-mode 'compilation-mode)
1556 (compilation-mode)) 1554 (compilation-mode))
1557 (let ((directories (list (expand-file-name directory))) 1555 (let ((directories (list (expand-file-name directory)))
1649 ;; to save it first. 1647 ;; to save it first.
1650 (or noninteractive 1648 (or noninteractive
1651 (let ((b (get-file-buffer (expand-file-name filename)))) 1649 (let ((b (get-file-buffer (expand-file-name filename))))
1652 (if (and b (buffer-modified-p b) 1650 (if (and b (buffer-modified-p b)
1653 (y-or-n-p (format "Save buffer %s first? " (buffer-name b)))) 1651 (y-or-n-p (format "Save buffer %s first? " (buffer-name b))))
1654 (save-excursion (set-buffer b) (save-buffer))))) 1652 (with-current-buffer b (save-buffer)))))
1655 1653
1656 ;; Force logging of the file name for each file compiled. 1654 ;; Force logging of the file name for each file compiled.
1657 (setq byte-compile-last-logged-file nil) 1655 (setq byte-compile-last-logged-file nil)
1658 (let ((byte-compile-current-file filename) 1656 (let ((byte-compile-current-file filename)
1659 (set-auto-coding-for-load t) 1657 (set-auto-coding-for-load t)
1660 target-file input-buffer output-buffer 1658 target-file input-buffer output-buffer
1661 byte-compile-dest-file) 1659 byte-compile-dest-file)
1662 (setq target-file (byte-compile-dest-file filename)) 1660 (setq target-file (byte-compile-dest-file filename))
1663 (setq byte-compile-dest-file target-file) 1661 (setq byte-compile-dest-file target-file)
1664 (save-excursion 1662 (with-current-buffer
1665 (setq input-buffer (get-buffer-create " *Compiler Input*")) 1663 (setq input-buffer (get-buffer-create " *Compiler Input*"))
1666 (set-buffer input-buffer)
1667 (erase-buffer) 1664 (erase-buffer)
1668 (setq buffer-file-coding-system nil) 1665 (setq buffer-file-coding-system nil)
1669 ;; Always compile an Emacs Lisp file as multibyte 1666 ;; Always compile an Emacs Lisp file as multibyte
1670 ;; unless the file itself forces unibyte with -*-coding: raw-text;-*- 1667 ;; unless the file itself forces unibyte with -*-coding: raw-text;-*-
1671 (set-buffer-multibyte t) 1668 (set-buffer-multibyte t)
1862 (looking-at ";")) 1859 (looking-at ";"))
1863 (forward-line 1)) 1860 (forward-line 1))
1864 (not (eobp))) 1861 (not (eobp)))
1865 (setq byte-compile-read-position (point) 1862 (setq byte-compile-read-position (point)
1866 byte-compile-last-position byte-compile-read-position) 1863 byte-compile-last-position byte-compile-read-position)
1867 (let ((form (read inbuffer))) 1864 (let* ((old-style-backquotes nil)
1865 (form (read inbuffer)))
1866 ;; Warn about the use of old-style backquotes.
1867 (when old-style-backquotes
1868 (byte-compile-warn "!! The file uses old-style backquotes !!
1869 This functionality has been obsolete for more than 10 years already
1870 and will be removed soon. See (elisp)Backquote in the manual."))
1868 (byte-compile-file-form form))) 1871 (byte-compile-file-form form)))
1869 ;; Compile pending forms at end of file. 1872 ;; Compile pending forms at end of file.
1870 (byte-compile-flush-pending) 1873 (byte-compile-flush-pending)
1871 ;; Make warnings about unresolved functions 1874 ;; Make warnings about unresolved functions
1872 ;; give the end of the file as their position. 1875 ;; give the end of the file as their position.
2035 list that represents a doc string reference. 2038 list that represents a doc string reference.
2036 `autoload' and `custom-declare-variable' need that." 2039 `autoload' and `custom-declare-variable' need that."
2037 ;; We need to examine byte-compile-dynamic-docstrings 2040 ;; We need to examine byte-compile-dynamic-docstrings
2038 ;; in the input buffer (now current), not in the output buffer. 2041 ;; in the input buffer (now current), not in the output buffer.
2039 (let ((dynamic-docstrings byte-compile-dynamic-docstrings)) 2042 (let ((dynamic-docstrings byte-compile-dynamic-docstrings))
2040 (set-buffer 2043 (with-current-buffer outbuffer
2041 (prog1 (current-buffer) 2044 (let (position)
2042 (set-buffer outbuffer) 2045
2043 (let (position) 2046 ;; Insert the doc string, and make it a comment with #@LENGTH.
2044 2047 (and (>= (nth 1 info) 0)
2045 ;; Insert the doc string, and make it a comment with #@LENGTH. 2048 dynamic-docstrings
2046 (and (>= (nth 1 info) 0) 2049 (not byte-compile-compatibility)
2047 dynamic-docstrings 2050 (progn
2048 (not byte-compile-compatibility) 2051 ;; Make the doc string start at beginning of line
2049 (progn 2052 ;; for make-docfile's sake.
2050 ;; Make the doc string start at beginning of line 2053 (insert "\n")
2051 ;; for make-docfile's sake. 2054 (setq position
2052 (insert "\n") 2055 (byte-compile-output-as-comment
2053 (setq position 2056 (nth (nth 1 info) form) nil))
2054 (byte-compile-output-as-comment 2057 (setq position (- (position-bytes position) (point-min) -1))
2055 (nth (nth 1 info) form) nil)) 2058 ;; If the doc string starts with * (a user variable),
2056 (setq position (- (position-bytes position) (point-min) -1)) 2059 ;; negate POSITION.
2057 ;; If the doc string starts with * (a user variable), 2060 (if (and (stringp (nth (nth 1 info) form))
2058 ;; negate POSITION. 2061 (> (length (nth (nth 1 info) form)) 0)
2059 (if (and (stringp (nth (nth 1 info) form)) 2062 (eq (aref (nth (nth 1 info) form) 0) ?*))
2060 (> (length (nth (nth 1 info) form)) 0) 2063 (setq position (- position)))))
2061 (eq (aref (nth (nth 1 info) form) 0) ?*)) 2064
2062 (setq position (- position))))) 2065 (if preface
2063 2066 (progn
2064 (if preface 2067 (insert preface)
2065 (progn 2068 (prin1 name outbuffer)))
2066 (insert preface) 2069 (insert (car info))
2067 (prin1 name outbuffer))) 2070 (let ((print-escape-newlines t)
2068 (insert (car info)) 2071 (print-quoted t)
2069 (let ((print-escape-newlines t) 2072 ;; For compatibility with code before print-circle,
2070 (print-quoted t) 2073 ;; use a cons cell to say that we want
2071 ;; For compatibility with code before print-circle, 2074 ;; print-gensym-alist not to be cleared
2072 ;; use a cons cell to say that we want 2075 ;; between calls to print functions.
2073 ;; print-gensym-alist not to be cleared 2076 (print-gensym '(t))
2074 ;; between calls to print functions. 2077 (print-circle ; handle circular data structures
2075 (print-gensym '(t)) 2078 (not byte-compile-disable-print-circle))
2076 (print-circle ; handle circular data structures 2079 print-gensym-alist ; was used before print-circle existed.
2077 (not byte-compile-disable-print-circle)) 2080 (print-continuous-numbering t)
2078 print-gensym-alist ; was used before print-circle existed. 2081 print-number-table
2079 (print-continuous-numbering t) 2082 (index 0))
2080 print-number-table 2083 (prin1 (car form) outbuffer)
2081 (index 0)) 2084 (while (setq form (cdr form))
2082 (prin1 (car form) outbuffer) 2085 (setq index (1+ index))
2083 (while (setq form (cdr form)) 2086 (insert " ")
2084 (setq index (1+ index)) 2087 (cond ((and (numberp specindex) (= index specindex)
2085 (insert " ") 2088 ;; Don't handle the definition dynamically
2086 (cond ((and (numberp specindex) (= index specindex) 2089 ;; if it refers (or might refer)
2087 ;; Don't handle the definition dynamically 2090 ;; to objects already output
2088 ;; if it refers (or might refer) 2091 ;; (for instance, gensyms in the arg list).
2089 ;; to objects already output 2092 (let (non-nil)
2090 ;; (for instance, gensyms in the arg list). 2093 (dotimes (i (length print-number-table))
2091 (let (non-nil) 2094 (if (aref print-number-table i)
2092 (dotimes (i (length print-number-table)) 2095 (setq non-nil t)))
2093 (if (aref print-number-table i) 2096 (not non-nil)))
2094 (setq non-nil t))) 2097 ;; Output the byte code and constants specially
2095 (not non-nil))) 2098 ;; for lazy dynamic loading.
2096 ;; Output the byte code and constants specially 2099 (let ((position
2097 ;; for lazy dynamic loading. 2100 (byte-compile-output-as-comment
2098 (let ((position 2101 (cons (car form) (nth 1 form))
2099 (byte-compile-output-as-comment 2102 t)))
2100 (cons (car form) (nth 1 form)) 2103 (setq position (- (position-bytes position) (point-min) -1))
2101 t))) 2104 (princ (format "(#$ . %d) nil" position) outbuffer)
2102 (setq position (- (position-bytes position) (point-min) -1)) 2105 (setq form (cdr form))
2103 (princ (format "(#$ . %d) nil" position) outbuffer) 2106 (setq index (1+ index))))
2104 (setq form (cdr form)) 2107 ((= index (nth 1 info))
2105 (setq index (1+ index)))) 2108 (if position
2106 ((= index (nth 1 info)) 2109 (princ (format (if quoted "'(#$ . %d)" "(#$ . %d)")
2107 (if position 2110 position)
2108 (princ (format (if quoted "'(#$ . %d)" "(#$ . %d)") 2111 outbuffer)
2109 position) 2112 (let ((print-escape-newlines nil))
2110 outbuffer) 2113 (goto-char (prog1 (1+ (point))
2111 (let ((print-escape-newlines nil)) 2114 (prin1 (car form) outbuffer)))
2112 (goto-char (prog1 (1+ (point)) 2115 (insert "\\\n")
2113 (prin1 (car form) outbuffer))) 2116 (goto-char (point-max)))))
2114 (insert "\\\n") 2117 (t
2115 (goto-char (point-max))))) 2118 (prin1 (car form) outbuffer)))))
2116 (t 2119 (insert (nth 2 info)))))
2117 (prin1 (car form) outbuffer)))))
2118 (insert (nth 2 info))))))
2119 nil) 2120 nil)
2120 2121
2121 (defun byte-compile-keep-pending (form &optional handler) 2122 (defun byte-compile-keep-pending (form &optional handler)
2122 (if (memq byte-optimize '(t source)) 2123 (if (memq byte-optimize '(t source))
2123 (setq form (byte-optimize-form form t))) 2124 (setq form (byte-optimize-form form t)))
2399 ;; Print Lisp object EXP in the output file, inside a comment, 2400 ;; Print Lisp object EXP in the output file, inside a comment,
2400 ;; and return the file position it will have. 2401 ;; and return the file position it will have.
2401 ;; If QUOTED is non-nil, print with quoting; otherwise, print without quoting. 2402 ;; If QUOTED is non-nil, print with quoting; otherwise, print without quoting.
2402 (defun byte-compile-output-as-comment (exp quoted) 2403 (defun byte-compile-output-as-comment (exp quoted)
2403 (let ((position (point))) 2404 (let ((position (point)))
2404 (set-buffer 2405 (with-current-buffer outbuffer
2405 (prog1 (current-buffer) 2406
2406 (set-buffer outbuffer) 2407 ;; Insert EXP, and make it a comment with #@LENGTH.
2407 2408 (insert " ")
2408 ;; Insert EXP, and make it a comment with #@LENGTH. 2409 (if quoted
2409 (insert " ") 2410 (prin1 exp outbuffer)
2410 (if quoted 2411 (princ exp outbuffer))
2411 (prin1 exp outbuffer) 2412 (goto-char position)
2412 (princ exp outbuffer)) 2413 ;; Quote certain special characters as needed.
2413 (goto-char position) 2414 ;; get_doc_string in doc.c does the unquoting.
2414 ;; Quote certain special characters as needed. 2415 (while (search-forward "\^A" nil t)
2415 ;; get_doc_string in doc.c does the unquoting. 2416 (replace-match "\^A\^A" t t))
2416 (while (search-forward "\^A" nil t) 2417 (goto-char position)
2417 (replace-match "\^A\^A" t t)) 2418 (while (search-forward "\000" nil t)
2418 (goto-char position) 2419 (replace-match "\^A0" t t))
2419 (while (search-forward "\000" nil t) 2420 (goto-char position)
2420 (replace-match "\^A0" t t)) 2421 (while (search-forward "\037" nil t)
2421 (goto-char position) 2422 (replace-match "\^A_" t t))
2422 (while (search-forward "\037" nil t) 2423 (goto-char (point-max))
2423 (replace-match "\^A_" t t)) 2424 (insert "\037")
2424 (goto-char (point-max)) 2425 (goto-char position)
2425 (insert "\037") 2426 (insert "#@" (format "%d" (- (position-bytes (point-max))
2426 (goto-char position) 2427 (position-bytes position))))
2427 (insert "#@" (format "%d" (- (position-bytes (point-max)) 2428
2428 (position-bytes position)))) 2429 ;; Save the file position of the object.
2429 2430 ;; Note we should add 1 to skip the space
2430 ;; Save the file position of the object. 2431 ;; that we inserted before the actual doc string,
2431 ;; Note we should add 1 to skip the space 2432 ;; and subtract 1 to convert from an 1-origin Emacs position
2432 ;; that we inserted before the actual doc string, 2433 ;; to a file position; they cancel.
2433 ;; and subtract 1 to convert from an 1-origin Emacs position 2434 (setq position (point))
2434 ;; to a file position; they cancel. 2435 (goto-char (point-max)))
2435 (setq position (point))
2436 (goto-char (point-max))))
2437 position)) 2436 position))
2438 2437
2439 2438
2440 2439
2441 ;;;###autoload 2440 ;;;###autoload