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