annotate lisp/bytecomp.el @ 392:1f50e6fe4f3f r21-2-11

Import from CVS: tag r21-2-11
author cvs
date Mon, 13 Aug 2007 11:10:50 +0200
parents 8626e4521993
children 74fd4e045ea6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1 ;;; bytecomp.el --- compilation of Lisp code into byte code.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3 ;;; Copyright (C) 1985-1987, 1991-1994 Free Software Foundation, Inc.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4 ;;; Copyright (C) 1996 Ben Wing.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
5
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
6 ;; Author: Jamie Zawinski <jwz@netscape.com>
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
7 ;; Hallvard Furuseth <hbf@ulrik.uio.no>
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
8 ;; Keywords: internal
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
9
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
10 ;; Subsequently modified by RMS and others.
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
11
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
12 (defconst byte-compile-version (purecopy "2.26 XEmacs; 1998-10-07."))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
13
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
14 ;; This file is part of XEmacs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
15
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
16 ;; XEmacs is free software; you can redistribute it and/or modify it
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
17 ;; under the terms of the GNU General Public License as published by
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
18 ;; the Free Software Foundation; either version 2, or (at your option)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
19 ;; any later version.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
20
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
21 ;; XEmacs is distributed in the hope that it will be useful, but
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
22 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
24 ;; General Public License for more details.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
25
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
26 ;; You should have received a copy of the GNU General Public License
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
27 ;; along with XEmacs; see the file COPYING. If not, write to the
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
28 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
29 ;; Boston, MA 02111-1307, USA.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
30
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
31 ;;; Synched up with: FSF 19.30.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
32
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
33 ;;; Commentary:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
34
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 280
diff changeset
35 ;; The Emacs Lisp byte compiler. This crunches lisp source into a
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
36 ;; sort of p-code which takes up less space and can be interpreted
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
37 ;; faster. The user entry points are byte-compile-file,
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 280
diff changeset
38 ;; byte-recompile-directory and byte-compile-buffer.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
39
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
40 ;;; Code:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
41
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
42 ;;; ========================================================================
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
43 ;;; Entry points:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
44 ;;; byte-recompile-directory, byte-compile-file,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
45 ;;; batch-byte-compile, batch-byte-recompile-directory,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
46 ;;; byte-compile, compile-defun,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
47 ;;; display-call-tree
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
48 ;;; RMS says:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
49 ;;; (byte-compile-buffer and byte-compile-and-load-file were turned off
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
50 ;;; because they are not terribly useful and get in the way of completion.)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
51 ;;; But I'm leaving them. --ben
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
52
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
53 ;;; This version of the byte compiler has the following improvements:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
54 ;;; + optimization of compiled code:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
55 ;;; - removal of unreachable code;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
56 ;;; - removal of calls to side-effectless functions whose return-value
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
57 ;;; is unused;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
58 ;;; - compile-time evaluation of safe constant forms, such as (consp nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
59 ;;; and (ash 1 6);
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
60 ;;; - open-coding of literal lambdas;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
61 ;;; - peephole optimization of emitted code;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
62 ;;; - trivial functions are left uncompiled for speed.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
63 ;;; + support for inline functions;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
64 ;;; + compile-time evaluation of arbitrary expressions;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
65 ;;; + compile-time warning messages for:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
66 ;;; - functions being redefined with incompatible arglists;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
67 ;;; - functions being redefined as macros, or vice-versa;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
68 ;;; - functions or macros defined multiple times in the same file;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
69 ;;; - functions being called with the incorrect number of arguments;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
70 ;;; - functions being called which are not defined globally, in the
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
71 ;;; file, or as autoloads;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
72 ;;; - assignment and reference of undeclared free variables;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
73 ;;; - various syntax errors;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
74 ;;; + correct compilation of nested defuns, defmacros, defvars and defsubsts;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
75 ;;; + correct compilation of top-level uses of macros;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
76 ;;; + the ability to generate a histogram of functions called.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
77
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
78 ;;; User customization variables:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
79 ;;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
80 ;;; byte-compile-verbose Whether to report the function currently being
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
81 ;;; compiled in the minibuffer;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
82 ;;; byte-optimize Whether to do optimizations; this may be
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
83 ;;; t, nil, 'source, or 'byte;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
84 ;;; byte-optimize-log Whether to report (in excruciating detail)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
85 ;;; exactly which optimizations have been made.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
86 ;;; This may be t, nil, 'source, or 'byte;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
87 ;;; byte-compile-error-on-warn Whether to stop compilation when a warning is
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
88 ;;; produced;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
89 ;;; byte-compile-delete-errors Whether the optimizer may delete calls or
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
90 ;;; variable references that are side-effect-free
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
91 ;;; except that they may return an error.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
92 ;;; byte-compile-generate-call-tree Whether to generate a histogram of
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
93 ;;; function calls. This can be useful for
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
94 ;;; finding unused functions, as well as simple
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
95 ;;; performance metering.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
96 ;;; byte-compile-warnings List of warnings to issue, or t. May contain
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
97 ;;; 'free-vars (references to variables not in the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
98 ;;; current lexical scope)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
99 ;;; 'unused-vars (non-global variables bound but
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
100 ;;; not referenced)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
101 ;;; 'unresolved (calls to unknown functions)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
102 ;;; 'callargs (lambda calls with args that don't
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
103 ;;; match the lambda's definition)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
104 ;;; 'subr-callargs (calls to subrs with args that
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
105 ;;; don't match the subr's definition)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
106 ;;; 'redefine (function cell redefined from
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
107 ;;; a macro to a lambda or vice versa,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
108 ;;; or redefined to take other args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
109 ;;; 'obsolete (obsolete variables and functions)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
110 ;;; 'pedantic (references to Emacs-compatible
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
111 ;;; symbols)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
112 ;;; byte-compile-emacs19-compatibility Whether the compiler should
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
113 ;;; generate .elc files which can be loaded into
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
114 ;;; generic emacs 19.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
115 ;;; emacs-lisp-file-regexp Regexp for the extension of source-files;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
116 ;;; see also the function byte-compile-dest-file.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
117 ;;; byte-compile-overwrite-file If nil, delete old .elc files before saving.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
118 ;;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
119 ;;; Most of the above parameters can also be set on a file-by-file basis; see
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
120 ;;; the documentation of the `byte-compiler-options' macro.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
121
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
122 ;;; New Features:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
123 ;;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
124 ;;; o The form `defsubst' is just like `defun', except that the function
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
125 ;;; generated will be open-coded in compiled code which uses it. This
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
126 ;;; means that no function call will be generated, it will simply be
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
127 ;;; spliced in. Lisp functions calls are very slow, so this can be a
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
128 ;;; big win.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
129 ;;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
130 ;;; You can generally accomplish the same thing with `defmacro', but in
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
131 ;;; that case, the defined procedure can't be used as an argument to
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
132 ;;; mapcar, etc.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
133 ;;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
134 ;;; o You can make a given function be inline even if it has already been
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
135 ;;; defined with `defun' by using the `proclaim-inline' form like so:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
136 ;;; (proclaim-inline my-function)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
137 ;;; This is, in fact, exactly what `defsubst' does. To make a function no
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
138 ;;; longer be inline, you must use `proclaim-notinline'. Beware that if
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
139 ;;; you define a function with `defsubst' and later redefine it with
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
140 ;;; `defun', it will still be open-coded until you use proclaim-notinline.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
141 ;;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
142 ;;; o You can also open-code one particular call to a function without
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
143 ;;; open-coding all calls. Use the 'inline' form to do this, like so:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
144 ;;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
145 ;;; (inline (foo 1 2 3)) ;; `foo' will be open-coded
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
146 ;;; or...
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
147 ;;; (inline ;; `foo' and `baz' will be
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
148 ;;; (foo 1 2 3 (bar 5)) ;; open-coded, but `bar' will not.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
149 ;;; (baz 0))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
150 ;;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
151 ;;; o It is possible to open-code a function in the same file it is defined
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
152 ;;; in without having to load that file before compiling it. the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
153 ;;; byte-compiler has been modified to remember function definitions in
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
154 ;;; the compilation environment in the same way that it remembers macro
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
155 ;;; definitions.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
156 ;;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
157 ;;; o Forms like ((lambda ...) ...) are open-coded.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
158 ;;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
159 ;;; o The form `eval-when-compile' is like progn, except that the body
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
160 ;;; is evaluated at compile-time. When it appears at top-level, this
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
161 ;;; is analogous to the Common Lisp idiom (eval-when (compile) ...).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
162 ;;; When it does not appear at top-level, it is similar to the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
163 ;;; Common Lisp #. reader macro (but not in interpreted code).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
164 ;;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
165 ;;; o The form `eval-and-compile' is similar to eval-when-compile, but
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
166 ;;; the whole form is evalled both at compile-time and at run-time.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
167 ;;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
168 ;;; o The command M-x byte-compile-and-load-file does what you'd think.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
169 ;;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
170 ;;; o The command compile-defun is analogous to eval-defun.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
171 ;;;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
172 ;;; o If you run byte-compile-file on a filename which is visited in a
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
173 ;;; buffer, and that buffer is modified, you are asked whether you want
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
174 ;;; to save the buffer before compiling.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
175 ;;;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
176 ;;; o You can add this to /etc/magic to make file(1) recognize the files
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
177 ;;; generated by this compiler:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
178 ;;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
179 ;;; 0 string ;ELC GNU Emacs Lisp compiled file,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
180 ;;; >4 byte x version %d
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
181 ;;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
182 ;;; TO DO:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
183 ;;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
184 ;;; o Should implement declarations and proclamations, notably special,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
185 ;;; unspecial, and ignore. Do this in such a way as to not break cl.el.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
186 ;;; o The bound-but-not-used warnings are not issued for variables whose
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
187 ;;; bindings were established in the arglist, due to the lack of an
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
188 ;;; ignore declaration. Once ignore exists, this should be turned on.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
189 ;;; o Warn about functions and variables defined but not used?
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
190 ;;; Maybe add some kind of `export' declaration for this?
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
191 ;;; (With interactive functions being automatically exported?)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
192 ;;; o Any reference to a variable, even one which is a no-op, will cause
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
193 ;;; the warning not to be given. Possibly we could use the for-effect
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
194 ;;; flag to determine when this reference is useless; possibly more
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
195 ;;; complex flow analysis would be necessary.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
196 ;;; o If the optimizer deletes a variable reference, we might be left with
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
197 ;;; a bound-but-not-referenced warning. Generally this is ok, but not if
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
198 ;;; it's a synergistic result of macroexpansion. Need some way to note
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
199 ;;; that a varref is being optimized away? Of course it would be nice to
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
200 ;;; optimize away the binding too, someday, but it's unsafe today.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
201 ;;; o (See byte-optimize.el for the optimization TODO list.)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
202
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
203 (require 'backquote)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
204
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
205 (or (fboundp 'defsubst)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
206 ;; This really ought to be loaded already!
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
207 (load-library "bytecomp-runtime"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
208
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
209 (eval-when-compile
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
210 (defvar byte-compile-single-version nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
211 "If this is true, the choice of emacs version (v19 or v20) byte-codes will
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
212 be hard-coded into bytecomp when it compiles itself. If the compiler itself
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
213 is compiled with optimization, this causes a speedup.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
214
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
215 (cond
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
216 (byte-compile-single-version
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
217 (defmacro byte-compile-single-version () t)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
218 (defmacro byte-compile-version-cond (cond) (list 'quote (eval cond))))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
219 (t
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
220 (defmacro byte-compile-single-version () nil)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
221 (defmacro byte-compile-version-cond (cond) cond)))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
222 )
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
223
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
224 (defvar emacs-lisp-file-regexp (purecopy "\\.el$")
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
225 "*Regexp which matches Emacs Lisp source files.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
226 You may want to redefine `byte-compile-dest-file' if you change this.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
227
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
228 ;; This enables file name handlers such as jka-compr
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
229 ;; to remove parts of the file name that should not be copied
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
230 ;; through to the output file name.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
231 (defun byte-compiler-base-file-name (filename)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
232 (let ((handler (find-file-name-handler filename
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
233 'byte-compiler-base-file-name)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
234 (if handler
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
235 (funcall handler 'byte-compiler-base-file-name filename)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
236 filename)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
237
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
238 (unless (fboundp 'byte-compile-dest-file)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
239 ;; The user may want to redefine this along with emacs-lisp-file-regexp,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
240 ;; so only define it if it is undefined.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
241 (defun byte-compile-dest-file (filename)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
242 "Convert an Emacs Lisp source file name to a compiled file name."
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
243 (setq filename (byte-compiler-base-file-name filename))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
244 (setq filename (file-name-sans-versions filename))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
245 (if (string-match emacs-lisp-file-regexp filename)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
246 (concat (substring filename 0 (match-beginning 0)) ".elc")
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
247 (concat filename ".elc"))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
248
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
249 ;; This can be the 'byte-compile property of any symbol.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
250 (autoload 'byte-compile-inline-expand "byte-optimize")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
251
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
252 ;; This is the entrypoint to the lapcode optimizer pass1.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
253 (autoload 'byte-optimize-form "byte-optimize")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
254 ;; This is the entrypoint to the lapcode optimizer pass2.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
255 (autoload 'byte-optimize-lapcode "byte-optimize")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
256 (autoload 'byte-compile-unfold-lambda "byte-optimize")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
257
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
258 ;; This is the entry point to the decompiler, which is used by the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
259 ;; disassembler. The disassembler just requires 'byte-compile, but
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
260 ;; that doesn't define this function, so this seems to be a reasonable
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
261 ;; thing to do.
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
262 (autoload 'byte-decompile-bytecode "byte-optimize")
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
263
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
264 (defvar byte-compile-verbose
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
265 (and (not noninteractive) (> (device-baud-rate) search-slow-speed))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
266 "*Non-nil means print messages describing progress of byte-compiler.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
267
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
268 (defvar byte-compile-emacs19-compatibility
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
269 (not (emacs-version>= 20))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
270 "*Non-nil means generate output that can run in Emacs 19.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
271
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
272 (defvar byte-compile-print-gensym t
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
273 "*Non-nil means generate code that creates unique symbols at run-time.
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
274 This is achieved by printing uninterned symbols using the `#:SYMBOL'
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
275 notation, so that they will be read uninterned when run.
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
276
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
277 With this feature, code that uses uninterned symbols in macros will
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
278 not be runnable under pre-21.0 XEmacsen.
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
279
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
280 When `byte-compile-emacs19-compatibility' is non-nil, this variable is
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
281 ignored and considered to be nil.")
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
282
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
283 (defvar byte-optimize t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
284 "*Enables optimization in the byte compiler.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
285 nil means don't do any optimization.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
286 t means do all optimizations.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
287 `source' means do source-level optimizations only.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
288 `byte' means do code-level optimizations only.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
289
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
290 (defvar byte-compile-delete-errors t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
291 "*If non-nil, the optimizer may delete forms that may signal an error.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
292 This includes variable references and calls to functions such as `car'.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
293
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
294 ;; XEmacs addition
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
295 (defvar byte-compile-new-bytecodes nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
296 "This is completely ignored. It is only around for backwards
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
297 compatibility.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
298
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
299
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
300 ;; FSF enables byte-compile-dynamic-docstrings but not byte-compile-dynamic
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
301 ;; by default. This would be a reasonable conservative approach except
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
302 ;; for the fact that if you enable either of these, you get incompatible
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
303 ;; byte code that can't be read by XEmacs 19.13 or before or FSF 19.28 or
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
304 ;; before.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
305 ;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
306 ;; Therefore, neither is enabled for 19.14. Both are enabled for 20.0
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
307 ;; because we have no reason to be conservative about changing the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
308 ;; way things work. (Ben)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
309
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
310 ;; However, I don't think that defaulting byte-compile-dynamic to nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
311 ;; is a compatibility issue - rather it is a performance issue.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
312 ;; Therefore I am setting byte-compile-dynamic back to nil. (mrb)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
313
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
314 (defvar byte-compile-dynamic nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
315 "*If non-nil, compile function bodies so they load lazily.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
316 They are hidden comments in the compiled file, and brought into core when the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
317 function is called.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
318
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
319 To enable this option, make it a file-local variable
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
320 in the source file you want it to apply to.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
321 For example, add -*-byte-compile-dynamic: t;-*- on the first line.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
322
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
323 When this option is true, if you load the compiled file and then move it,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
324 the functions you loaded will not be able to run.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
325
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
326 (defvar byte-compile-dynamic-docstrings (emacs-version>= 20)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
327 "*If non-nil, compile doc strings for lazy access.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
328 We bury the doc strings of functions and variables
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
329 inside comments in the file, and bring them into core only when they
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
330 are actually needed.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
331
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
332 When this option is true, if you load the compiled file and then move it,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
333 you won't be able to find the documentation of anything in that file.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
334
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
335 To disable this option for a certain file, make it a file-local variable
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
336 in the source file. For example, add this to the first line:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
337 -*-byte-compile-dynamic-docstrings:nil;-*-
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
338 You can also set the variable globally.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
339
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
340 This option is enabled by default because it reduces Emacs memory usage.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
341
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
342 (defvar byte-optimize-log nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
343 "*If true, the byte-compiler will log its optimizations into *Compile-Log*.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
344 If this is 'source, then only source-level optimizations will be logged.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
345 If it is 'byte, then only byte-level optimizations will be logged.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
346
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
347 (defvar byte-compile-error-on-warn nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
348 "*If true, the byte-compiler reports warnings with `error'.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
349
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
350 ;; byte-compile-warning-types in FSF.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
351 (defvar byte-compile-default-warnings
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
352 '(redefine callargs subr-callargs free-vars unresolved unused-vars obsolete)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
353 "*The warnings used when byte-compile-warnings is t.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
354
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
355 (defvar byte-compile-warnings t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
356 "*List of warnings that the compiler should issue (t for the default set).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
357 Elements of the list may be:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
358
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
359 free-vars references to variables not in the current lexical scope.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
360 unused-vars references to non-global variables bound but not referenced.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
361 unresolved calls to unknown functions.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
362 callargs lambda calls with args that don't match the definition.
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
363 subr-callargs calls to subrs with args that don't match the definition.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
364 redefine function cell redefined from a macro to a lambda or vice
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
365 versa, or redefined to take a different number of arguments.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
366 obsolete use of an obsolete function or variable.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
367 pedantic warn of use of compatible symbols.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
368
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
369 The default set is specified by `byte-compile-default-warnings' and
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
370 normally encompasses all possible warnings.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
371
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
372 See also the macro `byte-compiler-options'.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
373
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
374 (defvar byte-compile-generate-call-tree nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
375 "*Non-nil means collect call-graph information when compiling.
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
376 This records functions that were called and from where.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
377 If the value is t, compilation displays the call graph when it finishes.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
378 If the value is neither t nor nil, compilation asks you whether to display
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
379 the graph.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
380
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
381 The call tree only lists functions called, not macros used. Those functions
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
382 which the byte-code interpreter knows about directly (eq, cons, etc.) are
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
383 not reported.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
384
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
385 The call tree also lists those functions which are not known to be called
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
386 \(that is, to which no calls have been compiled). Functions which can be
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
387 invoked interactively are excluded from this list.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
388
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
389 (defconst byte-compile-call-tree nil "Alist of functions and their call tree.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
390 Each element looks like
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
391
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
392 \(FUNCTION CALLERS CALLS\)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
393
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
394 where CALLERS is a list of functions that call FUNCTION, and CALLS
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
395 is a list of functions for which calls were generated while compiling
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
396 FUNCTION.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
397
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
398 (defvar byte-compile-call-tree-sort 'name
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
399 "*If non-nil, sort the call tree.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
400 The values `name', `callers', `calls', `calls+callers'
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
401 specify different fields to sort on.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
402
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
403 (defvar byte-compile-overwrite-file t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
404 "If nil, old .elc files are deleted before the new is saved, and .elc
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
405 files will have the same modes as the corresponding .el file. Otherwise,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
406 existing .elc files will simply be overwritten, and the existing modes
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
407 will not be changed. If this variable is nil, then an .elc file which
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
408 is a symbolic link will be turned into a normal file, instead of the file
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
409 which the link points to being overwritten.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
410
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
411 (defvar byte-recompile-directory-ignore-errors-p nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
412 "If true, then `byte-recompile-directory' will continue compiling even
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
413 when an error occurs in a file. This is bound to t by
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
414 `batch-byte-recompile-directory'.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
415
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
416 (defvar byte-recompile-directory-recursively t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
417 "*If true, then `byte-recompile-directory' will recurse on subdirectories.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
418
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
419 (defvar byte-compile-constants nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
420 "list of all constants encountered during compilation of this form")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
421 (defvar byte-compile-variables nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
422 "list of all variables encountered during compilation of this form")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
423 (defvar byte-compile-bound-variables nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
424 "Alist of variables bound in the context of the current form,
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
425 that is, the current lexical environment. This list lives partly
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
426 on the specbind stack. The cdr of each cell is an integer bitmask.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
427
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
428 (defconst byte-compile-referenced-bit 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
429 (defconst byte-compile-assigned-bit 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
430 (defconst byte-compile-arglist-bit 4)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
431 (defconst byte-compile-global-bit 8)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
432
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
433 (defvar byte-compile-free-references)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
434 (defvar byte-compile-free-assignments)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
435 (defvar debug-issue-ebola-notices)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
436
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
437 (defvar byte-compiler-error-flag)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
438
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
439 (defconst byte-compile-initial-macro-environment
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
440 (purecopy
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
441 '((byte-compiler-options . (lambda (&rest forms)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
442 (apply 'byte-compiler-options-handler forms)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
443 (eval-when-compile . (lambda (&rest body)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
444 (list 'quote (eval (byte-compile-top-level
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
445 (cons 'progn body))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
446 (eval-and-compile . (lambda (&rest body)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
447 (eval (cons 'progn body))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
448 (cons 'progn body)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
449 "The default macro-environment passed to macroexpand by the compiler.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
450 Placing a macro here will cause a macro to have different semantics when
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
451 expanded by the compiler as when expanded by the interpreter.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
452
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
453 (defvar byte-compile-macro-environment byte-compile-initial-macro-environment
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
454 "Alist of macros defined in the file being compiled.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
455 Each element looks like (MACRONAME . DEFINITION). It is
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
456 \(MACRONAME . nil) when a macro is redefined as a function.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
457
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
458 (defvar byte-compile-function-environment nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
459 "Alist of functions defined in the file being compiled.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
460 This is so we can inline them when necessary.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
461 Each element looks like (FUNCTIONNAME . DEFINITION). It is
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
462 \(FUNCTIONNAME . nil) when a function is redefined as a macro.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
463
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
464 (defvar byte-compile-autoload-environment nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
465 "Alist of functions and macros defined by autoload in the file being compiled.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
466 This is so we can suppress warnings about calls to these functions, even though
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
467 they do not have `real' definitions.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
468 Each element looks like (FUNCTIONNAME . CALL-TO-AUTOLOAD).")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
469
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
470 (defvar byte-compile-unresolved-functions nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
471 "Alist of undefined functions to which calls have been compiled (used for
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
472 warnings when the function is later defined with incorrect args).")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
473
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
474 (defvar byte-compile-file-domain) ; domain of file being compiled
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
475
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
476 (defvar byte-compile-tag-number 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
477 (defvar byte-compile-output nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
478 "Alist describing contents to put in byte code string.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
479 Each element is (INDEX . VALUE)")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
480 (defvar byte-compile-depth 0 "Current depth of execution stack.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
481 (defvar byte-compile-maxdepth 0 "Maximum depth of execution stack.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
482
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
483
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
484 ;;; The byte codes; this information is duplicated in bytecode.c
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
485
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
486 (defconst byte-code-vector nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
487 "An array containing byte-code names indexed by byte-code values.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
488
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
489 (defconst byte-stack+-info nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
490 "An array with the stack adjustment for each byte-code.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
491
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
492 (defmacro byte-defop (opcode stack-adjust opname &optional docstring)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
493 ;; This is a speed-hack for building the byte-code-vector at compile-time.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
494 ;; We fill in the vector at macroexpand-time, and then after the last call
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
495 ;; to byte-defop, we write the vector out as a constant instead of writing
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
496 ;; out a bunch of calls to aset.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
497 ;; Actually, we don't fill in the vector itself, because that could make
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
498 ;; it problematic to compile big changes to this compiler; we store the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
499 ;; values on its plist, and remove them later in -extrude.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
500 (let ((v1 (or (get 'byte-code-vector 'tmp-compile-time-value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
501 (put 'byte-code-vector 'tmp-compile-time-value
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
502 (make-vector 256 nil))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
503 (v2 (or (get 'byte-stack+-info 'tmp-compile-time-value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
504 (put 'byte-stack+-info 'tmp-compile-time-value
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
505 (make-vector 256 nil)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
506 (aset v1 opcode opname)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
507 (aset v2 opcode stack-adjust))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
508 (if docstring
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
509 (list 'defconst opname opcode (concat "Byte code opcode " docstring "."))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
510 (list 'defconst opname opcode)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
511
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
512 (defmacro byte-extrude-byte-code-vectors ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
513 (prog1 (list 'setq 'byte-code-vector
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
514 (get 'byte-code-vector 'tmp-compile-time-value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
515 'byte-stack+-info
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
516 (get 'byte-stack+-info 'tmp-compile-time-value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
517 (remprop 'byte-code-vector 'tmp-compile-time-value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
518 (remprop 'byte-stack+-info 'tmp-compile-time-value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
519
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
520
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
521 ;; unused: 0-7
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
522
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
523 ;; These opcodes are special in that they pack their argument into the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
524 ;; opcode word.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
525 ;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
526 (byte-defop 8 1 byte-varref "for variable reference")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
527 (byte-defop 16 -1 byte-varset "for setting a variable")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
528 (byte-defop 24 -1 byte-varbind "for binding a variable")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
529 (byte-defop 32 0 byte-call "for calling a function")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
530 (byte-defop 40 0 byte-unbind "for unbinding special bindings")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
531 ;; codes 8-47 are consumed by the preceding opcodes
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
532
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
533 ;; unused: 48-55
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
534
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
535 (byte-defop 56 -1 byte-nth)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
536 (byte-defop 57 0 byte-symbolp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
537 (byte-defop 58 0 byte-consp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
538 (byte-defop 59 0 byte-stringp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
539 (byte-defop 60 0 byte-listp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
540 (byte-defop 61 -1 byte-old-eq)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
541 (byte-defop 62 -1 byte-old-memq)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
542 (byte-defop 63 0 byte-not)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
543 (byte-defop 64 0 byte-car)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
544 (byte-defop 65 0 byte-cdr)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
545 (byte-defop 66 -1 byte-cons)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
546 (byte-defop 67 0 byte-list1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
547 (byte-defop 68 -1 byte-list2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
548 (byte-defop 69 -2 byte-list3)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
549 (byte-defop 70 -3 byte-list4)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
550 (byte-defop 71 0 byte-length)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
551 (byte-defop 72 -1 byte-aref)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
552 (byte-defop 73 -2 byte-aset)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
553 (byte-defop 74 0 byte-symbol-value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
554 (byte-defop 75 0 byte-symbol-function) ; this was commented out
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
555 (byte-defop 76 -1 byte-set)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
556 (byte-defop 77 -1 byte-fset) ; this was commented out
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
557 (byte-defop 78 -1 byte-get)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
558 (byte-defop 79 -2 byte-substring)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
559 (byte-defop 80 -1 byte-concat2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
560 (byte-defop 81 -2 byte-concat3)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
561 (byte-defop 82 -3 byte-concat4)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
562 (byte-defop 83 0 byte-sub1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
563 (byte-defop 84 0 byte-add1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
564 (byte-defop 85 -1 byte-eqlsign)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
565 (byte-defop 86 -1 byte-gtr)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
566 (byte-defop 87 -1 byte-lss)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
567 (byte-defop 88 -1 byte-leq)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
568 (byte-defop 89 -1 byte-geq)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
569 (byte-defop 90 -1 byte-diff)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
570 (byte-defop 91 0 byte-negate)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
571 (byte-defop 92 -1 byte-plus)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
572 (byte-defop 93 -1 byte-max)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
573 (byte-defop 94 -1 byte-min)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
574 (byte-defop 95 -1 byte-mult)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
575 (byte-defop 96 1 byte-point)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
576 (byte-defop 97 -1 byte-eq) ; new as of v20
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
577 (byte-defop 98 0 byte-goto-char)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
578 (byte-defop 99 0 byte-insert)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
579 (byte-defop 100 1 byte-point-max)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
580 (byte-defop 101 1 byte-point-min)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
581 (byte-defop 102 0 byte-char-after)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
582 (byte-defop 103 1 byte-following-char)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
583 (byte-defop 104 1 byte-preceding-char)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
584 (byte-defop 105 1 byte-current-column)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
585 (byte-defop 106 0 byte-indent-to)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
586 (byte-defop 107 -1 byte-equal) ; new as of v20
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
587 (byte-defop 108 1 byte-eolp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
588 (byte-defop 109 1 byte-eobp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
589 (byte-defop 110 1 byte-bolp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
590 (byte-defop 111 1 byte-bobp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
591 (byte-defop 112 1 byte-current-buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
592 (byte-defop 113 0 byte-set-buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
593 (byte-defop 114 0 byte-save-current-buffer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
594 "To make a binding to record the current buffer.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
595 ;;(byte-defop 114 1 byte-read-char-OBSOLETE) ;obsolete as of v19
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
596 (byte-defop 115 -1 byte-memq) ; new as of v20
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
597 (byte-defop 116 1 byte-interactive-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
598
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
599 (byte-defop 117 0 byte-forward-char)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
600 (byte-defop 118 0 byte-forward-word)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
601 (byte-defop 119 -1 byte-skip-chars-forward)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
602 (byte-defop 120 -1 byte-skip-chars-backward)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
603 (byte-defop 121 0 byte-forward-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
604 (byte-defop 122 0 byte-char-syntax)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
605 (byte-defop 123 -1 byte-buffer-substring)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
606 (byte-defop 124 -1 byte-delete-region)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
607 (byte-defop 125 -1 byte-narrow-to-region)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
608 (byte-defop 126 1 byte-widen)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
609 (byte-defop 127 0 byte-end-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
610
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
611 ;; unused: 128
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
612
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
613 ;; These store their argument in the next two bytes
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
614 (byte-defop 129 1 byte-constant2
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
615 "for reference to a constant with vector index >= byte-constant-limit")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
616 (byte-defop 130 0 byte-goto "for unconditional jump")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
617 (byte-defop 131 -1 byte-goto-if-nil "to pop value and jump if it's nil")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
618 (byte-defop 132 -1 byte-goto-if-not-nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
619 "to pop value and jump if it's not nil")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
620 (byte-defop 133 -1 byte-goto-if-nil-else-pop
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
621 "to examine top-of-stack, jump and don't pop it if it's nil,
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
622 otherwise pop it")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
623 (byte-defop 134 -1 byte-goto-if-not-nil-else-pop
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
624 "to examine top-of-stack, jump and don't pop it if it's non-nil,
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
625 otherwise pop it")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
626
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
627 (byte-defop 135 -1 byte-return "to pop a value and return it from `byte-code'")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
628 (byte-defop 136 -1 byte-discard "to discard one value from stack")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
629 (byte-defop 137 1 byte-dup "to duplicate the top of the stack")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
630
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
631 (byte-defop 138 0 byte-save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
632 "to make a binding to record the buffer, point and mark")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
633 (byte-defop 139 0 byte-save-window-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
634 "to make a binding to record entire window configuration")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
635 (byte-defop 140 0 byte-save-restriction
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
636 "to make a binding to record the current buffer clipping restrictions")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
637 (byte-defop 141 -1 byte-catch
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
638 "for catch. Takes, on stack, the tag and an expression for the body")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
639 (byte-defop 142 -1 byte-unwind-protect
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
640 "for unwind-protect. Takes, on stack, an expression for the unwind-action")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
641
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
642 ;; For condition-case. Takes, on stack, the variable to bind,
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
643 ;; an expression for the body, and a list of clauses.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
644 (byte-defop 143 -2 byte-condition-case)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
645
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
646 ;; For entry to with-output-to-temp-buffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
647 ;; Takes, on stack, the buffer name.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
648 ;; Binds standard-output and does some other things.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
649 ;; Returns with temp buffer on the stack in place of buffer name.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
650 (byte-defop 144 0 byte-temp-output-buffer-setup)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
651
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
652 ;; For exit from with-output-to-temp-buffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
653 ;; Expects the temp buffer on the stack underneath value to return.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
654 ;; Pops them both, then pushes the value back on.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
655 ;; Unbinds standard-output and makes the temp buffer visible.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
656 (byte-defop 145 -1 byte-temp-output-buffer-show)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
657
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
658 ;; To unbind back to the beginning of this frame.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
659 ;; Not used yet, but will be needed for tail-recursion elimination.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
660 (byte-defop 146 0 byte-unbind-all)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
661
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
662 (byte-defop 147 -2 byte-set-marker)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
663 (byte-defop 148 0 byte-match-beginning)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
664 (byte-defop 149 0 byte-match-end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
665 (byte-defop 150 0 byte-upcase)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
666 (byte-defop 151 0 byte-downcase)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
667 (byte-defop 152 -1 byte-string=)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
668 (byte-defop 153 -1 byte-string<)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
669 (byte-defop 154 -1 byte-old-equal)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
670 (byte-defop 155 -1 byte-nthcdr)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
671 (byte-defop 156 -1 byte-elt)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
672 (byte-defop 157 -1 byte-old-member)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
673 (byte-defop 158 -1 byte-old-assq)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
674 (byte-defop 159 0 byte-nreverse)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
675 (byte-defop 160 -1 byte-setcar)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
676 (byte-defop 161 -1 byte-setcdr)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
677 (byte-defop 162 0 byte-car-safe)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
678 (byte-defop 163 0 byte-cdr-safe)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
679 (byte-defop 164 -1 byte-nconc)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
680 (byte-defop 165 -1 byte-quo)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
681 (byte-defop 166 -1 byte-rem)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
682 (byte-defop 167 0 byte-numberp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
683 (byte-defop 168 0 byte-integerp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
684
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
685 ;; unused: 169
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
686
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
687 ;; These are not present in FSF.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
688 ;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
689 (byte-defop 170 0 byte-rel-goto)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
690 (byte-defop 171 -1 byte-rel-goto-if-nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
691 (byte-defop 172 -1 byte-rel-goto-if-not-nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
692 (byte-defop 173 -1 byte-rel-goto-if-nil-else-pop)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
693 (byte-defop 174 -1 byte-rel-goto-if-not-nil-else-pop)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
694
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
695 (byte-defop 175 nil byte-listN)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
696 (byte-defop 176 nil byte-concatN)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
697 (byte-defop 177 nil byte-insertN)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
698
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
699 ;; unused: 178-181
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
700
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
701 ;; these ops are new to v20
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
702 (byte-defop 182 -1 byte-member)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
703 (byte-defop 183 -1 byte-assq)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
704
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
705 ;; unused: 184-191
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
706
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
707 (byte-defop 192 1 byte-constant "for reference to a constant")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
708 ;; codes 193-255 are consumed by byte-constant.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
709 (defconst byte-constant-limit 64
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
710 "Exclusive maximum index usable in the `byte-constant' opcode.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
711
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
712 (defconst byte-goto-ops (purecopy
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
713 '(byte-goto byte-goto-if-nil byte-goto-if-not-nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
714 byte-goto-if-nil-else-pop
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
715 byte-goto-if-not-nil-else-pop))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
716 "List of byte-codes whose offset is a pc.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
717
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
718 (defconst byte-goto-always-pop-ops
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
719 (purecopy '(byte-goto-if-nil byte-goto-if-not-nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
720
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
721 (defconst byte-rel-goto-ops
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
722 (purecopy '(byte-rel-goto byte-rel-goto-if-nil byte-rel-goto-if-not-nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
723 byte-rel-goto-if-nil-else-pop byte-rel-goto-if-not-nil-else-pop))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
724 "byte-codes for relative jumps.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
725
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
726 (byte-extrude-byte-code-vectors)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
727
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
728 ;;; lapcode generator
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
729 ;;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
730 ;;; the byte-compiler now does source -> lapcode -> bytecode instead of
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
731 ;;; source -> bytecode, because it's a lot easier to make optimizations
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
732 ;;; on lapcode than on bytecode.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
733 ;;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
734 ;;; Elements of the lapcode list are of the form (<instruction> . <parameter>)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
735 ;;; where instruction is a symbol naming a byte-code instruction,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
736 ;;; and parameter is an argument to that instruction, if any.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
737 ;;;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
738 ;;; The instruction can be the pseudo-op TAG, which means that this position
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
739 ;;; in the instruction stream is a target of a goto. (car PARAMETER) will be
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
740 ;;; the PC for this location, and the whole instruction "(TAG pc)" will be the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
741 ;;; parameter for some goto op.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
742 ;;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
743 ;;; If the operation is varbind, varref, varset or push-constant, then the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
744 ;;; parameter is (variable/constant . index_in_constant_vector).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
745 ;;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
746 ;;; First, the source code is macroexpanded and optimized in various ways.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
747 ;;; Then the resultant code is compiled into lapcode. Another set of
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
748 ;;; optimizations are then run over the lapcode. Then the variables and
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
749 ;;; constants referenced by the lapcode are collected and placed in the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
750 ;;; constants-vector. (This happens now so that variables referenced by dead
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
751 ;;; code don't consume space.) And finally, the lapcode is transformed into
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
752 ;;; compacted byte-code.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
753 ;;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
754 ;;; A distinction is made between variables and constants because the variable-
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
755 ;;; referencing instructions are more sensitive to the variables being near the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
756 ;;; front of the constants-vector than the constant-referencing instructions.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
757 ;;; Also, this lets us notice references to free variables.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
758
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
759 (defun byte-compile-lapcode (lap)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
760 "Turns lapcode into bytecode. The lapcode is destroyed."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
761 ;; Lapcode modifications: changes the ID of a tag to be the tag's PC.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
762 (let ((pc 0) ; Program counter
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
763 op off ; Operation & offset
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
764 (bytes '()) ; Put the output bytes here
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
765 (patchlist nil) ; List of tags and goto's to patch
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
766 rest rel tmp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
767 (while lap
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
768 (setq op (car (car lap))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
769 off (cdr (car lap)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
770 (cond ((not (symbolp op))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
771 (error "Non-symbolic opcode `%s'" op))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
772 ((eq op 'TAG)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
773 (setcar off pc)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
774 (push off patchlist))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
775 ((memq op byte-goto-ops)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
776 (setq pc (+ pc 3))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
777 (setq bytes (cons (cons pc (cdr off))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
778 (cons nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
779 (cons (symbol-value op) bytes))))
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
780 (push bytes patchlist))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
781 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
782 (setq bytes
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
783 (cond ((cond ((consp off)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
784 ;; Variable or constant reference
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
785 (setq off (cdr off))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
786 (eq op 'byte-constant)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
787 (cond ((< off byte-constant-limit)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
788 (setq pc (1+ pc))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
789 (cons (+ byte-constant off) bytes))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
790 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
791 (setq pc (+ 3 pc))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
792 (cons (lsh off -8)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
793 (cons (logand off 255)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
794 (cons byte-constant2 bytes))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
795 ((and (<= byte-listN (symbol-value op))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
796 (<= (symbol-value op) byte-insertN))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
797 (setq pc (+ 2 pc))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
798 (cons off (cons (symbol-value op) bytes)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
799 ((< off 6)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
800 (setq pc (1+ pc))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
801 (cons (+ (symbol-value op) off) bytes))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
802 ((< off 256)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
803 (setq pc (+ 2 pc))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
804 (cons off (cons (+ (symbol-value op) 6) bytes)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
805 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
806 (setq pc (+ 3 pc))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
807 (cons (lsh off -8)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
808 (cons (logand off 255)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
809 (cons (+ (symbol-value op) 7)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
810 bytes))))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
811 (setq lap (cdr lap)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
812 ;;(if (not (= pc (length bytes)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
813 ;; (error "Compiler error: pc mismatch - %s %s" pc (length bytes)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
814 (cond (t ;; starting with Emacs 19.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
815 ;; Make relative jumps
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
816 (setq patchlist (nreverse patchlist))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
817 (while (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
818 (setq off 0) ; PC change because of deleted bytes
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
819 (setq rest patchlist)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
820 (while rest
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
821 (setq tmp (car rest))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
822 (and (consp (car tmp)) ; Jump
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
823 (prog1 (null (nth 1 tmp)) ; Absolute jump
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
824 (setq tmp (car tmp)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
825 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
826 (setq rel (- (car (cdr tmp)) (car tmp)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
827 (and (<= -129 rel) (< rel 128)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
828 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
829 ;; Convert to relative jump.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
830 (setcdr (car rest) (cdr (cdr (car rest))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
831 (setcar (cdr (car rest))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
832 (+ (car (cdr (car rest)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
833 (- byte-rel-goto byte-goto)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
834 (setq off (1- off))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
835 (setcar tmp (+ (car tmp) off)) ; Adjust PC
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
836 (setq rest (cdr rest)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
837 ;; If optimizing, repeat until no change.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
838 (and byte-optimize
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
839 (not (zerop off)))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
840 ;; Patch PC into jumps
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
841 (let (bytes)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
842 (while patchlist
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
843 (setq bytes (car patchlist))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
844 (cond ((atom (car bytes))) ; Tag
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
845 ((nth 1 bytes) ; Relative jump
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
846 (setcar bytes (+ (- (car (cdr (car bytes))) (car (car bytes)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
847 128)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
848 (t ; Absolute jump
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
849 (setq pc (car (cdr (car bytes)))) ; Pick PC from tag
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
850 (setcar (cdr bytes) (logand pc 255))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
851 (setcar bytes (lsh pc -8))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
852 (setq patchlist (cdr patchlist))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
853 (concat (nreverse bytes))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
854
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
855
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
856 ;;; byte compiler messages
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
857
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
858 (defvar byte-compile-current-form nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
859 (defvar byte-compile-current-file nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
860 (defvar byte-compile-dest-file nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
861
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
862 (defmacro byte-compile-log (format-string &rest args)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
863 `(when (and byte-optimize (memq byte-optimize-log '(t source)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
864 (let ((print-escape-newlines t)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
865 (print-level 4)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
866 (print-length 4))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
867 (byte-compile-log-1 (format ,format-string ,@args)))))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
868
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
869 (defconst byte-compile-last-warned-form 'nothing)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
870
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
871 ;; Log a message STRING in *Compile-Log*.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
872 ;; Also log the current function and file if not already done.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
873 (defun byte-compile-log-1 (string &optional fill)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
874 (let* ((this-form (or byte-compile-current-form "toplevel forms"))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
875 (while-compiling-msg
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
876 (when (or byte-compile-current-file
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
877 (not (eq this-form byte-compile-last-warned-form)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
878 (format
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
879 "While compiling %s%s:"
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
880 this-form
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
881 (cond
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
882 ((stringp byte-compile-current-file)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
883 (concat " in file " byte-compile-current-file))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
884 ((bufferp byte-compile-current-file)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
885 (concat " in buffer "
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
886 (buffer-name byte-compile-current-file)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
887 (""))))))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
888 (if noninteractive
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
889 (progn
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
890 (when while-compiling-msg (message "%s" while-compiling-msg))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
891 (message " %s" string))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
892 (with-current-buffer (get-buffer-create "*Compile-Log*")
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
893 (goto-char (point-max))
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
894 (when byte-compile-current-file
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
895 (when (> (point-max) (point-min))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
896 (insert "\n\^L\n"))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
897 (insert (current-time-string) "\n"))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
898 (when while-compiling-msg (insert while-compiling-msg "\n"))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
899 (insert " " string "\n")
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
900 (when (and fill (not (string-match "\n" string)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
901 (let ((fill-prefix " ")
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
902 (fill-column 78))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
903 (fill-paragraph nil)))))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
904 (setq byte-compile-current-file nil)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
905 (setq byte-compile-last-warned-form this-form)))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
906
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
907 ;; Log the start of a file in *Compile-Log*, and mark it as done.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
908 ;; But do nothing in batch mode.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
909 (defun byte-compile-log-file ()
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
910 (when (and byte-compile-current-file (not noninteractive))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
911 (with-current-buffer (get-buffer-create "*Compile-Log*")
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
912 (when (> (point-max) (point-min))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
913 (goto-char (point-max))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
914 (insert "\n\^L\n"))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
915 (insert "Compiling "
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
916 (if (stringp byte-compile-current-file)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
917 (concat "file " byte-compile-current-file)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
918 (concat "buffer " (buffer-name byte-compile-current-file)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
919 " at " (current-time-string) "\n")
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
920 (setq byte-compile-current-file nil))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
921
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
922 (defun byte-compile-warn (format &rest args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
923 (setq format (apply 'format format args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
924 (if byte-compile-error-on-warn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
925 (error "%s" format) ; byte-compile-file catches and logs it
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
926 (byte-compile-log-1 (concat "** " format) t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
927 ;;; RMS says:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
928 ;;; It is useless to flash warnings too fast to be read.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
929 ;;; Besides, they will all be shown at the end.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
930 ;;; and comments out the next two lines.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
931 (or noninteractive ; already written on stdout.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
932 (message "Warning: %s" format))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
933
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
934 ;;; This function should be used to report errors that have halted
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
935 ;;; compilation of the current file.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
936 (defun byte-compile-report-error (error-info)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
937 (setq byte-compiler-error-flag t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
938 (byte-compile-log-1
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
939 (concat "!! "
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
940 (format (if (cdr error-info) "%s (%s)" "%s")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
941 (get (car error-info) 'error-message)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
942 (prin1-to-string (cdr error-info))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
943
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
944 ;;; Used by make-obsolete.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
945 (defun byte-compile-obsolete (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
946 (let ((new (get (car form) 'byte-obsolete-info)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
947 (if (memq 'obsolete byte-compile-warnings)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
948 (byte-compile-warn "%s is an obsolete function; %s" (car form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
949 (if (stringp (car new))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
950 (car new)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
951 (format "use %s instead." (car new)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
952 (funcall (or (cdr new) 'byte-compile-normal-call) form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
953
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
954 ;;; Used by make-obsolete.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
955 (defun byte-compile-compatible (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
956 (let ((new (get (car form) 'byte-compatible-info)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
957 (if (memq 'pedantic byte-compile-warnings)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
958 (byte-compile-warn "%s is provided for compatibility; %s" (car form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
959 (if (stringp (car new))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
960 (car new)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
961 (format "use %s instead." (car new)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
962 (funcall (or (cdr new) 'byte-compile-normal-call) form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
963
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
964 ;; Compiler options
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
965
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
966 (defconst byte-compiler-legal-options
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
967 '((optimize byte-optimize (t nil source byte) val)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
968 (file-format byte-compile-emacs19-compatibility (emacs19 emacs20)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
969 (eq val 'emacs19))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
970 (delete-errors byte-compile-delete-errors (t nil) val)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
971 (verbose byte-compile-verbose (t nil) val)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
972 (new-bytecodes byte-compile-new-bytecodes (t nil) val)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
973 (warnings byte-compile-warnings
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
974 ((callargs subr-callargs redefine free-vars unused-vars unresolved))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
975 val)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
976
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
977 ;; XEmacs addition
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
978 (defconst byte-compiler-obsolete-options
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
979 '((new-bytecodes t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
980
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
981 ;; Inhibit v19/v20 selectors if the version is hardcoded.
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
982 ;; #### This should print a warning if the user tries to change something
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
983 ;; than can't be changed because the running compiler doesn't support it.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
984 (cond
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
985 ((byte-compile-single-version)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
986 (setcar (cdr (cdr (assq 'file-format byte-compiler-legal-options)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
987 (if (byte-compile-version-cond byte-compile-emacs19-compatibility)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
988 '(emacs19) '(emacs20)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
989
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
990 ;; now we can copy it.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
991 (setq byte-compiler-legal-options (purecopy byte-compiler-legal-options))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
992
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
993 (defun byte-compiler-options-handler (&rest args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
994 (let (key val desc choices)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
995 (while args
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
996 (if (or (atom (car args)) (nthcdr 2 (car args)) (null (cdr (car args))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
997 (error "malformed byte-compiler-option %s" (car args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
998 (setq key (car (car args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
999 val (car (cdr (car args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1000 desc (assq key byte-compiler-legal-options))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1001 (or desc
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1002 (error "unknown byte-compiler option %s" key))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1003 (if (assq key byte-compiler-obsolete-options)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1004 (byte-compile-warn "%s is an obsolete byte-compiler option." key))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1005 (setq choices (nth 2 desc))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1006 (if (consp (car choices))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1007 (let* (this
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1008 (handler 'cons)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1009 (var (nth 1 desc))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1010 (ret (and (memq (car val) '(+ -))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1011 (copy-sequence (if (eq t (symbol-value var))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1012 (car choices)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1013 (symbol-value var))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1014 (setq choices (car choices))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1015 (while val
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1016 (setq this (car val))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1017 (cond ((memq this choices)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1018 (setq ret (funcall handler this ret)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1019 ((eq this '+) (setq handler 'cons))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1020 ((eq this '-) (setq handler 'delq))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1021 ((error "%s only accepts %s." key choices)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1022 (setq val (cdr val)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1023 (set (nth 1 desc) ret))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1024 (or (memq val choices)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1025 (error "%s must be one of %s." key choices))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1026 (set (nth 1 desc) (eval (nth 3 desc))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1027 (setq args (cdr args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1028 nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1029
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1030 ;;; sanity-checking arglists
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1031
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1032 (defun byte-compile-fdefinition (name macro-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1033 (let* ((list (if (memq macro-p '(nil subr))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1034 byte-compile-function-environment
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1035 byte-compile-macro-environment))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1036 (env (cdr (assq name list))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1037 (or env
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1038 (let ((fn name))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1039 (while (and (symbolp fn)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1040 (fboundp fn)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1041 (or (symbolp (symbol-function fn))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1042 (consp (symbol-function fn))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1043 (and (not macro-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1044 (compiled-function-p (symbol-function fn)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1045 (and (eq macro-p 'subr) (subrp fn))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1046 (setq fn (symbol-function fn)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1047 (if (or (and (not macro-p) (compiled-function-p fn))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1048 (and (eq macro-p 'subr) (subrp fn)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1049 fn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1050 (and (consp fn)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1051 (not (eq macro-p 'subr))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1052 (if (eq 'macro (car fn))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1053 (cdr fn)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1054 (if macro-p
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1055 nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1056 (if (eq 'autoload (car fn))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1057 nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1058 fn)))))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1059
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1060 (defun byte-compile-arglist-signature (arglist)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1061 (let ((args 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1062 opts
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1063 restp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1064 (while arglist
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1065 (cond ((eq (car arglist) '&optional)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1066 (or opts (setq opts 0)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1067 ((eq (car arglist) '&rest)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1068 (if (cdr arglist)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1069 (setq restp t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1070 arglist nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1071 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1072 (if opts
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1073 (setq opts (1+ opts))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1074 (setq args (1+ args)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1075 (setq arglist (cdr arglist)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1076 (cons args (if restp nil (if opts (+ args opts) args)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1077
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1078
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1079 (defun byte-compile-arglist-signatures-congruent-p (old new)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1080 (not (or
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1081 (> (car new) (car old)) ; requires more args now
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1082 (and (null (cdr old)) ; tooks rest-args, doesn't any more
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1083 (cdr new))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1084 (and (cdr new) (cdr old) ; can't take as many args now
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1085 (< (cdr new) (cdr old)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1086 )))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1087
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1088 (defun byte-compile-arglist-signature-string (signature)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1089 (cond ((null (cdr signature))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1090 (format "%d+" (car signature)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1091 ((= (car signature) (cdr signature))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1092 (format "%d" (car signature)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1093 (t (format "%d-%d" (car signature) (cdr signature)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1094
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1095
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1096 ;; Warn if the form is calling a function with the wrong number of arguments.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1097 (defun byte-compile-callargs-warn (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1098 (let* ((def (or (byte-compile-fdefinition (car form) nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1099 (byte-compile-fdefinition (car form) t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1100 (sig (and def (byte-compile-arglist-signature
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1101 (if (eq 'lambda (car-safe def))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1102 (nth 1 def)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1103 (if (compiled-function-p def)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1104 (compiled-function-arglist def)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1105 '(&rest def))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1106 (ncall (length (cdr form))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1107 (if (and (null def)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1108 (fboundp 'subr-min-args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1109 (setq def (byte-compile-fdefinition (car form) 'subr)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1110 (setq sig (cons (subr-min-args def) (subr-max-args def))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1111 (if sig
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1112 (if (or (< ncall (car sig))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1113 (and (cdr sig) (> ncall (cdr sig))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1114 (byte-compile-warn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1115 "%s called with %d argument%s, but %s %s"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1116 (car form) ncall
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1117 (if (= 1 ncall) "" "s")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1118 (if (< ncall (car sig))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1119 "requires"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1120 "accepts only")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1121 (byte-compile-arglist-signature-string sig)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1122 (or (fboundp (car form)) ; might be a subr or autoload.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1123 ;; ## this doesn't work with recursion.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1124 (eq (car form) byte-compile-current-form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1125 ;; It's a currently-undefined function.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1126 ;; Remember number of args in call.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1127 (let ((cons (assq (car form) byte-compile-unresolved-functions))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1128 (n (length (cdr form))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1129 (if cons
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1130 (or (memq n (cdr cons))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1131 (setcdr cons (cons n (cdr cons))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1132 (setq byte-compile-unresolved-functions
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1133 (cons (list (car form) n)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1134 byte-compile-unresolved-functions))))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1135
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1136 ;; Warn if the function or macro is being redefined with a different
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1137 ;; number of arguments.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1138 (defun byte-compile-arglist-warn (form macrop)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1139 (let ((old (byte-compile-fdefinition (nth 1 form) macrop)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1140 (if old
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1141 (let ((sig1 (byte-compile-arglist-signature
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1142 (if (eq 'lambda (car-safe old))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1143 (nth 1 old)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1144 (if (compiled-function-p old)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1145 (compiled-function-arglist old)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1146 '(&rest def)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1147 (sig2 (byte-compile-arglist-signature (nth 2 form))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1148 (or (byte-compile-arglist-signatures-congruent-p sig1 sig2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1149 (byte-compile-warn "%s %s used to take %s %s, now takes %s"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1150 (if (eq (car form) 'defun) "function" "macro")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1151 (nth 1 form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1152 (byte-compile-arglist-signature-string sig1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1153 (if (equal sig1 '(1 . 1)) "argument" "arguments")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1154 (byte-compile-arglist-signature-string sig2))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1155 ;; This is the first definition. See if previous calls are compatible.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1156 (let ((calls (assq (nth 1 form) byte-compile-unresolved-functions))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1157 nums sig min max)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1158 (if calls
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1159 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1160 (setq sig (byte-compile-arglist-signature (nth 2 form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1161 nums (sort (copy-sequence (cdr calls)) (function <))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1162 min (car nums)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1163 max (car (nreverse nums)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1164 (if (or (< min (car sig))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1165 (and (cdr sig) (> max (cdr sig))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1166 (byte-compile-warn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1167 "%s being defined to take %s%s, but was previously called with %s"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1168 (nth 1 form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1169 (byte-compile-arglist-signature-string sig)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1170 (if (equal sig '(1 . 1)) " arg" " args")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1171 (byte-compile-arglist-signature-string (cons min max))))
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1172
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1173 (setq byte-compile-unresolved-functions
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1174 (delq calls byte-compile-unresolved-functions)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1175 )))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1176
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1177 ;; If we have compiled any calls to functions which are not known to be
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1178 ;; defined, issue a warning enumerating them.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1179 ;; `unresolved' in the list `byte-compile-warnings' disables this.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1180 (defun byte-compile-warn-about-unresolved-functions (&optional msg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1181 (if (memq 'unresolved byte-compile-warnings)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1182 (let ((byte-compile-current-form (or msg "the end of the data")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1183 ;; First delete the autoloads from the list.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1184 (if byte-compile-autoload-environment
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1185 (let ((rest byte-compile-unresolved-functions))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1186 (while rest
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1187 (if (assq (car (car rest)) byte-compile-autoload-environment)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1188 (setq byte-compile-unresolved-functions
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1189 (delq (car rest) byte-compile-unresolved-functions)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1190 (setq rest (cdr rest)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1191 ;; Now warn.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1192 (if (cdr byte-compile-unresolved-functions)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1193 (let* ((str "The following functions are not known to be defined: ")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1194 (L (+ (length str) 5))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1195 (rest (reverse byte-compile-unresolved-functions))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1196 s)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1197 (while rest
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1198 (setq s (symbol-name (car (car rest)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1199 L (+ L (length s) 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1200 rest (cdr rest))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1201 (if (<= L (1- fill-column))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1202 (setq str (concat str " " s (and rest ",")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1203 (setq str (concat str "\n " s (and rest ","))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1204 L (+ (length s) 4))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1205 (byte-compile-warn "%s" str))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1206 (if byte-compile-unresolved-functions
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1207 (byte-compile-warn "the function %s is not known to be defined."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1208 (car (car byte-compile-unresolved-functions)))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1209 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1210
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1211 (defun byte-compile-defvar-p (var)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1212 ;; Whether the byte compiler thinks that non-lexical references to this
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1213 ;; variable are ok.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1214 (or (globally-boundp var)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1215 (let ((rest byte-compile-bound-variables))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1216 (while (and rest var)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1217 (if (and (eq var (car-safe (car rest)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1218 (not (= 0 (logand (cdr (car rest))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1219 byte-compile-global-bit))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1220 (setq var nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1221 (setq rest (cdr rest)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1222 ;; if var is nil at this point, it's a defvar in this file.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1223 (not var))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1224
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1225
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1226 ;;; If we have compiled bindings of variables which have no referents, warn.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1227 (defun byte-compile-warn-about-unused-variables ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1228 (let ((rest byte-compile-bound-variables)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1229 (unreferenced '())
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1230 cell)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1231 (while (and rest
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1232 ;; only warn about variables whose lifetime is now ending,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1233 ;; that is, variables from the lexical scope that is now
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1234 ;; terminating. (Think nested lets.)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1235 (not (eq (car rest) 'new-scope)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1236 (setq cell (car rest))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1237 (if (and (= 0 (logand byte-compile-referenced-bit (cdr cell)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1238 ;; Don't warn about declared-but-unused arguments,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1239 ;; for two reasons: first, the arglist structure
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1240 ;; might be imposed by external forces, and we don't
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1241 ;; have (declare (ignore x)) yet; and second, inline
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1242 ;; expansion produces forms like
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1243 ;; ((lambda (arg) (byte-code "..." [arg])) x)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1244 ;; which we can't (ok, well, don't) recognize as
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1245 ;; containing a reference to arg, so every inline
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1246 ;; expansion would generate a warning. (If we had
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1247 ;; `ignore' then inline expansion could emit an
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1248 ;; ignore declaration.)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1249 (= 0 (logand byte-compile-arglist-bit (cdr cell)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1250 ;; Don't warn about defvars because this is a
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1251 ;; legitimate special binding.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1252 (not (byte-compile-defvar-p (car cell))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1253 (setq unreferenced (cons (car cell) unreferenced)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1254 (setq rest (cdr rest)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1255 (setq unreferenced (nreverse unreferenced))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1256 (while unreferenced
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1257 (byte-compile-warn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1258 (format "variable %s bound but not referenced" (car unreferenced)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1259 (setq unreferenced (cdr unreferenced)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1260
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1261
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1262 (defmacro byte-compile-constant-symbol-p (symbol)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1263 `(or (keywordp ,symbol) (memq ,symbol '(nil t))))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1264
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1265 (defmacro byte-compile-constp (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1266 ;; Returns non-nil if FORM is a constant.
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1267 `(cond ((consp ,form) (eq (car ,form) 'quote))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1268 ((symbolp ,form) (byte-compile-constant-symbol-p ,form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1269 (t)))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1270
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1271 (defmacro byte-compile-close-variables (&rest body)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1272 `(let
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1273 (;;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1274 ;; Close over these variables to encapsulate the
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1275 ;; compilation state
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1276 ;;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1277 (byte-compile-macro-environment
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1278 ;; Copy it because the compiler may patch into the
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1279 ;; macroenvironment.
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1280 (copy-alist byte-compile-initial-macro-environment))
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1281 (byte-compile-function-environment nil)
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1282 (byte-compile-autoload-environment nil)
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1283 (byte-compile-unresolved-functions nil)
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1284 (byte-compile-bound-variables nil)
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1285 (byte-compile-free-references nil)
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1286 (byte-compile-free-assignments nil)
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1287 ;;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1288 ;; Close over these variables so that `byte-compiler-options'
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1289 ;; can change them on a per-file basis.
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1290 ;;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1291 (byte-compile-verbose byte-compile-verbose)
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1292 (byte-optimize byte-optimize)
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1293 (byte-compile-emacs19-compatibility
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1294 byte-compile-emacs19-compatibility)
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1295 (byte-compile-dynamic byte-compile-dynamic)
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1296 (byte-compile-dynamic-docstrings
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1297 byte-compile-dynamic-docstrings)
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1298 (byte-compile-warnings (if (eq byte-compile-warnings t)
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1299 byte-compile-default-warnings
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1300 byte-compile-warnings))
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1301 (byte-compile-file-domain nil)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1302
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1303 ;; We reserve the right to compare ANY objects for equality.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1304 (debug-issue-ebola-notices -42)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1305 )
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1306 (prog1
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1307 (progn ,@body)
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1308 (if (memq 'unused-vars byte-compile-warnings)
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1309 ;; done compiling in this scope, warn now.
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1310 (byte-compile-warn-about-unused-variables)))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1311
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1312
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1313 (defmacro displaying-byte-compile-warnings (&rest body)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1314 `(let* ((byte-compile-log-buffer (get-buffer-create "*Compile-Log*"))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1315 (byte-compile-point-max-prev (point-max byte-compile-log-buffer)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1316 ;; Log the file name or buffer name.
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1317 (byte-compile-log-file)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1318 ;; Record how much is logged now.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1319 ;; We will display the log buffer if anything more is logged
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1320 ;; before the end of BODY.
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1321 (defvar byte-compile-warnings-beginning)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1322 (let ((byte-compile-warnings-beginning
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1323 (if (boundp 'byte-compile-warnings-beginning)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1324 byte-compile-warnings-beginning
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1325 (point-max byte-compile-log-buffer))))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1326
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1327 (unwind-protect
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1328 (condition-case error-info
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1329 (progn ,@body)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1330 (error
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1331 (byte-compile-report-error error-info)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1332
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1333 ;; Always set point in log to start of interesting output.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1334 (with-current-buffer byte-compile-log-buffer
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1335 (let ((show-begin
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1336 (progn (goto-char byte-compile-point-max-prev)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1337 (skip-chars-forward "\^L\n")
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1338 (point))))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1339 ;; If there were compilation warnings, display them.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1340 (if temp-buffer-show-function
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1341 (let ((show-buffer (get-buffer-create "*Compile-Log-Show*")))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1342 ;; Always clean show-buffer, even when not displaying it,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1343 ;; so that misleading previous messages aren't left around.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1344 (with-current-buffer show-buffer
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1345 (setq buffer-read-only nil)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1346 (erase-buffer))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1347 (copy-to-buffer show-buffer show-begin (point-max))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1348 (when (< byte-compile-warnings-beginning (point-max))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1349 (funcall temp-buffer-show-function show-buffer)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1350 (when (< byte-compile-warnings-beginning (point-max))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1351 (select-window
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1352 (prog1 (selected-window)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1353 (select-window (display-buffer (current-buffer)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1354 (goto-char show-begin)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1355 (recenter 1)))))))))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1356
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1357
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1358 ;;;###autoload
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1359 (defun byte-force-recompile (directory)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1360 "Recompile every `.el' file in DIRECTORY that already has a `.elc' file.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1361 Files in subdirectories of DIRECTORY are processed also."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1362 (interactive "DByte force recompile (directory): ")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1363 (byte-recompile-directory directory nil t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1364
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1365 ;;;###autoload
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1366 (defun byte-recompile-directory (directory &optional arg norecursion force)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1367 "Recompile every `.el' file in DIRECTORY that needs recompilation.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1368 This is if a `.elc' file exists but is older than the `.el' file.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1369 Files in subdirectories of DIRECTORY are processed also unless argument
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1370 NORECURSION is non-nil.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1371
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1372 If the `.elc' file does not exist, normally the `.el' file is *not* compiled.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1373 But a prefix argument (optional second arg) means ask user,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1374 for each such `.el' file, whether to compile it. Prefix argument 0 means
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1375 don't ask and compile the file anyway.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1376
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1377 A nonzero prefix argument also means ask about each subdirectory.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1378
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1379 If the fourth argument FORCE is non-nil,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1380 recompile every `.el' file that already has a `.elc' file."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1381 (interactive "DByte recompile directory: \nP")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1382 (if arg
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1383 (setq arg (prefix-numeric-value arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1384 (if noninteractive
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1385 nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1386 (save-some-buffers)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1387 (redraw-modeline))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1388 (let ((directories (list (expand-file-name directory)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1389 (file-count 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1390 (dir-count 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1391 last-dir)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1392 (displaying-byte-compile-warnings
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1393 (while directories
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1394 (setq directory (file-name-as-directory (car directories)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1395 (or noninteractive (message "Checking %s..." directory))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1396 (let ((files (directory-files directory))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1397 source dest)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1398 (while files
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1399 (setq source (expand-file-name (car files) directory))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1400 (if (and (not (member (car files) '("." ".." "RCS" "CVS" "SCCS")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1401 ;; Stay away from directory back-links, etc:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1402 (not (file-symlink-p source))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1403 (file-directory-p source)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1404 byte-recompile-directory-recursively)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1405 ;; This file is a subdirectory. Handle them differently.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1406 (if (or (null arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1407 (eq arg 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1408 (y-or-n-p (concat "Check " source "? ")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1409 (setq directories
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1410 (nconc directories (list source))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1411 ;; It is an ordinary file. Decide whether to compile it.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1412 (if (and (string-match emacs-lisp-file-regexp source)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1413 (not (auto-save-file-name-p source))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1414 (setq dest (byte-compile-dest-file source))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1415 (if (file-exists-p dest)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1416 ;; File was already compiled.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1417 (or force (file-newer-than-file-p source dest))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1418 ;; No compiled file exists yet.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1419 (and arg
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1420 (or (eq 0 arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1421 (y-or-n-p (concat "Compile " source "? "))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1422 (progn ;(if (and noninteractive (not byte-compile-verbose))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1423 ; (message "Compiling %s..." source))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1424 ; we do this in byte-compile-file.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1425 (if byte-recompile-directory-ignore-errors-p
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1426 (batch-byte-compile-1 source)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1427 (byte-compile-file source))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1428 (or noninteractive
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1429 (message "Checking %s..." directory))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1430 (setq file-count (1+ file-count))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1431 (if (not (eq last-dir directory))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1432 (setq last-dir directory
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1433 dir-count (1+ dir-count)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1434 )))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1435 (setq files (cdr files))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1436 (setq directories (cdr directories))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1437 (message "Done (Total of %d file%s compiled%s)"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1438 file-count (if (= file-count 1) "" "s")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1439 (if (> dir-count 1) (format " in %d directories" dir-count) ""))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1440
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1441 ;;;###autoload
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1442 (defun byte-recompile-file (filename &optional force)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1443 "Recompile a file of Lisp code named FILENAME if it needs recompilation.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1444 This is if the `.elc' file exists but is older than the `.el' file.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1445
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1446 If the `.elc' file does not exist, normally the `.el' file is *not*
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1447 compiled. But a prefix argument (optional second arg) means ask user
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1448 whether to compile it. Prefix argument 0 don't ask and recompile anyway."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1449 (interactive "fByte recompile file: \nP")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1450 (let ((dest))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1451 (if (and (string-match emacs-lisp-file-regexp filename)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1452 (not (auto-save-file-name-p filename))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1453 (setq dest (byte-compile-dest-file filename))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1454 (if (file-exists-p dest)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1455 (file-newer-than-file-p filename dest)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1456 (and force
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1457 (or (eq 0 force)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1458 (y-or-n-p (concat "Compile " filename "? "))))))
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1459 (byte-compile-file filename))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1460
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1461 ;;;###autoload
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1462 (defun byte-compile-file (filename &optional load)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1463 "Compile a file of Lisp code named FILENAME into a file of byte code.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1464 The output file's name is made by appending `c' to the end of FILENAME.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1465 With prefix arg (noninteractively: 2nd arg), load the file after compiling."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1466 ;; (interactive "fByte compile file: \nP")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1467 (interactive
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1468 (let ((file buffer-file-name)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1469 (file-name nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1470 (file-dir nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1471 (and file
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1472 (eq (cdr (assq 'major-mode (buffer-local-variables)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1473 'emacs-lisp-mode)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1474 (setq file-name (file-name-nondirectory file)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1475 file-dir (file-name-directory file)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1476 (list (read-file-name (if current-prefix-arg
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1477 "Byte compile and load file: "
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1478 "Byte compile file: ")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1479 file-dir nil nil file-name)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1480 current-prefix-arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1481 ;; Expand now so we get the current buffer's defaults
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1482 (setq filename (expand-file-name filename))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1483
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1484 ;; If we're compiling a file that's in a buffer and is modified, offer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1485 ;; to save it first.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1486 (or noninteractive
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1487 (let ((b (get-file-buffer (expand-file-name filename))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1488 (if (and b (buffer-modified-p b)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1489 (y-or-n-p (format "save buffer %s first? " (buffer-name b))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1490 (save-excursion (set-buffer b) (save-buffer)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1491
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1492 (if (or noninteractive byte-compile-verbose) ; XEmacs change
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1493 (message "Compiling %s..." filename))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1494 (let (;;(byte-compile-current-file (file-name-nondirectory filename))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1495 (byte-compile-current-file filename)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1496 target-file input-buffer output-buffer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1497 byte-compile-dest-file)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1498 (setq target-file (byte-compile-dest-file filename))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1499 (setq byte-compile-dest-file target-file)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1500 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1501 (setq input-buffer (get-buffer-create " *Compiler Input*"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1502 (set-buffer input-buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1503 (erase-buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1504 (insert-file-contents filename)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1505 ;; Run hooks including the uncompression hook.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1506 ;; If they change the file name, then change it for the output also.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1507 (let ((buffer-file-name filename)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1508 (default-major-mode 'emacs-lisp-mode)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1509 (enable-local-eval nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1510 (normal-mode)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1511 (setq filename buffer-file-name)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1512 (setq byte-compiler-error-flag nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1513 ;; It is important that input-buffer not be current at this call,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1514 ;; so that the value of point set in input-buffer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1515 ;; within byte-compile-from-buffer lingers in that buffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1516 (setq output-buffer (byte-compile-from-buffer input-buffer filename))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1517 (if byte-compiler-error-flag
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1518 nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1519 (if byte-compile-verbose
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1520 (message "Compiling %s...done" filename))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1521 (kill-buffer input-buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1522 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1523 (set-buffer output-buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1524 (goto-char (point-max))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1525 (insert "\n") ; aaah, unix.
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1526 (setq target-file (byte-compile-dest-file filename))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1527 (unless byte-compile-overwrite-file
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1528 (ignore-file-errors (delete-file target-file)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1529 (if (file-writable-p target-file)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1530 (progn
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1531 (when (memq system-type '(ms-dos windows-nt))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1532 (defvar buffer-file-type)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1533 (setq buffer-file-type t))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1534 (write-region 1 (point-max) target-file))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1535 ;; This is just to give a better error message than write-region
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1536 (signal 'file-error
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1537 (list "Opening output file"
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1538 (if (file-exists-p target-file)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1539 "cannot overwrite file"
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1540 "directory not writable or nonexistent")
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1541 target-file)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1542 (or byte-compile-overwrite-file
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1543 (condition-case ()
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1544 (set-file-modes target-file (file-modes filename))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1545 (error nil)))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1546 (kill-buffer (current-buffer)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1547 (if (and byte-compile-generate-call-tree
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1548 (or (eq t byte-compile-generate-call-tree)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1549 (y-or-n-p (format "Report call tree for %s? " filename))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1550 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1551 (display-call-tree filename)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1552 (if load
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1553 (load target-file))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1554 t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1555
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1556 ;; RMS comments the next two out.
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 280
diff changeset
1557
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 280
diff changeset
1558 ;;;###autoload
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1559 (defun byte-compile-and-load-file (&optional filename)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1560 "Compile a file of Lisp code named FILENAME into a file of byte code,
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1561 and then load it. The output file's name is made by appending \"c\" to
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1562 the end of FILENAME."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1563 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1564 (if filename ; I don't get it, (interactive-p) doesn't always work
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1565 (byte-compile-file filename t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1566 (let ((current-prefix-arg '(4)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1567 (call-interactively 'byte-compile-file))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1568
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 280
diff changeset
1569 ;;;###autoload
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1570 (defun byte-compile-buffer (&optional buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1571 "Byte-compile and evaluate contents of BUFFER (default: the current buffer)."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1572 (interactive "bByte compile buffer: ")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1573 (setq buffer (if buffer (get-buffer buffer) (current-buffer)))
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 280
diff changeset
1574 (message "Compiling %s..." buffer)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1575 (let* ((filename (or (buffer-file-name buffer)
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 280
diff changeset
1576 (prin1-to-string buffer)))
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 280
diff changeset
1577 (byte-compile-current-file buffer))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1578 (byte-compile-from-buffer buffer filename t))
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 280
diff changeset
1579 (message "Compiling %s...done" buffer)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1580 t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1581
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1582 ;;; compiling a single function
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1583 ;;;###autoload
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1584 (defun compile-defun (&optional arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1585 "Compile and evaluate the current top-level form.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1586 Print the result in the minibuffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1587 With argument, insert value in current buffer after the form."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1588 (interactive "P")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1589 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1590 (end-of-defun)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1591 (beginning-of-defun)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1592 (let* ((byte-compile-current-file (buffer-file-name))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1593 (load-file-name (buffer-file-name))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1594 (byte-compile-last-warned-form 'nothing)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1595 (value (eval (displaying-byte-compile-warnings
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1596 (byte-compile-sexp (read (current-buffer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1597 "toplevel forms")))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1598 (cond (arg
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1599 (message "Compiling from buffer... done.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1600 (prin1 value (current-buffer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1601 (insert "\n"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1602 ((message "%s" (prin1-to-string value)))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1603
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1604 (defvar byte-compile-inbuffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1605 (defvar byte-compile-outbuffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1606
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1607 (defun byte-compile-from-buffer (byte-compile-inbuffer filename &optional eval)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1608 ;; buffer --> output-buffer, or buffer --> eval form, return nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1609 (let (byte-compile-outbuffer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1610 ;; Prevent truncation of flonums and lists as we read and print them
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1611 (float-output-format nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1612 (case-fold-search nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1613 (print-length nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1614 (print-level nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1615 ;; Simulate entry to byte-compile-top-level
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1616 (byte-compile-constants nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1617 (byte-compile-variables nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1618 (byte-compile-tag-number 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1619 (byte-compile-depth 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1620 (byte-compile-maxdepth 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1621 (byte-compile-output nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1622 ;; #### This is bound in b-c-close-variables.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1623 ;; (byte-compile-warnings (if (eq byte-compile-warnings t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1624 ;; byte-compile-warning-types
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1625 ;; byte-compile-warnings))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1626 )
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1627 (byte-compile-close-variables
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1628 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1629 (setq byte-compile-outbuffer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1630 (set-buffer (get-buffer-create " *Compiler Output*")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1631 (erase-buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1632 ;; (emacs-lisp-mode)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1633 (setq case-fold-search nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1634 (and filename
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1635 (not eval)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1636 (byte-compile-insert-header filename
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1637 byte-compile-inbuffer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1638 byte-compile-outbuffer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1639
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1640 ;; This is a kludge. Some operating systems (OS/2, DOS) need to
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1641 ;; write files containing binary information specially.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1642 ;; Under most circumstances, such files will be in binary
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1643 ;; overwrite mode, so those OS's use that flag to guess how
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1644 ;; they should write their data. Advise them that .elc files
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1645 ;; need to be written carefully.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1646 (setq overwrite-mode 'overwrite-mode-binary))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1647 (displaying-byte-compile-warnings
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1648 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1649 (set-buffer byte-compile-inbuffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1650 (goto-char 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1651
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1652 ;; Compile the forms from the input buffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1653 (while (progn
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1654 (while (progn (skip-chars-forward " \t\n\^L")
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1655 (looking-at ";"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1656 (forward-line 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1657 (not (eobp)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1658 (byte-compile-file-form (read byte-compile-inbuffer)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1659
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1660 ;; Compile pending forms at end of file.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1661 (byte-compile-flush-pending)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1662 (byte-compile-warn-about-unresolved-functions)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1663 ;; Should we always do this? When calling multiple files, it
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1664 ;; would be useful to delay this warning until all have
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1665 ;; been compiled.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1666 (setq byte-compile-unresolved-functions nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1667 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1668 (set-buffer byte-compile-outbuffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1669 (goto-char (point-min))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1670 (if (not eval)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1671 byte-compile-outbuffer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1672 (let (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1673 (while (condition-case nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1674 (progn (setq form (read byte-compile-outbuffer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1675 t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1676 (end-of-file nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1677 (eval form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1678 (kill-buffer byte-compile-outbuffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1679 nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1680
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1681 (defun byte-compile-insert-header (filename byte-compile-inbuffer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1682 byte-compile-outbuffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1683 (set-buffer byte-compile-inbuffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1684 (let ((dynamic-docstrings byte-compile-dynamic-docstrings))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1685 (set-buffer byte-compile-outbuffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1686 (goto-char 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1687 ;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1688 ;; The magic number of .elc files is ";ELC", or 0x3B454C43. After that is
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1689 ;; the file-format version number (19 or 20) as a byte, followed by some
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1690 ;; nulls. The primary motivation for doing this is to get some binary
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1691 ;; characters up in the first line of the file so that `diff' will simply
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1692 ;; say "Binary files differ" instead of actually doing a diff of two .elc
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1693 ;; files. An extra benefit is that you can add this to /etc/magic:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1694 ;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1695 ;; 0 string ;ELC GNU Emacs Lisp compiled file,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1696 ;; >4 byte x version %d
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1697 ;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1698 (insert
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1699 ";ELC"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1700 (if (byte-compile-version-cond byte-compile-emacs19-compatibility) 19 20)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1701 "\000\000\000\n"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1702 )
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1703 (insert ";;; compiled by "
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1704 (or (and (boundp 'user-mail-address) user-mail-address)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1705 (concat (user-login-name) "@" (system-name)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1706 " on "
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1707 (current-time-string) "\n;;; from file " filename "\n")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1708 (insert ";;; emacs version " emacs-version ".\n")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1709 (insert ";;; bytecomp version " byte-compile-version "\n;;; "
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1710 (cond
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1711 ((eq byte-optimize 'source) "source-level optimization only")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1712 ((eq byte-optimize 'byte) "byte-level optimization only")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1713 (byte-optimize "optimization is on")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1714 (t "optimization is off"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1715 (if (byte-compile-version-cond byte-compile-emacs19-compatibility)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1716 "; compiled with Emacs 19 compatibility.\n"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1717 ".\n"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1718 (if (not (byte-compile-version-cond byte-compile-emacs19-compatibility))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1719 (insert ";;; this file uses opcodes which do not exist in Emacs 19.\n"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1720 ;; Have to check if emacs-version is bound so that this works
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1721 ;; in files loaded early in loadup.el.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1722 "\n(if (and (boundp 'emacs-version)\n"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1723 "\t (or (and (boundp 'epoch::version) epoch::version)\n"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1724 "\t (string-lessp emacs-version \"20\")))\n"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1725 " (error \"`"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1726 ;; prin1-to-string is used to quote backslashes.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1727 (substring (prin1-to-string (file-name-nondirectory filename))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1728 1 -1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1729 "' was compiled for Emacs 20\"))\n\n"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1730 (insert "(or (boundp 'current-load-list) (setq current-load-list nil))\n"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1731 "\n")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1732 (if (and (byte-compile-version-cond byte-compile-emacs19-compatibility)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1733 dynamic-docstrings)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1734 (insert ";;; this file uses opcodes which do not exist prior to\n"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1735 ";;; XEmacs 19.14/GNU Emacs 19.29 or later."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1736 ;; Have to check if emacs-version is bound so that this works
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1737 ;; in files loaded early in loadup.el.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1738 "\n(if (and (boundp 'emacs-version)\n"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1739 "\t (or (and (boundp 'epoch::version) epoch::version)\n"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1740 "\t (and (not (string-match \"XEmacs\" emacs-version))\n"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1741 "\t (string-lessp emacs-version \"19.29\"))\n"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1742 "\t (string-lessp emacs-version \"19.14\")))\n"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1743 " (error \"`"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1744 ;; prin1-to-string is used to quote backslashes.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1745 (substring (prin1-to-string (file-name-nondirectory filename))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1746 1 -1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1747 "' was compiled for XEmacs 19.14/Emacs 19.29 or later\"))\n\n"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1748 )
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1749 ))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1750
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1751 ;; back in the inbuffer; determine and set the coding system for the .elc
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1752 ;; file if under Mule. If there are any extended characters in the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1753 ;; input file, use `escape-quoted' to make sure that both binary and
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1754 ;; extended characters are output properly and distinguished properly.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1755 ;; Otherwise, use `no-conversion' for maximum portability with non-Mule
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1756 ;; Emacsen.
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1757 (when (featurep 'mule)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1758 (defvar buffer-file-coding-system)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1759 (if (save-excursion
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1760 (set-buffer byte-compile-inbuffer)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1761 (goto-char (point-min))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1762 ;; mrb- There must be a better way than skip-chars-forward
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1763 (skip-chars-forward (concat (char-to-string 0) "-"
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1764 (char-to-string 255)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1765 (eq (point) (point-max)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1766 (setq buffer-file-coding-system 'no-conversion)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1767 (insert "(require 'mule)\n;;;###coding system: escape-quoted\n")
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1768 (setq buffer-file-coding-system 'escape-quoted)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1769 ;; #### Lazy loading not yet implemented for MULE files
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1770 ;; mrb - Fix this someday.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1771 (save-excursion
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1772 (set-buffer byte-compile-inbuffer)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1773 (setq byte-compile-dynamic nil
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1774 byte-compile-dynamic-docstrings nil))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1775 ;;(external-debugging-output (prin1-to-string (buffer-local-variables))))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1776 ))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1777 )
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1778
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1779
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1780 (defun byte-compile-output-file-form (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1781 ;; writes the given form to the output buffer, being careful of docstrings
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1782 ;; in defun, defmacro, defvar, defconst and autoload because make-docfile is
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1783 ;; so amazingly stupid.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1784 ;; defalias calls are output directly by byte-compile-file-form-defmumble;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1785 ;; it does not pay to first build the defalias in defmumble and then parse
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1786 ;; it here.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1787 (if (and (memq (car-safe form) '(defun defmacro defvar defconst autoload))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1788 (stringp (nth 3 form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1789 (byte-compile-output-docform nil nil '("\n(" 3 ")") form nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1790 (eq (car form) 'autoload))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1791 (let ((print-escape-newlines t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1792 (print-length nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1793 (print-level nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1794 (print-readably t) ; print #[] for bytecode, 'x for (quote x)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1795 (print-gensym (if (and byte-compile-print-gensym
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1796 (not byte-compile-emacs19-compatibility))
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1797 t nil)))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1798 (princ "\n" byte-compile-outbuffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1799 (prin1 form byte-compile-outbuffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1800 nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1801
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1802 (defun byte-compile-output-docform (preface name info form specindex quoted)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1803 "Print a form with a doc string. INFO is (prefix doc-index postfix).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1804 If PREFACE and NAME are non-nil, print them too,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1805 before INFO and the FORM but after the doc string itself.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1806 If SPECINDEX is non-nil, it is the index in FORM
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1807 of the function bytecode string. In that case,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1808 we output that argument and the following argument (the constants vector)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1809 together, for lazy loading.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1810 QUOTED says that we have to put a quote before the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1811 list that represents a doc string reference.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1812 `autoload' needs that."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1813 ;; We need to examine byte-compile-dynamic-docstrings
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1814 ;; in the input buffer (now current), not in the output buffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1815 (let ((dynamic-docstrings byte-compile-dynamic-docstrings))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1816 (set-buffer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1817 (prog1 (current-buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1818 (set-buffer byte-compile-outbuffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1819 (let (position)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1820
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1821 ;; Insert the doc string, and make it a comment with #@LENGTH.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1822 (and (>= (nth 1 info) 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1823 dynamic-docstrings
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1824 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1825 ;; Make the doc string start at beginning of line
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1826 ;; for make-docfile's sake.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1827 (insert "\n")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1828 (setq position
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1829 (byte-compile-output-as-comment
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1830 (nth (nth 1 info) form) nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1831 ;; If the doc string starts with * (a user variable),
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1832 ;; negate POSITION.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1833 (if (and (stringp (nth (nth 1 info) form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1834 (> (length (nth (nth 1 info) form)) 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1835 (char= (aref (nth (nth 1 info) form) 0) ?*))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1836 (setq position (- position)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1837
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1838 (if preface
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1839 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1840 (insert preface)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1841 (prin1 name byte-compile-outbuffer)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1842 (insert (car info))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1843 (let ((print-escape-newlines t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1844 (print-readably t) ; print #[] for bytecode, 'x for (quote x)
245
51092a27c943 Import from CVS: tag r20-5b21
cvs
parents: 209
diff changeset
1845 ;; Use a cons cell to say that we want
51092a27c943 Import from CVS: tag r20-5b21
cvs
parents: 209
diff changeset
1846 ;; print-gensym-alist not to be cleared between calls
51092a27c943 Import from CVS: tag r20-5b21
cvs
parents: 209
diff changeset
1847 ;; to print functions.
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1848 (print-gensym (if (and byte-compile-print-gensym
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1849 (not byte-compile-emacs19-compatibility))
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1850 '(t) nil))
245
51092a27c943 Import from CVS: tag r20-5b21
cvs
parents: 209
diff changeset
1851 print-gensym-alist
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1852 (index 0))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1853 (prin1 (car form) byte-compile-outbuffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1854 (while (setq form (cdr form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1855 (setq index (1+ index))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1856 (insert " ")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1857 (cond ((and (numberp specindex) (= index specindex))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1858 (let ((position
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1859 (byte-compile-output-as-comment
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1860 (cons (car form) (nth 1 form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1861 t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1862 (princ (format "(#$ . %d) nil" position)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1863 byte-compile-outbuffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1864 (setq form (cdr form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1865 (setq index (1+ index))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1866 ((= index (nth 1 info))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1867 (if position
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1868 (princ (format (if quoted "'(#$ . %d)" "(#$ . %d)")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1869 position)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1870 byte-compile-outbuffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1871 (let ((print-escape-newlines nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1872 (goto-char (prog1 (1+ (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1873 (prin1 (car form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1874 byte-compile-outbuffer)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1875 (insert "\\\n")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1876 (goto-char (point-max)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1877 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1878 (prin1 (car form) byte-compile-outbuffer)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1879 (insert (nth 2 info))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1880 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1881
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1882 (defvar for-effect) ; ## Kludge! This should be an arg, not a special.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1883
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1884 (defun byte-compile-keep-pending (form &optional handler)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1885 (if (memq byte-optimize '(t source))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1886 (setq form (byte-optimize-form form t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1887 (if handler
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1888 (let ((for-effect t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1889 ;; To avoid consing up monstrously large forms at load time, we split
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1890 ;; the output regularly.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1891 (and (memq (car-safe form) '(fset defalias define-function))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1892 (nthcdr 300 byte-compile-output)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1893 (byte-compile-flush-pending))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1894 (funcall handler form)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1895 (when for-effect
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1896 (byte-compile-discard)))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1897 (byte-compile-form form t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1898 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1899
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1900 (defun byte-compile-flush-pending ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1901 (if byte-compile-output
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1902 (let ((form (byte-compile-out-toplevel t 'file)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1903 (cond ((eq (car-safe form) 'progn)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1904 (mapcar 'byte-compile-output-file-form (cdr form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1905 (form
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1906 (byte-compile-output-file-form form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1907 (setq byte-compile-constants nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1908 byte-compile-variables nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1909 byte-compile-depth 0
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1910 byte-compile-maxdepth 0
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1911 byte-compile-output nil))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1912
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1913 (defun byte-compile-file-form (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1914 (let ((byte-compile-current-form nil) ; close over this for warnings.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1915 handler)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1916 (cond
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1917 ((not (consp form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1918 (byte-compile-keep-pending form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1919 ((and (symbolp (car form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1920 (setq handler (get (car form) 'byte-hunk-handler)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1921 (cond ((setq form (funcall handler form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1922 (byte-compile-flush-pending)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1923 (byte-compile-output-file-form form))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1924 ((eq form (setq form (macroexpand form byte-compile-macro-environment)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1925 (byte-compile-keep-pending form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1926 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1927 (byte-compile-file-form form)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1928
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1929 ;; Functions and variables with doc strings must be output separately,
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1930 ;; so make-docfile can recognize them. Most other things can be output
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1931 ;; as byte-code.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1932
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1933 (put 'defsubst 'byte-hunk-handler 'byte-compile-file-form-defsubst)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1934 (defun byte-compile-file-form-defsubst (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1935 (cond ((assq (nth 1 form) byte-compile-unresolved-functions)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1936 (setq byte-compile-current-form (nth 1 form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1937 (byte-compile-warn "defsubst %s was used before it was defined"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1938 (nth 1 form))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1939 (byte-compile-file-form
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1940 (macroexpand form byte-compile-macro-environment))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1941 ;; Return nil so the form is not output twice.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1942 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1943
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1944 (put 'autoload 'byte-hunk-handler 'byte-compile-file-form-autoload)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1945 (defun byte-compile-file-form-autoload (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1946 ;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1947 ;; If this is an autoload of a macro, and all arguments are constants (that
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1948 ;; is, there is no hairy computation going on here) then evaluate the form
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1949 ;; at compile-time. This is so that we can make use of macros which we
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1950 ;; have autoloaded from the file being compiled. Normal function autoloads
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1951 ;; are not automatically evaluated at compile time, because there's not
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1952 ;; much point to it (so why bother cluttering up the compile-time namespace.)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1953 ;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1954 ;; If this is an autoload of a function, then record its definition in the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1955 ;; byte-compile-autoload-environment to suppress any `not known to be
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1956 ;; defined' warnings at the end of this file (this only matters for
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1957 ;; functions which are autoloaded and compiled in the same file, if the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1958 ;; autoload already exists in the compilation environment, we wouldn't have
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1959 ;; warned anyway.)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1960 ;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1961 (let* ((name (if (byte-compile-constp (nth 1 form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1962 (eval (nth 1 form))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1963 ;; In v19, the 5th arg to autoload can be t, nil, 'macro, or 'keymap.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1964 (macrop (and (byte-compile-constp (nth 5 form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1965 (memq (eval (nth 5 form)) '(t macro))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1966 ;; (functionp (and (byte-compile-constp (nth 5 form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1967 ;; (eq 'nil (eval (nth 5 form)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1968 )
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1969 (if (and macrop
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1970 (let ((form form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1971 ;; all forms are constant
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1972 (while (if (setq form (cdr form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1973 (byte-compile-constp (car form))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1974 (null form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1975 ;; eval the macro autoload into the compilation enviroment
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1976 (eval form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1977
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1978 (if name
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1979 (let ((old (assq name byte-compile-autoload-environment)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1980 (cond (old
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1981 (if (memq 'redefine byte-compile-warnings)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1982 (byte-compile-warn "multiple autoloads for %s" name))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1983 (setcdr old form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1984 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1985 ;; We only use the names in the autoload environment, but
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1986 ;; it might be useful to have the bodies some day.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1987 (setq byte-compile-autoload-environment
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1988 (cons (cons name form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1989 byte-compile-autoload-environment)))))))
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
1990 ;;
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1991 ;; Now output the form.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1992 (if (stringp (nth 3 form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1993 form
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1994 ;; No doc string, so we can compile this as a normal form.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1995 (byte-compile-keep-pending form 'byte-compile-normal-call)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1996
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
1997 (put 'defvar 'byte-hunk-handler 'byte-compile-file-form-defvar)
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
1998 (put 'defconst 'byte-hunk-handler 'byte-compile-file-form-defvar)
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
1999 (defun byte-compile-file-form-defvar (form)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2000 (if (> (length form) 4)
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
2001 (byte-compile-warn "%s used with too many args (%s)"
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
2002 (car form) (nth 1 form)))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2003 (if (and (> (length form) 3) (not (stringp (nth 3 form))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2004 (byte-compile-warn "Third arg to %s %s is not a string: %s"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2005 (car form) (nth 1 form) (nth 3 form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2006 (if (null (nth 3 form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2007 ;; Since there is no doc string, we can compile this as a normal form,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2008 ;; and not do a file-boundary.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2009 (byte-compile-keep-pending form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2010 (if (memq 'free-vars byte-compile-warnings)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2011 (setq byte-compile-bound-variables
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2012 (cons (cons (nth 1 form) byte-compile-global-bit)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2013 byte-compile-bound-variables)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2014 (cond ((consp (nth 2 form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2015 (setq form (copy-sequence form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2016 (setcar (cdr (cdr form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2017 (byte-compile-top-level (nth 2 form) nil 'file))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2018
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2019 ;; The following turns out not to be necessary, since we emit a call to
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2020 ;; defvar, which can hack Vfile_domain by itself!
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2021 ;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2022 ;; If a file domain has been set, emit (put 'VAR 'variable-domain ...)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2023 ;; after this defvar.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2024 ; (if byte-compile-file-domain
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2025 ; (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2026 ; ;; Actually, this will emit the (put ...) before the (defvar ...)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2027 ; ;; but I don't think that can matter in this case.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2028 ; (byte-compile-keep-pending
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2029 ; (list 'put (list 'quote (nth 1 form)) ''variable-domain
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2030 ; (list 'quote byte-compile-file-domain)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2031 form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2032
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2033 (put 'require 'byte-hunk-handler 'byte-compile-file-form-eval-boundary)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2034 (defun byte-compile-file-form-eval-boundary (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2035 (eval form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2036 (byte-compile-keep-pending form 'byte-compile-normal-call))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2037
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2038 (put 'progn 'byte-hunk-handler 'byte-compile-file-form-progn)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2039 (put 'prog1 'byte-hunk-handler 'byte-compile-file-form-progn)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2040 (put 'prog2 'byte-hunk-handler 'byte-compile-file-form-progn)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2041 (defun byte-compile-file-form-progn (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2042 (mapcar 'byte-compile-file-form (cdr form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2043 ;; Return nil so the forms are not output twice.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2044 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2045
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2046 ;; This handler is not necessary, but it makes the output from dont-compile
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2047 ;; and similar macros cleaner.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2048 (put 'eval 'byte-hunk-handler 'byte-compile-file-form-eval)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2049 (defun byte-compile-file-form-eval (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2050 (if (eq (car-safe (nth 1 form)) 'quote)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2051 (nth 1 (nth 1 form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2052 (byte-compile-keep-pending form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2053
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2054 (put 'defun 'byte-hunk-handler 'byte-compile-file-form-defun)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2055 (defun byte-compile-file-form-defun (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2056 (byte-compile-file-form-defmumble form nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2057
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2058 (put 'defmacro 'byte-hunk-handler 'byte-compile-file-form-defmacro)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2059 (defun byte-compile-file-form-defmacro (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2060 (byte-compile-file-form-defmumble form t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2061
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2062 (defun byte-compile-compiled-obj-to-list (obj)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2063 ;; #### this is fairly disgusting. Rewrite the code instead
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2064 ;; so that it doesn't create compiled objects in the first place!
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2065 ;; Much better than creating them and then "uncreating" them
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2066 ;; like this.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2067 (read (concat "("
245
51092a27c943 Import from CVS: tag r20-5b21
cvs
parents: 209
diff changeset
2068 (substring (let ((print-readably t)
51092a27c943 Import from CVS: tag r20-5b21
cvs
parents: 209
diff changeset
2069 (print-gensym
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
2070 (if (and byte-compile-print-gensym
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
2071 (not byte-compile-emacs19-compatibility))
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
2072 '(t) nil))
245
51092a27c943 Import from CVS: tag r20-5b21
cvs
parents: 209
diff changeset
2073 (print-gensym-alist nil))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2074 (prin1-to-string obj))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2075 2 -1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2076 ")")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2077
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2078 (defun byte-compile-file-form-defmumble (form macrop)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2079 (let* ((name (car (cdr form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2080 (this-kind (if macrop 'byte-compile-macro-environment
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2081 'byte-compile-function-environment))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2082 (that-kind (if macrop 'byte-compile-function-environment
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2083 'byte-compile-macro-environment))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2084 (this-one (assq name (symbol-value this-kind)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2085 (that-one (assq name (symbol-value that-kind)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2086 (byte-compile-free-references nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2087 (byte-compile-free-assignments nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2088
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2089 ;; When a function or macro is defined, add it to the call tree so that
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2090 ;; we can tell when functions are not used.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2091 (if byte-compile-generate-call-tree
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2092 (or (assq name byte-compile-call-tree)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2093 (setq byte-compile-call-tree
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2094 (cons (list name nil nil) byte-compile-call-tree))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2095
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2096 (setq byte-compile-current-form name) ; for warnings
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2097 (when (memq 'redefine byte-compile-warnings)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2098 (byte-compile-arglist-warn form macrop))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2099 (defvar filename) ; #### filename used free
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2100 (when byte-compile-verbose
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2101 (message "Compiling %s... (%s)"
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2102 (if filename (file-name-nondirectory filename) "")
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2103 (nth 1 form)))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2104 (cond (that-one
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2105 (when (and (memq 'redefine byte-compile-warnings)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2106 ;; hack hack: don't warn when compiling the stubs in
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2107 ;; bytecomp-runtime...
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2108 (not (assq (nth 1 form)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2109 byte-compile-initial-macro-environment)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2110 (byte-compile-warn
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2111 "%s defined multiple times, as both function and macro"
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2112 (nth 1 form)))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2113 (setcdr that-one nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2114 (this-one
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2115 (when (and (memq 'redefine byte-compile-warnings)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2116 ;; hack: don't warn when compiling the magic internal
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2117 ;; byte-compiler macros in bytecomp-runtime.el...
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2118 (not (assq (nth 1 form)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2119 byte-compile-initial-macro-environment)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2120 (byte-compile-warn "%s %s defined multiple times in this file"
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2121 (if macrop "macro" "function")
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2122 (nth 1 form))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2123 ((and (fboundp name)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2124 (or (subrp (symbol-function name))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2125 (eq (car-safe (symbol-function name))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2126 (if macrop 'lambda 'macro))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2127 (if (memq 'redefine byte-compile-warnings)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2128 (byte-compile-warn "%s %s being redefined as a %s"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2129 (if (subrp (symbol-function name))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2130 "subr"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2131 (if macrop "function" "macro"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2132 (nth 1 form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2133 (if macrop "macro" "function")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2134 ;; shadow existing definition
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2135 (set this-kind
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2136 (cons (cons name nil) (symbol-value this-kind)))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2137 (let ((body (nthcdr 3 form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2138 (if (and (stringp (car body))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2139 (symbolp (car-safe (cdr-safe body)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2140 (car-safe (cdr-safe body))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2141 (stringp (car-safe (cdr-safe (cdr-safe body)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2142 (byte-compile-warn "Probable `\"' without `\\' in doc string of %s"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2143 (nth 1 form))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2144 (let* ((new-one (byte-compile-lambda (cons 'lambda (nthcdr 2 form))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2145 (code (byte-compile-byte-code-maker new-one)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2146 (if this-one
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2147 (setcdr this-one new-one)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2148 (set this-kind
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2149 (cons (cons name new-one) (symbol-value this-kind))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2150 (if (and (stringp (nth 3 form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2151 (eq 'quote (car-safe code))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2152 (eq 'lambda (car-safe (nth 1 code))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2153 (cons (car form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2154 (cons name (cdr (nth 1 code))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2155 (byte-compile-flush-pending)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2156 (if (not (stringp (nth 3 form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2157 ;; No doc string. Provide -1 as the "doc string index"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2158 ;; so that no element will be treated as a doc string.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2159 (byte-compile-output-docform
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2160 "\n(defalias '"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2161 name
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2162 (cond ((atom code)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2163 (if macrop '(" '(macro . #[" -1 "])") '(" #[" -1 "]")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2164 ((eq (car code) 'quote)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2165 (setq code new-one)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2166 (if macrop '(" '(macro " -1 ")") '(" '(" -1 ")")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2167 ((if macrop '(" (cons 'macro (" -1 "))") '(" (" -1 ")"))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2168 ;; FSF just calls `(append code nil)' here but that relies
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2169 ;; on horrible C kludges in concat() that accept byte-
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2170 ;; compiled objects and pretend they're vectors.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2171 (if (compiled-function-p code)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2172 (byte-compile-compiled-obj-to-list code)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2173 (append code nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2174 (and (atom code) byte-compile-dynamic
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2175 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2176 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2177 ;; Output the form by hand, that's much simpler than having
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2178 ;; b-c-output-file-form analyze the defalias.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2179 (byte-compile-output-docform
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2180 "\n(defalias '"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2181 name
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2182 (cond ((atom code) ; compiled-function-p
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2183 (if macrop '(" '(macro . #[" 4 "])") '(" #[" 4 "]")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2184 ((eq (car code) 'quote)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2185 (setq code new-one)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2186 (if macrop '(" '(macro " 2 ")") '(" '(" 2 ")")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2187 ((if macrop '(" (cons 'macro (" 5 "))") '(" (" 5 ")"))))
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
2188 ;; The result of byte-compile-byte-code-maker is either a
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2189 ;; compiled-function object, or a list of some kind. If it's
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2190 ;; not a cons, we must coerce it into a list of the elements
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2191 ;; to be printed to the file.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2192 (if (consp code)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2193 code
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2194 (nconc (list
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2195 (compiled-function-arglist code)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2196 (compiled-function-instructions code)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2197 (compiled-function-constants code)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2198 (compiled-function-stack-depth code))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2199 (let ((doc (documentation code t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2200 (if doc (list doc)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2201 (if (commandp code)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2202 (list (nth 1 (compiled-function-interactive code))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2203 (and (atom code) byte-compile-dynamic
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2204 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2205 nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2206 (princ ")" byte-compile-outbuffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2207 nil))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2208
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2209 ;; Print Lisp object EXP in the output file, inside a comment,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2210 ;; and return the file position it will have.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2211 ;; If QUOTED is non-nil, print with quoting; otherwise, print without quoting.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2212 (defun byte-compile-output-as-comment (exp quoted)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2213 (let ((position (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2214 (set-buffer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2215 (prog1 (current-buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2216 (set-buffer byte-compile-outbuffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2217
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2218 ;; Insert EXP, and make it a comment with #@LENGTH.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2219 (insert " ")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2220 (if quoted
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2221 (prin1 exp byte-compile-outbuffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2222 (princ exp byte-compile-outbuffer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2223 (goto-char position)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2224 ;; Quote certain special characters as needed.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2225 ;; get_doc_string in doc.c does the unquoting.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2226 (while (search-forward "\^A" nil t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2227 (replace-match "\^A\^A" t t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2228 (goto-char position)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2229 (while (search-forward "\000" nil t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2230 (replace-match "\^A0" t t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2231 (goto-char position)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2232 (while (search-forward "\037" nil t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2233 (replace-match "\^A_" t t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2234 (goto-char (point-max))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2235 (insert "\037")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2236 (goto-char position)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2237 (insert "#@" (format "%d" (- (point-max) position)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2238
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2239 ;; Save the file position of the object.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2240 ;; Note we should add 1 to skip the space
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2241 ;; that we inserted before the actual doc string,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2242 ;; and subtract 1 to convert from an 1-origin Emacs position
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2243 ;; to a file position; they cancel.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2244 (setq position (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2245 (goto-char (point-max))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2246 position))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2247
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2248
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2249
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2250 ;; The `domain' declaration. This is legal only at top-level in a file, and
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2251 ;; should generally be the first form in the file. It is not legal inside
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2252 ;; function bodies.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2253
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2254 (put 'domain 'byte-hunk-handler 'byte-compile-file-form-domain)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2255 (defun byte-compile-file-form-domain (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2256 (if (not (null (cdr (cdr form))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2257 (byte-compile-warn "domain used with too many arguments: %s" form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2258 (let ((domain (nth 1 form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2259 (or (null domain)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2260 (stringp domain)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2261 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2262 (byte-compile-warn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2263 "argument to `domain' declaration must be a literal string: %s"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2264 form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2265 (setq domain nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2266 (setq byte-compile-file-domain domain))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2267 (byte-compile-keep-pending form 'byte-compile-normal-call))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2268
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2269 (defun byte-compile-domain (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2270 (byte-compile-warn "The `domain' declaration is legal only at top-level: %s"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2271 (let ((print-escape-newlines t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2272 (print-level 4)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2273 (print-length 4))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2274 (prin1-to-string form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2275 (byte-compile-normal-call
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2276 (list 'signal ''error
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2277 (list 'quote (list "`domain' used inside a function" form)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2278
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2279 ;; This is part of bytecomp.el in 19.35:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2280 (put 'custom-declare-variable 'byte-hunk-handler
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2281 'byte-compile-file-form-custom-declare-variable)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2282 (defun byte-compile-file-form-custom-declare-variable (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2283 (if (memq 'free-vars byte-compile-warnings)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2284 (setq byte-compile-bound-variables
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2285 (cons (cons (nth 1 (nth 1 form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2286 byte-compile-global-bit)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2287 byte-compile-bound-variables)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2288 form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2289
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2290
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2291 ;;;###autoload
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2292 (defun byte-compile (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2293 "If FORM is a symbol, byte-compile its function definition.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2294 If FORM is a lambda or a macro, byte-compile it as a function."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2295 (displaying-byte-compile-warnings
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2296 (byte-compile-close-variables
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2297 (let* ((fun (if (symbolp form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2298 (and (fboundp form) (symbol-function form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2299 form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2300 (macro (eq (car-safe fun) 'macro)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2301 (if macro
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2302 (setq fun (cdr fun)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2303 (cond ((eq (car-safe fun) 'lambda)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2304 (setq fun (if macro
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2305 (cons 'macro (byte-compile-lambda fun))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2306 (byte-compile-lambda fun)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2307 (if (symbolp form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2308 (defalias form fun)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2309 fun)))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2310
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2311 ;;;###autoload
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2312 (defun byte-compile-sexp (sexp &optional msg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2313 "Compile and return SEXP."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2314 (displaying-byte-compile-warnings
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2315 (byte-compile-close-variables
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2316 (prog1
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2317 (byte-compile-top-level sexp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2318 (byte-compile-warn-about-unresolved-functions msg)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2319
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2320 ;; Given a function made by byte-compile-lambda, make a form which produces it.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2321 (defun byte-compile-byte-code-maker (fun)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2322 (cond
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2323 ;; ## atom is faster than compiled-func-p.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2324 ((atom fun) ; compiled-function-p
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2325 fun)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2326 ;; b-c-lambda didn't produce a compiled-function, so it must be a trivial
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2327 ;; function.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2328 ((let (tmp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2329 (if (and (setq tmp (assq 'byte-code (cdr-safe (cdr fun))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2330 (null (cdr (memq tmp fun))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2331 ;; Generate a make-byte-code call.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2332 (let* ((interactive (assq 'interactive (cdr (cdr fun)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2333 (nconc (list 'make-byte-code
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2334 (list 'quote (nth 1 fun)) ;arglist
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2335 (nth 1 tmp) ;instructions
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2336 (nth 2 tmp) ;constants
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2337 (nth 3 tmp)) ;stack-depth
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2338 (cond ((stringp (nth 2 fun))
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2339 (list (nth 2 fun))) ;docstring
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2340 (interactive
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2341 (list nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2342 (cond (interactive
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2343 (list (if (or (null (nth 1 interactive))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2344 (stringp (nth 1 interactive)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2345 (nth 1 interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2346 ;; Interactive spec is a list or a variable
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2347 ;; (if it is correct).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2348 (list 'quote (nth 1 interactive))))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2349 ;; a non-compiled function (probably trivial)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2350 (list 'quote fun))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2351
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2352 ;; Byte-compile a lambda-expression and return a valid function.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2353 ;; The value is usually a compiled function but may be the original
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2354 ;; lambda-expression.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2355 (defun byte-compile-lambda (fun)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2356 (or (eq 'lambda (car-safe fun))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2357 (error "not a lambda -- %s" (prin1-to-string fun)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2358 (let* ((arglist (nth 1 fun))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2359 (byte-compile-bound-variables
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2360 (let ((new-bindings
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2361 (mapcar #'(lambda (x) (cons x byte-compile-arglist-bit))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2362 (and (memq 'free-vars byte-compile-warnings)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2363 (delq '&rest (delq '&optional
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2364 (copy-sequence arglist)))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2365 (nconc new-bindings
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2366 (cons 'new-scope byte-compile-bound-variables))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2367 (body (cdr (cdr fun)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2368 (doc (if (stringp (car body))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2369 (prog1 (car body)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2370 (setq body (cdr body)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2371 (int (assq 'interactive body)))
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2372 (dolist (arg arglist)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2373 (cond ((not (symbolp arg))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2374 (byte-compile-warn "non-symbol in arglist: %S" arg))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2375 ((byte-compile-constant-symbol-p arg)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2376 (byte-compile-warn "constant symbol in arglist: %s" arg))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2377 ((and (char= ?\& (aref (symbol-name arg) 0))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2378 (not (eq arg '&optional))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2379 (not (eq arg '&rest)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2380 (byte-compile-warn "unrecognized `&' keyword in arglist: %s"
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2381 arg))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2382 (cond (int
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2383 ;; Skip (interactive) if it is in front (the most usual location).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2384 (if (eq int (car body))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2385 (setq body (cdr body)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2386 (cond ((consp (cdr int))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2387 (if (cdr (cdr int))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2388 (byte-compile-warn "malformed interactive spec: %s"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2389 (prin1-to-string int)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2390 ;; If the interactive spec is a call to `list',
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2391 ;; don't compile it, because `call-interactively'
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2392 ;; looks at the args of `list'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2393 (let ((form (nth 1 int)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2394 (while (or (eq (car-safe form) 'let)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2395 (eq (car-safe form) 'let*)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2396 (eq (car-safe form) 'save-excursion))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2397 (while (consp (cdr form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2398 (setq form (cdr form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2399 (setq form (car form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2400 (or (eq (car-safe form) 'list)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2401 (setq int (list 'interactive
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2402 (byte-compile-top-level (nth 1 int)))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2403 ((cdr int)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2404 (byte-compile-warn "malformed interactive spec: %s"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2405 (prin1-to-string int))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2406 (let ((compiled (byte-compile-top-level (cons 'progn body) nil 'lambda)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2407 (if (memq 'unused-vars byte-compile-warnings)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2408 ;; done compiling in this scope, warn now.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2409 (byte-compile-warn-about-unused-variables))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2410 (if (eq 'byte-code (car-safe compiled))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2411 (apply 'make-byte-code
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2412 (append (list arglist)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2413 ;; byte-string, constants-vector, stack depth
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2414 (cdr compiled)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2415 ;; optionally, the doc string.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2416 (if (or doc int)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2417 (list doc))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2418 ;; optionally, the interactive spec.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2419 (if int
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2420 (list (nth 1 int)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2421 (setq compiled
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2422 (nconc (if int (list int))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2423 (cond ((eq (car-safe compiled) 'progn) (cdr compiled))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2424 (compiled (list compiled)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2425 (nconc (list 'lambda arglist)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2426 (if (or doc (stringp (car compiled)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2427 (cons doc (cond (compiled)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2428 (body (list nil))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2429 compiled))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2430
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2431 (defun byte-compile-constants-vector ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2432 ;; Builds the constants-vector from the current variables and constants.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2433 ;; This modifies the constants from (const . nil) to (const . offset).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2434 ;; To keep the byte-codes to look up the vector as short as possible:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2435 ;; First 6 elements are vars, as there are one-byte varref codes for those.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2436 ;; Next up to byte-constant-limit are constants, still with one-byte codes.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2437 ;; Next variables again, to get 2-byte codes for variable lookup.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2438 ;; The rest of the constants and variables need 3-byte byte-codes.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2439 (let* ((i -1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2440 (rest (nreverse byte-compile-variables)) ; nreverse because the first
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2441 (other (nreverse byte-compile-constants)) ; vars often are used most.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2442 ret tmp
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2443 (limits '(5 ; Use the 1-byte varref codes,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2444 63 ; 1-constlim ; 1-byte byte-constant codes,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2445 255 ; 2-byte varref codes,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2446 65535)) ; 3-byte codes for the rest.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2447 limit)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2448 (while (or rest other)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2449 (setq limit (car limits))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2450 (while (and rest (not (eq i limit)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2451 (if (setq tmp (assq (car (car rest)) ret))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2452 (setcdr (car rest) (cdr tmp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2453 (setcdr (car rest) (setq i (1+ i)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2454 (setq ret (cons (car rest) ret)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2455 (setq rest (cdr rest)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2456 (setq limits (cdr limits)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2457 rest (prog1 other
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2458 (setq other rest))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2459 (apply 'vector (nreverse (mapcar 'car ret)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2460
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2461 ;; Given an expression FORM, compile it and return an equivalent byte-code
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2462 ;; expression (a call to the function byte-code).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2463 (defun byte-compile-top-level (form &optional for-effect output-type)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2464 ;; OUTPUT-TYPE advises about how form is expected to be used:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2465 ;; 'eval or nil -> a single form,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2466 ;; 'progn or t -> a list of forms,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2467 ;; 'lambda -> body of a lambda,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2468 ;; 'file -> used at file-level.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2469 (let ((byte-compile-constants nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2470 (byte-compile-variables nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2471 (byte-compile-tag-number 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2472 (byte-compile-depth 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2473 (byte-compile-maxdepth 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2474 (byte-compile-output nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2475 (if (memq byte-optimize '(t source))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2476 (setq form (byte-optimize-form form for-effect)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2477 (while (and (eq (car-safe form) 'progn) (null (cdr (cdr form))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2478 (setq form (nth 1 form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2479 (if (and (eq 'byte-code (car-safe form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2480 (not (memq byte-optimize '(t byte)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2481 (stringp (nth 1 form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2482 (vectorp (nth 2 form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2483 (natnump (nth 3 form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2484 form
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2485 (byte-compile-form form for-effect)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2486 (byte-compile-out-toplevel for-effect output-type))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2487
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2488 (defun byte-compile-out-toplevel (&optional for-effect output-type)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2489 (if for-effect
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2490 ;; The stack is empty. Push a value to be returned from (byte-code ..).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2491 (if (eq (car (car byte-compile-output)) 'byte-discard)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2492 (setq byte-compile-output (cdr byte-compile-output))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2493 (byte-compile-push-constant
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2494 ;; Push any constant - preferably one which already is used, and
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2495 ;; a number or symbol - ie not some big sequence. The return value
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2496 ;; isn't returned, but it would be a shame if some textually large
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2497 ;; constant was not optimized away because we chose to return it.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2498 (and (not (assq nil byte-compile-constants)) ; Nil is often there.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2499 (let ((tmp (reverse byte-compile-constants)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2500 (while (and tmp (not (or (symbolp (car (car tmp)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2501 (numberp (car (car tmp))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2502 (setq tmp (cdr tmp)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2503 (car (car tmp)))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2504 (byte-compile-out 'byte-return 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2505 (setq byte-compile-output (nreverse byte-compile-output))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2506 (if (memq byte-optimize '(t byte))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2507 (setq byte-compile-output
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2508 (byte-optimize-lapcode byte-compile-output for-effect)))
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
2509
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2510 ;; Decompile trivial functions:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2511 ;; only constants and variables, or a single funcall except in lambdas.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2512 ;; Except for Lisp_Compiled objects, forms like (foo "hi")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2513 ;; are still quicker than (byte-code "..." [foo "hi"] 2).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2514 ;; Note that even (quote foo) must be parsed just as any subr by the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2515 ;; interpreter, so quote should be compiled into byte-code in some contexts.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2516 ;; What to leave uncompiled:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2517 ;; lambda -> never. we used to leave it uncompiled if the body was
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2518 ;; a single atom, but that causes confusion if the docstring
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2519 ;; uses the (file . pos) syntax. Besides, now that we have
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2520 ;; the Lisp_Compiled type, the compiled form is faster.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2521 ;; eval -> atom, quote or (function atom atom atom)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2522 ;; progn -> as <<same-as-eval>> or (progn <<same-as-eval>> atom)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2523 ;; file -> as progn, but takes both quotes and atoms, and longer forms.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2524 (let (rest
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2525 (maycall (not (eq output-type 'lambda))) ; t if we may make a funcall.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2526 tmp body)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2527 (cond
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2528 ;; #### This should be split out into byte-compile-nontrivial-function-p.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2529 ((or (eq output-type 'lambda)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2530 (nthcdr (if (eq output-type 'file) 50 8) byte-compile-output)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2531 (assq 'TAG byte-compile-output) ; Not necessary, but speeds up a bit.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2532 (not (setq tmp (assq 'byte-return byte-compile-output)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2533 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2534 (setq rest (nreverse
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2535 (cdr (memq tmp (reverse byte-compile-output)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2536 (while (cond
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2537 ((memq (car (car rest)) '(byte-varref byte-constant))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2538 (setq tmp (car (cdr (car rest))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2539 (if (if (eq (car (car rest)) 'byte-constant)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2540 (or (consp tmp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2541 (and (symbolp tmp)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2542 (not (byte-compile-constant-symbol-p tmp)))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2543 (if maycall
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2544 (setq body (cons (list 'quote tmp) body)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2545 (setq body (cons tmp body))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2546 ((and maycall
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2547 ;; Allow a funcall if at most one atom follows it.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2548 (null (nthcdr 3 rest))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2549 (setq tmp
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2550 ;; XEmacs change for rms funs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2551 (or (and
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2552 (byte-compile-version-cond
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2553 byte-compile-emacs19-compatibility)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2554 (get (car (car rest))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2555 'byte-opcode19-invert))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2556 (get (car (car rest))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2557 'byte-opcode-invert)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2558 (or (null (cdr rest))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2559 (and (memq output-type '(file progn t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2560 (cdr (cdr rest))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2561 (eq (car (nth 1 rest)) 'byte-discard)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2562 (progn (setq rest (cdr rest)) t))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2563 (setq maycall nil) ; Only allow one real function call.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2564 (setq body (nreverse body))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2565 (setq body (list
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2566 (if (and (eq tmp 'funcall)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2567 (eq (car-safe (car body)) 'quote))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2568 (cons (nth 1 (car body)) (cdr body))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2569 (cons tmp body))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2570 (or (eq output-type 'file)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2571 (not (delq nil (mapcar 'consp (cdr (car body))))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2572 (setq rest (cdr rest)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2573 rest))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2574 (let ((byte-compile-vector (byte-compile-constants-vector)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2575 (list 'byte-code (byte-compile-lapcode byte-compile-output)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2576 byte-compile-vector byte-compile-maxdepth)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2577 ;; it's a trivial function
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2578 ((cdr body) (cons 'progn (nreverse body)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2579 ((car body)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2580
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2581 ;; Given BODY, compile it and return a new body.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2582 (defun byte-compile-top-level-body (body &optional for-effect)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2583 (setq body (byte-compile-top-level (cons 'progn body) for-effect t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2584 (cond ((eq (car-safe body) 'progn)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2585 (cdr body))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2586 (body
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2587 (list body))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2588
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
2589 ;; This is the recursive entry point for compiling each subform of an
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2590 ;; expression.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2591 ;; If for-effect is non-nil, byte-compile-form will output a byte-discard
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2592 ;; before terminating (ie. no value will be left on the stack).
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2593 ;; A byte-compile handler may, when for-effect is non-nil, choose output code
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2594 ;; which does not leave a value on the stack, and then set for-effect to nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2595 ;; (to prevent byte-compile-form from outputting the byte-discard).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2596 ;; If a handler wants to call another handler, it should do so via
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2597 ;; byte-compile-form, or take extreme care to handle for-effect correctly.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2598 ;; (Use byte-compile-form-do-effect to reset the for-effect flag too.)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2599 ;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2600 (defun byte-compile-form (form &optional for-effect)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2601 (setq form (macroexpand form byte-compile-macro-environment))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2602 (cond ((not (consp form))
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2603 (cond ((or (not (symbolp form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2604 (byte-compile-constant-symbol-p form))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2605 (byte-compile-constant form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2606 ((and for-effect byte-compile-delete-errors)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2607 (setq for-effect nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2608 (t (byte-compile-variable-ref 'byte-varref form))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2609 ((symbolp (car form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2610 (let* ((fn (car form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2611 (handler (get fn 'byte-compile)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2612 (if (memq fn '(t nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2613 (byte-compile-warn "%s called as a function" fn))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2614 (if (and handler
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2615 (or (not (byte-compile-version-cond
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2616 byte-compile-emacs19-compatibility))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2617 (not (get (get fn 'byte-opcode) 'emacs20-opcode))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2618 (funcall handler form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2619 (if (memq 'callargs byte-compile-warnings)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2620 (byte-compile-callargs-warn form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2621 (byte-compile-normal-call form))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2622 ((and (or (compiled-function-p (car form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2623 (eq (car-safe (car form)) 'lambda))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2624 ;; if the form comes out the same way it went in, that's
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2625 ;; because it was malformed, and we couldn't unfold it.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2626 (not (eq form (setq form (byte-compile-unfold-lambda form)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2627 (byte-compile-form form for-effect)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2628 (setq for-effect nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2629 ((byte-compile-normal-call form)))
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2630 (when for-effect
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2631 (byte-compile-discard)))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2632
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2633 (defun byte-compile-normal-call (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2634 (if byte-compile-generate-call-tree
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2635 (byte-compile-annotate-call-tree form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2636 (byte-compile-push-constant (car form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2637 (mapcar 'byte-compile-form (cdr form)) ; wasteful, but faster.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2638 (byte-compile-out 'byte-call (length (cdr form))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2639
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2640 ;; kludge added to XEmacs to work around the bogosities of a nonlexical lisp.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2641 (or (fboundp 'globally-boundp) (fset 'globally-boundp 'boundp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2642
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2643 (defun byte-compile-variable-ref (base-op var &optional varbind-flags)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2644 (if (or (not (symbolp var)) (byte-compile-constant-symbol-p var))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2645 (byte-compile-warn
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2646 (case base-op
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2647 (byte-varref "Variable reference to %s %s")
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2648 (byte-varset "Attempt to set %s %s")
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2649 (byte-varbind "Attempt to let-bind %s %s"))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2650 (if (symbolp var) "constant symbol" "non-symbol")
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2651 var)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2652 (if (and (get var 'byte-obsolete-variable)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2653 (memq 'obsolete byte-compile-warnings))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2654 (let ((ob (get var 'byte-obsolete-variable)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2655 (byte-compile-warn "%s is an obsolete variable; %s" var
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2656 (if (stringp ob)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2657 ob
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2658 (format "use %s instead." ob)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2659 (if (and (get var 'byte-compatible-variable)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2660 (memq 'pedantic byte-compile-warnings))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2661 (let ((ob (get var 'byte-compatible-variable)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2662 (byte-compile-warn "%s is provided for compatibility; %s" var
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2663 (if (stringp ob)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2664 ob
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2665 (format "use %s instead." ob)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2666 (if (memq 'free-vars byte-compile-warnings)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2667 (if (eq base-op 'byte-varbind)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2668 (setq byte-compile-bound-variables
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2669 (cons (cons var (or varbind-flags 0))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2670 byte-compile-bound-variables))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2671 (or (globally-boundp var)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2672 (let ((cell (assq var byte-compile-bound-variables)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2673 (if cell (setcdr cell
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2674 (logior (cdr cell)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2675 (if (eq base-op 'byte-varset)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2676 byte-compile-assigned-bit
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2677 byte-compile-referenced-bit)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2678 (if (eq base-op 'byte-varset)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2679 (or (memq var byte-compile-free-assignments)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2680 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2681 (byte-compile-warn "assignment to free variable %s"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2682 var)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2683 (setq byte-compile-free-assignments
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2684 (cons var byte-compile-free-assignments))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2685 (or (memq var byte-compile-free-references)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2686 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2687 (byte-compile-warn "reference to free variable %s" var)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2688 (setq byte-compile-free-references
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2689 (cons var byte-compile-free-references)))))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2690 (let ((tmp (assq var byte-compile-variables)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2691 (or tmp
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2692 (setq tmp (list var)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2693 byte-compile-variables (cons tmp byte-compile-variables)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2694 (byte-compile-out base-op tmp)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2695
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2696 (defmacro byte-compile-get-constant (const)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2697 `(or (if (stringp ,const)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2698 (assoc ,const byte-compile-constants)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2699 (assq ,const byte-compile-constants))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2700 (car (setq byte-compile-constants
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2701 (cons (list ,const) byte-compile-constants)))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2702
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2703 ;; Use this when the value of a form is a constant. This obeys for-effect.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2704 (defun byte-compile-constant (const)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2705 (if for-effect
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2706 (setq for-effect nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2707 (byte-compile-out 'byte-constant (byte-compile-get-constant const))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2708
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2709 ;; Use this for a constant that is not the value of its containing form.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2710 ;; This ignores for-effect.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2711 (defun byte-compile-push-constant (const)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2712 (let ((for-effect nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2713 (inline (byte-compile-constant const))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2714
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2715
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2716 ;; Compile those primitive ordinary functions
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2717 ;; which have special byte codes just for speed.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2718
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2719 (defmacro byte-defop-compiler (function &optional compile-handler)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2720 ;; add a compiler-form for FUNCTION.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2721 ;; If function is a symbol, then the variable "byte-SYMBOL" must name
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2722 ;; the opcode to be used. If function is a list, the first element
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2723 ;; is the function and the second element is the bytecode-symbol.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2724 ;; COMPILE-HANDLER is the function to use to compile this byte-op, or
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2725 ;; may be the abbreviations 0, 1, 2, 3, 0-1, 1-2, 2-3, 0+1, 1+1, 2+1,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2726 ;; 0-1+1, 1-2+1, 2-3+1, 0+2, or 1+2. If it is nil, then the handler is
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2727 ;; "byte-compile-SYMBOL."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2728 (let (opcode)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2729 (if (symbolp function)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2730 (setq opcode (intern (concat "byte-" (symbol-name function))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2731 (setq opcode (car (cdr function))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2732 function (car function)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2733 (let ((fnform
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2734 (list 'put (list 'quote function) ''byte-compile
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2735 (list 'quote
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2736 (or (cdr (assq compile-handler
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2737 '((0 . byte-compile-no-args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2738 (1 . byte-compile-one-arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2739 (2 . byte-compile-two-args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2740 (3 . byte-compile-three-args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2741 (0-1 . byte-compile-zero-or-one-arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2742 (1-2 . byte-compile-one-or-two-args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2743 (2-3 . byte-compile-two-or-three-args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2744 (0+1 . byte-compile-no-args-with-one-extra)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2745 (1+1 . byte-compile-one-arg-with-one-extra)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2746 (2+1 . byte-compile-two-args-with-one-extra)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2747 (0-1+1 . byte-compile-zero-or-one-arg-with-one-extra)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2748 (1-2+1 . byte-compile-one-or-two-args-with-one-extra)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2749 (2-3+1 . byte-compile-two-or-three-args-with-one-extra)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2750 (0+2 . byte-compile-no-args-with-two-extra)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2751 (1+2 . byte-compile-one-arg-with-two-extra)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
2752
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2753 )))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2754 compile-handler
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2755 (intern (concat "byte-compile-"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2756 (symbol-name function))))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2757 (if opcode
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2758 (list 'progn fnform
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2759 (list 'put (list 'quote function)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2760 ''byte-opcode (list 'quote opcode))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2761 (list 'put (list 'quote opcode)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2762 ''byte-opcode-invert (list 'quote function)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2763 fnform))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2764
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2765 (defmacro byte-defop-compiler20 (function &optional compile-handler)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2766 ;; Just like byte-defop-compiler, but defines an opcode that will only
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2767 ;; be used when byte-compile-emacs19-compatibility is false.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2768 (if (and (byte-compile-single-version)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2769 byte-compile-emacs19-compatibility)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2770 ;; #### instead of doing nothing, this should do some remprops,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2771 ;; #### to protect against the case where a single-version compiler
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2772 ;; #### is loaded into a world that has contained a multi-version one.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2773 nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2774 (list 'progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2775 (list 'put
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2776 (list 'quote
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2777 (or (car (cdr-safe function))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2778 (intern (concat "byte-"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2779 (symbol-name (or (car-safe function) function))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2780 ''emacs20-opcode t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2781 (list 'byte-defop-compiler function compile-handler))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2782
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2783 ;; XEmacs addition:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2784 (defmacro byte-defop-compiler-rmsfun (function &optional compile-handler)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2785 ;; for functions like `eq' that compile into different opcodes depending
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2786 ;; on the Emacs version: byte-old-eq for v19, byte-eq for v20.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2787 (let ((opcode (intern (concat "byte-" (symbol-name function))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2788 (opcode19 (intern (concat "byte-old-" (symbol-name function))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2789 (fnform
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2790 (list 'put (list 'quote function) ''byte-compile
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2791 (list 'quote
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2792 (or (cdr (assq compile-handler
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2793 '((2 . byte-compile-two-args-19->20)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2794 )))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2795 compile-handler
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2796 (intern (concat "byte-compile-"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2797 (symbol-name function))))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2798 (list 'progn fnform
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2799 (list 'put (list 'quote function)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2800 ''byte-opcode (list 'quote opcode))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2801 (list 'put (list 'quote function)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2802 ''byte-opcode19 (list 'quote opcode19))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2803 (list 'put (list 'quote opcode)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2804 ''byte-opcode-invert (list 'quote function))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2805 (list 'put (list 'quote opcode19)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2806 ''byte-opcode19-invert (list 'quote function)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2807
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2808 (defmacro byte-defop-compiler-1 (function &optional compile-handler)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2809 (list 'byte-defop-compiler (list function nil) compile-handler))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2810
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2811
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2812 (put 'byte-call 'byte-opcode-invert 'funcall)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2813 (put 'byte-list1 'byte-opcode-invert 'list)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2814 (put 'byte-list2 'byte-opcode-invert 'list)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2815 (put 'byte-list3 'byte-opcode-invert 'list)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2816 (put 'byte-list4 'byte-opcode-invert 'list)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2817 (put 'byte-listN 'byte-opcode-invert 'list)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2818 (put 'byte-concat2 'byte-opcode-invert 'concat)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2819 (put 'byte-concat3 'byte-opcode-invert 'concat)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2820 (put 'byte-concat4 'byte-opcode-invert 'concat)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2821 (put 'byte-concatN 'byte-opcode-invert 'concat)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2822 (put 'byte-insertN 'byte-opcode-invert 'insert)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2823
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
2824 ;; How old is this stuff? -slb
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
2825 ;(byte-defop-compiler (dot byte-point) 0+1)
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
2826 ;(byte-defop-compiler (dot-max byte-point-max) 0+1)
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
2827 ;(byte-defop-compiler (dot-min byte-point-min) 0+1)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2828 (byte-defop-compiler point 0+1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2829 (byte-defop-compiler-rmsfun eq 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2830 (byte-defop-compiler point-max 0+1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2831 (byte-defop-compiler point-min 0+1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2832 (byte-defop-compiler following-char 0+1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2833 (byte-defop-compiler preceding-char 0+1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2834 (byte-defop-compiler current-column 0+1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2835 ;; FSF has special function here; generalized here by the 1+2 stuff.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2836 (byte-defop-compiler (indent-to-column byte-indent-to) 1+2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2837 (byte-defop-compiler indent-to 1+2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2838 (byte-defop-compiler-rmsfun equal 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2839 (byte-defop-compiler eolp 0+1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2840 (byte-defop-compiler eobp 0+1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2841 (byte-defop-compiler bolp 0+1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2842 (byte-defop-compiler bobp 0+1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2843 (byte-defop-compiler current-buffer 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2844 ;;(byte-defop-compiler read-char 0) ;; obsolete
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2845 (byte-defop-compiler-rmsfun memq 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2846 (byte-defop-compiler interactive-p 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2847 (byte-defop-compiler widen 0+1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2848 (byte-defop-compiler end-of-line 0-1+1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2849 (byte-defop-compiler forward-char 0-1+1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2850 (byte-defop-compiler forward-line 0-1+1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2851 (byte-defop-compiler symbolp 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2852 (byte-defop-compiler consp 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2853 (byte-defop-compiler stringp 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2854 (byte-defop-compiler listp 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2855 (byte-defop-compiler not 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2856 (byte-defop-compiler (null byte-not) 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2857 (byte-defop-compiler car 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2858 (byte-defop-compiler cdr 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2859 (byte-defop-compiler length 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2860 (byte-defop-compiler symbol-value 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2861 (byte-defop-compiler symbol-function 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2862 (byte-defop-compiler (1+ byte-add1) 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2863 (byte-defop-compiler (1- byte-sub1) 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2864 (byte-defop-compiler goto-char 1+1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2865 (byte-defop-compiler char-after 0-1+1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2866 (byte-defop-compiler set-buffer 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2867 ;;(byte-defop-compiler set-mark 1) ;; obsolete
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2868 (byte-defop-compiler forward-word 1+1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2869 (byte-defop-compiler char-syntax 1+1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2870 (byte-defop-compiler nreverse 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2871 (byte-defop-compiler car-safe 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2872 (byte-defop-compiler cdr-safe 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2873 (byte-defop-compiler numberp 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2874 (byte-defop-compiler integerp 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2875 (byte-defop-compiler skip-chars-forward 1-2+1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2876 (byte-defop-compiler skip-chars-backward 1-2+1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2877 (byte-defop-compiler (eql byte-eq) 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2878 (byte-defop-compiler20 old-eq 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2879 (byte-defop-compiler20 old-memq 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2880 (byte-defop-compiler cons 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2881 (byte-defop-compiler aref 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2882 (byte-defop-compiler get 2+1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2883 (byte-defop-compiler nth 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2884 (byte-defop-compiler substring 2-3)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2885 (byte-defop-compiler (move-marker byte-set-marker) 2-3)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2886 (byte-defop-compiler set-marker 2-3)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2887 (byte-defop-compiler match-beginning 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2888 (byte-defop-compiler match-end 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2889 (byte-defop-compiler upcase 1+1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2890 (byte-defop-compiler downcase 1+1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2891 (byte-defop-compiler string= 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2892 (byte-defop-compiler string< 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2893 (byte-defop-compiler (string-equal byte-string=) 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2894 (byte-defop-compiler (string-lessp byte-string<) 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2895 (byte-defop-compiler20 old-equal 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2896 (byte-defop-compiler nthcdr 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2897 (byte-defop-compiler elt 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2898 (byte-defop-compiler20 old-member 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2899 (byte-defop-compiler20 old-assq 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2900 (byte-defop-compiler (rplaca byte-setcar) 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2901 (byte-defop-compiler (rplacd byte-setcdr) 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2902 (byte-defop-compiler setcar 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2903 (byte-defop-compiler setcdr 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2904 (byte-defop-compiler delete-region 2+1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2905 (byte-defop-compiler narrow-to-region 2+1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2906 (byte-defop-compiler (% byte-rem) 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2907 (byte-defop-compiler aset 3)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2908
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2909 (byte-defop-compiler-rmsfun member 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2910 (byte-defop-compiler-rmsfun assq 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2911
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2912 (byte-defop-compiler max byte-compile-associative)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2913 (byte-defop-compiler min byte-compile-associative)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2914 (byte-defop-compiler (+ byte-plus) byte-compile-associative)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2915 (byte-defop-compiler (* byte-mult) byte-compile-associative)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2916
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2917 ;;####(byte-defop-compiler move-to-column 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2918 (byte-defop-compiler-1 interactive byte-compile-noop)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2919 (byte-defop-compiler-1 domain byte-compile-domain)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2920
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2921 ;; As of GNU Emacs 19.18 and Lucid Emacs 19.8, mod and % are different: `%'
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2922 ;; means integral remainder and may have a negative result; `mod' is always
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2923 ;; positive, and accepts floating point args. All code which uses `mod' and
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2924 ;; requires the new interpretation must be compiled with bytecomp version 2.18
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2925 ;; or newer, or the emitted code will run the byte-code for `%' instead of an
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2926 ;; actual call to `mod'. So be careful of compiling new code with an old
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
2927 ;; compiler. Note also that `%' is more efficient than `mod' because the
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2928 ;; former is byte-coded and the latter is not.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2929 ;;(byte-defop-compiler (mod byte-rem) 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2930
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2931
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2932 (defun byte-compile-subr-wrong-args (form n)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2933 (when (memq 'subr-callargs byte-compile-warnings)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2934 (byte-compile-warn "%s called with %d arg%s, but requires %s"
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2935 (car form) (length (cdr form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2936 (if (= 1 (length (cdr form))) "" "s") n))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2937 ;; get run-time wrong-number-of-args error.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2938 (byte-compile-normal-call form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2939
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2940 (defun byte-compile-no-args (form)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2941 (case (length (cdr form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2942 (0 (byte-compile-out (get (car form) 'byte-opcode) 0))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2943 (t (byte-compile-subr-wrong-args form "none"))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2944
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2945 (defun byte-compile-one-arg (form)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2946 (case (length (cdr form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2947 (1 (byte-compile-form (car (cdr form))) ;; Push the argument
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2948 (byte-compile-out (get (car form) 'byte-opcode) 0))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2949 (t (byte-compile-subr-wrong-args form 1))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2950
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2951 (defun byte-compile-two-args (form)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2952 (case (length (cdr form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2953 (2 (byte-compile-form (nth 1 form)) ;; Push the arguments
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2954 (byte-compile-form (nth 2 form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2955 (byte-compile-out (get (car form) 'byte-opcode) 0))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2956 (t (byte-compile-subr-wrong-args form 2))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2957
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2958 (defun byte-compile-three-args (form)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2959 (case (length (cdr form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2960 (3 (byte-compile-form (nth 1 form)) ;; Push the arguments
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2961 (byte-compile-form (nth 2 form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2962 (byte-compile-form (nth 3 form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2963 (byte-compile-out (get (car form) 'byte-opcode) 0))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2964 (t (byte-compile-subr-wrong-args form 3))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2965
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2966 (defun byte-compile-zero-or-one-arg (form)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2967 (case (length (cdr form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2968 (0 (byte-compile-one-arg (append form '(nil))))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2969 (1 (byte-compile-one-arg form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2970 (t (byte-compile-subr-wrong-args form "0-1"))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2971
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2972 (defun byte-compile-one-or-two-args (form)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2973 (case (length (cdr form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2974 (1 (byte-compile-two-args (append form '(nil))))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2975 (2 (byte-compile-two-args form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2976 (t (byte-compile-subr-wrong-args form "1-2"))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2977
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2978 (defun byte-compile-two-or-three-args (form)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2979 (case (length (cdr form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2980 (2 (byte-compile-three-args (append form '(nil))))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2981 (3 (byte-compile-three-args form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2982 (t (byte-compile-subr-wrong-args form "2-3"))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2983
298
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 284
diff changeset
2984 ;; from Ben Wing <ben@xemacs.org>: some inlined functions have extra
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2985 ;; optional args added to them in XEmacs 19.12. Changing the byte
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2986 ;; interpreter to deal with these args would be wrong and cause
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2987 ;; incompatibility, so we generate non-inlined calls for those cases.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2988 ;; Without the following functions, spurious warnings will be generated;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2989 ;; however, they would still compile correctly because
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2990 ;; `byte-compile-subr-wrong-args' also converts the call to non-inlined.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2991
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2992 (defun byte-compile-no-args-with-one-extra (form)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2993 (case (length (cdr form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2994 (0 (byte-compile-no-args form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2995 (1 (byte-compile-normal-call form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2996 (t (byte-compile-subr-wrong-args form "0-1"))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2997
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2998 (defun byte-compile-one-arg-with-one-extra (form)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
2999 (case (length (cdr form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3000 (1 (byte-compile-one-arg form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3001 (2 (byte-compile-normal-call form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3002 (t (byte-compile-subr-wrong-args form "1-2"))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3003
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3004 (defun byte-compile-two-args-with-one-extra (form)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3005 (case (length (cdr form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3006 (2 (byte-compile-two-args form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3007 (3 (byte-compile-normal-call form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3008 (t (byte-compile-subr-wrong-args form "2-3"))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3009
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3010 (defun byte-compile-zero-or-one-arg-with-one-extra (form)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3011 (case (length (cdr form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3012 (0 (byte-compile-one-arg (append form '(nil))))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3013 (1 (byte-compile-one-arg form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3014 (2 (byte-compile-normal-call form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3015 (t (byte-compile-subr-wrong-args form "0-2"))))
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
3016
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3017 (defun byte-compile-one-or-two-args-with-one-extra (form)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3018 (case (length (cdr form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3019 (1 (byte-compile-two-args (append form '(nil))))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3020 (2 (byte-compile-two-args form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3021 (3 (byte-compile-normal-call form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3022 (t (byte-compile-subr-wrong-args form "1-3"))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3023
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3024 (defun byte-compile-two-or-three-args-with-one-extra (form)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3025 (case (length (cdr form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3026 (2 (byte-compile-three-args (append form '(nil))))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3027 (3 (byte-compile-three-args form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3028 (4 (byte-compile-normal-call form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3029 (t (byte-compile-subr-wrong-args form "2-4"))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3030
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3031 (defun byte-compile-no-args-with-two-extra (form)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3032 (case (length (cdr form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3033 (0 (byte-compile-no-args form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3034 ((1 2) (byte-compile-normal-call form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3035 (t (byte-compile-subr-wrong-args form "0-2"))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3036
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3037 (defun byte-compile-one-arg-with-two-extra (form)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3038 (case (length (cdr form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3039 (1 (byte-compile-one-arg form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3040 ((2 3) (byte-compile-normal-call form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3041 (t (byte-compile-subr-wrong-args form "1-3"))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3042
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3043 ;; XEmacs: used for functions that have a different opcode in v19 than v20.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3044 ;; this includes `eq', `equal', and other old-ified functions.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3045 (defun byte-compile-two-args-19->20 (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3046 (if (not (= (length form) 3))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3047 (byte-compile-subr-wrong-args form 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3048 (byte-compile-form (car (cdr form))) ;; Push the arguments
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3049 (byte-compile-form (nth 2 form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3050 (if (byte-compile-version-cond byte-compile-emacs19-compatibility)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3051 (byte-compile-out (get (car form) 'byte-opcode19) 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3052 (byte-compile-out (get (car form) 'byte-opcode) 0))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3053
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3054 (defun byte-compile-noop (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3055 (byte-compile-constant nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3056
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3057 (defun byte-compile-discard ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3058 (byte-compile-out 'byte-discard 0))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3059
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3060 ;; Compile a function that accepts one or more args and is right-associative.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3061 ;; We do it by left-associativity so that the operations
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3062 ;; are done in the same order as in interpreted code.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3063 ;(defun byte-compile-associative (form)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3064 ; (if (cdr form)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3065 ; (let ((opcode (get (car form) 'byte-opcode))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3066 ; (args (copy-sequence (cdr form))))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3067 ; (byte-compile-form (car args))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3068 ; (setq args (cdr args))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3069 ; (while args
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3070 ; (byte-compile-form (car args))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3071 ; (byte-compile-out opcode 0)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3072 ; (setq args (cdr args))))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3073 ; (byte-compile-constant (eval form))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3074
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3075 ;; Compile a function that accepts one or more args and is right-associative.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3076 ;; We do it by left-associativity so that the operations
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3077 ;; are done in the same order as in interpreted code.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3078 (defun byte-compile-associative (form)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3079 (let ((args (cdr form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3080 (opcode (get (car form) 'byte-opcode)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3081 (case (length args)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3082 (0 (byte-compile-constant (eval form)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3083 (t (byte-compile-form (car args))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3084 (dolist (arg (cdr args))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3085 (byte-compile-form arg)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3086 (byte-compile-out opcode 0))))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3087
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3088
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3089 ;; more complicated compiler macros
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3090
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3091 (byte-defop-compiler list)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3092 (byte-defop-compiler concat)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3093 (byte-defop-compiler fset)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3094 (byte-defop-compiler insert)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3095 (byte-defop-compiler-1 function byte-compile-function-form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3096 (byte-defop-compiler-1 - byte-compile-minus)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3097 (byte-defop-compiler (/ byte-quo) byte-compile-quo)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3098 (byte-defop-compiler nconc)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3099 (byte-defop-compiler-1 beginning-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3100
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3101 (byte-defop-compiler (= byte-eqlsign) byte-compile-arithcompare)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3102 (byte-defop-compiler (< byte-lss) byte-compile-arithcompare)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3103 (byte-defop-compiler (> byte-gtr) byte-compile-arithcompare)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3104 (byte-defop-compiler (<= byte-leq) byte-compile-arithcompare)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3105 (byte-defop-compiler (>= byte-geq) byte-compile-arithcompare)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3106
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3107 (defun byte-compile-arithcompare (form)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3108 (case (length (cdr form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3109 (0 (byte-compile-subr-wrong-args form "1 or more"))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3110 (1 (byte-compile-constant t))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3111 (2 (byte-compile-two-args form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3112 (t (byte-compile-normal-call form))))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3113
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3114 (byte-defop-compiler /= byte-compile-/=)
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 272
diff changeset
3115
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 272
diff changeset
3116 (defun byte-compile-/= (form)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3117 (case (length (cdr form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3118 (0 (byte-compile-subr-wrong-args form "1 or more"))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3119 (1 (byte-compile-constant t))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3120 ;; optimize (/= X Y) to (not (= X Y))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3121 (2 (byte-compile-form-do-effect `(not (= ,@(cdr form)))))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3122 (t (byte-compile-normal-call form))))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3123
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3124 ;; buffer-substring now has its own function. This used to be
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3125 ;; 2+1, but now all args are optional.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3126 (byte-defop-compiler buffer-substring)
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 272
diff changeset
3127
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3128 (defun byte-compile-buffer-substring (form)
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
3129 ;; buffer-substring used to take exactly two args, but now takes 0-3.
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
3130 ;; convert 0-2 to two args and use special bytecode operand.
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
3131 ;; convert 3 args to a normal call.
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
3132 (case (length (cdr form))
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
3133 (0 (byte-compile-two-args (append form '(nil nil))))
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
3134 (1 (byte-compile-two-args (append form '(nil))))
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
3135 (2 (byte-compile-two-args form))
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
3136 (3 (byte-compile-normal-call form))
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
3137 (t (byte-compile-subr-wrong-args form "0-3"))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3138
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3139 (defun byte-compile-list (form)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3140 (let* ((args (cdr form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3141 (nargs (length args)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3142 (cond
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3143 ((= nargs 0)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3144 (byte-compile-constant nil))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3145 ((< nargs 5)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3146 (mapcar 'byte-compile-form args)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3147 (byte-compile-out
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3148 (aref [byte-list1 byte-list2 byte-list3 byte-list4] (1- nargs))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3149 0))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3150 ((< nargs 256)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3151 (mapcar 'byte-compile-form args)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3152 (byte-compile-out 'byte-listN nargs))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3153 (t (byte-compile-normal-call form)))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3154
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3155 (defun byte-compile-concat (form)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3156 (let* ((args (cdr form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3157 (nargs (length args)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3158 ;; Concat of one arg is not a no-op if arg is not a string.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3159 (cond
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3160 ((memq nargs '(2 3 4))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3161 (mapcar 'byte-compile-form args)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3162 (byte-compile-out
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3163 (aref [byte-concat2 byte-concat3 byte-concat4] (- nargs 2))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3164 0))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3165 ((eq nargs 0)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3166 (byte-compile-form ""))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3167 ((< nargs 256)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3168 (mapcar 'byte-compile-form args)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3169 (byte-compile-out 'byte-concatN nargs))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3170 ((byte-compile-normal-call form)))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3171
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3172 (defun byte-compile-minus (form)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3173 (let ((args (cdr form)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3174 (case (length args)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3175 (0 (byte-compile-subr-wrong-args form "1 or more"))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3176 (1 (byte-compile-form (car args))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3177 (byte-compile-out 'byte-negate 0))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3178 (t (byte-compile-form (car args))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3179 (dolist (elt (cdr args))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3180 (byte-compile-form elt)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3181 (byte-compile-out 'byte-diff 0))))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3182
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3183 (defun byte-compile-quo (form)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3184 (let ((args (cdr form)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3185 (case (length args)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3186 (0 (byte-compile-subr-wrong-args form "1 or more"))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3187 (1 (byte-compile-constant 1)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3188 (byte-compile-form (car args))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3189 (byte-compile-out 'byte-quo 0))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3190 (t (byte-compile-form (car args))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3191 (dolist (elt (cdr args))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3192 (byte-compile-form elt)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3193 (byte-compile-out 'byte-quo 0))))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3194
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3195 (defun byte-compile-nconc (form)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3196 (let ((args (cdr form)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3197 (case (length args)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3198 (0 (byte-compile-constant nil))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3199 ;; nconc of one arg is a noop, even if that arg isn't a list.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3200 (1 (byte-compile-form (car args)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3201 (t (byte-compile-form (car args))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3202 (dolist (elt (cdr args))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3203 (byte-compile-form elt)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3204 (byte-compile-out 'byte-nconc 0))))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3205
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3206 (defun byte-compile-fset (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3207 ;; warn about forms like (fset 'foo '(lambda () ...))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3208 ;; (where the lambda expression is non-trivial...)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3209 ;; Except don't warn if the first argument is 'make-byte-code, because
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3210 ;; I'm sick of getting mail asking me whether that warning is a problem.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3211 (let ((fn (nth 2 form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3212 body)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3213 (when (and (eq (car-safe fn) 'quote)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3214 (eq (car-safe (setq fn (nth 1 fn))) 'lambda)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3215 (not (eq (car-safe (cdr-safe (nth 1 form))) 'make-byte-code)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3216 (setq body (cdr (cdr fn)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3217 (if (stringp (car body)) (setq body (cdr body)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3218 (if (eq 'interactive (car-safe (car body))) (setq body (cdr body)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3219 (if (and (consp (car body))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3220 (not (eq 'byte-code (car (car body)))))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3221 (byte-compile-warn
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3222 "A quoted lambda form is the second argument of fset. This is probably
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3223 not what you want, as that lambda cannot be compiled. Consider using
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3224 the syntax (function (lambda (...) ...)) instead."))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3225 (byte-compile-two-args form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3226
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3227 (defun byte-compile-funarg (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3228 ;; (mapcar '(lambda (x) ..) ..) ==> (mapcar (function (lambda (x) ..)) ..)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3229 ;; for cases where it's guaranteed that first arg will be used as a lambda.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3230 (byte-compile-normal-call
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3231 (let ((fn (nth 1 form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3232 (if (and (eq (car-safe fn) 'quote)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3233 (eq (car-safe (nth 1 fn)) 'lambda))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3234 (cons (car form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3235 (cons (cons 'function (cdr fn))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3236 (cdr (cdr form))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3237 form))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3238
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3239 ;; (function foo) must compile like 'foo, not like (symbol-function 'foo).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3240 ;; Otherwise it will be incompatible with the interpreter,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3241 ;; and (funcall (function foo)) will lose with autoloads.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3242
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3243 (defun byte-compile-function-form (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3244 (byte-compile-constant
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3245 (cond ((symbolp (nth 1 form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3246 (nth 1 form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3247 ((byte-compile-lambda (nth 1 form))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3248
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3249 (defun byte-compile-insert (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3250 (cond ((null (cdr form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3251 (byte-compile-constant nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3252 ((<= (length form) 256)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3253 (mapcar 'byte-compile-form (cdr form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3254 (if (cdr (cdr form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3255 (byte-compile-out 'byte-insertN (length (cdr form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3256 (byte-compile-out 'byte-insert 0)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3257 ((memq t (mapcar 'consp (cdr (cdr form))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3258 (byte-compile-normal-call form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3259 ;; We can split it; there is no function call after inserting 1st arg.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3260 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3261 (while (setq form (cdr form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3262 (byte-compile-form (car form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3263 (byte-compile-out 'byte-insert 0)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3264 (when (cdr form)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3265 (byte-compile-discard))))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3266
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3267 ;; alas, the old (pre-19.12, and all existing versions of FSFmacs 19)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3268 ;; byte compiler will generate incorrect code for
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3269 ;; (beginning-of-line nil buffer) because it buggily doesn't
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3270 ;; check the number of arguments passed to beginning-of-line.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3271
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3272 (defun byte-compile-beginning-of-line (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3273 (let ((len (length form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3274 (cond ((> len 3)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3275 (byte-compile-subr-wrong-args form "0-2"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3276 ((or (= len 3) (not (byte-compile-constp (nth 1 form))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3277 (byte-compile-normal-call form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3278 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3279 (byte-compile-form
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3280 (list 'forward-line
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3281 (if (integerp (setq form (or (eval (nth 1 form)) 1)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3282 (1- form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3283 (byte-compile-warn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3284 "Non-numeric arg to beginning-of-line: %s" form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3285 (list '1- (list 'quote form))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3286 t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3287 (byte-compile-constant nil)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3288
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3289
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3290 (byte-defop-compiler set)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3291 (byte-defop-compiler-1 setq)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3292 (byte-defop-compiler-1 set-default)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3293 (byte-defop-compiler-1 setq-default)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3294
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3295 (byte-defop-compiler-1 quote)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3296 (byte-defop-compiler-1 quote-form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3297
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3298 (defun byte-compile-setq (form)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3299 (let ((args (cdr form)) var val)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3300 (if (null args)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3301 ;; (setq), with no arguments.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3302 (byte-compile-form nil for-effect)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3303 (while args
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3304 (setq var (pop args))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3305 (if (null args)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3306 ;; Odd number of args? Let `set' get the error.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3307 (byte-compile-form `(set ',var) for-effect)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3308 (setq val (pop args))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3309 (if (keywordp var)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3310 ;; (setq :foo ':foo) compatibility kludge
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3311 (byte-compile-form `(set ',var ,val) (if args t for-effect))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3312 (byte-compile-form val)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3313 (unless (or args for-effect)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3314 (byte-compile-out 'byte-dup 0))
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3315 (byte-compile-variable-ref 'byte-varset var))))))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3316 (setq for-effect nil))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3317
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3318 (defun byte-compile-set (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3319 ;; Compile (set 'foo x) as (setq foo x) for trivially better code and so
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3320 ;; that we get applicable warnings. Compile everything else (including
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3321 ;; malformed calls) like a normal 2-arg byte-coded function.
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3322 (let ((symform (nth 1 form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3323 (valform (nth 2 form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3324 sym)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3325 (if (and (= (length form) 3)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3326 (= (safe-length symform) 2)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3327 (eq (car symform) 'quote)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3328 (symbolp (setq sym (car (cdr symform))))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3329 (not (byte-compile-constant-symbol-p sym)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3330 (byte-compile-setq `(setq ,sym ,valform))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3331 (byte-compile-two-args form))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3332
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3333 (defun byte-compile-setq-default (form)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3334 (let ((args (cdr form)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3335 (if (null args)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3336 ;; (setq-default), with no arguments.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3337 (byte-compile-form nil for-effect)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3338 ;; emit multiple calls to `set-default' if necessary
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3339 (while args
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3340 (byte-compile-form
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3341 ;; Odd number of args? Let `set-default' get the error.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3342 `(set-default ',(pop args) ,@(if args (list (pop args)) nil))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3343 (if args t for-effect)))))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3344 (setq for-effect nil))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3345
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3346
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3347 (defun byte-compile-set-default (form)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3348 (let* ((args (cdr form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3349 (nargs (length args))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3350 (var (car args)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3351 (when (and (= (safe-length var) 2)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3352 (eq (car var) 'quote))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3353 (let ((sym (nth 1 var)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3354 (cond
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3355 ((not (symbolp sym))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3356 (byte-compile-warn "Attempt to set-globally non-symbol %s" sym))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3357 ((byte-compile-constant-symbol-p sym)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3358 (byte-compile-warn "Attempt to set-globally constant symbol %s" sym))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3359 ((let ((cell (assq sym byte-compile-bound-variables)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3360 (and cell
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3361 (setcdr cell (logior (cdr cell) byte-compile-assigned-bit))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3362 t)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3363 ;; notice calls to set-default/setq-default for variables which
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3364 ;; have not been declared with defvar/defconst.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3365 ((globally-boundp sym)) ; OK
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3366 ((not (memq 'free-vars byte-compile-warnings))) ; warnings suppressed?
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3367 ((memq sym byte-compile-free-assignments)) ; already warned about sym
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3368 (t
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3369 (byte-compile-warn "assignment to free variable %s" sym)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3370 (push sym byte-compile-free-assignments)))))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3371 (if (= nargs 2)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3372 ;; now emit a normal call to set-default
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3373 (byte-compile-normal-call form)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3374 (byte-compile-subr-wrong-args form 2))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3375
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3376
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3377 (defun byte-compile-quote (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3378 (byte-compile-constant (car (cdr form))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3379
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3380 (defun byte-compile-quote-form (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3381 (byte-compile-constant (byte-compile-top-level (nth 1 form))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3382
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3383
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3384 ;;; control structures
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3385
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3386 (defun byte-compile-body (body &optional for-effect)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3387 (while (cdr body)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3388 (byte-compile-form (car body) t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3389 (setq body (cdr body)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3390 (byte-compile-form (car body) for-effect))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3391
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3392 (proclaim-inline byte-compile-body-do-effect)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3393 (defun byte-compile-body-do-effect (body)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3394 (byte-compile-body body for-effect)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3395 (setq for-effect nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3396
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3397 (proclaim-inline byte-compile-form-do-effect)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3398 (defun byte-compile-form-do-effect (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3399 (byte-compile-form form for-effect)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3400 (setq for-effect nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3401
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3402 (byte-defop-compiler-1 inline byte-compile-progn)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3403 (byte-defop-compiler-1 progn)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3404 (byte-defop-compiler-1 prog1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3405 (byte-defop-compiler-1 prog2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3406 (byte-defop-compiler-1 if)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3407 (byte-defop-compiler-1 cond)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3408 (byte-defop-compiler-1 and)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3409 (byte-defop-compiler-1 or)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3410 (byte-defop-compiler-1 while)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3411 (byte-defop-compiler-1 funcall)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3412 (byte-defop-compiler-1 apply byte-compile-funarg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3413 (byte-defop-compiler-1 mapcar byte-compile-funarg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3414 (byte-defop-compiler-1 mapatoms byte-compile-funarg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3415 (byte-defop-compiler-1 mapconcat byte-compile-funarg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3416 (byte-defop-compiler-1 let)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3417 (byte-defop-compiler-1 let*)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3418
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3419 (defun byte-compile-progn (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3420 (byte-compile-body-do-effect (cdr form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3421
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3422 (defun byte-compile-prog1 (form)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3423 (setq form (cdr form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3424 (byte-compile-form-do-effect (pop form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3425 (byte-compile-body form t))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3426
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3427 (defun byte-compile-prog2 (form)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3428 (setq form (cdr form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3429 (byte-compile-form (pop form) t)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3430 (byte-compile-form-do-effect (pop form))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3431 (byte-compile-body form t))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3432
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3433 (defmacro byte-compile-goto-if (cond discard tag)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3434 `(byte-compile-goto
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3435 (if ,cond
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3436 (if ,discard 'byte-goto-if-not-nil 'byte-goto-if-not-nil-else-pop)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3437 (if ,discard 'byte-goto-if-nil 'byte-goto-if-nil-else-pop))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3438 ,tag))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3439
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3440 (defun byte-compile-if (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3441 (byte-compile-form (car (cdr form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3442 (if (null (nthcdr 3 form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3443 ;; No else-forms
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3444 (let ((donetag (byte-compile-make-tag)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3445 (byte-compile-goto-if nil for-effect donetag)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3446 (byte-compile-form (nth 2 form) for-effect)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3447 (byte-compile-out-tag donetag))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3448 (let ((donetag (byte-compile-make-tag)) (elsetag (byte-compile-make-tag)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3449 (byte-compile-goto 'byte-goto-if-nil elsetag)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3450 (byte-compile-form (nth 2 form) for-effect)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3451 (byte-compile-goto 'byte-goto donetag)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3452 (byte-compile-out-tag elsetag)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3453 (byte-compile-body (cdr (cdr (cdr form))) for-effect)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3454 (byte-compile-out-tag donetag)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3455 (setq for-effect nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3456
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3457 (defun byte-compile-cond (clauses)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3458 (let ((donetag (byte-compile-make-tag))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3459 nexttag clause)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3460 (while (setq clauses (cdr clauses))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3461 (setq clause (car clauses))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3462 (cond ((or (eq (car clause) t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3463 (and (eq (car-safe (car clause)) 'quote)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3464 (car-safe (cdr-safe (car clause)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3465 ;; Unconditional clause
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3466 (setq clause (cons t clause)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3467 clauses nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3468 ((cdr clauses)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3469 (byte-compile-form (car clause))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3470 (if (null (cdr clause))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3471 ;; First clause is a singleton.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3472 (byte-compile-goto-if t for-effect donetag)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3473 (setq nexttag (byte-compile-make-tag))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3474 (byte-compile-goto 'byte-goto-if-nil nexttag)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3475 (byte-compile-body (cdr clause) for-effect)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3476 (byte-compile-goto 'byte-goto donetag)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3477 (byte-compile-out-tag nexttag)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3478 ;; Last clause
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3479 (and (cdr clause) (not (eq (car clause) t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3480 (progn (byte-compile-form (car clause))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3481 (byte-compile-goto-if nil for-effect donetag)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3482 (setq clause (cdr clause))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3483 (byte-compile-body-do-effect clause)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3484 (byte-compile-out-tag donetag)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3485
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3486 (defun byte-compile-and (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3487 (let ((failtag (byte-compile-make-tag))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3488 (args (cdr form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3489 (if (null args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3490 (byte-compile-form-do-effect t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3491 (while (cdr args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3492 (byte-compile-form (car args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3493 (byte-compile-goto-if nil for-effect failtag)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3494 (setq args (cdr args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3495 (byte-compile-form-do-effect (car args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3496 (byte-compile-out-tag failtag))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3497
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3498 (defun byte-compile-or (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3499 (let ((wintag (byte-compile-make-tag))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3500 (args (cdr form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3501 (if (null args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3502 (byte-compile-form-do-effect nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3503 (while (cdr args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3504 (byte-compile-form (car args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3505 (byte-compile-goto-if t for-effect wintag)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3506 (setq args (cdr args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3507 (byte-compile-form-do-effect (car args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3508 (byte-compile-out-tag wintag))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3509
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3510 (defun byte-compile-while (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3511 (let ((endtag (byte-compile-make-tag))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3512 (looptag (byte-compile-make-tag)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3513 (byte-compile-out-tag looptag)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3514 (byte-compile-form (car (cdr form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3515 (byte-compile-goto-if nil for-effect endtag)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3516 (byte-compile-body (cdr (cdr form)) t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3517 (byte-compile-goto 'byte-goto looptag)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3518 (byte-compile-out-tag endtag)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3519 (setq for-effect nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3520
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3521 (defun byte-compile-funcall (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3522 (mapcar 'byte-compile-form (cdr form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3523 (byte-compile-out 'byte-call (length (cdr (cdr form)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3524
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3525
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3526 (defun byte-compile-let (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3527 ;; First compute the binding values in the old scope.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3528 (let ((varlist (car (cdr form))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3529 (while varlist
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3530 (if (consp (car varlist))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3531 (byte-compile-form (car (cdr (car varlist))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3532 (byte-compile-push-constant nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3533 (setq varlist (cdr varlist))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3534 (let ((byte-compile-bound-variables
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3535 (cons 'new-scope byte-compile-bound-variables))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3536 (varlist (reverse (car (cdr form))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3537 (extra-flags
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3538 ;; If this let is of the form (let (...) (byte-code ...))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3539 ;; then assume that it is the result of a transformation of
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3540 ;; ((lambda (...) (byte-code ... )) ...) and thus compile
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3541 ;; the variable bindings as if they were arglist bindings
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3542 ;; (which matters for what warnings.)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3543 (if (eq 'byte-code (car-safe (nth 2 form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3544 byte-compile-arglist-bit
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3545 nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3546 (while varlist
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3547 (byte-compile-variable-ref 'byte-varbind
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3548 (if (consp (car varlist))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3549 (car (car varlist))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3550 (car varlist))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3551 extra-flags)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3552 (setq varlist (cdr varlist)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3553 (byte-compile-body-do-effect (cdr (cdr form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3554 (if (memq 'unused-vars byte-compile-warnings)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3555 ;; done compiling in this scope, warn now.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3556 (byte-compile-warn-about-unused-variables))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3557 (byte-compile-out 'byte-unbind (length (car (cdr form))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3558
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3559 (defun byte-compile-let* (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3560 (let ((byte-compile-bound-variables
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3561 (cons 'new-scope byte-compile-bound-variables))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3562 (varlist (copy-sequence (car (cdr form)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3563 (while varlist
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3564 (if (atom (car varlist))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3565 (byte-compile-push-constant nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3566 (byte-compile-form (car (cdr (car varlist))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3567 (setcar varlist (car (car varlist))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3568 (byte-compile-variable-ref 'byte-varbind (car varlist))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3569 (setq varlist (cdr varlist)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3570 (byte-compile-body-do-effect (cdr (cdr form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3571 (if (memq 'unused-vars byte-compile-warnings)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3572 ;; done compiling in this scope, warn now.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3573 (byte-compile-warn-about-unused-variables))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3574 (byte-compile-out 'byte-unbind (length (car (cdr form))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3575
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3576
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 272
diff changeset
3577 ;;(byte-defop-compiler-1 /= byte-compile-negated)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3578 (byte-defop-compiler-1 atom byte-compile-negated)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3579 (byte-defop-compiler-1 nlistp byte-compile-negated)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3580
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 272
diff changeset
3581 ;;(put '/= 'byte-compile-negated-op '=)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3582 (put 'atom 'byte-compile-negated-op 'consp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3583 (put 'nlistp 'byte-compile-negated-op 'listp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3584
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3585 (defun byte-compile-negated (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3586 (byte-compile-form-do-effect (byte-compile-negation-optimizer form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3587
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 272
diff changeset
3588 ;; Even when optimization is off, atom is optimized to (not (consp ...)).
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3589 (defun byte-compile-negation-optimizer (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3590 ;; an optimizer for forms where <form1> is less efficient than (not <form2>)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3591 (list 'not
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3592 (cons (or (get (car form) 'byte-compile-negated-op)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3593 (error
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3594 "Compiler error: `%s' has no `byte-compile-negated-op' property"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3595 (car form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3596 (cdr form))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3597
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3598 ;;; other tricky macro-like special-forms
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3599
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3600 (byte-defop-compiler-1 catch)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3601 (byte-defop-compiler-1 unwind-protect)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3602 (byte-defop-compiler-1 condition-case)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3603 (byte-defop-compiler-1 save-excursion)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3604 (byte-defop-compiler-1 save-current-buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3605 (byte-defop-compiler-1 save-restriction)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3606 (byte-defop-compiler-1 save-window-excursion)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3607 (byte-defop-compiler-1 with-output-to-temp-buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3608 ;; no track-mouse.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3609
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3610 (defun byte-compile-catch (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3611 (byte-compile-form (car (cdr form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3612 (byte-compile-push-constant
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3613 (byte-compile-top-level (cons 'progn (cdr (cdr form))) for-effect))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3614 (byte-compile-out 'byte-catch 0))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3615
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3616 (defun byte-compile-unwind-protect (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3617 (byte-compile-push-constant
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3618 (byte-compile-top-level-body (cdr (cdr form)) t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3619 (byte-compile-out 'byte-unwind-protect 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3620 (byte-compile-form-do-effect (car (cdr form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3621 (byte-compile-out 'byte-unbind 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3622
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3623 ;;(defun byte-compile-track-mouse (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3624 ;; (byte-compile-form
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3625 ;; (list
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3626 ;; 'funcall
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3627 ;; (list 'quote
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3628 ;; (list 'lambda nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3629 ;; (cons 'track-mouse
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3630 ;; (byte-compile-top-level-body (cdr form))))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3631
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3632 (defun byte-compile-condition-case (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3633 (let* ((var (nth 1 form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3634 (byte-compile-bound-variables
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3635 (if var
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3636 (cons (cons var 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3637 (cons 'new-scope byte-compile-bound-variables))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3638 (cons 'new-scope byte-compile-bound-variables))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3639 (or (symbolp var)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3640 (byte-compile-warn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3641 "%s is not a variable-name or nil (in condition-case)"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3642 (prin1-to-string var)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3643 (byte-compile-push-constant var)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3644 (byte-compile-push-constant (byte-compile-top-level
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3645 (nth 2 form) for-effect))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3646 (let ((clauses (cdr (cdr (cdr form))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3647 compiled-clauses)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3648 (while clauses
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3649 (let* ((clause (car clauses))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3650 (condition (car clause)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3651 (cond ((not (or (symbolp condition)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3652 (and (listp condition)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3653 (let ((syms condition) (ok t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3654 (while syms
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3655 (if (not (symbolp (car syms)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3656 (setq ok nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3657 (setq syms (cdr syms)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3658 ok))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3659 (byte-compile-warn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3660 "%s is not a symbol naming a condition or a list of such (in condition-case)"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3661 (prin1-to-string condition)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3662 ;; ((not (or (eq condition 't)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3663 ;; (and (stringp (get condition 'error-message))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3664 ;; (consp (get condition 'error-conditions)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3665 ;; (byte-compile-warn
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
3666 ;; "%s is not a known condition name (in condition-case)"
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3667 ;; condition))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3668 )
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3669 (setq compiled-clauses
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3670 (cons (cons condition
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3671 (byte-compile-top-level-body
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3672 (cdr clause) for-effect))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3673 compiled-clauses)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3674 (setq clauses (cdr clauses)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3675 (byte-compile-push-constant (nreverse compiled-clauses)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3676 (if (memq 'unused-vars byte-compile-warnings)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3677 ;; done compiling in this scope, warn now.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3678 (byte-compile-warn-about-unused-variables))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3679 (byte-compile-out 'byte-condition-case 0)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3680
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3681
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3682 (defun byte-compile-save-excursion (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3683 (byte-compile-out 'byte-save-excursion 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3684 (byte-compile-body-do-effect (cdr form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3685 (byte-compile-out 'byte-unbind 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3686
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3687 (defun byte-compile-save-restriction (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3688 (byte-compile-out 'byte-save-restriction 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3689 (byte-compile-body-do-effect (cdr form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3690 (byte-compile-out 'byte-unbind 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3691
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3692 (defun byte-compile-save-current-buffer (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3693 (if (byte-compile-version-cond byte-compile-emacs19-compatibility)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3694 ;; `save-current-buffer' special form is not available in XEmacs 19.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3695 (byte-compile-form
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3696 `(let ((_byte_compiler_save_buffer_emulation_closure_ (current-buffer)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3697 (unwind-protect
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3698 (progn ,@(cdr form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3699 (and (buffer-live-p _byte_compiler_save_buffer_emulation_closure_)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3700 (set-buffer _byte_compiler_save_buffer_emulation_closure_)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3701 (byte-compile-out 'byte-save-current-buffer 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3702 (byte-compile-body-do-effect (cdr form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3703 (byte-compile-out 'byte-unbind 1)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3704
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3705 (defun byte-compile-save-window-excursion (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3706 (byte-compile-push-constant
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3707 (byte-compile-top-level-body (cdr form) for-effect))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3708 (byte-compile-out 'byte-save-window-excursion 0))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3709
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3710 (defun byte-compile-with-output-to-temp-buffer (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3711 (byte-compile-form (car (cdr form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3712 (byte-compile-out 'byte-temp-output-buffer-setup 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3713 (byte-compile-body (cdr (cdr form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3714 (byte-compile-out 'byte-temp-output-buffer-show 0))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3715
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3716
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3717 ;;; top-level forms elsewhere
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3718
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3719 (byte-defop-compiler-1 defun)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3720 (byte-defop-compiler-1 defmacro)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3721 (byte-defop-compiler-1 defvar)
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
3722 (byte-defop-compiler-1 defconst byte-compile-defvar)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3723 (byte-defop-compiler-1 autoload)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3724 ;; According to Mly this can go now that lambda is a macro
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3725 ;(byte-defop-compiler-1 lambda byte-compile-lambda-form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3726 (byte-defop-compiler-1 defalias)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3727 (byte-defop-compiler-1 define-function)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3728
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3729 (defun byte-compile-defun (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3730 ;; This is not used for file-level defuns with doc strings.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3731 (byte-compile-two-args ; Use this to avoid byte-compile-fset's warning.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3732 (list 'fset (list 'quote (nth 1 form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3733 (byte-compile-byte-code-maker
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3734 (byte-compile-lambda (cons 'lambda (cdr (cdr form)))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3735 (byte-compile-discard)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3736 (byte-compile-constant (nth 1 form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3737
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3738 (defun byte-compile-defmacro (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3739 ;; This is not used for file-level defmacros with doc strings.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3740 (byte-compile-body-do-effect
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3741 (list (list 'fset (list 'quote (nth 1 form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3742 (let ((code (byte-compile-byte-code-maker
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3743 (byte-compile-lambda
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3744 (cons 'lambda (cdr (cdr form)))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3745 (if (eq (car-safe code) 'make-byte-code)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3746 (list 'cons ''macro code)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3747 (list 'quote (cons 'macro (eval code))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3748 (list 'quote (nth 1 form)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3749
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
3750 (defun byte-compile-defvar (form)
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
3751 ;; This is not used for file-level defvar/consts with doc strings:
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
3752 ;; byte-compile-file-form-defvar will be used in that case.
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
3753 (let ((var (nth 1 form))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3754 (value (nth 2 form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3755 (string (nth 3 form)))
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
3756 (if (> (length form) 4)
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
3757 (byte-compile-warn "%s used with too many args" (car form)))
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
3758 (if (memq 'free-vars byte-compile-warnings)
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
3759 (setq byte-compile-bound-variables
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
3760 (cons (cons var byte-compile-global-bit)
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
3761 byte-compile-bound-variables)))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3762 (byte-compile-body-do-effect
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
3763 (list (if (cdr (cdr form))
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
3764 (if (eq (car form) 'defconst)
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
3765 (list 'setq var value)
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
3766 (list 'or (list 'boundp (list 'quote var))
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
3767 (list 'setq var value))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3768 ;; Put the defined variable in this library's load-history entry
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
3769 ;; just as a real defvar would.
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
3770 (list 'setq 'current-load-list
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
3771 (list 'cons (list 'quote var)
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
3772 'current-load-list))
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
3773 (if string
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
3774 (list 'put (list 'quote var) ''variable-documentation string))
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
3775 (list 'quote var)))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3776
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3777 (defun byte-compile-autoload (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3778 (and (byte-compile-constp (nth 1 form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3779 (byte-compile-constp (nth 5 form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3780 (memq (eval (nth 5 form)) '(t macro)) ; macro-p
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3781 (not (fboundp (eval (nth 1 form))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3782 (byte-compile-warn
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
3783 "The compiler ignores `autoload' except at top level. You should
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3784 probably put the autoload of the macro `%s' at top-level."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3785 (eval (nth 1 form))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3786 (byte-compile-normal-call form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3787
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3788 ;; Lambda's in valid places are handled as special cases by various code.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3789 ;; The ones that remain are errors.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3790 ;; According to Mly this can go now that lambda is a macro
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3791 ;(defun byte-compile-lambda-form (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3792 ; (byte-compile-warn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3793 ; "`lambda' used in function position is invalid: probably you mean #'%s"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3794 ; (let ((print-escape-newlines t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3795 ; (print-level 4)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3796 ; (print-length 4))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3797 ; (prin1-to-string form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3798 ; (byte-compile-normal-call
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3799 ; (list 'signal ''error
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3800 ; (list 'quote (list "`lambda' used in function position" form)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3801
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3802 ;; Compile normally, but deal with warnings for the function being defined.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3803 (defun byte-compile-defalias (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3804 (if (and (consp (cdr form)) (consp (nth 1 form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3805 (eq (car (nth 1 form)) 'quote)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3806 (consp (cdr (nth 1 form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3807 (symbolp (nth 1 (nth 1 form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3808 (consp (nthcdr 2 form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3809 (consp (nth 2 form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3810 (eq (car (nth 2 form)) 'quote)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3811 (consp (cdr (nth 2 form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3812 (symbolp (nth 1 (nth 2 form))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3813 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3814 (byte-compile-defalias-warn (nth 1 (nth 1 form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3815 (nth 1 (nth 2 form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3816 (setq byte-compile-function-environment
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3817 (cons (cons (nth 1 (nth 1 form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3818 (nth 1 (nth 2 form)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3819 byte-compile-function-environment))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3820 (byte-compile-normal-call form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3821
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3822 (defun byte-compile-define-function (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3823 (byte-compile-defalias form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3824
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3825 ;; Turn off warnings about prior calls to the function being defalias'd.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3826 ;; This could be smarter and compare those calls with
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3827 ;; the function it is being aliased to.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3828 (defun byte-compile-defalias-warn (new alias)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3829 (let ((calls (assq new byte-compile-unresolved-functions)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3830 (if calls
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3831 (setq byte-compile-unresolved-functions
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3832 (delq calls byte-compile-unresolved-functions)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3833
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3834 ;;; tags
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3835
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3836 ;; Note: Most operations will strip off the 'TAG, but it speeds up
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3837 ;; optimization to have the 'TAG as a part of the tag.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3838 ;; Tags will be (TAG . (tag-number . stack-depth)).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3839 (defun byte-compile-make-tag ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3840 (list 'TAG (setq byte-compile-tag-number (1+ byte-compile-tag-number))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3841
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3842
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3843 (defun byte-compile-out-tag (tag)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3844 (push tag byte-compile-output)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3845 (if (cdr (cdr tag))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3846 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3847 ;; ## remove this someday
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3848 (and byte-compile-depth
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3849 (not (= (cdr (cdr tag)) byte-compile-depth))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3850 (error "Compiler bug: depth conflict at tag %d" (car (cdr tag))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3851 (setq byte-compile-depth (cdr (cdr tag))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3852 (setcdr (cdr tag) byte-compile-depth)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3853
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3854 (defun byte-compile-goto (opcode tag)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3855 (push (cons opcode tag) byte-compile-output)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3856 (setcdr (cdr tag) (if (memq opcode byte-goto-always-pop-ops)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3857 (1- byte-compile-depth)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3858 byte-compile-depth))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3859 (setq byte-compile-depth (and (not (eq opcode 'byte-goto))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3860 (1- byte-compile-depth))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3861
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3862 (defun byte-compile-out (opcode offset)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3863 (push (cons opcode offset) byte-compile-output)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3864 (case opcode
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3865 (byte-call
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3866 (setq byte-compile-depth (- byte-compile-depth offset)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3867 (byte-return
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3868 ;; This is actually an unnecessary case, because there should be
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3869 ;; no more opcodes behind byte-return.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3870 (setq byte-compile-depth nil))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3871 (t
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3872 (setq byte-compile-depth (+ byte-compile-depth
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3873 (or (aref byte-stack+-info
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3874 (symbol-value opcode))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3875 (- (1- offset))))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3876 byte-compile-maxdepth (max byte-compile-depth
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3877 byte-compile-maxdepth))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3878 ;;(if (< byte-compile-depth 0) (error "Compiler error: stack underflow"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3879 )
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3880
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3881
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3882 ;;; call tree stuff
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3883
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3884 (defun byte-compile-annotate-call-tree (form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3885 (let (entry)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3886 ;; annotate the current call
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3887 (if (setq entry (assq (car form) byte-compile-call-tree))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3888 (or (memq byte-compile-current-form (nth 1 entry)) ;callers
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3889 (setcar (cdr entry)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3890 (cons byte-compile-current-form (nth 1 entry))))
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3891 (push (list (car form) (list byte-compile-current-form) nil)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3892 byte-compile-call-tree))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3893 ;; annotate the current function
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3894 (if (setq entry (assq byte-compile-current-form byte-compile-call-tree))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3895 (or (memq (car form) (nth 2 entry)) ;called
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3896 (setcar (cdr (cdr entry))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3897 (cons (car form) (nth 2 entry))))
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3898 (push (list byte-compile-current-form nil (list (car form)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3899 byte-compile-call-tree))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3900
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3901 ;; Renamed from byte-compile-report-call-tree
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3902 ;; to avoid interfering with completion of byte-compile-file.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3903 ;;;###autoload
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3904 (defun display-call-tree (&optional filename)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3905 "Display a call graph of a specified file.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3906 This lists which functions have been called, what functions called
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3907 them, and what functions they call. The list includes all functions
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3908 whose definitions have been compiled in this Emacs session, as well as
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3909 all functions called by those functions.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3910
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3911 The call graph does not include macros, inline functions, or
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3912 primitives that the byte-code interpreter knows about directly \(eq,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3913 cons, etc.\).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3914
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3915 The call tree also lists those functions which are not known to be called
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3916 \(that is, to which no calls have been compiled\), and which cannot be
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3917 invoked interactively."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3918 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3919 (message "Generating call tree...")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3920 (with-output-to-temp-buffer "*Call-Tree*"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3921 (set-buffer "*Call-Tree*")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3922 (erase-buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3923 (message "Generating call tree... (sorting on %s)"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3924 byte-compile-call-tree-sort)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3925 (insert "Call tree for "
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3926 (cond ((null byte-compile-current-file) (or filename "???"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3927 ((stringp byte-compile-current-file)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3928 byte-compile-current-file)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3929 (t (buffer-name byte-compile-current-file)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3930 " sorted on "
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3931 (prin1-to-string byte-compile-call-tree-sort)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3932 ":\n\n")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3933 (if byte-compile-call-tree-sort
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3934 (setq byte-compile-call-tree
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3935 (sort byte-compile-call-tree
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3936 (cond
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3937 ((eq byte-compile-call-tree-sort 'callers)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3938 #'(lambda (x y) (< (length (nth 1 x))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3939 (length (nth 1 y)))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3940 ((eq byte-compile-call-tree-sort 'calls)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3941 #'(lambda (x y) (< (length (nth 2 x))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3942 (length (nth 2 y)))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3943 ((eq byte-compile-call-tree-sort 'calls+callers)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3944 #'(lambda (x y) (< (+ (length (nth 1 x))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3945 (length (nth 2 x)))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3946 (+ (length (nth 1 y))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3947 (length (nth 2 y))))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3948 ((eq byte-compile-call-tree-sort 'name)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3949 #'(lambda (x y) (string< (car x)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
3950 (car y))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3951 (t (error
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3952 "`byte-compile-call-tree-sort': `%s' - unknown sort mode"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3953 byte-compile-call-tree-sort))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3954 (message "Generating call tree...")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3955 (let ((rest byte-compile-call-tree)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3956 (b (current-buffer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3957 f p
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3958 callers calls)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3959 (while rest
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3960 (prin1 (car (car rest)) b)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3961 (setq callers (nth 1 (car rest))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3962 calls (nth 2 (car rest)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3963 (insert "\t"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3964 (cond ((not (fboundp (setq f (car (car rest)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3965 (if (null f)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3966 " <top level>";; shouldn't insert nil then, actually -sk
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3967 " <not defined>"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3968 ((subrp (setq f (symbol-function f)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3969 " <subr>")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3970 ((symbolp f)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3971 (format " ==> %s" f))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3972 ((compiled-function-p f)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3973 "<compiled function>")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3974 ((not (consp f))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3975 "<malformed function>")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3976 ((eq 'macro (car f))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3977 (if (or (compiled-function-p (cdr f))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3978 (assq 'byte-code (cdr (cdr (cdr f)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3979 " <compiled macro>"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3980 " <macro>"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3981 ((assq 'byte-code (cdr (cdr f)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3982 "<compiled lambda>")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3983 ((eq 'lambda (car f))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3984 "<function>")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3985 (t "???"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3986 (format " (%d callers + %d calls = %d)"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3987 ;; Does the optimizer eliminate common subexpressions?-sk
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3988 (length callers)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3989 (length calls)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3990 (+ (length callers) (length calls)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3991 "\n")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3992 (if callers
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3993 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3994 (insert " called by:\n")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3995 (setq p (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3996 (insert " " (if (car callers)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3997 (mapconcat 'symbol-name callers ", ")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3998 "<top level>"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3999 (let ((fill-prefix " "))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4000 (fill-region-as-paragraph p (point)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4001 (if calls
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4002 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4003 (insert " calls:\n")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4004 (setq p (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4005 (insert " " (mapconcat 'symbol-name calls ", "))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4006 (let ((fill-prefix " "))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4007 (fill-region-as-paragraph p (point)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4008 (insert "\n")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4009 (setq rest (cdr rest)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4010
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4011 (message "Generating call tree...(finding uncalled functions...)")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4012 (setq rest byte-compile-call-tree)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4013 (let ((uncalled nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4014 (while rest
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4015 (or (nth 1 (car rest))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4016 (null (setq f (car (car rest))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4017 (byte-compile-fdefinition f t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4018 (commandp (byte-compile-fdefinition f nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4019 (setq uncalled (cons f uncalled)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4020 (setq rest (cdr rest)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4021 (if uncalled
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4022 (let ((fill-prefix " "))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4023 (insert "Noninteractive functions not known to be called:\n ")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4024 (setq p (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4025 (insert (mapconcat 'symbol-name (nreverse uncalled) ", "))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4026 (fill-region-as-paragraph p (point)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4027 )
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4028 (message "Generating call tree...done.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4029 ))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4030
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4031
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4032 ;;; by crl@newton.purdue.edu
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4033 ;;; Only works noninteractively.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4034 ;;;###autoload
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4035 (defun batch-byte-compile ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4036 "Run `byte-compile-file' on the files remaining on the command line.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4037 Use this from the command line, with `-batch';
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4038 it won't work in an interactive Emacs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4039 Each file is processed even if an error occurred previously.
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 259
diff changeset
4040 For example, invoke \"xemacs -batch -f batch-byte-compile $emacs/ ~/*.el\""
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4041 ;; command-line-args-left is what is left of the command line (from
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4042 ;; startup.el)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4043 (defvar command-line-args-left) ;Avoid 'free variable' warning
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4044 (if (not noninteractive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4045 (error "`batch-byte-compile' is to be used only with -batch"))
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
4046 (let ((error nil))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4047 (while command-line-args-left
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4048 (if (file-directory-p (expand-file-name (car command-line-args-left)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4049 (let ((files (directory-files (car command-line-args-left)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4050 source dest)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4051 (while files
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4052 (if (and (string-match emacs-lisp-file-regexp (car files))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4053 (not (auto-save-file-name-p (car files)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4054 (setq source (expand-file-name
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4055 (car files)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4056 (car command-line-args-left)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4057 (setq dest (byte-compile-dest-file source))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4058 (file-exists-p dest)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4059 (file-newer-than-file-p source dest))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4060 (if (null (batch-byte-compile-1 source))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4061 (setq error t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4062 (setq files (cdr files))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4063 (if (null (batch-byte-compile-1 (car command-line-args-left)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4064 (setq error t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4065 (setq command-line-args-left (cdr command-line-args-left)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4066 (message "Done")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4067 (kill-emacs (if error 1 0))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4068
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4069 (defun batch-byte-compile-1 (file)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4070 (condition-case err
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4071 (progn (byte-compile-file file) t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4072 (error
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4073 (princ ">>Error occurred processing ")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4074 (princ file)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4075 (princ ": ")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4076 (if (fboundp 'display-error) ; XEmacs 19.8+
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4077 (display-error err nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4078 (princ (or (get (car err) 'error-message) (car err)))
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
4079 (mapcar #'(lambda (x) (princ " ") (prin1 x)) (cdr err)))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4080 (princ "\n")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4081 nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4082
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4083 ;;;###autoload
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4084 (defun batch-byte-recompile-directory-norecurse ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4085 "Same as `batch-byte-recompile-directory' but without recursion."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4086 (setq byte-recompile-directory-recursively nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4087 (batch-byte-recompile-directory))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4088
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4089 ;;;###autoload
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4090 (defun batch-byte-recompile-directory ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4091 "Runs `byte-recompile-directory' on the dirs remaining on the command line.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4092 Must be used only with `-batch', and kills Emacs on completion.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4093 For example, invoke `xemacs -batch -f batch-byte-recompile-directory .'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4094 ;; command-line-args-left is what is left of the command line (startup.el)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4095 (defvar command-line-args-left) ;Avoid 'free variable' warning
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4096 (if (not noninteractive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4097 (error "batch-byte-recompile-directory is to be used only with -batch"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4098 (or command-line-args-left
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4099 (setq command-line-args-left '(".")))
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
4100 (let ((byte-recompile-directory-ignore-errors-p t))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4101 (while command-line-args-left
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4102 (byte-recompile-directory (car command-line-args-left))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4103 (setq command-line-args-left (cdr command-line-args-left))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4104 (kill-emacs 0))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4105
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4106 (make-obsolete 'elisp-compile-defun 'compile-defun)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4107 (make-obsolete 'byte-compile-report-call-tree 'display-call-tree)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4108
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4109 ;; other make-obsolete calls in obsolete.el.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4110
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4111 (provide 'byte-compile)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4112 (provide 'bytecomp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4113
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4114
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4115 ;;; report metering (see the hacks in bytecode.c)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4116
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4117 (if (boundp 'byte-code-meter)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4118 (defun byte-compile-report-ops ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4119 (defvar byte-code-meter)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4120 (with-output-to-temp-buffer "*Meter*"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4121 (set-buffer "*Meter*")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4122 (let ((i 0) n op off)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4123 (while (< i 256)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4124 (setq n (aref (aref byte-code-meter 0) i)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4125 off nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4126 (if t ;(not (zerop n))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4127 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4128 (setq op i)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4129 (setq off nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4130 (cond ((< op byte-nth)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4131 (setq off (logand op 7))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4132 (setq op (logand op 248)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4133 ((>= op byte-constant)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4134 (setq off (- op byte-constant)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4135 op byte-constant)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4136 (setq op (aref byte-code-vector op))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4137 (insert (format "%-4d" i))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4138 (insert (symbol-name op))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4139 (if off (insert " [" (int-to-string off) "]"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4140 (indent-to 40)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4141 (insert (int-to-string n) "\n")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4142 (setq i (1+ i)))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4143
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4144
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4145 ;; To avoid "lisp nesting exceeds max-lisp-eval-depth" when bytecomp compiles
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4146 ;; itself, compile some of its most used recursive functions (at load time).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4147 ;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4148 (eval-when-compile
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4149 (or (compiled-function-p (symbol-function 'byte-compile-form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4150 (assq 'byte-code (symbol-function 'byte-compile-form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4151 (let ((byte-optimize nil) ; do it fast
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4152 (byte-compile-warnings nil))
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
4153 (mapcar #'(lambda (x)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
4154 (or noninteractive (message "compiling %s..." x))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
4155 (byte-compile x)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
4156 (or noninteractive (message "compiling %s...done" x)))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4157 '(byte-compile-normal-call
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4158 byte-compile-form
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4159 byte-compile-body
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4160 ;; Inserted some more than necessary, to speed it up.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4161 byte-compile-top-level
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4162 byte-compile-out-toplevel
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4163 byte-compile-constant
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4164 byte-compile-variable-ref))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4165 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4166
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4167 ;;; bytecomp.el ends here