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