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