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