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