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