annotate lisp/bytecomp/bytecomp.el @ 16:0293115a14e9 r19-15b91

Import from CVS: tag r19-15b91
author cvs
date Mon, 13 Aug 2007 08:49:20 +0200
parents ac2d302a0011
children 859a2309aef8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; bytecomp.el --- compilation of Lisp code into byte code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;;; Copyright (C) 1985-1987, 1991-1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Author: Jamie Zawinski <jwz@lucid.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Hallvard Furuseth <hbf@ulrik.uio.no>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Keywords: internal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; Subsequently modified by RMS and others.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 (defconst byte-compile-version (purecopy "2.25; 1-Sep-94."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;; You should have received a copy of the GNU General Public License
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
26 ;; along with XEmacs; see the file COPYING. If not, write to the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
28 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;; Synched up with: FSF 19.30.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; The Emacs Lisp byte compiler. This crunches lisp source into a sort
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; of p-code which takes up less space and can be interpreted faster.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; The user entry points are byte-compile-file and byte-recompile-directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;;; ========================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;; Entry points:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;;; byte-recompile-directory, byte-compile-file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;;; batch-byte-compile, batch-byte-recompile-directory,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;;; byte-compile, compile-defun,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;;; display-call-tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;;; RMS says:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;;; (byte-compile-buffer and byte-compile-and-load-file were turned off
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;;; because they are not terribly useful and get in the way of completion.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;;; But I'm leaving them. --ben
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;;; This version of the byte compiler has the following improvements:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;;; + optimization of compiled code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;;; - removal of unreachable code;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;;; - removal of calls to side-effectless functions whose return-value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;;; is unused;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;;; - compile-time evaluation of safe constant forms, such as (consp nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;;; and (ash 1 6);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;;; - open-coding of literal lambdas;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;;; - peephole optimization of emitted code;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;;; - trivial functions are left uncompiled for speed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;;; + support for inline functions;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;;; + compile-time evaluation of arbitrary expressions;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;;; + compile-time warning messages for:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;;; - functions being redefined with incompatible arglists;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;;; - functions being redefined as macros, or vice-versa;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;;; - functions or macros defined multiple times in the same file;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;;; - functions being called with the incorrect number of arguments;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;;; - functions being called which are not defined globally, in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;;; file, or as autoloads;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;;; - assignment and reference of undeclared free variables;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;;; - various syntax errors;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;;; + correct compilation of nested defuns, defmacros, defvars and defsubsts;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;;; + correct compilation of top-level uses of macros;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;;; + the ability to generate a histogram of functions called.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;;; User customization variables:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;;; byte-compile-verbose Whether to report the function currently being
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;;; compiled in the minibuffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ;;; byte-optimize Whether to do optimizations; this may be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;;; t, nil, 'source, or 'byte;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ;;; byte-optimize-log Whether to report (in excruciating detail)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;;; exactly which optimizations have been made.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;;; This may be t, nil, 'source, or 'byte;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;;; byte-compile-error-on-warn Whether to stop compilation when a warning is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;;; produced;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;;; byte-compile-delete-errors Whether the optimizer may delete calls or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ;;; variable references that are side-effect-free
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ;;; except that they may return an error.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ;;; byte-compile-generate-call-tree Whether to generate a histogram of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;;; function calls. This can be useful for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 ;;; finding unused functions, as well as simple
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;;; performance metering.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ;;; byte-compile-warnings List of warnings to issue, or t. May contain
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 ;;; 'free-vars (references to variables not in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 ;;; current lexical scope)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 ;;; 'unused-vars (non-global variables bound but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 ;;; not referenced)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 ;;; 'unresolved (calls to unknown functions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ;;; 'callargs (lambda calls with args that don't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 ;;; match the lambda's definition)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 ;;; 'redefine (function cell redefined from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 ;;; a macro to a lambda or vice versa,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 ;;; or redefined to take other args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 ;;; 'obsolete (obsolete variables and functions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 ;;; (RMS calls the following option byte-compile-compatibility but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 ;;; our name is better)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ;;; byte-compile-emacs18-compatibility Whether the compiler should
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 ;;; generate .elc files which can be loaded into
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 ;;; generic emacs 18.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 ;;; emacs-lisp-file-regexp Regexp for the extension of source-files;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 ;;; see also the function byte-compile-dest-file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 ;;; byte-compile-overwrite-file If nil, delete old .elc files before saving.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ;;; Most of the above parameters can also be set on a file-by-file basis; see
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;;; the documentation of the `byte-compiler-options' macro.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 ;;; New Features:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 ;;; o The form `defsubst' is just like `defun', except that the function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 ;;; generated will be open-coded in compiled code which uses it. This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 ;;; means that no function call will be generated, it will simply be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 ;;; spliced in. Lisp functions calls are very slow, so this can be a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 ;;; big win.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ;;; You can generally accomplish the same thing with `defmacro', but in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 ;;; that case, the defined procedure can't be used as an argument to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 ;;; mapcar, etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 ;;; o You can make a given function be inline even if it has already been
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 ;;; defined with `defun' by using the `proclaim-inline' form like so:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 ;;; (proclaim-inline my-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 ;;; This is, in fact, exactly what `defsubst' does. To make a function no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 ;;; longer be inline, you must use `proclaim-notinline'. Beware that if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 ;;; you define a function with `defsubst' and later redefine it with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 ;;; `defun', it will still be open-coded until you use proclaim-notinline.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 ;;; o You can also open-code one particular call to a function without
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 ;;; open-coding all calls. Use the 'inline' form to do this, like so:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 ;;; (inline (foo 1 2 3)) ;; `foo' will be open-coded
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ;;; or...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 ;;; (inline ;; `foo' and `baz' will be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 ;;; (foo 1 2 3 (bar 5)) ;; open-coded, but `bar' will not.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 ;;; (baz 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 ;;; o It is possible to open-code a function in the same file it is defined
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 ;;; in without having to load that file before compiling it. the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 ;;; byte-compiler has been modified to remember function definitions in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 ;;; the compilation environment in the same way that it remembers macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 ;;; definitions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 ;;; o Forms like ((lambda ...) ...) are open-coded.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 ;;; o The form `eval-when-compile' is like progn, except that the body
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 ;;; is evaluated at compile-time. When it appears at top-level, this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 ;;; is analogous to the Common Lisp idiom (eval-when (compile) ...).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 ;;; When it does not appear at top-level, it is similar to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 ;;; Common Lisp #. reader macro (but not in interpreted code).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 ;;; o The form `eval-and-compile' is similar to eval-when-compile, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 ;;; the whole form is evalled both at compile-time and at run-time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 ;;; o The command M-x byte-compile-and-load-file does what you'd think.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 ;;; o The command compile-defun is analogous to eval-defun.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 ;;; o If you run byte-compile-file on a filename which is visited in a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 ;;; buffer, and that buffer is modified, you are asked whether you want
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 ;;; to save the buffer before compiling.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 ;;; o You can add this to /etc/magic to make file(1) recognise the files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 ;;; generated by this compiler:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 ;;; 0 string ;ELC GNU Emacs Lisp compiled file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 ;;; >4 byte x version %d
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 ;;; TO DO:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 ;;; o Should implement declarations and proclamations, notably special,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 ;;; unspecial, and ignore. Do this in such a way as to not break cl.el.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 ;;; o The bound-but-not-used warnings are not issued for variables whose
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 ;;; bindings were established in the arglist, due to the lack of an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 ;;; ignore declaration. Once ignore exists, this should be turned on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 ;;; o Warn about functions and variables defined but not used?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 ;;; Maybe add some kind of `export' declaration for this?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 ;;; (With interactive functions being automatically exported?)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 ;;; o Any reference to a variable, even one which is a no-op, will cause
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 ;;; the warning not to be given. Possibly we could use the for-effect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 ;;; flag to determine when this reference is useless; possibly more
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 ;;; complex flow analysis would be necessary.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 ;;; o If the optimizer deletes a variable reference, we might be left with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 ;;; a bound-but-not-referenced warning. Generally this is ok, but not if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 ;;; it's a synergistic result of macroexpansion. Need some way to note
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 ;;; that a varref is being optimized away? Of course it would be nice to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 ;;; optimize away the binding too, someday, but it's unsafe today.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 ;;; o Is it time to finally delete all of that egregious v18 compatibility
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 ;;; code yet?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 ;;; o (See byte-optimize.el for the optimization TODO list.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (require 'backquote)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (or (fboundp 'defsubst)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 ;; This really ought to be loaded already!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (load-library "bytecomp-runtime"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (eval-when-compile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (defvar byte-compile-single-version nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 "If this is true, the choice of emacs version (v18 or v19) byte-codes will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 be hard-coded into bytecomp when it compiles itself. If the compiler itself
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 is compiled with optimization, this causes a speedup.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (cond (byte-compile-single-version
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (defmacro byte-compile-single-version () t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (defmacro byte-compile-version-cond (cond) (list 'quote (eval cond))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (defmacro byte-compile-single-version () nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (defmacro byte-compile-version-cond (cond) cond)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 ;;; The crud you see scattered through this file of the form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 ;;; (or (and (boundp 'epoch::version) epoch::version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 ;;; (string-lessp emacs-version "19"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 ;;; is because the Epoch folks couldn't be bothered to follow the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 ;;; normal emacs version numbering convention.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (defvar emacs-lisp-file-regexp (if (eq system-type 'vax-vms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (purecopy "\\.EL\\(;[0-9]+\\)?$")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (purecopy "\\.el$"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 "*Regexp which matches Emacs Lisp source files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 You may want to redefine `byte-compile-dest-file' if you change this.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 ;; This enables file name handlers such as jka-compr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 ;; to remove parts of the file name that should not be copied
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 ;; through to the output file name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (defun byte-compiler-base-file-name (filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (let ((handler (find-file-name-handler filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 'byte-compiler-base-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (if handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (funcall handler 'byte-compiler-base-file-name filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (or (fboundp 'byte-compile-dest-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 ;; The user may want to redefine this along with emacs-lisp-file-regexp,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 ;; so only define it if it is undefined.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (defun byte-compile-dest-file (filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 "Convert an Emacs Lisp source file name to a compiled file name."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (setq filename (byte-compiler-base-file-name filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (setq filename (file-name-sans-versions filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (cond ((eq system-type 'vax-vms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (concat (substring filename 0 (string-match ";" filename)) "c"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 ((string-match emacs-lisp-file-regexp filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (concat (substring filename 0 (match-beginning 0)) ".elc"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (t (concat filename ".elc")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 ;; This can be the 'byte-compile property of any symbol.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (autoload 'byte-compile-inline-expand "byte-optimize")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 ;; This is the entrypoint to the lapcode optimizer pass1.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (autoload 'byte-optimize-form "byte-optimize")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 ;; This is the entrypoint to the lapcode optimizer pass2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (autoload 'byte-optimize-lapcode "byte-optimize")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (autoload 'byte-compile-unfold-lambda "byte-optimize")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 ;; This is the entry point to the decompiler, which is used by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 ;; disassembler. The disassembler just requires 'byte-compile, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 ;; that doesn't define this function, so this seems to be a reasonable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 ;; thing to do.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (autoload 'byte-decompile-bytecode "byte-opt")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (defvar byte-compile-verbose
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (and (not noninteractive) (> (device-baud-rate) search-slow-speed))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 "*Non-nil means print messages describing progress of byte-compiler.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (defvar byte-compile-emacs18-compatibility nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 "*Non-nil means generate output that can run in Emacs 18.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (defvar byte-optimize t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 "*Enables optimization in the byte compiler.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 nil means don't do any optimization.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 t means do all optimizations.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 `source' means do source-level optimizations only.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 `byte' means do code-level optimizations only.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (defvar byte-compile-delete-errors t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 "*If non-nil, the optimizer may delete forms that may signal an error.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 This includes variable references and calls to functions such as `car'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 ;; XEmacs addition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (defvar byte-compile-new-bytecodes nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 "This is completely ignored. It is only around for backwards
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 compatibility.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
295
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 ;; FSF enables byte-compile-dynamic-docstrings but not byte-compile-dynamic
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 ;; by default. This would be a reasonable conservative approach except
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 ;; for the fact that if you enable either of these, you get incompatible
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 ;; byte code that can't be read by XEmacs 19.13 or before or FSF 19.28 or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 ;; before.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 ;; Therefore, neither is enabled for 19.14.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (defvar byte-compile-dynamic nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 "*If non-nil, compile function bodies so they load lazily.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 They are hidden comments in the compiled file, and brought into core when the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 function is called.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 To enable this option, make it a file-local variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 in the source file you want it to apply to.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 For example, add -*-byte-compile-dynamic: t;-*- on the first line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 When this option is true, if you load the compiled file and then move it,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 the functions you loaded will not be able to run.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (defvar byte-compile-dynamic-docstrings nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 "*If non-nil, compile doc strings for lazy access.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 We bury the doc strings of functions and variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 inside comments in the file, and bring them into core only when they
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 are actually needed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 When this option is true, if you load the compiled file and then move it,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 you won't be able to find the documentation of anything in that file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 To disable this option for a certain file, make it a file-local variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 in the source file. For example, add this to the first line:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 -*-byte-compile-dynamic-docstrings:nil;-*-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 You can also set the variable globally.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 This option is enabled by default because it reduces Emacs memory usage.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (defvar byte-optimize-log nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 "*If true, the byte-compiler will log its optimizations into *Compile-Log*.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 If this is 'source, then only source-level optimizations will be logged.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 If it is 'byte, then only byte-level optimizations will be logged.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (defvar byte-compile-error-on-warn nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 "*If true, the byte-compiler reports warnings with `error'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 ;; byte-compile-warning-types in FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (defvar byte-compile-default-warnings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 '(redefine callargs free-vars unresolved unused-vars obsolete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 "*The warnings used when byte-compile-warnings is t.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (defvar byte-compile-warnings t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 "*List of warnings that the compiler should issue (t for the default set).
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
347 Elements of the list may be:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 free-vars references to variables not in the current lexical scope.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 unused-vars references to non-global variables bound but not referenced.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 unresolved calls to unknown functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 callargs lambda calls with args that don't match the definition.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 redefine function cell redefined from a macro to a lambda or vice
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 versa, or redefined to take a different number of arguments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 obsolete use of an obsolete function or variable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 The default set is specified by `byte-compile-default-warnings' and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 normally encompasses all possible warnings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 See also the macro `byte-compiler-options'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (defvar byte-compile-generate-call-tree nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 "*Non-nil means collect call-graph information when compiling.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 This records functions were called and from where.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 If the value is t, compilation displays the call graph when it finishes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 If the value is neither t nor nil, compilation asks you whether to display
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 the graph.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 The call tree only lists functions called, not macros used. Those functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 which the byte-code interpreter knows about directly (eq, cons, etc.) are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 not reported.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 The call tree also lists those functions which are not known to be called
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 \(that is, to which no calls have been compiled). Functions which can be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 invoked interactively are excluded from this list.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (defconst byte-compile-call-tree nil "Alist of functions and their call tree.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 Each element looks like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 \(FUNCTION CALLERS CALLS\)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 where CALLERS is a list of functions that call FUNCTION, and CALLS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 is a list of functions for which calls were generated while compiling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 FUNCTION.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (defvar byte-compile-call-tree-sort 'name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 "*If non-nil, sort the call tree.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 The values `name', `callers', `calls', `calls+callers'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 specify different fields to sort on.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (defvar byte-compile-overwrite-file t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 "If nil, old .elc files are deleted before the new is saved, and .elc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 files will have the same modes as the corresponding .el file. Otherwise,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 existing .elc files will simply be overwritten, and the existing modes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 will not be changed. If this variable is nil, then an .elc file which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 is a symbolic link will be turned into a normal file, instead of the file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 which the link points to being overwritten.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 (defvar byte-recompile-directory-ignore-errors-p nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 "If true, then `byte-recompile-directory' will continue compiling even
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 when an error occurs in a file. This is bound to t by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 `batch-byte-recompile-directory'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (defvar byte-recompile-directory-recursively t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 "*If true, then `byte-recompile-directory' will recurse on subdirectories.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (defvar byte-compile-constants nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 "list of all constants encountered during compilation of this form")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (defvar byte-compile-variables nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 "list of all variables encountered during compilation of this form")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (defvar byte-compile-bound-variables nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 "Alist of variables bound in the context of the current form,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 that is, the current lexical environment. This list lives partly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 on the specbind stack. The cdr of each cell is an integer bitmask.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (defconst byte-compile-referenced-bit 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (defconst byte-compile-assigned-bit 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (defconst byte-compile-arglist-bit 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (defconst byte-compile-global-bit 8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (defvar byte-compile-free-references)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (defvar byte-compile-free-assignments)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (defvar byte-compiler-error-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (defconst byte-compile-initial-macro-environment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (purecopy
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 '((byte-compiler-options . (lambda (&rest forms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (apply 'byte-compiler-options-handler forms)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (eval-when-compile . (lambda (&rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (list 'quote (eval (byte-compile-top-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (cons 'progn body))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (eval-and-compile . (lambda (&rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (eval (cons 'progn body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (cons 'progn body)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 "The default macro-environment passed to macroexpand by the compiler.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 Placing a macro here will cause a macro to have different semantics when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 expanded by the compiler as when expanded by the interpreter.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (defvar byte-compile-macro-environment byte-compile-initial-macro-environment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 "Alist of macros defined in the file being compiled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 Each element looks like (MACRONAME . DEFINITION). It is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 \(MACRONAME . nil) when a macro is redefined as a function.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (defvar byte-compile-function-environment nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 "Alist of functions defined in the file being compiled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 This is so we can inline them when necessary.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 Each element looks like (FUNCTIONNAME . DEFINITION). It is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 \(FUNCTIONNAME . nil) when a function is redefined as a macro.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (defvar byte-compile-autoload-environment nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 "Alist of functions and macros defined by autoload in the file being compiled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 This is so we can suppress warnings about calls to these functions, even though
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 they do not have `real' definitions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 Each element looks like (FUNCTIONNAME . CALL-TO-AUTOLOAD).")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (defvar byte-compile-unresolved-functions nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 "Alist of undefined functions to which calls have been compiled (used for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 warnings when the function is later defined with incorrect args).")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (defvar byte-compile-file-domain) ; domain of file being compiled
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (defvar byte-compile-tag-number 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (defvar byte-compile-output nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 "Alist describing contents to put in byte code string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 Each element is (INDEX . VALUE)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (defvar byte-compile-depth 0 "Current depth of execution stack.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (defvar byte-compile-maxdepth 0 "Maximum depth of execution stack.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 ;;; The byte codes; this information is duplicated in bytecomp.c
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (defconst byte-code-vector nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 "An array containing byte-code names indexed by byte-code values.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (defconst byte-stack+-info nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 "An array with the stack adjustment for each byte-code.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (defmacro byte-defop (opcode stack-adjust opname &optional docstring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 ;; This is a speed-hack for building the byte-code-vector at compile-time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 ;; We fill in the vector at macroexpand-time, and then after the last call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 ;; to byte-defop, we write the vector out as a constant instead of writing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 ;; out a bunch of calls to aset.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 ;; Actually, we don't fill in the vector itself, because that could make
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 ;; it problematic to compile big changes to this compiler; we store the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 ;; values on its plist, and remove them later in -extrude.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (let ((v1 (or (get 'byte-code-vector 'tmp-compile-time-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (put 'byte-code-vector 'tmp-compile-time-value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (make-vector 256 nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (v2 (or (get 'byte-stack+-info 'tmp-compile-time-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (put 'byte-stack+-info 'tmp-compile-time-value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (make-vector 256 nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (aset v1 opcode opname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (aset v2 opcode stack-adjust))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (if docstring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (list 'defconst opname opcode (concat "Byte code opcode " docstring "."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (list 'defconst opname opcode)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (defmacro byte-extrude-byte-code-vectors ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (prog1 (list 'setq 'byte-code-vector
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (get 'byte-code-vector 'tmp-compile-time-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 'byte-stack+-info
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (get 'byte-stack+-info 'tmp-compile-time-value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 ;; emacs-18 has no REMPROP.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (put 'byte-code-vector 'tmp-compile-time-value nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (put 'byte-stack+-info 'tmp-compile-time-value nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 ;; unused: 0-7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 ;; These opcodes are special in that they pack their argument into the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 ;; opcode word.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (byte-defop 8 1 byte-varref "for variable reference")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (byte-defop 16 -1 byte-varset "for setting a variable")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (byte-defop 24 -1 byte-varbind "for binding a variable")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (byte-defop 32 0 byte-call "for calling a function")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (byte-defop 40 0 byte-unbind "for unbinding special bindings")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 ;; codes 8-47 are consumed by the preceding opcodes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 ;; unused: 48-55
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (byte-defop 56 -1 byte-nth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (byte-defop 57 0 byte-symbolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (byte-defop 58 0 byte-consp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (byte-defop 59 0 byte-stringp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (byte-defop 60 0 byte-listp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (byte-defop 61 -1 byte-eq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (byte-defop 62 -1 byte-memq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (byte-defop 63 0 byte-not)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 (byte-defop 64 0 byte-car)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (byte-defop 65 0 byte-cdr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 (byte-defop 66 -1 byte-cons)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (byte-defop 67 0 byte-list1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (byte-defop 68 -1 byte-list2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 (byte-defop 69 -2 byte-list3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 (byte-defop 70 -3 byte-list4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (byte-defop 71 0 byte-length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 (byte-defop 72 -1 byte-aref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 (byte-defop 73 -2 byte-aset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (byte-defop 74 0 byte-symbol-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (byte-defop 75 0 byte-symbol-function) ; this was commented out
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (byte-defop 76 -1 byte-set)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (byte-defop 77 -1 byte-fset) ; this was commented out
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 (byte-defop 78 -1 byte-get)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (byte-defop 79 -2 byte-substring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 (byte-defop 80 -1 byte-concat2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 (byte-defop 81 -2 byte-concat3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 (byte-defop 82 -3 byte-concat4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (byte-defop 83 0 byte-sub1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (byte-defop 84 0 byte-add1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 (byte-defop 85 -1 byte-eqlsign)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 (byte-defop 86 -1 byte-gtr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (byte-defop 87 -1 byte-lss)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 (byte-defop 88 -1 byte-leq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 (byte-defop 89 -1 byte-geq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 (byte-defop 90 -1 byte-diff)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (byte-defop 91 0 byte-negate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 (byte-defop 92 -1 byte-plus)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 (byte-defop 93 -1 byte-max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 (byte-defop 94 -1 byte-min)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 (byte-defop 95 -1 byte-mult) ; v19 only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 (byte-defop 96 1 byte-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 (byte-defop 97 1 byte-mark-OBSOLETE) ; no longer generated as of v18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 (byte-defop 98 0 byte-goto-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 (byte-defop 99 0 byte-insert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 (byte-defop 100 1 byte-point-max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 (byte-defop 101 1 byte-point-min)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 (byte-defop 102 0 byte-char-after)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 (byte-defop 103 1 byte-following-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 (byte-defop 104 1 byte-preceding-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 (byte-defop 105 1 byte-current-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 (byte-defop 106 0 byte-indent-to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 (byte-defop 107 0 byte-scan-buffer-OBSOLETE) ; no longer generated as of v18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 (byte-defop 108 1 byte-eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 (byte-defop 109 1 byte-eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 (byte-defop 110 1 byte-bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 (byte-defop 111 1 byte-bobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 (byte-defop 112 1 byte-current-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 (byte-defop 113 0 byte-set-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 (byte-defop 114 1 byte-read-char-OBSOLETE)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (byte-defop 115 0 byte-set-mark-OBSOLETE)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (byte-defop 116 1 byte-interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 ;; These ops are new to v19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 (byte-defop 117 0 byte-forward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 (byte-defop 118 0 byte-forward-word)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 (byte-defop 119 -1 byte-skip-chars-forward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (byte-defop 120 -1 byte-skip-chars-backward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 (byte-defop 121 0 byte-forward-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 (byte-defop 122 0 byte-char-syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 (byte-defop 123 -1 byte-buffer-substring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 (byte-defop 124 -1 byte-delete-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 (byte-defop 125 -1 byte-narrow-to-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 (byte-defop 126 1 byte-widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 (byte-defop 127 0 byte-end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 ;; unused: 128
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 ;; These store their argument in the next two bytes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 (byte-defop 129 1 byte-constant2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 "for reference to a constant with vector index >= byte-constant-limit")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 (byte-defop 130 0 byte-goto "for unconditional jump")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (byte-defop 131 -1 byte-goto-if-nil "to pop value and jump if it's nil")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 (byte-defop 132 -1 byte-goto-if-not-nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 "to pop value and jump if it's not nil")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 (byte-defop 133 -1 byte-goto-if-nil-else-pop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 "to examine top-of-stack, jump and don't pop it if it's nil,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 otherwise pop it")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 (byte-defop 134 -1 byte-goto-if-not-nil-else-pop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 "to examine top-of-stack, jump and don't pop it if it's non nil,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 otherwise pop it")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 (byte-defop 135 -1 byte-return "to pop a value and return it from `byte-code'")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (byte-defop 136 -1 byte-discard "to discard one value from stack")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (byte-defop 137 1 byte-dup "to duplicate the top of the stack")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (byte-defop 138 0 byte-save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 "to make a binding to record the buffer, point and mark")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (byte-defop 139 0 byte-save-window-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 "to make a binding to record entire window configuration")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (byte-defop 140 0 byte-save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 "to make a binding to record the current buffer clipping restrictions")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (byte-defop 141 -1 byte-catch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 "for catch. Takes, on stack, the tag and an expression for the body")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 (byte-defop 142 -1 byte-unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 "for unwind-protect. Takes, on stack, an expression for the unwind-action")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 ;; For condition-case. Takes, on stack, the variable to bind,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 ;; an expression for the body, and a list of clauses.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 (byte-defop 143 -2 byte-condition-case)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 ;; For entry to with-output-to-temp-buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 ;; Takes, on stack, the buffer name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 ;; Binds standard-output and does some other things.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 ;; Returns with temp buffer on the stack in place of buffer name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 (byte-defop 144 0 byte-temp-output-buffer-setup)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 ;; For exit from with-output-to-temp-buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 ;; Expects the temp buffer on the stack underneath value to return.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 ;; Pops them both, then pushes the value back on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 ;; Unbinds standard-output and makes the temp buffer visible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (byte-defop 145 -1 byte-temp-output-buffer-show)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 ;; these ops are new to v19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 ;; To unbind back to the beginning of this frame.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 ;; Not used yet, but will be needed for tail-recursion elimination.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 (byte-defop 146 0 byte-unbind-all)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 ;; these ops are new to v19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 (byte-defop 147 -2 byte-set-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 (byte-defop 148 0 byte-match-beginning)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 (byte-defop 149 0 byte-match-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 (byte-defop 150 0 byte-upcase)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 (byte-defop 151 0 byte-downcase)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 (byte-defop 152 -1 byte-string=)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 (byte-defop 153 -1 byte-string<)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 (byte-defop 154 -1 byte-equal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 (byte-defop 155 -1 byte-nthcdr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 (byte-defop 156 -1 byte-elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (byte-defop 157 -1 byte-member)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 (byte-defop 158 -1 byte-assq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 (byte-defop 159 0 byte-nreverse)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 (byte-defop 160 -1 byte-setcar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 (byte-defop 161 -1 byte-setcdr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 (byte-defop 162 0 byte-car-safe)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 (byte-defop 163 0 byte-cdr-safe)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 (byte-defop 164 -1 byte-nconc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 (byte-defop 165 -1 byte-quo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 (byte-defop 166 -1 byte-rem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (byte-defop 167 0 byte-numberp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 (byte-defop 168 0 byte-integerp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 ;; unused: 169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 ;; These are not present in FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 ;; New to v19. These store their arg in the next byte.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 (byte-defop 170 0 byte-rel-goto)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 (byte-defop 171 -1 byte-rel-goto-if-nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 (byte-defop 172 -1 byte-rel-goto-if-not-nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 (byte-defop 173 -1 byte-rel-goto-if-nil-else-pop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 (byte-defop 174 -1 byte-rel-goto-if-not-nil-else-pop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 (byte-defop 175 nil byte-listN)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 (byte-defop 176 nil byte-concatN)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 (byte-defop 177 nil byte-insertN)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 ;; unused: 178-191
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 (byte-defop 192 1 byte-constant "for reference to a constant")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 ;; codes 193-255 are consumed by byte-constant.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 (defconst byte-constant-limit 64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 "Exclusive maximum index usable in the `byte-constant' opcode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 (defconst byte-goto-ops (purecopy
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 '(byte-goto byte-goto-if-nil byte-goto-if-not-nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 byte-goto-if-nil-else-pop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 byte-goto-if-not-nil-else-pop))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 "List of byte-codes whose offset is a pc.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 (defconst byte-goto-always-pop-ops
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 (purecopy '(byte-goto-if-nil byte-goto-if-not-nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 (defconst byte-rel-goto-ops
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 (purecopy '(byte-rel-goto byte-rel-goto-if-nil byte-rel-goto-if-not-nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 byte-rel-goto-if-nil-else-pop byte-rel-goto-if-not-nil-else-pop))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 "byte-codes for relative jumps.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 (byte-extrude-byte-code-vectors)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 ;;; lapcode generator
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 ;;; the byte-compiler now does source -> lapcode -> bytecode instead of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 ;;; source -> bytecode, because it's a lot easier to make optimizations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 ;;; on lapcode than on bytecode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 ;;; Elements of the lapcode list are of the form (<instruction> . <parameter>)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 ;;; where instruction is a symbol naming a byte-code instruction,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 ;;; and parameter is an argument to that instruction, if any.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 ;;; The instruction can be the pseudo-op TAG, which means that this position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 ;;; in the instruction stream is a target of a goto. (car PARAMETER) will be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 ;;; the PC for this location, and the whole instruction "(TAG pc)" will be the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 ;;; parameter for some goto op.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 ;;; If the operation is varbind, varref, varset or push-constant, then the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 ;;; parameter is (variable/constant . index_in_constant_vector).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 ;;; First, the source code is macroexpanded and optimized in various ways.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 ;;; Then the resultant code is compiled into lapcode. Another set of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 ;;; optimizations are then run over the lapcode. Then the variables and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 ;;; constants referenced by the lapcode are collected and placed in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 ;;; constants-vector. (This happens now so that variables referenced by dead
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 ;;; code don't consume space.) And finally, the lapcode is transformed into
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 ;;; compacted byte-code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 ;;; A distinction is made between variables and constants because the variable-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 ;;; referencing instructions are more sensitive to the variables being near the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 ;;; front of the constants-vector than the constant-referencing instructions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 ;;; Also, this lets us notice references to free variables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 (defun byte-compile-lapcode (lap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 "Turns lapcode into bytecode. The lapcode is destroyed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 ;; Lapcode modifications: changes the ID of a tag to be the tag's PC.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 (let ((pc 0) ; Program counter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 op off ; Operation & offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 (bytes '()) ; Put the output bytes here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 (patchlist nil) ; List of tags and goto's to patch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 rest rel tmp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 (while lap
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 (setq op (car (car lap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 off (cdr (car lap)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 (cond ((not (symbolp op))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 (error "Non-symbolic opcode `%s'" op))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 ((eq op 'TAG)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 (setcar off pc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 (setq patchlist (cons off patchlist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 ((memq op byte-goto-ops)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 (setq pc (+ pc 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 (setq bytes (cons (cons pc (cdr off))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 (cons nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 (cons (symbol-value op) bytes))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 (setq patchlist (cons bytes patchlist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 (setq bytes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 (cond ((cond ((consp off)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 ;; Variable or constant reference
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 (setq off (cdr off))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 (eq op 'byte-constant)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 (cond ((< off byte-constant-limit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 (setq pc (1+ pc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 (cons (+ byte-constant off) bytes))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 (setq pc (+ 3 pc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 (cons (lsh off -8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 (cons (logand off 255)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 (cons byte-constant2 bytes))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 ((<= byte-listN (symbol-value op))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 (setq pc (+ 2 pc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 (cons off (cons (symbol-value op) bytes)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 ((< off 6)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 (setq pc (1+ pc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 (cons (+ (symbol-value op) off) bytes))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 ((< off 256)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 (setq pc (+ 2 pc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 (cons off (cons (+ (symbol-value op) 6) bytes)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 (setq pc (+ 3 pc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 (cons (lsh off -8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 (cons (logand off 255)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 (cons (+ (symbol-value op) 7)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 bytes))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 (setq lap (cdr lap)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 ;;(if (not (= pc (length bytes)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 ;; (error "Compiler error: pc mismatch - %s %s" pc (length bytes)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 (cond ((not (byte-compile-version-cond byte-compile-emacs18-compatibility))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 ;; Make relative jumps
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 (setq patchlist (nreverse patchlist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 (while (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 (setq off 0) ; PC change because of deleted bytes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 (setq rest patchlist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 (while rest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 (setq tmp (car rest))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 (and (consp (car tmp)) ; Jump
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 (prog1 (null (nth 1 tmp)) ; Absolute jump
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 (setq tmp (car tmp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 (setq rel (- (car (cdr tmp)) (car tmp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 (and (<= -129 rel) (< rel 128)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 ;; Convert to relative jump.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 (setcdr (car rest) (cdr (cdr (car rest))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 (setcar (cdr (car rest))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 (+ (car (cdr (car rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 (- byte-rel-goto byte-goto)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 (setq off (1- off))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 (setcar tmp (+ (car tmp) off)) ; Adjust PC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 (setq rest (cdr rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 ;; If optimizing, repeat until no change.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 (and byte-optimize
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 (not (zerop off)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 ;; Patch PC into jumps
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 (let (bytes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 (while patchlist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 (setq bytes (car patchlist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 (cond ((atom (car bytes))) ; Tag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 ((nth 1 bytes) ; Relative jump
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 (setcar bytes (+ (- (car (cdr (car bytes))) (car (car bytes)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 128)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 (t ; Absolute jump
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 (setq pc (car (cdr (car bytes)))) ; Pick PC from tag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 (setcar (cdr bytes) (logand pc 255))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 (setcar bytes (lsh pc -8))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 (setq patchlist (cdr patchlist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 (concat (nreverse bytes))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 ;;; byte compiler messages
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 (defvar byte-compile-current-form nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 (defvar byte-compile-current-file nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 (defvar byte-compile-dest-file nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 (defmacro byte-compile-log (format-string &rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 (list 'and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 'byte-optimize
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 '(memq byte-optimize-log '(t source))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 (list 'let '((print-escape-newlines t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 (print-level 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 (print-length 4))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 (list 'byte-compile-log-1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 (cons 'format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 (cons format-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 '(lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 (if (symbolp x) (list 'prin1-to-string x) x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 args)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 (defconst byte-compile-last-warned-form nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 ;; Log a message STRING in *Compile-Log*.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 ;; Also log the current function and file if not already done.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 (defun byte-compile-log-1 (string &optional fill)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 (let ((this-form (or byte-compile-current-form "toplevel forms")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 (noninteractive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 (if (or byte-compile-current-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 (and byte-compile-last-warned-form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 (not (eq this-form byte-compile-last-warned-form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 (message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 (format "While compiling %s%s:"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 this-form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 (if byte-compile-current-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 (if (stringp byte-compile-current-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 (concat " in file " byte-compile-current-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 (concat " in buffer "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 (buffer-name byte-compile-current-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 ""))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 (message " %s" string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 (set-buffer (get-buffer-create "*Compile-Log*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 (cond ((or byte-compile-current-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 (and byte-compile-last-warned-form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 (not (eq this-form byte-compile-last-warned-form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 (if byte-compile-current-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 (insert "\n\^L\n" (current-time-string) "\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 (insert "While compiling "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 (if (stringp this-form) this-form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 (format "%s" this-form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 (if byte-compile-current-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 (if (stringp byte-compile-current-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 (insert " in file " byte-compile-current-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 (insert " in buffer "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 (buffer-name byte-compile-current-file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 (insert ":\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 (insert " " string "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 (if (and fill (not (string-match "\n" string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 (let ((fill-prefix " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 (fill-column 78))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 (fill-paragraph nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 (setq byte-compile-current-file nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 byte-compile-last-warned-form this-form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 ;; Log the start of a file in *Compile-Log*, and mark it as done.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 ;; But do nothing in batch mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 (defun byte-compile-log-file ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 (and byte-compile-current-file (not noninteractive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 (set-buffer (get-buffer-create "*Compile-Log*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 (insert "\n\^L\nCompiling "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 (if (stringp byte-compile-current-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 (concat "file " byte-compile-current-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 (concat "buffer " (buffer-name byte-compile-current-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 " at " (current-time-string) "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 (setq byte-compile-current-file nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 (defun byte-compile-warn (format &rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 (setq format (apply 'format format args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 (if byte-compile-error-on-warn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 (error "%s" format) ; byte-compile-file catches and logs it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 (byte-compile-log-1 (concat "** " format) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 ;;; RMS says:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 ;;; It is useless to flash warnings too fast to be read.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 ;;; Besides, they will all be shown at the end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 ;;; and comments out the next two lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 (or noninteractive ; already written on stdout.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 (message "Warning: %s" format))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 ;;; This function should be used to report errors that have halted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 ;;; compilation of the current file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 (defun byte-compile-report-error (error-info)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 (setq byte-compiler-error-flag t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 (byte-compile-log-1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 (concat "!! "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 (format (if (cdr error-info) "%s (%s)" "%s")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 (get (car error-info) 'error-message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 (prin1-to-string (cdr error-info))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 ;;; Used by make-obsolete.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 (defun byte-compile-obsolete (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 (let ((new (get (car form) 'byte-obsolete-info)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 (if (memq 'obsolete byte-compile-warnings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 (byte-compile-warn "%s is an obsolete function; %s" (car form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 (if (stringp (car new))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 (car new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 (format "use %s instead." (car new)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 (funcall (or (cdr new) 'byte-compile-normal-call) form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 ;; Compiler options
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 (defconst byte-compiler-legal-options
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 '((optimize byte-optimize (t nil source byte) val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 (file-format byte-compile-emacs18-compatibility (emacs18 emacs19)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 (eq val 'emacs18))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 (delete-errors byte-compile-delete-errors (t nil) val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 (verbose byte-compile-verbose (t nil) val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 (new-bytecodes byte-compile-new-bytecodes (t nil) val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 (warnings byte-compile-warnings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 ((callargs redefine free-vars unused-vars unresolved))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 ;; XEmacs addition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 (defconst byte-compiler-obsolete-options
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 '((new-bytecodes t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 ;; Inhibit v18/v19 selectors if the version is hardcoded.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 ;; #### This should print a warning if the user tries to change something
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 ;; than can't be changed because the running compiler doesn't support it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 ((byte-compile-single-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 (setcar (cdr (cdr (assq 'file-format byte-compiler-legal-options)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 (if (byte-compile-version-cond byte-compile-emacs18-compatibility)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 '(emacs18) '(emacs19)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 ;; now we can copy it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 (setq byte-compiler-legal-options (purecopy byte-compiler-legal-options))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 (defun byte-compiler-options-handler (&rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 (let (key val desc choices)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 (while args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 (if (or (atom (car args)) (nthcdr 2 (car args)) (null (cdr (car args))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 (error "malformed byte-compiler-option %s" (car args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 (setq key (car (car args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 val (car (cdr (car args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 desc (assq key byte-compiler-legal-options))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 (or desc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 (error "unknown byte-compiler option %s" key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 (if (assq key byte-compiler-obsolete-options)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 (byte-compile-warn "%s is an obsolete byte-compiler option." key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 (setq choices (nth 2 desc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 (if (consp (car choices))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 (let* (this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 (handler 'cons)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 (var (nth 1 desc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 (ret (and (memq (car val) '(+ -))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 (copy-sequence (if (eq t (symbol-value var))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 (car choices)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 (symbol-value var))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 (setq choices (car choices))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 (while val
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 (setq this (car val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 (cond ((memq this choices)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 (setq ret (funcall handler this ret)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 ((eq this '+) (setq handler 'cons))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 ((eq this '-) (setq handler 'delq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 ((error "%s only accepts %s." key choices)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 (setq val (cdr val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 (set (nth 1 desc) ret))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 (or (memq val choices)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 (error "%s must be one of %s." key choices))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 (set (nth 1 desc) (eval (nth 3 desc))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 (setq args (cdr args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 ;;; sanity-checking arglists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 (defun byte-compile-fdefinition (name macro-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 (let* ((list (if (memq macro-p '(nil subr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 byte-compile-function-environment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 byte-compile-macro-environment))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 (env (cdr (assq name list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 (or env
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 (let ((fn name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 (while (and (symbolp fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 (fboundp fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 (or (symbolp (symbol-function fn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 (consp (symbol-function fn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 (and (not macro-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 (compiled-function-p (symbol-function fn)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 (and (eq macro-p 'subr) (subrp fn))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 (setq fn (symbol-function fn)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 (if (or (and (not macro-p) (compiled-function-p fn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 (and (eq macro-p 'subr) (subrp fn)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 fn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 (and (consp fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 (not (eq macro-p 'subr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 (if (eq 'macro (car fn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 (cdr fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 (if macro-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 (if (eq 'autoload (car fn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 fn)))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 (defun byte-compile-arglist-signature (arglist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 (let ((args 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 opts
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 restp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055 (while arglist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 (cond ((eq (car arglist) '&optional)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 (or opts (setq opts 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 ((eq (car arglist) '&rest)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059 (if (cdr arglist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 (setq restp t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 arglist nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063 (if opts
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064 (setq opts (1+ opts))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 (setq args (1+ args)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 (setq arglist (cdr arglist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 (cons args (if restp nil (if opts (+ args opts) args)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 (defun byte-compile-arglist-signatures-congruent-p (old new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 (not (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 (> (car new) (car old)) ; requires more args now
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 (and (null (cdr old)) ; tooks rest-args, doesn't any more
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 (cdr new))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 (and (cdr new) (cdr old) ; can't take as many args now
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 (< (cdr new) (cdr old)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 (defun byte-compile-arglist-signature-string (signature)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 (cond ((null (cdr signature))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 (format "%d+" (car signature)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 ((= (car signature) (cdr signature))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 (format "%d" (car signature)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 (t (format "%d-%d" (car signature) (cdr signature)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 ;; Warn if the form is calling a function with the wrong number of arguments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 (defun byte-compile-callargs-warn (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 (let* ((def (or (byte-compile-fdefinition (car form) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 (byte-compile-fdefinition (car form) t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 (sig (and def (byte-compile-arglist-signature
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 (if (eq 'lambda (car-safe def))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 (nth 1 def)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 (if (compiled-function-p def)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095 (compiled-function-arglist def)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 '(&rest def))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 (ncall (length (cdr form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 (if (and (null def)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 (fboundp 'subr-min-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 (setq def (byte-compile-fdefinition (car form) 'subr)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101 (setq sig (cons (subr-min-args def) (subr-max-args def))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 (if sig
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 (if (or (< ncall (car sig))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104 (and (cdr sig) (> ncall (cdr sig))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 (byte-compile-warn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 "%s called with %d argument%s, but %s %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107 (car form) ncall
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 (if (= 1 ncall) "" "s")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 (if (< ncall (car sig))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 "requires"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 "accepts only")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 (byte-compile-arglist-signature-string sig)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 (or (fboundp (car form)) ; might be a subr or autoload.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114 ;; ## this doesn't work with recursion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 (eq (car form) byte-compile-current-form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 ;; It's a currently-undefined function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 ;; Remember number of args in call.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 (let ((cons (assq (car form) byte-compile-unresolved-functions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 (n (length (cdr form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 (if cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121 (or (memq n (cdr cons))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 (setcdr cons (cons n (cdr cons))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123 (setq byte-compile-unresolved-functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 (cons (list (car form) n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 byte-compile-unresolved-functions))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 ;; Warn if the function or macro is being redefined with a different
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 ;; number of arguments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 (defun byte-compile-arglist-warn (form macrop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 (let ((old (byte-compile-fdefinition (nth 1 form) macrop)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 (if old
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 (let ((sig1 (byte-compile-arglist-signature
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133 (if (eq 'lambda (car-safe old))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 (nth 1 old)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 (if (compiled-function-p old)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 (compiled-function-arglist old)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 '(&rest def)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 (sig2 (byte-compile-arglist-signature (nth 2 form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 (or (byte-compile-arglist-signatures-congruent-p sig1 sig2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 (byte-compile-warn "%s %s used to take %s %s, now takes %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 (if (eq (car form) 'defun) "function" "macro")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 (nth 1 form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 (byte-compile-arglist-signature-string sig1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 (if (equal sig1 '(1 . 1)) "argument" "arguments")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145 (byte-compile-arglist-signature-string sig2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 ;; This is the first definition. See if previous calls are compatible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 (let ((calls (assq (nth 1 form) byte-compile-unresolved-functions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 nums sig min max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 (if calls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 (setq sig (byte-compile-arglist-signature (nth 2 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 nums (sort (copy-sequence (cdr calls)) (function <))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 min (car nums)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154 max (car (nreverse nums)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 (if (or (< min (car sig))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 (and (cdr sig) (> max (cdr sig))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 (byte-compile-warn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 "%s being defined to take %s%s, but was previously called with %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 (nth 1 form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 (byte-compile-arglist-signature-string sig)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 (if (equal sig '(1 . 1)) " arg" " args")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 (byte-compile-arglist-signature-string (cons min max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 (setq byte-compile-unresolved-functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 (delq calls byte-compile-unresolved-functions)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 ;; If we have compiled any calls to functions which are not known to be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 ;; defined, issue a warning enumerating them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 ;; `unresolved' in the list `byte-compile-warnings' disables this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 (defun byte-compile-warn-about-unresolved-functions (&optional msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172 (if (memq 'unresolved byte-compile-warnings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 (let ((byte-compile-current-form (or msg "the end of the data")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 ;; First delete the autoloads from the list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 (if byte-compile-autoload-environment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176 (let ((rest byte-compile-unresolved-functions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 (while rest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 (if (assq (car (car rest)) byte-compile-autoload-environment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 (setq byte-compile-unresolved-functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 (delq (car rest) byte-compile-unresolved-functions)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 (setq rest (cdr rest)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 ;; Now warn.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 (if (cdr byte-compile-unresolved-functions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184 (let* ((str "The following functions are not known to be defined: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 (L (+ (length str) 5))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 (rest (reverse byte-compile-unresolved-functions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 (while rest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 (setq s (symbol-name (car (car rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 L (+ L (length s) 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 rest (cdr rest))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 (if (<= L (1- fill-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 (setq str (concat str " " s (and rest ",")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194 (setq str (concat str "\n " s (and rest ","))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 L (+ (length s) 4))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 (byte-compile-warn "%s" str))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 (if byte-compile-unresolved-functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 (byte-compile-warn "the function %s is not known to be defined."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 (car (car byte-compile-unresolved-functions)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 (defun byte-compile-defvar-p (var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203 ;; Whether the byte compiler thinks that nonexical references to this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204 ;; variable are ok.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 (or (globally-boundp var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206 (let ((rest byte-compile-bound-variables))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 (while (and rest var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208 (if (and (eq var (car-safe (car rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209 (not (= 0 (logand (cdr (car rest))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 byte-compile-global-bit))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 (setq var nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 (setq rest (cdr rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213 ;; if var is nil at this point, it's a defvar in this file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 (not var))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 ;;; If we have compiled bindings of variables which have no referents, warn.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 (defun byte-compile-warn-about-unused-variables ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 (let ((rest byte-compile-bound-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 (unreferenced '())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 (while (and rest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223 ;; only warn about variables whose lifetime is now ending,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 ;; that is, variables from the lexical scope that is now
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 ;; terminating. (Think nested lets.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226 (not (eq (car rest) 'new-scope)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227 (setq cell (car rest))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 (if (and (= 0 (logand byte-compile-referenced-bit (cdr cell)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 ;; Don't warn about declared-but-unused arguments, for two
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 ;; reasons: first, the arglist structure might be imposed by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 ;; external forces, and we don't have (declare (ignore x)) yet;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232 ;; and second, inline expansion produces forms like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 ;; ((lambda (arg) (byte-code "..." [arg])) x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 ;; which we can't (ok, well, don't) recognise as containing a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235 ;; reference to arg, so every inline expansion would generate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 ;; a warning. (If we had `ignore' then inline expansion could
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237 ;; emit an ignore declaration.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238 (= 0 (logand byte-compile-arglist-bit (cdr cell)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 ;; Don't warn about defvars because this is a legitimate special
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240 ;; binding.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241 (not (byte-compile-defvar-p (car cell))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242 (setq unreferenced (cons (car cell) unreferenced)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243 (setq rest (cdr rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244 (setq unreferenced (nreverse unreferenced))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245 (while unreferenced
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246 (byte-compile-warn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247 (format "variable %s bound but not referenced" (car unreferenced)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248 (setq unreferenced (cdr unreferenced)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251 (defmacro byte-compile-constp (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252 ;; Returns non-nil if FORM is a constant.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 (` (cond ((consp (, form)) (eq (car (, form)) 'quote))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 ((not (symbolp (, form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 ((keywordp (, form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 ((memq (, form) '(nil t))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 (defmacro byte-compile-close-variables (&rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259 (cons 'let
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260 (cons '(;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261 ;; Close over these variables to encapsulate the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262 ;; compilation state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264 (byte-compile-macro-environment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 ;; Copy it because the compiler may patch into the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266 ;; macroenvironment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267 (copy-alist byte-compile-initial-macro-environment))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268 (byte-compile-function-environment nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269 (byte-compile-autoload-environment nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270 (byte-compile-unresolved-functions nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271 (byte-compile-bound-variables nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272 (byte-compile-free-references nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 (byte-compile-free-assignments nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275 ;; Close over these variables so that `byte-compiler-options'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276 ;; can change them on a per-file basis.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1277 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278 (byte-compile-verbose byte-compile-verbose)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279 (byte-optimize byte-optimize)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 (byte-compile-emacs18-compatibility
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281 byte-compile-emacs18-compatibility)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282 (byte-compile-dynamic byte-compile-dynamic)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283 (byte-compile-dynamic-docstrings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284 byte-compile-dynamic-docstrings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 (byte-compile-warnings (if (eq byte-compile-warnings t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286 byte-compile-default-warnings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 byte-compile-warnings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288 (byte-compile-file-domain nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291 (list 'prog1 (cons 'progn body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292 '(if (memq 'unused-vars byte-compile-warnings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 ;; done compiling in this scope, warn now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294 (byte-compile-warn-about-unused-variables)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 (defvar byte-compile-warnings-point-max nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 (defmacro displaying-byte-compile-warnings (&rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299 (list 'let
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300 '((byte-compile-warnings-point-max byte-compile-warnings-point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 ;; Log the file name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1302 '(byte-compile-log-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1303 ;; Record how much is logged now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304 ;; We will display the log buffer if anything more is logged
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305 ;; before the end of BODY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306 '(or byte-compile-warnings-point-max
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308 (set-buffer (get-buffer-create "*Compile-Log*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309 (setq byte-compile-warnings-point-max (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310 (list 'unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 (list 'condition-case 'error-info
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312 (cons 'progn body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 '(error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314 (byte-compile-report-error error-info)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315 '(save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316 ;; If there were compilation warnings, display them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 (set-buffer "*Compile-Log*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 (if (= byte-compile-warnings-point-max (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 (select-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1321 (prog1 (selected-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322 (select-window (display-buffer (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323 (goto-char byte-compile-warnings-point-max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324 (recenter 1))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328 (defun byte-force-recompile (directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329 "Recompile every `.el' file in DIRECTORY that already has a `.elc' file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 Files in subdirectories of DIRECTORY are processed also."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331 (interactive "DByte force recompile (directory): ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332 (byte-recompile-directory directory nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1334 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335 (defun byte-recompile-directory (directory &optional arg norecursion force)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1336 "Recompile every `.el' file in DIRECTORY that needs recompilation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337 This is if a `.elc' file exists but is older than the `.el' file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338 Files in subdirectories of DIRECTORY are processed also unless argument
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339 NORECURSION is non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 If the `.elc' file does not exist, normally the `.el' file is *not* compiled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342 But a prefix argument (optional second arg) means ask user,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343 for each such `.el' file, whether to compile it. Prefix argument 0 means
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344 don't ask and compile the file anyway.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346 A nonzero prefix argument also means ask about each subdirectory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348 If the fourth argument FORCE is non-nil,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349 recompile every `.el' file that already has a `.elc' file."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350 (interactive "DByte recompile directory: \nP")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1351 (if arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 (setq arg (prefix-numeric-value arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 (if noninteractive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355 (save-some-buffers)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 (redraw-modeline))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 (let ((directories (list (expand-file-name directory)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358 (file-count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 (dir-count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 last-dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 (displaying-byte-compile-warnings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362 (while directories
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 (setq directory (file-name-as-directory (car directories)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 (or noninteractive (message "Checking %s..." directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365 (let ((files (directory-files directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 source dest)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 (while files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368 (setq source (expand-file-name (car files) directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369 (if (and (not (member (car files) '("." ".." "RCS" "CVS" "SCCS")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 ;; Stay away from directory back-links, etc:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 (not (file-symlink-p source))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 (file-directory-p source)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373 byte-recompile-directory-recursively)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374 ;; This file is a subdirectory. Handle them differently.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 (if (or (null arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376 (eq arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377 (y-or-n-p (concat "Check " source "? ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378 (setq directories
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 (nconc directories (list source))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 ;; It is an ordinary file. Decide whether to compile it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381 (if (and (string-match emacs-lisp-file-regexp source)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382 (not (auto-save-file-name-p source))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 (setq dest (byte-compile-dest-file source))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 (if (file-exists-p dest)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 ;; File was already compiled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386 (or force (file-newer-than-file-p source dest))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387 ;; No compiled file exists yet.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388 (and arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389 (or (eq 0 arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390 (y-or-n-p (concat "Compile " source "? "))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391 (progn ;(if (and noninteractive (not byte-compile-verbose))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392 ; (message "Compiling %s..." source))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393 ; we do this in byte-compile-file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394 (if byte-recompile-directory-ignore-errors-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395 (batch-byte-compile-1 source)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396 (byte-compile-file source))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397 (or noninteractive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398 (message "Checking %s..." directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 (setq file-count (1+ file-count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400 (if (not (eq last-dir directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401 (setq last-dir directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402 dir-count (1+ dir-count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1404 (setq files (cdr files))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405 (setq directories (cdr directories))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406 (message "Done (Total of %d file%s compiled%s)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1407 file-count (if (= file-count 1) "" "s")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408 (if (> dir-count 1) (format " in %d directories" dir-count) ""))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411 (defun byte-recompile-file (filename &optional force)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412 "Recompile a file of Lisp code named FILENAME if it needs recompilation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413 This is if the `.elc' file exists but is older than the `.el' file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415 If the `.elc' file does not exist, normally the `.el' file is *not*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416 compiled. But a prefix argument (optional second arg) means ask user
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1417 whether to compile it. Prefix argument 0 don't ask and recompile anyway."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418 (interactive "fByte recompile file: \nP")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419 (let ((dest))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420 (if (and (string-match emacs-lisp-file-regexp filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421 (not (auto-save-file-name-p filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1422 (setq dest (byte-compile-dest-file filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423 (if (file-exists-p dest)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424 (file-newer-than-file-p filename dest)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425 (and force
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426 (or (eq 0 force)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427 (y-or-n-p (concat "Compile " filename "? "))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1428 (byte-compile-file filename))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1429
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1430 (defvar kanji-flag nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1431
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1433 (defun byte-compile-file (filename &optional load)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434 "Compile a file of Lisp code named FILENAME into a file of byte code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435 The output file's name is made by appending `c' to the end of FILENAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436 With prefix arg (noninteractively: 2nd arg), load the file after compiling."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 ;; (interactive "fByte compile file: \nP")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1438 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1439 (let ((file buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440 (file-name nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441 (file-dir nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442 (and file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443 (eq (cdr (assq 'major-mode (buffer-local-variables)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444 'emacs-lisp-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445 (setq file-name (file-name-nondirectory file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446 file-dir (file-name-directory file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447 (list (read-file-name (if current-prefix-arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448 "Byte compile and load file: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449 "Byte compile file: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450 file-dir nil nil file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1451 current-prefix-arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452 ;; Expand now so we get the current buffer's defaults
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453 (setq filename (expand-file-name filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455 ;; If we're compiling a file that's in a buffer and is modified, offer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456 ;; to save it first.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457 (or noninteractive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458 (let ((b (get-file-buffer (expand-file-name filename))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1459 (if (and b (buffer-modified-p b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460 (y-or-n-p (format "save buffer %s first? " (buffer-name b))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461 (save-excursion (set-buffer b) (save-buffer)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 (if (or noninteractive byte-compile-verbose) ; XEmacs change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1464 (message "Compiling %s..." filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1465 (let (;;(byte-compile-current-file (file-name-nondirectory filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1466 (byte-compile-current-file filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1467 target-file input-buffer output-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1468 byte-compile-dest-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1469 (setq target-file (byte-compile-dest-file filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1470 (setq byte-compile-dest-file target-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1471 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1472 (setq input-buffer (get-buffer-create " *Compiler Input*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1473 (set-buffer input-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1474 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1475 (insert-file-contents filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1476 ;; Run hooks including the uncompression hook.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1477 ;; If they change the file name, then change it for the output also.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1478 (let ((buffer-file-name filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1479 (default-major-mode 'emacs-lisp-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1480 (enable-local-eval nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1481 (normal-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1482 (setq filename buffer-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1483 (setq byte-compiler-error-flag nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1484 ;; It is important that input-buffer not be current at this call,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1485 ;; so that the value of point set in input-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1486 ;; within byte-compile-from-buffer lingers in that buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1487 (setq output-buffer (byte-compile-from-buffer input-buffer filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1488 (if byte-compiler-error-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1489 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1490 (if byte-compile-verbose
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1491 (message "Compiling %s...done" filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492 (kill-buffer input-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494 (set-buffer output-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1496 (insert "\n") ; aaah, unix.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497 (let ((vms-stmlf-recfm t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1498 (setq target-file (byte-compile-dest-file filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1499 (or byte-compile-overwrite-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1500 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1501 (delete-file target-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502 (error nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503 (if (file-writable-p target-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1504 (let ((kanji-flag nil)) ; for nemacs, from Nakagawa Takayuki
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505 (if (or (eq system-type 'ms-dos) (eq system-type 'windows-nt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 (setq buffer-file-type t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507 (write-region 1 (point-max) target-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508 ;; This is just to give a better error message than write-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509 (signal 'file-error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1510 (list "Opening output file"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511 (if (file-exists-p target-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1512 "cannot overwrite file"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1513 "directory not writable or nonexistent")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1514 target-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1515 (or byte-compile-overwrite-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1516 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517 (set-file-modes target-file (file-modes filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518 (error nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1519 (kill-buffer (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1520 (if (and byte-compile-generate-call-tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1521 (or (eq t byte-compile-generate-call-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1522 (y-or-n-p (format "Report call tree for %s? " filename))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524 (display-call-tree filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525 (if load
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1526 (load target-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1527 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1528
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1529 ;; RMS comments the next two out.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1530 (defun byte-compile-and-load-file (&optional filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531 "Compile a file of Lisp code named FILENAME into a file of byte code,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1532 and then load it. The output file's name is made by appending \"c\" to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1533 the end of FILENAME."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1534 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1535 (if filename ; I don't get it, (interactive-p) doesn't always work
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1536 (byte-compile-file filename t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1537 (let ((current-prefix-arg '(4)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1538 (call-interactively 'byte-compile-file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1539
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1540 (defun byte-compile-buffer (&optional buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1541 "Byte-compile and evaluate contents of BUFFER (default: the current buffer)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1542 (interactive "bByte compile buffer: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1543 (setq buffer (if buffer (get-buffer buffer) (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1544 (message "Compiling %s..." (buffer-name buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1545 (let* ((filename (or (buffer-file-name buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1546 (concat "#<buffer " (buffer-name buffer) ">")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1547 (byte-compile-current-file buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1548 (byte-compile-from-buffer buffer filename t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1549 (message "Compiling %s...done" (buffer-name buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1550 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1551
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1552 ;;; compiling a single function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1553 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1554 (defun compile-defun (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1555 "Compile and evaluate the current top-level form.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1556 Print the result in the minibuffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1557 With argument, insert value in current buffer after the form."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1558 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1559 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1560 (end-of-defun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1561 (beginning-of-defun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1562 (let* ((byte-compile-current-file nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1563 (byte-compile-last-warned-form 'nothing)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1564 (value (eval (displaying-byte-compile-warnings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1565 (byte-compile-sexp (read (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1566 "toplevel forms")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1567 (cond (arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1568 (message "Compiling from buffer... done.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1569 (prin1 value (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1570 (insert "\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1571 ((message "%s" (prin1-to-string value)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1572
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1573 (defvar byte-compile-inbuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1574 (defvar byte-compile-outbuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1575
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1576 (defun byte-compile-from-buffer (byte-compile-inbuffer filename &optional eval)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1577 ;; buffer --> output-buffer, or buffer --> eval form, return nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1578 (let (byte-compile-outbuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1579 ;; Prevent truncation of flonums and lists as we read and print them
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1580 (float-output-format nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1581 (case-fold-search nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1582 (print-length nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1583 (print-level nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1584 ;; Simulate entry to byte-compile-top-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1585 (byte-compile-constants nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1586 (byte-compile-variables nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1587 (byte-compile-tag-number 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1588 (byte-compile-depth 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1589 (byte-compile-maxdepth 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1590 (byte-compile-output nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1591 ;; #### This is bound in b-c-close-variables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1592 ;; (byte-compile-warnings (if (eq byte-compile-warnings t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1593 ;; byte-compile-warning-types
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1594 ;; byte-compile-warnings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1595 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1596 (byte-compile-close-variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1597 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1598 (setq byte-compile-outbuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1599 (set-buffer (get-buffer-create " *Compiler Output*")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1600 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1601 ;; (emacs-lisp-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1602 (setq case-fold-search nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1603 (and filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1604 (not eval)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1605 (byte-compile-insert-header filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1606 byte-compile-inbuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1607 byte-compile-outbuffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1608
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1609 ;; This is a kludge. Some operating systems (OS/2, DOS) need to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1610 ;; write files containing binary information specially.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1611 ;; Under most circumstances, such files will be in binary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1612 ;; overwrite mode, so those OS's use that flag to guess how
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1613 ;; they should write their data. Advise them that .elc files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1614 ;; need to be written carefully.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1615 (setq overwrite-mode 'overwrite-mode-binary))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1616 (displaying-byte-compile-warnings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1617 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1618 (set-buffer byte-compile-inbuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1619 (goto-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1620
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1621 ;; Compile the forms from the input buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1622 (while (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1623 (while (progn (skip-chars-forward " \t\n\^l")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1624 (looking-at ";"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1625 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1626 (not (eobp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1627 (byte-compile-file-form (read byte-compile-inbuffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1628
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1629 ;; Compile pending forms at end of file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1630 (byte-compile-flush-pending)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1631 (byte-compile-warn-about-unresolved-functions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1632 ;; SHould we always do this? When calling multiple files, it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1633 ;; would be useful to delay this warning until all have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1634 ;; been compiled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1635 (setq byte-compile-unresolved-functions nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1636 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1637 (set-buffer byte-compile-outbuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1638 (goto-char (point-min))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1639 (if (not eval)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1640 byte-compile-outbuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1641 (let (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1642 (while (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1643 (progn (setq form (read byte-compile-outbuffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1644 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1645 (end-of-file nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1646 (eval form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1647 (kill-buffer byte-compile-outbuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1648 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1649
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1650 (defun byte-compile-insert-header (filename byte-compile-inbuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1651 byte-compile-outbuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1652 (set-buffer byte-compile-inbuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1653 (let ((dynamic-docstrings byte-compile-dynamic-docstrings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1654 (set-buffer byte-compile-outbuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1655 (goto-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1656 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1657 ;; The magic number of .elc files is ";ELC", or 0x3B454C43. After that is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1658 ;; the file-format version number (18 or 19) as a byte, followed by some
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1659 ;; nulls. The primary motivation for doing this is to get some binary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1660 ;; characters up in the first line of the file so that `diff' will simply
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1661 ;; say "Binary files differ" instead of actually doing a diff of two .elc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1662 ;; files. An extra benefit is that you can add this to /etc/magic:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1663 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1664 ;; 0 string ;ELC GNU Emacs Lisp compiled file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1665 ;; >4 byte x version %d
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1666 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1667 (insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1668 ";ELC"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1669 (if (byte-compile-version-cond byte-compile-emacs18-compatibility) 18 19)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1670 "\000\000\000\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1671 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1672 (insert ";;; compiled by "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1673 (or (and (boundp 'user-mail-address) user-mail-address)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1674 (concat (user-login-name) "@" (system-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1675 " on "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1676 (current-time-string) "\n;;; from file " filename "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1677 (insert ";;; emacs version " emacs-version ".\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1678 (insert ";;; bytecomp version " byte-compile-version "\n;;; "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1679 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1680 ((eq byte-optimize 'source) "source-level optimization only")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1681 ((eq byte-optimize 'byte) "byte-level optimization only")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1682 (byte-optimize "optimization is on")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1683 (t "optimization is off"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1684 (if (byte-compile-version-cond byte-compile-emacs18-compatibility)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1685 "; compiled with Emacs 18 compatibility.\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1686 ".\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1687 (if (not (byte-compile-version-cond byte-compile-emacs18-compatibility))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1688 (insert ";;; this file uses opcodes which do not exist in Emacs 18.\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1689 ;; Have to check if emacs-version is bound so that this works
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1690 ;; in files loaded early in loadup.el.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1691 "\n(if (and (boundp 'emacs-version)\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1692 "\t (or (and (boundp 'epoch::version) epoch::version)\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1693 (if dynamic-docstrings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1694 "\t (string-lessp emacs-version \"19.14\")))\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1695 "\t (string-lessp emacs-version \"19\")))\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1696 " (error \"`"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1697 ;; prin1-to-string is used to quote backslashes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1698 (substring (prin1-to-string (file-name-nondirectory filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1699 1 -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1700 (if dynamic-docstrings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1701 "' was compiled for XEmacs 19.14/Emacs 19.29 or later\"))\n\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1702 "' was compiled for Emacs 19\"))\n\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1703 (insert "(or (boundp 'current-load-list) (setq current-load-list nil))\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1704 "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1705 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1706
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1707
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1708
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1709 (defun byte-compile-output-file-form (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1710 ;; writes the given form to the output buffer, being careful of docstrings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1711 ;; in defun, defmacro, defvar, defconst and autoload because make-docfile is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1712 ;; so amazingly stupid.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1713 ;; defalias calls are output directly by byte-compile-file-form-defmumble;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1714 ;; it does not pay to first build the defalias in defmumble and then parse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1715 ;; it here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1716 (if (and (memq (car-safe form) '(defun defmacro defvar defconst autoload))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1717 (stringp (nth 3 form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1718 (byte-compile-output-docform nil nil '("\n(" 3 ")") form nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1719 (eq (car form) 'autoload))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1720 (let ((print-escape-newlines t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1721 (print-length nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1722 (print-level nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1723 (print-readably t) ; print #[] for bytecode, 'x for (quote x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1724 (print-gensym nil)) ; this is too dangerous for now
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1725 (princ "\n" byte-compile-outbuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1726 (prin1 form byte-compile-outbuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1727 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1728
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1729 (defun byte-compile-output-docform (preface name info form specindex quoted)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1730 "Print a form with a doc string. INFO is (prefix doc-index postfix).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1731 If PREFACE and NAME are non-nil, print them too,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1732 before INFO and the FORM but after the doc string itself.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1733 If SPECINDEX is non-nil, it is the index in FORM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1734 of the function bytecode string. In that case,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1735 we output that argument and the following argument (the constants vector)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1736 together, for lazy loading.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1737 QUOTED says that we have to put a quote before the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1738 list that represents a doc string reference.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1739 `autoload' needs that."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1740 ;; We need to examine byte-compile-dynamic-docstrings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1741 ;; in the input buffer (now current), not in the output buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1742 (let ((dynamic-docstrings byte-compile-dynamic-docstrings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1743 (set-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1744 (prog1 (current-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1745 (set-buffer byte-compile-outbuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1746 (let (position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1747
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1748 ;; Insert the doc string, and make it a comment with #@LENGTH.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1749 (and (>= (nth 1 info) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1750 dynamic-docstrings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1751 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1752 ;; Make the doc string start at beginning of line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1753 ;; for make-docfile's sake.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1754 (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1755 (setq position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1756 (byte-compile-output-as-comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1757 (nth (nth 1 info) form) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1758 ;; If the doc string starts with * (a user variable),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1759 ;; negate POSITION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1760 (if (and (stringp (nth (nth 1 info) form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1761 (> (length (nth (nth 1 info) form)) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1762 (eq (aref (nth (nth 1 info) form) 0) ?*))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1763 (setq position (- position)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1764
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1765 (if preface
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1766 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1767 (insert preface)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1768 (prin1 name byte-compile-outbuffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1769 (insert (car info))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1770 (let ((print-escape-newlines t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1771 (print-readably t) ; print #[] for bytecode, 'x for (quote x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1772 (print-gensym nil) ; this is too dangerous for now
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1773 (index 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1774 (prin1 (car form) byte-compile-outbuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1775 (while (setq form (cdr form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1776 (setq index (1+ index))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1777 (insert " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1778 (cond ((and (numberp specindex) (= index specindex))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1779 (let ((position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1780 (byte-compile-output-as-comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1781 (cons (car form) (nth 1 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1782 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1783 (princ (format "(#$ . %d) nil" position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1784 byte-compile-outbuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1785 (setq form (cdr form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1786 (setq index (1+ index))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1787 ((= index (nth 1 info))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1788 (if position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1789 (princ (format (if quoted "'(#$ . %d)" "(#$ . %d)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1790 position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1791 byte-compile-outbuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1792 (let ((print-escape-newlines nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1793 (goto-char (prog1 (1+ (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1794 (prin1 (car form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1795 byte-compile-outbuffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1796 (insert "\\\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1797 (goto-char (point-max)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1798 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1799 (prin1 (car form) byte-compile-outbuffer)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1800 (insert (nth 2 info))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1801 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1802
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1803 (defvar for-effect) ; ## Kludge! This should be an arg, not a special.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1804
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1805 (defun byte-compile-keep-pending (form &optional handler)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1806 (if (memq byte-optimize '(t source))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1807 (setq form (byte-optimize-form form t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1808 (if handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1809 (let ((for-effect t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1810 ;; To avoid consing up monstrously large forms at load time, we split
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1811 ;; the output regularly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1812 (and (memq (car-safe form) '(fset defalias define-function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1813 (nthcdr 300 byte-compile-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1814 (byte-compile-flush-pending))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1815 (funcall handler form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1816 (if for-effect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1817 (byte-compile-discard)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1818 (byte-compile-form form t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1819 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1820
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1821 (defun byte-compile-flush-pending ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1822 (if byte-compile-output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1823 (let ((form (byte-compile-out-toplevel t 'file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1824 (cond ((eq (car-safe form) 'progn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1825 (mapcar 'byte-compile-output-file-form (cdr form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1826 (form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1827 (byte-compile-output-file-form form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1828 (setq byte-compile-constants nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1829 byte-compile-variables nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1830 byte-compile-depth 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1831 byte-compile-maxdepth 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1832 byte-compile-output nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1833
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1834 (defun byte-compile-file-form (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1835 (let ((byte-compile-current-form nil) ; close over this for warnings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1836 handler)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1837 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1838 ((not (consp form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1839 (byte-compile-keep-pending form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1840 ((and (symbolp (car form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1841 (setq handler (get (car form) 'byte-hunk-handler)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1842 (cond ((setq form (funcall handler form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1843 (byte-compile-flush-pending)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1844 (byte-compile-output-file-form form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1845 ((eq form (setq form (macroexpand form byte-compile-macro-environment)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1846 (byte-compile-keep-pending form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1847 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1848 (byte-compile-file-form form)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1849
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1850 ;; Functions and variables with doc strings must be output separately,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1851 ;; so make-docfile can recognise them. Most other things can be output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1852 ;; as byte-code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1853
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1854 (put 'defsubst 'byte-hunk-handler 'byte-compile-file-form-defsubst)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1855 (defun byte-compile-file-form-defsubst (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1856 (cond ((assq (nth 1 form) byte-compile-unresolved-functions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1857 (setq byte-compile-current-form (nth 1 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1858 (byte-compile-warn "defsubst %s was used before it was defined"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1859 (nth 1 form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1860 (byte-compile-file-form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1861 (macroexpand form byte-compile-macro-environment))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1862 ;; Return nil so the form is not output twice.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1863 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1864
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1865 (put 'autoload 'byte-hunk-handler 'byte-compile-file-form-autoload)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1866 (defun byte-compile-file-form-autoload (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1867 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1868 ;; If this is an autoload of a macro, and all arguments are constants (that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1869 ;; is, there is no hairy computation going on here) then evaluate the form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1870 ;; at compile-time. This is so that we can make use of macros which we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1871 ;; have autoloaded from the file being compiled. Normal function autoloads
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1872 ;; are not automatically evaluated at compile time, because there's not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1873 ;; much point to it (so why bother cluttering up the compile-time namespace.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1874 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1875 ;; If this is an autoload of a function, then record its definition in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1876 ;; byte-compile-autoload-environment to suppress any `not known to be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1877 ;; defined' warnings at the end of this file (this only matters for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1878 ;; functions which are autoloaded and compiled in the same file, if the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1879 ;; autoload already exists in the compilation environment, we wouldn't have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1880 ;; warned anyway.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1881 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1882 (let* ((name (if (byte-compile-constp (nth 1 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1883 (eval (nth 1 form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1884 ;; In v19, the 5th arg to autoload can be t, nil, 'macro, or 'keymap.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1885 (macrop (and (byte-compile-constp (nth 5 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1886 (memq (eval (nth 5 form)) '(t macro))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1887 ;; (functionp (and (byte-compile-constp (nth 5 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1888 ;; (eq 'nil (eval (nth 5 form)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1889 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1890 (if (and macrop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1891 (let ((form form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1892 ;; all forms are constant
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1893 (while (if (setq form (cdr form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1894 (byte-compile-constp (car form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1895 (null form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1896 ;; eval the macro autoload into the compilation enviroment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1897 (eval form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1898
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1899 (if name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1900 (let ((old (assq name byte-compile-autoload-environment)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1901 (cond (old
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1902 (if (memq 'redefine byte-compile-warnings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1903 (byte-compile-warn "multiple autoloads for %s" name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1904 (setcdr old form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1905 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1906 ;; We only use the names in the autoload environment, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1907 ;; it might be useful to have the bodies some day.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1908 (setq byte-compile-autoload-environment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1909 (cons (cons name form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1910 byte-compile-autoload-environment)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1911 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1912 ;; Now output the form.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1913 (if (stringp (nth 3 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1914 form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1915 ;; No doc string, so we can compile this as a normal form.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1916 (byte-compile-keep-pending form 'byte-compile-normal-call)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1917
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1918 (put 'defvar 'byte-hunk-handler 'byte-compile-file-form-defvar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1919 (put 'defconst 'byte-hunk-handler 'byte-compile-file-form-defvar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1920 (defun byte-compile-file-form-defvar (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1921 (if (> (length form) 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1922 (byte-compile-warn "%s used with too many args (%s)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1923 (car form) (nth 1 form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1924 (if (and (> (length form) 3) (not (stringp (nth 3 form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1925 (byte-compile-warn "Third arg to %s %s is not a string: %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1926 (car form) (nth 1 form) (nth 3 form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1927 (if (null (nth 3 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1928 ;; Since there is no doc string, we can compile this as a normal form,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1929 ;; and not do a file-boundary.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1930 (byte-compile-keep-pending form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1931 (if (memq 'free-vars byte-compile-warnings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1932 (setq byte-compile-bound-variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1933 (cons (cons (nth 1 form) byte-compile-global-bit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1934 byte-compile-bound-variables)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1935 (cond ((consp (nth 2 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1936 (setq form (copy-sequence form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1937 (setcar (cdr (cdr form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1938 (byte-compile-top-level (nth 2 form) nil 'file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1939
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1940 ;; The following turns out not to be necessary, since we emit a call to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1941 ;; defvar, which can hack Vfile_domain by itself!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1942 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1943 ;; If a file domain has been set, emit (put 'VAR 'variable-domain ...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1944 ;; after this defvar.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1945 ; (if byte-compile-file-domain
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1946 ; (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1947 ; ;; Actually, this will emit the (put ...) before the (defvar ...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1948 ; ;; but I don't think that can matter in this case.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1949 ; (byte-compile-keep-pending
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1950 ; (list 'put (list 'quote (nth 1 form)) ''variable-domain
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1951 ; (list 'quote byte-compile-file-domain)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1952 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1953
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1954 (put 'require 'byte-hunk-handler 'byte-compile-file-form-eval-boundary)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1955 (defun byte-compile-file-form-eval-boundary (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1956 (eval form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1957 (byte-compile-keep-pending form 'byte-compile-normal-call))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1958
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1959 (put 'progn 'byte-hunk-handler 'byte-compile-file-form-progn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1960 (put 'prog1 'byte-hunk-handler 'byte-compile-file-form-progn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1961 (put 'prog2 'byte-hunk-handler 'byte-compile-file-form-progn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1962 (defun byte-compile-file-form-progn (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1963 (mapcar 'byte-compile-file-form (cdr form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1964 ;; Return nil so the forms are not output twice.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1965 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1966
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1967 ;; This handler is not necessary, but it makes the output from dont-compile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1968 ;; and similar macros cleaner.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1969 (put 'eval 'byte-hunk-handler 'byte-compile-file-form-eval)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1970 (defun byte-compile-file-form-eval (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1971 (if (eq (car-safe (nth 1 form)) 'quote)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1972 (nth 1 (nth 1 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1973 (byte-compile-keep-pending form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1974
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1975 (put 'defun 'byte-hunk-handler 'byte-compile-file-form-defun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1976 (defun byte-compile-file-form-defun (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1977 (byte-compile-file-form-defmumble form nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1978
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1979 (put 'defmacro 'byte-hunk-handler 'byte-compile-file-form-defmacro)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1980 (defun byte-compile-file-form-defmacro (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1981 (byte-compile-file-form-defmumble form t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1982
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1983 (defun byte-compile-compiled-obj-to-list (obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1984 ;; #### this is fairly disgusting. Rewrite the code instead
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1985 ;; so that it doesn't create compiled objects in the first place!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1986 ;; Much better than creating them and then "uncreating" them
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1987 ;; like this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1988 (read (concat "("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1989 (substring (let ((print-readably t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1990 (prin1-to-string obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1991 2 -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1992 ")")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1993
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1994 (defun byte-compile-file-form-defmumble (form macrop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1995 (let* ((name (car (cdr form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1996 (this-kind (if macrop 'byte-compile-macro-environment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1997 'byte-compile-function-environment))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1998 (that-kind (if macrop 'byte-compile-function-environment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1999 'byte-compile-macro-environment))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2000 (this-one (assq name (symbol-value this-kind)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2001 (that-one (assq name (symbol-value that-kind)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2002 (byte-compile-free-references nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2003 (byte-compile-free-assignments nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2004
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2005 ;; When a function or macro is defined, add it to the call tree so that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2006 ;; we can tell when functions are not used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2007 (if byte-compile-generate-call-tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2008 (or (assq name byte-compile-call-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2009 (setq byte-compile-call-tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2010 (cons (list name nil nil) byte-compile-call-tree))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2011
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2012 (setq byte-compile-current-form name) ; for warnings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2013 (if (memq 'redefine byte-compile-warnings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2014 (byte-compile-arglist-warn form macrop))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2015 (if byte-compile-verbose
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2016 (message "Compiling %s... (%s)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2017 ;; #### filename used free
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2018 (if filename (file-name-nondirectory filename) "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2019 (nth 1 form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2020 (cond (that-one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2021 (if (and (memq 'redefine byte-compile-warnings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2022 ;; hack hack: don't warn when compiling the stubs in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2023 ;; bytecomp-runtime...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2024 (not (assq (nth 1 form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2025 byte-compile-initial-macro-environment)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2026 (byte-compile-warn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2027 "%s defined multiple times, as both function and macro"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2028 (nth 1 form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2029 (setcdr that-one nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2030 (this-one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2031 (if (and (memq 'redefine byte-compile-warnings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2032 ;; hack: don't warn when compiling the magic internal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2033 ;; byte-compiler macros in bytecomp-runtime.el...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2034 (not (assq (nth 1 form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2035 byte-compile-initial-macro-environment)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2036 (byte-compile-warn "%s %s defined multiple times in this file"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2037 (if macrop "macro" "function")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2038 (nth 1 form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2039 ((and (fboundp name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2040 (or (subrp (symbol-function name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2041 (eq (car-safe (symbol-function name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2042 (if macrop 'lambda 'macro))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2043 (if (memq 'redefine byte-compile-warnings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2044 (byte-compile-warn "%s %s being redefined as a %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2045 (if (subrp (symbol-function name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2046 "subr"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2047 (if macrop "function" "macro"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2048 (nth 1 form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2049 (if macrop "macro" "function")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2050 ;; shadow existing definition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2051 (set this-kind
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2052 (cons (cons name nil) (symbol-value this-kind))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2053 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2054 (let ((body (nthcdr 3 form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2055 (if (and (stringp (car body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2056 (symbolp (car-safe (cdr-safe body)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2057 (car-safe (cdr-safe body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2058 (stringp (car-safe (cdr-safe (cdr-safe body)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2059 (byte-compile-warn "Probable `\"' without `\\' in doc string of %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2060 (nth 1 form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2061 (let* ((new-one (byte-compile-lambda (cons 'lambda (nthcdr 2 form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2062 (code (byte-compile-byte-code-maker new-one)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2063 (if this-one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2064 (setcdr this-one new-one)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2065 (set this-kind
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2066 (cons (cons name new-one) (symbol-value this-kind))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2067 (if (and (stringp (nth 3 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2068 (eq 'quote (car-safe code))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2069 (eq 'lambda (car-safe (nth 1 code))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2070 (cons (car form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2071 (cons name (cdr (nth 1 code))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2072 (byte-compile-flush-pending)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2073 (if (not (stringp (nth 3 form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2074 ;; No doc string. Provide -1 as the "doc string index"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2075 ;; so that no element will be treated as a doc string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2076 (byte-compile-output-docform
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2077 (if (byte-compile-version-cond byte-compile-emacs18-compatibility)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2078 "\n(fset '" "\n(defalias '")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2079 name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2080 (cond ((atom code)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2081 (if macrop '(" '(macro . #[" -1 "])") '(" #[" -1 "]")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2082 ((eq (car code) 'quote)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2083 (setq code new-one)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2084 (if macrop '(" '(macro " -1 ")") '(" '(" -1 ")")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2085 ((if macrop '(" (cons 'macro (" -1 "))") '(" (" -1 ")"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2086 ;; FSF just calls `(append code nil)' here but that relies
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2087 ;; on horrible C kludges in concat() that accept byte-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2088 ;; compiled objects and pretend they're vectors.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2089 (if (compiled-function-p code)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2090 (byte-compile-compiled-obj-to-list code)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2091 (append code nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2092 (and (atom code) byte-compile-dynamic
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2093 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2094 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2095 ;; Output the form by hand, that's much simpler than having
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2096 ;; b-c-output-file-form analyze the defalias.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2097 (byte-compile-output-docform
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2098 (if (byte-compile-version-cond byte-compile-emacs18-compatibility)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2099 "\n(fset '" "\n(defalias '")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2100 name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2101 (cond ((atom code) ; compiled-function-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2102 (if macrop '(" '(macro . #[" 4 "])") '(" #[" 4 "]")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2103 ((eq (car code) 'quote)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2104 (setq code new-one)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2105 (if macrop '(" '(macro " 2 ")") '(" '(" 2 ")")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2106 ((if macrop '(" (cons 'macro (" 5 "))") '(" (" 5 ")"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2107 ;; The result of byte-compile-byte-code-maker is either a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2108 ;; compiled-function object, or a list of some kind. If it's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2109 ;; not a cons, we must coerce it into a list of the elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2110 ;; to be printed to the file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2111 (if (consp code)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2112 code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2113 (nconc (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2114 (compiled-function-arglist code)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2115 (compiled-function-instructions code)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2116 (compiled-function-constants code)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2117 (compiled-function-stack-depth code))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2118 (let ((doc (documentation code t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2119 (if doc (list doc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2120 (if (commandp code)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2121 (list (nth 1 (compiled-function-interactive code))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2122 (and (atom code) byte-compile-dynamic
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2123 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2124 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2125 (princ ")" byte-compile-outbuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2126 nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2128 ;; Print Lisp object EXP in the output file, inside a comment,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2129 ;; and return the file position it will have.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2130 ;; If QUOTED is non-nil, print with quoting; otherwise, print without quoting.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2131 (defun byte-compile-output-as-comment (exp quoted)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2132 (let ((position (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2133 (set-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2134 (prog1 (current-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2135 (set-buffer byte-compile-outbuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2137 ;; Insert EXP, and make it a comment with #@LENGTH.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2138 (insert " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2139 (if quoted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2140 (prin1 exp byte-compile-outbuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2141 (princ exp byte-compile-outbuffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2142 (goto-char position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2143 ;; Quote certain special characters as needed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2144 ;; get_doc_string in doc.c does the unquoting.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2145 (while (search-forward "\^A" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2146 (replace-match "\^A\^A" t t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2147 (goto-char position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2148 (while (search-forward "\000" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2149 (replace-match "\^A0" t t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2150 (goto-char position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2151 (while (search-forward "\037" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2152 (replace-match "\^A_" t t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2153 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2154 (insert "\037")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2155 (goto-char position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2156 (insert "#@" (format "%d" (- (point-max) position)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2157
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2158 ;; Save the file position of the object.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2159 ;; Note we should add 1 to skip the space
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2160 ;; that we inserted before the actual doc string,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2161 ;; and subtract 1 to convert from an 1-origin Emacs position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2162 ;; to a file position; they cancel.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2163 (setq position (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2164 (goto-char (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2165 position))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2166
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2168
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2169 ;; The `domain' declaration. This is legal only at top-level in a file, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2170 ;; should generally be the first form in the file. It is not legal inside
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2171 ;; function bodies.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2173 (put 'domain 'byte-hunk-handler 'byte-compile-file-form-domain)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2174 (defun byte-compile-file-form-domain (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2175 (if (not (null (cdr (cdr form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2176 (byte-compile-warn "domain used with too many arguments: %s" form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2177 (let ((domain (nth 1 form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2178 (or (null domain)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2179 (stringp domain)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2180 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2181 (byte-compile-warn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2182 "argument to `domain' declaration must be a literal string: %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2183 form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2184 (setq domain nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2185 (setq byte-compile-file-domain domain))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2186 (byte-compile-keep-pending form 'byte-compile-normal-call))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2187
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2188 (defun byte-compile-domain (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2189 (byte-compile-warn "The `domain' declaration is legal only at top-level: %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2190 (let ((print-escape-newlines t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2191 (print-level 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2192 (print-length 4))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2193 (prin1-to-string form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2194 (byte-compile-normal-call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2195 (list 'signal ''error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2196 (list 'quote (list "`domain' used inside a function" form)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2197
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2198
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2199 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2200 (defun byte-compile (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2201 "If FORM is a symbol, byte-compile its function definition.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2202 If FORM is a lambda or a macro, byte-compile it as a function."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2203 (displaying-byte-compile-warnings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2204 (byte-compile-close-variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2205 (let* ((fun (if (symbolp form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2206 (and (fboundp form) (symbol-function form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2207 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2208 (macro (eq (car-safe fun) 'macro)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2209 (if macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2210 (setq fun (cdr fun)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2211 (cond ((eq (car-safe fun) 'lambda)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2212 (setq fun (if macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2213 (cons 'macro (byte-compile-lambda fun))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2214 (byte-compile-lambda fun)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2215 (if (symbolp form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2216 (defalias form fun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2217 fun)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2218
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2219 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2220 (defun byte-compile-sexp (sexp &optional msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2221 "Compile and return SEXP."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2222 (displaying-byte-compile-warnings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2223 (byte-compile-close-variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2224 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2225 (byte-compile-top-level sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2226 (byte-compile-warn-about-unresolved-functions msg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2227
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2228 ;; Given a function made by byte-compile-lambda, make a form which produces it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2229 (defun byte-compile-byte-code-maker (fun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2230 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2231 ((byte-compile-version-cond byte-compile-emacs18-compatibility)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2232 ;; Return (quote (lambda ...)).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2233 (list 'quote (byte-compile-byte-code-unmake fun)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2234 ;; ## atom is faster than compiled-func-p.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2235 ((atom fun) ; compiled-function-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2236 ;; generate-emacs19-bytecodes must be on, otherwise byte-compile-lambda
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2237 ;; would have produced a lambda.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2238 fun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2239 ;; b-c-lambda didn't produce a compiled-function, so it's either a trivial
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2240 ;; function, or this is Emacs 18, or generate-emacs19-bytecodes is off.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2241 ((let (tmp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2242 (if (and (setq tmp (assq 'byte-code (cdr-safe (cdr fun))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2243 (null (cdr (memq tmp fun))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2244 ;; Generate a make-byte-code call.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2245 (let* ((interactive (assq 'interactive (cdr (cdr fun)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2246 (nconc (list 'make-byte-code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2247 (list 'quote (nth 1 fun)) ;arglist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2248 (nth 1 tmp) ;bytes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2249 (nth 2 tmp) ;consts
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2250 (nth 3 tmp)) ;depth
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2251 (cond ((stringp (nth 2 fun))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2252 (list (nth 2 fun))) ;doc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2253 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2254 (list nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2255 (cond (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2256 (list (if (or (null (nth 1 interactive))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2257 (stringp (nth 1 interactive)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2258 (nth 1 interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2259 ;; Interactive spec is a list or a variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2260 ;; (if it is correct).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2261 (list 'quote (nth 1 interactive))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2262 ;; a non-compiled function (probably trivial)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2263 (list 'quote fun))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2264
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2265 ;; Turn a function into an ordinary lambda. Needed for v18 files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2266 (defun byte-compile-byte-code-unmake (function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2267 (if (consp function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2268 function ; It already is a lambda.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2270 (nconc (list 'lambda (compiled-function-arglist function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2271 (let ((doc (documentation function t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2272 (if doc (list doc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2273 (if (commandp function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2274 (list (compiled-function-interactive function)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2275 (list (list 'byte-code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2276 (compiled-function-instructions function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2277 (compiled-function-constants function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2278 (compiled-function-stack-depth function))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2279
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2280
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2281 ;; Byte-compile a lambda-expression and return a valid function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2282 ;; The value is usually a compiled function but may be the original
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2283 ;; lambda-expression.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2284 (defun byte-compile-lambda (fun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2285 (or (eq 'lambda (car-safe fun))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2286 (error "not a lambda -- %s" (prin1-to-string fun)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2287 (let* ((arglist (nth 1 fun))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2288 (byte-compile-bound-variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2289 (let ((new-bindings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2290 (mapcar (function (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2291 (cons x byte-compile-arglist-bit)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2292 (and (memq 'free-vars byte-compile-warnings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2293 (delq '&rest (delq '&optional
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2294 (copy-sequence arglist)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2295 (nconc new-bindings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2296 (cons 'new-scope byte-compile-bound-variables))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2297 (body (cdr (cdr fun)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2298 (doc (if (stringp (car body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2299 (prog1 (car body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2300 (setq body (cdr body)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2301 (int (assq 'interactive body)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2302 (let ((rest arglist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2303 (while rest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2304 (cond ((not (symbolp (car rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2305 (byte-compile-warn "non-symbol in arglist: %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2306 (prin1-to-string (car rest))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2307 ((memq (car rest) '(t nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2308 (byte-compile-warn "constant in arglist: %s" (car rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2309 ((and (= ?\& (aref (symbol-name (car rest)) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2310 (not (memq (car rest) '(&optional &rest))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2311 (byte-compile-warn "unrecognised `&' keyword in arglist: %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2312 (car rest))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2313 (setq rest (cdr rest))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2314 (cond (int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2315 ;; Skip (interactive) if it is in front (the most usual location).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2316 (if (eq int (car body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2317 (setq body (cdr body)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2318 (cond ((consp (cdr int))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2319 (if (cdr (cdr int))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2320 (byte-compile-warn "malformed interactive spec: %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2321 (prin1-to-string int)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2322 ;; If the interactive spec is a call to `list',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2323 ;; don't compile it, because `call-interactively'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2324 ;; looks at the args of `list'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2325 (let ((form (nth 1 int)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2326 (while (or (eq (car-safe form) 'let)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2327 (eq (car-safe form) 'let*)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2328 (eq (car-safe form) 'save-excursion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2329 (while (consp (cdr form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2330 (setq form (cdr form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2331 (setq form (car form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2332 (or (eq (car-safe form) 'list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2333 (setq int (list 'interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2334 (byte-compile-top-level (nth 1 int)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2335 ((cdr int)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2336 (byte-compile-warn "malformed interactive spec: %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2337 (prin1-to-string int))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2338 (let ((compiled (byte-compile-top-level (cons 'progn body) nil 'lambda)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2339 (if (memq 'unused-vars byte-compile-warnings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2340 ;; done compiling in this scope, warn now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2341 (byte-compile-warn-about-unused-variables))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2342 (if (and (eq 'byte-code (car-safe compiled))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2343 (not (byte-compile-version-cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2344 byte-compile-emacs18-compatibility)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2345 (apply 'make-byte-code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2346 (append (list arglist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2347 ;; byte-string, constants-vector, stack depth
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2348 (cdr compiled)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2349 ;; optionally, the doc string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2350 (if (or doc int)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2351 (list doc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2352 ;; optionally, the interactive spec.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2353 (if int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2354 (list (nth 1 int)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2355 (setq compiled
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2356 (nconc (if int (list int))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2357 (cond ((eq (car-safe compiled) 'progn) (cdr compiled))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2358 (compiled (list compiled)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2359 (nconc (list 'lambda arglist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2360 (if (or doc (stringp (car compiled)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2361 (cons doc (cond (compiled)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2362 (body (list nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2363 compiled))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2364
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2365 (defun byte-compile-constants-vector ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2366 ;; Builds the constants-vector from the current variables and constants.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2367 ;; This modifies the constants from (const . nil) to (const . offset).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2368 ;; To keep the byte-codes to look up the vector as short as possible:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2369 ;; First 6 elements are vars, as there are one-byte varref codes for those.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2370 ;; Next up to byte-constant-limit are constants, still with one-byte codes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2371 ;; Next variables again, to get 2-byte codes for variable lookup.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2372 ;; The rest of the constants and variables need 3-byte byte-codes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2373 (let* ((i -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2374 (rest (nreverse byte-compile-variables)) ; nreverse because the first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2375 (other (nreverse byte-compile-constants)) ; vars often are used most.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2376 ret tmp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2377 (limits '(5 ; Use the 1-byte varref codes,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2378 63 ; 1-constlim ; 1-byte byte-constant codes,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2379 255 ; 2-byte varref codes,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2380 65535)) ; 3-byte codes for the rest.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2381 limit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2382 (while (or rest other)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2383 (setq limit (car limits))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2384 (while (and rest (not (eq i limit)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2385 (if (setq tmp (assq (car (car rest)) ret))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2386 (setcdr (car rest) (cdr tmp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2387 (setcdr (car rest) (setq i (1+ i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2388 (setq ret (cons (car rest) ret)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2389 (setq rest (cdr rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2390 (setq limits (cdr limits)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2391 rest (prog1 other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2392 (setq other rest))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2393 (apply 'vector (nreverse (mapcar 'car ret)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2394
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2395 ;; Given an expression FORM, compile it and return an equivalent byte-code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2396 ;; expression (a call to the function byte-code).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2397 (defun byte-compile-top-level (form &optional for-effect output-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2398 ;; OUTPUT-TYPE advises about how form is expected to be used:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2399 ;; 'eval or nil -> a single form,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2400 ;; 'progn or t -> a list of forms,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2401 ;; 'lambda -> body of a lambda,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2402 ;; 'file -> used at file-level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2403 (let ((byte-compile-constants nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2404 (byte-compile-variables nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2405 (byte-compile-tag-number 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2406 (byte-compile-depth 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2407 (byte-compile-maxdepth 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2408 (byte-compile-output nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2409 (if (memq byte-optimize '(t source))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2410 (setq form (byte-optimize-form form for-effect)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2411 (while (and (eq (car-safe form) 'progn) (null (cdr (cdr form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2412 (setq form (nth 1 form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2413 (if (and (eq 'byte-code (car-safe form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2414 (not (memq byte-optimize '(t byte)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2415 (stringp (nth 1 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2416 (vectorp (nth 2 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2417 (natnump (nth 3 form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2418 form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2419 (byte-compile-form form for-effect)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2420 (byte-compile-out-toplevel for-effect output-type))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2421
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2422 (defun byte-compile-out-toplevel (&optional for-effect output-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2423 (if for-effect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2424 ;; The stack is empty. Push a value to be returned from (byte-code ..).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2425 (if (eq (car (car byte-compile-output)) 'byte-discard)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2426 (setq byte-compile-output (cdr byte-compile-output))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2427 (byte-compile-push-constant
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2428 ;; Push any constant - preferably one which already is used, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2429 ;; a number or symbol - ie not some big sequence. The return value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2430 ;; isn't returned, but it would be a shame if some textually large
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2431 ;; constant was not optimized away because we chose to return it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2432 (and (not (assq nil byte-compile-constants)) ; Nil is often there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2433 (let ((tmp (reverse byte-compile-constants)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2434 (while (and tmp (not (or (symbolp (car (car tmp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2435 (numberp (car (car tmp))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2436 (setq tmp (cdr tmp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2437 (car (car tmp)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2438 (byte-compile-out 'byte-return 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2439 (setq byte-compile-output (nreverse byte-compile-output))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2440 (if (memq byte-optimize '(t byte))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2441 (setq byte-compile-output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2442 (byte-optimize-lapcode byte-compile-output for-effect)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2443
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2444 ;; Decompile trivial functions:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2445 ;; only constants and variables, or a single funcall except in lambdas.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2446 ;; Except for Lisp_Compiled objects, forms like (foo "hi")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2447 ;; are still quicker than (byte-code "..." [foo "hi"] 2).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2448 ;; Note that even (quote foo) must be parsed just as any subr by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2449 ;; interpreter, so quote should be compiled into byte-code in some contexts.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2450 ;; What to leave uncompiled:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2451 ;; lambda -> never. we used to leave it uncompiled if the body was
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2452 ;; a single atom, but that causes confusion if the docstring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2453 ;; uses the (file . pos) syntax. Besides, now that we have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2454 ;; the Lisp_Compiled type, the compiled form is faster.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2455 ;; eval -> atom, quote or (function atom atom atom)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2456 ;; progn -> as <<same-as-eval>> or (progn <<same-as-eval>> atom)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2457 ;; file -> as progn, but takes both quotes and atoms, and longer forms.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2458 (let (rest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2459 (maycall (not (eq output-type 'lambda))) ; t if we may make a funcall.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2460 tmp body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2461 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2462 ;; #### This should be split out into byte-compile-nontrivial-function-p.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2463 ((or (eq output-type 'lambda)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2464 (nthcdr (if (eq output-type 'file) 50 8) byte-compile-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2465 (assq 'TAG byte-compile-output) ; Not necessary, but speeds up a bit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2466 (not (setq tmp (assq 'byte-return byte-compile-output)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2467 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2468 (setq rest (nreverse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2469 (cdr (memq tmp (reverse byte-compile-output)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2470 (while (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2471 ((memq (car (car rest)) '(byte-varref byte-constant))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2472 (setq tmp (car (cdr (car rest))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2473 (if (if (eq (car (car rest)) 'byte-constant)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2474 (or (consp tmp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2475 (and (symbolp tmp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2476 (not (keywordp tmp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2477 (not (memq tmp '(nil t))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2478 (if maycall
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2479 (setq body (cons (list 'quote tmp) body)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2480 (setq body (cons tmp body))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2481 ((and maycall
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2482 ;; Allow a funcall if at most one atom follows it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2483 (null (nthcdr 3 rest))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2484 (setq tmp (get (car (car rest)) 'byte-opcode-invert))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2485 (or (null (cdr rest))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2486 (and (memq output-type '(file progn t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2487 (cdr (cdr rest))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2488 (eq (car (nth 1 rest)) 'byte-discard)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2489 (progn (setq rest (cdr rest)) t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2490 (setq maycall nil) ; Only allow one real function call.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2491 (setq body (nreverse body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2492 (setq body (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2493 (if (and (eq tmp 'funcall)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2494 (eq (car-safe (car body)) 'quote))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2495 (cons (nth 1 (car body)) (cdr body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2496 (cons tmp body))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2497 (or (eq output-type 'file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2498 (not (delq nil (mapcar 'consp (cdr (car body))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2499 (setq rest (cdr rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2500 rest))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2501 (let ((byte-compile-vector (byte-compile-constants-vector)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2502 (list 'byte-code (byte-compile-lapcode byte-compile-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2503 byte-compile-vector byte-compile-maxdepth)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2504 ;; it's a trivial function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2505 ((cdr body) (cons 'progn (nreverse body)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2506 ((car body)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2507
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2508 ;; Given BODY, compile it and return a new body.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2509 (defun byte-compile-top-level-body (body &optional for-effect)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2510 (setq body (byte-compile-top-level (cons 'progn body) for-effect t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2511 (cond ((eq (car-safe body) 'progn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2512 (cdr body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2513 (body
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2514 (list body))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2515
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2516 ;; This is the recursive entry point for compiling each subform of an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2517 ;; expression.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2518 ;; If for-effect is non-nil, byte-compile-form will output a byte-discard
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2519 ;; before terminating (ie no value will be left on the stack).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2520 ;; A byte-compile handler may, when for-effect is non-nil, choose output code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2521 ;; which does not leave a value on the stack, and then set for-effect to nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2522 ;; (to prevent byte-compile-form from outputting the byte-discard).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2523 ;; If a handler wants to call another handler, it should do so via
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2524 ;; byte-compile-form, or take extreme care to handle for-effect correctly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2525 ;; (Use byte-compile-form-do-effect to reset the for-effect flag too.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2526 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2527 (defun byte-compile-form (form &optional for-effect)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2528 (setq form (macroexpand form byte-compile-macro-environment))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2529 (cond ((not (consp form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2530 ;; XEmacs addition: keywordp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2531 (cond ((or (not (symbolp form)) (keywordp form) (memq form '(nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2532 (byte-compile-constant form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2533 ((and for-effect byte-compile-delete-errors)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2534 (setq for-effect nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2535 (t (byte-compile-variable-ref 'byte-varref form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2536 ((symbolp (car form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2537 (let* ((fn (car form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2538 (handler (get fn 'byte-compile)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2539 (if (memq fn '(t nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2540 (byte-compile-warn "%s called as a function" fn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2541 (if (and handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2542 (or (not (byte-compile-version-cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2543 byte-compile-emacs18-compatibility))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2544 (not (get (get fn 'byte-opcode) 'emacs19-opcode))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2545 (funcall handler form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2546 (if (memq 'callargs byte-compile-warnings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2547 (byte-compile-callargs-warn form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2548 (byte-compile-normal-call form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2549 ((and (or (compiled-function-p (car form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2550 (eq (car-safe (car form)) 'lambda))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2551 ;; if the form comes out the same way it went in, that's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2552 ;; because it was malformed, and we couldn't unfold it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2553 (not (eq form (setq form (byte-compile-unfold-lambda form)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2554 (byte-compile-form form for-effect)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2555 (setq for-effect nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2556 ((byte-compile-normal-call form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2557 (if for-effect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2558 (byte-compile-discard)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2559
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2560 (defun byte-compile-normal-call (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2561 (if byte-compile-generate-call-tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2562 (byte-compile-annotate-call-tree form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2563 (byte-compile-push-constant (car form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2564 (mapcar 'byte-compile-form (cdr form)) ; wasteful, but faster.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2565 (byte-compile-out 'byte-call (length (cdr form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2566
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2567 ;; kludge added to XEmacs to work around the bogosities of a nonlexical lisp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2568 (or (fboundp 'globally-boundp) (fset 'globally-boundp 'boundp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2569
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2570 (defun byte-compile-variable-ref (base-op var &optional varbind-flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2571 (if (or (not (symbolp var)) (keywordp var) (memq var '(nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2572 (byte-compile-warn (if (eq base-op 'byte-varbind)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2573 "Attempt to let-bind %s %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2574 "Variable reference to %s %s")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2575 (if (symbolp var) "constant" "nonvariable")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2576 (prin1-to-string var))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2577 (if (and (get var 'byte-obsolete-variable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2578 (memq 'obsolete byte-compile-warnings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2579 (let ((ob (get var 'byte-obsolete-variable)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2580 (byte-compile-warn "%s is an obsolete variable; %s" var
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2581 (if (stringp ob)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2582 ob
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2583 (format "use %s instead." ob)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2584 (if (memq 'free-vars byte-compile-warnings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2585 (if (eq base-op 'byte-varbind)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2586 (setq byte-compile-bound-variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2587 (cons (cons var (or varbind-flags 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2588 byte-compile-bound-variables))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2589 (or (globally-boundp var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2590 (let ((cell (assq var byte-compile-bound-variables)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2591 (if cell (setcdr cell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2592 (logior (cdr cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2593 (if (eq base-op 'byte-varset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2594 byte-compile-assigned-bit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2595 byte-compile-referenced-bit)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2596 (if (eq base-op 'byte-varset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2597 (or (memq var byte-compile-free-assignments)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2598 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2599 (byte-compile-warn "assignment to free variable %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2600 var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2601 (setq byte-compile-free-assignments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2602 (cons var byte-compile-free-assignments))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2603 (or (memq var byte-compile-free-references)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2604 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2605 (byte-compile-warn "reference to free variable %s" var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2606 (setq byte-compile-free-references
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2607 (cons var byte-compile-free-references)))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2608 (let ((tmp (assq var byte-compile-variables)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2609 (or tmp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2610 (setq tmp (list var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2611 byte-compile-variables (cons tmp byte-compile-variables)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2612 (byte-compile-out base-op tmp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2613
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2614 (defmacro byte-compile-get-constant (const)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2615 (` (or (if (stringp (, const))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2616 (assoc (, const) byte-compile-constants)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2617 (assq (, const) byte-compile-constants))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2618 (car (setq byte-compile-constants
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2619 (cons (list (, const)) byte-compile-constants))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2620
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2621 ;; Use this when the value of a form is a constant. This obeys for-effect.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2622 (defun byte-compile-constant (const)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2623 (if for-effect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2624 (setq for-effect nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2625 (byte-compile-out 'byte-constant (byte-compile-get-constant const))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2626
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2627 ;; Use this for a constant that is not the value of its containing form.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2628 ;; This ignores for-effect.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2629 (defun byte-compile-push-constant (const)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2630 (let ((for-effect nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2631 (inline (byte-compile-constant const))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2632
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2633
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2634 ;; Compile those primitive ordinary functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2635 ;; which have special byte codes just for speed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2636
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2637 (defmacro byte-defop-compiler (function &optional compile-handler)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2638 ;; add a compiler-form for FUNCTION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2639 ;; If function is a symbol, then the variable "byte-SYMBOL" must name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2640 ;; the opcode to be used. If function is a list, the first element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2641 ;; is the function and the second element is the bytecode-symbol.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2642 ;; COMPILE-HANDLER is the function to use to compile this byte-op, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2643 ;; may be the abbreviations 0, 1, 2, 3, 0-1, 1-2, 2-3, 0+1, 1+1, 2+1,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2644 ;; 0-1+1, 1-2+1, 2-3+1, 0+2, or 1+2. If it is nil, then the handler is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2645 ;; "byte-compile-SYMBOL."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2646 (let (opcode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2647 (if (symbolp function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2648 (setq opcode (intern (concat "byte-" (symbol-name function))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2649 (setq opcode (car (cdr function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2650 function (car function)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2651 (let ((fnform
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2652 (list 'put (list 'quote function) ''byte-compile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2653 (list 'quote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2654 (or (cdr (assq compile-handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2655 '((0 . byte-compile-no-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2656 (1 . byte-compile-one-arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2657 (2 . byte-compile-two-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2658 (3 . byte-compile-three-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2659 (0-1 . byte-compile-zero-or-one-arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2660 (1-2 . byte-compile-one-or-two-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2661 (2-3 . byte-compile-two-or-three-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2662 (0+1 . byte-compile-no-args-with-one-extra)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2663 (1+1 . byte-compile-one-arg-with-one-extra)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2664 (2+1 . byte-compile-two-args-with-one-extra)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2665 (0-1+1 . byte-compile-zero-or-one-arg-with-one-extra)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2666 (1-2+1 . byte-compile-one-or-two-args-with-one-extra)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2667 (2-3+1 . byte-compile-two-or-three-args-with-one-extra)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2668 (0+2 . byte-compile-no-args-with-two-extra)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2669 (1+2 . byte-compile-one-arg-with-two-extra)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2670
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2671 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2672 compile-handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2673 (intern (concat "byte-compile-"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2674 (symbol-name function))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2675 (if opcode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2676 (list 'progn fnform
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2677 (list 'put (list 'quote function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2678 ''byte-opcode (list 'quote opcode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2679 (list 'put (list 'quote opcode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2680 ''byte-opcode-invert (list 'quote function)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2681 fnform))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2682
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2683 (defmacro byte-defop-compiler19 (function &optional compile-handler)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2684 ;; Just like byte-defop-compiler, but defines an opcode that will only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2685 ;; be used when byte-compile-emacs18-compatibility is false.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2686 (if (and (byte-compile-single-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2687 byte-compile-emacs18-compatibility)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2688 ;; #### instead of doing nothing, this should do some remprops,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2689 ;; #### to protect against the case where a single-version compiler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2690 ;; #### is loaded into a world that has contained a multi-version one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2691 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2692 (list 'progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2693 (list 'put
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2694 (list 'quote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2695 (or (car (cdr-safe function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2696 (intern (concat "byte-"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2697 (symbol-name (or (car-safe function) function))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2698 ''emacs19-opcode t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2699 (list 'byte-defop-compiler function compile-handler))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2700
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2701 (defmacro byte-defop-compiler-1 (function &optional compile-handler)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2702 (list 'byte-defop-compiler (list function nil) compile-handler))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2703
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2704
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2705 (put 'byte-call 'byte-opcode-invert 'funcall)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2706 (put 'byte-list1 'byte-opcode-invert 'list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2707 (put 'byte-list2 'byte-opcode-invert 'list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2708 (put 'byte-list3 'byte-opcode-invert 'list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2709 (put 'byte-list4 'byte-opcode-invert 'list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2710 (put 'byte-listN 'byte-opcode-invert 'list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2711 (put 'byte-concat2 'byte-opcode-invert 'concat)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2712 (put 'byte-concat3 'byte-opcode-invert 'concat)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2713 (put 'byte-concat4 'byte-opcode-invert 'concat)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2714 (put 'byte-concatN 'byte-opcode-invert 'concat)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2715 (put 'byte-insertN 'byte-opcode-invert 'insert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2716
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2717 (byte-defop-compiler (dot byte-point) 0+1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2718 (byte-defop-compiler (dot-max byte-point-max) 0+1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2719 (byte-defop-compiler (dot-min byte-point-min) 0+1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2720 (byte-defop-compiler point 0+1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2721 ;;(byte-defop-compiler mark 0) ;; obsolete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2722 (byte-defop-compiler point-max 0+1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2723 (byte-defop-compiler point-min 0+1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2724 (byte-defop-compiler following-char 0+1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2725 (byte-defop-compiler preceding-char 0+1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2726 (byte-defop-compiler current-column 0+1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2727 ;; FSF has special function here; generalized here by the 1+2 stuff.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2728 (byte-defop-compiler (indent-to-column byte-indent-to) 1+2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2729 (byte-defop-compiler indent-to 1+2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2730 (byte-defop-compiler eolp 0+1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2731 (byte-defop-compiler eobp 0+1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2732 (byte-defop-compiler bolp 0+1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2733 (byte-defop-compiler bobp 0+1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2734 (byte-defop-compiler current-buffer 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2735 ;;(byte-defop-compiler read-char 0) ;; obsolete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2736 (byte-defop-compiler interactive-p 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2737 (byte-defop-compiler19 widen 0+1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2738 (byte-defop-compiler19 end-of-line 0-1+1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2739 (byte-defop-compiler19 forward-char 0-1+1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2740 (byte-defop-compiler19 forward-line 0-1+1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2741 (byte-defop-compiler symbolp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2742 (byte-defop-compiler consp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2743 (byte-defop-compiler stringp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2744 (byte-defop-compiler listp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2745 (byte-defop-compiler not 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2746 (byte-defop-compiler (null byte-not) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2747 (byte-defop-compiler car 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2748 (byte-defop-compiler cdr 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2749 (byte-defop-compiler length 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2750 (byte-defop-compiler symbol-value 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2751 (byte-defop-compiler symbol-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2752 (byte-defop-compiler (1+ byte-add1) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2753 (byte-defop-compiler (1- byte-sub1) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2754 (byte-defop-compiler goto-char 1+1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2755 (byte-defop-compiler char-after 1+1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2756 (byte-defop-compiler set-buffer 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2757 ;;(byte-defop-compiler set-mark 1) ;; obsolete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2758 (byte-defop-compiler19 forward-word 1+1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2759 (byte-defop-compiler19 char-syntax 1+1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2760 (byte-defop-compiler19 nreverse 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2761 (byte-defop-compiler19 car-safe 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2762 (byte-defop-compiler19 cdr-safe 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2763 (byte-defop-compiler19 numberp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2764 (byte-defop-compiler19 integerp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2765 (byte-defop-compiler19 skip-chars-forward 1-2+1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2766 (byte-defop-compiler19 skip-chars-backward 1-2+1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2767 ;;(byte-defop-compiler (eql byte-eq) 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2768 (byte-defop-compiler eq 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2769 (byte-defop-compiler memq 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2770 (byte-defop-compiler cons 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2771 (byte-defop-compiler aref 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2772 (byte-defop-compiler (= byte-eqlsign) 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2773 (byte-defop-compiler (< byte-lss) 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2774 (byte-defop-compiler (> byte-gtr) 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2775 (byte-defop-compiler (<= byte-leq) 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2776 (byte-defop-compiler (>= byte-geq) 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2777 (byte-defop-compiler get 2+1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2778 (byte-defop-compiler nth 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2779 (byte-defop-compiler substring 2-3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2780 (byte-defop-compiler19 (move-marker byte-set-marker) 2-3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2781 (byte-defop-compiler19 set-marker 2-3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2782 (byte-defop-compiler19 match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2783 (byte-defop-compiler19 match-end 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2784 (byte-defop-compiler19 upcase 1+1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2785 (byte-defop-compiler19 downcase 1+1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2786 (byte-defop-compiler19 string= 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2787 (byte-defop-compiler19 string< 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2788 (byte-defop-compiler19 (string-equal byte-string=) 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2789 (byte-defop-compiler19 (string-lessp byte-string<) 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2790 (byte-defop-compiler19 equal 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2791 (byte-defop-compiler19 nthcdr 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2792 (byte-defop-compiler19 elt 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2793 (byte-defop-compiler19 member 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2794 (byte-defop-compiler19 assq 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2795 (byte-defop-compiler19 (rplaca byte-setcar) 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2796 (byte-defop-compiler19 (rplacd byte-setcdr) 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2797 (byte-defop-compiler19 setcar 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2798 (byte-defop-compiler19 setcdr 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2799 ;; buffer-substring now has its own function. This used to be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2800 ;; 2+1, but now all args are optional.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2801 (byte-defop-compiler19 buffer-substring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2802 (byte-defop-compiler19 delete-region 2+1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2803 (byte-defop-compiler19 narrow-to-region 2+1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2804 (byte-defop-compiler19 (% byte-rem) 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2805 (byte-defop-compiler aset 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2806
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2807 (byte-defop-compiler max byte-compile-associative)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2808 (byte-defop-compiler min byte-compile-associative)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2809 (byte-defop-compiler (+ byte-plus) byte-compile-associative)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2810 (byte-defop-compiler19 (* byte-mult) byte-compile-associative)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2811
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2812 ;;####(byte-defop-compiler19 move-to-column 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2813 (byte-defop-compiler-1 interactive byte-compile-noop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2814 (byte-defop-compiler-1 domain byte-compile-domain)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2815
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2816 ;; As of GNU Emacs 19.18 and Lucid Emacs 19.8, mod and % are different: `%'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2817 ;; means integral remainder and may have a negative result; `mod' is always
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2818 ;; positive, and accepts floating point args. All code which uses `mod' and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2819 ;; requires the new interpretation must be compiled with bytecomp version 2.18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2820 ;; or newer, or the emitted code will run the byte-code for `%' instead of an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2821 ;; actual call to `mod'. So be careful of compiling new code with an old
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2822 ;; compiler. Note also that `%' is more efficient than `mod' because the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2823 ;; former is byte-coded and the latter is not.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2824 ;;(byte-defop-compiler19 (mod byte-rem) 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2825
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2826
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2827 (defun byte-compile-subr-wrong-args (form n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2828 (byte-compile-warn "%s called with %d arg%s, but requires %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2829 (car form) (length (cdr form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2830 (if (= 1 (length (cdr form))) "" "s") n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2831 ;; get run-time wrong-number-of-args error.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2832 (byte-compile-normal-call form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2833
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2834 (defun byte-compile-no-args (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2835 (if (not (= (length form) 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2836 (byte-compile-subr-wrong-args form "none")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2837 (byte-compile-out (get (car form) 'byte-opcode) 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2838
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2839 (defun byte-compile-one-arg (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2840 (if (not (= (length form) 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2841 (byte-compile-subr-wrong-args form 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2842 (byte-compile-form (car (cdr form))) ;; Push the argument
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2843 (byte-compile-out (get (car form) 'byte-opcode) 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2844
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2845 (defun byte-compile-two-args (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2846 (if (not (= (length form) 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2847 (byte-compile-subr-wrong-args form 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2848 (byte-compile-form (car (cdr form))) ;; Push the arguments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2849 (byte-compile-form (nth 2 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2850 (byte-compile-out (get (car form) 'byte-opcode) 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2851
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2852 (defun byte-compile-three-args (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2853 (if (not (= (length form) 4))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2854 (byte-compile-subr-wrong-args form 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2855 (byte-compile-form (car (cdr form))) ;; Push the arguments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2856 (byte-compile-form (nth 2 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2857 (byte-compile-form (nth 3 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2858 (byte-compile-out (get (car form) 'byte-opcode) 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2859
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2860 (defun byte-compile-zero-or-one-arg (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2861 (let ((len (length form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2862 (cond ((= len 1) (byte-compile-one-arg (append form '(nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2863 ((= len 2) (byte-compile-one-arg form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2864 (t (byte-compile-subr-wrong-args form "0-1")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2865
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2866 (defun byte-compile-one-or-two-args (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2867 (let ((len (length form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2868 (cond ((= len 2) (byte-compile-two-args (append form '(nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2869 ((= len 3) (byte-compile-two-args form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2870 (t (byte-compile-subr-wrong-args form "1-2")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2871
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2872 (defun byte-compile-two-or-three-args (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2873 (let ((len (length form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2874 (cond ((= len 3) (byte-compile-three-args (append form '(nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2875 ((= len 4) (byte-compile-three-args form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2876 (t (byte-compile-subr-wrong-args form "2-3")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2877
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2878 ;; from Ben Wing <wing@666.com>: some inlined functions have extra
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2879 ;; optional args added to them in XEmacs 19.12. Changing the byte
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2880 ;; interpreter to deal with these args would be wrong and cause
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2881 ;; incompatibility, so we generate non-inlined calls for those cases.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2882 ;; Without the following functions, spurious warnings will be generated;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2883 ;; however, they would still compile correctly because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2884 ;; `byte-compile-subr-wrong-args' also converts the call to non-inlined.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2885
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2886 (defun byte-compile-no-args-with-one-extra (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2887 (let ((len (length form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2888 (cond ((= len 1) (byte-compile-no-args form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2889 ((= len 2) (byte-compile-normal-call form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2890 (t (byte-compile-subr-wrong-args form "0-1")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2891
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2892 (defun byte-compile-one-arg-with-one-extra (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2893 (let ((len (length form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2894 (cond ((= len 2) (byte-compile-one-arg form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2895 ((= len 3) (byte-compile-normal-call form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2896 (t (byte-compile-subr-wrong-args form "1-2")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2897
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2898 (defun byte-compile-two-args-with-one-extra (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2899 (let ((len (length form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2900 (cond ((= len 3) (byte-compile-two-args form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2901 ((= len 4) (byte-compile-normal-call form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2902 (t (byte-compile-subr-wrong-args form "2-3")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2903
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2904 (defun byte-compile-zero-or-one-arg-with-one-extra (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2905 (let ((len (length form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2906 (cond ((= len 1) (byte-compile-one-arg (append form '(nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2907 ((= len 2) (byte-compile-one-arg form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2908 ((= len 3) (byte-compile-normal-call form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2909 (t (byte-compile-subr-wrong-args form "0-2")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2910
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2911 (defun byte-compile-one-or-two-args-with-one-extra (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2912 (let ((len (length form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2913 (cond ((= len 2) (byte-compile-two-args (append form '(nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2914 ((= len 3) (byte-compile-two-args form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2915 ((= len 4) (byte-compile-normal-call form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2916 (t (byte-compile-subr-wrong-args form "1-3")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2917
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2918 (defun byte-compile-two-or-three-args-with-one-extra (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2919 (let ((len (length form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2920 (cond ((= len 3) (byte-compile-three-args (append form '(nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2921 ((= len 4) (byte-compile-three-args form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2922 ((= len 5) (byte-compile-normal-call form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2923 (t (byte-compile-subr-wrong-args form "2-4")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2924
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2925 (defun byte-compile-no-args-with-two-extra (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2926 (let ((len (length form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2927 (cond ((= len 1) (byte-compile-no-args form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2928 ((or (= len 2) (= len 3)) (byte-compile-normal-call form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2929 (t (byte-compile-subr-wrong-args form "0-2")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2930
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2931 (defun byte-compile-one-arg-with-two-extra (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2932 (let ((len (length form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2933 (cond ((= len 2) (byte-compile-one-arg form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2934 ((or (= len 3) (= len 4)) (byte-compile-normal-call form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2935 (t (byte-compile-subr-wrong-args form "1-3")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2936
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2937
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2938 (defun byte-compile-noop (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2939 (byte-compile-constant nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2940
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2941 (defun byte-compile-discard ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2942 (byte-compile-out 'byte-discard 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2943
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2944
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2945 ;; Compile a function that accepts one or more args and is right-associative.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2946 ;; We do it by left-associativity so that the operations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2947 ;; are done in the same order as in interpreted code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2948 (defun byte-compile-associative (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2949 (if (cdr form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2950 (let ((opcode (get (car form) 'byte-opcode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2951 (args (copy-sequence (cdr form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2952 (byte-compile-form (car args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2953 (setq args (cdr args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2954 (while args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2955 (byte-compile-form (car args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2956 (byte-compile-out opcode 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2957 (setq args (cdr args))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2958 (byte-compile-constant (eval form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2959
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2960
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2961 ;; more complicated compiler macros
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2962
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2963 (byte-defop-compiler list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2964 (byte-defop-compiler concat)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2965 (byte-defop-compiler fset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2966 (byte-defop-compiler insert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2967 (byte-defop-compiler-1 function byte-compile-function-form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2968 (byte-defop-compiler-1 - byte-compile-minus)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2969 (byte-defop-compiler19 (/ byte-quo) byte-compile-quo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2970 (byte-defop-compiler19 nconc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2971 (byte-defop-compiler-1 beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2972
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2973 (defun byte-compile-buffer-substring (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2974 (let ((len (length form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2975 ;; buffer-substring used to take exactly two args, but now takes 0-3.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2976 ;; convert 0-2 to two args and use special bytecode operand.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2977 ;; convert 3 args to a normal call.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2978 (cond ((= len 1) (setq form (append form '(nil nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2979 (= len 2) (setq form (append form '(nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2980 (cond ((= len 3) (byte-compile-two-args form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2981 ((= len 4) (byte-compile-normal-call form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2982 (t (byte-compile-subr-wrong-args form "0-3")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2983
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2984 (defun byte-compile-list (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2985 (let ((count (length (cdr form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2986 (cond ((= count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2987 (byte-compile-constant nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2988 ((< count 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2989 (mapcar 'byte-compile-form (cdr form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2990 (byte-compile-out
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2991 (aref [byte-list1 byte-list2 byte-list3 byte-list4] (1- count)) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2992 ((and (< count 256) (not (byte-compile-version-cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2993 byte-compile-emacs18-compatibility)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2994 (mapcar 'byte-compile-form (cdr form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2995 (byte-compile-out 'byte-listN count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2996 (t (byte-compile-normal-call form)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2997
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2998 (defun byte-compile-concat (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2999 (let ((count (length (cdr form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3000 (cond ((and (< 1 count) (< count 5))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3001 (mapcar 'byte-compile-form (cdr form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3002 (byte-compile-out
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3003 (aref [byte-concat2 byte-concat3 byte-concat4] (- count 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3004 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3005 ;; Concat of one arg is not a no-op if arg is not a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3006 ((= count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3007 (byte-compile-form ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3008 ((and (< count 256) (not (byte-compile-version-cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3009 byte-compile-emacs18-compatibility)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3010 (mapcar 'byte-compile-form (cdr form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3011 (byte-compile-out 'byte-concatN count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3012 ((byte-compile-normal-call form)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3013
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3014 (defun byte-compile-minus (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3015 (if (null (setq form (cdr form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3016 (byte-compile-constant 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3017 (byte-compile-form (car form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3018 (if (cdr form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3019 (while (setq form (cdr form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3020 (byte-compile-form (car form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3021 (byte-compile-out 'byte-diff 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3022 (byte-compile-out 'byte-negate 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3023
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3024 (defun byte-compile-quo (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3025 (let ((len (length form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3026 (cond ((<= len 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3027 (byte-compile-subr-wrong-args form "2 or more"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3028 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3029 (byte-compile-form (car (setq form (cdr form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3030 (while (setq form (cdr form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3031 (byte-compile-form (car form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3032 (byte-compile-out 'byte-quo 0))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3033
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3034 (defun byte-compile-nconc (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3035 (let ((len (length form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3036 (cond ((= len 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3037 (byte-compile-constant nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3038 ((= len 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3039 ;; nconc of one arg is a noop, even if that arg isn't a list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3040 (byte-compile-form (nth 1 form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3041 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3042 (byte-compile-form (car (setq form (cdr form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3043 (while (setq form (cdr form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3044 (byte-compile-form (car form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3045 (byte-compile-out 'byte-nconc 0))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3046
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3047 (defun byte-compile-fset (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3048 ;; warn about forms like (fset 'foo '(lambda () ...))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3049 ;; (where the lambda expression is non-trivial...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3050 ;; Except don't warn if the first argument is 'make-byte-code, because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3051 ;; I'm sick of getting mail asking me whether that warning is a problem.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3052 (let ((fn (nth 2 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3053 body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3054 (if (and (eq (car-safe fn) 'quote)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3055 (eq (car-safe (setq fn (nth 1 fn))) 'lambda)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3056 (not (eq (car-safe (cdr-safe (nth 1 form))) 'make-byte-code)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3057 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3058 (setq body (cdr (cdr fn)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3059 (if (stringp (car body)) (setq body (cdr body)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3060 (if (eq 'interactive (car-safe (car body))) (setq body (cdr body)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3061 (if (and (consp (car body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3062 (not (eq 'byte-code (car (car body)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3063 (byte-compile-warn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3064 "A quoted lambda form is the second argument of fset. This is probably
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3065 not what you want, as that lambda cannot be compiled. Consider using
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3066 the syntax (function (lambda (...) ...)) instead.")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3067 (byte-compile-two-args form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3068
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3069 (defun byte-compile-funarg (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3070 ;; (mapcar '(lambda (x) ..) ..) ==> (mapcar (function (lambda (x) ..)) ..)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3071 ;; for cases where it's guaranteed that first arg will be used as a lambda.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3072 (byte-compile-normal-call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3073 (let ((fn (nth 1 form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3074 (if (and (eq (car-safe fn) 'quote)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3075 (eq (car-safe (nth 1 fn)) 'lambda))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3076 (cons (car form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3077 (cons (cons 'function (cdr fn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3078 (cdr (cdr form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3079 form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3080
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3081 ;; (function foo) must compile like 'foo, not like (symbol-function 'foo).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3082 ;; Otherwise it will be incompatible with the interpreter,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3083 ;; and (funcall (function foo)) will lose with autoloads.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3084
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3085 (defun byte-compile-function-form (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3086 (byte-compile-constant
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3087 (cond ((symbolp (nth 1 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3088 (nth 1 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3089 ;; If we're not allowed to use #[] syntax, then output a form like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3090 ;; '(lambda (..) (byte-code ..)) instead of a call to make-byte-code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3091 ;; In this situation, calling make-byte-code at run-time will usually
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3092 ;; be less efficient than processing a call to byte-code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3093 ((byte-compile-version-cond byte-compile-emacs18-compatibility)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3094 (byte-compile-byte-code-unmake (byte-compile-lambda (nth 1 form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3095 ((byte-compile-lambda (nth 1 form))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3096
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3097 (defun byte-compile-insert (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3098 (cond ((null (cdr form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3099 (byte-compile-constant nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3100 ((and (not (byte-compile-version-cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3101 byte-compile-emacs18-compatibility))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3102 (<= (length form) 256))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3103 (mapcar 'byte-compile-form (cdr form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3104 (if (cdr (cdr form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3105 (byte-compile-out 'byte-insertN (length (cdr form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3106 (byte-compile-out 'byte-insert 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3107 ((memq t (mapcar 'consp (cdr (cdr form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3108 (byte-compile-normal-call form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3109 ;; We can split it; there is no function call after inserting 1st arg.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3110 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3111 (while (setq form (cdr form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3112 (byte-compile-form (car form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3113 (byte-compile-out 'byte-insert 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3114 (if (cdr form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3115 (byte-compile-discard))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3117 ;; alas, the old (pre-19.12, and all existing versions of FSFmacs 19)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3118 ;; byte compiler will generate incorrect code for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3119 ;; (beginning-of-line nil buffer) because it buggily doesn't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3120 ;; check the number of arguments passed to beginning-of-line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3122 (defun byte-compile-beginning-of-line (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3123 (let ((len (length form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3124 (cond ((> len 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3125 (byte-compile-subr-wrong-args form "0-2"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3126 ((or (= len 3) (not (byte-compile-constp (nth 1 form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3127 (byte-compile-normal-call form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3128 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3129 (byte-compile-form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3130 (list 'forward-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3131 (if (integerp (setq form (or (eval (nth 1 form)) 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3132 (1- form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3133 (byte-compile-warn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3134 "Non-numeric arg to beginning-of-line: %s" form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3135 (list '1- (list 'quote form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3136 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3137 (byte-compile-constant nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3138
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3139
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3140 (byte-defop-compiler set)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3141 (byte-defop-compiler-1 setq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3142 (byte-defop-compiler-1 set-default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3143 (byte-defop-compiler-1 setq-default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3145 (byte-defop-compiler-1 quote)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3146 (byte-defop-compiler-1 quote-form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3148 (defun byte-compile-setq (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3149 (let ((args (cdr form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3150 (if args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3151 (while args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3152 (byte-compile-form (car (cdr args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3153 (or for-effect (cdr (cdr args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3154 (byte-compile-out 'byte-dup 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3155 (byte-compile-variable-ref 'byte-varset (car args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3156 (setq args (cdr (cdr args))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3157 ;; (setq), with no arguments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3158 (byte-compile-form nil for-effect))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3159 (setq for-effect nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3161 (defun byte-compile-set (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3162 ;; Compile (set 'foo x) as (setq foo x) for trivially better code and so
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3163 ;; that we get applicable warnings. Compile everything else (including
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3164 ;; malformed calls) like a normal 2-arg byte-coded function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3165 (if (or (not (eq (car-safe (nth 1 form)) 'quote))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3166 (not (= (length form) 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3167 (not (= (length (nth 1 form)) 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3168 (byte-compile-two-args form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3169 (byte-compile-setq (list 'setq (nth 1 (nth 1 form)) (nth 2 form)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3170
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3171 (defun byte-compile-setq-default (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3172 (let ((rest (cdr form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3173 ;; emit multiple calls to set-default if necessary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3174 (while rest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3175 (byte-compile-form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3176 (list 'set-default (list 'quote (car rest)) (car (cdr rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3177 (not (null (cdr (cdr rest)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3178 (setq rest (cdr (cdr rest))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3180 (defun byte-compile-set-default (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3181 (let ((rest (cdr form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3182 (if (cdr (cdr (cdr form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3183 ;; emit multiple calls to set-default if necessary; all but last
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3184 ;; for-effect (this recurses.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3185 (while rest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3186 (byte-compile-form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3187 (list 'set-default (car rest) (car (cdr rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3188 (not (null (cdr rest))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3189 (setq rest (cdr (cdr rest))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3190 ;; else, this is the one-armed version
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3191 (let ((var (nth 1 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3192 ;;(val (nth 2 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3193 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3194 ;; notice calls to set-default/setq-default for variables which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3195 ;; have not been declared with defvar/defconst.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3196 (if (and (memq 'free-vars byte-compile-warnings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3197 (or (null var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3198 (and (eq (car-safe var) 'quote)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3199 (= 2 (length var)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3200 (let ((sym (nth 1 var))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3201 cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3202 (or (and sym (symbolp sym) (globally-boundp sym))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3203 (and (setq cell (assq sym byte-compile-bound-variables))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3204 (setcdr cell (logior (cdr cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3205 byte-compile-assigned-bit)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3206 (memq sym byte-compile-free-assignments)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3207 (if (or (not (symbolp sym)) (memq sym '(t nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3208 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3209 (byte-compile-warn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3210 "Attempt to set-globally %s %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3211 (if (symbolp sym) "constant" "nonvariable")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3212 (prin1-to-string sym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3213 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3214 (byte-compile-warn "assignment to free variable %s" sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3215 (setq byte-compile-free-assignments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3216 (cons sym byte-compile-free-assignments)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3217 ;; now emit a normal call to set-default (or possibly multiple calls)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3218 (byte-compile-normal-call form)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3219
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3220
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3221 (defun byte-compile-quote (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3222 (byte-compile-constant (car (cdr form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3224 (defun byte-compile-quote-form (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3225 (byte-compile-constant (byte-compile-top-level (nth 1 form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3226
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3227
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3228 ;;; control structures
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3229
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3230 (defun byte-compile-body (body &optional for-effect)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3231 (while (cdr body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3232 (byte-compile-form (car body) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3233 (setq body (cdr body)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3234 (byte-compile-form (car body) for-effect))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3236 (proclaim-inline byte-compile-body-do-effect)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3237 (defun byte-compile-body-do-effect (body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3238 (byte-compile-body body for-effect)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3239 (setq for-effect nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3240
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3241 (proclaim-inline byte-compile-form-do-effect)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3242 (defun byte-compile-form-do-effect (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3243 (byte-compile-form form for-effect)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3244 (setq for-effect nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3245
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3246 (byte-defop-compiler-1 inline byte-compile-progn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3247 (byte-defop-compiler-1 progn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3248 (byte-defop-compiler-1 prog1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3249 (byte-defop-compiler-1 prog2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3250 (byte-defop-compiler-1 if)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3251 (byte-defop-compiler-1 cond)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3252 (byte-defop-compiler-1 and)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3253 (byte-defop-compiler-1 or)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3254 (byte-defop-compiler-1 while)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3255 (byte-defop-compiler-1 funcall)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3256 (byte-defop-compiler-1 apply byte-compile-funarg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3257 (byte-defop-compiler-1 mapcar byte-compile-funarg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3258 (byte-defop-compiler-1 mapatoms byte-compile-funarg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3259 (byte-defop-compiler-1 mapconcat byte-compile-funarg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3260 (byte-defop-compiler-1 let)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3261 (byte-defop-compiler-1 let*)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3262
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3263 (defun byte-compile-progn (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3264 (byte-compile-body-do-effect (cdr form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3265
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3266 (defun byte-compile-prog1 (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3267 (byte-compile-form-do-effect (car (cdr form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3268 (byte-compile-body (cdr (cdr form)) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3270 (defun byte-compile-prog2 (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3271 (byte-compile-form (nth 1 form) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3272 (byte-compile-form-do-effect (nth 2 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3273 (byte-compile-body (cdr (cdr (cdr form))) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3274
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3275 (defmacro byte-compile-goto-if (cond discard tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3276 (` (byte-compile-goto
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3277 (if (, cond)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3278 (if (, discard) 'byte-goto-if-not-nil 'byte-goto-if-not-nil-else-pop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3279 (if (, discard) 'byte-goto-if-nil 'byte-goto-if-nil-else-pop))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3280 (, tag))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3281
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3282 (defun byte-compile-if (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3283 (byte-compile-form (car (cdr form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3284 (if (null (nthcdr 3 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3285 ;; No else-forms
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3286 (let ((donetag (byte-compile-make-tag)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3287 (byte-compile-goto-if nil for-effect donetag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3288 (byte-compile-form (nth 2 form) for-effect)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3289 (byte-compile-out-tag donetag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3290 (let ((donetag (byte-compile-make-tag)) (elsetag (byte-compile-make-tag)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3291 (byte-compile-goto 'byte-goto-if-nil elsetag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3292 (byte-compile-form (nth 2 form) for-effect)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3293 (byte-compile-goto 'byte-goto donetag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3294 (byte-compile-out-tag elsetag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3295 (byte-compile-body (cdr (cdr (cdr form))) for-effect)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3296 (byte-compile-out-tag donetag)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3297 (setq for-effect nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3298
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3299 (defun byte-compile-cond (clauses)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3300 (let ((donetag (byte-compile-make-tag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3301 nexttag clause)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3302 (while (setq clauses (cdr clauses))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3303 (setq clause (car clauses))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3304 (cond ((or (eq (car clause) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3305 (and (eq (car-safe (car clause)) 'quote)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3306 (car-safe (cdr-safe (car clause)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3307 ;; Unconditional clause
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3308 (setq clause (cons t clause)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3309 clauses nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3310 ((cdr clauses)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3311 (byte-compile-form (car clause))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3312 (if (null (cdr clause))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3313 ;; First clause is a singleton.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3314 (byte-compile-goto-if t for-effect donetag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3315 (setq nexttag (byte-compile-make-tag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3316 (byte-compile-goto 'byte-goto-if-nil nexttag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3317 (byte-compile-body (cdr clause) for-effect)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3318 (byte-compile-goto 'byte-goto donetag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3319 (byte-compile-out-tag nexttag)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3320 ;; Last clause
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3321 (and (cdr clause) (not (eq (car clause) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3322 (progn (byte-compile-form (car clause))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3323 (byte-compile-goto-if nil for-effect donetag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3324 (setq clause (cdr clause))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3325 (byte-compile-body-do-effect clause)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3326 (byte-compile-out-tag donetag)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3327
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3328 (defun byte-compile-and (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3329 (let ((failtag (byte-compile-make-tag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3330 (args (cdr form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3331 (if (null args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3332 (byte-compile-form-do-effect t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3333 (while (cdr args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3334 (byte-compile-form (car args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3335 (byte-compile-goto-if nil for-effect failtag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3336 (setq args (cdr args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3337 (byte-compile-form-do-effect (car args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3338 (byte-compile-out-tag failtag))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3339
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3340 (defun byte-compile-or (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3341 (let ((wintag (byte-compile-make-tag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3342 (args (cdr form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3343 (if (null args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3344 (byte-compile-form-do-effect nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3345 (while (cdr args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3346 (byte-compile-form (car args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3347 (byte-compile-goto-if t for-effect wintag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3348 (setq args (cdr args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3349 (byte-compile-form-do-effect (car args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3350 (byte-compile-out-tag wintag))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3351
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3352 (defun byte-compile-while (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3353 (let ((endtag (byte-compile-make-tag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3354 (looptag (byte-compile-make-tag)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3355 (byte-compile-out-tag looptag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3356 (byte-compile-form (car (cdr form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3357 (byte-compile-goto-if nil for-effect endtag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3358 (byte-compile-body (cdr (cdr form)) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3359 (byte-compile-goto 'byte-goto looptag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3360 (byte-compile-out-tag endtag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3361 (setq for-effect nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3362
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3363 (defun byte-compile-funcall (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3364 (mapcar 'byte-compile-form (cdr form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3365 (byte-compile-out 'byte-call (length (cdr (cdr form)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3366
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3367
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3368 (defun byte-compile-let (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3369 ;; First compute the binding values in the old scope.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3370 (let ((varlist (car (cdr form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3371 (while varlist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3372 (if (consp (car varlist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3373 (byte-compile-form (car (cdr (car varlist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3374 (byte-compile-push-constant nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3375 (setq varlist (cdr varlist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3376 (let ((byte-compile-bound-variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3377 (cons 'new-scope byte-compile-bound-variables))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3378 (varlist (reverse (car (cdr form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3379 (extra-flags
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3380 ;; If this let is of the form (let (...) (byte-code ...))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3381 ;; then assume that it is the result of a transformation of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3382 ;; ((lambda (...) (byte-code ... )) ...) and thus compile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3383 ;; the variable bindings as if they were arglist bindings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3384 ;; (which matters for what warnings.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3385 (if (eq 'byte-code (car-safe (nth 2 form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3386 byte-compile-arglist-bit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3387 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3388 (while varlist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3389 (byte-compile-variable-ref 'byte-varbind
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3390 (if (consp (car varlist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3391 (car (car varlist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3392 (car varlist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3393 extra-flags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3394 (setq varlist (cdr varlist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3395 (byte-compile-body-do-effect (cdr (cdr form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3396 (if (memq 'unused-vars byte-compile-warnings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3397 ;; done compiling in this scope, warn now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3398 (byte-compile-warn-about-unused-variables))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3399 (byte-compile-out 'byte-unbind (length (car (cdr form))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3400
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3401 (defun byte-compile-let* (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3402 (let ((byte-compile-bound-variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3403 (cons 'new-scope byte-compile-bound-variables))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3404 (varlist (copy-sequence (car (cdr form)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3405 (while varlist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3406 (if (atom (car varlist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3407 (byte-compile-push-constant nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3408 (byte-compile-form (car (cdr (car varlist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3409 (setcar varlist (car (car varlist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3410 (byte-compile-variable-ref 'byte-varbind (car varlist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3411 (setq varlist (cdr varlist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3412 (byte-compile-body-do-effect (cdr (cdr form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3413 (if (memq 'unused-vars byte-compile-warnings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3414 ;; done compiling in this scope, warn now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3415 (byte-compile-warn-about-unused-variables))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3416 (byte-compile-out 'byte-unbind (length (car (cdr form))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3417
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3418
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3419 (byte-defop-compiler-1 /= byte-compile-negated)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3420 (byte-defop-compiler-1 atom byte-compile-negated)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3421 (byte-defop-compiler-1 nlistp byte-compile-negated)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3422
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3423 (put '/= 'byte-compile-negated-op '=)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3424 (put 'atom 'byte-compile-negated-op 'consp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3425 (put 'nlistp 'byte-compile-negated-op 'listp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3426
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3427 (defun byte-compile-negated (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3428 (byte-compile-form-do-effect (byte-compile-negation-optimizer form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3429
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3430 ;; Even when optimization is off, /= is optimized to (not (= ...)).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3431 (defun byte-compile-negation-optimizer (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3432 ;; an optimizer for forms where <form1> is less efficient than (not <form2>)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3433 (list 'not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3434 (cons (or (get (car form) 'byte-compile-negated-op)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3435 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3436 "Compiler error: `%s' has no `byte-compile-negated-op' property"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3437 (car form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3438 (cdr form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3439
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3440 ;;; other tricky macro-like special-forms
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3441
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3442 (byte-defop-compiler-1 catch)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3443 (byte-defop-compiler-1 unwind-protect)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3444 (byte-defop-compiler-1 condition-case)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3445 (byte-defop-compiler-1 save-excursion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3446 (byte-defop-compiler-1 save-restriction)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3447 (byte-defop-compiler-1 save-window-excursion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3448 (byte-defop-compiler-1 with-output-to-temp-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3449 ;; no track-mouse.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3450
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3451 (defun byte-compile-catch (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3452 (byte-compile-form (car (cdr form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3453 (byte-compile-push-constant
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3454 (byte-compile-top-level (cons 'progn (cdr (cdr form))) for-effect))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3455 (byte-compile-out 'byte-catch 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3456
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3457 (defun byte-compile-unwind-protect (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3458 (byte-compile-push-constant
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3459 (byte-compile-top-level-body (cdr (cdr form)) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3460 (byte-compile-out 'byte-unwind-protect 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3461 (byte-compile-form-do-effect (car (cdr form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3462 (byte-compile-out 'byte-unbind 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3463
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3464 ;;(defun byte-compile-track-mouse (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3465 ;; (byte-compile-form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3466 ;; (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3467 ;; 'funcall
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3468 ;; (list 'quote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3469 ;; (list 'lambda nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3470 ;; (cons 'track-mouse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3471 ;; (byte-compile-top-level-body (cdr form))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3472
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3473 (defun byte-compile-condition-case (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3474 (let* ((var (nth 1 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3475 (byte-compile-bound-variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3476 (if var
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3477 (cons (cons var 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3478 (cons 'new-scope byte-compile-bound-variables))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3479 (cons 'new-scope byte-compile-bound-variables))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3480 (or (symbolp var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3481 (byte-compile-warn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3482 "%s is not a variable-name or nil (in condition-case)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3483 (prin1-to-string var)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3484 (byte-compile-push-constant var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3485 (byte-compile-push-constant (byte-compile-top-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3486 (nth 2 form) for-effect))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3487 (let ((clauses (cdr (cdr (cdr form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3488 compiled-clauses)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3489 (while clauses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3490 (let* ((clause (car clauses))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3491 (condition (car clause)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3492 (cond ((not (or (symbolp condition)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3493 (and (listp condition)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3494 (let ((syms condition) (ok t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3495 (while syms
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3496 (if (not (symbolp (car syms)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3497 (setq ok nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3498 (setq syms (cdr syms)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3499 ok))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3500 (byte-compile-warn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3501 "%s is not a symbol naming a condition or a list of such (in condition-case)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3502 (prin1-to-string condition)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3503 ;; ((not (or (eq condition 't)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3504 ;; (and (stringp (get condition 'error-message))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3505 ;; (consp (get condition 'error-conditions)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3506 ;; (byte-compile-warn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3507 ;; "%s is not a known condition name (in condition-case)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3508 ;; condition))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3509 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3510 (setq compiled-clauses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3511 (cons (cons condition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3512 (byte-compile-top-level-body
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3513 (cdr clause) for-effect))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3514 compiled-clauses)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3515 (setq clauses (cdr clauses)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3516 (byte-compile-push-constant (nreverse compiled-clauses)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3517 (if (memq 'unused-vars byte-compile-warnings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3518 ;; done compiling in this scope, warn now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3519 (byte-compile-warn-about-unused-variables))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3520 (byte-compile-out 'byte-condition-case 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3521
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3522
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3523 (defun byte-compile-save-excursion (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3524 (byte-compile-out 'byte-save-excursion 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3525 (byte-compile-body-do-effect (cdr form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3526 (byte-compile-out 'byte-unbind 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3527
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3528 (defun byte-compile-save-restriction (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3529 (byte-compile-out 'byte-save-restriction 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3530 (byte-compile-body-do-effect (cdr form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3531 (byte-compile-out 'byte-unbind 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3532
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3533 (defun byte-compile-save-window-excursion (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3534 (byte-compile-push-constant
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3535 (byte-compile-top-level-body (cdr form) for-effect))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3536 (byte-compile-out 'byte-save-window-excursion 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3537
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3538 (defun byte-compile-with-output-to-temp-buffer (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3539 (byte-compile-form (car (cdr form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3540 (byte-compile-out 'byte-temp-output-buffer-setup 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3541 (byte-compile-body (cdr (cdr form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3542 (byte-compile-out 'byte-temp-output-buffer-show 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3543
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3544
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3545 ;;; top-level forms elsewhere
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3546
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3547 (byte-defop-compiler-1 defun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3548 (byte-defop-compiler-1 defmacro)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3549 (byte-defop-compiler-1 defvar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3550 (byte-defop-compiler-1 defconst byte-compile-defvar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3551 (byte-defop-compiler-1 autoload)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3552 ;; According to Mly this can go now that lambda is a macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3553 ;(byte-defop-compiler-1 lambda byte-compile-lambda-form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3554 (byte-defop-compiler-1 defalias)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3555 (byte-defop-compiler-1 define-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3556
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3557 (defun byte-compile-defun (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3558 ;; This is not used for file-level defuns with doc strings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3559 (byte-compile-two-args ; Use this to avoid byte-compile-fset's warning.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3560 (list 'fset (list 'quote (nth 1 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3561 (byte-compile-byte-code-maker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3562 (byte-compile-lambda (cons 'lambda (cdr (cdr form)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3563 (byte-compile-discard)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3564 (byte-compile-constant (nth 1 form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3565
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3566 (defun byte-compile-defmacro (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3567 ;; This is not used for file-level defmacros with doc strings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3568 (byte-compile-body-do-effect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3569 (list (list 'fset (list 'quote (nth 1 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3570 (let ((code (byte-compile-byte-code-maker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3571 (byte-compile-lambda
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3572 (cons 'lambda (cdr (cdr form)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3573 (if (eq (car-safe code) 'make-byte-code)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3574 (list 'cons ''macro code)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3575 (list 'quote (cons 'macro (eval code))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3576 (list 'quote (nth 1 form)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3577
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3578 (defun byte-compile-defvar (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3579 ;; This is not used for file-level defvar/consts with doc strings:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3580 ;; byte-compile-file-form-defvar will be used in that case.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3581 (let ((var (nth 1 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3582 (value (nth 2 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3583 (string (nth 3 form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3584 (if (> (length form) 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3585 (byte-compile-warn "%s used with too many args" (car form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3586 (if (memq 'free-vars byte-compile-warnings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3587 (setq byte-compile-bound-variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3588 (cons (cons var byte-compile-global-bit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3589 byte-compile-bound-variables)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3590 (byte-compile-body-do-effect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3591 (list (if (cdr (cdr form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3592 (if (eq (car form) 'defconst)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3593 (list 'setq var value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3594 (list 'or (list 'boundp (list 'quote var))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3595 (list 'setq var value))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3596 ;; Put the defined variable in this library's load-history entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3597 ;; just as a real defvar would.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3598 (list 'setq 'current-load-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3599 (list 'cons (list 'quote var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3600 'current-load-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3601 (if string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3602 (list 'put (list 'quote var) ''variable-documentation string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3603 (list 'quote var)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3604
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3605 (defun byte-compile-autoload (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3606 (and (byte-compile-constp (nth 1 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3607 (byte-compile-constp (nth 5 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3608 (memq (eval (nth 5 form)) '(t macro)) ; macro-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3609 (not (fboundp (eval (nth 1 form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3610 (byte-compile-warn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3611 "The compiler ignores `autoload' except at top level. You should
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3612 probably put the autoload of the macro `%s' at top-level."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3613 (eval (nth 1 form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3614 (byte-compile-normal-call form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3615
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3616 ;; Lambda's in valid places are handled as special cases by various code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3617 ;; The ones that remain are errors.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3618 ;; According to Mly this can go now that lambda is a macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3619 ;(defun byte-compile-lambda-form (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3620 ; (byte-compile-warn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3621 ; "`lambda' used in function position is invalid: probably you mean #'%s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3622 ; (let ((print-escape-newlines t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3623 ; (print-level 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3624 ; (print-length 4))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3625 ; (prin1-to-string form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3626 ; (byte-compile-normal-call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3627 ; (list 'signal ''error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3628 ; (list 'quote (list "`lambda' used in function position" form)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3629
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3630 ;; Compile normally, but deal with warnings for the function being defined.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3631 (defun byte-compile-defalias (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3632 (if (and (consp (cdr form)) (consp (nth 1 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3633 (eq (car (nth 1 form)) 'quote)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3634 (consp (cdr (nth 1 form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3635 (symbolp (nth 1 (nth 1 form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3636 (consp (nthcdr 2 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3637 (consp (nth 2 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3638 (eq (car (nth 2 form)) 'quote)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3639 (consp (cdr (nth 2 form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3640 (symbolp (nth 1 (nth 2 form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3641 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3642 (byte-compile-defalias-warn (nth 1 (nth 1 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3643 (nth 1 (nth 2 form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3644 (setq byte-compile-function-environment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3645 (cons (cons (nth 1 (nth 1 form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3646 (nth 1 (nth 2 form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3647 byte-compile-function-environment))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3648 (byte-compile-normal-call form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3649
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3650 (defun byte-compile-define-function (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3651 (byte-compile-defalias form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3652
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3653 ;; Turn off warnings about prior calls to the function being defalias'd.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3654 ;; This could be smarter and compare those calls with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3655 ;; the function it is being aliased to.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3656 (defun byte-compile-defalias-warn (new alias)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3657 (let ((calls (assq new byte-compile-unresolved-functions)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3658 (if calls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3659 (setq byte-compile-unresolved-functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3660 (delq calls byte-compile-unresolved-functions)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3661
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3662 ;;; tags
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3663
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3664 ;; Note: Most operations will strip off the 'TAG, but it speeds up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3665 ;; optimization to have the 'TAG as a part of the tag.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3666 ;; Tags will be (TAG . (tag-number . stack-depth)).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3667 (defun byte-compile-make-tag ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3668 (list 'TAG (setq byte-compile-tag-number (1+ byte-compile-tag-number))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3669
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3670
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3671 (defun byte-compile-out-tag (tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3672 (setq byte-compile-output (cons tag byte-compile-output))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3673 (if (cdr (cdr tag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3674 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3675 ;; ## remove this someday
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3676 (and byte-compile-depth
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3677 (not (= (cdr (cdr tag)) byte-compile-depth))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3678 (error "Compiler bug: depth conflict at tag %d" (car (cdr tag))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3679 (setq byte-compile-depth (cdr (cdr tag))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3680 (setcdr (cdr tag) byte-compile-depth)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3681
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3682 (defun byte-compile-goto (opcode tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3683 (setq byte-compile-output (cons (cons opcode tag) byte-compile-output))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3684 (setcdr (cdr tag) (if (memq opcode byte-goto-always-pop-ops)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3685 (1- byte-compile-depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3686 byte-compile-depth))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3687 (setq byte-compile-depth (and (not (eq opcode 'byte-goto))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3688 (1- byte-compile-depth))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3689
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3690 (defun byte-compile-out (opcode offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3691 (setq byte-compile-output (cons (cons opcode offset) byte-compile-output))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3692 (cond ((eq opcode 'byte-call)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3693 (setq byte-compile-depth (- byte-compile-depth offset)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3694 ((eq opcode 'byte-return)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3695 ;; This is actually an unnecessary case, because there should be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3696 ;; no more opcodes behind byte-return.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3697 (setq byte-compile-depth nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3698 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3699 (setq byte-compile-depth (+ byte-compile-depth
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3700 (or (aref byte-stack+-info
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3701 (symbol-value opcode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3702 (- (1- offset))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3703 byte-compile-maxdepth (max byte-compile-depth
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3704 byte-compile-maxdepth))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3705 ;;(if (< byte-compile-depth 0) (error "Compiler error: stack underflow"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3706 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3707
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3708
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3709 ;;; call tree stuff
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3710
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3711 (defun byte-compile-annotate-call-tree (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3712 (let (entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3713 ;; annotate the current call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3714 (if (setq entry (assq (car form) byte-compile-call-tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3715 (or (memq byte-compile-current-form (nth 1 entry)) ;callers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3716 (setcar (cdr entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3717 (cons byte-compile-current-form (nth 1 entry))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3718 (setq byte-compile-call-tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3719 (cons (list (car form) (list byte-compile-current-form) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3720 byte-compile-call-tree)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3721 ;; annotate the current function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3722 (if (setq entry (assq byte-compile-current-form byte-compile-call-tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3723 (or (memq (car form) (nth 2 entry)) ;called
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3724 (setcar (cdr (cdr entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3725 (cons (car form) (nth 2 entry))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3726 (setq byte-compile-call-tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3727 (cons (list byte-compile-current-form nil (list (car form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3728 byte-compile-call-tree)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3729 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3730
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3731 ;; Renamed from byte-compile-report-call-tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3732 ;; to avoid interfering with completion of byte-compile-file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3733 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3734 (defun display-call-tree (&optional filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3735 "Display a call graph of a specified file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3736 This lists which functions have been called, what functions called
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3737 them, and what functions they call. The list includes all functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3738 whose definitions have been compiled in this Emacs session, as well as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3739 all functions called by those functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3740
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3741 The call graph does not include macros, inline functions, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3742 primitives that the byte-code interpreter knows about directly \(eq,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3743 cons, etc.\).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3744
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3745 The call tree also lists those functions which are not known to be called
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3746 \(that is, to which no calls have been compiled\), and which cannot be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3747 invoked interactively."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3748 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3749 (message "Generating call tree...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3750 (with-output-to-temp-buffer "*Call-Tree*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3751 (set-buffer "*Call-Tree*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3752 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3753 (message "Generating call tree... (sorting on %s)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3754 byte-compile-call-tree-sort)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3755 (insert "Call tree for "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3756 (cond ((null byte-compile-current-file) (or filename "???"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3757 ((stringp byte-compile-current-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3758 byte-compile-current-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3759 (t (buffer-name byte-compile-current-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3760 " sorted on "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3761 (prin1-to-string byte-compile-call-tree-sort)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3762 ":\n\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3763 (if byte-compile-call-tree-sort
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3764 (setq byte-compile-call-tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3765 (sort byte-compile-call-tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3766 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3767 ((eq byte-compile-call-tree-sort 'callers)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3768 (function (lambda (x y) (< (length (nth 1 x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3769 (length (nth 1 y))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3770 ((eq byte-compile-call-tree-sort 'calls)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3771 (function (lambda (x y) (< (length (nth 2 x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3772 (length (nth 2 y))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3773 ((eq byte-compile-call-tree-sort 'calls+callers)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3774 (function (lambda (x y) (< (+ (length (nth 1 x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3775 (length (nth 2 x)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3776 (+ (length (nth 1 y))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3777 (length (nth 2 y)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3778 ((eq byte-compile-call-tree-sort 'name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3779 (function (lambda (x y) (string< (car x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3780 (car y)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3781 (t (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3782 "`byte-compile-call-tree-sort': `%s' - unknown sort mode"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3783 byte-compile-call-tree-sort))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3784 (message "Generating call tree...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3785 (let ((rest byte-compile-call-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3786 (b (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3787 f p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3788 callers calls)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3789 (while rest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3790 (prin1 (car (car rest)) b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3791 (setq callers (nth 1 (car rest))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3792 calls (nth 2 (car rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3793 (insert "\t"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3794 (cond ((not (fboundp (setq f (car (car rest)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3795 (if (null f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3796 " <top level>";; shouldn't insert nil then, actually -sk
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3797 " <not defined>"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3798 ((subrp (setq f (symbol-function f)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3799 " <subr>")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3800 ((symbolp f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3801 (format " ==> %s" f))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3802 ((compiled-function-p f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3803 "<compiled function>")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3804 ((not (consp f))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3805 "<malformed function>")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3806 ((eq 'macro (car f))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3807 (if (or (compiled-function-p (cdr f))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3808 (assq 'byte-code (cdr (cdr (cdr f)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3809 " <compiled macro>"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3810 " <macro>"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3811 ((assq 'byte-code (cdr (cdr f)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3812 "<compiled lambda>")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3813 ((eq 'lambda (car f))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3814 "<function>")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3815 (t "???"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3816 (format " (%d callers + %d calls = %d)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3817 ;; Does the optimizer eliminate common subexpressions?-sk
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3818 (length callers)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3819 (length calls)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3820 (+ (length callers) (length calls)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3821 "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3822 (if callers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3823 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3824 (insert " called by:\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3825 (setq p (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3826 (insert " " (if (car callers)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3827 (mapconcat 'symbol-name callers ", ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3828 "<top level>"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3829 (let ((fill-prefix " "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3830 (fill-region-as-paragraph p (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3831 (if calls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3832 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3833 (insert " calls:\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3834 (setq p (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3835 (insert " " (mapconcat 'symbol-name calls ", "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3836 (let ((fill-prefix " "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3837 (fill-region-as-paragraph p (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3838 (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3839 (setq rest (cdr rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3840
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3841 (message "Generating call tree...(finding uncalled functions...)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3842 (setq rest byte-compile-call-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3843 (let ((uncalled nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3844 (while rest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3845 (or (nth 1 (car rest))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3846 (null (setq f (car (car rest))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3847 (byte-compile-fdefinition f t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3848 (commandp (byte-compile-fdefinition f nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3849 (setq uncalled (cons f uncalled)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3850 (setq rest (cdr rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3851 (if uncalled
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3852 (let ((fill-prefix " "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3853 (insert "Noninteractive functions not known to be called:\n ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3854 (setq p (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3855 (insert (mapconcat 'symbol-name (nreverse uncalled) ", "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3856 (fill-region-as-paragraph p (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3857 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3858 (message "Generating call tree...done.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3859 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3860
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3861
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3862 ;;; by crl@newton.purdue.edu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3863 ;;; Only works noninteractively.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3864 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3865 (defun batch-byte-compile ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3866 "Run `byte-compile-file' on the files remaining on the command line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3867 Use this from the command line, with `-batch';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3868 it won't work in an interactive Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3869 Each file is processed even if an error occurred previously.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3870 For example, invoke \"emacs -batch -f batch-byte-compile $emacs/ ~/*.el\""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3871 ;; command-line-args-left is what is left of the command line (from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3872 ;; startup.el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3873 (defvar command-line-args-left) ;Avoid 'free variable' warning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3874 (if (not noninteractive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3875 (error "`batch-byte-compile' is to be used only with -batch"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3876 (let ((error nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3877 (while command-line-args-left
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3878 (if (file-directory-p (expand-file-name (car command-line-args-left)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3879 (let ((files (directory-files (car command-line-args-left)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3880 source dest)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3881 (while files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3882 (if (and (string-match emacs-lisp-file-regexp (car files))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3883 (not (auto-save-file-name-p (car files)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3884 (setq source (expand-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3885 (car files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3886 (car command-line-args-left)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3887 (setq dest (byte-compile-dest-file source))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3888 (file-exists-p dest)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3889 (file-newer-than-file-p source dest))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3890 (if (null (batch-byte-compile-1 source))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3891 (setq error t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3892 (setq files (cdr files))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3893 (if (null (batch-byte-compile-1 (car command-line-args-left)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3894 (setq error t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3895 (setq command-line-args-left (cdr command-line-args-left)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3896 (message "Done")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3897 (kill-emacs (if error 1 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3898
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3899 (defun batch-byte-compile-1 (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3900 (condition-case err
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3901 (progn (byte-compile-file file) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3902 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3903 (princ ">>Error occurred processing ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3904 (princ file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3905 (princ ": ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3906 (if (fboundp 'display-error) ; XEmacs 19.8+
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3907 (display-error err nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3908 (princ (or (get (car err) 'error-message) (car err)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3909 (mapcar '(lambda (x) (princ " ") (prin1 x)) (cdr err)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3910 (princ "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3911 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3912
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3913 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3914 (defun batch-byte-recompile-directory-norecurse ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3915 "Same as `batch-byte-recompile-directory' but without recursion."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3916 (setq byte-recompile-directory-recursively nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3917 (batch-byte-recompile-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3918
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3919 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3920 (defun batch-byte-recompile-directory ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3921 "Runs `byte-recompile-directory' on the dirs remaining on the command line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3922 Must be used only with `-batch', and kills Emacs on completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3923 For example, invoke `xemacs -batch -f batch-byte-recompile-directory .'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3924 ;; command-line-args-left is what is left of the command line (startup.el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3925 (defvar command-line-args-left) ;Avoid 'free variable' warning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3926 (if (not noninteractive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3927 (error "batch-byte-recompile-directory is to be used only with -batch"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3928 (or command-line-args-left
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3929 (setq command-line-args-left '(".")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3930 (let ((byte-recompile-directory-ignore-errors-p t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3931 (while command-line-args-left
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3932 (byte-recompile-directory (car command-line-args-left))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3933 (setq command-line-args-left (cdr command-line-args-left))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3934 (kill-emacs 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3935
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3936 (make-obsolete 'elisp-compile-defun 'compile-defun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3937 (make-obsolete 'byte-compile-report-call-tree 'display-call-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3938
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3939 ;; other make-obsolete calls in obsolete.el.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3940
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3941 (provide 'byte-compile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3942 (provide 'bytecomp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3943
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3944
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3945 ;;; report metering (see the hacks in bytecode.c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3946
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3947 (if (boundp 'byte-code-meter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3948 (defun byte-compile-report-ops ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3949 (defvar byte-code-meter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3950 (with-output-to-temp-buffer "*Meter*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3951 (set-buffer "*Meter*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3952 (let ((i 0) n op off)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3953 (while (< i 256)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3954 (setq n (aref (aref byte-code-meter 0) i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3955 off nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3956 (if t ;(not (zerop n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3957 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3958 (setq op i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3959 (setq off nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3960 (cond ((< op byte-nth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3961 (setq off (logand op 7))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3962 (setq op (logand op 248)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3963 ((>= op byte-constant)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3964 (setq off (- op byte-constant)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3965 op byte-constant)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3966 (setq op (aref byte-code-vector op))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3967 (insert (format "%-4d" i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3968 (insert (symbol-name op))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3969 (if off (insert " [" (int-to-string off) "]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3970 (indent-to 40)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3971 (insert (int-to-string n) "\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3972 (setq i (1+ i)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3973
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3974
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3975 ;; To avoid "lisp nesting exceeds max-lisp-eval-depth" when bytecomp compiles
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3976 ;; itself, compile some of its most used recursive functions (at load time).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3977 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3978 (eval-when-compile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3979 (or (compiled-function-p (symbol-function 'byte-compile-form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3980 (assq 'byte-code (symbol-function 'byte-compile-form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3981 (let ((byte-optimize nil) ; do it fast
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3982 (byte-compile-warnings nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3983 (mapcar '(lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3984 (or noninteractive (message "compiling %s..." x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3985 (byte-compile x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3986 (or noninteractive (message "compiling %s...done" x)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3987 '(byte-compile-normal-call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3988 byte-compile-form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3989 byte-compile-body
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3990 ;; Inserted some more than necessary, to speed it up.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3991 byte-compile-top-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3992 byte-compile-out-toplevel
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3993 byte-compile-constant
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3994 byte-compile-variable-ref))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3995 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3996
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3997 ;;; bytecomp.el ends here