comparison lisp/emacs-lisp/bytecomp.el @ 28402:843e552813e3

Doc fixes. (byte-compile-file-form-autoload): Update byte-compile-function-environment.
author Dave Love <fx@gnu.org>
date Wed, 29 Mar 2000 21:32:57 +0000
parents 49b7af1b8e1b
children 561ff5634d32
comparison
equal deleted inserted replaced
28401:65f19ae2c578 28402:843e552813e3
6 ;; Author: Jamie Zawinski <jwz@lucid.com> 6 ;; Author: Jamie Zawinski <jwz@lucid.com>
7 ;; Hallvard Furuseth <hbf@ulrik.uio.no> 7 ;; Hallvard Furuseth <hbf@ulrik.uio.no>
8 ;; Maintainer: FSF 8 ;; Maintainer: FSF
9 ;; Keywords: lisp 9 ;; Keywords: lisp
10 10
11 ;;; This version incorporates changes up to version 2.10 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 "$Revision: 2.65 $") 13 (defconst byte-compile-version "$Revision: 2.66 $")
14 14
15 ;; This file is part of GNU Emacs. 15 ;; This file is part of GNU Emacs.
16 16
17 ;; GNU Emacs is free software; you can redistribute it and/or modify 17 ;; GNU Emacs is free software; you can redistribute it and/or modify
18 ;; it under the terms of the GNU General Public License as published by 18 ;; it under the terms of the GNU General Public License as published by
62 ;; + compile-time warning messages for: 62 ;; + compile-time warning messages for:
63 ;; - functions being redefined with incompatible arglists; 63 ;; - functions being redefined with incompatible arglists;
64 ;; - functions being redefined as macros, or vice-versa; 64 ;; - functions being redefined as macros, or vice-versa;
65 ;; - functions or macros defined multiple times in the same file; 65 ;; - functions or macros defined multiple times in the same file;
66 ;; - functions being called with the incorrect number of arguments; 66 ;; - functions being called with the incorrect number of arguments;
67 ;; - functions being called which are not defined globally, in the 67 ;; - functions being called which are not defined globally, in the
68 ;; file, or as autoloads; 68 ;; file, or as autoloads;
69 ;; - assignment and reference of undeclared free variables; 69 ;; - assignment and reference of undeclared free variables;
70 ;; - various syntax errors; 70 ;; - various syntax errors;
71 ;; + correct compilation of nested defuns, defmacros, defvars and defsubsts; 71 ;; + correct compilation of nested defuns, defmacros, defvars and defsubsts;
72 ;; + correct compilation of top-level uses of macros; 72 ;; + correct compilation of top-level uses of macros;
74 74
75 ;; User customization variables: 75 ;; User customization variables:
76 ;; 76 ;;
77 ;; byte-compile-verbose Whether to report the function currently being 77 ;; byte-compile-verbose Whether to report the function currently being
78 ;; compiled in the minibuffer; 78 ;; compiled in the minibuffer;
79 ;; byte-optimize Whether to do optimizations; this may be 79 ;; byte-optimize Whether to do optimizations; this may be
80 ;; t, nil, 'source, or 'byte; 80 ;; t, nil, 'source, or 'byte;
81 ;; byte-optimize-log Whether to report (in excruciating detail) 81 ;; byte-optimize-log Whether to report (in excruciating detail)
82 ;; exactly which optimizations have been made. 82 ;; exactly which optimizations have been made.
83 ;; This may be t, nil, 'source, or 'byte; 83 ;; This may be t, nil, 'source, or 'byte;
84 ;; byte-compile-error-on-warn Whether to stop compilation when a warning is 84 ;; byte-compile-error-on-warn Whether to stop compilation when a warning is
85 ;; produced; 85 ;; produced;
86 ;; byte-compile-delete-errors Whether the optimizer may delete calls or 86 ;; byte-compile-delete-errors Whether the optimizer may delete calls or
87 ;; variable references that are side-effect-free 87 ;; variable references that are side-effect-free
88 ;; except that they may return an error. 88 ;; except that they may return an error.
89 ;; byte-compile-generate-call-tree Whether to generate a histogram of 89 ;; byte-compile-generate-call-tree Whether to generate a histogram of
90 ;; function calls. This can be useful for 90 ;; function calls. This can be useful for
91 ;; finding unused functions, as well as simple 91 ;; finding unused functions, as well as simple
92 ;; performance metering. 92 ;; performance metering.
93 ;; byte-compile-warnings List of warnings to issue, or t. May contain 93 ;; byte-compile-warnings List of warnings to issue, or t. May contain
94 ;; 'free-vars (references to variables not in the 94 ;; 'free-vars (references to variables not in the
95 ;; current lexical scope) 95 ;; current lexical scope)
123 ;; o You can also open-code one particular call to a function without 123 ;; o You can also open-code one particular call to a function without
124 ;; open-coding all calls. Use the 'inline' form to do this, like so: 124 ;; open-coding all calls. Use the 'inline' form to do this, like so:
125 ;; 125 ;;
126 ;; (inline (foo 1 2 3)) ;; `foo' will be open-coded 126 ;; (inline (foo 1 2 3)) ;; `foo' will be open-coded
127 ;; or... 127 ;; or...
128 ;; (inline ;; `foo' and `baz' will be 128 ;; (inline ;; `foo' and `baz' will be
129 ;; (foo 1 2 3 (bar 5)) ;; open-coded, but `bar' will not. 129 ;; (foo 1 2 3 (bar 5)) ;; open-coded, but `bar' will not.
130 ;; (baz 0)) 130 ;; (baz 0))
131 ;; 131 ;;
132 ;; o It is possible to open-code a function in the same file it is defined 132 ;; o It is possible to open-code a function in the same file it is defined
133 ;; in without having to load that file before compiling it. the 133 ;; in without having to load that file before compiling it. the
146 ;; o The form `eval-and-compile' is similar to eval-when-compile, but 146 ;; o The form `eval-and-compile' is similar to eval-when-compile, but
147 ;; the whole form is evalled both at compile-time and at run-time. 147 ;; the whole form is evalled both at compile-time and at run-time.
148 ;; 148 ;;
149 ;; o The command compile-defun is analogous to eval-defun. 149 ;; o The command compile-defun is analogous to eval-defun.
150 ;; 150 ;;
151 ;; 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
152 ;; 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
153 ;; to save the buffer before compiling. 153 ;; to save the buffer before compiling.
154 ;; 154 ;;
155 ;; o byte-compiled files now start with the string `;ELC'. 155 ;; o byte-compiled files now start with the string `;ELC'.
156 ;; Some versions of `file' can be customized to recognize that. 156 ;; Some versions of `file' can be customized to recognize that.
256 :type 'boolean) 256 :type 'boolean)
257 257
258 ;; (defvar byte-compile-generate-emacs19-bytecodes 258 ;; (defvar byte-compile-generate-emacs19-bytecodes
259 ;; (not (or (and (boundp 'epoch::version) epoch::version) 259 ;; (not (or (and (boundp 'epoch::version) epoch::version)
260 ;; (string-lessp emacs-version "19"))) 260 ;; (string-lessp emacs-version "19")))
261 ;; "*If this is true, then the byte-compiler will generate bytecode which 261 ;; "*If this is true, then the byte-compiler will generate bytecode which
262 ;; makes use of byte-ops which are present only in Emacs 19. Code generated 262 ;; makes use of byte-ops which are present only in Emacs 19. Code generated
263 ;; this way can never be run in Emacs 18, and may even cause it to crash.") 263 ;; this way can never be run in Emacs 18, and may even cause it to crash.")
264 264
265 (defcustom byte-optimize t 265 (defcustom byte-optimize t
266 "*Enables optimization in the byte compiler. 266 "*Enables optimization in the byte compiler.
382 382
383 ;; (defvar byte-compile-overwrite-file t 383 ;; (defvar byte-compile-overwrite-file t
384 ;; "If nil, old .elc files are deleted before the new is saved, and .elc 384 ;; "If nil, old .elc files are deleted before the new is saved, and .elc
385 ;; files will have the same modes as the corresponding .el file. Otherwise, 385 ;; files will have the same modes as the corresponding .el file. Otherwise,
386 ;; existing .elc files will simply be overwritten, and the existing modes 386 ;; existing .elc files will simply be overwritten, and the existing modes
387 ;; will not be changed. If this variable is nil, then an .elc file which 387 ;; will not be changed. If this variable is nil, then an .elc file which
388 ;; is a symbolic link will be turned into a normal file, instead of the file 388 ;; is a symbolic link will be turned into a normal file, instead of the file
389 ;; which the link points to being overwritten.") 389 ;; which the link points to being overwritten.")
390 390
391 (defvar byte-compile-constants nil 391 (defvar byte-compile-constants nil
392 "List of all constants encountered during compilation of this form.") 392 "List of all constants encountered during compilation of this form.")
572 "for reference to a constant with vector index >= byte-constant-limit") 572 "for reference to a constant with vector index >= byte-constant-limit")
573 (byte-defop 130 0 byte-goto "for unconditional jump") 573 (byte-defop 130 0 byte-goto "for unconditional jump")
574 (byte-defop 131 -1 byte-goto-if-nil "to pop value and jump if it's nil") 574 (byte-defop 131 -1 byte-goto-if-nil "to pop value and jump if it's nil")
575 (byte-defop 132 -1 byte-goto-if-not-nil "to pop value and jump if it's not nil") 575 (byte-defop 132 -1 byte-goto-if-not-nil "to pop value and jump if it's not nil")
576 (byte-defop 133 -1 byte-goto-if-nil-else-pop 576 (byte-defop 133 -1 byte-goto-if-nil-else-pop
577 "to examine top-of-stack, jump and don't pop it if it's nil, 577 "to examine top-of-stack, jump and don't pop it if it's nil,
578 otherwise pop it") 578 otherwise pop it")
579 (byte-defop 134 -1 byte-goto-if-not-nil-else-pop 579 (byte-defop 134 -1 byte-goto-if-not-nil-else-pop
580 "to examine top-of-stack, jump and don't pop it if it's non nil, 580 "to examine top-of-stack, jump and don't pop it if it's non nil,
581 otherwise pop it") 581 otherwise pop it")
582 582
583 (byte-defop 135 -1 byte-return "to pop a value and return it from `byte-code'") 583 (byte-defop 135 -1 byte-return "to pop a value and return it from `byte-code'")
584 (byte-defop 136 -1 byte-discard "to discard one value from stack") 584 (byte-defop 136 -1 byte-discard "to discard one value from stack")
585 (byte-defop 137 1 byte-dup "to duplicate the top of the stack") 585 (byte-defop 137 1 byte-dup "to duplicate the top of the stack")
593 (byte-defop 141 -1 byte-catch 593 (byte-defop 141 -1 byte-catch
594 "for catch. Takes, on stack, the tag and an expression for the body") 594 "for catch. Takes, on stack, the tag and an expression for the body")
595 (byte-defop 142 -1 byte-unwind-protect 595 (byte-defop 142 -1 byte-unwind-protect
596 "for unwind-protect. Takes, on stack, an expression for the unwind-action") 596 "for unwind-protect. Takes, on stack, an expression for the unwind-action")
597 597
598 ;; For condition-case. Takes, on stack, the variable to bind, 598 ;; For condition-case. Takes, on stack, the variable to bind,
599 ;; an expression for the body, and a list of clauses. 599 ;; an expression for the body, and a list of clauses.
600 (byte-defop 143 -2 byte-condition-case) 600 (byte-defop 143 -2 byte-condition-case)
601 601
602 ;; For entry to with-output-to-temp-buffer. 602 ;; For entry to with-output-to-temp-buffer.
603 ;; Takes, on stack, the buffer name. 603 ;; Takes, on stack, the buffer name.
670 ;;; 670 ;;;
671 ;;; Elements of the lapcode list are of the form (<instruction> . <parameter>) 671 ;;; Elements of the lapcode list are of the form (<instruction> . <parameter>)
672 ;;; where instruction is a symbol naming a byte-code instruction, 672 ;;; where instruction is a symbol naming a byte-code instruction,
673 ;;; and parameter is an argument to that instruction, if any. 673 ;;; and parameter is an argument to that instruction, if any.
674 ;;; 674 ;;;
675 ;;; The instruction can be the pseudo-op TAG, which means that this position 675 ;;; The instruction can be the pseudo-op TAG, which means that this position
676 ;;; in the instruction stream is a target of a goto. (car PARAMETER) will be 676 ;;; in the instruction stream is a target of a goto. (car PARAMETER) will be
677 ;;; the PC for this location, and the whole instruction "(TAG pc)" will be the 677 ;;; the PC for this location, and the whole instruction "(TAG pc)" will be the
678 ;;; parameter for some goto op. 678 ;;; parameter for some goto op.
679 ;;; 679 ;;;
680 ;;; If the operation is varbind, varref, varset or push-constant, then the 680 ;;; If the operation is varbind, varref, varset or push-constant, then the
914 ;; (verbose byte-compile-verbose (t nil) val) 914 ;; (verbose byte-compile-verbose (t nil) val)
915 ;; (warnings byte-compile-warnings ((callargs redefine free-vars unresolved)) 915 ;; (warnings byte-compile-warnings ((callargs redefine free-vars unresolved))
916 ;; val))) 916 ;; val)))
917 917
918 ;; Inhibit v18/v19 selectors if the version is hardcoded. 918 ;; Inhibit v18/v19 selectors if the version is hardcoded.
919 ;; #### This should print a warning if the user tries to change something 919 ;; #### This should print a warning if the user tries to change something
920 ;; than can't be changed because the running compiler doesn't support it. 920 ;; than can't be changed because the running compiler doesn't support it.
921 ;; (cond 921 ;; (cond
922 ;; ((byte-compile-single-version) 922 ;; ((byte-compile-single-version)
923 ;; (setcar (cdr (cdr (assq 'new-bytecodes byte-compiler-valid-options))) 923 ;; (setcar (cdr (cdr (assq 'new-bytecodes byte-compiler-valid-options)))
924 ;; (list (byte-compile-version-cond 924 ;; (list (byte-compile-version-cond
1148 (defsubst byte-compile-const-symbol-p (symbol) 1148 (defsubst byte-compile-const-symbol-p (symbol)
1149 (or (memq symbol '(nil t)) 1149 (or (memq symbol '(nil t))
1150 (keywordp symbol))) 1150 (keywordp symbol)))
1151 1151
1152 (defmacro byte-compile-constp (form) 1152 (defmacro byte-compile-constp (form)
1153 ;; Returns non-nil if FORM is a constant. 1153 "Return non-nil if FORM is a constant."
1154 `(cond ((consp ,form) (eq (car ,form) 'quote)) 1154 `(cond ((consp ,form) (eq (car ,form) 'quote))
1155 ((not (symbolp ,form))) 1155 ((not (symbolp ,form)))
1156 ((byte-compile-const-symbol-p ,form)))) 1156 ((byte-compile-const-symbol-p ,form))))
1157 1157
1158 (defmacro byte-compile-close-variables (&rest body) 1158 (defmacro byte-compile-close-variables (&rest body)
1400 (load target-file)) 1400 (load target-file))
1401 t))) 1401 t)))
1402 1402
1403 ;;(defun byte-compile-and-load-file (&optional filename) 1403 ;;(defun byte-compile-and-load-file (&optional filename)
1404 ;; "Compile a file of Lisp code named FILENAME into a file of byte code, 1404 ;; "Compile a file of Lisp code named FILENAME into a file of byte code,
1405 ;;and then load it. The output file's name is made by appending \"c\" to 1405 ;;and then load it. The output file's name is made by appending \"c\" to
1406 ;;the end of FILENAME." 1406 ;;the end of FILENAME."
1407 ;; (interactive) 1407 ;; (interactive)
1408 ;; (if filename ; I don't get it, (interactive-p) doesn't always work 1408 ;; (if filename ; I don't get it, (interactive-p) doesn't always work
1409 ;; (byte-compile-file filename t) 1409 ;; (byte-compile-file filename t)
1410 ;; (let ((current-prefix-arg '(4))) 1410 ;; (let ((current-prefix-arg '(4)))
1804 (and (let ((form form)) 1804 (and (let ((form form))
1805 (while (if (setq form (cdr form)) (byte-compile-constp (car form)))) 1805 (while (if (setq form (cdr form)) (byte-compile-constp (car form))))
1806 (null form)) ;Constants only 1806 (null form)) ;Constants only
1807 (eval (nth 5 form)) ;Macro 1807 (eval (nth 5 form)) ;Macro
1808 (eval form)) ;Define the autoload. 1808 (eval form)) ;Define the autoload.
1809 ;; Avoid undefined function warnings for the autoload.
1810 (if (and (consp (nth 1 form))
1811 (eq (car (nth 1 form)) 'quote)
1812 (consp (cdr (nth 1 form)))
1813 (symbolp (nth 1 (nth 1 form))))
1814 (add-to-list 'byte-compile-function-environment
1815 (cons (nth 1 (nth 1 form))
1816 form)))
1809 (if (stringp (nth 3 form)) 1817 (if (stringp (nth 3 form))
1810 form 1818 form
1811 ;; No doc string, so we can compile this as a normal form. 1819 ;; No doc string, so we can compile this as a normal form.
1812 (byte-compile-keep-pending form 'byte-compile-normal-call))) 1820 (byte-compile-keep-pending form 'byte-compile-normal-call)))
1813 1821
2306 (cond ((eq (car-safe body) 'progn) 2314 (cond ((eq (car-safe body) 'progn)
2307 (cdr body)) 2315 (cdr body))
2308 (body 2316 (body
2309 (list body)))) 2317 (list body))))
2310 2318
2311 ;; This is the recursive entry point for compiling each subform of an 2319 ;; This is the recursive entry point for compiling each subform of an
2312 ;; expression. 2320 ;; expression.
2313 ;; If for-effect is non-nil, byte-compile-form will output a byte-discard 2321 ;; If for-effect is non-nil, byte-compile-form will output a byte-discard
2314 ;; before terminating (ie no value will be left on the stack). 2322 ;; before terminating (ie no value will be left on the stack).
2315 ;; A byte-compile handler may, when for-effect is non-nil, choose output code 2323 ;; A byte-compile handler may, when for-effect is non-nil, choose output code
2316 ;; which does not leave a value on the stack, and then set for-effect to nil 2324 ;; which does not leave a value on the stack, and then set for-effect to nil
3132 (prin1-to-string condition))) 3140 (prin1-to-string condition)))
3133 ;; ((not (or (eq condition 't) 3141 ;; ((not (or (eq condition 't)
3134 ;; (and (stringp (get condition 'error-message)) 3142 ;; (and (stringp (get condition 'error-message))
3135 ;; (consp (get condition 'error-conditions))))) 3143 ;; (consp (get condition 'error-conditions)))))
3136 ;; (byte-compile-warn 3144 ;; (byte-compile-warn
3137 ;; "%s is not a known condition name (in condition-case)" 3145 ;; "%s is not a known condition name (in condition-case)"
3138 ;; condition)) 3146 ;; condition))
3139 ) 3147 )
3140 (setq compiled-clauses 3148 (setq compiled-clauses
3141 (cons (cons condition 3149 (cons (cons condition
3142 (byte-compile-top-level-body 3150 (byte-compile-top-level-body
3222 ;; Put the defined variable in this library's load-history entry 3230 ;; Put the defined variable in this library's load-history entry
3223 ;; just as a real defvar would. 3231 ;; just as a real defvar would.
3224 (list 'setq 'current-load-list 3232 (list 'setq 'current-load-list
3225 (list 'cons (list 'quote var) 3233 (list 'cons (list 'quote var)
3226 'current-load-list)) 3234 'current-load-list))
3227 (if string 3235 (if string
3228 (list 'put (list 'quote var) ''variable-documentation string)) 3236 (list 'put (list 'quote var) ''variable-documentation string))
3229 (list 'quote var))))) 3237 (list 'quote var)))))
3230 3238
3231 (defun byte-compile-autoload (form) 3239 (defun byte-compile-autoload (form)
3232 (and (byte-compile-constp (nth 1 form)) 3240 (and (byte-compile-constp (nth 1 form))
3233 (byte-compile-constp (nth 5 form)) 3241 (byte-compile-constp (nth 5 form))
3234 (eval (nth 5 form)) ; macro-p 3242 (eval (nth 5 form)) ; macro-p
3235 (not (fboundp (eval (nth 1 form)))) 3243 (not (fboundp (eval (nth 1 form))))
3236 (byte-compile-warn 3244 (byte-compile-warn
3237 "The compiler ignores `autoload' except at top level. You should 3245 "The compiler ignores `autoload' except at top level. You should
3238 probably put the autoload of the macro `%s' at top-level." 3246 probably put the autoload of the macro `%s' at top-level."
3239 (eval (nth 1 form)))) 3247 (eval (nth 1 form))))
3240 (byte-compile-normal-call form)) 3248 (byte-compile-normal-call form))
3241 3249
3242 ;; Lambda's in valid places are handled as special cases by various code. 3250 ;; Lambdas in valid places are handled as special cases by various code.
3243 ;; The ones that remain are errors. 3251 ;; The ones that remain are errors.
3244 (defun byte-compile-lambda-form (form) 3252 (defun byte-compile-lambda-form (form)
3245 (error "`lambda' used as function name is invalid")) 3253 (error "`lambda' used as function name is invalid"))
3246 3254
3247 ;; Compile normally, but deal with warnings for the function being defined. 3255 ;; Compile normally, but deal with warnings for the function being defined.