Mercurial > hg > xemacs-beta
annotate lisp/bytecomp.el @ 5568:b039c0f018b8
Error if byte-compiling a form hasn't wrapped byte-compile-inbuffer.
lisp/ChangeLog addition:
2011-09-09 Aidan Kehoe <kehoea@parhasard.net>
* bytecomp.el (byte-compile-from-buffer):
If compiling a form has changed the current buffer (that is, some
eval-when-compile form hasn't done save-excursion when
appropriate), error and exit; we can't guarantee we'll give useful
code in that context. See
http://mid.gmane.org/20110909110831.GD2875@acm.acm and related
discussion.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Fri, 09 Sep 2011 22:50:31 +0100 |
parents | 4654c01af32b |
children | f0f1fd0d8486 |
rev | line source |
---|---|
428 | 1 ;;; bytecomp.el --- compilation of Lisp code into byte code. |
2 | |
3 ;;; Copyright (C) 1985-1987, 1991-1994 Free Software Foundation, Inc. | |
4 ;;; Copyright (C) 1996 Ben Wing. | |
5 | |
442 | 6 ;; Authors: Jamie Zawinski <jwz@jwz.org> |
428 | 7 ;; Hallvard Furuseth <hbf@ulrik.uio.no> |
442 | 8 ;; Ben Wing <ben@xemacs.org> |
9 ;; Martin Buchholz <martin@xemacs.org> | |
10 ;; Richard Stallman <rms@gnu.org> | |
11 ;; Keywords: internal lisp | |
12 | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
13 (defconst byte-compile-version "2.28 XEmacs; 2009-08-09.") |
428 | 14 |
15 ;; This file is part of XEmacs. | |
16 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5269
diff
changeset
|
17 ;; XEmacs is free software: you can redistribute it and/or modify it |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5269
diff
changeset
|
18 ;; under the terms of the GNU General Public License as published by the |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5269
diff
changeset
|
19 ;; Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5269
diff
changeset
|
20 ;; option) any later version. |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5269
diff
changeset
|
21 |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5269
diff
changeset
|
22 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5269
diff
changeset
|
23 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5269
diff
changeset
|
24 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5269
diff
changeset
|
25 ;; for more details. |
428 | 26 |
27 ;; You should have received a copy of the GNU General Public License | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5269
diff
changeset
|
28 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>. |
428 | 29 |
30 ;;; Synched up with: FSF 19.30. | |
31 | |
32 ;;; Commentary: | |
33 | |
34 ;; The Emacs Lisp byte compiler. This crunches lisp source into a | |
442 | 35 ;; sort of p-code (`bytecode') which takes up less space and can be |
36 ;; interpreted faster. First, the source code forms are converted to | |
37 ;; an intermediate form, `lapcode' [`LAP' == `Lisp Assembly Program'] | |
38 ;; which is much easier to manipulate than bytecode. Then the lapcode | |
39 ;; is converted to bytecode, which can be considered to be actual | |
40 ;; machine language. Optimizations can occur at either the source | |
41 ;; level or the lapcode level. | |
42 | |
43 ;; The user entry points are byte-compile-file, | |
428 | 44 ;; byte-recompile-directory and byte-compile-buffer. |
45 | |
46 ;;; Code: | |
47 | |
48 ;;; ======================================================================== | |
49 ;;; Entry points: | |
50 ;;; byte-recompile-directory, byte-compile-file, | |
51 ;;; batch-byte-compile, batch-byte-recompile-directory, | |
52 ;;; byte-compile, compile-defun, | |
53 ;;; display-call-tree | |
54 ;;; RMS says: | |
55 ;;; (byte-compile-buffer and byte-compile-and-load-file were turned off | |
56 ;;; because they are not terribly useful and get in the way of completion.) | |
57 ;;; But I'm leaving them. --ben | |
58 | |
59 ;;; This version of the byte compiler has the following improvements: | |
60 ;;; + optimization of compiled code: | |
61 ;;; - removal of unreachable code; | |
62 ;;; - removal of calls to side-effectless functions whose return-value | |
63 ;;; is unused; | |
64 ;;; - compile-time evaluation of safe constant forms, such as (consp nil) | |
65 ;;; and (ash 1 6); | |
66 ;;; - open-coding of literal lambdas; | |
67 ;;; - peephole optimization of emitted code; | |
68 ;;; - trivial functions are left uncompiled for speed. | |
69 ;;; + support for inline functions; | |
70 ;;; + compile-time evaluation of arbitrary expressions; | |
71 ;;; + compile-time warning messages for: | |
72 ;;; - functions being redefined with incompatible arglists; | |
73 ;;; - functions being redefined as macros, or vice-versa; | |
74 ;;; - functions or macros defined multiple times in the same file; | |
75 ;;; - functions being called with the incorrect number of arguments; | |
76 ;;; - functions being called which are not defined globally, in the | |
77 ;;; file, or as autoloads; | |
78 ;;; - assignment and reference of undeclared free variables; | |
79 ;;; - various syntax errors; | |
80 ;;; + correct compilation of nested defuns, defmacros, defvars and defsubsts; | |
81 ;;; + correct compilation of top-level uses of macros; | |
82 ;;; + the ability to generate a histogram of functions called. | |
83 | |
84 ;;; User customization variables: | |
85 ;;; | |
86 ;;; byte-compile-verbose Whether to report the function currently being | |
87 ;;; compiled in the minibuffer; | |
88 ;;; byte-optimize Whether to do optimizations; this may be | |
89 ;;; t, nil, 'source, or 'byte; | |
90 ;;; byte-optimize-log Whether to report (in excruciating detail) | |
91 ;;; exactly which optimizations have been made. | |
92 ;;; This may be t, nil, 'source, or 'byte; | |
93 ;;; byte-compile-error-on-warn Whether to stop compilation when a warning is | |
94 ;;; produced; | |
95 ;;; byte-compile-delete-errors Whether the optimizer may delete calls or | |
96 ;;; variable references that are side-effect-free | |
97 ;;; except that they may return an error. | |
98 ;;; byte-compile-generate-call-tree Whether to generate a histogram of | |
99 ;;; function calls. This can be useful for | |
100 ;;; finding unused functions, as well as simple | |
101 ;;; performance metering. | |
102 ;;; byte-compile-warnings List of warnings to issue, or t. May contain | |
103 ;;; 'free-vars (references to variables not in the | |
104 ;;; current lexical scope) | |
105 ;;; 'unused-vars (non-global variables bound but | |
106 ;;; not referenced) | |
107 ;;; 'unresolved (calls to unknown functions) | |
108 ;;; 'callargs (lambda calls with args that don't | |
109 ;;; match the lambda's definition) | |
110 ;;; 'subr-callargs (calls to subrs with args that | |
111 ;;; don't match the subr's definition) | |
112 ;;; 'redefine (function cell redefined from | |
113 ;;; a macro to a lambda or vice versa, | |
114 ;;; or redefined to take other args) | |
115 ;;; 'obsolete (obsolete variables and functions) | |
116 ;;; 'pedantic (references to Emacs-compatible | |
117 ;;; symbols) | |
4719
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
118 ;;; 'discarded-consing (use of mapcar instead of |
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
119 ;;; mapc, and similar) |
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
120 ;;; 'quoted-lambda (quoting a lambda expression |
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
121 ;;; as data, not as a function, |
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
122 ;;; and using it in a function |
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
123 ;;; context ) |
428 | 124 ;;; emacs-lisp-file-regexp Regexp for the extension of source-files; |
444 | 125 ;;; see also the function `byte-compile-dest-file'. |
428 | 126 ;;; byte-compile-overwrite-file If nil, delete old .elc files before saving. |
127 ;;; | |
128 ;;; Most of the above parameters can also be set on a file-by-file basis; see | |
129 ;;; the documentation of the `byte-compiler-options' macro. | |
130 | |
131 ;;; New Features: | |
132 ;;; | |
133 ;;; o The form `defsubst' is just like `defun', except that the function | |
134 ;;; generated will be open-coded in compiled code which uses it. This | |
135 ;;; means that no function call will be generated, it will simply be | |
136 ;;; spliced in. Lisp functions calls are very slow, so this can be a | |
137 ;;; big win. | |
138 ;;; | |
139 ;;; You can generally accomplish the same thing with `defmacro', but in | |
140 ;;; that case, the defined procedure can't be used as an argument to | |
141 ;;; mapcar, etc. | |
142 ;;; | |
143 ;;; o You can make a given function be inline even if it has already been | |
144 ;;; defined with `defun' by using the `proclaim-inline' form like so: | |
145 ;;; (proclaim-inline my-function) | |
146 ;;; This is, in fact, exactly what `defsubst' does. To make a function no | |
147 ;;; longer be inline, you must use `proclaim-notinline'. Beware that if | |
148 ;;; you define a function with `defsubst' and later redefine it with | |
444 | 149 ;;; `defun', it will still be open-coded until you use `proclaim-notinline'. |
428 | 150 ;;; |
151 ;;; o You can also open-code one particular call to a function without | |
152 ;;; open-coding all calls. Use the 'inline' form to do this, like so: | |
153 ;;; | |
154 ;;; (inline (foo 1 2 3)) ;; `foo' will be open-coded | |
155 ;;; or... | |
156 ;;; (inline ;; `foo' and `baz' will be | |
157 ;;; (foo 1 2 3 (bar 5)) ;; open-coded, but `bar' will not. | |
158 ;;; (baz 0)) | |
159 ;;; | |
160 ;;; o It is possible to open-code a function in the same file it is defined | |
161 ;;; in without having to load that file before compiling it. the | |
162 ;;; byte-compiler has been modified to remember function definitions in | |
163 ;;; the compilation environment in the same way that it remembers macro | |
164 ;;; definitions. | |
165 ;;; | |
166 ;;; o Forms like ((lambda ...) ...) are open-coded. | |
167 ;;; | |
444 | 168 ;;; o The form `eval-when-compile' is like `progn', except that the body |
428 | 169 ;;; is evaluated at compile-time. When it appears at top-level, this |
170 ;;; is analogous to the Common Lisp idiom (eval-when (compile) ...). | |
171 ;;; When it does not appear at top-level, it is similar to the | |
172 ;;; Common Lisp #. reader macro (but not in interpreted code). | |
173 ;;; | |
444 | 174 ;;; o The form `eval-and-compile' is similar to `eval-when-compile', |
175 ;;; but the whole form is evalled both at compile-time and at run-time. | |
428 | 176 ;;; |
177 ;;; o The command M-x byte-compile-and-load-file does what you'd think. | |
178 ;;; | |
444 | 179 ;;; o The command `compile-defun' is analogous to `eval-defun'. |
428 | 180 ;;; |
444 | 181 ;;; o If you run `byte-compile-file' on a filename which is visited in a |
428 | 182 ;;; buffer, and that buffer is modified, you are asked whether you want |
183 ;;; to save the buffer before compiling. | |
184 ;;; | |
185 ;;; o You can add this to /etc/magic to make file(1) recognize the files | |
186 ;;; generated by this compiler: | |
187 ;;; | |
613 | 188 ;;; 0 string ;ELC XEmacs Lisp compiled file, |
428 | 189 ;;; >4 byte x version %d |
190 ;;; | |
191 ;;; TO DO: | |
192 ;;; | |
193 ;;; o Should implement declarations and proclamations, notably special, | |
194 ;;; unspecial, and ignore. Do this in such a way as to not break cl.el. | |
195 ;;; o The bound-but-not-used warnings are not issued for variables whose | |
196 ;;; bindings were established in the arglist, due to the lack of an | |
197 ;;; ignore declaration. Once ignore exists, this should be turned on. | |
198 ;;; o Warn about functions and variables defined but not used? | |
199 ;;; Maybe add some kind of `export' declaration for this? | |
200 ;;; (With interactive functions being automatically exported?) | |
201 ;;; o Any reference to a variable, even one which is a no-op, will cause | |
202 ;;; the warning not to be given. Possibly we could use the for-effect | |
203 ;;; flag to determine when this reference is useless; possibly more | |
204 ;;; complex flow analysis would be necessary. | |
205 ;;; o If the optimizer deletes a variable reference, we might be left with | |
206 ;;; a bound-but-not-referenced warning. Generally this is ok, but not if | |
207 ;;; it's a synergistic result of macroexpansion. Need some way to note | |
208 ;;; that a varref is being optimized away? Of course it would be nice to | |
209 ;;; optimize away the binding too, someday, but it's unsafe today. | |
210 ;;; o (See byte-optimize.el for the optimization TODO list.) | |
211 | |
212 (require 'backquote) | |
213 | |
214 (or (fboundp 'defsubst) | |
215 ;; This really ought to be loaded already! | |
216 (load-library "bytecomp-runtime")) | |
217 | |
444 | 218 (defvar emacs-lisp-file-regexp "\\.el$" |
428 | 219 "*Regexp which matches Emacs Lisp source files. |
220 You may want to redefine `byte-compile-dest-file' if you change this.") | |
221 | |
222 ;; This enables file name handlers such as jka-compr | |
223 ;; to remove parts of the file name that should not be copied | |
224 ;; through to the output file name. | |
225 (defun byte-compiler-base-file-name (filename) | |
226 (let ((handler (find-file-name-handler filename | |
227 'byte-compiler-base-file-name))) | |
228 (if handler | |
229 (funcall handler 'byte-compiler-base-file-name filename) | |
230 filename))) | |
231 | |
232 (unless (fboundp 'byte-compile-dest-file) | |
233 ;; The user may want to redefine this along with emacs-lisp-file-regexp, | |
234 ;; so only define it if it is undefined. | |
235 (defun byte-compile-dest-file (filename) | |
236 "Convert an Emacs Lisp source file name to a compiled file name." | |
237 (setq filename (byte-compiler-base-file-name filename)) | |
238 (setq filename (file-name-sans-versions filename)) | |
239 (if (string-match emacs-lisp-file-regexp filename) | |
240 (concat (substring filename 0 (match-beginning 0)) ".elc") | |
241 (concat filename ".elc")))) | |
242 | |
243 ;; This can be the 'byte-compile property of any symbol. | |
244 (autoload 'byte-compile-inline-expand "byte-optimize") | |
245 | |
246 ;; This is the entrypoint to the lapcode optimizer pass1. | |
247 (autoload 'byte-optimize-form "byte-optimize") | |
248 ;; This is the entrypoint to the lapcode optimizer pass2. | |
249 (autoload 'byte-optimize-lapcode "byte-optimize") | |
250 (autoload 'byte-compile-unfold-lambda "byte-optimize") | |
251 | |
252 ;; This is the entry point to the decompiler, which is used by the | |
253 ;; disassembler. The disassembler just requires 'byte-compile, but | |
254 ;; that doesn't define this function, so this seems to be a reasonable | |
255 ;; thing to do. | |
256 (autoload 'byte-decompile-bytecode "byte-optimize") | |
257 | |
258 (defvar byte-compile-verbose | |
259 (and (not noninteractive) (> (device-baud-rate) search-slow-speed)) | |
260 "*Non-nil means print messages describing progress of byte-compiler.") | |
261 | |
262 (defvar byte-compile-print-gensym t | |
263 "*Non-nil means generate code that creates unique symbols at run-time. | |
264 This is achieved by printing uninterned symbols using the `#:SYMBOL' | |
265 notation, so that they will be read uninterned when run. | |
266 | |
267 With this feature, code that uses uninterned symbols in macros will | |
5503
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
268 not be runnable under pre-21.0 XEmacsen.") |
428 | 269 |
270 (defvar byte-optimize t | |
271 "*Enables optimization in the byte compiler. | |
272 nil means don't do any optimization. | |
273 t means do all optimizations. | |
274 `source' means do source-level optimizations only. | |
275 `byte' means do code-level optimizations only.") | |
276 | |
277 (defvar byte-compile-delete-errors t | |
278 "*If non-nil, the optimizer may delete forms that may signal an error. | |
279 This includes variable references and calls to functions such as `car'.") | |
280 | |
281 ;; XEmacs addition | |
282 (defvar byte-compile-new-bytecodes nil | |
283 "This is completely ignored. It is only around for backwards | |
284 compatibility.") | |
285 | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
286 (defvar byte-compile-checks-on-load '((featurep 'xemacs)) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
287 "A list of expressions to check when first loading a file. |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
288 Emacs will throw an error if any of them fail; checks will be made in |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
289 reverse order.") |
428 | 290 |
291 ;; FSF enables byte-compile-dynamic-docstrings but not byte-compile-dynamic | |
292 ;; by default. This would be a reasonable conservative approach except | |
293 ;; for the fact that if you enable either of these, you get incompatible | |
294 ;; byte code that can't be read by XEmacs 19.13 or before or FSF 19.28 or | |
295 ;; before. | |
296 ;; | |
297 ;; Therefore, neither is enabled for 19.14. Both are enabled for 20.0 | |
298 ;; because we have no reason to be conservative about changing the | |
299 ;; way things work. (Ben) | |
300 | |
301 ;; However, I don't think that defaulting byte-compile-dynamic to nil | |
302 ;; is a compatibility issue - rather it is a performance issue. | |
303 ;; Therefore I am setting byte-compile-dynamic back to nil. (mrb) | |
304 | |
305 (defvar byte-compile-dynamic nil | |
306 "*If non-nil, compile function bodies so they load lazily. | |
307 They are hidden comments in the compiled file, and brought into core when the | |
308 function is called. | |
309 | |
310 To enable this option, make it a file-local variable | |
311 in the source file you want it to apply to. | |
312 For example, add -*-byte-compile-dynamic: t;-*- on the first line. | |
313 | |
314 When this option is true, if you load the compiled file and then move it, | |
315 the functions you loaded will not be able to run.") | |
316 | |
317 (defvar byte-compile-dynamic-docstrings (emacs-version>= 20) | |
318 "*If non-nil, compile doc strings for lazy access. | |
319 We bury the doc strings of functions and variables | |
320 inside comments in the file, and bring them into core only when they | |
321 are actually needed. | |
322 | |
323 When this option is true, if you load the compiled file and then move it, | |
324 you won't be able to find the documentation of anything in that file. | |
325 | |
326 To disable this option for a certain file, make it a file-local variable | |
327 in the source file. For example, add this to the first line: | |
328 -*-byte-compile-dynamic-docstrings:nil;-*- | |
329 You can also set the variable globally. | |
330 | |
331 This option is enabled by default because it reduces Emacs memory usage.") | |
332 | |
333 (defvar byte-optimize-log nil | |
334 "*If true, the byte-compiler will log its optimizations into *Compile-Log*. | |
335 If this is 'source, then only source-level optimizations will be logged. | |
336 If it is 'byte, then only byte-level optimizations will be logged.") | |
337 | |
338 (defvar byte-compile-error-on-warn nil | |
339 "*If true, the byte-compiler reports warnings with `error'.") | |
340 | |
341 ;; byte-compile-warning-types in FSF. | |
342 (defvar byte-compile-default-warnings | |
4719
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
343 '(redefine callargs subr-callargs free-vars unresolved unused-vars obsolete |
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
344 discarded-consing quoted-lambda) |
428 | 345 "*The warnings used when byte-compile-warnings is t.") |
346 | |
347 (defvar byte-compile-warnings t | |
348 "*List of warnings that the compiler should issue (t for the default set). | |
349 Elements of the list may be: | |
350 | |
351 free-vars references to variables not in the current lexical scope. | |
352 unused-vars references to non-global variables bound but not referenced. | |
353 unresolved calls to unknown functions. | |
354 callargs lambda calls with args that don't match the definition. | |
355 subr-callargs calls to subrs with args that don't match the definition. | |
356 redefine function cell redefined from a macro to a lambda or vice | |
357 versa, or redefined to take a different number of arguments. | |
358 obsolete use of an obsolete function or variable. | |
359 pedantic warn of use of compatible symbols. | |
4719
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
360 discarded-consing |
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
361 calls to (some) functions that allocate memory, where that |
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
362 memory is immediately discarded; canonically, the use of |
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
363 mapcar instead of mapc |
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
364 quoted-lambda passing a lambda expression not quoted as a function, as a |
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
365 function argument |
428 | 366 |
367 The default set is specified by `byte-compile-default-warnings' and | |
368 normally encompasses all possible warnings. | |
369 | |
370 See also the macro `byte-compiler-options'.") | |
371 | |
372 (defvar byte-compile-generate-call-tree nil | |
373 "*Non-nil means collect call-graph information when compiling. | |
374 This records functions that were called and from where. | |
375 If the value is t, compilation displays the call graph when it finishes. | |
376 If the value is neither t nor nil, compilation asks you whether to display | |
377 the graph. | |
378 | |
379 The call tree only lists functions called, not macros used. Those functions | |
380 which the byte-code interpreter knows about directly (eq, cons, etc.) are | |
381 not reported. | |
382 | |
383 The call tree also lists those functions which are not known to be called | |
384 \(that is, to which no calls have been compiled). Functions which can be | |
385 invoked interactively are excluded from this list.") | |
386 | |
387 (defconst byte-compile-call-tree nil "Alist of functions and their call tree. | |
388 Each element looks like | |
389 | |
390 \(FUNCTION CALLERS CALLS\) | |
391 | |
392 where CALLERS is a list of functions that call FUNCTION, and CALLS | |
393 is a list of functions for which calls were generated while compiling | |
394 FUNCTION.") | |
395 | |
396 (defvar byte-compile-call-tree-sort 'name | |
397 "*If non-nil, sort the call tree. | |
398 The values `name', `callers', `calls', `calls+callers' | |
399 specify different fields to sort on.") | |
400 | |
401 (defvar byte-compile-overwrite-file t | |
402 "If nil, old .elc files are deleted before the new is saved, and .elc | |
403 files will have the same modes as the corresponding .el file. Otherwise, | |
404 existing .elc files will simply be overwritten, and the existing modes | |
405 will not be changed. If this variable is nil, then an .elc file which | |
406 is a symbolic link will be turned into a normal file, instead of the file | |
407 which the link points to being overwritten.") | |
408 | |
409 (defvar byte-recompile-directory-ignore-errors-p nil | |
410 "If true, then `byte-recompile-directory' will continue compiling even | |
411 when an error occurs in a file. This is bound to t by | |
412 `batch-byte-recompile-directory'.") | |
413 | |
502 | 414 (defvar byte-recompile-ignore-uncompilable-mule-files t |
415 "If non-nil, `byte-recompile-*' ignores non-ASCII .el files in a non-Mule | |
416 XEmacs. This assumes that such files have a -*- coding: ??? -*- magic | |
417 cookie in their first line or a ;;;###coding system: magic cookie | |
418 early in the file.") | |
419 | |
428 | 420 (defvar byte-recompile-directory-recursively t |
421 "*If true, then `byte-recompile-directory' will recurse on subdirectories.") | |
422 | |
423 (defvar byte-compile-constants nil | |
424 "list of all constants encountered during compilation of this form") | |
425 (defvar byte-compile-variables nil | |
426 "list of all variables encountered during compilation of this form") | |
427 (defvar byte-compile-bound-variables nil | |
428 "Alist of variables bound in the context of the current form, | |
429 that is, the current lexical environment. This list lives partly | |
430 on the specbind stack. The cdr of each cell is an integer bitmask.") | |
5391
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
431 (defvar byte-compile-output-preface nil |
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
432 "Form to output before current by `byte-compile-output-file-form' |
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
433 This is used for implementing `load-time-value'.") |
428 | 434 |
4623
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
435 (defvar byte-compile-force-escape-quoted nil |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
436 "If t, `byte-compile-maybe-reset-coding' always chooses `escape-quoted' |
4623
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
437 |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
438 This is for situations where the byte compiler output file needs to be |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
439 able to encode character values above ?\\xFF, but this cannot be |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
440 easily determined from the input file.") |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
441 |
428 | 442 (defconst byte-compile-referenced-bit 1) |
443 (defconst byte-compile-assigned-bit 2) | |
444 (defconst byte-compile-arglist-bit 4) | |
445 (defconst byte-compile-global-bit 8) | |
446 | |
447 (defvar byte-compile-free-references) | |
448 (defvar byte-compile-free-assignments) | |
449 | |
450 (defvar byte-compiler-error-flag) | |
451 | |
446 | 452 ;;; A form of eval that includes the currently defined macro definitions. |
453 ;;; This helps implement the promise made in the Lispref: | |
454 ;;; | |
455 ;;; "If a file being compiled contains a `defmacro' form, the macro is | |
456 ;;; defined temporarily for the rest of the compilation of that file." | |
457 (defun byte-compile-eval (form) | |
458 (let ((save-macro-environment nil)) | |
459 (unwind-protect | |
5503
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
460 (loop |
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
461 for (sym . def) in byte-compile-macro-environment |
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
462 do (when (symbolp sym) |
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
463 (push |
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
464 (if (fboundp sym) |
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
465 (cons sym (symbol-function sym)) |
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
466 sym) |
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
467 save-macro-environment) |
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
468 (fset sym (cons 'macro def))) |
446 | 469 finally return (eval form)) |
470 (dolist (elt save-macro-environment) | |
471 (if (symbolp elt) | |
472 (fmakunbound elt) | |
473 (fset (car elt) (cdr elt))))))) | |
474 | |
5566
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
475 (defvar for-effect) ; ## Kludge! This should be an arg, not a special. |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
476 |
428 | 477 (defconst byte-compile-initial-macro-environment |
5263
0d436a78c514
Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
478 `((byte-compiler-options |
0d436a78c514
Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
479 . ,#'(lambda (&rest forms) |
0d436a78c514
Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
480 (apply 'byte-compiler-options-handler forms))) |
0d436a78c514
Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
481 (eval-when-compile |
0d436a78c514
Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
482 . ,#'(lambda (&rest body) |
0d436a78c514
Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
483 (list 'quote (byte-compile-eval (cons 'progn body))))) |
0d436a78c514
Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
484 (eval-and-compile |
0d436a78c514
Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
485 . ,#'(lambda (&rest body) |
0d436a78c514
Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
486 (byte-compile-eval (cons 'progn body)) |
0d436a78c514
Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
487 (cons 'progn body))) |
0d436a78c514
Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
488 (the . |
5269
90a0084b3541
Rephrase the #'the docstring, make it nicer while byte-compiling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5265
diff
changeset
|
489 ,#'(lambda (type form) |
5282
dcc34e28cd84
Warn at byte-compile in #'the if FORM constant & not TYPE; fix byte-compile-constp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5269
diff
changeset
|
490 (if (cl-const-expr-p form) |
dcc34e28cd84
Warn at byte-compile in #'the if FORM constant & not TYPE; fix byte-compile-constp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5269
diff
changeset
|
491 (or (eval (cl-make-type-test form type)) |
dcc34e28cd84
Warn at byte-compile in #'the if FORM constant & not TYPE; fix byte-compile-constp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5269
diff
changeset
|
492 (byte-compile-warn |
dcc34e28cd84
Warn at byte-compile in #'the if FORM constant & not TYPE; fix byte-compile-constp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5269
diff
changeset
|
493 "%s is not of type %s" form type))) |
5263
0d436a78c514
Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
494 (if byte-compile-delete-errors |
5269
90a0084b3541
Rephrase the #'the docstring, make it nicer while byte-compiling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5265
diff
changeset
|
495 form |
5562
855b667dea13
Drop cl-macro-environment in favour of byte-compile-macro-environment.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
496 (funcall (cdr (symbol-function 'the)) type form)))) |
855b667dea13
Drop cl-macro-environment in favour of byte-compile-macro-environment.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
497 (load-time-value |
855b667dea13
Drop cl-macro-environment in favour of byte-compile-macro-environment.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
498 . ,#'(lambda (form &optional read-only) |
855b667dea13
Drop cl-macro-environment in favour of byte-compile-macro-environment.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
499 (let* ((gensym (gensym)) |
855b667dea13
Drop cl-macro-environment in favour of byte-compile-macro-environment.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
500 (byte-compile-bound-variables |
855b667dea13
Drop cl-macro-environment in favour of byte-compile-macro-environment.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
501 (acons gensym byte-compile-global-bit |
855b667dea13
Drop cl-macro-environment in favour of byte-compile-macro-environment.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
502 byte-compile-bound-variables))) |
855b667dea13
Drop cl-macro-environment in favour of byte-compile-macro-environment.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
503 (setq byte-compile-output-preface |
855b667dea13
Drop cl-macro-environment in favour of byte-compile-macro-environment.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
504 (byte-compile-top-level |
855b667dea13
Drop cl-macro-environment in favour of byte-compile-macro-environment.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
505 `(progn (setq ,gensym ,form) ,byte-compile-output-preface) |
855b667dea13
Drop cl-macro-environment in favour of byte-compile-macro-environment.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
506 t 'file)) |
855b667dea13
Drop cl-macro-environment in favour of byte-compile-macro-environment.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
507 `(symbol-value ',gensym)))) |
855b667dea13
Drop cl-macro-environment in favour of byte-compile-macro-environment.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
508 (labels |
855b667dea13
Drop cl-macro-environment in favour of byte-compile-macro-environment.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
509 . ,#'(lambda (bindings &rest body) |
5566
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
510 (let* ((names (mapcar 'car bindings)) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
511 (lambdas (mapcar |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
512 (function* |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
513 (lambda ((name . definition)) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
514 (cons 'lambda (cdr (cl-transform-lambda |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
515 definition name))))) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
516 bindings)) |
5562
855b667dea13
Drop cl-macro-environment in favour of byte-compile-macro-environment.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
517 (placeholders |
5566
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
518 (mapcar #'(lambda (lambda) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
519 (make-byte-code (second lambda) "\xc0\x87" |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
520 [42] 1)) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
521 lambdas)) |
5562
855b667dea13
Drop cl-macro-environment in favour of byte-compile-macro-environment.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
522 (byte-compile-macro-environment |
5566
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
523 (pairlis names (mapcar |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
524 #'(lambda (placeholder) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
525 `(lambda (&rest cl-labels-args) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
526 (list* 'funcall ,placeholder |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
527 cl-labels-args))) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
528 placeholders) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
529 byte-compile-macro-environment)) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
530 (gensym (gensym))) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
531 (put gensym 'byte-compile-label-alist |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
532 (pairlis placeholders |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
533 (mapcar 'second (mapcar 'cl-macroexpand-all |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
534 lambdas)))) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
535 (put gensym 'byte-compile |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
536 #'(lambda (form) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
537 (let* ((byte-compile-label-alist |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
538 (get (car form) 'byte-compile-label-alist))) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
539 (dolist (acons byte-compile-label-alist) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
540 (setf (cdr acons) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
541 (byte-compile-lambda (cdr acons)))) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
542 (byte-compile-body-do-effect |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
543 (sublis byte-compile-label-alist (cdr form) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
544 :test #'eq)) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
545 (dolist (acons byte-compile-label-alist) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
546 (nsubst (cdr acons) (car acons) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
547 byte-compile-label-alist :test #'eq |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
548 :descend-structures t))))) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
549 (cl-macroexpand-all (cons gensym body) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
550 byte-compile-macro-environment)))) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
551 (flet . |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
552 ,#'(lambda (bindings &rest body) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
553 (let* ((names (mapcar 'car bindings)) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
554 (lambdas (mapcar |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
555 (function* |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
556 (lambda ((function . definition)) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
557 (cons 'lambda (cdr (cl-transform-lambda |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
558 definition function))))) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
559 bindings)) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
560 (gensym (gensym))) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
561 (put gensym 'byte-compile-flet-environment |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
562 (pairlis names lambdas)) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
563 (put gensym 'byte-compile |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
564 #'(lambda (form) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
565 (let* ((byte-compile-flet-environment |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
566 (get (car form) 'byte-compile-flet-environment)) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
567 (byte-compile-function-environment |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
568 (append byte-compile-flet-environment |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
569 byte-compile-function-environment)) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
570 name) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
571 (dolist (acons byte-compile-flet-environment) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
572 (setq name (car acons)) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
573 (if (and (memq 'redefine byte-compile-warnings) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
574 (or (cdr |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
575 (assq name |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
576 byte-compile-macro-environment)) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
577 (eq 'macro |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
578 (ignore-errors |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
579 (car (symbol-function name)))))) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
580 ;; XEmacs change; this is a warning, not an |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
581 ;; error. The only use case for #'flet instead |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
582 ;; of #'labels is to shadow a dynamically |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
583 ;; bound function at runtime, and it's |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
584 ;; reasonable to do this even if that symbol |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
585 ;; has a macro binding at compile time. |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
586 (byte-compile-warn |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
587 "flet: redefining macro %s as a function" |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
588 name)) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
589 (if (get name 'byte-opcode) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
590 (byte-compile-warn |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
591 "flet: %s has a byte code, consider #'labels" |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
592 name)) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
593 (if (get name 'byte-compile) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
594 (byte-compile-warn |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
595 "flet: %s has a byte-compile method, |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
596 consider #'labels" name))) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
597 (byte-compile-form (second form))))) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
598 `(,gensym (letf* ,(mapcar* #'(lambda (name lambda) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
599 `((symbol-function ',name) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
600 ,lambda)) names lambdas) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
601 ,@body)))))) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
602 |
428 | 603 "The default macro-environment passed to macroexpand by the compiler. |
604 Placing a macro here will cause a macro to have different semantics when | |
605 expanded by the compiler as when expanded by the interpreter.") | |
606 | |
607 (defvar byte-compile-function-environment nil | |
608 "Alist of functions defined in the file being compiled. | |
609 This is so we can inline them when necessary. | |
610 Each element looks like (FUNCTIONNAME . DEFINITION). It is | |
611 \(FUNCTIONNAME . nil) when a function is redefined as a macro.") | |
612 | |
613 (defvar byte-compile-autoload-environment nil | |
614 "Alist of functions and macros defined by autoload in the file being compiled. | |
615 This is so we can suppress warnings about calls to these functions, even though | |
616 they do not have `real' definitions. | |
617 Each element looks like (FUNCTIONNAME . CALL-TO-AUTOLOAD).") | |
618 | |
619 (defvar byte-compile-unresolved-functions nil | |
620 "Alist of undefined functions to which calls have been compiled (used for | |
621 warnings when the function is later defined with incorrect args).") | |
622 | |
623 (defvar byte-compile-file-domain) ; domain of file being compiled | |
624 | |
625 (defvar byte-compile-tag-number 0) | |
626 (defvar byte-compile-output nil | |
627 "Alist describing contents to put in byte code string. | |
628 Each element is (INDEX . VALUE)") | |
629 (defvar byte-compile-depth 0 "Current depth of execution stack.") | |
630 (defvar byte-compile-maxdepth 0 "Maximum depth of execution stack.") | |
631 | |
632 | |
633 ;;; The byte codes; this information is duplicated in bytecode.c | |
634 | |
635 (defconst byte-code-vector nil | |
636 "An array containing byte-code names indexed by byte-code values.") | |
637 | |
638 (defconst byte-stack+-info nil | |
639 "An array with the stack adjustment for each byte-code.") | |
640 | |
641 (defmacro byte-defop (opcode stack-adjust opname &optional docstring) | |
642 ;; This is a speed-hack for building the byte-code-vector at compile-time. | |
643 ;; We fill in the vector at macroexpand-time, and then after the last call | |
644 ;; to byte-defop, we write the vector out as a constant instead of writing | |
645 ;; out a bunch of calls to aset. | |
646 ;; Actually, we don't fill in the vector itself, because that could make | |
647 ;; it problematic to compile big changes to this compiler; we store the | |
648 ;; values on its plist, and remove them later in -extrude. | |
649 (let ((v1 (or (get 'byte-code-vector 'tmp-compile-time-value) | |
650 (put 'byte-code-vector 'tmp-compile-time-value | |
651 (make-vector 256 nil)))) | |
652 (v2 (or (get 'byte-stack+-info 'tmp-compile-time-value) | |
653 (put 'byte-stack+-info 'tmp-compile-time-value | |
654 (make-vector 256 nil))))) | |
655 (aset v1 opcode opname) | |
656 (aset v2 opcode stack-adjust)) | |
657 (if docstring | |
658 (list 'defconst opname opcode (concat "Byte code opcode " docstring ".")) | |
659 (list 'defconst opname opcode))) | |
660 | |
661 (defmacro byte-extrude-byte-code-vectors () | |
662 (prog1 (list 'setq 'byte-code-vector | |
663 (get 'byte-code-vector 'tmp-compile-time-value) | |
664 'byte-stack+-info | |
665 (get 'byte-stack+-info 'tmp-compile-time-value)) | |
666 (remprop 'byte-code-vector 'tmp-compile-time-value) | |
667 (remprop 'byte-stack+-info 'tmp-compile-time-value))) | |
668 | |
669 | |
670 ;; unused: 0-7 | |
671 | |
672 ;; These opcodes are special in that they pack their argument into the | |
673 ;; opcode word. | |
674 ;; | |
675 (byte-defop 8 1 byte-varref "for variable reference") | |
676 (byte-defop 16 -1 byte-varset "for setting a variable") | |
677 (byte-defop 24 -1 byte-varbind "for binding a variable") | |
678 (byte-defop 32 0 byte-call "for calling a function") | |
679 (byte-defop 40 0 byte-unbind "for unbinding special bindings") | |
680 ;; codes 8-47 are consumed by the preceding opcodes | |
681 | |
682 ;; unused: 48-55 | |
683 | |
684 (byte-defop 56 -1 byte-nth) | |
685 (byte-defop 57 0 byte-symbolp) | |
686 (byte-defop 58 0 byte-consp) | |
687 (byte-defop 59 0 byte-stringp) | |
688 (byte-defop 60 0 byte-listp) | |
689 (byte-defop 61 -1 byte-old-eq) | |
690 (byte-defop 62 -1 byte-old-memq) | |
691 (byte-defop 63 0 byte-not) | |
692 (byte-defop 64 0 byte-car) | |
693 (byte-defop 65 0 byte-cdr) | |
694 (byte-defop 66 -1 byte-cons) | |
695 (byte-defop 67 0 byte-list1) | |
696 (byte-defop 68 -1 byte-list2) | |
697 (byte-defop 69 -2 byte-list3) | |
698 (byte-defop 70 -3 byte-list4) | |
699 (byte-defop 71 0 byte-length) | |
700 (byte-defop 72 -1 byte-aref) | |
701 (byte-defop 73 -2 byte-aset) | |
702 (byte-defop 74 0 byte-symbol-value) | |
703 (byte-defop 75 0 byte-symbol-function) ; this was commented out | |
704 (byte-defop 76 -1 byte-set) | |
705 (byte-defop 77 -1 byte-fset) ; this was commented out | |
706 (byte-defop 78 -1 byte-get) | |
5089
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
707 (byte-defop 79 -2 byte-subseq) |
428 | 708 (byte-defop 80 -1 byte-concat2) |
709 (byte-defop 81 -2 byte-concat3) | |
710 (byte-defop 82 -3 byte-concat4) | |
711 (byte-defop 83 0 byte-sub1) | |
712 (byte-defop 84 0 byte-add1) | |
713 (byte-defop 85 -1 byte-eqlsign) | |
714 (byte-defop 86 -1 byte-gtr) | |
715 (byte-defop 87 -1 byte-lss) | |
716 (byte-defop 88 -1 byte-leq) | |
717 (byte-defop 89 -1 byte-geq) | |
718 (byte-defop 90 -1 byte-diff) | |
719 (byte-defop 91 0 byte-negate) | |
720 (byte-defop 92 -1 byte-plus) | |
721 (byte-defop 93 -1 byte-max) | |
722 (byte-defop 94 -1 byte-min) | |
723 (byte-defop 95 -1 byte-mult) | |
724 (byte-defop 96 1 byte-point) | |
725 (byte-defop 97 -1 byte-eq) ; new as of v20 | |
726 (byte-defop 98 0 byte-goto-char) | |
727 (byte-defop 99 0 byte-insert) | |
728 (byte-defop 100 1 byte-point-max) | |
729 (byte-defop 101 1 byte-point-min) | |
730 (byte-defop 102 0 byte-char-after) | |
731 (byte-defop 103 1 byte-following-char) | |
732 (byte-defop 104 1 byte-preceding-char) | |
733 (byte-defop 105 1 byte-current-column) | |
734 (byte-defop 106 0 byte-indent-to) | |
735 (byte-defop 107 -1 byte-equal) ; new as of v20 | |
736 (byte-defop 108 1 byte-eolp) | |
737 (byte-defop 109 1 byte-eobp) | |
738 (byte-defop 110 1 byte-bolp) | |
739 (byte-defop 111 1 byte-bobp) | |
740 (byte-defop 112 1 byte-current-buffer) | |
741 (byte-defop 113 0 byte-set-buffer) | |
742 (byte-defop 114 0 byte-save-current-buffer | |
743 "To make a binding to record the current buffer.") | |
744 ;;(byte-defop 114 1 byte-read-char-OBSOLETE) ;obsolete as of v19 | |
745 (byte-defop 115 -1 byte-memq) ; new as of v20 | |
746 (byte-defop 116 1 byte-interactive-p) | |
747 | |
748 (byte-defop 117 0 byte-forward-char) | |
749 (byte-defop 118 0 byte-forward-word) | |
750 (byte-defop 119 -1 byte-skip-chars-forward) | |
751 (byte-defop 120 -1 byte-skip-chars-backward) | |
752 (byte-defop 121 0 byte-forward-line) | |
753 (byte-defop 122 0 byte-char-syntax) | |
754 (byte-defop 123 -1 byte-buffer-substring) | |
755 (byte-defop 124 -1 byte-delete-region) | |
756 (byte-defop 125 -1 byte-narrow-to-region) | |
757 (byte-defop 126 1 byte-widen) | |
758 (byte-defop 127 0 byte-end-of-line) | |
759 | |
760 ;; unused: 128 | |
761 | |
762 ;; These store their argument in the next two bytes | |
763 (byte-defop 129 1 byte-constant2 | |
764 "for reference to a constant with vector index >= byte-constant-limit") | |
765 (byte-defop 130 0 byte-goto "for unconditional jump") | |
766 (byte-defop 131 -1 byte-goto-if-nil "to pop value and jump if it's nil") | |
767 (byte-defop 132 -1 byte-goto-if-not-nil | |
768 "to pop value and jump if it's not nil") | |
769 (byte-defop 133 -1 byte-goto-if-nil-else-pop | |
770 "to examine top-of-stack, jump and don't pop it if it's nil, | |
771 otherwise pop it") | |
772 (byte-defop 134 -1 byte-goto-if-not-nil-else-pop | |
773 "to examine top-of-stack, jump and don't pop it if it's non-nil, | |
774 otherwise pop it") | |
775 | |
776 (byte-defop 135 -1 byte-return "to pop a value and return it from `byte-code'") | |
777 (byte-defop 136 -1 byte-discard "to discard one value from stack") | |
778 (byte-defop 137 1 byte-dup "to duplicate the top of the stack") | |
779 | |
780 (byte-defop 138 0 byte-save-excursion | |
781 "to make a binding to record the buffer, point and mark") | |
4775
1d61580e0cf7
Remove Fsave_window_excursion from window.c, it's overridden by Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4743
diff
changeset
|
782 (byte-defop 139 0 byte-save-window-excursion ; almost obsolete |
428 | 783 "to make a binding to record entire window configuration") |
784 (byte-defop 140 0 byte-save-restriction | |
785 "to make a binding to record the current buffer clipping restrictions") | |
786 (byte-defop 141 -1 byte-catch | |
787 "for catch. Takes, on stack, the tag and an expression for the body") | |
788 (byte-defop 142 -1 byte-unwind-protect | |
789 "for unwind-protect. Takes, on stack, an expression for the unwind-action") | |
790 | |
791 ;; For condition-case. Takes, on stack, the variable to bind, | |
792 ;; an expression for the body, and a list of clauses. | |
793 (byte-defop 143 -2 byte-condition-case) | |
794 | |
795 ;; For entry to with-output-to-temp-buffer. | |
796 ;; Takes, on stack, the buffer name. | |
797 ;; Binds standard-output and does some other things. | |
798 ;; Returns with temp buffer on the stack in place of buffer name. | |
799 (byte-defop 144 0 byte-temp-output-buffer-setup) | |
800 | |
801 ;; For exit from with-output-to-temp-buffer. | |
802 ;; Expects the temp buffer on the stack underneath value to return. | |
803 ;; Pops them both, then pushes the value back on. | |
804 ;; Unbinds standard-output and makes the temp buffer visible. | |
805 (byte-defop 145 -1 byte-temp-output-buffer-show) | |
806 | |
807 ;; To unbind back to the beginning of this frame. | |
808 ;; Not used yet, but will be needed for tail-recursion elimination. | |
809 (byte-defop 146 0 byte-unbind-all) | |
810 | |
811 (byte-defop 147 -2 byte-set-marker) | |
812 (byte-defop 148 0 byte-match-beginning) | |
813 (byte-defop 149 0 byte-match-end) | |
814 (byte-defop 150 0 byte-upcase) | |
815 (byte-defop 151 0 byte-downcase) | |
816 (byte-defop 152 -1 byte-string=) | |
817 (byte-defop 153 -1 byte-string<) | |
818 (byte-defop 154 -1 byte-old-equal) | |
819 (byte-defop 155 -1 byte-nthcdr) | |
820 (byte-defop 156 -1 byte-elt) | |
821 (byte-defop 157 -1 byte-old-member) | |
822 (byte-defop 158 -1 byte-old-assq) | |
823 (byte-defop 159 0 byte-nreverse) | |
824 (byte-defop 160 -1 byte-setcar) | |
825 (byte-defop 161 -1 byte-setcdr) | |
826 (byte-defop 162 0 byte-car-safe) | |
827 (byte-defop 163 0 byte-cdr-safe) | |
828 (byte-defop 164 -1 byte-nconc) | |
829 (byte-defop 165 -1 byte-quo) | |
830 (byte-defop 166 -1 byte-rem) | |
831 (byte-defop 167 0 byte-numberp) | |
4885
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
832 (byte-defop 168 0 byte-fixnump) |
428 | 833 |
834 ;; unused: 169 | |
835 | |
836 ;; These are not present in FSF. | |
837 ;; | |
838 (byte-defop 170 0 byte-rel-goto) | |
839 (byte-defop 171 -1 byte-rel-goto-if-nil) | |
840 (byte-defop 172 -1 byte-rel-goto-if-not-nil) | |
841 (byte-defop 173 -1 byte-rel-goto-if-nil-else-pop) | |
842 (byte-defop 174 -1 byte-rel-goto-if-not-nil-else-pop) | |
843 | |
844 (byte-defop 175 nil byte-listN) | |
845 (byte-defop 176 nil byte-concatN) | |
846 (byte-defop 177 nil byte-insertN) | |
847 | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
848 (byte-defop 178 1 byte-bind-multiple-value-limits) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
849 (byte-defop 179 -3 byte-multiple-value-list-internal) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
850 (byte-defop 180 0 byte-multiple-value-call) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
851 (byte-defop 181 -1 byte-throw) |
428 | 852 |
853 ;; these ops are new to v20 | |
854 (byte-defop 182 -1 byte-member) | |
855 (byte-defop 183 -1 byte-assq) | |
856 | |
857 ;; unused: 184-191 | |
858 | |
859 (byte-defop 192 1 byte-constant "for reference to a constant") | |
860 ;; codes 193-255 are consumed by byte-constant. | |
861 (defconst byte-constant-limit 64 | |
862 "Exclusive maximum index usable in the `byte-constant' opcode.") | |
863 | |
444 | 864 (defconst byte-goto-ops |
865 '(byte-goto byte-goto-if-nil byte-goto-if-not-nil | |
866 byte-goto-if-nil-else-pop | |
867 byte-goto-if-not-nil-else-pop) | |
428 | 868 "List of byte-codes whose offset is a pc.") |
869 | |
870 (defconst byte-goto-always-pop-ops | |
444 | 871 '(byte-goto-if-nil byte-goto-if-not-nil)) |
428 | 872 |
873 (defconst byte-rel-goto-ops | |
444 | 874 '(byte-rel-goto byte-rel-goto-if-nil byte-rel-goto-if-not-nil |
875 byte-rel-goto-if-nil-else-pop byte-rel-goto-if-not-nil-else-pop) | |
428 | 876 "byte-codes for relative jumps.") |
877 | |
878 (byte-extrude-byte-code-vectors) | |
879 | |
880 ;;; lapcode generator | |
881 ;;; | |
882 ;;; the byte-compiler now does source -> lapcode -> bytecode instead of | |
883 ;;; source -> bytecode, because it's a lot easier to make optimizations | |
884 ;;; on lapcode than on bytecode. | |
885 ;;; | |
886 ;;; Elements of the lapcode list are of the form (<instruction> . <parameter>) | |
887 ;;; where instruction is a symbol naming a byte-code instruction, | |
888 ;;; and parameter is an argument to that instruction, if any. | |
889 ;;; | |
890 ;;; The instruction can be the pseudo-op TAG, which means that this position | |
891 ;;; in the instruction stream is a target of a goto. (car PARAMETER) will be | |
892 ;;; the PC for this location, and the whole instruction "(TAG pc)" will be the | |
893 ;;; parameter for some goto op. | |
894 ;;; | |
895 ;;; If the operation is varbind, varref, varset or push-constant, then the | |
896 ;;; parameter is (variable/constant . index_in_constant_vector). | |
897 ;;; | |
898 ;;; First, the source code is macroexpanded and optimized in various ways. | |
899 ;;; Then the resultant code is compiled into lapcode. Another set of | |
900 ;;; optimizations are then run over the lapcode. Then the variables and | |
901 ;;; constants referenced by the lapcode are collected and placed in the | |
902 ;;; constants-vector. (This happens now so that variables referenced by dead | |
903 ;;; code don't consume space.) And finally, the lapcode is transformed into | |
904 ;;; compacted byte-code. | |
905 ;;; | |
906 ;;; A distinction is made between variables and constants because the variable- | |
907 ;;; referencing instructions are more sensitive to the variables being near the | |
908 ;;; front of the constants-vector than the constant-referencing instructions. | |
909 ;;; Also, this lets us notice references to free variables. | |
910 | |
911 (defun byte-compile-lapcode (lap) | |
912 "Turns lapcode into bytecode. The lapcode is destroyed." | |
913 ;; Lapcode modifications: changes the ID of a tag to be the tag's PC. | |
914 (let ((pc 0) ; Program counter | |
915 op off ; Operation & offset | |
916 (bytes '()) ; Put the output bytes here | |
917 (patchlist nil) ; List of tags and goto's to patch | |
918 rest rel tmp) | |
919 (while lap | |
920 (setq op (car (car lap)) | |
921 off (cdr (car lap))) | |
922 (cond ((not (symbolp op)) | |
923 (error "Non-symbolic opcode `%s'" op)) | |
924 ((eq op 'TAG) | |
925 (setcar off pc) | |
926 (push off patchlist)) | |
927 ((memq op byte-goto-ops) | |
928 (setq pc (+ pc 3)) | |
929 (setq bytes (cons (cons pc (cdr off)) | |
930 (cons nil | |
931 (cons (symbol-value op) bytes)))) | |
932 (push bytes patchlist)) | |
933 (t | |
934 (setq bytes | |
935 (cond ((cond ((consp off) | |
936 ;; Variable or constant reference | |
937 (setq off (cdr off)) | |
938 (eq op 'byte-constant))) | |
939 (cond ((< off byte-constant-limit) | |
940 (setq pc (1+ pc)) | |
941 (cons (+ byte-constant off) bytes)) | |
942 (t | |
943 (setq pc (+ 3 pc)) | |
944 (cons (lsh off -8) | |
945 (cons (logand off 255) | |
946 (cons byte-constant2 bytes)))))) | |
947 ((and (<= byte-listN (symbol-value op)) | |
948 (<= (symbol-value op) byte-insertN)) | |
949 (setq pc (+ 2 pc)) | |
950 (cons off (cons (symbol-value op) bytes))) | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
951 ((= byte-multiple-value-call (symbol-value op)) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
952 (setq pc (1+ pc)) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
953 ;; Ignore off. |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
954 (cons (symbol-value op) bytes)) |
428 | 955 ((< off 6) |
956 (setq pc (1+ pc)) | |
957 (cons (+ (symbol-value op) off) bytes)) | |
958 ((< off 256) | |
959 (setq pc (+ 2 pc)) | |
960 (cons off (cons (+ (symbol-value op) 6) bytes))) | |
961 (t | |
962 (setq pc (+ 3 pc)) | |
963 (cons (lsh off -8) | |
964 (cons (logand off 255) | |
965 (cons (+ (symbol-value op) 7) | |
966 bytes)))))))) | |
967 (setq lap (cdr lap))) | |
968 ;;(if (not (= pc (length bytes))) | |
969 ;; (error "Compiler error: pc mismatch - %s %s" pc (length bytes))) | |
970 (cond (t ;; starting with Emacs 19. | |
971 ;; Make relative jumps | |
972 (setq patchlist (nreverse patchlist)) | |
973 (while (progn | |
974 (setq off 0) ; PC change because of deleted bytes | |
975 (setq rest patchlist) | |
976 (while rest | |
977 (setq tmp (car rest)) | |
978 (and (consp (car tmp)) ; Jump | |
979 (prog1 (null (nth 1 tmp)) ; Absolute jump | |
980 (setq tmp (car tmp))) | |
981 (progn | |
982 (setq rel (- (car (cdr tmp)) (car tmp))) | |
983 (and (<= -129 rel) (< rel 128))) | |
984 (progn | |
985 ;; Convert to relative jump. | |
986 (setcdr (car rest) (cdr (cdr (car rest)))) | |
987 (setcar (cdr (car rest)) | |
988 (+ (car (cdr (car rest))) | |
989 (- byte-rel-goto byte-goto))) | |
990 (setq off (1- off)))) | |
991 (setcar tmp (+ (car tmp) off)) ; Adjust PC | |
992 (setq rest (cdr rest))) | |
993 ;; If optimizing, repeat until no change. | |
994 (and byte-optimize | |
995 (not (zerop off))))))) | |
996 ;; Patch PC into jumps | |
997 (let (bytes) | |
998 (while patchlist | |
999 (setq bytes (car patchlist)) | |
1000 (cond ((atom (car bytes))) ; Tag | |
1001 ((nth 1 bytes) ; Relative jump | |
1002 (setcar bytes (+ (- (car (cdr (car bytes))) (car (car bytes))) | |
1003 128))) | |
1004 (t ; Absolute jump | |
1005 (setq pc (car (cdr (car bytes)))) ; Pick PC from tag | |
1006 (setcar (cdr bytes) (logand pc 255)) | |
1007 (setcar bytes (lsh pc -8)))) | |
1008 (setq patchlist (cdr patchlist)))) | |
1009 (concat (nreverse bytes)))) | |
1010 | |
1011 | |
1012 ;;; byte compiler messages | |
1013 | |
1014 (defvar byte-compile-current-form nil) | |
1015 (defvar byte-compile-current-file nil) | |
1016 (defvar byte-compile-dest-file nil) | |
1017 | |
1018 (defmacro byte-compile-log (format-string &rest args) | |
1019 `(when (and byte-optimize (memq byte-optimize-log '(t source))) | |
1020 (let ((print-escape-newlines t) | |
1021 (print-level 4) | |
1022 (print-length 4)) | |
1023 (byte-compile-log-1 (format ,format-string ,@args))))) | |
1024 | |
1025 (defconst byte-compile-last-warned-form 'nothing) | |
1026 | |
1027 ;; Log a message STRING in *Compile-Log*. | |
1028 ;; Also log the current function and file if not already done. | |
1029 (defun byte-compile-log-1 (string &optional fill) | |
1030 (let* ((this-form (or byte-compile-current-form "toplevel forms")) | |
1031 (while-compiling-msg | |
1032 (when (or byte-compile-current-file | |
1033 (not (eq this-form byte-compile-last-warned-form))) | |
1034 (format | |
1035 "While compiling %s%s:" | |
1036 this-form | |
1037 (cond | |
1038 ((stringp byte-compile-current-file) | |
1039 (concat " in file " byte-compile-current-file)) | |
1040 ((bufferp byte-compile-current-file) | |
1041 (concat " in buffer " | |
1042 (buffer-name byte-compile-current-file))) | |
1043 ("")))))) | |
1044 (if noninteractive | |
1045 (progn | |
1046 (when while-compiling-msg (message "%s" while-compiling-msg)) | |
1047 (message " %s" string)) | |
1048 (with-current-buffer (get-buffer-create "*Compile-Log*") | |
1049 (goto-char (point-max)) | |
1050 (when byte-compile-current-file | |
1051 (when (> (point-max) (point-min)) | |
1052 (insert "\n\^L\n")) | |
1053 (insert (current-time-string) "\n")) | |
1054 (when while-compiling-msg (insert while-compiling-msg "\n")) | |
1055 (insert " " string "\n") | |
1056 (when (and fill (not (string-match "\n" string))) | |
1057 (let ((fill-prefix " ") | |
1058 (fill-column 78)) | |
1059 (fill-paragraph nil))))) | |
1060 (setq byte-compile-current-file nil) | |
1061 (setq byte-compile-last-warned-form this-form))) | |
1062 | |
1063 ;; Log the start of a file in *Compile-Log*, and mark it as done. | |
1064 ;; But do nothing in batch mode. | |
1065 (defun byte-compile-log-file () | |
1066 (when (and byte-compile-current-file (not noninteractive)) | |
1067 (with-current-buffer (get-buffer-create "*Compile-Log*") | |
1068 (when (> (point-max) (point-min)) | |
1069 (goto-char (point-max)) | |
1070 (insert "\n\^L\n")) | |
1071 (insert "Compiling " | |
1072 (if (stringp byte-compile-current-file) | |
1073 (concat "file " byte-compile-current-file) | |
1074 (concat "buffer " (buffer-name byte-compile-current-file))) | |
1075 " at " (current-time-string) "\n") | |
1076 (setq byte-compile-current-file nil)))) | |
1077 | |
502 | 1078 (defvar byte-compile-inbuffer) |
1079 (defvar byte-compile-outbuffer) | |
1080 | |
428 | 1081 (defun byte-compile-warn (format &rest args) |
1082 (setq format (apply 'format format args)) | |
1083 (if byte-compile-error-on-warn | |
1084 (error "%s" format) ; byte-compile-file catches and logs it | |
1085 (byte-compile-log-1 (concat "** " format) t) | |
502 | 1086 |
1087 ;; This was a first attempt to add line numbers to the | |
1088 ;; byte-compilation output. Unfortunately, it doesn't work | |
1089 ;; perfectly: it reports the line number at the end of the form | |
1090 ;; (which may be an entire function), rather than the line number | |
1091 ;; of the actual problem. Doing this right is hard because we | |
1092 ;; currently use the built-in Lisp parser to parse the entire form | |
1093 ;; at once. What we basically need is a whole separate parser | |
1094 ;; that annotates its output with line numbers. For example, we | |
1095 ;; might modify the parser in lread.c so that, with the right | |
1096 ;; option set, it replaces every Lisp object contained in the | |
1097 ;; structure it returns with a cons of that object and the line | |
1098 ;; number it was found on (determined by counting newlines, | |
1099 ;; starting from some arbitrary point). You then have two | |
1100 ;; options: (a) Modify the byte compiler so that everything that | |
1101 ;; compiles a form deals with the new annotated form rather than | |
1102 ;; the old one, or (b) The byte compiler saves this structure | |
1103 ;; while converting it into a normal structure that's given to the | |
1104 ;; various form handlers, which need no (or less) modification. | |
1105 ;; In the former case, finding the line number is trivial because | |
1106 ;; it's in the form. In the latter case, finding the line number | |
1107 ;; depends on having a unique Lisp object that can be looked up in | |
1108 ;; the annotated structure -- i.e. a list, vector, or string. | |
1109 ;; You'd have to look at the various places where errors are spit | |
1110 ;; out (not very many, really), and make sure that such a unique | |
1111 ;; object is available. Then you do a depth-first search through | |
1112 ;; the annotated structure to find the object. | |
1113 ;; | |
1114 ;; An alternative way of doing (b) that's probably much more | |
1115 ;; efficient (and easier to implement) is simply to have the | |
1116 ;; parser in lread.c annotate every unique object using a separate | |
1117 ;; hash table. This also eliminates the need for a search to find | |
1118 ;; the line number. In order to be fine-grained enough to get at | |
1119 ;; every symbol in a form -- e.g. if we want to pinpoint a | |
1120 ;; particular undefined variable in a function call -- we need to | |
1121 ;; annotate every cons, not just each list. We still have | |
1122 ;; (probably unimportant) problems with vectors, since all we have | |
1123 ;; is the start of the vector. If we cared about this, we could | |
1124 ;; store in the hash table a list of the line numbers for each | |
1125 ;; item in the vector, not just its start. | |
1126 ;; | |
1127 ;; --ben | |
1128 | |
1129 ; (byte-compile-log-1 (concat "** line: " | |
1130 ; (save-excursion | |
1131 ; (set-buffer byte-compile-inbuffer) | |
1132 ; (int-to-string (line-number))) | |
1133 ; " " | |
1134 ; format) t) | |
428 | 1135 ;;; RMS says: |
1136 ;;; It is useless to flash warnings too fast to be read. | |
1137 ;;; Besides, they will all be shown at the end. | |
1138 ;;; and comments out the next two lines. | |
1139 (or noninteractive ; already written on stdout. | |
1140 (message "Warning: %s" format)))) | |
1141 | |
1142 ;;; This function should be used to report errors that have halted | |
1143 ;;; compilation of the current file. | |
1144 (defun byte-compile-report-error (error-info) | |
1145 (setq byte-compiler-error-flag t) | |
1146 (byte-compile-log-1 | |
1147 (concat "!! " | |
1148 (format (if (cdr error-info) "%s (%s)" "%s") | |
1149 (get (car error-info) 'error-message) | |
442 | 1150 (prin1-to-string (cdr error-info))))) |
1151 (if stack-trace-on-error | |
1152 (backtrace nil t))) | |
428 | 1153 |
1154 ;;; Used by make-obsolete. | |
1155 (defun byte-compile-obsolete (form) | |
1156 (let ((new (get (car form) 'byte-obsolete-info))) | |
1157 (if (memq 'obsolete byte-compile-warnings) | |
1158 (byte-compile-warn "%s is an obsolete function; %s" (car form) | |
1159 (if (stringp (car new)) | |
1160 (car new) | |
1161 (format "use %s instead." (car new))))) | |
1162 (funcall (or (cdr new) 'byte-compile-normal-call) form))) | |
1163 | |
1164 ;;; Used by make-obsolete. | |
1165 (defun byte-compile-compatible (form) | |
1166 (let ((new (get (car form) 'byte-compatible-info))) | |
1167 (if (memq 'pedantic byte-compile-warnings) | |
1168 (byte-compile-warn "%s is provided for compatibility; %s" (car form) | |
1169 (if (stringp (car new)) | |
1170 (car new) | |
1171 (format "use %s instead." (car new))))) | |
1172 (funcall (or (cdr new) 'byte-compile-normal-call) form))) | |
1173 | |
1174 ;; Compiler options | |
1175 | |
1176 (defconst byte-compiler-legal-options | |
1177 '((optimize byte-optimize (t nil source byte) val) | |
5503
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
1178 (file-format byte-compile-emacs19-compatibility (emacs20) |
428 | 1179 (eq val 'emacs19)) |
1180 (delete-errors byte-compile-delete-errors (t nil) val) | |
1181 (verbose byte-compile-verbose (t nil) val) | |
1182 (new-bytecodes byte-compile-new-bytecodes (t nil) val) | |
1183 (warnings byte-compile-warnings | |
4719
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
1184 ((callargs subr-callargs redefine free-vars unused-vars |
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
1185 unresolved discarded-consing quoted-lambda)) |
428 | 1186 val))) |
1187 | |
1188 ;; XEmacs addition | |
1189 (defconst byte-compiler-obsolete-options | |
5503
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
1190 '((new-bytecodes t) (byte-compile-emacs19-compatibility nil))) |
428 | 1191 |
1192 (defun byte-compiler-options-handler (&rest args) | |
1193 (let (key val desc choices) | |
1194 (while args | |
1195 (if (or (atom (car args)) (nthcdr 2 (car args)) (null (cdr (car args)))) | |
1196 (error "malformed byte-compiler-option %s" (car args))) | |
1197 (setq key (car (car args)) | |
1198 val (car (cdr (car args))) | |
1199 desc (assq key byte-compiler-legal-options)) | |
1200 (or desc | |
1201 (error "unknown byte-compiler option %s" key)) | |
1202 (if (assq key byte-compiler-obsolete-options) | |
1203 (byte-compile-warn "%s is an obsolete byte-compiler option." key)) | |
1204 (setq choices (nth 2 desc)) | |
1205 (if (consp (car choices)) | |
1206 (let* (this | |
1207 (handler 'cons) | |
1208 (var (nth 1 desc)) | |
1209 (ret (and (memq (car val) '(+ -)) | |
1210 (copy-sequence (if (eq t (symbol-value var)) | |
1211 (car choices) | |
1212 (symbol-value var)))))) | |
1213 (setq choices (car choices)) | |
1214 (while val | |
1215 (setq this (car val)) | |
1216 (cond ((memq this choices) | |
1217 (setq ret (funcall handler this ret))) | |
1218 ((eq this '+) (setq handler 'cons)) | |
1219 ((eq this '-) (setq handler 'delq)) | |
1220 ((error "%s only accepts %s." key choices))) | |
1221 (setq val (cdr val))) | |
1222 (set (nth 1 desc) ret)) | |
1223 (or (memq val choices) | |
1224 (error "%s must be one of %s." key choices)) | |
1225 (set (nth 1 desc) (eval (nth 3 desc)))) | |
1226 (setq args (cdr args))) | |
1227 nil)) | |
1228 | |
1229 ;;; sanity-checking arglists | |
1230 | |
1231 (defun byte-compile-fdefinition (name macro-p) | |
1232 (let* ((list (if (memq macro-p '(nil subr)) | |
1233 byte-compile-function-environment | |
1234 byte-compile-macro-environment)) | |
1235 (env (cdr (assq name list)))) | |
1236 (or env | |
1237 (let ((fn name)) | |
1238 (while (and (symbolp fn) | |
1239 (fboundp fn) | |
1240 (or (symbolp (symbol-function fn)) | |
1241 (consp (symbol-function fn)) | |
1242 (and (not macro-p) | |
1243 (compiled-function-p (symbol-function fn))) | |
1244 (and (eq macro-p 'subr) (subrp fn)))) | |
1245 (setq fn (symbol-function fn))) | |
1246 (if (or (and (not macro-p) (compiled-function-p fn)) | |
1247 (and (eq macro-p 'subr) (subrp fn))) | |
1248 fn | |
1249 (and (consp fn) | |
1250 (not (eq macro-p 'subr)) | |
1251 (if (eq 'macro (car fn)) | |
1252 (cdr fn) | |
1253 (if macro-p | |
1254 nil | |
1255 (if (eq 'autoload (car fn)) | |
1256 nil | |
1257 fn))))))))) | |
1258 | |
1259 (defun byte-compile-arglist-signature (arglist) | |
1260 (let ((args 0) | |
1261 opts | |
1262 restp) | |
1263 (while arglist | |
1264 (cond ((eq (car arglist) '&optional) | |
1265 (or opts (setq opts 0))) | |
1266 ((eq (car arglist) '&rest) | |
1267 (if (cdr arglist) | |
1268 (setq restp t | |
1269 arglist nil))) | |
1270 (t | |
1271 (if opts | |
1272 (setq opts (1+ opts)) | |
1273 (setq args (1+ args))))) | |
1274 (setq arglist (cdr arglist))) | |
1275 (cons args (if restp nil (if opts (+ args opts) args))))) | |
1276 | |
1277 | |
1278 (defun byte-compile-arglist-signatures-congruent-p (old new) | |
1279 (not (or | |
1280 (> (car new) (car old)) ; requires more args now | |
1281 (and (null (cdr old)) ; tooks rest-args, doesn't any more | |
1282 (cdr new)) | |
1283 (and (cdr new) (cdr old) ; can't take as many args now | |
1284 (< (cdr new) (cdr old))) | |
1285 ))) | |
1286 | |
1287 (defun byte-compile-arglist-signature-string (signature) | |
1288 (cond ((null (cdr signature)) | |
1289 (format "%d+" (car signature))) | |
1290 ((= (car signature) (cdr signature)) | |
1291 (format "%d" (car signature))) | |
1292 (t (format "%d-%d" (car signature) (cdr signature))))) | |
1293 | |
1294 | |
1295 ;; Warn if the form is calling a function with the wrong number of arguments. | |
1296 (defun byte-compile-callargs-warn (form) | |
1297 (let* ((def (or (byte-compile-fdefinition (car form) nil) | |
1298 (byte-compile-fdefinition (car form) t))) | |
1299 (sig (and def (byte-compile-arglist-signature | |
1300 (if (eq 'lambda (car-safe def)) | |
1301 (nth 1 def) | |
1302 (if (compiled-function-p def) | |
1303 (compiled-function-arglist def) | |
1304 '(&rest def)))))) | |
1305 (ncall (length (cdr form)))) | |
1306 (if (and (null def) | |
1307 (fboundp 'subr-min-args) | |
1308 (setq def (byte-compile-fdefinition (car form) 'subr))) | |
1309 (setq sig (cons (subr-min-args def) (subr-max-args def)))) | |
1310 (if sig | |
1311 (if (or (< ncall (car sig)) | |
1312 (and (cdr sig) (> ncall (cdr sig)))) | |
1313 (byte-compile-warn | |
1314 "%s called with %d argument%s, but %s %s" | |
1315 (car form) ncall | |
1316 (if (= 1 ncall) "" "s") | |
1317 (if (< ncall (car sig)) | |
1318 "requires" | |
1319 "accepts only") | |
1320 (byte-compile-arglist-signature-string sig))) | |
1321 (or (fboundp (car form)) ; might be a subr or autoload. | |
1322 ;; ## this doesn't work with recursion. | |
1323 (eq (car form) byte-compile-current-form) | |
1324 ;; It's a currently-undefined function. | |
1325 ;; Remember number of args in call. | |
1326 (let ((cons (assq (car form) byte-compile-unresolved-functions)) | |
1327 (n (length (cdr form)))) | |
1328 (if cons | |
1329 (or (memq n (cdr cons)) | |
1330 (setcdr cons (cons n (cdr cons)))) | |
1331 (setq byte-compile-unresolved-functions | |
1332 (cons (list (car form) n) | |
1333 byte-compile-unresolved-functions)))))))) | |
1334 | |
1335 ;; Warn if the function or macro is being redefined with a different | |
1336 ;; number of arguments. | |
1337 (defun byte-compile-arglist-warn (form macrop) | |
1338 (let ((old (byte-compile-fdefinition (nth 1 form) macrop))) | |
1339 (if old | |
1340 (let ((sig1 (byte-compile-arglist-signature | |
1341 (if (eq 'lambda (car-safe old)) | |
1342 (nth 1 old) | |
1343 (if (compiled-function-p old) | |
1344 (compiled-function-arglist old) | |
1345 '(&rest def))))) | |
1346 (sig2 (byte-compile-arglist-signature (nth 2 form)))) | |
1347 (or (byte-compile-arglist-signatures-congruent-p sig1 sig2) | |
1348 (byte-compile-warn "%s %s used to take %s %s, now takes %s" | |
1349 (if (eq (car form) 'defun) "function" "macro") | |
1350 (nth 1 form) | |
1351 (byte-compile-arglist-signature-string sig1) | |
1352 (if (equal sig1 '(1 . 1)) "argument" "arguments") | |
1353 (byte-compile-arglist-signature-string sig2)))) | |
1354 ;; This is the first definition. See if previous calls are compatible. | |
1355 (let ((calls (assq (nth 1 form) byte-compile-unresolved-functions)) | |
1356 nums sig min max) | |
1357 (if calls | |
1358 (progn | |
1359 (setq sig (byte-compile-arglist-signature (nth 2 form)) | |
1360 nums (sort (copy-sequence (cdr calls)) (function <)) | |
1361 min (car nums) | |
1362 max (car (nreverse nums))) | |
1363 (if (or (< min (car sig)) | |
1364 (and (cdr sig) (> max (cdr sig)))) | |
1365 (byte-compile-warn | |
1366 "%s being defined to take %s%s, but was previously called with %s" | |
1367 (nth 1 form) | |
1368 (byte-compile-arglist-signature-string sig) | |
1369 (if (equal sig '(1 . 1)) " arg" " args") | |
1370 (byte-compile-arglist-signature-string (cons min max)))) | |
1371 | |
1372 (setq byte-compile-unresolved-functions | |
1373 (delq calls byte-compile-unresolved-functions))))) | |
1374 ))) | |
1375 | |
1376 ;; If we have compiled any calls to functions which are not known to be | |
1377 ;; defined, issue a warning enumerating them. | |
1378 ;; `unresolved' in the list `byte-compile-warnings' disables this. | |
1379 (defun byte-compile-warn-about-unresolved-functions (&optional msg) | |
1380 (if (memq 'unresolved byte-compile-warnings) | |
1381 (let ((byte-compile-current-form (or msg "the end of the data"))) | |
1382 ;; First delete the autoloads from the list. | |
1383 (if byte-compile-autoload-environment | |
1384 (let ((rest byte-compile-unresolved-functions)) | |
1385 (while rest | |
1386 (if (assq (car (car rest)) byte-compile-autoload-environment) | |
1387 (setq byte-compile-unresolved-functions | |
1388 (delq (car rest) byte-compile-unresolved-functions))) | |
1389 (setq rest (cdr rest))))) | |
1390 ;; Now warn. | |
1391 (if (cdr byte-compile-unresolved-functions) | |
1392 (let* ((str "The following functions are not known to be defined: ") | |
1393 (L (+ (length str) 5)) | |
1394 (rest (reverse byte-compile-unresolved-functions)) | |
1395 s) | |
1396 (while rest | |
1397 (setq s (symbol-name (car (car rest))) | |
1398 L (+ L (length s) 2) | |
1399 rest (cdr rest)) | |
1400 (if (<= L (1- fill-column)) | |
1401 (setq str (concat str " " s (and rest ","))) | |
1402 (setq str (concat str "\n " s (and rest ",")) | |
1403 L (+ (length s) 4)))) | |
1404 (byte-compile-warn "%s" str)) | |
1405 (if byte-compile-unresolved-functions | |
1406 (byte-compile-warn "the function %s is not known to be defined." | |
1407 (car (car byte-compile-unresolved-functions))))))) | |
1408 nil) | |
1409 | |
1410 (defun byte-compile-defvar-p (var) | |
1411 ;; Whether the byte compiler thinks that non-lexical references to this | |
1412 ;; variable are ok. | |
1413 (or (globally-boundp var) | |
1414 (let ((rest byte-compile-bound-variables)) | |
1415 (while (and rest var) | |
1416 (if (and (eq var (car-safe (car rest))) | |
1417 (not (= 0 (logand (cdr (car rest)) | |
1418 byte-compile-global-bit)))) | |
1419 (setq var nil)) | |
1420 (setq rest (cdr rest))) | |
1421 ;; if var is nil at this point, it's a defvar in this file. | |
444 | 1422 (not var)) |
1423 ;; Perhaps (eval-when-compile (defvar foo)) | |
1424 (and (boundp 'current-load-list) | |
1425 (memq var current-load-list)))) | |
428 | 1426 |
1427 | |
1428 ;;; If we have compiled bindings of variables which have no referents, warn. | |
1429 (defun byte-compile-warn-about-unused-variables () | |
1430 (let ((rest byte-compile-bound-variables) | |
1431 (unreferenced '()) | |
1432 cell) | |
1433 (while (and rest | |
1434 ;; only warn about variables whose lifetime is now ending, | |
1435 ;; that is, variables from the lexical scope that is now | |
1436 ;; terminating. (Think nested lets.) | |
1437 (not (eq (car rest) 'new-scope))) | |
1438 (setq cell (car rest)) | |
1439 (if (and (= 0 (logand byte-compile-referenced-bit (cdr cell))) | |
1440 ;; Don't warn about declared-but-unused arguments, | |
1441 ;; for two reasons: first, the arglist structure | |
1442 ;; might be imposed by external forces, and we don't | |
1443 ;; have (declare (ignore x)) yet; and second, inline | |
1444 ;; expansion produces forms like | |
1445 ;; ((lambda (arg) (byte-code "..." [arg])) x) | |
1446 ;; which we can't (ok, well, don't) recognize as | |
1447 ;; containing a reference to arg, so every inline | |
1448 ;; expansion would generate a warning. (If we had | |
1449 ;; `ignore' then inline expansion could emit an | |
1450 ;; ignore declaration.) | |
1451 (= 0 (logand byte-compile-arglist-bit (cdr cell))) | |
1452 ;; Don't warn about defvars because this is a | |
1453 ;; legitimate special binding. | |
1454 (not (byte-compile-defvar-p (car cell)))) | |
1455 (setq unreferenced (cons (car cell) unreferenced))) | |
1456 (setq rest (cdr rest))) | |
1457 (setq unreferenced (nreverse unreferenced)) | |
1458 (while unreferenced | |
1459 (byte-compile-warn | |
1460 (format "variable %s bound but not referenced" (car unreferenced))) | |
1461 (setq unreferenced (cdr unreferenced))))) | |
1462 | |
1463 | |
1464 (defmacro byte-compile-constant-symbol-p (symbol) | |
1465 `(or (keywordp ,symbol) (memq ,symbol '(nil t)))) | |
1466 | |
1467 (defmacro byte-compile-constp (form) | |
1468 ;; Returns non-nil if FORM is a constant. | |
5282
dcc34e28cd84
Warn at byte-compile in #'the if FORM constant & not TYPE; fix byte-compile-constp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5269
diff
changeset
|
1469 `(cond ((consp ,form) (memq (car ,form) '(quote function))) |
428 | 1470 ((symbolp ,form) (byte-compile-constant-symbol-p ,form)) |
1471 (t))) | |
1472 | |
1473 (defmacro byte-compile-close-variables (&rest body) | |
1474 `(let | |
1475 (;; | |
1476 ;; Close over these variables to encapsulate the | |
1477 ;; compilation state | |
1478 ;; | |
1479 (byte-compile-macro-environment | |
1480 ;; Copy it because the compiler may patch into the | |
1481 ;; macroenvironment. | |
1482 (copy-alist byte-compile-initial-macro-environment)) | |
1483 (byte-compile-function-environment nil) | |
1484 (byte-compile-autoload-environment nil) | |
1485 (byte-compile-unresolved-functions nil) | |
1486 (byte-compile-bound-variables nil) | |
1487 (byte-compile-free-references nil) | |
1488 (byte-compile-free-assignments nil) | |
1489 ;; | |
1490 ;; Close over these variables so that `byte-compiler-options' | |
1491 ;; can change them on a per-file basis. | |
1492 ;; | |
1493 (byte-compile-verbose byte-compile-verbose) | |
1494 (byte-optimize byte-optimize) | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1495 (byte-compile-checks-on-load |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1496 byte-compile-checks-on-load) |
428 | 1497 (byte-compile-dynamic byte-compile-dynamic) |
1498 (byte-compile-dynamic-docstrings | |
1499 byte-compile-dynamic-docstrings) | |
1500 (byte-compile-warnings (if (eq byte-compile-warnings t) | |
1501 byte-compile-default-warnings | |
1502 byte-compile-warnings)) | |
1503 (byte-compile-file-domain nil)) | |
1504 (prog1 | |
1505 (progn ,@body) | |
1506 (if (memq 'unused-vars byte-compile-warnings) | |
1507 ;; done compiling in this scope, warn now. | |
1508 (byte-compile-warn-about-unused-variables))))) | |
1509 | |
1510 | |
1511 (defmacro displaying-byte-compile-warnings (&rest body) | |
1512 `(let* ((byte-compile-log-buffer (get-buffer-create "*Compile-Log*")) | |
1513 (byte-compile-point-max-prev (point-max byte-compile-log-buffer))) | |
1514 ;; Log the file name or buffer name. | |
1515 (byte-compile-log-file) | |
1516 ;; Record how much is logged now. | |
1517 ;; We will display the log buffer if anything more is logged | |
1518 ;; before the end of BODY. | |
1519 (defvar byte-compile-warnings-beginning) | |
1520 (let ((byte-compile-warnings-beginning | |
1521 (if (boundp 'byte-compile-warnings-beginning) | |
1522 byte-compile-warnings-beginning | |
1523 (point-max byte-compile-log-buffer)))) | |
1524 | |
1525 (unwind-protect | |
442 | 1526 (call-with-condition-handler |
1527 #'(lambda (error-info) | |
1528 (byte-compile-report-error error-info)) | |
1529 #'(lambda () | |
1530 (progn ,@body))) | |
428 | 1531 ;; Always set point in log to start of interesting output. |
1532 (with-current-buffer byte-compile-log-buffer | |
1533 (let ((show-begin | |
1534 (progn (goto-char byte-compile-point-max-prev) | |
1535 (skip-chars-forward "\^L\n") | |
1536 (point)))) | |
1537 ;; If there were compilation warnings, display them. | |
1538 (if temp-buffer-show-function | |
1539 (let ((show-buffer (get-buffer-create "*Compile-Log-Show*"))) | |
1540 ;; Always clean show-buffer, even when not displaying it, | |
1541 ;; so that misleading previous messages aren't left around. | |
1542 (with-current-buffer show-buffer | |
1543 (setq buffer-read-only nil) | |
1544 (erase-buffer)) | |
1545 (copy-to-buffer show-buffer show-begin (point-max)) | |
1546 (when (< byte-compile-warnings-beginning (point-max)) | |
1547 (funcall temp-buffer-show-function show-buffer))) | |
1548 (when (< byte-compile-warnings-beginning (point-max)) | |
1549 (select-window | |
1550 (prog1 (selected-window) | |
1551 (select-window (display-buffer (current-buffer))) | |
1552 (goto-char show-begin) | |
1553 (recenter 1))))))))))) | |
1554 | |
1555 | |
1556 ;;;###autoload | |
1557 (defun byte-force-recompile (directory) | |
1558 "Recompile every `.el' file in DIRECTORY that already has a `.elc' file. | |
1559 Files in subdirectories of DIRECTORY are processed also." | |
1560 (interactive "DByte force recompile (directory): ") | |
442 | 1561 (byte-recompile-directory directory nil nil t)) |
428 | 1562 |
1563 ;;;###autoload | |
1564 (defun byte-recompile-directory (directory &optional arg norecursion force) | |
1565 "Recompile every `.el' file in DIRECTORY that needs recompilation. | |
1566 This is if a `.elc' file exists but is older than the `.el' file. | |
444 | 1567 Files in subdirectories of DIRECTORY are also processed unless |
1568 optional argument NORECURSION is non-nil. | |
428 | 1569 |
1570 If the `.elc' file does not exist, normally the `.el' file is *not* compiled. | |
1571 But a prefix argument (optional second arg) means ask user, | |
1572 for each such `.el' file, whether to compile it. Prefix argument 0 means | |
1573 don't ask and compile the file anyway. | |
1574 | |
1575 A nonzero prefix argument also means ask about each subdirectory. | |
1576 | |
444 | 1577 If the fourth optional argument FORCE is non-nil, |
428 | 1578 recompile every `.el' file that already has a `.elc' file." |
1579 (interactive "DByte recompile directory: \nP") | |
1580 (if arg | |
1581 (setq arg (prefix-numeric-value arg))) | |
1582 (if noninteractive | |
1583 nil | |
1584 (save-some-buffers) | |
1585 (redraw-modeline)) | |
1586 (let ((directories (list (expand-file-name directory))) | |
1587 (file-count 0) | |
1588 (dir-count 0) | |
1589 last-dir) | |
1590 (displaying-byte-compile-warnings | |
1591 (while directories | |
1592 (setq directory (file-name-as-directory (car directories))) | |
1593 (or noninteractive (message "Checking %s..." directory)) | |
1594 (let ((files (directory-files directory)) | |
1595 source dest) | |
1596 (while files | |
1597 (setq source (expand-file-name (car files) directory)) | |
1598 (if (and (not (member (car files) '("." ".." "RCS" "CVS" "SCCS"))) | |
1599 ;; Stay away from directory back-links, etc: | |
1600 (not (file-symlink-p source)) | |
1601 (file-directory-p source) | |
1602 byte-recompile-directory-recursively) | |
1603 ;; This file is a subdirectory. Handle them differently. | |
1604 (if (or (null arg) | |
1605 (eq arg 0) | |
1606 (y-or-n-p (concat "Check " source "? "))) | |
1607 (setq directories | |
1608 (nconc directories (list source)))) | |
1609 ;; It is an ordinary file. Decide whether to compile it. | |
1610 (if (and (string-match emacs-lisp-file-regexp source) | |
1611 (not (auto-save-file-name-p source)) | |
502 | 1612 ;; make sure not a mule file we can't handle. |
1613 (or (not byte-recompile-ignore-uncompilable-mule-files) | |
1614 (featurep 'mule) | |
1615 (not (find-coding-system-magic-cookie-in-file | |
1616 source))) | |
428 | 1617 (setq dest (byte-compile-dest-file source)) |
1618 (if (file-exists-p dest) | |
1619 ;; File was already compiled. | |
1620 (or force (file-newer-than-file-p source dest)) | |
1621 ;; No compiled file exists yet. | |
1622 (and arg | |
1623 (or (eq 0 arg) | |
1624 (y-or-n-p (concat "Compile " source "? ")))))) | |
1625 (progn ;(if (and noninteractive (not byte-compile-verbose)) | |
1626 ; (message "Compiling %s..." source)) | |
1627 ; we do this in byte-compile-file. | |
1628 (if byte-recompile-directory-ignore-errors-p | |
1629 (batch-byte-compile-1 source) | |
1630 (byte-compile-file source)) | |
1631 (or noninteractive | |
1632 (message "Checking %s..." directory)) | |
1633 (setq file-count (1+ file-count)) | |
1634 (if (not (eq last-dir directory)) | |
1635 (setq last-dir directory | |
1636 dir-count (1+ dir-count))) | |
1637 ))) | |
1638 (setq files (cdr files)))) | |
1639 (setq directories (cdr directories)))) | |
1640 (message "Done (Total of %d file%s compiled%s)" | |
1641 file-count (if (= file-count 1) "" "s") | |
1642 (if (> dir-count 1) (format " in %d directories" dir-count) "")))) | |
1643 | |
1644 ;;;###autoload | |
1645 (defun byte-recompile-file (filename &optional force) | |
1646 "Recompile a file of Lisp code named FILENAME if it needs recompilation. | |
1647 This is if the `.elc' file exists but is older than the `.el' file. | |
1648 | |
1649 If the `.elc' file does not exist, normally the `.el' file is *not* | |
1650 compiled. But a prefix argument (optional second arg) means ask user | |
1651 whether to compile it. Prefix argument 0 don't ask and recompile anyway." | |
1652 (interactive "fByte recompile file: \nP") | |
1653 (let ((dest)) | |
1654 (if (and (string-match emacs-lisp-file-regexp filename) | |
1655 (not (auto-save-file-name-p filename)) | |
1656 (setq dest (byte-compile-dest-file filename)) | |
1657 (if (file-exists-p dest) | |
1658 (file-newer-than-file-p filename dest) | |
1659 (and force | |
1660 (or (eq 0 force) | |
502 | 1661 (y-or-n-p (concat "Compile " filename "? "))))) |
1662 (or (not byte-recompile-ignore-uncompilable-mule-files) | |
1663 (featurep 'mule) | |
1664 (not (find-coding-system-magic-cookie-in-file filename)))) | |
428 | 1665 (byte-compile-file filename)))) |
1666 | |
1667 ;;;###autoload | |
1668 (defun byte-compile-file (filename &optional load) | |
1669 "Compile a file of Lisp code named FILENAME into a file of byte code. | |
1670 The output file's name is made by appending `c' to the end of FILENAME. | |
1671 With prefix arg (noninteractively: 2nd arg), load the file after compiling." | |
1672 ;; (interactive "fByte compile file: \nP") | |
1673 (interactive | |
1674 (let ((file buffer-file-name) | |
1675 (file-name nil) | |
1676 (file-dir nil)) | |
1677 (and file | |
1678 (eq (cdr (assq 'major-mode (buffer-local-variables))) | |
1679 'emacs-lisp-mode) | |
1680 (setq file-name (file-name-nondirectory file) | |
1681 file-dir (file-name-directory file))) | |
1682 (list (read-file-name (if current-prefix-arg | |
1683 "Byte compile and load file: " | |
1684 "Byte compile file: ") | |
1685 file-dir nil nil file-name) | |
1686 current-prefix-arg))) | |
1687 ;; Expand now so we get the current buffer's defaults | |
1688 (setq filename (expand-file-name filename)) | |
1689 | |
1690 ;; If we're compiling a file that's in a buffer and is modified, offer | |
1691 ;; to save it first. | |
1692 (or noninteractive | |
1693 (let ((b (get-file-buffer (expand-file-name filename)))) | |
1694 (if (and b (buffer-modified-p b) | |
1695 (y-or-n-p (format "save buffer %s first? " (buffer-name b)))) | |
1696 (save-excursion (set-buffer b) (save-buffer))))) | |
1697 | |
1698 (if (or noninteractive byte-compile-verbose) ; XEmacs change | |
1699 (message "Compiling %s..." filename)) | |
1700 (let (;;(byte-compile-current-file (file-name-nondirectory filename)) | |
1701 (byte-compile-current-file filename) | |
1702 target-file input-buffer output-buffer | |
1703 byte-compile-dest-file) | |
1704 (setq target-file (byte-compile-dest-file filename)) | |
1705 (setq byte-compile-dest-file target-file) | |
1706 (save-excursion | |
1707 (setq input-buffer (get-buffer-create " *Compiler Input*")) | |
1708 (set-buffer input-buffer) | |
1709 (erase-buffer) | |
1710 (insert-file-contents filename) | |
1711 ;; Run hooks including the uncompression hook. | |
1712 ;; If they change the file name, then change it for the output also. | |
1713 (let ((buffer-file-name filename) | |
1714 (default-major-mode 'emacs-lisp-mode) | |
1715 (enable-local-eval nil)) | |
1716 (normal-mode) | |
1717 (setq filename buffer-file-name))) | |
1718 (setq byte-compiler-error-flag nil) | |
1719 ;; It is important that input-buffer not be current at this call, | |
1720 ;; so that the value of point set in input-buffer | |
1721 ;; within byte-compile-from-buffer lingers in that buffer. | |
1722 (setq output-buffer (byte-compile-from-buffer input-buffer filename)) | |
1723 (if byte-compiler-error-flag | |
1724 nil | |
1725 (if byte-compile-verbose | |
1726 (message "Compiling %s...done" filename)) | |
1727 (kill-buffer input-buffer) | |
1728 (save-excursion | |
1729 (set-buffer output-buffer) | |
1730 (goto-char (point-max)) | |
1731 (insert "\n") ; aaah, unix. | |
1732 (setq target-file (byte-compile-dest-file filename)) | |
1733 (unless byte-compile-overwrite-file | |
1734 (ignore-file-errors (delete-file target-file))) | |
1735 (if (file-writable-p target-file) | |
4529
6f41fb7f3a65
Protect .elc encoding from latin-unity.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4392
diff
changeset
|
1736 ;; prevent generic hooks from changing our format, eg, |
6f41fb7f3a65
Protect .elc encoding from latin-unity.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4392
diff
changeset
|
1737 ;; latin-unity is known to change the coding system! |
6f41fb7f3a65
Protect .elc encoding from latin-unity.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4392
diff
changeset
|
1738 (let ((write-region-pre-hook nil)) |
6f41fb7f3a65
Protect .elc encoding from latin-unity.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4392
diff
changeset
|
1739 (write-region 1 (point-max) target-file)) |
428 | 1740 ;; This is just to give a better error message than write-region |
1741 (signal 'file-error | |
1742 (list "Opening output file" | |
1743 (if (file-exists-p target-file) | |
1744 "cannot overwrite file" | |
1745 "directory not writable or nonexistent") | |
1746 target-file))) | |
1747 (or byte-compile-overwrite-file | |
1748 (condition-case () | |
1749 (set-file-modes target-file (file-modes filename)) | |
1750 (error nil))) | |
1751 (kill-buffer (current-buffer))) | |
1752 (if (and byte-compile-generate-call-tree | |
1753 (or (eq t byte-compile-generate-call-tree) | |
1754 (y-or-n-p (format "Report call tree for %s? " filename)))) | |
1755 (save-excursion | |
1756 (display-call-tree filename))) | |
1757 (if load | |
1758 (load target-file)) | |
1759 t))) | |
1760 | |
1761 ;; RMS comments the next two out. | |
1762 | |
1763 ;;;###autoload | |
1764 (defun byte-compile-and-load-file (&optional filename) | |
1765 "Compile a file of Lisp code named FILENAME into a file of byte code, | |
1766 and then load it. The output file's name is made by appending \"c\" to | |
1767 the end of FILENAME." | |
1768 (interactive) | |
1769 (if filename ; I don't get it, (interactive-p) doesn't always work | |
1770 (byte-compile-file filename t) | |
1771 (let ((current-prefix-arg '(4))) | |
1772 (call-interactively 'byte-compile-file)))) | |
1773 | |
1774 ;;;###autoload | |
1775 (defun byte-compile-buffer (&optional buffer) | |
1776 "Byte-compile and evaluate contents of BUFFER (default: the current buffer)." | |
1777 (interactive "bByte compile buffer: ") | |
1778 (setq buffer (if buffer (get-buffer buffer) (current-buffer))) | |
1779 (message "Compiling %s..." buffer) | |
1780 (let* ((filename (or (buffer-file-name buffer) | |
1781 (prin1-to-string buffer))) | |
1782 (byte-compile-current-file buffer)) | |
1783 (byte-compile-from-buffer buffer filename t)) | |
1784 (message "Compiling %s...done" buffer) | |
1785 t) | |
1786 | |
1787 ;;; compiling a single function | |
1788 ;;;###autoload | |
1789 (defun compile-defun (&optional arg) | |
1790 "Compile and evaluate the current top-level form. | |
1791 Print the result in the minibuffer. | |
1792 With argument, insert value in current buffer after the form." | |
1793 (interactive "P") | |
1794 (save-excursion | |
1795 (end-of-defun) | |
1796 (beginning-of-defun) | |
1797 (let* ((byte-compile-current-file (buffer-file-name)) | |
1798 (load-file-name (buffer-file-name)) | |
1799 (byte-compile-last-warned-form 'nothing) | |
1800 (value (eval (displaying-byte-compile-warnings | |
1801 (byte-compile-sexp (read (current-buffer)) | |
1802 "toplevel forms"))))) | |
1803 (cond (arg | |
1804 (message "Compiling from buffer... done.") | |
1805 (prin1 value (current-buffer)) | |
1806 (insert "\n")) | |
1807 ((message "%s" (prin1-to-string value))))))) | |
1808 | |
1809 (defun byte-compile-from-buffer (byte-compile-inbuffer filename &optional eval) | |
1810 ;; buffer --> output-buffer, or buffer --> eval form, return nil | |
1811 (let (byte-compile-outbuffer | |
1812 ;; Prevent truncation of flonums and lists as we read and print them | |
1813 (float-output-format nil) | |
1814 (case-fold-search nil) | |
1815 (print-length nil) | |
1816 (print-level nil) | |
1817 ;; Simulate entry to byte-compile-top-level | |
1818 (byte-compile-constants nil) | |
1819 (byte-compile-variables nil) | |
1820 (byte-compile-tag-number 0) | |
1821 (byte-compile-depth 0) | |
1822 (byte-compile-maxdepth 0) | |
1823 (byte-compile-output nil) | |
1824 ;; #### This is bound in b-c-close-variables. | |
1825 ;; (byte-compile-warnings (if (eq byte-compile-warnings t) | |
1826 ;; byte-compile-warning-types | |
1827 ;; byte-compile-warnings)) | |
4623
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
1828 (byte-compile-force-escape-quoted byte-compile-force-escape-quoted) |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1829 (byte-compile-using-dynamic nil)) |
428 | 1830 (byte-compile-close-variables |
1831 (save-excursion | |
1832 (setq byte-compile-outbuffer | |
1833 (set-buffer (get-buffer-create " *Compiler Output*"))) | |
1834 (erase-buffer) | |
1835 ;; (emacs-lisp-mode) | |
1836 (setq case-fold-search nil) | |
1837 (and filename | |
1838 (not eval) | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1839 (byte-compile-maybe-reset-coding byte-compile-inbuffer |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1840 byte-compile-outbuffer)) |
4623
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
1841 (setq byte-compile-using-dynamic |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
1842 (or (symbol-value-in-buffer 'byte-compile-dynamic |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
1843 byte-compile-inbuffer) |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
1844 (symbol-value-in-buffer 'byte-compile-dynamic-docstrings |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
1845 byte-compile-inbuffer))) |
428 | 1846 ;; This is a kludge. Some operating systems (OS/2, DOS) need to |
1847 ;; write files containing binary information specially. | |
1848 ;; Under most circumstances, such files will be in binary | |
1849 ;; overwrite mode, so those OS's use that flag to guess how | |
1850 ;; they should write their data. Advise them that .elc files | |
1851 ;; need to be written carefully. | |
1852 (setq overwrite-mode 'overwrite-mode-binary)) | |
1853 (displaying-byte-compile-warnings | |
1854 (save-excursion | |
4623
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
1855 ;; All our save-excursions may have led to a less-than-useful |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
1856 ;; value for point in the outbuffer: |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
1857 (goto-char (point-max byte-compile-outbuffer) byte-compile-outbuffer) |
428 | 1858 (set-buffer byte-compile-inbuffer) |
1859 (goto-char 1) | |
1860 | |
1861 ;; Compile the forms from the input buffer. | |
1862 (while (progn | |
1863 (while (progn (skip-chars-forward " \t\n\^L") | |
1864 (looking-at ";")) | |
1865 (forward-line 1)) | |
1866 (not (eobp))) | |
5568
b039c0f018b8
Error if byte-compiling a form hasn't wrapped byte-compile-inbuffer.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5566
diff
changeset
|
1867 (byte-compile-file-form (read byte-compile-inbuffer)) |
b039c0f018b8
Error if byte-compiling a form hasn't wrapped byte-compile-inbuffer.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5566
diff
changeset
|
1868 (or (eq byte-compile-inbuffer (current-buffer)) |
b039c0f018b8
Error if byte-compiling a form hasn't wrapped byte-compile-inbuffer.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5566
diff
changeset
|
1869 (error 'invalid-state |
b039c0f018b8
Error if byte-compiling a form hasn't wrapped byte-compile-inbuffer.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5566
diff
changeset
|
1870 "byte compiling didn't save-excursion appropriately" |
b039c0f018b8
Error if byte-compiling a form hasn't wrapped byte-compile-inbuffer.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5566
diff
changeset
|
1871 (current-buffer)))) |
428 | 1872 |
1873 ;; Compile pending forms at end of file. | |
1874 (byte-compile-flush-pending) | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1875 (byte-compile-insert-header filename byte-compile-inbuffer |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1876 byte-compile-outbuffer) |
428 | 1877 (byte-compile-warn-about-unresolved-functions) |
1878 ;; Should we always do this? When calling multiple files, it | |
1879 ;; would be useful to delay this warning until all have | |
1880 ;; been compiled. | |
1881 (setq byte-compile-unresolved-functions nil))) | |
1882 (save-excursion | |
1883 (set-buffer byte-compile-outbuffer) | |
4623
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
1884 (goto-char (point-min)) |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
1885 (when (and (or byte-compile-using-dynamic |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
1886 (eq buffer-file-coding-system 'raw-text-unix)) |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
1887 (re-search-forward "[^\x00-\xff]" nil t)) |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
1888 (when (or noninteractive byte-compile-verbose) |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
1889 (message |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
1890 "%s: includes char above ?\\xFF, recompiling sans dynamic features." |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
1891 filename)) |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
1892 (set-symbol-value-in-buffer 'byte-compile-dynamic nil |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
1893 byte-compile-inbuffer) |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
1894 (set-symbol-value-in-buffer 'byte-compile-dynamic-docstrings nil |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
1895 byte-compile-inbuffer) |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
1896 (setq byte-compile-force-escape-quoted t |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
1897 byte-compile-outbuffer |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
1898 (byte-compile-from-buffer byte-compile-inbuffer |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
1899 filename eval))))) |
428 | 1900 (if (not eval) |
1901 byte-compile-outbuffer | |
1902 (let (form) | |
1903 (while (condition-case nil | |
1904 (progn (setq form (read byte-compile-outbuffer)) | |
1905 t) | |
1906 (end-of-file nil)) | |
1907 (eval form))) | |
1908 (kill-buffer byte-compile-outbuffer) | |
1909 nil))) | |
1910 | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1911 (defvar byte-compile-checks-and-comments-space 475 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1912 "Number of octets of space for checks and comments; used by the dynamic |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1913 docstrings code.") |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1914 |
428 | 1915 (defun byte-compile-insert-header (filename byte-compile-inbuffer |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1916 byte-compile-outbuffer) |
428 | 1917 (set-buffer byte-compile-inbuffer) |
4686
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
1918 (let (comments) |
428 | 1919 (set-buffer byte-compile-outbuffer) |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1920 (delete-region 1 (1+ byte-compile-checks-and-comments-space)) |
428 | 1921 (goto-char 1) |
1922 ;; | |
1923 ;; The magic number of .elc files is ";ELC", or 0x3B454C43. After that is | |
1924 ;; the file-format version number (19 or 20) as a byte, followed by some | |
1925 ;; nulls. The primary motivation for doing this is to get some binary | |
1926 ;; characters up in the first line of the file so that `diff' will simply | |
1927 ;; say "Binary files differ" instead of actually doing a diff of two .elc | |
1928 ;; files. An extra benefit is that you can add this to /etc/magic: | |
1929 ;; | |
613 | 1930 ;; 0 string ;ELC XEmacs Lisp compiled file, |
428 | 1931 ;; >4 byte x version %d |
1932 ;; | |
1933 (insert | |
1934 ";ELC" | |
5503
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
1935 20 |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1936 "\000\000\000\n") |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1937 (when (not (eq (find-coding-system 'raw-text-unix) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1938 (find-coding-system buffer-file-coding-system))) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1939 (insert (format ";;;###coding system: %s\n" |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1940 (coding-system-name buffer-file-coding-system)))) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1941 (insert (format |
4686
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
1942 "\n(or %s\n (error \"Loading this file requires %s\"))\n" |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
1943 (let ((print-readably t)) |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
1944 (prin1-to-string (if (> (length |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
1945 byte-compile-checks-on-load) |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
1946 1) |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
1947 (cons 'and |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
1948 (setq byte-compile-checks-on-load |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
1949 (reverse |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
1950 byte-compile-checks-on-load))) |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
1951 (car byte-compile-checks-on-load)))) |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
1952 (loop |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
1953 for check in byte-compile-checks-on-load |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
1954 with seen-first = nil |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
1955 with res = "" |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
1956 do |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
1957 (if seen-first |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
1958 (setq res (concat res ", ")) |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
1959 (setq seen-first t)) |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
1960 ;; Print featurep calls differently: |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
1961 (if (and (eq (car check) 'featurep) |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
1962 (eq (car (second check)) 'quote) |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
1963 (symbolp (second (second check)))) |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
1964 (setq res (concat res |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
1965 (symbol-name (second (second check))))) |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
1966 (setq res (concat res |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
1967 (let ((print-readably t)) |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
1968 (prin1-to-string check))))) |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
1969 finally return res))) |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1970 (setq comments |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1971 (with-string-as-buffer-contents "" |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1972 (insert "\n;;; compiled by " |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1973 (or (and (boundp 'user-mail-address) user-mail-address) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1974 (concat (user-login-name) "@" (system-name))) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1975 " on " |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1976 (current-time-string) "\n;;; from file " filename "\n") |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1977 (insert ";;; emacs version " emacs-version ".\n") |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1978 (insert ";;; bytecomp version " byte-compile-version "\n;;; " |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1979 (cond |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1980 ((eq byte-optimize 'source) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1981 "source-level optimization only") |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1982 ((eq byte-optimize 'byte) "byte-level optimization only") |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1983 (byte-optimize "optimization is on") |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1984 (t "optimization is off")) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1985 "\n"))) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1986 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1987 ;; We won't trip this unless the byte-compiler changes, in which case |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1988 ;; it's just a matter of upping the space. |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1989 (assert (natnump (- (1+ byte-compile-checks-and-comments-space) (point))) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1990 t "Not enough space for the feature checks!") |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1991 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1992 (if (natnump (- (1+ byte-compile-checks-and-comments-space) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1993 (+ (point) (length comments)))) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1994 (insert comments)) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1995 (insert-char ?\ (- (1+ byte-compile-checks-and-comments-space) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1996 (point))))) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1997 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1998 (defun byte-compile-maybe-reset-coding (byte-compile-inbuffer |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1999 byte-compile-outbuffer) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2000 ;; We also reserve some space for the feature checks: |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2001 (goto-char 1) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2002 (insert-char ?\ byte-compile-checks-and-comments-space) |
771 | 2003 (if (or (featurep '(not mule)) ;; Don't scan buffer if we are not muleized |
4623
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2004 (and |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2005 (not byte-compile-force-escape-quoted) |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2006 (save-excursion |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2007 (set-buffer byte-compile-inbuffer) |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2008 (goto-char (point-min)) |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2009 ;; Look for any non-Latin-1 literals or Unicode character |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2010 ;; escapes. Any such occurrences in a @#COUNT comment will lead |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2011 ;; to an escape-quoted coding cookie being inserted, but this is |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2012 ;; not true of ordinary comments. |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2013 (let ((non-latin-1-re |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2014 (concat "[^\000-\377]" |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2015 #r"\|\\u[0-9a-fA-F]\{4,4\}\|\\U[0-9a-fA-F]" |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2016 "\\{8,8\\}")) |
4623
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2017 (case-fold-search nil)) |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2018 (catch 'need-to-escape-quote |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2019 (while (re-search-forward non-latin-1-re nil t) |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2020 (skip-chars-backward "^;" (point-at-bol)) |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2021 (if (bolp) (throw 'need-to-escape-quote nil)) |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2022 (forward-line 1)) |
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2023 t))))) |
771 | 2024 (setq buffer-file-coding-system 'raw-text-unix) |
2025 (setq buffer-file-coding-system 'escape-quoted) | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2026 (pushnew '(featurep 'mule) byte-compile-checks-on-load) |
771 | 2027 (save-excursion |
2028 (set-buffer byte-compile-inbuffer) | |
2029 (setq byte-compile-dynamic nil | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2030 byte-compile-dynamic-docstrings nil)))) |
428 | 2031 |
2032 (defun byte-compile-output-file-form (form) | |
2033 ;; writes the given form to the output buffer, being careful of docstrings | |
2034 ;; in defun, defmacro, defvar, defconst and autoload because make-docfile is | |
2035 ;; so amazingly stupid. | |
2036 ;; defalias calls are output directly by byte-compile-file-form-defmumble; | |
2037 ;; it does not pay to first build the defalias in defmumble and then parse | |
2038 ;; it here. | |
4539
061e030e3270
Fix some bugs in load-history construction, built-in symbol file names.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4529
diff
changeset
|
2039 (if (and (memq (car-safe form) '(defun defmacro defvar defconst autoload |
061e030e3270
Fix some bugs in load-history construction, built-in symbol file names.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4529
diff
changeset
|
2040 custom-declare-variable)) |
428 | 2041 (stringp (nth 3 form))) |
2042 (byte-compile-output-docform nil nil '("\n(" 3 ")") form nil | |
4539
061e030e3270
Fix some bugs in load-history construction, built-in symbol file names.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4529
diff
changeset
|
2043 (memq (car form) |
061e030e3270
Fix some bugs in load-history construction, built-in symbol file names.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4529
diff
changeset
|
2044 '(autoload custom-declare-variable))) |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5548
diff
changeset
|
2045 (let* ((print-escape-newlines t) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5548
diff
changeset
|
2046 (print-length nil) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5548
diff
changeset
|
2047 (print-level nil) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5548
diff
changeset
|
2048 (print-readably t) ; print #[] for bytecode, 'x for (quote x) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5548
diff
changeset
|
2049 (print-gensym byte-compile-print-gensym) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5548
diff
changeset
|
2050 (print-continuous-numbering print-gensym) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5548
diff
changeset
|
2051 (print-circle t)) |
5391
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2052 (when byte-compile-output-preface |
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2053 (princ "\n(progn " byte-compile-outbuffer) |
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2054 (prin1 byte-compile-output-preface byte-compile-outbuffer)) |
428 | 2055 (princ "\n" byte-compile-outbuffer) |
2056 (prin1 form byte-compile-outbuffer) | |
5391
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2057 (when byte-compile-output-preface (princ ")" byte-compile-outbuffer)) |
428 | 2058 nil))) |
2059 | |
2060 (defun byte-compile-output-docform (preface name info form specindex quoted) | |
2061 "Print a form with a doc string. INFO is (prefix doc-index postfix). | |
2062 If PREFACE and NAME are non-nil, print them too, | |
2063 before INFO and the FORM but after the doc string itself. | |
2064 If SPECINDEX is non-nil, it is the index in FORM | |
2065 of the function bytecode string. In that case, | |
2066 we output that argument and the following argument (the constants vector) | |
2067 together, for lazy loading. | |
2068 QUOTED says that we have to put a quote before the | |
2069 list that represents a doc string reference. | |
2070 `autoload' needs that." | |
2071 ;; We need to examine byte-compile-dynamic-docstrings | |
2072 ;; in the input buffer (now current), not in the output buffer. | |
2073 (let ((dynamic-docstrings byte-compile-dynamic-docstrings)) | |
2074 (set-buffer | |
2075 (prog1 (current-buffer) | |
2076 (set-buffer byte-compile-outbuffer) | |
2077 (let (position) | |
2078 | |
2079 ;; Insert the doc string, and make it a comment with #@LENGTH. | |
2080 (and (>= (nth 1 info) 0) | |
2081 dynamic-docstrings | |
2082 (progn | |
2083 ;; Make the doc string start at beginning of line | |
2084 ;; for make-docfile's sake. | |
2085 (insert "\n") | |
2086 (setq position | |
2087 (byte-compile-output-as-comment | |
2088 (nth (nth 1 info) form) nil)) | |
2089 ;; If the doc string starts with * (a user variable), | |
2090 ;; negate POSITION. | |
2091 (if (and (stringp (nth (nth 1 info) form)) | |
2092 (> (length (nth (nth 1 info) form)) 0) | |
2093 (char= (aref (nth (nth 1 info) form) 0) ?*)) | |
2094 (setq position (- position))))) | |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5548
diff
changeset
|
2095 (byte-compile-flush-pending) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5548
diff
changeset
|
2096 (let* ((print-escape-newlines t) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5548
diff
changeset
|
2097 (print-readably t) ; print #[] for bytecode, 'x for (quote x) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5548
diff
changeset
|
2098 (print-gensym byte-compile-print-gensym) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5548
diff
changeset
|
2099 (print-continuous-numbering print-gensym) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5548
diff
changeset
|
2100 (print-circle t) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5548
diff
changeset
|
2101 (index 0)) |
5391
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2102 (when byte-compile-output-preface |
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2103 (princ "\n(progn " byte-compile-outbuffer) |
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2104 (prin1 byte-compile-output-preface byte-compile-outbuffer)) |
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2105 (if preface |
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2106 (progn |
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2107 (insert preface) |
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2108 (prin1 name byte-compile-outbuffer))) |
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2109 (insert (car info)) |
428 | 2110 (prin1 (car form) byte-compile-outbuffer) |
2111 (while (setq form (cdr form)) | |
2112 (setq index (1+ index)) | |
2113 (insert " ") | |
2114 (cond ((and (numberp specindex) (= index specindex)) | |
2115 (let ((position | |
2116 (byte-compile-output-as-comment | |
2117 (cons (car form) (nth 1 form)) | |
2118 t))) | |
2119 (princ (format "(#$ . %d) nil" position) | |
2120 byte-compile-outbuffer) | |
2121 (setq form (cdr form)) | |
2122 (setq index (1+ index)))) | |
2123 ((= index (nth 1 info)) | |
2124 (if position | |
2125 (princ (format (if quoted "'(#$ . %d)" "(#$ . %d)") | |
2126 position) | |
2127 byte-compile-outbuffer) | |
2128 (let ((print-escape-newlines nil)) | |
2129 (goto-char (prog1 (1+ (point)) | |
2130 (prin1 (car form) | |
2131 byte-compile-outbuffer))) | |
2132 (insert "\\\n") | |
2133 (goto-char (point-max))))) | |
2134 (t | |
2135 (prin1 (car form) byte-compile-outbuffer))))) | |
5391
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2136 (insert (nth 2 info)) |
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2137 (when byte-compile-output-preface |
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2138 (princ ")" byte-compile-outbuffer)))))) |
428 | 2139 nil) |
2140 | |
2141 (defun byte-compile-keep-pending (form &optional handler) | |
2142 (if (memq byte-optimize '(t source)) | |
2143 (setq form (byte-optimize-form form t))) | |
2144 (if handler | |
2145 (let ((for-effect t)) | |
2146 ;; To avoid consing up monstrously large forms at load time, we split | |
2147 ;; the output regularly. | |
2148 (and (memq (car-safe form) '(fset defalias define-function)) | |
2149 (nthcdr 300 byte-compile-output) | |
2150 (byte-compile-flush-pending)) | |
2151 (funcall handler form) | |
2152 (when for-effect | |
2153 (byte-compile-discard))) | |
2154 (byte-compile-form form t)) | |
2155 nil) | |
2156 | |
2157 (defun byte-compile-flush-pending () | |
2158 (if byte-compile-output | |
2159 (let ((form (byte-compile-out-toplevel t 'file))) | |
2160 (cond ((eq (car-safe form) 'progn) | |
4783
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4775
diff
changeset
|
2161 (mapc 'byte-compile-output-file-form (cdr form))) |
428 | 2162 (form |
2163 (byte-compile-output-file-form form))) | |
2164 (setq byte-compile-constants nil | |
2165 byte-compile-variables nil | |
2166 byte-compile-depth 0 | |
2167 byte-compile-maxdepth 0 | |
2168 byte-compile-output nil)))) | |
2169 | |
2170 (defun byte-compile-file-form (form) | |
2171 (let ((byte-compile-current-form nil) ; close over this for warnings. | |
5391
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2172 (byte-compile-output-preface nil) |
428 | 2173 handler) |
2174 (cond | |
2175 ((not (consp form)) | |
2176 (byte-compile-keep-pending form)) | |
2177 ((and (symbolp (car form)) | |
2178 (setq handler (get (car form) 'byte-hunk-handler))) | |
2179 (cond ((setq form (funcall handler form)) | |
2180 (byte-compile-flush-pending) | |
2181 (byte-compile-output-file-form form)))) | |
2182 ((eq form (setq form (macroexpand form byte-compile-macro-environment))) | |
2183 (byte-compile-keep-pending form)) | |
2184 (t | |
2185 (byte-compile-file-form form))))) | |
2186 | |
2187 ;; Functions and variables with doc strings must be output separately, | |
2188 ;; so make-docfile can recognize them. Most other things can be output | |
2189 ;; as byte-code. | |
2190 | |
2191 (put 'defsubst 'byte-hunk-handler 'byte-compile-file-form-defsubst) | |
2192 (defun byte-compile-file-form-defsubst (form) | |
2193 (cond ((assq (nth 1 form) byte-compile-unresolved-functions) | |
2194 (setq byte-compile-current-form (nth 1 form)) | |
2195 (byte-compile-warn "defsubst %s was used before it was defined" | |
2196 (nth 1 form)))) | |
2197 (byte-compile-file-form | |
2198 (macroexpand form byte-compile-macro-environment)) | |
2199 ;; Return nil so the form is not output twice. | |
2200 nil) | |
2201 | |
2202 (put 'autoload 'byte-hunk-handler 'byte-compile-file-form-autoload) | |
2203 (defun byte-compile-file-form-autoload (form) | |
2204 ;; | |
2205 ;; If this is an autoload of a macro, and all arguments are constants (that | |
2206 ;; is, there is no hairy computation going on here) then evaluate the form | |
2207 ;; at compile-time. This is so that we can make use of macros which we | |
2208 ;; have autoloaded from the file being compiled. Normal function autoloads | |
2209 ;; are not automatically evaluated at compile time, because there's not | |
2210 ;; much point to it (so why bother cluttering up the compile-time namespace.) | |
2211 ;; | |
2212 ;; If this is an autoload of a function, then record its definition in the | |
2213 ;; byte-compile-autoload-environment to suppress any `not known to be | |
2214 ;; defined' warnings at the end of this file (this only matters for | |
2215 ;; functions which are autoloaded and compiled in the same file, if the | |
2216 ;; autoload already exists in the compilation environment, we wouldn't have | |
2217 ;; warned anyway.) | |
2218 ;; | |
2219 (let* ((name (if (byte-compile-constp (nth 1 form)) | |
2220 (eval (nth 1 form)))) | |
2221 ;; In v19, the 5th arg to autoload can be t, nil, 'macro, or 'keymap. | |
2222 (macrop (and (byte-compile-constp (nth 5 form)) | |
2223 (memq (eval (nth 5 form)) '(t macro)))) | |
2224 ;; (functionp (and (byte-compile-constp (nth 5 form)) | |
2225 ;; (eq 'nil (eval (nth 5 form))))) | |
2226 ) | |
2227 (if (and macrop | |
2228 (let ((form form)) | |
2229 ;; all forms are constant | |
2230 (while (if (setq form (cdr form)) | |
2231 (byte-compile-constp (car form)))) | |
2232 (null form))) | |
440 | 2233 ;; eval the macro autoload into the compilation environment |
428 | 2234 (eval form)) |
2235 | |
2236 (if name | |
2237 (let ((old (assq name byte-compile-autoload-environment))) | |
2238 (cond (old | |
2239 (if (memq 'redefine byte-compile-warnings) | |
2240 (byte-compile-warn "multiple autoloads for %s" name)) | |
2241 (setcdr old form)) | |
2242 (t | |
2243 ;; We only use the names in the autoload environment, but | |
2244 ;; it might be useful to have the bodies some day. | |
2245 (setq byte-compile-autoload-environment | |
2246 (cons (cons name form) | |
2247 byte-compile-autoload-environment))))))) | |
2248 ;; | |
2249 ;; Now output the form. | |
2250 (if (stringp (nth 3 form)) | |
2251 form | |
2252 ;; No doc string, so we can compile this as a normal form. | |
2253 (byte-compile-keep-pending form 'byte-compile-normal-call))) | |
2254 | |
442 | 2255 (put 'defvar 'byte-hunk-handler 'byte-compile-file-form-defvar-or-defconst) |
2256 (put 'defconst 'byte-hunk-handler 'byte-compile-file-form-defvar-or-defconst) | |
2257 (defun byte-compile-file-form-defvar-or-defconst (form) | |
2258 ;; (defvar|defconst VAR [VALUE [DOCSTRING]]) | |
428 | 2259 (if (> (length form) 4) |
442 | 2260 (byte-compile-warn |
2261 "%s %s called with %d arguments, but accepts only %s" | |
2262 (car form) (nth 1 form) (length (cdr form)) 3)) | |
428 | 2263 (if (and (> (length form) 3) (not (stringp (nth 3 form)))) |
2264 (byte-compile-warn "Third arg to %s %s is not a string: %s" | |
2265 (car form) (nth 1 form) (nth 3 form))) | |
2266 (if (null (nth 3 form)) | |
2267 ;; Since there is no doc string, we can compile this as a normal form, | |
2268 ;; and not do a file-boundary. | |
2269 (byte-compile-keep-pending form) | |
2270 (if (memq 'free-vars byte-compile-warnings) | |
2271 (setq byte-compile-bound-variables | |
2272 (cons (cons (nth 1 form) byte-compile-global-bit) | |
2273 byte-compile-bound-variables))) | |
2274 (cond ((consp (nth 2 form)) | |
2275 (setq form (copy-sequence form)) | |
2276 (setcar (cdr (cdr form)) | |
2277 (byte-compile-top-level (nth 2 form) nil 'file)))) | |
2278 | |
2279 ;; The following turns out not to be necessary, since we emit a call to | |
2280 ;; defvar, which can hack Vfile_domain by itself! | |
2281 ;; | |
2282 ;; If a file domain has been set, emit (put 'VAR 'variable-domain ...) | |
2283 ;; after this defvar. | |
2284 ; (if byte-compile-file-domain | |
2285 ; (progn | |
2286 ; ;; Actually, this will emit the (put ...) before the (defvar ...) | |
2287 ; ;; but I don't think that can matter in this case. | |
2288 ; (byte-compile-keep-pending | |
2289 ; (list 'put (list 'quote (nth 1 form)) ''variable-domain | |
2290 ; (list 'quote byte-compile-file-domain))))) | |
2291 form)) | |
2292 | |
2293 (put 'require 'byte-hunk-handler 'byte-compile-file-form-eval-boundary) | |
2294 (defun byte-compile-file-form-eval-boundary (form) | |
2295 (eval form) | |
2296 (byte-compile-keep-pending form 'byte-compile-normal-call)) | |
2297 | |
4686
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2298 ;; XEmacs change: be careful about multiple values with these three forms. |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2299 (put 'progn 'byte-hunk-handler |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2300 #'(lambda (form) |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2301 (mapc 'byte-compile-file-form (cdr form)) |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2302 ;; Return nil so the forms are not output twice. |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2303 nil)) |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2304 |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2305 (put 'prog1 'byte-hunk-handler |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2306 #'(lambda (form) |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2307 (when (first form) |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2308 (byte-compile-file-form `(or ,(first form) nil)) |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2309 (mapc 'byte-compile-file-form (cdr form)) |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2310 nil))) |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2311 |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2312 (put 'prog2 'byte-hunk-handler |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2313 #'(lambda (form) |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2314 (when (first form) |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2315 (byte-compile-file-form (first form)) |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2316 (when (second form) |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2317 (setq form (cdr form)) |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2318 (byte-compile-file-form `(or ,(first form) nil)) |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2319 (mapc 'byte-compile-file-form (cdr form)) |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2320 nil)))) |
428 | 2321 |
2322 ;; This handler is not necessary, but it makes the output from dont-compile | |
2323 ;; and similar macros cleaner. | |
2324 (put 'eval 'byte-hunk-handler 'byte-compile-file-form-eval) | |
2325 (defun byte-compile-file-form-eval (form) | |
2326 (if (eq (car-safe (nth 1 form)) 'quote) | |
2327 (nth 1 (nth 1 form)) | |
2328 (byte-compile-keep-pending form))) | |
2329 | |
2330 (put 'defun 'byte-hunk-handler 'byte-compile-file-form-defun) | |
2331 (defun byte-compile-file-form-defun (form) | |
2332 (byte-compile-file-form-defmumble form nil)) | |
2333 | |
2334 (put 'defmacro 'byte-hunk-handler 'byte-compile-file-form-defmacro) | |
2335 (defun byte-compile-file-form-defmacro (form) | |
2336 (byte-compile-file-form-defmumble form t)) | |
2337 | |
2338 (defun byte-compile-file-form-defmumble (form macrop) | |
2339 (let* ((name (car (cdr form))) | |
2340 (this-kind (if macrop 'byte-compile-macro-environment | |
2341 'byte-compile-function-environment)) | |
2342 (that-kind (if macrop 'byte-compile-function-environment | |
2343 'byte-compile-macro-environment)) | |
2344 (this-one (assq name (symbol-value this-kind))) | |
2345 (that-one (assq name (symbol-value that-kind))) | |
2346 (byte-compile-free-references nil) | |
2347 (byte-compile-free-assignments nil)) | |
2348 | |
2349 ;; When a function or macro is defined, add it to the call tree so that | |
2350 ;; we can tell when functions are not used. | |
2351 (if byte-compile-generate-call-tree | |
2352 (or (assq name byte-compile-call-tree) | |
2353 (setq byte-compile-call-tree | |
2354 (cons (list name nil nil) byte-compile-call-tree)))) | |
2355 | |
2356 (setq byte-compile-current-form name) ; for warnings | |
2357 (when (memq 'redefine byte-compile-warnings) | |
2358 (byte-compile-arglist-warn form macrop)) | |
2359 (defvar filename) ; #### filename used free | |
2360 (when byte-compile-verbose | |
2361 (message "Compiling %s... (%s)" | |
2362 (if filename (file-name-nondirectory filename) "") | |
2363 (nth 1 form))) | |
2364 (cond (that-one | |
2365 (when (and (memq 'redefine byte-compile-warnings) | |
2366 ;; hack hack: don't warn when compiling the stubs in | |
2367 ;; bytecomp-runtime... | |
2368 (not (assq (nth 1 form) | |
2369 byte-compile-initial-macro-environment))) | |
2370 (byte-compile-warn | |
2371 "%s defined multiple times, as both function and macro" | |
2372 (nth 1 form))) | |
2373 (setcdr that-one nil)) | |
2374 (this-one | |
2375 (when (and (memq 'redefine byte-compile-warnings) | |
2376 ;; hack: don't warn when compiling the magic internal | |
2377 ;; byte-compiler macros in bytecomp-runtime.el... | |
2378 (not (assq (nth 1 form) | |
2379 byte-compile-initial-macro-environment))) | |
2380 (byte-compile-warn "%s %s defined multiple times in this file" | |
2381 (if macrop "macro" "function") | |
2382 (nth 1 form)))) | |
2383 ((and (fboundp name) | |
2384 (or (subrp (symbol-function name)) | |
2385 (eq (car-safe (symbol-function name)) | |
2386 (if macrop 'lambda 'macro)))) | |
2387 (if (memq 'redefine byte-compile-warnings) | |
2388 (byte-compile-warn "%s %s being redefined as a %s" | |
2389 (if (subrp (symbol-function name)) | |
2390 "subr" | |
2391 (if macrop "function" "macro")) | |
2392 (nth 1 form) | |
2393 (if macrop "macro" "function"))) | |
2394 ;; shadow existing definition | |
2395 (set this-kind | |
2396 (cons (cons name nil) (symbol-value this-kind))))) | |
2397 (let ((body (nthcdr 3 form))) | |
2398 (if (and (stringp (car body)) | |
2399 (symbolp (car-safe (cdr-safe body))) | |
2400 (car-safe (cdr-safe body)) | |
2401 (stringp (car-safe (cdr-safe (cdr-safe body))))) | |
2402 (byte-compile-warn "Probable `\"' without `\\' in doc string of %s" | |
2403 (nth 1 form)))) | |
5506
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2404 |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2405 ;; Generate code for declarations in macro definitions. |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2406 ;; Remove declarations from the body of the macro definition. |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2407 (when macrop |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2408 (let ((byte-compile-defmacro-body (nthcdr 3 form))) |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2409 (if (stringp (car byte-compile-defmacro-body)) |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2410 (setq byte-compile-defmacro-body (nthcdr 4 form))) |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2411 (when (and (consp byte-compile-defmacro-body) |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2412 (eq 'declare (car-safe (car byte-compile-defmacro-body)))) |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2413 (if (eq 'declare (car-safe (car-safe |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2414 (cdr byte-compile-defmacro-body)))) |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2415 (byte-compile-warn "Multiple macro-specific `declare' calls \ |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2416 not supported by XEmacs.")) |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2417 (setq byte-compile-output-preface |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2418 (byte-compile-top-level |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2419 `(progn (and macro-declaration-function |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2420 (funcall macro-declaration-function |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2421 ',name |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2422 ',(car byte-compile-defmacro-body))) |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2423 ,byte-compile-output-preface) t 'file))))) |
428 | 2424 (let* ((new-one (byte-compile-lambda (cons 'lambda (nthcdr 2 form)))) |
5106
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2425 (code (byte-compile-byte-code-maker new-one)) |
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2426 (docform-info |
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2427 (cond ((atom code) ; compiled-function-p |
5391
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2428 (if macrop '(" '(macro . #[" 4 "]))") '(" #[" 4 "])"))) |
5106
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2429 ((eq (car code) 'quote) |
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2430 (setq code new-one) |
5391
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2431 (if macrop '(" '(macro " 2 "))") '(" '(" 2 "))"))) |
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2432 ((if macrop '(" (cons 'macro (" 5 ")))") '(" (" 5 "))")))))) |
428 | 2433 (if this-one |
2434 (setcdr this-one new-one) | |
2435 (set this-kind | |
2436 (cons (cons name new-one) (symbol-value this-kind)))) | |
2437 (if (and (stringp (nth 3 form)) | |
2438 (eq 'quote (car-safe code)) | |
2439 (eq 'lambda (car-safe (nth 1 code)))) | |
2440 (cons (car form) | |
5106
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2441 (cons name (cdr (nth 1 code)))) |
428 | 2442 (byte-compile-flush-pending) |
2443 (if (not (stringp (nth 3 form))) | |
5106
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2444 ;; No doc string. Provide -1 as the "doc string index" so that |
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2445 ;; no element will be treated as a doc string by |
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2446 ;; byte-compile-output-doc-form. |
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2447 (setq docform-info (list (first docform-info) -1 |
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2448 (third docform-info)))) |
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2449 (byte-compile-output-docform |
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2450 "\n(defalias '" |
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2451 name |
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2452 docform-info |
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2453 ;; The result of byte-compile-byte-code-maker is either a |
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2454 ;; compiled-function object, or a list of some kind. If it's not a |
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2455 ;; cons, we must coerce it into a list of the elements to be |
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2456 ;; printed to the file. |
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2457 (if (consp code) |
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2458 code |
5391
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2459 (list* (compiled-function-arglist code) |
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2460 (compiled-function-instructions code) |
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2461 (compiled-function-constants code) |
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2462 (compiled-function-stack-depth code) |
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2463 (compiled-function-doc-string code) |
5106
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2464 (if (commandp code) |
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2465 (list (nth 1 (compiled-function-interactive code)))))) |
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2466 (and (atom code) byte-compile-dynamic |
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2467 1) |
428 | 2468 nil)) |
5106
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2469 nil))) |
428 | 2470 |
2471 ;; Print Lisp object EXP in the output file, inside a comment, | |
2472 ;; and return the file position it will have. | |
2473 ;; If QUOTED is non-nil, print with quoting; otherwise, print without quoting. | |
2474 (defun byte-compile-output-as-comment (exp quoted) | |
2475 (let ((position (point))) | |
2476 (set-buffer | |
2477 (prog1 (current-buffer) | |
2478 (set-buffer byte-compile-outbuffer) | |
2479 | |
2480 ;; Insert EXP, and make it a comment with #@LENGTH. | |
2481 (insert " ") | |
2482 (if quoted | |
2483 (prin1 exp byte-compile-outbuffer) | |
2484 (princ exp byte-compile-outbuffer)) | |
2485 (goto-char position) | |
2486 ;; Quote certain special characters as needed. | |
2487 ;; get_doc_string in doc.c does the unquoting. | |
2488 (while (search-forward "\^A" nil t) | |
2489 (replace-match "\^A\^A" t t)) | |
2490 (goto-char position) | |
2491 (while (search-forward "\000" nil t) | |
2492 (replace-match "\^A0" t t)) | |
2493 (goto-char position) | |
2494 (while (search-forward "\037" nil t) | |
2495 (replace-match "\^A_" t t)) | |
2496 (goto-char (point-max)) | |
2497 (insert "\037") | |
2498 (goto-char position) | |
2499 (insert "#@" (format "%d" (- (point-max) position))) | |
2500 | |
2501 ;; Save the file position of the object. | |
2502 ;; Note we should add 1 to skip the space | |
2503 ;; that we inserted before the actual doc string, | |
2504 ;; and subtract 1 to convert from an 1-origin Emacs position | |
2505 ;; to a file position; they cancel. | |
2506 (setq position (point)) | |
2507 (goto-char (point-max)))) | |
2508 position)) | |
2509 | |
2510 | |
2511 | |
2512 ;; The `domain' declaration. This is legal only at top-level in a file, and | |
2513 ;; should generally be the first form in the file. It is not legal inside | |
2514 ;; function bodies. | |
2515 | |
2516 (put 'domain 'byte-hunk-handler 'byte-compile-file-form-domain) | |
2517 (defun byte-compile-file-form-domain (form) | |
2518 (if (not (null (cdr (cdr form)))) | |
2519 (byte-compile-warn "domain used with too many arguments: %s" form)) | |
2520 (let ((domain (nth 1 form))) | |
2521 (or (null domain) | |
2522 (stringp domain) | |
2523 (progn | |
2524 (byte-compile-warn | |
2525 "argument to `domain' declaration must be a literal string: %s" | |
2526 form) | |
2527 (setq domain nil))) | |
2528 (setq byte-compile-file-domain domain)) | |
2529 (byte-compile-keep-pending form 'byte-compile-normal-call)) | |
2530 | |
2531 (defun byte-compile-domain (form) | |
2532 (byte-compile-warn "The `domain' declaration is legal only at top-level: %s" | |
2533 (let ((print-escape-newlines t) | |
2534 (print-level 4) | |
2535 (print-length 4)) | |
2536 (prin1-to-string form))) | |
2537 (byte-compile-normal-call | |
2538 (list 'signal ''error | |
2539 (list 'quote (list "`domain' used inside a function" form))))) | |
2540 | |
2541 ;; This is part of bytecomp.el in 19.35: | |
2542 (put 'custom-declare-variable 'byte-hunk-handler | |
2543 'byte-compile-file-form-custom-declare-variable) | |
2544 (defun byte-compile-file-form-custom-declare-variable (form) | |
4289 | 2545 ;; XEmacs change; our implementation byte compiles and gives warnings |
2546 ;; about the default value code, which GNU's doesn't. | |
2547 (let* ((quoted-default (car-safe (cdr-safe (cdr-safe form)))) | |
2548 (to-examine (car-safe (cdr-safe quoted-default)))) | |
2549 (if (memq 'free-vars byte-compile-warnings) | |
2550 (setq byte-compile-bound-variables | |
2551 (cons (cons (nth 1 (nth 1 form)) | |
2552 byte-compile-global-bit) | |
2553 byte-compile-bound-variables))) | |
2554 ;; Byte compile anything that smells like a lambda. I initially | |
2555 ;; considered limiting it to the :initialize, :set and :get args, but | |
2556 ;; that's not amazingly forward-compatible, and anyone expecting other | |
2557 ;; things to be stored as data, not code, is unrealistic. | |
2558 (loop | |
2559 for entry in-ref (nthcdr 4 form) | |
2560 do (cond ((and (eq 'function (car-safe entry)) | |
2561 (consp (car-safe (cdr-safe entry)))) | |
2562 (setf entry (copy-sequence entry)) | |
2563 (setcar (cdr entry) (byte-compile-lambda (car (cdr entry))))) | |
2564 ((and (eq 'lambda (car-safe entry))) | |
2565 (setf entry (byte-compile-lambda entry))))) | |
2566 ;; Byte compile the default value, as we do for defvar. | |
2567 (when (consp (cdr-safe to-examine)) | |
2568 (setq form (copy-sequence form)) | |
2569 (setcdr (third form) | |
2570 (list (byte-compile-top-level to-examine nil 'file))) | |
2571 ;; And save a value to be examined in the custom UI, if that differs | |
2572 ;; from the init value. | |
2573 (unless (equal to-examine (car-safe (cdr (third form)))) | |
4304 | 2574 (setcdr (third form) |
2575 (list (byte-compile-top-level | |
2576 ;; This is ugly. custom-declare-variable errors if | |
2577 ;; it's passed a keyword it doesn't know about, and | |
2578 ;; so to make this code run on 21.4, we add code to | |
2579 ;; modify the standard-value property to the | |
2580 ;; byte-compiled value for DEFAULT. | |
2581 `(prog2 (put ,(second form) 'standard-value | |
2582 '(,to-examine)) | |
2583 ,to-examine) | |
2584 nil 'file))))) | |
4289 | 2585 form)) |
428 | 2586 |
2587 ;;;###autoload | |
2588 (defun byte-compile (form) | |
2589 "If FORM is a symbol, byte-compile its function definition. | |
2590 If FORM is a lambda or a macro, byte-compile it as a function." | |
2591 (displaying-byte-compile-warnings | |
2592 (byte-compile-close-variables | |
2593 (let* ((fun (if (symbolp form) | |
2594 (and (fboundp form) (symbol-function form)) | |
2595 form)) | |
2596 (macro (eq (car-safe fun) 'macro))) | |
2597 (if macro | |
2598 (setq fun (cdr fun))) | |
2599 (cond ((eq (car-safe fun) 'lambda) | |
2600 (setq fun (if macro | |
2601 (cons 'macro (byte-compile-lambda fun)) | |
2602 (byte-compile-lambda fun))) | |
2603 (if (symbolp form) | |
2604 (defalias form fun) | |
2605 fun))))))) | |
2606 | |
2607 ;;;###autoload | |
2608 (defun byte-compile-sexp (sexp &optional msg) | |
2609 "Compile and return SEXP." | |
2610 (displaying-byte-compile-warnings | |
2611 (byte-compile-close-variables | |
2612 (prog1 | |
2613 (byte-compile-top-level sexp) | |
2614 (byte-compile-warn-about-unresolved-functions msg))))) | |
2615 | |
2616 ;; Given a function made by byte-compile-lambda, make a form which produces it. | |
2617 (defun byte-compile-byte-code-maker (fun) | |
2618 (cond | |
2619 ;; ## atom is faster than compiled-func-p. | |
2620 ((atom fun) ; compiled-function-p | |
2621 fun) | |
2622 ;; b-c-lambda didn't produce a compiled-function, so it must be a trivial | |
2623 ;; function. | |
2624 ((let (tmp) | |
2625 (if (and (setq tmp (assq 'byte-code (cdr-safe (cdr fun)))) | |
2626 (null (cdr (memq tmp fun)))) | |
2627 ;; Generate a make-byte-code call. | |
2628 (let* ((interactive (assq 'interactive (cdr (cdr fun))))) | |
2629 (nconc (list 'make-byte-code | |
2630 (list 'quote (nth 1 fun)) ;arglist | |
2631 (nth 1 tmp) ;instructions | |
2632 (nth 2 tmp) ;constants | |
2633 (nth 3 tmp)) ;stack-depth | |
2634 (cond ((stringp (nth 2 fun)) | |
2635 (list (nth 2 fun))) ;docstring | |
2636 (interactive | |
2637 (list nil))) | |
2638 (cond (interactive | |
2639 (list (if (or (null (nth 1 interactive)) | |
2640 (stringp (nth 1 interactive))) | |
2641 (nth 1 interactive) | |
2642 ;; Interactive spec is a list or a variable | |
2643 ;; (if it is correct). | |
2644 (list 'quote (nth 1 interactive)))))))) | |
2645 ;; a non-compiled function (probably trivial) | |
2646 (list 'quote fun)))))) | |
2647 | |
2648 ;; Byte-compile a lambda-expression and return a valid function. | |
2649 ;; The value is usually a compiled function but may be the original | |
2650 ;; lambda-expression. | |
2651 (defun byte-compile-lambda (fun) | |
2652 (or (eq 'lambda (car-safe fun)) | |
2653 (error "not a lambda -- %s" (prin1-to-string fun))) | |
2654 (let* ((arglist (nth 1 fun)) | |
2655 (byte-compile-bound-variables | |
2656 (let ((new-bindings | |
2657 (mapcar #'(lambda (x) (cons x byte-compile-arglist-bit)) | |
2658 (and (memq 'free-vars byte-compile-warnings) | |
2659 (delq '&rest (delq '&optional | |
2660 (copy-sequence arglist))))))) | |
2661 (nconc new-bindings | |
2662 (cons 'new-scope byte-compile-bound-variables)))) | |
2663 (body (cdr (cdr fun))) | |
2664 (doc (if (stringp (car body)) | |
2665 (prog1 (car body) | |
1548 | 2666 ;; Discard the doc string |
2667 ;; only if it is not the only element of the body. | |
2668 (if (cdr body) | |
2669 (setq body (cdr body)))))) | |
4639
7757334005ae
bytecomp.el: always check code in (interactive SEXP) for sanity
Aidan Kehoe <kehoea@parhasard.net>
parents:
4623
diff
changeset
|
2670 (int (assq 'interactive body)) compiled-int) |
428 | 2671 (dolist (arg arglist) |
2672 (cond ((not (symbolp arg)) | |
2673 (byte-compile-warn "non-symbol in arglist: %S" arg)) | |
2674 ((byte-compile-constant-symbol-p arg) | |
2675 (byte-compile-warn "constant symbol in arglist: %s" arg)) | |
2676 ((and (char= ?\& (aref (symbol-name arg) 0)) | |
2677 (not (eq arg '&optional)) | |
2678 (not (eq arg '&rest))) | |
2679 (byte-compile-warn "unrecognized `&' keyword in arglist: %s" | |
2680 arg)))) | |
2681 (cond (int | |
2682 ;; Skip (interactive) if it is in front (the most usual location). | |
2683 (if (eq int (car body)) | |
2684 (setq body (cdr body))) | |
2685 (cond ((consp (cdr int)) | |
2686 (if (cdr (cdr int)) | |
2687 (byte-compile-warn "malformed interactive spec: %s" | |
2688 (prin1-to-string int))) | |
4639
7757334005ae
bytecomp.el: always check code in (interactive SEXP) for sanity
Aidan Kehoe <kehoea@parhasard.net>
parents:
4623
diff
changeset
|
2689 ;; If the interactive spec is a call to `list', don't |
7757334005ae
bytecomp.el: always check code in (interactive SEXP) for sanity
Aidan Kehoe <kehoea@parhasard.net>
parents:
4623
diff
changeset
|
2690 ;; store the compiled form, because `call-interactively' |
7757334005ae
bytecomp.el: always check code in (interactive SEXP) for sanity
Aidan Kehoe <kehoea@parhasard.net>
parents:
4623
diff
changeset
|
2691 ;; looks at the args of `list' and treats certain |
7757334005ae
bytecomp.el: always check code in (interactive SEXP) for sanity
Aidan Kehoe <kehoea@parhasard.net>
parents:
4623
diff
changeset
|
2692 ;; functions specially. Compiling it is nonetheless |
7757334005ae
bytecomp.el: always check code in (interactive SEXP) for sanity
Aidan Kehoe <kehoea@parhasard.net>
parents:
4623
diff
changeset
|
2693 ;; useful for warnings. |
428 | 2694 (let ((form (nth 1 int))) |
2695 (while (or (eq (car-safe form) 'let) | |
2696 (eq (car-safe form) 'let*) | |
2697 (eq (car-safe form) 'save-excursion)) | |
2698 (while (consp (cdr form)) | |
2699 (setq form (cdr form))) | |
2700 (setq form (car form))) | |
4639
7757334005ae
bytecomp.el: always check code in (interactive SEXP) for sanity
Aidan Kehoe <kehoea@parhasard.net>
parents:
4623
diff
changeset
|
2701 (setq compiled-int |
7757334005ae
bytecomp.el: always check code in (interactive SEXP) for sanity
Aidan Kehoe <kehoea@parhasard.net>
parents:
4623
diff
changeset
|
2702 (byte-compile-top-level (nth 1 int))) |
428 | 2703 (or (eq (car-safe form) 'list) |
4639
7757334005ae
bytecomp.el: always check code in (interactive SEXP) for sanity
Aidan Kehoe <kehoea@parhasard.net>
parents:
4623
diff
changeset
|
2704 (setq int (list 'interactive compiled-int))))) |
428 | 2705 ((cdr int) |
2706 (byte-compile-warn "malformed interactive spec: %s" | |
2707 (prin1-to-string int)))))) | |
2708 (let ((compiled (byte-compile-top-level (cons 'progn body) nil 'lambda))) | |
2709 (if (memq 'unused-vars byte-compile-warnings) | |
2710 ;; done compiling in this scope, warn now. | |
2711 (byte-compile-warn-about-unused-variables)) | |
2712 (if (eq 'byte-code (car-safe compiled)) | |
2713 (apply 'make-byte-code | |
2714 (append (list arglist) | |
2715 ;; byte-string, constants-vector, stack depth | |
2716 (cdr compiled) | |
2717 ;; optionally, the doc string. | |
2718 (if (or doc int) | |
2719 (list doc)) | |
2720 ;; optionally, the interactive spec. | |
2721 (if int | |
2722 (list (nth 1 int))))) | |
2723 (setq compiled | |
2724 (nconc (if int (list int)) | |
2725 (cond ((eq (car-safe compiled) 'progn) (cdr compiled)) | |
2726 (compiled (list compiled))))) | |
2727 (nconc (list 'lambda arglist) | |
2728 (if (or doc (stringp (car compiled))) | |
2729 (cons doc (cond (compiled) | |
2730 (body (list nil)))) | |
2731 compiled)))))) | |
2732 | |
2733 (defun byte-compile-constants-vector () | |
2734 ;; Builds the constants-vector from the current variables and constants. | |
2735 ;; This modifies the constants from (const . nil) to (const . offset). | |
2736 ;; To keep the byte-codes to look up the vector as short as possible: | |
2737 ;; First 6 elements are vars, as there are one-byte varref codes for those. | |
2738 ;; Next up to byte-constant-limit are constants, still with one-byte codes. | |
2739 ;; Next variables again, to get 2-byte codes for variable lookup. | |
2740 ;; The rest of the constants and variables need 3-byte byte-codes. | |
2741 (let* ((i -1) | |
2742 (rest (nreverse byte-compile-variables)) ; nreverse because the first | |
2743 (other (nreverse byte-compile-constants)) ; vars often are used most. | |
2744 ret tmp | |
2745 (limits '(5 ; Use the 1-byte varref codes, | |
2746 63 ; 1-constlim ; 1-byte byte-constant codes, | |
2747 255 ; 2-byte varref codes, | |
2748 65535)) ; 3-byte codes for the rest. | |
2749 limit) | |
2750 (while (or rest other) | |
2751 (setq limit (car limits)) | |
2752 (while (and rest (not (eq i limit))) | |
2753 (if (setq tmp (assq (car (car rest)) ret)) | |
2754 (setcdr (car rest) (cdr tmp)) | |
2755 (setcdr (car rest) (setq i (1+ i))) | |
2756 (setq ret (cons (car rest) ret))) | |
2757 (setq rest (cdr rest))) | |
2758 (setq limits (cdr limits) | |
2759 rest (prog1 other | |
2760 (setq other rest)))) | |
2761 (apply 'vector (nreverse (mapcar 'car ret))))) | |
2762 | |
2763 ;; Given an expression FORM, compile it and return an equivalent byte-code | |
2764 ;; expression (a call to the function byte-code). | |
2765 (defun byte-compile-top-level (form &optional for-effect output-type) | |
2766 ;; OUTPUT-TYPE advises about how form is expected to be used: | |
2767 ;; 'eval or nil -> a single form, | |
2768 ;; 'progn or t -> a list of forms, | |
2769 ;; 'lambda -> body of a lambda, | |
2770 ;; 'file -> used at file-level. | |
2771 (let ((byte-compile-constants nil) | |
2772 (byte-compile-variables nil) | |
2773 (byte-compile-tag-number 0) | |
2774 (byte-compile-depth 0) | |
2775 (byte-compile-maxdepth 0) | |
2776 (byte-compile-output nil)) | |
2777 (if (memq byte-optimize '(t source)) | |
2778 (setq form (byte-optimize-form form for-effect))) | |
2779 (while (and (eq (car-safe form) 'progn) (null (cdr (cdr form)))) | |
2780 (setq form (nth 1 form))) | |
2781 (if (and (eq 'byte-code (car-safe form)) | |
2782 (not (memq byte-optimize '(t byte))) | |
2783 (stringp (nth 1 form)) | |
2784 (vectorp (nth 2 form)) | |
2785 (natnump (nth 3 form))) | |
2786 form | |
2787 (byte-compile-form form for-effect) | |
2788 (byte-compile-out-toplevel for-effect output-type)))) | |
2789 | |
2790 (defun byte-compile-out-toplevel (&optional for-effect output-type) | |
2791 (if for-effect | |
2792 ;; The stack is empty. Push a value to be returned from (byte-code ..). | |
2793 (if (eq (car (car byte-compile-output)) 'byte-discard) | |
2794 (setq byte-compile-output (cdr byte-compile-output)) | |
2795 (byte-compile-push-constant | |
2796 ;; Push any constant - preferably one which already is used, and | |
2797 ;; a number or symbol - ie not some big sequence. The return value | |
2798 ;; isn't returned, but it would be a shame if some textually large | |
2799 ;; constant was not optimized away because we chose to return it. | |
2800 (and (not (assq nil byte-compile-constants)) ; Nil is often there. | |
2801 (let ((tmp (reverse byte-compile-constants))) | |
2802 (while (and tmp (not (or (symbolp (car (car tmp))) | |
2803 (numberp (car (car tmp)))))) | |
2804 (setq tmp (cdr tmp))) | |
2805 (car (car tmp))))))) | |
2806 (byte-compile-out 'byte-return 0) | |
2807 (setq byte-compile-output (nreverse byte-compile-output)) | |
2808 (if (memq byte-optimize '(t byte)) | |
2809 (setq byte-compile-output | |
2810 (byte-optimize-lapcode byte-compile-output for-effect))) | |
2811 | |
2812 ;; Decompile trivial functions: | |
2813 ;; only constants and variables, or a single funcall except in lambdas. | |
2814 ;; Except for Lisp_Compiled objects, forms like (foo "hi") | |
2815 ;; are still quicker than (byte-code "..." [foo "hi"] 2). | |
2816 ;; Note that even (quote foo) must be parsed just as any subr by the | |
2817 ;; interpreter, so quote should be compiled into byte-code in some contexts. | |
2818 ;; What to leave uncompiled: | |
2819 ;; lambda -> never. we used to leave it uncompiled if the body was | |
2820 ;; a single atom, but that causes confusion if the docstring | |
2821 ;; uses the (file . pos) syntax. Besides, now that we have | |
2822 ;; the Lisp_Compiled type, the compiled form is faster. | |
2823 ;; eval -> atom, quote or (function atom atom atom) | |
2824 ;; progn -> as <<same-as-eval>> or (progn <<same-as-eval>> atom) | |
2825 ;; file -> as progn, but takes both quotes and atoms, and longer forms. | |
2826 (let (rest | |
2827 (maycall (not (eq output-type 'lambda))) ; t if we may make a funcall. | |
2828 tmp body) | |
2829 (cond | |
2830 ;; #### This should be split out into byte-compile-nontrivial-function-p. | |
2831 ((or (eq output-type 'lambda) | |
2832 (nthcdr (if (eq output-type 'file) 50 8) byte-compile-output) | |
2833 (assq 'TAG byte-compile-output) ; Not necessary, but speeds up a bit. | |
2834 (not (setq tmp (assq 'byte-return byte-compile-output))) | |
2835 (progn | |
2836 (setq rest (nreverse | |
2837 (cdr (memq tmp (reverse byte-compile-output))))) | |
2838 (while (cond | |
2839 ((memq (car (car rest)) '(byte-varref byte-constant)) | |
2840 (setq tmp (car (cdr (car rest)))) | |
2841 (if (if (eq (car (car rest)) 'byte-constant) | |
2842 (or (consp tmp) | |
2843 (and (symbolp tmp) | |
2844 (not (byte-compile-constant-symbol-p tmp))))) | |
2845 (if maycall | |
2846 (setq body (cons (list 'quote tmp) body))) | |
2847 (setq body (cons tmp body)))) | |
2848 ((and maycall | |
2849 ;; Allow a funcall if at most one atom follows it. | |
2850 (null (nthcdr 3 rest)) | |
5503
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
2851 (setq tmp (get (car (car rest)) 'byte-opcode-invert)) |
428 | 2852 (or (null (cdr rest)) |
2853 (and (memq output-type '(file progn t)) | |
2854 (cdr (cdr rest)) | |
2855 (eq (car (nth 1 rest)) 'byte-discard) | |
2856 (progn (setq rest (cdr rest)) t)))) | |
2857 (setq maycall nil) ; Only allow one real function call. | |
2858 (setq body (nreverse body)) | |
2859 (setq body (list | |
2860 (if (and (eq tmp 'funcall) | |
2861 (eq (car-safe (car body)) 'quote)) | |
2862 (cons (nth 1 (car body)) (cdr body)) | |
2863 (cons tmp body)))) | |
2864 (or (eq output-type 'file) | |
2865 (not (delq nil (mapcar 'consp (cdr (car body)))))))) | |
2866 (setq rest (cdr rest))) | |
2867 rest)) | |
2868 (let ((byte-compile-vector (byte-compile-constants-vector))) | |
2869 (list 'byte-code (byte-compile-lapcode byte-compile-output) | |
2870 byte-compile-vector byte-compile-maxdepth))) | |
2871 ;; it's a trivial function | |
2872 ((cdr body) (cons 'progn (nreverse body))) | |
2873 ((car body))))) | |
2874 | |
2875 ;; Given BODY, compile it and return a new body. | |
2876 (defun byte-compile-top-level-body (body &optional for-effect) | |
2877 (setq body (byte-compile-top-level (cons 'progn body) for-effect t)) | |
2878 (cond ((eq (car-safe body) 'progn) | |
2879 (cdr body)) | |
2880 (body | |
2881 (list body)))) | |
2882 | |
2883 ;; This is the recursive entry point for compiling each subform of an | |
2884 ;; expression. | |
2885 ;; If for-effect is non-nil, byte-compile-form will output a byte-discard | |
2886 ;; before terminating (ie. no value will be left on the stack). | |
2887 ;; A byte-compile handler may, when for-effect is non-nil, choose output code | |
2888 ;; which does not leave a value on the stack, and then set for-effect to nil | |
2889 ;; (to prevent byte-compile-form from outputting the byte-discard). | |
2890 ;; If a handler wants to call another handler, it should do so via | |
2891 ;; byte-compile-form, or take extreme care to handle for-effect correctly. | |
2892 ;; (Use byte-compile-form-do-effect to reset the for-effect flag too.) | |
2893 ;; | |
2894 (defun byte-compile-form (form &optional for-effect) | |
2895 (setq form (macroexpand form byte-compile-macro-environment)) | |
2896 (cond ((not (consp form)) | |
2897 (cond ((or (not (symbolp form)) | |
2898 (byte-compile-constant-symbol-p form)) | |
2899 (byte-compile-constant form)) | |
2900 ((and for-effect byte-compile-delete-errors) | |
2901 (setq for-effect nil)) | |
2902 (t (byte-compile-variable-ref 'byte-varref form)))) | |
2903 ((symbolp (car form)) | |
2904 (let* ((fn (car form)) | |
2905 (handler (get fn 'byte-compile))) | |
2906 (if (memq fn '(t nil)) | |
2907 (byte-compile-warn "%s called as a function" fn)) | |
5503
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
2908 (if handler |
428 | 2909 (funcall handler form) |
2910 (if (memq 'callargs byte-compile-warnings) | |
2911 (byte-compile-callargs-warn form)) | |
2912 (byte-compile-normal-call form)))) | |
2913 ((and (or (compiled-function-p (car form)) | |
2914 (eq (car-safe (car form)) 'lambda)) | |
2915 ;; if the form comes out the same way it went in, that's | |
2916 ;; because it was malformed, and we couldn't unfold it. | |
2917 (not (eq form (setq form (byte-compile-unfold-lambda form))))) | |
2918 (byte-compile-form form for-effect) | |
2919 (setq for-effect nil)) | |
2920 ((byte-compile-normal-call form))) | |
2921 (when for-effect | |
2922 (byte-compile-discard))) | |
2923 | |
5294
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2924 ;; Generate the list of functions with keyword arguments like so: |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2925 ;; |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2926 ;; (delete-duplicates |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2927 ;; (sort* |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2928 ;; (loop |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2929 ;; for symbol being each symbol in obarray |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2930 ;; with arglist = nil |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2931 ;; if (and (fboundp symbol) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2932 ;; (ignore-errors (setq symbol (indirect-function symbol))) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2933 ;; (cond |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2934 ;; ((and (subrp symbol) (setq symbol (intern (subr-name symbol))))) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2935 ;; ((and (compiled-function-p symbol) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2936 ;; (setq symbol (compiled-function-annotation symbol))))) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2937 ;; (setq arglist (function-arglist symbol)) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2938 ;; (setq arglist (ignore-errors (read-from-string arglist))) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2939 ;; (setq arglist (car arglist)) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2940 ;; (setq arglist (position '&key arglist))) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2941 ;; collect (cons symbol arglist)) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2942 ;; #'string-lessp |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2943 ;; :key #'car) :test #'eq :key #'car) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2944 ;; |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2945 ;; That won't include those that take advantage of cl-seq.el's |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2946 ;; cl-parsing-keywords macro, but the below list does. |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2947 |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2948 (map nil |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2949 (function* |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2950 (lambda ((function . nargs)) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2951 ;; Document that the car of OBJECT, a symbol, describes a function |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2952 ;; taking keyword arguments from the argument index described by |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2953 ;; the cdr of OBJECT. |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2954 (put function 'byte-compile-keyword-start nargs))) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2955 '((adjoin . 3) (assoc* . 3) (assoc-if . 3) (assoc-if-not . 3) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2956 (count . 3) (count-if . 3) (count-if-not . 3) (define-behavior . 3) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2957 (define-behavior-group . 2) (delete* . 3) (delete-duplicates . 2) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2958 (delete-if . 3) (delete-if-not . 3) (fill . 3) (find . 3) (find-if . 3) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2959 (find-if-not . 3) (internal-make-translation-table . 1) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2960 (make-Print-context . 1) (make-hash-table . 1) (make-saved-window . 1) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2961 (make-window-configuration . 1) (member* . 3) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2962 (member-if . 3) (member-if-not . 3) (merge . 5) (nsublis . 3) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2963 (nsubst . 4) (nsubst-if . 4) (nsubst-if-not . 4) (nsubstitute . 4) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2964 (nsubstitute-if . 4) (nsubstitute-if-not . 4) (override-behavior . 2) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2965 (position . 3) (position-if . 3) (position-if-not . 3) (rassoc* . 3) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2966 (rassoc-if . 3) (rassoc-if-not . 3) (reduce . 3) (remove* . 3) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2967 (remove-duplicates . 2) (remove-if . 3) (remove-if-not . 3) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2968 (replace . 3) (sort* . 3) (stable-sort . 3) (sublis . 3) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2969 (subsetp . 3) (subst . 4) (subst-if . 4) (subst-if-not . 4) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2970 (substitute . 4) (substitute-if . 4) (substitute-if-not . 4) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2971 (tree-equal . 3))) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2972 |
428 | 2973 (defun byte-compile-normal-call (form) |
5358
31475de17064
#'byte-compile-normal-call; only examine properties of (car FORM) if a symbol
Aidan Kehoe <kehoea@parhasard.net>
parents:
5356
diff
changeset
|
2974 (and (symbolp (car form)) (get (car form) 'byte-compile-keyword-start) |
5294
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2975 (let ((plist (nthcdr (get (car form) 'byte-compile-keyword-start) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2976 form))) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2977 (symbol-macrolet |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2978 ((not-present '#:not-present)) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2979 (if (not (valid-plist-p plist)) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2980 (byte-compile-warn |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2981 "#'%s: ill-formed keyword argument list: %S" (car form) plist) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2982 (and |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2983 (memq 'callargs byte-compile-warnings) |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2984 (map nil |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2985 (function* |
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
2986 (lambda ((function . nargs)) |
5548
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
2987 (let ((value (plist-get plist function not-present))) |
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
2988 (when (and (not (eq value not-present)) |
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
2989 (byte-compile-constp value)) |
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
2990 (byte-compile-callargs-warn |
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
2991 (cons (eval value) |
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
2992 (member* |
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
2993 nargs |
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
2994 ;; Dummy arguments. There's no need for |
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
2995 ;; it to be longer than even 2, now, but |
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
2996 ;; very little harm in it. |
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
2997 '(9 8 7 6 5 4 3 2 1)))) |
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
2998 (when (and (eq (car-safe value) 'quote) |
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
2999 (eq (car-safe (nth 1 value)) 'lambda) |
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
3000 (or |
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
3001 (null (memq 'quoted-lambda |
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
3002 byte-compile-warnings)) |
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
3003 (byte-compile-warn |
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
3004 "Passing a quoted lambda to #'%s, \ |
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
3005 keyword %s, forcing function quoting" (car form) function))) |
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
3006 (setcar value 'function)))))) |
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
3007 '((:key . 1) (:test . 2) (:test-not . 2) (:if . 1) |
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
3008 (:if-not . 1)))))))) |
428 | 3009 (if byte-compile-generate-call-tree |
3010 (byte-compile-annotate-call-tree form)) | |
3011 (byte-compile-push-constant (car form)) | |
4783
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4775
diff
changeset
|
3012 (mapc 'byte-compile-form (cdr form)) ; wasteful, but faster. |
428 | 3013 (byte-compile-out 'byte-call (length (cdr form)))) |
3014 | |
3015 ;; kludge added to XEmacs to work around the bogosities of a nonlexical lisp. | |
3016 (or (fboundp 'globally-boundp) (fset 'globally-boundp 'boundp)) | |
3017 | |
3018 (defun byte-compile-variable-ref (base-op var &optional varbind-flags) | |
3019 (if (or (not (symbolp var)) (byte-compile-constant-symbol-p var)) | |
3020 (byte-compile-warn | |
3021 (case base-op | |
3022 (byte-varref "Variable reference to %s %s") | |
3023 (byte-varset "Attempt to set %s %s") | |
3024 (byte-varbind "Attempt to let-bind %s %s")) | |
3025 (if (symbolp var) "constant symbol" "non-symbol") | |
3026 var) | |
3027 (if (and (get var 'byte-obsolete-variable) | |
3028 (memq 'obsolete byte-compile-warnings)) | |
3029 (let ((ob (get var 'byte-obsolete-variable))) | |
3030 (byte-compile-warn "%s is an obsolete variable; %s" var | |
3031 (if (stringp ob) | |
3032 ob | |
3033 (format "use %s instead." ob))))) | |
3034 (if (and (get var 'byte-compatible-variable) | |
3035 (memq 'pedantic byte-compile-warnings)) | |
3036 (let ((ob (get var 'byte-compatible-variable))) | |
3037 (byte-compile-warn "%s is provided for compatibility; %s" var | |
3038 (if (stringp ob) | |
3039 ob | |
3040 (format "use %s instead." ob))))) | |
3041 (if (memq 'free-vars byte-compile-warnings) | |
3042 (if (eq base-op 'byte-varbind) | |
3043 (setq byte-compile-bound-variables | |
3044 (cons (cons var (or varbind-flags 0)) | |
3045 byte-compile-bound-variables)) | |
3046 (or (globally-boundp var) | |
3047 (let ((cell (assq var byte-compile-bound-variables))) | |
3048 (if cell (setcdr cell | |
3049 (logior (cdr cell) | |
3050 (if (eq base-op 'byte-varset) | |
3051 byte-compile-assigned-bit | |
3052 byte-compile-referenced-bit))))) | |
444 | 3053 (and (boundp 'current-load-list) |
3054 (memq var current-load-list)) | |
428 | 3055 (if (eq base-op 'byte-varset) |
3056 (or (memq var byte-compile-free-assignments) | |
3057 (progn | |
3058 (byte-compile-warn "assignment to free variable %s" | |
3059 var) | |
3060 (setq byte-compile-free-assignments | |
3061 (cons var byte-compile-free-assignments)))) | |
3062 (or (memq var byte-compile-free-references) | |
3063 (progn | |
3064 (byte-compile-warn "reference to free variable %s" var) | |
3065 (setq byte-compile-free-references | |
3066 (cons var byte-compile-free-references))))))))) | |
3067 (let ((tmp (assq var byte-compile-variables))) | |
3068 (or tmp | |
3069 (setq tmp (list var) | |
3070 byte-compile-variables (cons tmp byte-compile-variables))) | |
3071 (byte-compile-out base-op tmp))) | |
3072 | |
3073 (defmacro byte-compile-get-constant (const) | |
3074 `(or (if (stringp ,const) | |
3075 (assoc ,const byte-compile-constants) | |
3076 (assq ,const byte-compile-constants)) | |
3077 (car (setq byte-compile-constants | |
3078 (cons (list ,const) byte-compile-constants))))) | |
3079 | |
3080 ;; Use this when the value of a form is a constant. This obeys for-effect. | |
3081 (defun byte-compile-constant (const) | |
3082 (if for-effect | |
3083 (setq for-effect nil) | |
3084 (byte-compile-out 'byte-constant (byte-compile-get-constant const)))) | |
3085 | |
3086 ;; Use this for a constant that is not the value of its containing form. | |
3087 ;; This ignores for-effect. | |
3088 (defun byte-compile-push-constant (const) | |
3089 (let ((for-effect nil)) | |
3090 (inline (byte-compile-constant const)))) | |
3091 | |
3092 | |
3093 ;; Compile those primitive ordinary functions | |
3094 ;; which have special byte codes just for speed. | |
3095 | |
3096 (defmacro byte-defop-compiler (function &optional compile-handler) | |
3097 ;; add a compiler-form for FUNCTION. | |
446 | 3098 ;; If FUNCTION is a symbol, then the variable "byte-SYMBOL" must name |
3099 ;; the opcode to be used. If is a list, the first element | |
428 | 3100 ;; is the function and the second element is the bytecode-symbol. |
3101 ;; COMPILE-HANDLER is the function to use to compile this byte-op, or | |
3102 ;; may be the abbreviations 0, 1, 2, 3, 0-1, 1-2, 2-3, 0+1, 1+1, 2+1, | |
3103 ;; 0-1+1, 1-2+1, 2-3+1, 0+2, or 1+2. If it is nil, then the handler is | |
3104 ;; "byte-compile-SYMBOL." | |
3105 (let (opcode) | |
3106 (if (symbolp function) | |
3107 (setq opcode (intern (concat "byte-" (symbol-name function)))) | |
3108 (setq opcode (car (cdr function)) | |
3109 function (car function))) | |
3110 (let ((fnform | |
3111 (list 'put (list 'quote function) ''byte-compile | |
3112 (list 'quote | |
3113 (or (cdr (assq compile-handler | |
3114 '((0 . byte-compile-no-args) | |
3115 (1 . byte-compile-one-arg) | |
3116 (2 . byte-compile-two-args) | |
3117 (3 . byte-compile-three-args) | |
3118 (0-1 . byte-compile-zero-or-one-arg) | |
3119 (1-2 . byte-compile-one-or-two-args) | |
3120 (2-3 . byte-compile-two-or-three-args) | |
3121 (0+1 . byte-compile-no-args-with-one-extra) | |
3122 (1+1 . byte-compile-one-arg-with-one-extra) | |
3123 (2+1 . byte-compile-two-args-with-one-extra) | |
3124 (0-1+1 . byte-compile-zero-or-one-arg-with-one-extra) | |
3125 (1-2+1 . byte-compile-one-or-two-args-with-one-extra) | |
3126 (2-3+1 . byte-compile-two-or-three-args-with-one-extra) | |
3127 (0+2 . byte-compile-no-args-with-two-extra) | |
3128 (1+2 . byte-compile-one-arg-with-two-extra) | |
3129 | |
3130 ))) | |
3131 compile-handler | |
3132 (intern (concat "byte-compile-" | |
3133 (symbol-name function)))))))) | |
3134 (if opcode | |
3135 (list 'progn fnform | |
3136 (list 'put (list 'quote function) | |
3137 ''byte-opcode (list 'quote opcode)) | |
3138 (list 'put (list 'quote opcode) | |
3139 ''byte-opcode-invert (list 'quote function))) | |
3140 fnform)))) | |
3141 | |
3142 (defmacro byte-defop-compiler-1 (function &optional compile-handler) | |
3143 (list 'byte-defop-compiler (list function nil) compile-handler)) | |
3144 | |
3145 | |
3146 (put 'byte-call 'byte-opcode-invert 'funcall) | |
3147 (put 'byte-list1 'byte-opcode-invert 'list) | |
3148 (put 'byte-list2 'byte-opcode-invert 'list) | |
3149 (put 'byte-list3 'byte-opcode-invert 'list) | |
3150 (put 'byte-list4 'byte-opcode-invert 'list) | |
3151 (put 'byte-listN 'byte-opcode-invert 'list) | |
3152 (put 'byte-concat2 'byte-opcode-invert 'concat) | |
3153 (put 'byte-concat3 'byte-opcode-invert 'concat) | |
3154 (put 'byte-concat4 'byte-opcode-invert 'concat) | |
3155 (put 'byte-concatN 'byte-opcode-invert 'concat) | |
3156 (put 'byte-insertN 'byte-opcode-invert 'insert) | |
3157 | |
3158 ;; How old is this stuff? -slb | |
3159 ;(byte-defop-compiler (dot byte-point) 0+1) | |
3160 ;(byte-defop-compiler (dot-max byte-point-max) 0+1) | |
3161 ;(byte-defop-compiler (dot-min byte-point-min) 0+1) | |
3162 (byte-defop-compiler point 0+1) | |
5503
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
3163 (byte-defop-compiler eq 2) |
428 | 3164 (byte-defop-compiler point-max 0+1) |
3165 (byte-defop-compiler point-min 0+1) | |
3166 (byte-defop-compiler following-char 0+1) | |
3167 (byte-defop-compiler preceding-char 0+1) | |
3168 (byte-defop-compiler current-column 0+1) | |
3169 ;; FSF has special function here; generalized here by the 1+2 stuff. | |
3170 (byte-defop-compiler (indent-to-column byte-indent-to) 1+2) | |
3171 (byte-defop-compiler indent-to 1+2) | |
5503
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
3172 (byte-defop-compiler equal 2) |
428 | 3173 (byte-defop-compiler eolp 0+1) |
3174 (byte-defop-compiler eobp 0+1) | |
3175 (byte-defop-compiler bolp 0+1) | |
3176 (byte-defop-compiler bobp 0+1) | |
3177 (byte-defop-compiler current-buffer 0) | |
3178 ;;(byte-defop-compiler read-char 0) ;; obsolete | |
5503
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
3179 (byte-defop-compiler memq 2) |
428 | 3180 (byte-defop-compiler interactive-p 0) |
3181 (byte-defop-compiler widen 0+1) | |
3182 (byte-defop-compiler end-of-line 0-1+1) | |
3183 (byte-defop-compiler forward-char 0-1+1) | |
3184 (byte-defop-compiler forward-line 0-1+1) | |
3185 (byte-defop-compiler symbolp 1) | |
3186 (byte-defop-compiler consp 1) | |
3187 (byte-defop-compiler stringp 1) | |
3188 (byte-defop-compiler listp 1) | |
3189 (byte-defop-compiler not 1) | |
3190 (byte-defop-compiler (null byte-not) 1) | |
3191 (byte-defop-compiler car 1) | |
3192 (byte-defop-compiler cdr 1) | |
3193 (byte-defop-compiler length 1) | |
5562
855b667dea13
Drop cl-macro-environment in favour of byte-compile-macro-environment.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
3194 (byte-defop-compiler symbol-value 1) |
428 | 3195 (byte-defop-compiler symbol-function 1) |
3196 (byte-defop-compiler (1+ byte-add1) 1) | |
3197 (byte-defop-compiler (1- byte-sub1) 1) | |
3198 (byte-defop-compiler goto-char 1+1) | |
3199 (byte-defop-compiler char-after 0-1+1) | |
3200 (byte-defop-compiler set-buffer 1) | |
3201 ;;(byte-defop-compiler set-mark 1) ;; obsolete | |
2217 | 3202 (byte-defop-compiler forward-word 0-1+1) |
428 | 3203 (byte-defop-compiler char-syntax 1+1) |
3204 (byte-defop-compiler nreverse 1) | |
3205 (byte-defop-compiler car-safe 1) | |
3206 (byte-defop-compiler cdr-safe 1) | |
3207 (byte-defop-compiler numberp 1) | |
4885
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
3208 (byte-defop-compiler fixnump 1) |
428 | 3209 (byte-defop-compiler skip-chars-forward 1-2+1) |
3210 (byte-defop-compiler skip-chars-backward 1-2+1) | |
5301
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
3211 (byte-defop-compiler eq 2) |
5503
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
3212 ; (byte-defop-compiler old-eq 2) |
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
3213 ; (byte-defop-compiler old-memq 2) |
428 | 3214 (byte-defop-compiler cons 2) |
3215 (byte-defop-compiler aref 2) | |
3216 (byte-defop-compiler get 2+1) | |
3217 (byte-defop-compiler nth 2) | |
5089
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3218 (byte-defop-compiler subseq byte-compile-subseq) |
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3219 (byte-defop-compiler (substring byte-subseq) 2-3) |
428 | 3220 (byte-defop-compiler (move-marker byte-set-marker) 2-3) |
3221 (byte-defop-compiler set-marker 2-3) | |
3222 (byte-defop-compiler match-beginning 1) | |
3223 (byte-defop-compiler match-end 1) | |
3224 (byte-defop-compiler upcase 1+1) | |
3225 (byte-defop-compiler downcase 1+1) | |
3226 (byte-defop-compiler string= 2) | |
3227 (byte-defop-compiler string< 2) | |
3228 (byte-defop-compiler (string-equal byte-string=) 2) | |
3229 (byte-defop-compiler (string-lessp byte-string<) 2) | |
5503
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
3230 ; (byte-defop-compiler old-equal 2) |
428 | 3231 (byte-defop-compiler nthcdr 2) |
3232 (byte-defop-compiler elt 2) | |
5503
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
3233 (byte-defop-compiler old-member 2) |
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
3234 (byte-defop-compiler old-assq 2) |
428 | 3235 (byte-defop-compiler (rplaca byte-setcar) 2) |
3236 (byte-defop-compiler (rplacd byte-setcdr) 2) | |
3237 (byte-defop-compiler setcar 2) | |
3238 (byte-defop-compiler setcdr 2) | |
3239 (byte-defop-compiler delete-region 2+1) | |
3240 (byte-defop-compiler narrow-to-region 2+1) | |
3241 (byte-defop-compiler (% byte-rem) 2) | |
3242 (byte-defop-compiler aset 3) | |
3243 | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3244 (byte-defop-compiler-1 bind-multiple-value-limits) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3245 (byte-defop-compiler multiple-value-list-internal) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3246 (byte-defop-compiler-1 multiple-value-call) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3247 (byte-defop-compiler throw) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3248 |
5503
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
3249 (byte-defop-compiler member 2) |
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
3250 (byte-defop-compiler assq 2) |
428 | 3251 |
3252 ;;####(byte-defop-compiler move-to-column 1) | |
3253 (byte-defop-compiler-1 interactive byte-compile-noop) | |
3254 (byte-defop-compiler-1 domain byte-compile-domain) | |
3255 | |
3256 ;; As of GNU Emacs 19.18 and Lucid Emacs 19.8, mod and % are different: `%' | |
3257 ;; means integral remainder and may have a negative result; `mod' is always | |
3258 ;; positive, and accepts floating point args. All code which uses `mod' and | |
3259 ;; requires the new interpretation must be compiled with bytecomp version 2.18 | |
3260 ;; or newer, or the emitted code will run the byte-code for `%' instead of an | |
3261 ;; actual call to `mod'. So be careful of compiling new code with an old | |
3262 ;; compiler. Note also that `%' is more efficient than `mod' because the | |
3263 ;; former is byte-coded and the latter is not. | |
3264 ;;(byte-defop-compiler (mod byte-rem) 2) | |
3265 | |
3266 | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3267 (defun byte-compile-warn-wrong-args (form n) |
428 | 3268 (when (memq 'subr-callargs byte-compile-warnings) |
3269 (byte-compile-warn "%s called with %d arg%s, but requires %s" | |
3270 (car form) (length (cdr form)) | |
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5358
diff
changeset
|
3271 (if (eql 1 (length (cdr form))) "" "s") n))) |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3272 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3273 (defun byte-compile-subr-wrong-args (form n) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3274 (byte-compile-warn-wrong-args form n) |
428 | 3275 ;; get run-time wrong-number-of-args error. |
3276 (byte-compile-normal-call form)) | |
3277 | |
3278 (defun byte-compile-no-args (form) | |
3279 (case (length (cdr form)) | |
3280 (0 (byte-compile-out (get (car form) 'byte-opcode) 0)) | |
3281 (t (byte-compile-subr-wrong-args form "none")))) | |
3282 | |
3283 (defun byte-compile-one-arg (form) | |
3284 (case (length (cdr form)) | |
3285 (1 (byte-compile-form (car (cdr form))) ;; Push the argument | |
3286 (byte-compile-out (get (car form) 'byte-opcode) 0)) | |
3287 (t (byte-compile-subr-wrong-args form 1)))) | |
3288 | |
3289 (defun byte-compile-two-args (form) | |
3290 (case (length (cdr form)) | |
3291 (2 (byte-compile-form (nth 1 form)) ;; Push the arguments | |
3292 (byte-compile-form (nth 2 form)) | |
3293 (byte-compile-out (get (car form) 'byte-opcode) 0)) | |
3294 (t (byte-compile-subr-wrong-args form 2)))) | |
3295 | |
3296 (defun byte-compile-three-args (form) | |
3297 (case (length (cdr form)) | |
3298 (3 (byte-compile-form (nth 1 form)) ;; Push the arguments | |
3299 (byte-compile-form (nth 2 form)) | |
3300 (byte-compile-form (nth 3 form)) | |
3301 (byte-compile-out (get (car form) 'byte-opcode) 0)) | |
3302 (t (byte-compile-subr-wrong-args form 3)))) | |
3303 | |
3304 (defun byte-compile-zero-or-one-arg (form) | |
3305 (case (length (cdr form)) | |
3306 (0 (byte-compile-one-arg (append form '(nil)))) | |
3307 (1 (byte-compile-one-arg form)) | |
3308 (t (byte-compile-subr-wrong-args form "0-1")))) | |
3309 | |
3310 (defun byte-compile-one-or-two-args (form) | |
3311 (case (length (cdr form)) | |
3312 (1 (byte-compile-two-args (append form '(nil)))) | |
3313 (2 (byte-compile-two-args form)) | |
3314 (t (byte-compile-subr-wrong-args form "1-2")))) | |
3315 | |
3316 (defun byte-compile-two-or-three-args (form) | |
3317 (case (length (cdr form)) | |
3318 (2 (byte-compile-three-args (append form '(nil)))) | |
3319 (3 (byte-compile-three-args form)) | |
3320 (t (byte-compile-subr-wrong-args form "2-3")))) | |
3321 | |
3322 ;; from Ben Wing <ben@xemacs.org>: some inlined functions have extra | |
3323 ;; optional args added to them in XEmacs 19.12. Changing the byte | |
3324 ;; interpreter to deal with these args would be wrong and cause | |
3325 ;; incompatibility, so we generate non-inlined calls for those cases. | |
3326 ;; Without the following functions, spurious warnings will be generated; | |
3327 ;; however, they would still compile correctly because | |
3328 ;; `byte-compile-subr-wrong-args' also converts the call to non-inlined. | |
3329 | |
3330 (defun byte-compile-no-args-with-one-extra (form) | |
3331 (case (length (cdr form)) | |
3332 (0 (byte-compile-no-args form)) | |
446 | 3333 (1 (if (eq nil (nth 1 form)) |
3334 (byte-compile-no-args (butlast form)) | |
3335 (byte-compile-normal-call form))) | |
428 | 3336 (t (byte-compile-subr-wrong-args form "0-1")))) |
3337 | |
3338 (defun byte-compile-one-arg-with-one-extra (form) | |
3339 (case (length (cdr form)) | |
3340 (1 (byte-compile-one-arg form)) | |
446 | 3341 (2 (if (eq nil (nth 2 form)) |
3342 (byte-compile-one-arg (butlast form)) | |
3343 (byte-compile-normal-call form))) | |
428 | 3344 (t (byte-compile-subr-wrong-args form "1-2")))) |
3345 | |
3346 (defun byte-compile-two-args-with-one-extra (form) | |
3347 (case (length (cdr form)) | |
3348 (2 (byte-compile-two-args form)) | |
446 | 3349 (3 (if (eq nil (nth 3 form)) |
3350 (byte-compile-two-args (butlast form)) | |
3351 (byte-compile-normal-call form))) | |
428 | 3352 (t (byte-compile-subr-wrong-args form "2-3")))) |
3353 | |
3354 (defun byte-compile-zero-or-one-arg-with-one-extra (form) | |
3355 (case (length (cdr form)) | |
3356 (0 (byte-compile-one-arg (append form '(nil)))) | |
3357 (1 (byte-compile-one-arg form)) | |
446 | 3358 (2 (if (eq nil (nth 2 form)) |
3359 (byte-compile-one-arg (butlast form)) | |
3360 (byte-compile-normal-call form))) | |
428 | 3361 (t (byte-compile-subr-wrong-args form "0-2")))) |
3362 | |
3363 (defun byte-compile-one-or-two-args-with-one-extra (form) | |
3364 (case (length (cdr form)) | |
3365 (1 (byte-compile-two-args (append form '(nil)))) | |
3366 (2 (byte-compile-two-args form)) | |
446 | 3367 (3 (if (eq nil (nth 3 form)) |
3368 (byte-compile-two-args (butlast form)) | |
3369 (byte-compile-normal-call form))) | |
428 | 3370 (t (byte-compile-subr-wrong-args form "1-3")))) |
3371 | |
3372 (defun byte-compile-two-or-three-args-with-one-extra (form) | |
3373 (case (length (cdr form)) | |
3374 (2 (byte-compile-three-args (append form '(nil)))) | |
3375 (3 (byte-compile-three-args form)) | |
446 | 3376 (4 (if (eq nil (nth 4 form)) |
3377 (byte-compile-three-args (butlast form)) | |
3378 (byte-compile-normal-call form))) | |
428 | 3379 (t (byte-compile-subr-wrong-args form "2-4")))) |
3380 | |
3381 (defun byte-compile-no-args-with-two-extra (form) | |
3382 (case (length (cdr form)) | |
3383 (0 (byte-compile-no-args form)) | |
3384 ((1 2) (byte-compile-normal-call form)) | |
3385 (t (byte-compile-subr-wrong-args form "0-2")))) | |
3386 | |
3387 (defun byte-compile-one-arg-with-two-extra (form) | |
3388 (case (length (cdr form)) | |
3389 (1 (byte-compile-one-arg form)) | |
3390 ((2 3) (byte-compile-normal-call form)) | |
3391 (t (byte-compile-subr-wrong-args form "1-3")))) | |
3392 | |
3393 (defun byte-compile-noop (form) | |
3394 (byte-compile-constant nil)) | |
3395 | |
3396 (defun byte-compile-discard () | |
3397 (byte-compile-out 'byte-discard 0)) | |
3398 | |
446 | 3399 (defun byte-compile-max (form) |
3400 (let ((args (cdr form))) | |
428 | 3401 (case (length args) |
446 | 3402 (0 (byte-compile-subr-wrong-args form "1 or more")) |
3403 (1 (byte-compile-form (car args)) | |
3404 (when (not byte-compile-delete-errors) | |
3405 (byte-compile-out 'byte-dup 0) | |
3406 (byte-compile-out 'byte-max 0))) | |
428 | 3407 (t (byte-compile-form (car args)) |
446 | 3408 (dolist (elt (cdr args)) |
3409 (byte-compile-form elt) | |
3410 (byte-compile-out 'byte-max 0)))))) | |
3411 | |
3412 (defun byte-compile-min (form) | |
3413 (let ((args (cdr form))) | |
3414 (case (length args) | |
3415 (0 (byte-compile-subr-wrong-args form "1 or more")) | |
3416 (1 (byte-compile-form (car args)) | |
3417 (when (not byte-compile-delete-errors) | |
3418 (byte-compile-out 'byte-dup 0) | |
3419 (byte-compile-out 'byte-min 0))) | |
3420 (t (byte-compile-form (car args)) | |
3421 (dolist (elt (cdr args)) | |
3422 (byte-compile-form elt) | |
3423 (byte-compile-out 'byte-min 0)))))) | |
428 | 3424 |
3425 | |
3426 ;; more complicated compiler macros | |
3427 | |
3428 (byte-defop-compiler list) | |
3429 (byte-defop-compiler concat) | |
3430 (byte-defop-compiler fset) | |
3431 (byte-defop-compiler insert) | |
3432 (byte-defop-compiler-1 function byte-compile-function-form) | |
446 | 3433 (byte-defop-compiler max) |
3434 (byte-defop-compiler min) | |
3435 (byte-defop-compiler (+ byte-plus) byte-compile-plus) | |
3436 (byte-defop-compiler-1 - byte-compile-minus) | |
3437 (byte-defop-compiler (* byte-mult) byte-compile-mult) | |
3438 (byte-defop-compiler (/ byte-quo) byte-compile-quo) | |
428 | 3439 (byte-defop-compiler nconc) |
3440 (byte-defop-compiler-1 beginning-of-line) | |
3441 | |
3442 (byte-defop-compiler (= byte-eqlsign) byte-compile-arithcompare) | |
3443 (byte-defop-compiler (< byte-lss) byte-compile-arithcompare) | |
3444 (byte-defop-compiler (> byte-gtr) byte-compile-arithcompare) | |
3445 (byte-defop-compiler (<= byte-leq) byte-compile-arithcompare) | |
3446 (byte-defop-compiler (>= byte-geq) byte-compile-arithcompare) | |
3447 | |
3448 (defun byte-compile-arithcompare (form) | |
3449 (case (length (cdr form)) | |
3450 (0 (byte-compile-subr-wrong-args form "1 or more")) | |
549 | 3451 (1 (if byte-compile-delete-errors |
3452 (byte-compile-constant t) | |
3453 (byte-compile-normal-call form))) | |
428 | 3454 (2 (byte-compile-two-args form)) |
3455 (t (byte-compile-normal-call form)))) | |
3456 | |
3457 (byte-defop-compiler /= byte-compile-/=) | |
3458 | |
3459 (defun byte-compile-/= (form) | |
3460 (case (length (cdr form)) | |
3461 (0 (byte-compile-subr-wrong-args form "1 or more")) | |
3462 (1 (byte-compile-constant t)) | |
3463 ;; optimize (/= X Y) to (not (= X Y)) | |
3464 (2 (byte-compile-form-do-effect `(not (= ,@(cdr form))))) | |
3465 (t (byte-compile-normal-call form)))) | |
3466 | |
3467 ;; buffer-substring now has its own function. This used to be | |
3468 ;; 2+1, but now all args are optional. | |
3469 (byte-defop-compiler buffer-substring) | |
3470 | |
3471 (defun byte-compile-buffer-substring (form) | |
3472 ;; buffer-substring used to take exactly two args, but now takes 0-3. | |
3473 ;; convert 0-2 to two args and use special bytecode operand. | |
3474 ;; convert 3 args to a normal call. | |
3475 (case (length (cdr form)) | |
3476 (0 (byte-compile-two-args (append form '(nil nil)))) | |
3477 (1 (byte-compile-two-args (append form '(nil)))) | |
3478 (2 (byte-compile-two-args form)) | |
3479 (3 (byte-compile-normal-call form)) | |
3480 (t (byte-compile-subr-wrong-args form "0-3")))) | |
3481 | |
3482 (defun byte-compile-list (form) | |
3483 (let* ((args (cdr form)) | |
3484 (nargs (length args))) | |
3485 (cond | |
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5358
diff
changeset
|
3486 ((eql nargs 0) |
428 | 3487 (byte-compile-constant nil)) |
3488 ((< nargs 5) | |
4783
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4775
diff
changeset
|
3489 (mapc 'byte-compile-form args) |
428 | 3490 (byte-compile-out |
3491 (aref [byte-list1 byte-list2 byte-list3 byte-list4] (1- nargs)) | |
3492 0)) | |
3493 ((< nargs 256) | |
4783
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4775
diff
changeset
|
3494 (mapc 'byte-compile-form args) |
428 | 3495 (byte-compile-out 'byte-listN nargs)) |
3496 (t (byte-compile-normal-call form))))) | |
3497 | |
3498 (defun byte-compile-concat (form) | |
3499 (let* ((args (cdr form)) | |
3500 (nargs (length args))) | |
3501 ;; Concat of one arg is not a no-op if arg is not a string. | |
3502 (cond | |
3503 ((memq nargs '(2 3 4)) | |
4783
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4775
diff
changeset
|
3504 (mapc 'byte-compile-form args) |
428 | 3505 (byte-compile-out |
3506 (aref [byte-concat2 byte-concat3 byte-concat4] (- nargs 2)) | |
3507 0)) | |
3508 ((eq nargs 0) | |
3509 (byte-compile-form "")) | |
3510 ((< nargs 256) | |
4783
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4775
diff
changeset
|
3511 (mapc 'byte-compile-form args) |
428 | 3512 (byte-compile-out 'byte-concatN nargs)) |
3513 ((byte-compile-normal-call form))))) | |
3514 | |
446 | 3515 (defun byte-compile-plus (form) |
3516 (let ((args (cdr form))) | |
3517 (case (length args) | |
3518 (0 (byte-compile-constant 0)) | |
3519 (1 (byte-compile-plus (append form '(0)))) | |
3520 (t (byte-compile-form (car args)) | |
3521 (dolist (elt (cdr args)) | |
3522 (case elt | |
3523 (0 (when (not byte-compile-delete-errors) | |
3524 (byte-compile-constant 0) | |
3525 (byte-compile-out 'byte-plus 0))) | |
3526 (+1 (byte-compile-out 'byte-add1 0)) | |
3527 (-1 (byte-compile-out 'byte-sub1 0)) | |
3528 (t | |
3529 (byte-compile-form elt) | |
3530 (byte-compile-out 'byte-plus 0)))))))) | |
3531 | |
428 | 3532 (defun byte-compile-minus (form) |
3533 (let ((args (cdr form))) | |
3534 (case (length args) | |
3535 (0 (byte-compile-subr-wrong-args form "1 or more")) | |
3536 (1 (byte-compile-form (car args)) | |
3537 (byte-compile-out 'byte-negate 0)) | |
3538 (t (byte-compile-form (car args)) | |
3539 (dolist (elt (cdr args)) | |
446 | 3540 (case elt |
3541 (0 (when (not byte-compile-delete-errors) | |
3542 (byte-compile-constant 0) | |
3543 (byte-compile-out 'byte-diff 0))) | |
3544 (+1 (byte-compile-out 'byte-sub1 0)) | |
3545 (-1 (byte-compile-out 'byte-add1 0)) | |
3546 (t | |
3547 (byte-compile-form elt) | |
3548 (byte-compile-out 'byte-diff 0)))))))) | |
3549 | |
3550 (defun byte-compile-mult (form) | |
3551 (let ((args (cdr form))) | |
3552 (case (length args) | |
3553 (0 (byte-compile-constant 1)) | |
3554 (1 (byte-compile-mult (append form '(1)))) | |
3555 (t (byte-compile-form (car args)) | |
3556 (dolist (elt (cdr args)) | |
3557 (case elt | |
3558 (1 (when (not byte-compile-delete-errors) | |
3559 (byte-compile-constant 1) | |
3560 (byte-compile-out 'byte-mult 0))) | |
3561 (-1 (byte-compile-out 'byte-negate 0)) | |
3562 (2 (byte-compile-out 'byte-dup 0) | |
3563 (byte-compile-out 'byte-plus 0)) | |
3564 (t | |
3565 (byte-compile-form elt) | |
3566 (byte-compile-out 'byte-mult 0)))))))) | |
428 | 3567 |
3568 (defun byte-compile-quo (form) | |
3569 (let ((args (cdr form))) | |
3570 (case (length args) | |
3571 (0 (byte-compile-subr-wrong-args form "1 or more")) | |
3572 (1 (byte-compile-constant 1) | |
3573 (byte-compile-form (car args)) | |
3574 (byte-compile-out 'byte-quo 0)) | |
3575 (t (byte-compile-form (car args)) | |
3576 (dolist (elt (cdr args)) | |
446 | 3577 (case elt |
3578 (+1 (when (not byte-compile-delete-errors) | |
3579 (byte-compile-constant 1) | |
3580 (byte-compile-out 'byte-quo 0))) | |
3581 (-1 (byte-compile-out 'byte-negate 0)) | |
3582 (t | |
3583 (when (and (numberp elt) (= elt 0)) | |
3584 (byte-compile-warn "Attempt to divide by zero: %s" form)) | |
3585 (byte-compile-form elt) | |
3586 (byte-compile-out 'byte-quo 0)))))))) | |
428 | 3587 |
3588 (defun byte-compile-nconc (form) | |
3589 (let ((args (cdr form))) | |
3590 (case (length args) | |
3591 (0 (byte-compile-constant nil)) | |
3592 ;; nconc of one arg is a noop, even if that arg isn't a list. | |
3593 (1 (byte-compile-form (car args))) | |
3594 (t (byte-compile-form (car args)) | |
3595 (dolist (elt (cdr args)) | |
3596 (byte-compile-form elt) | |
3597 (byte-compile-out 'byte-nconc 0)))))) | |
3598 | |
3599 (defun byte-compile-fset (form) | |
3600 ;; warn about forms like (fset 'foo '(lambda () ...)) | |
3601 ;; (where the lambda expression is non-trivial...) | |
3602 ;; Except don't warn if the first argument is 'make-byte-code, because | |
3603 ;; I'm sick of getting mail asking me whether that warning is a problem. | |
3604 (let ((fn (nth 2 form)) | |
3605 body) | |
3606 (when (and (eq (car-safe fn) 'quote) | |
3607 (eq (car-safe (setq fn (nth 1 fn))) 'lambda) | |
3608 (not (eq (car-safe (cdr-safe (nth 1 form))) 'make-byte-code))) | |
3609 (setq body (cdr (cdr fn))) | |
3610 (if (stringp (car body)) (setq body (cdr body))) | |
3611 (if (eq 'interactive (car-safe (car body))) (setq body (cdr body))) | |
3612 (if (and (consp (car body)) | |
4719
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
3613 (not (eq 'byte-code (car (car body)))) |
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
3614 (memq 'quoted-lambda byte-compile-warnings)) |
428 | 3615 (byte-compile-warn |
3616 "A quoted lambda form is the second argument of fset. This is probably | |
3617 not what you want, as that lambda cannot be compiled. Consider using | |
3618 the syntax (function (lambda (...) ...)) instead.")))) | |
3619 (byte-compile-two-args form)) | |
3620 | |
5089
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3621 (defun byte-compile-subseq (form) |
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3622 (byte-compile-two-or-three-args form) |
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3623 ;; Check that XEmacs supports the substring-subseq equivalence. |
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3624 (pushnew '(eq 'subseq (symbol-function 'substring)) |
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3625 byte-compile-checks-on-load :test #'equal)) |
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3626 |
4743
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3627 (defmacro byte-compile-funarg-n (&rest n) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3628 `#'(lambda (form) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3629 ,@(loop |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3630 for en in n |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3631 collect `(let ((fn (nth ,en form))) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3632 (when (and (eq (car-safe fn) 'quote) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3633 (eq (car-safe (nth 1 fn)) 'lambda) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3634 (or |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3635 (null (memq 'quoted-lambda |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3636 byte-compile-warnings)) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3637 (byte-compile-warn |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3638 "Passing a quoted lambda (arg %d) to #'%s, \ |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3639 forcing function quoting" ,en (car form)))) |
4743
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3640 (setcar fn 'function)))) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3641 (byte-compile-normal-call form))) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3642 |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3643 ;; (mapcar '(lambda (x) ..) ..) ==> (mapcar (function (lambda (x) ..)) ..) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3644 ;; for cases where it's guaranteed that first arg will be used as a lambda. |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3645 (defalias 'byte-compile-funarg (byte-compile-funarg-n 1)) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3646 |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3647 ;; (sort ... '(lambda (x) ..)) ==> (sort ... (function (lambda (x) ..))) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3648 ;; for cases where it's guaranteed that second arg will be used as a lambda. |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3649 (defalias 'byte-compile-funarg-2 (byte-compile-funarg-n 2)) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3650 |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3651 ;; For #'merge, basically. |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3652 (defalias 'byte-compile-funarg-4 (byte-compile-funarg-n 4)) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3653 |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3654 ;; For #'call-with-condition-handler, basically. |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3655 (defalias 'byte-compile-funarg-1-2 (byte-compile-funarg-n 1 2)) |
428 | 3656 |
4716
dca5bb2adff1
Don't cons with #'mapcar calls where the result is discarded,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4686
diff
changeset
|
3657 ;; XEmacs change; don't cons up the list if it's going to be immediately |
4743
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3658 ;; discarded. GNU give a warning in `byte-compile-normal-call' instead, and |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3659 ;; only for #'mapcar. |
4719
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
3660 (defun byte-compile-maybe-mapc (form) |
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
3661 (and for-effect |
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
3662 (or (null (memq 'discarded-consing byte-compile-warnings)) |
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
3663 (byte-compile-warn |
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
3664 "Discarding the result of #'%s; maybe you meant #'mapc?" |
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
3665 (car form))) |
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4885
diff
changeset
|
3666 (setq form (cons 'mapc (cdr form)))) |
4716
dca5bb2adff1
Don't cons with #'mapcar calls where the result is discarded,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4686
diff
changeset
|
3667 (byte-compile-funarg form)) |
dca5bb2adff1
Don't cons with #'mapcar calls where the result is discarded,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4686
diff
changeset
|
3668 |
dca5bb2adff1
Don't cons with #'mapcar calls where the result is discarded,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4686
diff
changeset
|
3669 (defun byte-compile-maplist (form) |
4719
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
3670 (and for-effect |
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
3671 (or (null (memq 'discarded-consing byte-compile-warnings)) |
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
3672 (byte-compile-warn |
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
3673 "Discarding the result of #'maplist; maybe you meant #'mapl?")) |
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
3674 (setq form (cons 'mapl (cdr form)))) |
4716
dca5bb2adff1
Don't cons with #'mapcar calls where the result is discarded,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4686
diff
changeset
|
3675 (byte-compile-funarg form)) |
dca5bb2adff1
Don't cons with #'mapcar calls where the result is discarded,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4686
diff
changeset
|
3676 |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3677 ;; For when calls to #'sort or #'mapcar have more than two args, something |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3678 ;; recent XEmacs can handle, but GNU and 21.4 can't. |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3679 (defmacro byte-compile-maybe-add-* (complex max) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3680 `#'(lambda (form) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3681 (when (> (length (cdr form)) ,max) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3682 (when (memq 'callargs byte-compile-warnings) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3683 (byte-compile-warn |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3684 "#'%s called with %d arguments, using #'%s instead" |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3685 (car form) (length (cdr form)) ',complex)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3686 (setq form (cons ',complex (cdr form)))) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3687 (funcall (or (get ',complex 'byte-compile) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3688 'byte-compile-normal-call) form))) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3689 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3690 (defalias 'byte-compile-mapcar (byte-compile-maybe-add-* mapcar* 2)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3691 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3692 (defalias 'byte-compile-sort (byte-compile-maybe-add-* sort* 2)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3693 |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3694 (defalias 'byte-compile-fillarray (byte-compile-maybe-add-* fill 2)) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3695 |
428 | 3696 ;; (function foo) must compile like 'foo, not like (symbol-function 'foo). |
3697 ;; Otherwise it will be incompatible with the interpreter, | |
3698 ;; and (funcall (function foo)) will lose with autoloads. | |
3699 | |
3700 (defun byte-compile-function-form (form) | |
5265
5663ae9a8989
Warn at compile time, error at runtime, with (quote X Y), (function X Y).
Aidan Kehoe <kehoea@parhasard.net>
parents:
5263
diff
changeset
|
3701 (if (cddr form) |
5663ae9a8989
Warn at compile time, error at runtime, with (quote X Y), (function X Y).
Aidan Kehoe <kehoea@parhasard.net>
parents:
5263
diff
changeset
|
3702 (byte-compile-normal-call |
5663ae9a8989
Warn at compile time, error at runtime, with (quote X Y), (function X Y).
Aidan Kehoe <kehoea@parhasard.net>
parents:
5263
diff
changeset
|
3703 `(signal 'wrong-number-of-arguments '(function ,(length (cdr form))))) |
5663ae9a8989
Warn at compile time, error at runtime, with (quote X Y), (function X Y).
Aidan Kehoe <kehoea@parhasard.net>
parents:
5263
diff
changeset
|
3704 (byte-compile-constant |
5663ae9a8989
Warn at compile time, error at runtime, with (quote X Y), (function X Y).
Aidan Kehoe <kehoea@parhasard.net>
parents:
5263
diff
changeset
|
3705 (cond ((symbolp (nth 1 form)) |
5663ae9a8989
Warn at compile time, error at runtime, with (quote X Y), (function X Y).
Aidan Kehoe <kehoea@parhasard.net>
parents:
5263
diff
changeset
|
3706 (nth 1 form)) |
5663ae9a8989
Warn at compile time, error at runtime, with (quote X Y), (function X Y).
Aidan Kehoe <kehoea@parhasard.net>
parents:
5263
diff
changeset
|
3707 ((byte-compile-lambda (nth 1 form))))))) |
428 | 3708 |
3709 (defun byte-compile-insert (form) | |
3710 (cond ((null (cdr form)) | |
3711 (byte-compile-constant nil)) | |
3712 ((<= (length form) 256) | |
4783
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4775
diff
changeset
|
3713 (mapc 'byte-compile-form (cdr form)) |
428 | 3714 (if (cdr (cdr form)) |
3715 (byte-compile-out 'byte-insertN (length (cdr form))) | |
3716 (byte-compile-out 'byte-insert 0))) | |
3717 ((memq t (mapcar 'consp (cdr (cdr form)))) | |
3718 (byte-compile-normal-call form)) | |
3719 ;; We can split it; there is no function call after inserting 1st arg. | |
3720 (t | |
3721 (while (setq form (cdr form)) | |
3722 (byte-compile-form (car form)) | |
3723 (byte-compile-out 'byte-insert 0) | |
3724 (when (cdr form) | |
3725 (byte-compile-discard)))))) | |
3726 | |
3727 ;; alas, the old (pre-19.12, and all existing versions of FSFmacs 19) | |
3728 ;; byte compiler will generate incorrect code for | |
3729 ;; (beginning-of-line nil buffer) because it buggily doesn't | |
3730 ;; check the number of arguments passed to beginning-of-line. | |
3731 | |
3732 (defun byte-compile-beginning-of-line (form) | |
3733 (let ((len (length form))) | |
3734 (cond ((> len 3) | |
3735 (byte-compile-subr-wrong-args form "0-2")) | |
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5358
diff
changeset
|
3736 ((or (eql len 3) (not (byte-compile-constp (nth 1 form)))) |
428 | 3737 (byte-compile-normal-call form)) |
3738 (t | |
3739 (byte-compile-form | |
3740 (list 'forward-line | |
3741 (if (integerp (setq form (or (eval (nth 1 form)) 1))) | |
3742 (1- form) | |
3743 (byte-compile-warn | |
3744 "Non-numeric arg to beginning-of-line: %s" form) | |
3745 (list '1- (list 'quote form)))) | |
3746 t) | |
3747 (byte-compile-constant nil))))) | |
3748 | |
3749 | |
3750 (byte-defop-compiler set) | |
3751 (byte-defop-compiler-1 setq) | |
3752 (byte-defop-compiler-1 set-default) | |
3753 (byte-defop-compiler-1 setq-default) | |
3754 | |
3755 (byte-defop-compiler-1 quote) | |
3756 (byte-defop-compiler-1 quote-form) | |
3757 | |
3758 (defun byte-compile-setq (form) | |
3759 (let ((args (cdr form)) var val) | |
3760 (if (null args) | |
3761 ;; (setq), with no arguments. | |
3762 (byte-compile-form nil for-effect) | |
3763 (while args | |
3764 (setq var (pop args)) | |
3765 (if (null args) | |
3766 ;; Odd number of args? Let `set' get the error. | |
3767 (byte-compile-form `(set ',var) for-effect) | |
3768 (setq val (pop args)) | |
5344
2a54dfbe434f
Don't quote keywords, they've been self-quoting for well over a decade.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5301
diff
changeset
|
3769 (byte-compile-form val) |
2a54dfbe434f
Don't quote keywords, they've been self-quoting for well over a decade.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5301
diff
changeset
|
3770 (unless (or args for-effect) |
2a54dfbe434f
Don't quote keywords, they've been self-quoting for well over a decade.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5301
diff
changeset
|
3771 (byte-compile-out 'byte-dup 0)) |
2a54dfbe434f
Don't quote keywords, they've been self-quoting for well over a decade.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5301
diff
changeset
|
3772 (byte-compile-variable-ref 'byte-varset var))))) |
428 | 3773 (setq for-effect nil)) |
3774 | |
3775 (defun byte-compile-set (form) | |
3776 ;; Compile (set 'foo x) as (setq foo x) for trivially better code and so | |
3777 ;; that we get applicable warnings. Compile everything else (including | |
3778 ;; malformed calls) like a normal 2-arg byte-coded function. | |
3779 (let ((symform (nth 1 form)) | |
3780 (valform (nth 2 form)) | |
3781 sym) | |
5344
2a54dfbe434f
Don't quote keywords, they've been self-quoting for well over a decade.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5301
diff
changeset
|
3782 (if (and (eql (length form) 3) |
2a54dfbe434f
Don't quote keywords, they've been self-quoting for well over a decade.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5301
diff
changeset
|
3783 (eql (safe-length symform) 2) |
428 | 3784 (eq (car symform) 'quote) |
5344
2a54dfbe434f
Don't quote keywords, they've been self-quoting for well over a decade.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5301
diff
changeset
|
3785 (symbolp (setq sym (car (cdr symform))))) |
428 | 3786 (byte-compile-setq `(setq ,sym ,valform)) |
3787 (byte-compile-two-args form)))) | |
3788 | |
3789 (defun byte-compile-setq-default (form) | |
3790 (let ((args (cdr form))) | |
3791 (if (null args) | |
3792 ;; (setq-default), with no arguments. | |
3793 (byte-compile-form nil for-effect) | |
3794 ;; emit multiple calls to `set-default' if necessary | |
3795 (while args | |
3796 (byte-compile-form | |
3797 ;; Odd number of args? Let `set-default' get the error. | |
3798 `(set-default ',(pop args) ,@(if args (list (pop args)) nil)) | |
3799 (if args t for-effect))))) | |
3800 (setq for-effect nil)) | |
3801 | |
3802 (defun byte-compile-set-default (form) | |
3803 (let* ((args (cdr form)) | |
3804 (nargs (length args)) | |
3805 (var (car args))) | |
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5358
diff
changeset
|
3806 (when (and (eql (safe-length var) 2) (eq (car var) 'quote)) |
428 | 3807 (let ((sym (nth 1 var))) |
3808 (cond | |
3809 ((not (symbolp sym)) | |
3810 (byte-compile-warn "Attempt to set-globally non-symbol %s" sym)) | |
3811 ((byte-compile-constant-symbol-p sym) | |
3812 (byte-compile-warn "Attempt to set-globally constant symbol %s" sym)) | |
3813 ((let ((cell (assq sym byte-compile-bound-variables))) | |
3814 (and cell | |
3815 (setcdr cell (logior (cdr cell) byte-compile-assigned-bit)) | |
3816 t))) | |
3817 ;; notice calls to set-default/setq-default for variables which | |
3818 ;; have not been declared with defvar/defconst. | |
3819 ((globally-boundp sym)) ; OK | |
3820 ((not (memq 'free-vars byte-compile-warnings))) ; warnings suppressed? | |
3821 ((memq sym byte-compile-free-assignments)) ; already warned about sym | |
3822 (t | |
3823 (byte-compile-warn "assignment to free variable %s" sym) | |
3824 (push sym byte-compile-free-assignments))))) | |
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5358
diff
changeset
|
3825 (if (eql nargs 2) |
428 | 3826 ;; now emit a normal call to set-default |
3827 (byte-compile-normal-call form) | |
3828 (byte-compile-subr-wrong-args form 2)))) | |
3829 | |
3830 | |
3831 (defun byte-compile-quote (form) | |
5265
5663ae9a8989
Warn at compile time, error at runtime, with (quote X Y), (function X Y).
Aidan Kehoe <kehoea@parhasard.net>
parents:
5263
diff
changeset
|
3832 (if (cddr form) |
5663ae9a8989
Warn at compile time, error at runtime, with (quote X Y), (function X Y).
Aidan Kehoe <kehoea@parhasard.net>
parents:
5263
diff
changeset
|
3833 (byte-compile-normal-call |
5663ae9a8989
Warn at compile time, error at runtime, with (quote X Y), (function X Y).
Aidan Kehoe <kehoea@parhasard.net>
parents:
5263
diff
changeset
|
3834 `(signal 'wrong-number-of-arguments '(quote ,(length (cdr form))))) |
5663ae9a8989
Warn at compile time, error at runtime, with (quote X Y), (function X Y).
Aidan Kehoe <kehoea@parhasard.net>
parents:
5263
diff
changeset
|
3835 (byte-compile-constant (car (cdr form))))) |
428 | 3836 |
3837 (defun byte-compile-quote-form (form) | |
5265
5663ae9a8989
Warn at compile time, error at runtime, with (quote X Y), (function X Y).
Aidan Kehoe <kehoea@parhasard.net>
parents:
5263
diff
changeset
|
3838 (if (cddr form) |
5663ae9a8989
Warn at compile time, error at runtime, with (quote X Y), (function X Y).
Aidan Kehoe <kehoea@parhasard.net>
parents:
5263
diff
changeset
|
3839 (byte-compile-normal-call |
5663ae9a8989
Warn at compile time, error at runtime, with (quote X Y), (function X Y).
Aidan Kehoe <kehoea@parhasard.net>
parents:
5263
diff
changeset
|
3840 `(signal 'wrong-number-of-arguments '(quote ,(length (cdr form))))) |
5663ae9a8989
Warn at compile time, error at runtime, with (quote X Y), (function X Y).
Aidan Kehoe <kehoea@parhasard.net>
parents:
5263
diff
changeset
|
3841 (byte-compile-constant (byte-compile-top-level (nth 1 form))))) |
428 | 3842 |
3843 ;;; control structures | |
3844 | |
3845 (defun byte-compile-body (body &optional for-effect) | |
3846 (while (cdr body) | |
3847 (byte-compile-form (car body) t) | |
3848 (setq body (cdr body))) | |
3849 (byte-compile-form (car body) for-effect)) | |
3850 | |
3851 (proclaim-inline byte-compile-body-do-effect) | |
3852 (defun byte-compile-body-do-effect (body) | |
3853 (byte-compile-body body for-effect) | |
3854 (setq for-effect nil)) | |
3855 | |
3856 (proclaim-inline byte-compile-form-do-effect) | |
3857 (defun byte-compile-form-do-effect (form) | |
3858 (byte-compile-form form for-effect) | |
3859 (setq for-effect nil)) | |
3860 | |
3861 (byte-defop-compiler-1 inline byte-compile-progn) | |
3862 (byte-defop-compiler-1 progn) | |
3863 (byte-defop-compiler-1 prog1) | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3864 (byte-defop-compiler-1 multiple-value-prog1) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3865 (byte-defop-compiler-1 values) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3866 (byte-defop-compiler-1 values-list) |
428 | 3867 (byte-defop-compiler-1 prog2) |
3868 (byte-defop-compiler-1 if) | |
3869 (byte-defop-compiler-1 cond) | |
3870 (byte-defop-compiler-1 and) | |
3871 (byte-defop-compiler-1 or) | |
3872 (byte-defop-compiler-1 while) | |
3873 (byte-defop-compiler-1 funcall) | |
3874 (byte-defop-compiler-1 apply byte-compile-funarg) | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3875 (byte-defop-compiler-1 mapcar byte-compile-mapcar) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3876 (byte-defop-compiler-1 mapcar* byte-compile-maybe-mapc) |
428 | 3877 (byte-defop-compiler-1 mapatoms byte-compile-funarg) |
3878 (byte-defop-compiler-1 mapconcat byte-compile-funarg) | |
4743
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3879 (byte-defop-compiler-1 mapc byte-compile-funarg) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3880 (byte-defop-compiler-1 maphash byte-compile-funarg) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3881 (byte-defop-compiler-1 map-char-table byte-compile-funarg) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3882 (byte-defop-compiler-1 mapvector byte-compile-maybe-mapc) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3883 (byte-defop-compiler-1 mapc-internal byte-compile-funarg) |
4716
dca5bb2adff1
Don't cons with #'mapcar calls where the result is discarded,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4686
diff
changeset
|
3884 (byte-defop-compiler-1 maplist byte-compile-maplist) |
dca5bb2adff1
Don't cons with #'mapcar calls where the result is discarded,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4686
diff
changeset
|
3885 (byte-defop-compiler-1 mapl byte-compile-funarg) |
dca5bb2adff1
Don't cons with #'mapcar calls where the result is discarded,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4686
diff
changeset
|
3886 (byte-defop-compiler-1 mapcan byte-compile-funarg) |
dca5bb2adff1
Don't cons with #'mapcar calls where the result is discarded,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4686
diff
changeset
|
3887 (byte-defop-compiler-1 mapcon byte-compile-funarg) |
4719
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
3888 (byte-defop-compiler-1 map-database byte-compile-funarg) |
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
3889 (byte-defop-compiler-1 map-extent-children byte-compile-funarg) |
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
3890 (byte-defop-compiler-1 map-extents byte-compile-funarg) |
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
3891 (byte-defop-compiler-1 map-plist byte-compile-funarg) |
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
3892 (byte-defop-compiler-1 map-range-table byte-compile-funarg) |
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
3893 (byte-defop-compiler-1 map-syntax-table byte-compile-funarg) |
4743
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3894 |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3895 (byte-defop-compiler-1 remove-if byte-compile-funarg) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3896 (byte-defop-compiler-1 remove-if-not byte-compile-funarg) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3897 (byte-defop-compiler-1 delete-if byte-compile-funarg) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3898 (byte-defop-compiler-1 delete-if-not byte-compile-funarg) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3899 (byte-defop-compiler-1 find-if byte-compile-funarg) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3900 (byte-defop-compiler-1 find-if-not byte-compile-funarg) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3901 (byte-defop-compiler-1 position-if byte-compile-funarg) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3902 (byte-defop-compiler-1 position-if-not byte-compile-funarg) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3903 (byte-defop-compiler-1 count-if byte-compile-funarg) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3904 (byte-defop-compiler-1 count-if-not byte-compile-funarg) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3905 (byte-defop-compiler-1 member-if byte-compile-funarg) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3906 (byte-defop-compiler-1 member-if-not byte-compile-funarg) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3907 (byte-defop-compiler-1 assoc-if byte-compile-funarg) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3908 (byte-defop-compiler-1 assoc-if-not byte-compile-funarg) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3909 (byte-defop-compiler-1 rassoc-if byte-compile-funarg) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3910 (byte-defop-compiler-1 rassoc-if-not byte-compile-funarg) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3911 (byte-defop-compiler-1 reduce byte-compile-funarg) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3912 (byte-defop-compiler-1 some byte-compile-funarg) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3913 (byte-defop-compiler-1 every byte-compile-funarg) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3914 (byte-defop-compiler-1 notany byte-compile-funarg) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3915 (byte-defop-compiler-1 notevery byte-compile-funarg) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3916 |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3917 (byte-defop-compiler-1 walk-windows byte-compile-funarg) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3918 (byte-defop-compiler-1 get-window-with-predicate byte-compile-funarg) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3919 |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3920 (byte-defop-compiler-1 map byte-compile-funarg-2) |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3921 (byte-defop-compiler-1 map-into byte-compile-funarg-2) |
4743
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3922 (byte-defop-compiler-1 apropos-internal byte-compile-funarg-2) |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3923 (byte-defop-compiler-1 sort byte-compile-sort) |
4743
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3924 (byte-defop-compiler-1 sort* byte-compile-funarg-2) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3925 (byte-defop-compiler-1 stable-sort byte-compile-funarg-2) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3926 (byte-defop-compiler-1 substitute-if byte-compile-funarg-2) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3927 (byte-defop-compiler-1 substitute-if-not byte-compile-funarg-2) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3928 (byte-defop-compiler-1 nsubstitute-if byte-compile-funarg-2) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3929 (byte-defop-compiler-1 nsubstitute-if-not byte-compile-funarg-2) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3930 (byte-defop-compiler-1 subst-if byte-compile-funarg-2) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3931 (byte-defop-compiler-1 subst-if-not byte-compile-funarg-2) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3932 (byte-defop-compiler-1 nsubst-if byte-compile-funarg-2) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3933 (byte-defop-compiler-1 nsubst-if-not byte-compile-funarg-2) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3934 |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3935 (byte-defop-compiler-1 merge byte-compile-funarg-4) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3936 |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3937 (byte-defop-compiler-1 call-with-condition-handler byte-compile-funarg-1-2) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3938 (byte-defop-compiler-1 mapcar-extents byte-compile-funarg-1-2) |
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3939 |
428 | 3940 (byte-defop-compiler-1 let) |
3941 (byte-defop-compiler-1 let*) | |
3942 | |
4885
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
3943 (byte-defop-compiler-1 integerp) |
5301
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
3944 (byte-defop-compiler-1 eql) |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3945 (byte-defop-compiler-1 fillarray) |
4885
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
3946 |
428 | 3947 (defun byte-compile-progn (form) |
3948 (byte-compile-body-do-effect (cdr form))) | |
3949 | |
3950 (defun byte-compile-prog1 (form) | |
3951 (setq form (cdr form)) | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3952 ;; #'prog1 never returns multiple values: |
4686
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
3953 (byte-compile-form-do-effect `(or ,(pop form) nil)) |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3954 (byte-compile-body form t)) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3955 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3956 (defun byte-compile-multiple-value-prog1 (form) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3957 (setq form (cdr form)) |
428 | 3958 (byte-compile-form-do-effect (pop form)) |
3959 (byte-compile-body form t)) | |
3960 | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3961 (defun byte-compile-values (form) |
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5358
diff
changeset
|
3962 (if (eql 2 (length form)) |
4686
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
3963 (if (byte-compile-constp (second form)) |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
3964 (byte-compile-form-do-effect (second form)) |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
3965 ;; #'or compiles to bytecode, #'values doesn't: |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
3966 (byte-compile-form-do-effect `(or ,(second form) nil))) |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3967 (byte-compile-normal-call form))) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3968 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3969 (defun byte-compile-values-list (form) |
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5358
diff
changeset
|
3970 (if (and (eql 2 (length form)) |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3971 (or (null (second form)) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3972 (and (consp (second form)) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3973 (eq (car (second form)) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3974 'quote) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3975 (not (symbolp (car-safe (cdr (second form)))))))) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3976 (byte-compile-form-do-effect (car-safe (cdr (second form)))) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3977 (byte-compile-normal-call form))) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3978 |
428 | 3979 (defun byte-compile-prog2 (form) |
3980 (setq form (cdr form)) | |
3981 (byte-compile-form (pop form) t) | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3982 ;; #'prog2 never returns multiple values: |
4686
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
3983 (byte-compile-form-do-effect `(or ,(pop form) nil)) |
428 | 3984 (byte-compile-body form t)) |
3985 | |
3986 (defmacro byte-compile-goto-if (cond discard tag) | |
3987 `(byte-compile-goto | |
3988 (if ,cond | |
3989 (if ,discard 'byte-goto-if-not-nil 'byte-goto-if-not-nil-else-pop) | |
3990 (if ,discard 'byte-goto-if-nil 'byte-goto-if-nil-else-pop)) | |
3991 ,tag)) | |
3992 | |
3993 (defun byte-compile-if (form) | |
3994 (byte-compile-form (car (cdr form))) | |
3995 (if (null (nthcdr 3 form)) | |
3996 ;; No else-forms | |
3997 (let ((donetag (byte-compile-make-tag))) | |
3998 (byte-compile-goto-if nil for-effect donetag) | |
3999 (byte-compile-form (nth 2 form) for-effect) | |
4000 (byte-compile-out-tag donetag)) | |
4001 (let ((donetag (byte-compile-make-tag)) (elsetag (byte-compile-make-tag))) | |
4002 (byte-compile-goto 'byte-goto-if-nil elsetag) | |
4003 (byte-compile-form (nth 2 form) for-effect) | |
4004 (byte-compile-goto 'byte-goto donetag) | |
4005 (byte-compile-out-tag elsetag) | |
4006 (byte-compile-body (cdr (cdr (cdr form))) for-effect) | |
4007 (byte-compile-out-tag donetag))) | |
4008 (setq for-effect nil)) | |
4009 | |
4010 (defun byte-compile-cond (clauses) | |
4011 (let ((donetag (byte-compile-make-tag)) | |
4012 nexttag clause) | |
4013 (while (setq clauses (cdr clauses)) | |
4014 (setq clause (car clauses)) | |
4015 (cond ((or (eq (car clause) t) | |
4016 (and (eq (car-safe (car clause)) 'quote) | |
4017 (car-safe (cdr-safe (car clause))))) | |
4018 ;; Unconditional clause | |
4019 (setq clause (cons t clause) | |
4020 clauses nil)) | |
4021 ((cdr clauses) | |
4022 (byte-compile-form (car clause)) | |
4023 (if (null (cdr clause)) | |
4024 ;; First clause is a singleton. | |
4025 (byte-compile-goto-if t for-effect donetag) | |
4026 (setq nexttag (byte-compile-make-tag)) | |
4027 (byte-compile-goto 'byte-goto-if-nil nexttag) | |
4028 (byte-compile-body (cdr clause) for-effect) | |
4029 (byte-compile-goto 'byte-goto donetag) | |
4030 (byte-compile-out-tag nexttag))))) | |
4031 ;; Last clause | |
4032 (and (cdr clause) (not (eq (car clause) t)) | |
4033 (progn (byte-compile-form (car clause)) | |
4034 (byte-compile-goto-if nil for-effect donetag) | |
4035 (setq clause (cdr clause)))) | |
4036 (byte-compile-body-do-effect clause) | |
4037 (byte-compile-out-tag donetag))) | |
4038 | |
4039 (defun byte-compile-and (form) | |
4040 (let ((failtag (byte-compile-make-tag)) | |
4041 (args (cdr form))) | |
4042 (if (null args) | |
4043 (byte-compile-form-do-effect t) | |
4044 (while (cdr args) | |
4045 (byte-compile-form (car args)) | |
4046 (byte-compile-goto-if nil for-effect failtag) | |
4047 (setq args (cdr args))) | |
4048 (byte-compile-form-do-effect (car args)) | |
4049 (byte-compile-out-tag failtag)))) | |
4050 | |
4051 (defun byte-compile-or (form) | |
4052 (let ((wintag (byte-compile-make-tag)) | |
4053 (args (cdr form))) | |
4054 (if (null args) | |
4055 (byte-compile-form-do-effect nil) | |
4056 (while (cdr args) | |
4057 (byte-compile-form (car args)) | |
4058 (byte-compile-goto-if t for-effect wintag) | |
4059 (setq args (cdr args))) | |
4060 (byte-compile-form-do-effect (car args)) | |
4061 (byte-compile-out-tag wintag)))) | |
4062 | |
4063 (defun byte-compile-while (form) | |
4064 (let ((endtag (byte-compile-make-tag)) | |
4065 (looptag (byte-compile-make-tag))) | |
4066 (byte-compile-out-tag looptag) | |
4067 (byte-compile-form (car (cdr form))) | |
4068 (byte-compile-goto-if nil for-effect endtag) | |
4069 (byte-compile-body (cdr (cdr form)) t) | |
4070 (byte-compile-goto 'byte-goto looptag) | |
4071 (byte-compile-out-tag endtag) | |
4072 (setq for-effect nil))) | |
4073 | |
4074 (defun byte-compile-funcall (form) | |
5566
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
4075 (if (and (memq 'callargs byte-compile-warnings) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
4076 (byte-compile-constp (second form))) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
4077 (byte-compile-callargs-warn (cons (cl-const-expr-val (second form)) |
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
4078 (nthcdr 2 form)))) |
4783
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4775
diff
changeset
|
4079 (mapc 'byte-compile-form (cdr form)) |
428 | 4080 (byte-compile-out 'byte-call (length (cdr (cdr form))))) |
4081 | |
4082 | |
4083 (defun byte-compile-let (form) | |
4084 ;; First compute the binding values in the old scope. | |
4085 (let ((varlist (car (cdr form)))) | |
4086 (while varlist | |
4087 (if (consp (car varlist)) | |
4088 (byte-compile-form (car (cdr (car varlist)))) | |
4089 (byte-compile-push-constant nil)) | |
4090 (setq varlist (cdr varlist)))) | |
4091 (let ((byte-compile-bound-variables | |
4092 (cons 'new-scope byte-compile-bound-variables)) | |
4093 (varlist (reverse (car (cdr form)))) | |
4094 (extra-flags | |
4095 ;; If this let is of the form (let (...) (byte-code ...)) | |
4096 ;; then assume that it is the result of a transformation of | |
4097 ;; ((lambda (...) (byte-code ... )) ...) and thus compile | |
4098 ;; the variable bindings as if they were arglist bindings | |
4099 ;; (which matters for what warnings.) | |
4100 (if (eq 'byte-code (car-safe (nth 2 form))) | |
4101 byte-compile-arglist-bit | |
4102 nil))) | |
4103 (while varlist | |
4104 (byte-compile-variable-ref 'byte-varbind | |
4105 (if (consp (car varlist)) | |
4106 (car (car varlist)) | |
4107 (car varlist)) | |
4108 extra-flags) | |
4109 (setq varlist (cdr varlist))) | |
4110 (byte-compile-body-do-effect (cdr (cdr form))) | |
4111 (if (memq 'unused-vars byte-compile-warnings) | |
4112 ;; done compiling in this scope, warn now. | |
4113 (byte-compile-warn-about-unused-variables)) | |
4114 (byte-compile-out 'byte-unbind (length (car (cdr form)))))) | |
4115 | |
4116 (defun byte-compile-let* (form) | |
4117 (let ((byte-compile-bound-variables | |
4118 (cons 'new-scope byte-compile-bound-variables)) | |
4119 (varlist (copy-sequence (car (cdr form))))) | |
4120 (while varlist | |
4121 (if (atom (car varlist)) | |
4122 (byte-compile-push-constant nil) | |
4123 (byte-compile-form (car (cdr (car varlist)))) | |
4124 (setcar varlist (car (car varlist)))) | |
4125 (byte-compile-variable-ref 'byte-varbind (car varlist)) | |
4126 (setq varlist (cdr varlist))) | |
4127 (byte-compile-body-do-effect (cdr (cdr form))) | |
4128 (if (memq 'unused-vars byte-compile-warnings) | |
4129 ;; done compiling in this scope, warn now. | |
4130 (byte-compile-warn-about-unused-variables)) | |
4131 (byte-compile-out 'byte-unbind (length (car (cdr form)))))) | |
4132 | |
4885
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4133 ;; We've renamed the integerp bytecode to fixnump, and changed its semantics |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4134 ;; accordingly. This means #'integerp itself can't be as fast as it used to |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4135 ;; be, since it no longer has a bytecode to itself. As it happens, though, |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4136 ;; most of the non-core calls to #'integerp are in contexts where it is |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4137 ;; either going to receive a fixnum, or something non-numeric entirely; the |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4138 ;; contexts where it needs to distinguish between an integer and a float are |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4139 ;; very rare. So, we can have (integerp X) compile to: |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4140 ;; |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4141 ;; (or (fixnump X) (and (numberp X) (funcall #'integerp X))) |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4142 ;; |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4143 ;; without the multiple evaluation of X, and where #'fixnump and #'numberp |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4144 ;; both have bytecodes. We ignore for-effect, because byte-optimize.el will |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4145 ;; delete this call in its presence. |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4146 ;; |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4147 ;; This approach is byte-code compatible with 21.4 and with earlier 21.5 |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4148 ;; (except that earlier 21.5 with bignum support will confuse Bfixnump and |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4149 ;; Bintegerp; which it did in dealing with byte-compiled code from 21.4 |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4150 ;; anyway). |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4151 |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4152 (defun byte-compile-integerp (form) |
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5358
diff
changeset
|
4153 (if (not (eql (length form) 2)) |
4885
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4154 (byte-compile-subr-wrong-args form 1) |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4155 (let ((donetag (byte-compile-make-tag)) |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4156 (wintag (byte-compile-make-tag)) |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4157 (failtag (byte-compile-make-tag))) |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4158 (byte-compile-constant 'integerp) |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4159 (byte-compile-form (second form)) |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4160 (byte-compile-out 'byte-dup 0) |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4161 (byte-compile-out 'byte-fixnump 0) |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4162 (byte-compile-goto 'byte-goto-if-not-nil wintag) |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4163 (byte-compile-out 'byte-dup 0) |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4164 (byte-compile-out 'byte-numberp 0) |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4165 (byte-compile-goto 'byte-goto-if-nil failtag) |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4166 (byte-compile-out 'byte-call 1) |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4167 ;; At this point, the only thing from this function remaining on the |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4168 ;; stack is the return value of the called #'integerp, which reflects |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4169 ;; exactly what we want. Go directly to donetag, do not discard |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4170 ;; anything. |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4171 (byte-compile-goto 'byte-goto donetag) |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4172 (byte-compile-out-tag failtag) |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4173 (byte-compile-discard) |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4174 (byte-compile-discard) |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4175 (byte-compile-constant nil) |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4176 (byte-compile-goto 'byte-goto donetag) |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4177 (byte-compile-out-tag wintag) |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4178 (byte-compile-discard) |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4179 (byte-compile-discard) |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4180 (byte-compile-constant t) |
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4181 (byte-compile-out-tag donetag)))) |
428 | 4182 |
5301
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4183 (defun byte-compile-eql (form) |
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4184 (if (eql 3 (length form)) |
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4185 (let ((donetag (byte-compile-make-tag)) |
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4186 (eqtag (byte-compile-make-tag))) |
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4187 (mapc 'byte-compile-form (cdr form)) |
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4188 (byte-compile-out 'byte-dup 0) |
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4189 (byte-compile-out 'byte-numberp 0) |
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4190 (byte-compile-goto 'byte-goto-if-nil eqtag) |
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4191 (byte-compile-out 'byte-dup 0) |
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4192 (byte-compile-out 'byte-fixnump 0) |
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4193 (byte-compile-goto 'byte-goto-if-not-nil eqtag) |
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4194 (byte-compile-out 'byte-equal 0) |
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4195 (byte-compile-goto 'byte-goto donetag) |
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4196 (byte-compile-out-tag eqtag) |
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4197 (byte-compile-out 'byte-eq 0) |
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4198 (byte-compile-out-tag donetag)) |
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4199 (byte-compile-subr-wrong-args form 2))) |
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4200 |
428 | 4201 ;;(byte-defop-compiler-1 /= byte-compile-negated) |
4202 (byte-defop-compiler-1 atom byte-compile-negated) | |
4203 (byte-defop-compiler-1 nlistp byte-compile-negated) | |
4204 | |
4205 ;;(put '/= 'byte-compile-negated-op '=) | |
4206 (put 'atom 'byte-compile-negated-op 'consp) | |
4207 (put 'nlistp 'byte-compile-negated-op 'listp) | |
4208 | |
4209 (defun byte-compile-negated (form) | |
4210 (byte-compile-form-do-effect (byte-compile-negation-optimizer form))) | |
4211 | |
4212 ;; Even when optimization is off, atom is optimized to (not (consp ...)). | |
4213 (defun byte-compile-negation-optimizer (form) | |
4214 ;; an optimizer for forms where <form1> is less efficient than (not <form2>) | |
4215 (list 'not | |
4216 (cons (or (get (car form) 'byte-compile-negated-op) | |
4217 (error | |
4218 "Compiler error: `%s' has no `byte-compile-negated-op' property" | |
4219 (car form))) | |
4220 (cdr form)))) | |
4221 | |
4905
755ae5b97edb
Change "special form" to "special operator" in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4885
diff
changeset
|
4222 ;;; other tricky macro-like special-operators |
428 | 4223 |
4224 (byte-defop-compiler-1 catch) | |
4225 (byte-defop-compiler-1 unwind-protect) | |
4226 (byte-defop-compiler-1 condition-case) | |
4227 (byte-defop-compiler-1 save-excursion) | |
4228 (byte-defop-compiler-1 save-current-buffer) | |
4229 (byte-defop-compiler-1 save-restriction) | |
4230 (byte-defop-compiler-1 with-output-to-temp-buffer) | |
4231 ;; no track-mouse. | |
4232 | |
5356
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4233 (defvar byte-compile-active-blocks nil) |
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4234 |
428 | 4235 (defun byte-compile-catch (form) |
5356
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4236 "Byte-compile and return a `catch' from. |
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4237 |
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4238 If FORM is the result of macroexpanding a `block' form (the TAG argument is |
5376
4b529b940e2e
Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5374
diff
changeset
|
4239 a quoted symbol with a `cl-block-name' property) and there is no |
5356
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4240 corresponding `return-from' within the block--or equivalently, it was |
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4241 optimized away--just byte compile and return the BODY." |
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4242 (let* ((symbol (car-safe (cdr-safe (nth 1 form)))) |
5376
4b529b940e2e
Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5374
diff
changeset
|
4243 (not-present '#:not-present) |
4b529b940e2e
Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5374
diff
changeset
|
4244 (block (and symbol (symbolp symbol) |
4b529b940e2e
Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5374
diff
changeset
|
4245 (get symbol 'cl-block-name not-present))) |
4b529b940e2e
Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5374
diff
changeset
|
4246 (elt (and (not (eq block not-present)) (list block))) |
5356
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4247 (byte-compile-active-blocks |
5376
4b529b940e2e
Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5374
diff
changeset
|
4248 (if elt |
5356
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4249 (cons elt byte-compile-active-blocks) |
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4250 byte-compile-active-blocks)) |
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4251 (body |
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4252 (byte-compile-top-level (cons 'progn (cddr form)) |
5377
eac2e6bd5b2c
Correct some minor problems in my last change.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5376
diff
changeset
|
4253 (and (not elt) for-effect)))) |
5376
4b529b940e2e
Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5374
diff
changeset
|
4254 (if (and elt (not (cdr elt))) |
5356
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4255 ;; A lexical block without any contained return-from clauses: |
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4256 (byte-compile-form body) |
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4257 ;; A normal catch call, or a lexical block with a contained |
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4258 ;; return-from clause. |
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4259 (byte-compile-form (car (cdr form))) |
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4260 (byte-compile-push-constant body) |
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4261 (byte-compile-out 'byte-catch 0)))) |
5353
38e24b8be4ea
Improve the lexical scoping in #'block, #'return-from.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
4262 |
428 | 4263 (defun byte-compile-unwind-protect (form) |
4264 (byte-compile-push-constant | |
4265 (byte-compile-top-level-body (cdr (cdr form)) t)) | |
4266 (byte-compile-out 'byte-unwind-protect 0) | |
4267 (byte-compile-form-do-effect (car (cdr form))) | |
4268 (byte-compile-out 'byte-unbind 1)) | |
4269 | |
4270 ;;(defun byte-compile-track-mouse (form) | |
4271 ;; (byte-compile-form | |
4272 ;; (list | |
4273 ;; 'funcall | |
4274 ;; (list 'quote | |
4275 ;; (list 'lambda nil | |
4276 ;; (cons 'track-mouse | |
4277 ;; (byte-compile-top-level-body (cdr form)))))))) | |
4278 | |
4279 (defun byte-compile-condition-case (form) | |
4280 (let* ((var (nth 1 form)) | |
4281 (byte-compile-bound-variables | |
4282 (if var | |
4283 (cons (cons var 0) | |
4284 (cons 'new-scope byte-compile-bound-variables)) | |
4285 (cons 'new-scope byte-compile-bound-variables)))) | |
4286 (or (symbolp var) | |
4287 (byte-compile-warn | |
4288 "%s is not a variable-name or nil (in condition-case)" | |
4289 (prin1-to-string var))) | |
4290 (byte-compile-push-constant var) | |
4291 (byte-compile-push-constant (byte-compile-top-level | |
4292 (nth 2 form) for-effect)) | |
4293 (let ((clauses (cdr (cdr (cdr form)))) | |
4294 compiled-clauses) | |
4295 (while clauses | |
4296 (let* ((clause (car clauses)) | |
4297 (condition (car clause))) | |
4298 (cond ((not (or (symbolp condition) | |
4299 (and (listp condition) | |
4300 (let ((syms condition) (ok t)) | |
4301 (while syms | |
4302 (if (not (symbolp (car syms))) | |
4303 (setq ok nil)) | |
4304 (setq syms (cdr syms))) | |
4305 ok)))) | |
4306 (byte-compile-warn | |
4307 "%s is not a symbol naming a condition or a list of such (in condition-case)" | |
4308 (prin1-to-string condition))) | |
4309 ;; ((not (or (eq condition 't) | |
4310 ;; (and (stringp (get condition 'error-message)) | |
4311 ;; (consp (get condition 'error-conditions))))) | |
4312 ;; (byte-compile-warn | |
4313 ;; "%s is not a known condition name (in condition-case)" | |
4314 ;; condition)) | |
4315 ) | |
4316 (setq compiled-clauses | |
4317 (cons (cons condition | |
4318 (byte-compile-top-level-body | |
4319 (cdr clause) for-effect)) | |
4320 compiled-clauses))) | |
4321 (setq clauses (cdr clauses))) | |
4322 (byte-compile-push-constant (nreverse compiled-clauses))) | |
4323 (if (memq 'unused-vars byte-compile-warnings) | |
4324 ;; done compiling in this scope, warn now. | |
4325 (byte-compile-warn-about-unused-variables)) | |
4326 (byte-compile-out 'byte-condition-case 0))) | |
4327 | |
4328 | |
4329 (defun byte-compile-save-excursion (form) | |
4330 (byte-compile-out 'byte-save-excursion 0) | |
4331 (byte-compile-body-do-effect (cdr form)) | |
4332 (byte-compile-out 'byte-unbind 1)) | |
4333 | |
4334 (defun byte-compile-save-restriction (form) | |
4335 (byte-compile-out 'byte-save-restriction 0) | |
4336 (byte-compile-body-do-effect (cdr form)) | |
4337 (byte-compile-out 'byte-unbind 1)) | |
4338 | |
4339 (defun byte-compile-save-current-buffer (form) | |
5503
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
4340 (byte-compile-out 'byte-save-current-buffer 0) |
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
4341 (byte-compile-body-do-effect (cdr form)) |
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
4342 (byte-compile-out 'byte-unbind 1)) |
428 | 4343 |
4344 (defun byte-compile-with-output-to-temp-buffer (form) | |
4345 (byte-compile-form (car (cdr form))) | |
4346 (byte-compile-out 'byte-temp-output-buffer-setup 0) | |
4347 (byte-compile-body (cdr (cdr form))) | |
4348 (byte-compile-out 'byte-temp-output-buffer-show 0)) | |
5391
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
4349 |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4350 (defun byte-compile-multiple-value-call (form) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4351 (if (< (length form) 2) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4352 (progn |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4353 (byte-compile-warn-wrong-args form 1) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4354 (byte-compile-normal-call |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4355 `(signal 'wrong-number-of-arguments '(,(car form) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4356 ,(length (cdr form)))))) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4357 (setq form (cdr form)) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4358 (byte-compile-form (car form)) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4359 (byte-compile-push-constant 0) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4360 (byte-compile-variable-ref 'byte-varref 'multiple-values-limit) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4361 ;; bind-multiple-value-limits leaves two existing values on the stack, |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4362 ;; and pushes a new value, the specpdl_depth() at the time it was |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4363 ;; called. |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4364 (byte-compile-out 'byte-bind-multiple-value-limits 0) |
4783
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4775
diff
changeset
|
4365 (mapc 'byte-compile-form (cdr form)) |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4366 ;; Most of the other code puts this sort of value in the program stream, |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4367 ;; not pushing it on the stack. |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4368 (byte-compile-push-constant (+ 3 (length form))) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4369 (byte-compile-out 'byte-multiple-value-call (+ 3 (length form))) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4370 (pushnew '(subrp (symbol-function 'multiple-value-call)) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4371 byte-compile-checks-on-load |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4372 :test #'equal))) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4373 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4374 (defun byte-compile-multiple-value-list-internal (form) |
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5358
diff
changeset
|
4375 (if (not (eql 4 (length form))) |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4376 (progn |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4377 (byte-compile-warn-wrong-args form 3) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4378 (byte-compile-normal-call |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4379 `(signal 'wrong-number-of-arguments '(,(car form) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4380 ,(length (cdr form)))))) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4381 (byte-compile-form (nth 1 form)) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4382 (byte-compile-form (nth 2 form)) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4383 (byte-compile-out 'byte-bind-multiple-value-limits 0) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4384 (byte-compile-form (nth 3 form)) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4385 (byte-compile-out (get (car form) 'byte-opcode) 0) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4386 (pushnew '(subrp (symbol-function 'multiple-value-call)) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4387 byte-compile-checks-on-load |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4388 :test #'equal))) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4389 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4390 (defun byte-compile-throw (form) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4391 ;; We can't use byte-compile-two-args for throw because in the event that |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4392 ;; the form does not have two args, it tries to #'funcall it expecting a |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4393 ;; runtime wrong-number-of-arguments error. Now that #'throw is a special |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4394 ;; form, it provokes an invalid-function error instead (or at least it |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4395 ;; should; there's a kludge around for the moment in eval.c that avoids |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4396 ;; that, but this file should not assume that that will always be there). |
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5358
diff
changeset
|
4397 (if (not (eql 2 (length (cdr form)))) |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4398 (progn |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4399 (byte-compile-warn-wrong-args form 2) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4400 (byte-compile-normal-call |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4401 `(signal 'wrong-number-of-arguments '(,(car form) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4402 ,(length (cdr form)))))) |
5356
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4403 ;; If this form was macroexpanded from `return-from', mark the |
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4404 ;; corresponding block as having been referenced. |
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4405 (let* ((symbol (car-safe (cdr-safe (nth 1 form)))) |
5376
4b529b940e2e
Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5374
diff
changeset
|
4406 (not-present '#:not-present) |
5377
eac2e6bd5b2c
Correct some minor problems in my last change.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5376
diff
changeset
|
4407 (block (if (and symbol (symbolp symbol)) |
eac2e6bd5b2c
Correct some minor problems in my last change.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5376
diff
changeset
|
4408 (get symbol 'cl-block-name not-present) |
eac2e6bd5b2c
Correct some minor problems in my last change.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5376
diff
changeset
|
4409 not-present)) |
5376
4b529b940e2e
Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5374
diff
changeset
|
4410 (assq (and (not (eq block not-present)) |
4b529b940e2e
Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5374
diff
changeset
|
4411 (assq block byte-compile-active-blocks)))) |
5377
eac2e6bd5b2c
Correct some minor problems in my last change.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5376
diff
changeset
|
4412 (if assq |
eac2e6bd5b2c
Correct some minor problems in my last change.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5376
diff
changeset
|
4413 (setcdr assq t) |
eac2e6bd5b2c
Correct some minor problems in my last change.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5376
diff
changeset
|
4414 (if (not (eq block not-present)) |
eac2e6bd5b2c
Correct some minor problems in my last change.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5376
diff
changeset
|
4415 ;; No corresponding enclosing block. |
eac2e6bd5b2c
Correct some minor problems in my last change.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5376
diff
changeset
|
4416 (byte-compile-warn "return-from: no enclosing block named `%s'" |
eac2e6bd5b2c
Correct some minor problems in my last change.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5376
diff
changeset
|
4417 block)))) |
5376
4b529b940e2e
Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5374
diff
changeset
|
4418 (mapc 'byte-compile-form (cdr form)) ;; Push the arguments |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4419 (byte-compile-out (get (car form) 'byte-opcode) 0) |
5376
4b529b940e2e
Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5374
diff
changeset
|
4420 (pushnew '(null (function-max-args 'throw)) byte-compile-checks-on-load |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4421 :test #'equal))) |
428 | 4422 |
4423 ;;; top-level forms elsewhere | |
4424 | |
4425 (byte-defop-compiler-1 defun) | |
4426 (byte-defop-compiler-1 defmacro) | |
4427 (byte-defop-compiler-1 defvar) | |
442 | 4428 (byte-defop-compiler-1 defvar byte-compile-defvar-or-defconst) |
4429 (byte-defop-compiler-1 defconst byte-compile-defvar-or-defconst) | |
428 | 4430 (byte-defop-compiler-1 autoload) |
4431 ;; According to Mly this can go now that lambda is a macro | |
4432 ;(byte-defop-compiler-1 lambda byte-compile-lambda-form) | |
4433 (byte-defop-compiler-1 defalias) | |
4434 (byte-defop-compiler-1 define-function) | |
4435 | |
4436 (defun byte-compile-defun (form) | |
4437 ;; This is not used for file-level defuns with doc strings. | |
4438 (byte-compile-two-args ; Use this to avoid byte-compile-fset's warning. | |
4439 (list 'fset (list 'quote (nth 1 form)) | |
4440 (byte-compile-byte-code-maker | |
4441 (byte-compile-lambda (cons 'lambda (cdr (cdr form))))))) | |
4442 (byte-compile-discard) | |
4443 (byte-compile-constant (nth 1 form))) | |
4444 | |
4445 (defun byte-compile-defmacro (form) | |
4446 ;; This is not used for file-level defmacros with doc strings. | |
4447 (byte-compile-body-do-effect | |
4448 (list (list 'fset (list 'quote (nth 1 form)) | |
4449 (let ((code (byte-compile-byte-code-maker | |
4450 (byte-compile-lambda | |
4451 (cons 'lambda (cdr (cdr form))))))) | |
4452 (if (eq (car-safe code) 'make-byte-code) | |
4453 (list 'cons ''macro code) | |
4454 (list 'quote (cons 'macro (eval code)))))) | |
4455 (list 'quote (nth 1 form))))) | |
4456 | |
442 | 4457 (defun byte-compile-defvar-or-defconst (form) |
4458 ;; This is not used for file-level defvar/defconsts with doc strings: | |
4459 ;; byte-compile-file-form-defvar-or-defconst will be used in that case. | |
4460 ;; (defvar|defconst VAR [VALUE [DOCSTRING]]) | |
4461 (let ((fun (nth 0 form)) | |
4462 (var (nth 1 form)) | |
428 | 4463 (value (nth 2 form)) |
4464 (string (nth 3 form))) | |
442 | 4465 (when (> (length form) 4) |
4466 (byte-compile-warn | |
4467 "%s %s called with %d arguments, but accepts only %s" | |
4468 fun var (length (cdr form)) 3)) | |
4469 (when (memq 'free-vars byte-compile-warnings) | |
4470 (push (cons var byte-compile-global-bit) byte-compile-bound-variables)) | |
428 | 4471 (byte-compile-body-do-effect |
442 | 4472 (list |
4473 ;; Put the defined variable in this library's load-history entry | |
444 | 4474 ;; just as a real defvar would, but only in top-level forms with values. |
4475 (when (and (> (length form) 2) | |
4476 (null byte-compile-current-form)) | |
442 | 4477 `(push ',var current-load-list)) |
4478 (when (> (length form) 3) | |
4479 (when (and string (not (stringp string))) | |
4480 (byte-compile-warn "Third arg to %s %s is not a string: %s" | |
4481 fun var string)) | |
4482 `(put ',var 'variable-documentation ,string)) | |
4483 (if (cdr (cdr form)) ; `value' provided | |
4484 (if (eq fun 'defconst) | |
4485 ;; `defconst' sets `var' unconditionally. | |
4486 `(setq ,var ,value) | |
4487 ;; `defvar' sets `var' only when unbound. | |
1672 | 4488 `(if (not (default-boundp ',var)) (set-default ',var ,value)))) |
442 | 4489 `',var)))) |
428 | 4490 |
4491 (defun byte-compile-autoload (form) | |
4492 (and (byte-compile-constp (nth 1 form)) | |
4493 (byte-compile-constp (nth 5 form)) | |
4494 (memq (eval (nth 5 form)) '(t macro)) ; macro-p | |
4495 (not (fboundp (eval (nth 1 form)))) | |
4496 (byte-compile-warn | |
4497 "The compiler ignores `autoload' except at top level. You should | |
4498 probably put the autoload of the macro `%s' at top-level." | |
4499 (eval (nth 1 form)))) | |
4500 (byte-compile-normal-call form)) | |
4501 | |
4502 ;; Lambda's in valid places are handled as special cases by various code. | |
4503 ;; The ones that remain are errors. | |
4504 ;; According to Mly this can go now that lambda is a macro | |
4505 ;(defun byte-compile-lambda-form (form) | |
4506 ; (byte-compile-warn | |
4507 ; "`lambda' used in function position is invalid: probably you mean #'%s" | |
4508 ; (let ((print-escape-newlines t) | |
4509 ; (print-level 4) | |
4510 ; (print-length 4)) | |
4511 ; (prin1-to-string form))) | |
4512 ; (byte-compile-normal-call | |
4513 ; (list 'signal ''error | |
4514 ; (list 'quote (list "`lambda' used in function position" form))))) | |
4515 | |
4516 ;; Compile normally, but deal with warnings for the function being defined. | |
4517 (defun byte-compile-defalias (form) | |
4518 (if (and (consp (cdr form)) (consp (nth 1 form)) | |
4519 (eq (car (nth 1 form)) 'quote) | |
4520 (consp (cdr (nth 1 form))) | |
4521 (symbolp (nth 1 (nth 1 form))) | |
4522 (consp (nthcdr 2 form)) | |
4523 (consp (nth 2 form)) | |
4524 (eq (car (nth 2 form)) 'quote) | |
4525 (consp (cdr (nth 2 form))) | |
4526 (symbolp (nth 1 (nth 2 form)))) | |
4527 (progn | |
4528 (byte-compile-defalias-warn (nth 1 (nth 1 form)) | |
4529 (nth 1 (nth 2 form))) | |
4530 (setq byte-compile-function-environment | |
4531 (cons (cons (nth 1 (nth 1 form)) | |
4532 (nth 1 (nth 2 form))) | |
4533 byte-compile-function-environment)))) | |
4534 (byte-compile-normal-call form)) | |
4535 | |
4536 (defun byte-compile-define-function (form) | |
4537 (byte-compile-defalias form)) | |
4538 | |
4539 ;; Turn off warnings about prior calls to the function being defalias'd. | |
4540 ;; This could be smarter and compare those calls with | |
4541 ;; the function it is being aliased to. | |
4542 (defun byte-compile-defalias-warn (new alias) | |
4543 (let ((calls (assq new byte-compile-unresolved-functions))) | |
4544 (if calls | |
4545 (setq byte-compile-unresolved-functions | |
4546 (delq calls byte-compile-unresolved-functions))))) | |
4547 | |
4548 ;;; tags | |
4549 | |
4550 ;; Note: Most operations will strip off the 'TAG, but it speeds up | |
4551 ;; optimization to have the 'TAG as a part of the tag. | |
4552 ;; Tags will be (TAG . (tag-number . stack-depth)). | |
4553 (defun byte-compile-make-tag () | |
4554 (list 'TAG (setq byte-compile-tag-number (1+ byte-compile-tag-number)))) | |
4555 | |
4556 | |
4557 (defun byte-compile-out-tag (tag) | |
4558 (push tag byte-compile-output) | |
4559 (if (cdr (cdr tag)) | |
4560 (progn | |
4561 ;; ## remove this someday | |
4562 (and byte-compile-depth | |
4563 (not (= (cdr (cdr tag)) byte-compile-depth)) | |
4564 (error "Compiler bug: depth conflict at tag %d" (car (cdr tag)))) | |
4565 (setq byte-compile-depth (cdr (cdr tag)))) | |
4566 (setcdr (cdr tag) byte-compile-depth))) | |
4567 | |
4568 (defun byte-compile-goto (opcode tag) | |
4569 (push (cons opcode tag) byte-compile-output) | |
4570 (setcdr (cdr tag) (if (memq opcode byte-goto-always-pop-ops) | |
4571 (1- byte-compile-depth) | |
4572 byte-compile-depth)) | |
4573 (setq byte-compile-depth (and (not (eq opcode 'byte-goto)) | |
4574 (1- byte-compile-depth)))) | |
4575 | |
4576 (defun byte-compile-out (opcode offset) | |
4577 (push (cons opcode offset) byte-compile-output) | |
4578 (case opcode | |
4579 (byte-call | |
4580 (setq byte-compile-depth (- byte-compile-depth offset))) | |
4581 (byte-return | |
4582 ;; This is actually an unnecessary case, because there should be | |
4583 ;; no more opcodes behind byte-return. | |
4584 (setq byte-compile-depth nil)) | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4585 (byte-multiple-value-call |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4586 (setq byte-compile-depth (- byte-compile-depth offset))) |
428 | 4587 (t |
4588 (setq byte-compile-depth (+ byte-compile-depth | |
4589 (or (aref byte-stack+-info | |
4590 (symbol-value opcode)) | |
4591 (- (1- offset)))) | |
4592 byte-compile-maxdepth (max byte-compile-depth | |
4593 byte-compile-maxdepth)))) | |
4594 ;;(if (< byte-compile-depth 0) (error "Compiler error: stack underflow")) | |
4595 ) | |
4596 | |
4597 | |
4598 ;;; call tree stuff | |
4599 | |
4600 (defun byte-compile-annotate-call-tree (form) | |
4601 (let (entry) | |
4602 ;; annotate the current call | |
4603 (if (setq entry (assq (car form) byte-compile-call-tree)) | |
4604 (or (memq byte-compile-current-form (nth 1 entry)) ;callers | |
4605 (setcar (cdr entry) | |
4606 (cons byte-compile-current-form (nth 1 entry)))) | |
4607 (push (list (car form) (list byte-compile-current-form) nil) | |
4608 byte-compile-call-tree)) | |
4609 ;; annotate the current function | |
4610 (if (setq entry (assq byte-compile-current-form byte-compile-call-tree)) | |
4611 (or (memq (car form) (nth 2 entry)) ;called | |
4612 (setcar (cdr (cdr entry)) | |
4613 (cons (car form) (nth 2 entry)))) | |
4614 (push (list byte-compile-current-form nil (list (car form))) | |
4615 byte-compile-call-tree)))) | |
4616 | |
4617 ;; Renamed from byte-compile-report-call-tree | |
4618 ;; to avoid interfering with completion of byte-compile-file. | |
4619 ;;;###autoload | |
4620 (defun display-call-tree (&optional filename) | |
4621 "Display a call graph of a specified file. | |
4622 This lists which functions have been called, what functions called | |
4623 them, and what functions they call. The list includes all functions | |
4624 whose definitions have been compiled in this Emacs session, as well as | |
4625 all functions called by those functions. | |
4626 | |
4627 The call graph does not include macros, inline functions, or | |
4628 primitives that the byte-code interpreter knows about directly \(eq, | |
4629 cons, etc.\). | |
4630 | |
4631 The call tree also lists those functions which are not known to be called | |
4632 \(that is, to which no calls have been compiled\), and which cannot be | |
4633 invoked interactively." | |
4634 (interactive) | |
4635 (message "Generating call tree...") | |
4636 (with-output-to-temp-buffer "*Call-Tree*" | |
4637 (set-buffer "*Call-Tree*") | |
4638 (erase-buffer) | |
4639 (message "Generating call tree... (sorting on %s)" | |
4640 byte-compile-call-tree-sort) | |
4641 (insert "Call tree for " | |
4642 (cond ((null byte-compile-current-file) (or filename "???")) | |
4643 ((stringp byte-compile-current-file) | |
4644 byte-compile-current-file) | |
4645 (t (buffer-name byte-compile-current-file))) | |
4646 " sorted on " | |
4647 (prin1-to-string byte-compile-call-tree-sort) | |
4648 ":\n\n") | |
4649 (if byte-compile-call-tree-sort | |
4650 (setq byte-compile-call-tree | |
4651 (sort byte-compile-call-tree | |
4652 (cond | |
4653 ((eq byte-compile-call-tree-sort 'callers) | |
4654 #'(lambda (x y) (< (length (nth 1 x)) | |
4655 (length (nth 1 y))))) | |
4656 ((eq byte-compile-call-tree-sort 'calls) | |
4657 #'(lambda (x y) (< (length (nth 2 x)) | |
4658 (length (nth 2 y))))) | |
4659 ((eq byte-compile-call-tree-sort 'calls+callers) | |
4660 #'(lambda (x y) (< (+ (length (nth 1 x)) | |
4661 (length (nth 2 x))) | |
4662 (+ (length (nth 1 y)) | |
4663 (length (nth 2 y)))))) | |
4664 ((eq byte-compile-call-tree-sort 'name) | |
4665 #'(lambda (x y) (string< (car x) | |
4666 (car y)))) | |
4667 (t (error | |
4668 "`byte-compile-call-tree-sort': `%s' - unknown sort mode" | |
4669 byte-compile-call-tree-sort)))))) | |
4670 (message "Generating call tree...") | |
4671 (let ((rest byte-compile-call-tree) | |
4672 (b (current-buffer)) | |
4673 f p | |
4674 callers calls) | |
4675 (while rest | |
4676 (prin1 (car (car rest)) b) | |
4677 (setq callers (nth 1 (car rest)) | |
4678 calls (nth 2 (car rest))) | |
4679 (insert "\t" | |
4680 (cond ((not (fboundp (setq f (car (car rest))))) | |
4681 (if (null f) | |
4682 " <top level>";; shouldn't insert nil then, actually -sk | |
4683 " <not defined>")) | |
4684 ((subrp (setq f (symbol-function f))) | |
4685 " <subr>") | |
4686 ((symbolp f) | |
4687 (format " ==> %s" f)) | |
4688 ((compiled-function-p f) | |
4689 "<compiled function>") | |
4690 ((not (consp f)) | |
4691 "<malformed function>") | |
4692 ((eq 'macro (car f)) | |
4693 (if (or (compiled-function-p (cdr f)) | |
4694 (assq 'byte-code (cdr (cdr (cdr f))))) | |
4695 " <compiled macro>" | |
4696 " <macro>")) | |
4697 ((assq 'byte-code (cdr (cdr f))) | |
4698 "<compiled lambda>") | |
4699 ((eq 'lambda (car f)) | |
4700 "<function>") | |
4701 (t "???")) | |
4702 (format " (%d callers + %d calls = %d)" | |
4703 ;; Does the optimizer eliminate common subexpressions?-sk | |
4704 (length callers) | |
4705 (length calls) | |
4706 (+ (length callers) (length calls))) | |
4707 "\n") | |
4708 (if callers | |
4709 (progn | |
4710 (insert " called by:\n") | |
4711 (setq p (point)) | |
4712 (insert " " (if (car callers) | |
4713 (mapconcat 'symbol-name callers ", ") | |
4714 "<top level>")) | |
4715 (let ((fill-prefix " ")) | |
4716 (fill-region-as-paragraph p (point))))) | |
4717 (if calls | |
4718 (progn | |
4719 (insert " calls:\n") | |
4720 (setq p (point)) | |
4721 (insert " " (mapconcat 'symbol-name calls ", ")) | |
4722 (let ((fill-prefix " ")) | |
4723 (fill-region-as-paragraph p (point))))) | |
4724 (insert "\n") | |
4725 (setq rest (cdr rest))) | |
4726 | |
4727 (message "Generating call tree...(finding uncalled functions...)") | |
4728 (setq rest byte-compile-call-tree) | |
4729 (let ((uncalled nil)) | |
4730 (while rest | |
4731 (or (nth 1 (car rest)) | |
4732 (null (setq f (car (car rest)))) | |
4733 (byte-compile-fdefinition f t) | |
4734 (commandp (byte-compile-fdefinition f nil)) | |
4735 (setq uncalled (cons f uncalled))) | |
4736 (setq rest (cdr rest))) | |
4737 (if uncalled | |
4738 (let ((fill-prefix " ")) | |
4739 (insert "Noninteractive functions not known to be called:\n ") | |
4740 (setq p (point)) | |
4741 (insert (mapconcat 'symbol-name (nreverse uncalled) ", ")) | |
4742 (fill-region-as-paragraph p (point))))) | |
4743 ) | |
4744 (message "Generating call tree...done.") | |
4745 )) | |
4746 | |
4747 | |
4748 ;;; by crl@newton.purdue.edu | |
4749 ;;; Only works noninteractively. | |
4750 ;;;###autoload | |
4751 (defun batch-byte-compile () | |
4752 "Run `byte-compile-file' on the files remaining on the command line. | |
4753 Use this from the command line, with `-batch'; | |
4754 it won't work in an interactive Emacs. | |
4755 Each file is processed even if an error occurred previously. | |
444 | 4756 For example, invoke \"xemacs -batch -f batch-byte-compile $emacs/ ~/*.el\"." |
428 | 4757 ;; command-line-args-left is what is left of the command line (from |
4758 ;; startup.el) | |
4759 (defvar command-line-args-left) ;Avoid 'free variable' warning | |
4760 (if (not noninteractive) | |
4761 (error "`batch-byte-compile' is to be used only with -batch")) | |
4762 (let ((error nil)) | |
4763 (while command-line-args-left | |
442 | 4764 (if (null (batch-byte-compile-one-file)) |
4765 (setq error t))) | |
428 | 4766 (message "Done") |
4767 (kill-emacs (if error 1 0)))) | |
4768 | |
442 | 4769 ;;;###autoload |
4770 (defun batch-byte-compile-one-file () | |
4771 "Run `byte-compile-file' on a single file remaining on the command line. | |
4772 Use this from the command line, with `-batch'; | |
4773 it won't work in an interactive Emacs." | |
4774 ;; command-line-args-left is what is left of the command line (from | |
4775 ;; startup.el) | |
4776 (defvar command-line-args-left) ;Avoid 'free variable' warning | |
4777 (if (not noninteractive) | |
4778 (error "`batch-byte-compile-one-file' is to be used only with -batch")) | |
4779 (let (error | |
4780 (file-to-process (car command-line-args-left))) | |
4781 (setq command-line-args-left (cdr command-line-args-left)) | |
4782 (if (file-directory-p (expand-file-name file-to-process)) | |
4783 (let ((files (directory-files file-to-process)) | |
4784 source dest) | |
4785 (while files | |
4786 (if (and (string-match emacs-lisp-file-regexp (car files)) | |
4787 (not (auto-save-file-name-p (car files))) | |
4788 (setq source (expand-file-name | |
4789 (car files) | |
4790 file-to-process)) | |
4791 (setq dest (byte-compile-dest-file source)) | |
4792 (file-exists-p dest) | |
4793 (file-newer-than-file-p source dest)) | |
4794 (if (null (batch-byte-compile-1 source)) | |
4795 (setq error t))) | |
4796 (setq files (cdr files))) | |
4797 (null error)) | |
4798 (batch-byte-compile-1 file-to-process)))) | |
4799 | |
428 | 4800 (defun batch-byte-compile-1 (file) |
4801 (condition-case err | |
4802 (progn (byte-compile-file file) t) | |
4803 (error | |
4804 (princ ">>Error occurred processing ") | |
4805 (princ file) | |
4806 (princ ": ") | |
4807 (if (fboundp 'display-error) ; XEmacs 19.8+ | |
4808 (display-error err nil) | |
4809 (princ (or (get (car err) 'error-message) (car err))) | |
4783
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4775
diff
changeset
|
4810 (mapc #'(lambda (x) (princ " ") (prin1 x)) (cdr err))) |
428 | 4811 (princ "\n") |
4812 nil))) | |
4813 | |
4814 ;;;###autoload | |
4815 (defun batch-byte-recompile-directory-norecurse () | |
4816 "Same as `batch-byte-recompile-directory' but without recursion." | |
4817 (setq byte-recompile-directory-recursively nil) | |
4818 (batch-byte-recompile-directory)) | |
4819 | |
4820 ;;;###autoload | |
4821 (defun batch-byte-recompile-directory () | |
4822 "Runs `byte-recompile-directory' on the dirs remaining on the command line. | |
4823 Must be used only with `-batch', and kills Emacs on completion. | |
4824 For example, invoke `xemacs -batch -f batch-byte-recompile-directory .'." | |
4825 ;; command-line-args-left is what is left of the command line (startup.el) | |
4826 (defvar command-line-args-left) ;Avoid 'free variable' warning | |
4827 (if (not noninteractive) | |
4828 (error "batch-byte-recompile-directory is to be used only with -batch")) | |
4829 (or command-line-args-left | |
4830 (setq command-line-args-left '("."))) | |
4831 (let ((byte-recompile-directory-ignore-errors-p t)) | |
4832 (while command-line-args-left | |
4833 (byte-recompile-directory (car command-line-args-left)) | |
4834 (setq command-line-args-left (cdr command-line-args-left)))) | |
4835 (kill-emacs 0)) | |
4836 | |
4837 (make-obsolete 'elisp-compile-defun 'compile-defun) | |
4838 (make-obsolete 'byte-compile-report-call-tree 'display-call-tree) | |
4839 | |
4840 ;; other make-obsolete calls in obsolete.el. | |
4841 | |
4842 (provide 'byte-compile) | |
4843 (provide 'bytecomp) | |
4844 | |
4845 | |
4846 ;;; report metering (see the hacks in bytecode.c) | |
4847 | |
4848 (if (boundp 'byte-code-meter) | |
4849 (defun byte-compile-report-ops () | |
4850 (defvar byte-code-meter) | |
4851 (with-output-to-temp-buffer "*Meter*" | |
4852 (set-buffer "*Meter*") | |
4853 (let ((i 0) n op off) | |
4854 (while (< i 256) | |
4855 (setq n (aref (aref byte-code-meter 0) i) | |
4856 off nil) | |
4857 (if t ;(not (zerop n)) | |
4858 (progn | |
4859 (setq op i) | |
4860 (setq off nil) | |
4861 (cond ((< op byte-nth) | |
4862 (setq off (logand op 7)) | |
4863 (setq op (logand op 248))) | |
4864 ((>= op byte-constant) | |
4865 (setq off (- op byte-constant) | |
4866 op byte-constant))) | |
4867 (setq op (aref byte-code-vector op)) | |
4868 (insert (format "%-4d" i)) | |
4869 (insert (symbol-name op)) | |
4870 (if off (insert " [" (int-to-string off) "]")) | |
4871 (indent-to 40) | |
4872 (insert (int-to-string n) "\n"))) | |
4873 (setq i (1+ i))))))) | |
4874 | |
4875 | |
4876 ;; To avoid "lisp nesting exceeds max-lisp-eval-depth" when bytecomp compiles | |
4877 ;; itself, compile some of its most used recursive functions (at load time). | |
4878 ;; | |
4879 (eval-when-compile | |
4880 (or (compiled-function-p (symbol-function 'byte-compile-form)) | |
4881 (let ((byte-optimize nil) ; do it fast | |
4882 (byte-compile-warnings nil)) | |
5503
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
4883 (map nil (if noninteractive |
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
4884 #'byte-compile |
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
4885 #'(lambda (x) |
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
4886 (message "compiling %s..." x) |
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
4887 (byte-compile x) |
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
4888 (message "compiling %s...done" x))) |
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
4889 '(byte-compile-normal-call |
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
4890 byte-compile-form |
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
4891 byte-compile-body |
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
4892 ;; Inserted some more than necessary, to speed it up. |
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
4893 byte-compile-top-level |
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
4894 byte-compile-out-toplevel |
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
4895 byte-compile-constant |
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
4896 byte-compile-variable-ref))))) |
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
4897 |
428 | 4898 |
4683
0cc9d22c3732
Be more reliable about loading cl-macs at byte-compile time, cl.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
4899 (run-hooks 'bytecomp-load-hook) |
0cc9d22c3732
Be more reliable about loading cl-macs at byte-compile time, cl.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
4900 |
428 | 4901 ;;; bytecomp.el ends here |