Mercurial > hg > xemacs-beta
annotate lisp/bytecomp.el @ 5767:4e69b24a2301
Disable ASLR on Mavericks.
| author | Marcus Crestani <crestani@informatik.uni-tuebingen.de> |
|---|---|
| date | Mon, 28 Oct 2013 16:03:53 +0100 |
| parents | dbd8305e13cb |
| children | b527c25f36ce |
| rev | line source |
|---|---|
| 428 | 1 ;;; bytecomp.el --- compilation of Lisp code into byte code. |
| 2 | |
| 3 ;;; Copyright (C) 1985-1987, 1991-1994 Free Software Foundation, Inc. | |
| 4 ;;; Copyright (C) 1996 Ben Wing. | |
| 5 | |
| 442 | 6 ;; Authors: Jamie Zawinski <jwz@jwz.org> |
| 428 | 7 ;; Hallvard Furuseth <hbf@ulrik.uio.no> |
| 442 | 8 ;; Ben Wing <ben@xemacs.org> |
| 9 ;; Martin Buchholz <martin@xemacs.org> | |
| 10 ;; Richard Stallman <rms@gnu.org> | |
| 11 ;; Keywords: internal lisp | |
| 12 | |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
13 (defconst byte-compile-version "2.28 XEmacs; 2009-08-09.") |
| 428 | 14 |
| 15 ;; This file is part of XEmacs. | |
| 16 | |
|
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5269
diff
changeset
|
17 ;; XEmacs is free software: you can redistribute it and/or modify it |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5269
diff
changeset
|
18 ;; under the terms of the GNU General Public License as published by the |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5269
diff
changeset
|
19 ;; Free Software Foundation, either version 3 of the License, or (at your |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5269
diff
changeset
|
20 ;; option) any later version. |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5269
diff
changeset
|
21 |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5269
diff
changeset
|
22 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5269
diff
changeset
|
23 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5269
diff
changeset
|
24 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5269
diff
changeset
|
25 ;; for more details. |
| 428 | 26 |
| 27 ;; You should have received a copy of the GNU General Public License | |
|
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5269
diff
changeset
|
28 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>. |
| 428 | 29 |
| 30 ;;; Synched up with: FSF 19.30. | |
| 31 | |
| 32 ;;; Commentary: | |
| 33 | |
| 34 ;; The Emacs Lisp byte compiler. This crunches lisp source into a | |
| 442 | 35 ;; sort of p-code (`bytecode') which takes up less space and can be |
| 36 ;; interpreted faster. First, the source code forms are converted to | |
| 37 ;; an intermediate form, `lapcode' [`LAP' == `Lisp Assembly Program'] | |
| 38 ;; which is much easier to manipulate than bytecode. Then the lapcode | |
| 39 ;; is converted to bytecode, which can be considered to be actual | |
| 40 ;; machine language. Optimizations can occur at either the source | |
| 41 ;; level or the lapcode level. | |
| 42 | |
| 43 ;; The user entry points are byte-compile-file, | |
| 428 | 44 ;; byte-recompile-directory and byte-compile-buffer. |
| 45 | |
| 46 ;;; Code: | |
| 47 | |
| 48 ;;; ======================================================================== | |
| 49 ;;; Entry points: | |
| 50 ;;; byte-recompile-directory, byte-compile-file, | |
| 51 ;;; batch-byte-compile, batch-byte-recompile-directory, | |
| 52 ;;; byte-compile, compile-defun, | |
| 53 ;;; display-call-tree | |
| 54 ;;; RMS says: | |
| 55 ;;; (byte-compile-buffer and byte-compile-and-load-file were turned off | |
| 56 ;;; because they are not terribly useful and get in the way of completion.) | |
| 57 ;;; But I'm leaving them. --ben | |
| 58 | |
| 59 ;;; This version of the byte compiler has the following improvements: | |
| 60 ;;; + optimization of compiled code: | |
| 61 ;;; - removal of unreachable code; | |
| 62 ;;; - removal of calls to side-effectless functions whose return-value | |
| 63 ;;; is unused; | |
| 64 ;;; - compile-time evaluation of safe constant forms, such as (consp nil) | |
| 65 ;;; and (ash 1 6); | |
| 66 ;;; - open-coding of literal lambdas; | |
| 67 ;;; - peephole optimization of emitted code; | |
| 68 ;;; - trivial functions are left uncompiled for speed. | |
| 69 ;;; + support for inline functions; | |
| 70 ;;; + compile-time evaluation of arbitrary expressions; | |
| 71 ;;; + compile-time warning messages for: | |
| 72 ;;; - functions being redefined with incompatible arglists; | |
| 73 ;;; - functions being redefined as macros, or vice-versa; | |
| 74 ;;; - functions or macros defined multiple times in the same file; | |
| 75 ;;; - functions being called with the incorrect number of arguments; | |
| 76 ;;; - functions being called which are not defined globally, in the | |
| 77 ;;; file, or as autoloads; | |
| 78 ;;; - assignment and reference of undeclared free variables; | |
| 79 ;;; - various syntax errors; | |
| 80 ;;; + correct compilation of nested defuns, defmacros, defvars and defsubsts; | |
| 81 ;;; + correct compilation of top-level uses of macros; | |
| 82 ;;; + the ability to generate a histogram of functions called. | |
| 83 | |
| 84 ;;; User customization variables: | |
| 85 ;;; | |
| 86 ;;; byte-compile-verbose Whether to report the function currently being | |
| 87 ;;; compiled in the minibuffer; | |
| 88 ;;; byte-optimize Whether to do optimizations; this may be | |
| 89 ;;; t, nil, 'source, or 'byte; | |
| 90 ;;; byte-optimize-log Whether to report (in excruciating detail) | |
| 91 ;;; exactly which optimizations have been made. | |
| 92 ;;; This may be t, nil, 'source, or 'byte; | |
| 93 ;;; byte-compile-error-on-warn Whether to stop compilation when a warning is | |
| 94 ;;; produced; | |
| 95 ;;; byte-compile-delete-errors Whether the optimizer may delete calls or | |
| 96 ;;; variable references that are side-effect-free | |
| 97 ;;; except that they may return an error. | |
| 98 ;;; byte-compile-generate-call-tree Whether to generate a histogram of | |
| 99 ;;; function calls. This can be useful for | |
| 100 ;;; finding unused functions, as well as simple | |
| 101 ;;; performance metering. | |
| 102 ;;; byte-compile-warnings List of warnings to issue, or t. May contain | |
| 103 ;;; 'free-vars (references to variables not in the | |
| 104 ;;; current lexical scope) | |
| 105 ;;; 'unused-vars (non-global variables bound but | |
| 106 ;;; not referenced) | |
| 107 ;;; 'unresolved (calls to unknown functions) | |
| 108 ;;; 'callargs (lambda calls with args that don't | |
| 109 ;;; match the lambda's definition) | |
| 110 ;;; 'subr-callargs (calls to subrs with args that | |
| 111 ;;; don't match the subr's definition) | |
| 112 ;;; 'redefine (function cell redefined from | |
| 113 ;;; a macro to a lambda or vice versa, | |
| 114 ;;; or redefined to take other args) | |
| 115 ;;; 'obsolete (obsolete variables and functions) | |
| 116 ;;; 'pedantic (references to Emacs-compatible | |
| 117 ;;; symbols) | |
|
4719
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
118 ;;; 'discarded-consing (use of mapcar instead of |
|
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
119 ;;; mapc, and similar) |
|
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
120 ;;; 'quoted-lambda (quoting a lambda expression |
|
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
121 ;;; as data, not as a function, |
|
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
122 ;;; and using it in a function |
|
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
123 ;;; context ) |
| 428 | 124 ;;; emacs-lisp-file-regexp Regexp for the extension of source-files; |
| 444 | 125 ;;; see also the function `byte-compile-dest-file'. |
| 428 | 126 ;;; byte-compile-overwrite-file If nil, delete old .elc files before saving. |
| 127 ;;; | |
| 128 ;;; Most of the above parameters can also be set on a file-by-file basis; see | |
| 129 ;;; the documentation of the `byte-compiler-options' macro. | |
| 130 | |
| 131 ;;; New Features: | |
| 132 ;;; | |
| 133 ;;; o The form `defsubst' is just like `defun', except that the function | |
| 134 ;;; generated will be open-coded in compiled code which uses it. This | |
| 135 ;;; means that no function call will be generated, it will simply be | |
| 136 ;;; spliced in. Lisp functions calls are very slow, so this can be a | |
| 137 ;;; big win. | |
| 138 ;;; | |
| 139 ;;; You can generally accomplish the same thing with `defmacro', but in | |
| 140 ;;; that case, the defined procedure can't be used as an argument to | |
| 141 ;;; mapcar, etc. | |
| 142 ;;; | |
| 143 ;;; o You can make a given function be inline even if it has already been | |
| 144 ;;; defined with `defun' by using the `proclaim-inline' form like so: | |
| 145 ;;; (proclaim-inline my-function) | |
| 146 ;;; This is, in fact, exactly what `defsubst' does. To make a function no | |
| 147 ;;; longer be inline, you must use `proclaim-notinline'. Beware that if | |
| 148 ;;; you define a function with `defsubst' and later redefine it with | |
| 444 | 149 ;;; `defun', it will still be open-coded until you use `proclaim-notinline'. |
| 428 | 150 ;;; |
| 151 ;;; o You can also open-code one particular call to a function without | |
| 152 ;;; open-coding all calls. Use the 'inline' form to do this, like so: | |
| 153 ;;; | |
| 154 ;;; (inline (foo 1 2 3)) ;; `foo' will be open-coded | |
| 155 ;;; or... | |
| 156 ;;; (inline ;; `foo' and `baz' will be | |
| 157 ;;; (foo 1 2 3 (bar 5)) ;; open-coded, but `bar' will not. | |
| 158 ;;; (baz 0)) | |
| 159 ;;; | |
| 160 ;;; o It is possible to open-code a function in the same file it is defined | |
| 161 ;;; in without having to load that file before compiling it. the | |
| 162 ;;; byte-compiler has been modified to remember function definitions in | |
| 163 ;;; the compilation environment in the same way that it remembers macro | |
| 164 ;;; definitions. | |
| 165 ;;; | |
| 166 ;;; o Forms like ((lambda ...) ...) are open-coded. | |
| 167 ;;; | |
| 444 | 168 ;;; o The form `eval-when-compile' is like `progn', except that the body |
| 428 | 169 ;;; is evaluated at compile-time. When it appears at top-level, this |
| 170 ;;; is analogous to the Common Lisp idiom (eval-when (compile) ...). | |
| 171 ;;; When it does not appear at top-level, it is similar to the | |
| 172 ;;; Common Lisp #. reader macro (but not in interpreted code). | |
| 173 ;;; | |
| 444 | 174 ;;; o The form `eval-and-compile' is similar to `eval-when-compile', |
| 175 ;;; but the whole form is evalled both at compile-time and at run-time. | |
| 428 | 176 ;;; |
| 177 ;;; o The command M-x byte-compile-and-load-file does what you'd think. | |
| 178 ;;; | |
| 444 | 179 ;;; o The command `compile-defun' is analogous to `eval-defun'. |
| 428 | 180 ;;; |
| 444 | 181 ;;; o If you run `byte-compile-file' on a filename which is visited in a |
| 428 | 182 ;;; buffer, and that buffer is modified, you are asked whether you want |
| 183 ;;; to save the buffer before compiling. | |
| 184 ;;; | |
| 185 ;;; o You can add this to /etc/magic to make file(1) recognize the files | |
| 186 ;;; generated by this compiler: | |
| 187 ;;; | |
| 613 | 188 ;;; 0 string ;ELC XEmacs Lisp compiled file, |
| 428 | 189 ;;; >4 byte x version %d |
| 190 ;;; | |
| 191 ;;; TO DO: | |
| 192 ;;; | |
| 193 ;;; o Should implement declarations and proclamations, notably special, | |
| 194 ;;; unspecial, and ignore. Do this in such a way as to not break cl.el. | |
| 195 ;;; o The bound-but-not-used warnings are not issued for variables whose | |
| 196 ;;; bindings were established in the arglist, due to the lack of an | |
| 197 ;;; ignore declaration. Once ignore exists, this should be turned on. | |
| 198 ;;; o Warn about functions and variables defined but not used? | |
| 199 ;;; Maybe add some kind of `export' declaration for this? | |
| 200 ;;; (With interactive functions being automatically exported?) | |
| 201 ;;; o Any reference to a variable, even one which is a no-op, will cause | |
| 202 ;;; the warning not to be given. Possibly we could use the for-effect | |
| 203 ;;; flag to determine when this reference is useless; possibly more | |
| 204 ;;; complex flow analysis would be necessary. | |
| 205 ;;; o If the optimizer deletes a variable reference, we might be left with | |
| 206 ;;; a bound-but-not-referenced warning. Generally this is ok, but not if | |
| 207 ;;; it's a synergistic result of macroexpansion. Need some way to note | |
| 208 ;;; that a varref is being optimized away? Of course it would be nice to | |
| 209 ;;; optimize away the binding too, someday, but it's unsafe today. | |
| 210 ;;; o (See byte-optimize.el for the optimization TODO list.) | |
| 211 | |
| 212 (require 'backquote) | |
| 213 | |
| 214 (or (fboundp 'defsubst) | |
| 215 ;; This really ought to be loaded already! | |
| 216 (load-library "bytecomp-runtime")) | |
| 217 | |
| 444 | 218 (defvar emacs-lisp-file-regexp "\\.el$" |
| 428 | 219 "*Regexp which matches Emacs Lisp source files. |
| 220 You may want to redefine `byte-compile-dest-file' if you change this.") | |
| 221 | |
| 222 ;; This enables file name handlers such as jka-compr | |
| 223 ;; to remove parts of the file name that should not be copied | |
| 224 ;; through to the output file name. | |
| 225 (defun byte-compiler-base-file-name (filename) | |
| 226 (let ((handler (find-file-name-handler filename | |
| 227 'byte-compiler-base-file-name))) | |
| 228 (if handler | |
| 229 (funcall handler 'byte-compiler-base-file-name filename) | |
| 230 filename))) | |
| 231 | |
| 232 (unless (fboundp 'byte-compile-dest-file) | |
| 233 ;; The user may want to redefine this along with emacs-lisp-file-regexp, | |
| 234 ;; so only define it if it is undefined. | |
| 235 (defun byte-compile-dest-file (filename) | |
| 236 "Convert an Emacs Lisp source file name to a compiled file name." | |
| 237 (setq filename (byte-compiler-base-file-name filename)) | |
| 238 (setq filename (file-name-sans-versions filename)) | |
| 239 (if (string-match emacs-lisp-file-regexp filename) | |
| 240 (concat (substring filename 0 (match-beginning 0)) ".elc") | |
| 241 (concat filename ".elc")))) | |
| 242 | |
| 243 ;; This can be the 'byte-compile property of any symbol. | |
| 244 (autoload 'byte-compile-inline-expand "byte-optimize") | |
| 245 | |
| 246 ;; This is the entrypoint to the lapcode optimizer pass1. | |
| 247 (autoload 'byte-optimize-form "byte-optimize") | |
| 248 ;; This is the entrypoint to the lapcode optimizer pass2. | |
| 249 (autoload 'byte-optimize-lapcode "byte-optimize") | |
| 250 (autoload 'byte-compile-unfold-lambda "byte-optimize") | |
| 251 | |
| 252 ;; This is the entry point to the decompiler, which is used by the | |
| 253 ;; disassembler. The disassembler just requires 'byte-compile, but | |
| 254 ;; that doesn't define this function, so this seems to be a reasonable | |
| 255 ;; thing to do. | |
| 256 (autoload 'byte-decompile-bytecode "byte-optimize") | |
| 257 | |
| 258 (defvar byte-compile-verbose | |
| 259 (and (not noninteractive) (> (device-baud-rate) search-slow-speed)) | |
| 260 "*Non-nil means print messages describing progress of byte-compiler.") | |
| 261 | |
| 262 (defvar byte-compile-print-gensym t | |
| 263 "*Non-nil means generate code that creates unique symbols at run-time. | |
| 264 This is achieved by printing uninterned symbols using the `#:SYMBOL' | |
| 265 notation, so that they will be read uninterned when run. | |
| 266 | |
| 267 With this feature, code that uses uninterned symbols in macros will | |
|
5503
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
268 not be runnable under pre-21.0 XEmacsen.") |
| 428 | 269 |
| 270 (defvar byte-optimize t | |
| 271 "*Enables optimization in the byte compiler. | |
| 272 nil means don't do any optimization. | |
| 273 t means do all optimizations. | |
| 274 `source' means do source-level optimizations only. | |
| 275 `byte' means do code-level optimizations only.") | |
| 276 | |
| 277 (defvar byte-compile-delete-errors t | |
| 278 "*If non-nil, the optimizer may delete forms that may signal an error. | |
| 279 This includes variable references and calls to functions such as `car'.") | |
| 280 | |
| 281 ;; XEmacs addition | |
| 282 (defvar byte-compile-new-bytecodes nil | |
| 283 "This is completely ignored. It is only around for backwards | |
| 284 compatibility.") | |
| 285 | |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
286 (defvar byte-compile-checks-on-load '((featurep 'xemacs)) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
287 "A list of expressions to check when first loading a file. |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
288 Emacs will throw an error if any of them fail; checks will be made in |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
289 reverse order.") |
| 428 | 290 |
| 291 ;; FSF enables byte-compile-dynamic-docstrings but not byte-compile-dynamic | |
| 292 ;; by default. This would be a reasonable conservative approach except | |
| 293 ;; for the fact that if you enable either of these, you get incompatible | |
| 294 ;; byte code that can't be read by XEmacs 19.13 or before or FSF 19.28 or | |
| 295 ;; before. | |
| 296 ;; | |
| 297 ;; Therefore, neither is enabled for 19.14. Both are enabled for 20.0 | |
| 298 ;; because we have no reason to be conservative about changing the | |
| 299 ;; way things work. (Ben) | |
| 300 | |
| 301 ;; However, I don't think that defaulting byte-compile-dynamic to nil | |
| 302 ;; is a compatibility issue - rather it is a performance issue. | |
| 303 ;; Therefore I am setting byte-compile-dynamic back to nil. (mrb) | |
| 304 | |
| 305 (defvar byte-compile-dynamic nil | |
| 306 "*If non-nil, compile function bodies so they load lazily. | |
| 307 They are hidden comments in the compiled file, and brought into core when the | |
| 308 function is called. | |
| 309 | |
| 310 To enable this option, make it a file-local variable | |
| 311 in the source file you want it to apply to. | |
| 312 For example, add -*-byte-compile-dynamic: t;-*- on the first line. | |
| 313 | |
| 314 When this option is true, if you load the compiled file and then move it, | |
| 315 the functions you loaded will not be able to run.") | |
| 316 | |
| 317 (defvar byte-compile-dynamic-docstrings (emacs-version>= 20) | |
| 318 "*If non-nil, compile doc strings for lazy access. | |
| 319 We bury the doc strings of functions and variables | |
| 320 inside comments in the file, and bring them into core only when they | |
| 321 are actually needed. | |
| 322 | |
| 323 When this option is true, if you load the compiled file and then move it, | |
| 324 you won't be able to find the documentation of anything in that file. | |
| 325 | |
| 326 To disable this option for a certain file, make it a file-local variable | |
| 327 in the source file. For example, add this to the first line: | |
| 328 -*-byte-compile-dynamic-docstrings:nil;-*- | |
| 329 You can also set the variable globally. | |
| 330 | |
| 331 This option is enabled by default because it reduces Emacs memory usage.") | |
| 332 | |
| 333 (defvar byte-optimize-log nil | |
| 334 "*If true, the byte-compiler will log its optimizations into *Compile-Log*. | |
| 335 If this is 'source, then only source-level optimizations will be logged. | |
| 336 If it is 'byte, then only byte-level optimizations will be logged.") | |
| 337 | |
| 338 (defvar byte-compile-error-on-warn nil | |
| 339 "*If true, the byte-compiler reports warnings with `error'.") | |
| 340 | |
| 341 ;; byte-compile-warning-types in FSF. | |
| 342 (defvar byte-compile-default-warnings | |
|
4719
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
343 '(redefine callargs subr-callargs free-vars unresolved unused-vars obsolete |
|
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
344 discarded-consing quoted-lambda) |
| 428 | 345 "*The warnings used when byte-compile-warnings is t.") |
| 346 | |
| 347 (defvar byte-compile-warnings t | |
| 348 "*List of warnings that the compiler should issue (t for the default set). | |
| 349 Elements of the list may be: | |
| 350 | |
| 351 free-vars references to variables not in the current lexical scope. | |
| 352 unused-vars references to non-global variables bound but not referenced. | |
| 353 unresolved calls to unknown functions. | |
| 354 callargs lambda calls with args that don't match the definition. | |
| 355 subr-callargs calls to subrs with args that don't match the definition. | |
| 356 redefine function cell redefined from a macro to a lambda or vice | |
| 357 versa, or redefined to take a different number of arguments. | |
| 358 obsolete use of an obsolete function or variable. | |
| 359 pedantic warn of use of compatible symbols. | |
|
4719
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
360 discarded-consing |
|
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
361 calls to (some) functions that allocate memory, where that |
|
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
362 memory is immediately discarded; canonically, the use of |
|
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
363 mapcar instead of mapc |
|
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
364 quoted-lambda passing a lambda expression not quoted as a function, as a |
|
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
365 function argument |
| 428 | 366 |
| 367 The default set is specified by `byte-compile-default-warnings' and | |
| 368 normally encompasses all possible warnings. | |
| 369 | |
| 370 See also the macro `byte-compiler-options'.") | |
| 371 | |
| 372 (defvar byte-compile-generate-call-tree nil | |
| 373 "*Non-nil means collect call-graph information when compiling. | |
| 374 This records functions that were called and from where. | |
| 375 If the value is t, compilation displays the call graph when it finishes. | |
| 376 If the value is neither t nor nil, compilation asks you whether to display | |
| 377 the graph. | |
| 378 | |
| 379 The call tree only lists functions called, not macros used. Those functions | |
| 380 which the byte-code interpreter knows about directly (eq, cons, etc.) are | |
| 381 not reported. | |
| 382 | |
| 383 The call tree also lists those functions which are not known to be called | |
| 384 \(that is, to which no calls have been compiled). Functions which can be | |
| 385 invoked interactively are excluded from this list.") | |
| 386 | |
| 387 (defconst byte-compile-call-tree nil "Alist of functions and their call tree. | |
| 388 Each element looks like | |
| 389 | |
| 390 \(FUNCTION CALLERS CALLS\) | |
| 391 | |
| 392 where CALLERS is a list of functions that call FUNCTION, and CALLS | |
| 393 is a list of functions for which calls were generated while compiling | |
| 394 FUNCTION.") | |
| 395 | |
| 396 (defvar byte-compile-call-tree-sort 'name | |
| 397 "*If non-nil, sort the call tree. | |
| 398 The values `name', `callers', `calls', `calls+callers' | |
| 399 specify different fields to sort on.") | |
| 400 | |
| 401 (defvar byte-compile-overwrite-file t | |
| 402 "If nil, old .elc files are deleted before the new is saved, and .elc | |
| 403 files will have the same modes as the corresponding .el file. Otherwise, | |
| 404 existing .elc files will simply be overwritten, and the existing modes | |
| 405 will not be changed. If this variable is nil, then an .elc file which | |
| 406 is a symbolic link will be turned into a normal file, instead of the file | |
| 407 which the link points to being overwritten.") | |
| 408 | |
| 409 (defvar byte-recompile-directory-ignore-errors-p nil | |
| 410 "If true, then `byte-recompile-directory' will continue compiling even | |
| 411 when an error occurs in a file. This is bound to t by | |
| 412 `batch-byte-recompile-directory'.") | |
| 413 | |
| 502 | 414 (defvar byte-recompile-ignore-uncompilable-mule-files t |
| 415 "If non-nil, `byte-recompile-*' ignores non-ASCII .el files in a non-Mule | |
| 416 XEmacs. This assumes that such files have a -*- coding: ??? -*- magic | |
| 417 cookie in their first line or a ;;;###coding system: magic cookie | |
| 418 early in the file.") | |
| 419 | |
| 428 | 420 (defvar byte-recompile-directory-recursively t |
| 421 "*If true, then `byte-recompile-directory' will recurse on subdirectories.") | |
| 422 | |
| 423 (defvar byte-compile-constants nil | |
| 424 "list of all constants encountered during compilation of this form") | |
| 425 (defvar byte-compile-variables nil | |
| 426 "list of all variables encountered during compilation of this form") | |
| 427 (defvar byte-compile-bound-variables nil | |
| 428 "Alist of variables bound in the context of the current form, | |
| 429 that is, the current lexical environment. This list lives partly | |
| 430 on the specbind stack. The cdr of each cell is an integer bitmask.") | |
|
5391
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
431 (defvar byte-compile-output-preface nil |
|
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
432 "Form to output before current by `byte-compile-output-file-form' |
|
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
433 This is used for implementing `load-time-value'.") |
| 428 | 434 |
|
4623
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
435 (defvar byte-compile-force-escape-quoted nil |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
436 "If t, `byte-compile-maybe-reset-coding' always chooses `escape-quoted' |
|
4623
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
437 |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
438 This is for situations where the byte compiler output file needs to be |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
439 able to encode character values above ?\\xFF, but this cannot be |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
440 easily determined from the input file.") |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
441 |
| 428 | 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) | |
|
5613
a944c124b2d3
Be more careful about what we shadow, #'byte-compile-eval.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5612
diff
changeset
|
458 (let ((save-macro-environment nil) |
|
a944c124b2d3
Be more careful about what we shadow, #'byte-compile-eval.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5612
diff
changeset
|
459 ;; These are macros in byte-compile-initial-macro-environment that |
|
a944c124b2d3
Be more careful about what we shadow, #'byte-compile-eval.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5612
diff
changeset
|
460 ;; shouldn't be shadowed when calling #'byte-compile-eval, since |
|
a944c124b2d3
Be more careful about what we shadow, #'byte-compile-eval.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5612
diff
changeset
|
461 ;; such code is interpreted, not compiled. |
|
a944c124b2d3
Be more careful about what we shadow, #'byte-compile-eval.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5612
diff
changeset
|
462 ;; #### Consider giving this a docstring and a top-level value. |
|
a944c124b2d3
Be more careful about what we shadow, #'byte-compile-eval.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5612
diff
changeset
|
463 (byte-compile-no-shadow '(load-time-value labels flet))) |
| 446 | 464 (unwind-protect |
|
5503
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
465 (loop |
|
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
466 for (sym . def) in byte-compile-macro-environment |
|
5613
a944c124b2d3
Be more careful about what we shadow, #'byte-compile-eval.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5612
diff
changeset
|
467 do (when (and (symbolp sym) (not (memq sym byte-compile-no-shadow))) |
|
5503
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
468 (push |
|
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
469 (if (fboundp sym) |
|
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
470 (cons sym (symbol-function sym)) |
|
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
471 sym) |
|
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
472 save-macro-environment) |
|
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
473 (fset sym (cons 'macro def))) |
| 446 | 474 finally return (eval form)) |
| 475 (dolist (elt save-macro-environment) | |
| 476 (if (symbolp elt) | |
| 477 (fmakunbound elt) | |
| 478 (fset (car elt) (cdr elt))))))) | |
| 479 | |
|
5566
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
480 (defvar for-effect) ; ## Kludge! This should be an arg, not a special. |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
481 |
| 428 | 482 (defconst byte-compile-initial-macro-environment |
|
5263
0d436a78c514
Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
483 `((byte-compiler-options |
|
0d436a78c514
Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
484 . ,#'(lambda (&rest forms) |
|
0d436a78c514
Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
485 (apply 'byte-compiler-options-handler forms))) |
|
0d436a78c514
Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
486 (eval-when-compile |
|
0d436a78c514
Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
487 . ,#'(lambda (&rest body) |
|
0d436a78c514
Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
488 (list 'quote (byte-compile-eval (cons 'progn body))))) |
|
0d436a78c514
Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
489 (eval-and-compile |
|
0d436a78c514
Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
490 . ,#'(lambda (&rest body) |
|
0d436a78c514
Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
491 (byte-compile-eval (cons 'progn body)) |
|
0d436a78c514
Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
492 (cons 'progn body))) |
|
0d436a78c514
Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
493 (the . |
|
5269
90a0084b3541
Rephrase the #'the docstring, make it nicer while byte-compiling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5265
diff
changeset
|
494 ,#'(lambda (type form) |
|
5282
dcc34e28cd84
Warn at byte-compile in #'the if FORM constant & not TYPE; fix byte-compile-constp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5269
diff
changeset
|
495 (if (cl-const-expr-p form) |
|
dcc34e28cd84
Warn at byte-compile in #'the if FORM constant & not TYPE; fix byte-compile-constp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5269
diff
changeset
|
496 (or (eval (cl-make-type-test form type)) |
|
dcc34e28cd84
Warn at byte-compile in #'the if FORM constant & not TYPE; fix byte-compile-constp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5269
diff
changeset
|
497 (byte-compile-warn |
|
dcc34e28cd84
Warn at byte-compile in #'the if FORM constant & not TYPE; fix byte-compile-constp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5269
diff
changeset
|
498 "%s is not of type %s" form type))) |
|
5263
0d436a78c514
Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
499 (if byte-compile-delete-errors |
|
5269
90a0084b3541
Rephrase the #'the docstring, make it nicer while byte-compiling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5265
diff
changeset
|
500 form |
|
5562
855b667dea13
Drop cl-macro-environment in favour of byte-compile-macro-environment.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
501 (funcall (cdr (symbol-function 'the)) type form)))) |
|
5574
d4f334808463
Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5573
diff
changeset
|
502 (declare |
|
d4f334808463
Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5573
diff
changeset
|
503 . ,#'(lambda (&rest specs) |
|
d4f334808463
Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5573
diff
changeset
|
504 (while specs |
|
d4f334808463
Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5573
diff
changeset
|
505 (if (listp cl-declare-stack) (push (car specs) cl-declare-stack)) |
|
d4f334808463
Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5573
diff
changeset
|
506 (cl-do-proclaim (pop specs) nil)))) |
|
5562
855b667dea13
Drop cl-macro-environment in favour of byte-compile-macro-environment.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
507 (load-time-value |
|
5579
3e621ba12d36
Don't byte-compile at macroexpansion time, load-time-vale.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5577
diff
changeset
|
508 . ,(symbol-macrolet ((wrapper '#:load-time-value)) |
|
3e621ba12d36
Don't byte-compile at macroexpansion time, load-time-vale.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5577
diff
changeset
|
509 (put wrapper 'byte-compile |
|
3e621ba12d36
Don't byte-compile at macroexpansion time, load-time-vale.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5577
diff
changeset
|
510 #'(lambda (form) |
|
3e621ba12d36
Don't byte-compile at macroexpansion time, load-time-vale.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5577
diff
changeset
|
511 (let* ((gensym (gensym)) |
|
3e621ba12d36
Don't byte-compile at macroexpansion time, load-time-vale.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5577
diff
changeset
|
512 (byte-compile-bound-variables |
|
3e621ba12d36
Don't byte-compile at macroexpansion time, load-time-vale.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5577
diff
changeset
|
513 (acons gensym byte-compile-global-bit |
|
3e621ba12d36
Don't byte-compile at macroexpansion time, load-time-vale.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5577
diff
changeset
|
514 byte-compile-bound-variables))) |
|
3e621ba12d36
Don't byte-compile at macroexpansion time, load-time-vale.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5577
diff
changeset
|
515 (setq byte-compile-output-preface |
|
3e621ba12d36
Don't byte-compile at macroexpansion time, load-time-vale.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5577
diff
changeset
|
516 (byte-compile-top-level |
|
3e621ba12d36
Don't byte-compile at macroexpansion time, load-time-vale.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5577
diff
changeset
|
517 `(progn |
|
3e621ba12d36
Don't byte-compile at macroexpansion time, load-time-vale.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5577
diff
changeset
|
518 (setq ,gensym (progn ,(second form))) |
|
3e621ba12d36
Don't byte-compile at macroexpansion time, load-time-vale.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5577
diff
changeset
|
519 ,byte-compile-output-preface) |
|
3e621ba12d36
Don't byte-compile at macroexpansion time, load-time-vale.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5577
diff
changeset
|
520 t 'file)) |
|
3e621ba12d36
Don't byte-compile at macroexpansion time, load-time-vale.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5577
diff
changeset
|
521 (byte-compile-form `(symbol-value ',gensym) nil)))) |
|
3e621ba12d36
Don't byte-compile at macroexpansion time, load-time-vale.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5577
diff
changeset
|
522 #'(lambda (form &optional read-only) |
|
3e621ba12d36
Don't byte-compile at macroexpansion time, load-time-vale.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5577
diff
changeset
|
523 (list wrapper form)))) |
|
5562
855b667dea13
Drop cl-macro-environment in favour of byte-compile-macro-environment.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
524 (labels |
|
5656
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
525 . ,(symbol-macrolet ((wrapper '#:labels)) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
526 (labels |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
527 ((cannot-inline-alist (placeholders lambdas) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
528 (let ((inline |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
529 ;; What labels should be inline? |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
530 (remove-if-not |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
531 #'(lambda (placeholder) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
532 (eq 'byte-compile-inline-expand |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
533 (get placeholder |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
534 'byte-optimizer))) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
535 placeholders))) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
536 ;; Which of those labels--that should be |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
537 ;; inline--reference themeselves, or other labels that |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
538 ;; should be inline? Give a an alist mapping them to |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
539 ;; their data placeholders. |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
540 (mapcan |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
541 #'(lambda (placeholder lambda) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
542 (and |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
543 (eq 'byte-compile-inline-expand |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
544 (get placeholder 'byte-optimizer)) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
545 (block find |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
546 (subst-if nil |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
547 #'(lambda (tree) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
548 (if (memq tree inline) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
549 (return-from find t))) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
550 lambda) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
551 nil) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
552 `((,placeholder |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
553 . ,(get placeholder |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
554 'byte-compile-data-placeholder))))) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
555 placeholders lambdas))) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
556 (destructure-labels (form for-effect) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
557 (let* ((names (cadr (cl-pop2 form))) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
558 (lambdas (mapcar #'cadr (cdr (pop form)))) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
559 (placeholders (cadr (pop form))) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
560 (cannot-inline-alist (cannot-inline-alist |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
561 placeholders lambdas)) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
562 (lambdas (sublis cannot-inline-alist |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
563 lambdas :test #'eq))) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
564 ;; Used specially, note the bindings in our callers. |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
565 (setq byte-compile-function-environment |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
566 (pairlis |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
567 (mapcar #'cdr cannot-inline-alist) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
568 (mapcar #'car cannot-inline-alist) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
569 (pairlis placeholders lambdas |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
570 byte-compile-function-environment))) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
571 (if (memq byte-optimize '(t source)) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
572 (setq lambdas |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
573 (mapcar #'cadr (mapcar #'byte-optimize-form |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
574 lambdas)) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
575 form (byte-optimize-body form for-effect))) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
576 (values placeholders lambdas names form))) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
577 (warn-about-unused-labels (names placeholders) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
578 (when (memq 'unused-vars byte-compile-warnings) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
579 (loop |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
580 for placeholder in placeholders |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
581 for name in names |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
582 if (eql 0 (+ (get placeholder |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
583 'byte-compile-label-calls 0) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
584 (get (get placeholder |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
585 'byte-compile-data-placeholder |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
586 '#:no-such-data-placeholder) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
587 'byte-compile-label-calls 0))) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
588 do (byte-compile-warn |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
589 "label %s bound but not referenced" name)))) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
590 (byte-compile-transform-labels (form names lambdas |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
591 placeholders) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
592 (let ((compiled |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
593 (mapcar* #'byte-compile-lambda lambdas names))) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
594 (warn-about-unused-labels names placeholders) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
595 (mapc #'(lambda (placeholder function) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
596 (nsubst function placeholder compiled |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
597 :test #'eq |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
598 :descend-structures t) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
599 (nsubst function |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
600 (get placeholder |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
601 'byte-compile-data-placeholder) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
602 compiled :test #'eq |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
603 :descend-structures t)) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
604 placeholders compiled) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
605 (sublis (pairlis |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
606 placeholders compiled |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
607 (pairlis |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
608 (mapcar* |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
609 #'get placeholders |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
610 (load-time-value |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
611 (let ((list |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
612 (list |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
613 'byte-compile-data-placeholder))) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
614 (nconc list list)))) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
615 compiled)) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
616 form :test #'eq)))) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
617 (put wrapper 'byte-compile |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
618 #'(lambda (form) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
619 (let ((byte-compile-function-environment |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
620 byte-compile-function-environment)) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
621 (multiple-value-bind |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
622 (placeholders lambdas names form) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
623 (destructure-labels form for-effect) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
624 (byte-compile-body-do-effect |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
625 (byte-compile-transform-labels form names |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
626 lambdas |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
627 placeholders)))))) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
628 (put wrapper 'byte-hunk-handler |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
629 #'(lambda (form) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
630 (let ((byte-compile-function-environment |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
631 byte-compile-function-environment)) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
632 (multiple-value-bind |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
633 (placeholders lambdas names form) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
634 (destructure-labels form t) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
635 (byte-compile-file-form |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
636 (cons 'progn |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
637 (byte-compile-transform-labels |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
638 form names lambdas placeholders))))))) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
639 (put wrapper 'cl-compiler-macro |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
640 ;; This is only used when optimizing code. |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
641 #'(lambda (form &rest ignore) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
642 (let ((byte-compile-function-environment |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
643 byte-compile-function-environment) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
644 byte-optimize-form retry) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
645 (multiple-value-bind |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
646 (placeholders lambdas) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
647 (destructure-labels form for-effect) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
648 ;; Optimize most of the form, in passing |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
649 ;; expanding macros. |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
650 (setq byte-optimize-form |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
651 (mapcar #'byte-optimize-form |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
652 (list* (nth 1 form) `(list ,@lambdas) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
653 (cdddr form)))) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
654 ;; It may be reasonable to inline any labels |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
655 ;; used only once. |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
656 (dolist (placeholder placeholders) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
657 (and |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
658 (not (eq 'byte-compile-inline-expand |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
659 (get placeholder 'byte-optimizer))) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
660 (eql 0 (get (get placeholder |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
661 'byte-compile-data-placeholder |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
662 '#:no-such-data-placeholder) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
663 'byte-compile-label-calls 0)) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
664 (eql 1 (get placeholder |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
665 'byte-compile-label-calls 0)) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
666 (progn |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
667 (byte-compile-log |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
668 "label %s is used only once, inlining it" |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
669 placeholder) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
670 (setq retry t) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
671 (cl-do-proclaim `(inline ,placeholder) t)))) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
672 (when retry |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
673 (multiple-value-setq |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
674 (placeholders lambdas) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
675 (destructure-labels form for-effect)) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
676 (setq byte-optimize-form |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
677 (mapcar #'byte-optimize-form |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
678 (list* (nth 1 form) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
679 `(list ,@lambdas) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
680 (cdddr form))))) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
681 (if (equal (cdr form) byte-optimize-form) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
682 form |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
683 (cons (car form) byte-optimize-form))))))) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
684 #'(lambda (bindings &rest body) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
685 (let* ((names (mapcar 'car bindings)) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
686 (lambdas (mapcar |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
687 (function* |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
688 (lambda ((name . definition)) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
689 `#'(lambda ,@(cdr (cl-transform-lambda |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
690 definition name))))) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
691 bindings)) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
692 (placeholders (mapcar #'copy-symbol names)) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
693 (byte-compile-macro-environment |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
694 (pairlis names |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
695 (mapcar |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
696 #'(lambda (placeholder) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
697 `(lambda (&rest byte-compile-labels-args) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
698 (put |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
699 ',placeholder |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
700 'byte-compile-label-calls |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
701 (1+ (get ',placeholder |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
702 'byte-compile-label-calls |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
703 0))) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
704 (cons ',placeholder |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
705 byte-compile-labels-args))) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
706 placeholders) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
707 byte-compile-macro-environment))) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
708 ;; Tell the macroexpansion code what symbol to use when |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
709 ;; expanding #'FUNCTION-NAME: |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
710 (mapc #'put placeholders |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
711 (load-time-value |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
712 (let ((list (list 'byte-compile-data-placeholder))) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
713 (nconc list list))) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
714 (mapcar #'copy-symbol names)) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
715 (setq body |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
716 (cl-macroexpand-all |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
717 `(,wrapper ',names (list ,@lambdas) ',placeholders |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
718 ,@body) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
719 byte-compile-macro-environment)) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
720 (if (position 'lambda (mapcar #'(lambda (object) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
721 (car-safe (cdr-safe |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
722 object))) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
723 (cdr (third body))) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
724 :key #'car-safe :test-not #'eq) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
725 ;; #'lexical-let has worked its magic, not all the |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
726 ;; lambdas are lambdas. Give up on pre-compiling the |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
727 ;; labels. |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
728 (setq names (mapcar #'copy-symbol names) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
729 lambdas (cdr (third body)) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
730 body (sublis (pairlis placeholders names) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
731 (nthcdr 4 body) :test #'eq) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
732 lambdas (sublis (pairlis placeholders names) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
733 lambdas :test #'eq) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
734 body (cl-macroexpand-all |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
735 `(lexical-let |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
736 ,names |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
737 (setf ,@(mapcan #'list names lambdas)) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
738 ,@body) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
739 byte-compile-macro-environment)) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
740 body))))) |
|
5566
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
741 (flet . |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
742 ,#'(lambda (bindings &rest body) |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
743 (let* ((names (mapcar 'car bindings)) |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
744 (lambdas (mapcar |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
745 (function* |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
746 (lambda ((function . definition)) |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
747 (cons 'lambda (cdr (cl-transform-lambda |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
748 definition function))))) |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
749 bindings)) |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
750 (gensym (gensym))) |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
751 (put gensym 'byte-compile-flet-environment |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
752 (pairlis names lambdas)) |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
753 (put gensym 'byte-compile |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
754 #'(lambda (form) |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
755 (let* ((byte-compile-flet-environment |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
756 (get (car form) 'byte-compile-flet-environment)) |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
757 (byte-compile-function-environment |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
758 (append byte-compile-flet-environment |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
759 byte-compile-function-environment)) |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
760 name) |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
761 (dolist (acons byte-compile-flet-environment) |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
762 (setq name (car acons)) |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
763 (if (and (memq 'redefine byte-compile-warnings) |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
764 (or (cdr |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
765 (assq name |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
766 byte-compile-macro-environment)) |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
767 (eq 'macro |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
768 (ignore-errors |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
769 (car (symbol-function name)))))) |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
770 ;; XEmacs change; this is a warning, not an |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
771 ;; error. The only use case for #'flet instead |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
772 ;; of #'labels is to shadow a dynamically |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
773 ;; bound function at runtime, and it's |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
774 ;; reasonable to do this even if that symbol |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
775 ;; has a macro binding at compile time. |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
776 (byte-compile-warn |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
777 "flet: redefining macro %s as a function" |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
778 name)) |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
779 (if (get name 'byte-opcode) |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
780 (byte-compile-warn |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
781 "flet: %s has a byte code, consider #'labels" |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
782 name)) |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
783 (if (get name 'byte-compile) |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
784 (byte-compile-warn |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
785 "flet: %s has a byte-compile method, |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
786 consider #'labels" name))) |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
787 (byte-compile-form (second form))))) |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
788 `(,gensym (letf* ,(mapcar* #'(lambda (name lambda) |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
789 `((symbol-function ',name) |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
790 ,lambda)) names lambdas) |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
791 ,@body)))))) |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
792 |
| 428 | 793 "The default macro-environment passed to macroexpand by the compiler. |
| 794 Placing a macro here will cause a macro to have different semantics when | |
| 795 expanded by the compiler as when expanded by the interpreter.") | |
| 796 | |
| 797 (defvar byte-compile-function-environment nil | |
| 798 "Alist of functions defined in the file being compiled. | |
| 799 This is so we can inline them when necessary. | |
| 800 Each element looks like (FUNCTIONNAME . DEFINITION). It is | |
| 801 \(FUNCTIONNAME . nil) when a function is redefined as a macro.") | |
| 802 | |
| 803 (defvar byte-compile-autoload-environment nil | |
| 804 "Alist of functions and macros defined by autoload in the file being compiled. | |
| 805 This is so we can suppress warnings about calls to these functions, even though | |
| 806 they do not have `real' definitions. | |
| 807 Each element looks like (FUNCTIONNAME . CALL-TO-AUTOLOAD).") | |
| 808 | |
| 809 (defvar byte-compile-unresolved-functions nil | |
| 810 "Alist of undefined functions to which calls have been compiled (used for | |
| 811 warnings when the function is later defined with incorrect args).") | |
| 812 | |
| 813 (defvar byte-compile-file-domain) ; domain of file being compiled | |
| 814 | |
| 815 (defvar byte-compile-tag-number 0) | |
| 816 (defvar byte-compile-output nil | |
| 817 "Alist describing contents to put in byte code string. | |
| 818 Each element is (INDEX . VALUE)") | |
| 819 (defvar byte-compile-depth 0 "Current depth of execution stack.") | |
| 820 (defvar byte-compile-maxdepth 0 "Maximum depth of execution stack.") | |
| 821 | |
| 822 | |
| 823 ;;; The byte codes; this information is duplicated in bytecode.c | |
| 824 | |
| 825 (defconst byte-code-vector nil | |
| 826 "An array containing byte-code names indexed by byte-code values.") | |
| 827 | |
| 828 (defconst byte-stack+-info nil | |
| 829 "An array with the stack adjustment for each byte-code.") | |
| 830 | |
| 831 (defmacro byte-defop (opcode stack-adjust opname &optional docstring) | |
| 832 ;; This is a speed-hack for building the byte-code-vector at compile-time. | |
| 833 ;; We fill in the vector at macroexpand-time, and then after the last call | |
| 834 ;; to byte-defop, we write the vector out as a constant instead of writing | |
| 835 ;; out a bunch of calls to aset. | |
| 836 ;; Actually, we don't fill in the vector itself, because that could make | |
| 837 ;; it problematic to compile big changes to this compiler; we store the | |
| 838 ;; values on its plist, and remove them later in -extrude. | |
| 839 (let ((v1 (or (get 'byte-code-vector 'tmp-compile-time-value) | |
| 840 (put 'byte-code-vector 'tmp-compile-time-value | |
| 841 (make-vector 256 nil)))) | |
| 842 (v2 (or (get 'byte-stack+-info 'tmp-compile-time-value) | |
| 843 (put 'byte-stack+-info 'tmp-compile-time-value | |
| 844 (make-vector 256 nil))))) | |
| 845 (aset v1 opcode opname) | |
| 846 (aset v2 opcode stack-adjust)) | |
| 847 (if docstring | |
| 848 (list 'defconst opname opcode (concat "Byte code opcode " docstring ".")) | |
| 849 (list 'defconst opname opcode))) | |
| 850 | |
| 851 (defmacro byte-extrude-byte-code-vectors () | |
| 852 (prog1 (list 'setq 'byte-code-vector | |
| 853 (get 'byte-code-vector 'tmp-compile-time-value) | |
| 854 'byte-stack+-info | |
| 855 (get 'byte-stack+-info 'tmp-compile-time-value)) | |
| 856 (remprop 'byte-code-vector 'tmp-compile-time-value) | |
| 857 (remprop 'byte-stack+-info 'tmp-compile-time-value))) | |
| 858 | |
| 859 | |
| 860 ;; unused: 0-7 | |
| 861 | |
| 862 ;; These opcodes are special in that they pack their argument into the | |
| 863 ;; opcode word. | |
| 864 ;; | |
| 865 (byte-defop 8 1 byte-varref "for variable reference") | |
| 866 (byte-defop 16 -1 byte-varset "for setting a variable") | |
| 867 (byte-defop 24 -1 byte-varbind "for binding a variable") | |
| 868 (byte-defop 32 0 byte-call "for calling a function") | |
| 869 (byte-defop 40 0 byte-unbind "for unbinding special bindings") | |
| 870 ;; codes 8-47 are consumed by the preceding opcodes | |
| 871 | |
| 872 ;; unused: 48-55 | |
| 873 | |
| 874 (byte-defop 56 -1 byte-nth) | |
| 875 (byte-defop 57 0 byte-symbolp) | |
| 876 (byte-defop 58 0 byte-consp) | |
| 877 (byte-defop 59 0 byte-stringp) | |
| 878 (byte-defop 60 0 byte-listp) | |
| 879 (byte-defop 61 -1 byte-old-eq) | |
| 880 (byte-defop 62 -1 byte-old-memq) | |
| 881 (byte-defop 63 0 byte-not) | |
| 882 (byte-defop 64 0 byte-car) | |
| 883 (byte-defop 65 0 byte-cdr) | |
| 884 (byte-defop 66 -1 byte-cons) | |
| 885 (byte-defop 67 0 byte-list1) | |
| 886 (byte-defop 68 -1 byte-list2) | |
| 887 (byte-defop 69 -2 byte-list3) | |
| 888 (byte-defop 70 -3 byte-list4) | |
| 889 (byte-defop 71 0 byte-length) | |
| 890 (byte-defop 72 -1 byte-aref) | |
| 891 (byte-defop 73 -2 byte-aset) | |
| 892 (byte-defop 74 0 byte-symbol-value) | |
| 893 (byte-defop 75 0 byte-symbol-function) ; this was commented out | |
| 894 (byte-defop 76 -1 byte-set) | |
| 895 (byte-defop 77 -1 byte-fset) ; this was commented out | |
| 896 (byte-defop 78 -1 byte-get) | |
|
5089
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
897 (byte-defop 79 -2 byte-subseq) |
| 428 | 898 (byte-defop 80 -1 byte-concat2) |
| 899 (byte-defop 81 -2 byte-concat3) | |
| 900 (byte-defop 82 -3 byte-concat4) | |
| 901 (byte-defop 83 0 byte-sub1) | |
| 902 (byte-defop 84 0 byte-add1) | |
| 903 (byte-defop 85 -1 byte-eqlsign) | |
| 904 (byte-defop 86 -1 byte-gtr) | |
| 905 (byte-defop 87 -1 byte-lss) | |
| 906 (byte-defop 88 -1 byte-leq) | |
| 907 (byte-defop 89 -1 byte-geq) | |
| 908 (byte-defop 90 -1 byte-diff) | |
| 909 (byte-defop 91 0 byte-negate) | |
| 910 (byte-defop 92 -1 byte-plus) | |
| 911 (byte-defop 93 -1 byte-max) | |
| 912 (byte-defop 94 -1 byte-min) | |
| 913 (byte-defop 95 -1 byte-mult) | |
| 914 (byte-defop 96 1 byte-point) | |
| 915 (byte-defop 97 -1 byte-eq) ; new as of v20 | |
| 916 (byte-defop 98 0 byte-goto-char) | |
| 917 (byte-defop 99 0 byte-insert) | |
| 918 (byte-defop 100 1 byte-point-max) | |
| 919 (byte-defop 101 1 byte-point-min) | |
| 920 (byte-defop 102 0 byte-char-after) | |
| 921 (byte-defop 103 1 byte-following-char) | |
| 922 (byte-defop 104 1 byte-preceding-char) | |
| 923 (byte-defop 105 1 byte-current-column) | |
| 924 (byte-defop 106 0 byte-indent-to) | |
| 925 (byte-defop 107 -1 byte-equal) ; new as of v20 | |
| 926 (byte-defop 108 1 byte-eolp) | |
| 927 (byte-defop 109 1 byte-eobp) | |
| 928 (byte-defop 110 1 byte-bolp) | |
| 929 (byte-defop 111 1 byte-bobp) | |
| 930 (byte-defop 112 1 byte-current-buffer) | |
| 931 (byte-defop 113 0 byte-set-buffer) | |
| 932 (byte-defop 114 0 byte-save-current-buffer | |
| 933 "To make a binding to record the current buffer.") | |
| 934 ;;(byte-defop 114 1 byte-read-char-OBSOLETE) ;obsolete as of v19 | |
| 935 (byte-defop 115 -1 byte-memq) ; new as of v20 | |
| 936 (byte-defop 116 1 byte-interactive-p) | |
| 937 | |
| 938 (byte-defop 117 0 byte-forward-char) | |
| 939 (byte-defop 118 0 byte-forward-word) | |
| 940 (byte-defop 119 -1 byte-skip-chars-forward) | |
| 941 (byte-defop 120 -1 byte-skip-chars-backward) | |
| 942 (byte-defop 121 0 byte-forward-line) | |
| 943 (byte-defop 122 0 byte-char-syntax) | |
| 944 (byte-defop 123 -1 byte-buffer-substring) | |
| 945 (byte-defop 124 -1 byte-delete-region) | |
| 946 (byte-defop 125 -1 byte-narrow-to-region) | |
| 947 (byte-defop 126 1 byte-widen) | |
| 948 (byte-defop 127 0 byte-end-of-line) | |
| 949 | |
| 950 ;; unused: 128 | |
| 951 | |
| 952 ;; These store their argument in the next two bytes | |
| 953 (byte-defop 129 1 byte-constant2 | |
| 954 "for reference to a constant with vector index >= byte-constant-limit") | |
| 955 (byte-defop 130 0 byte-goto "for unconditional jump") | |
| 956 (byte-defop 131 -1 byte-goto-if-nil "to pop value and jump if it's nil") | |
| 957 (byte-defop 132 -1 byte-goto-if-not-nil | |
| 958 "to pop value and jump if it's not nil") | |
| 959 (byte-defop 133 -1 byte-goto-if-nil-else-pop | |
| 960 "to examine top-of-stack, jump and don't pop it if it's nil, | |
| 961 otherwise pop it") | |
| 962 (byte-defop 134 -1 byte-goto-if-not-nil-else-pop | |
| 963 "to examine top-of-stack, jump and don't pop it if it's non-nil, | |
| 964 otherwise pop it") | |
| 965 | |
| 966 (byte-defop 135 -1 byte-return "to pop a value and return it from `byte-code'") | |
| 967 (byte-defop 136 -1 byte-discard "to discard one value from stack") | |
| 968 (byte-defop 137 1 byte-dup "to duplicate the top of the stack") | |
| 969 | |
| 970 (byte-defop 138 0 byte-save-excursion | |
| 971 "to make a binding to record the buffer, point and mark") | |
|
4775
1d61580e0cf7
Remove Fsave_window_excursion from window.c, it's overridden by Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4743
diff
changeset
|
972 (byte-defop 139 0 byte-save-window-excursion ; almost obsolete |
| 428 | 973 "to make a binding to record entire window configuration") |
| 974 (byte-defop 140 0 byte-save-restriction | |
| 975 "to make a binding to record the current buffer clipping restrictions") | |
| 976 (byte-defop 141 -1 byte-catch | |
| 977 "for catch. Takes, on stack, the tag and an expression for the body") | |
| 978 (byte-defop 142 -1 byte-unwind-protect | |
| 979 "for unwind-protect. Takes, on stack, an expression for the unwind-action") | |
| 980 | |
| 981 ;; For condition-case. Takes, on stack, the variable to bind, | |
| 982 ;; an expression for the body, and a list of clauses. | |
| 983 (byte-defop 143 -2 byte-condition-case) | |
| 984 | |
| 985 ;; For entry to with-output-to-temp-buffer. | |
| 986 ;; Takes, on stack, the buffer name. | |
| 987 ;; Binds standard-output and does some other things. | |
| 988 ;; Returns with temp buffer on the stack in place of buffer name. | |
| 989 (byte-defop 144 0 byte-temp-output-buffer-setup) | |
| 990 | |
| 991 ;; For exit from with-output-to-temp-buffer. | |
| 992 ;; Expects the temp buffer on the stack underneath value to return. | |
| 993 ;; Pops them both, then pushes the value back on. | |
| 994 ;; Unbinds standard-output and makes the temp buffer visible. | |
| 995 (byte-defop 145 -1 byte-temp-output-buffer-show) | |
| 996 | |
| 997 ;; To unbind back to the beginning of this frame. | |
| 998 ;; Not used yet, but will be needed for tail-recursion elimination. | |
| 999 (byte-defop 146 0 byte-unbind-all) | |
| 1000 | |
| 1001 (byte-defop 147 -2 byte-set-marker) | |
| 1002 (byte-defop 148 0 byte-match-beginning) | |
| 1003 (byte-defop 149 0 byte-match-end) | |
| 1004 (byte-defop 150 0 byte-upcase) | |
| 1005 (byte-defop 151 0 byte-downcase) | |
| 1006 (byte-defop 152 -1 byte-string=) | |
| 1007 (byte-defop 153 -1 byte-string<) | |
| 1008 (byte-defop 154 -1 byte-old-equal) | |
| 1009 (byte-defop 155 -1 byte-nthcdr) | |
| 1010 (byte-defop 156 -1 byte-elt) | |
| 1011 (byte-defop 157 -1 byte-old-member) | |
| 1012 (byte-defop 158 -1 byte-old-assq) | |
| 1013 (byte-defop 159 0 byte-nreverse) | |
| 1014 (byte-defop 160 -1 byte-setcar) | |
| 1015 (byte-defop 161 -1 byte-setcdr) | |
| 1016 (byte-defop 162 0 byte-car-safe) | |
| 1017 (byte-defop 163 0 byte-cdr-safe) | |
| 1018 (byte-defop 164 -1 byte-nconc) | |
| 1019 (byte-defop 165 -1 byte-quo) | |
| 1020 (byte-defop 166 -1 byte-rem) | |
| 1021 (byte-defop 167 0 byte-numberp) | |
|
4885
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
1022 (byte-defop 168 0 byte-fixnump) |
| 428 | 1023 |
| 1024 ;; unused: 169 | |
| 1025 | |
| 1026 ;; These are not present in FSF. | |
| 1027 ;; | |
| 1028 (byte-defop 170 0 byte-rel-goto) | |
| 1029 (byte-defop 171 -1 byte-rel-goto-if-nil) | |
| 1030 (byte-defop 172 -1 byte-rel-goto-if-not-nil) | |
| 1031 (byte-defop 173 -1 byte-rel-goto-if-nil-else-pop) | |
| 1032 (byte-defop 174 -1 byte-rel-goto-if-not-nil-else-pop) | |
| 1033 | |
| 1034 (byte-defop 175 nil byte-listN) | |
| 1035 (byte-defop 176 nil byte-concatN) | |
| 1036 (byte-defop 177 nil byte-insertN) | |
| 1037 | |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1038 (byte-defop 178 1 byte-bind-multiple-value-limits) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1039 (byte-defop 179 -3 byte-multiple-value-list-internal) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1040 (byte-defop 180 0 byte-multiple-value-call) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1041 (byte-defop 181 -1 byte-throw) |
| 428 | 1042 |
| 1043 ;; these ops are new to v20 | |
| 1044 (byte-defop 182 -1 byte-member) | |
| 1045 (byte-defop 183 -1 byte-assq) | |
| 1046 | |
| 1047 ;; unused: 184-191 | |
| 1048 | |
| 1049 (byte-defop 192 1 byte-constant "for reference to a constant") | |
| 1050 ;; codes 193-255 are consumed by byte-constant. | |
| 1051 (defconst byte-constant-limit 64 | |
| 1052 "Exclusive maximum index usable in the `byte-constant' opcode.") | |
| 1053 | |
| 444 | 1054 (defconst byte-goto-ops |
| 1055 '(byte-goto byte-goto-if-nil byte-goto-if-not-nil | |
| 1056 byte-goto-if-nil-else-pop | |
| 1057 byte-goto-if-not-nil-else-pop) | |
| 428 | 1058 "List of byte-codes whose offset is a pc.") |
| 1059 | |
| 1060 (defconst byte-goto-always-pop-ops | |
| 444 | 1061 '(byte-goto-if-nil byte-goto-if-not-nil)) |
| 428 | 1062 |
| 1063 (defconst byte-rel-goto-ops | |
| 444 | 1064 '(byte-rel-goto byte-rel-goto-if-nil byte-rel-goto-if-not-nil |
| 1065 byte-rel-goto-if-nil-else-pop byte-rel-goto-if-not-nil-else-pop) | |
| 428 | 1066 "byte-codes for relative jumps.") |
| 1067 | |
| 1068 (byte-extrude-byte-code-vectors) | |
| 1069 | |
| 1070 ;;; lapcode generator | |
| 1071 ;;; | |
| 1072 ;;; the byte-compiler now does source -> lapcode -> bytecode instead of | |
| 1073 ;;; source -> bytecode, because it's a lot easier to make optimizations | |
| 1074 ;;; on lapcode than on bytecode. | |
| 1075 ;;; | |
| 1076 ;;; Elements of the lapcode list are of the form (<instruction> . <parameter>) | |
| 1077 ;;; where instruction is a symbol naming a byte-code instruction, | |
| 1078 ;;; and parameter is an argument to that instruction, if any. | |
| 1079 ;;; | |
| 1080 ;;; The instruction can be the pseudo-op TAG, which means that this position | |
| 1081 ;;; in the instruction stream is a target of a goto. (car PARAMETER) will be | |
| 1082 ;;; the PC for this location, and the whole instruction "(TAG pc)" will be the | |
| 1083 ;;; parameter for some goto op. | |
| 1084 ;;; | |
| 1085 ;;; If the operation is varbind, varref, varset or push-constant, then the | |
| 1086 ;;; parameter is (variable/constant . index_in_constant_vector). | |
| 1087 ;;; | |
| 1088 ;;; First, the source code is macroexpanded and optimized in various ways. | |
| 1089 ;;; Then the resultant code is compiled into lapcode. Another set of | |
| 1090 ;;; optimizations are then run over the lapcode. Then the variables and | |
| 1091 ;;; constants referenced by the lapcode are collected and placed in the | |
| 1092 ;;; constants-vector. (This happens now so that variables referenced by dead | |
| 1093 ;;; code don't consume space.) And finally, the lapcode is transformed into | |
| 1094 ;;; compacted byte-code. | |
| 1095 ;;; | |
| 1096 ;;; A distinction is made between variables and constants because the variable- | |
| 1097 ;;; referencing instructions are more sensitive to the variables being near the | |
| 1098 ;;; front of the constants-vector than the constant-referencing instructions. | |
| 1099 ;;; Also, this lets us notice references to free variables. | |
| 1100 | |
| 1101 (defun byte-compile-lapcode (lap) | |
| 1102 "Turns lapcode into bytecode. The lapcode is destroyed." | |
| 1103 ;; Lapcode modifications: changes the ID of a tag to be the tag's PC. | |
| 1104 (let ((pc 0) ; Program counter | |
| 1105 op off ; Operation & offset | |
| 1106 (bytes '()) ; Put the output bytes here | |
| 1107 (patchlist nil) ; List of tags and goto's to patch | |
| 1108 rest rel tmp) | |
| 1109 (while lap | |
| 1110 (setq op (car (car lap)) | |
| 1111 off (cdr (car lap))) | |
| 1112 (cond ((not (symbolp op)) | |
| 1113 (error "Non-symbolic opcode `%s'" op)) | |
| 1114 ((eq op 'TAG) | |
| 1115 (setcar off pc) | |
| 1116 (push off patchlist)) | |
| 1117 ((memq op byte-goto-ops) | |
| 1118 (setq pc (+ pc 3)) | |
| 1119 (setq bytes (cons (cons pc (cdr off)) | |
| 1120 (cons nil | |
| 1121 (cons (symbol-value op) bytes)))) | |
| 1122 (push bytes patchlist)) | |
| 1123 (t | |
| 1124 (setq bytes | |
| 1125 (cond ((cond ((consp off) | |
| 1126 ;; Variable or constant reference | |
| 1127 (setq off (cdr off)) | |
| 1128 (eq op 'byte-constant))) | |
| 1129 (cond ((< off byte-constant-limit) | |
| 1130 (setq pc (1+ pc)) | |
| 1131 (cons (+ byte-constant off) bytes)) | |
| 1132 (t | |
| 1133 (setq pc (+ 3 pc)) | |
| 1134 (cons (lsh off -8) | |
| 1135 (cons (logand off 255) | |
| 1136 (cons byte-constant2 bytes)))))) | |
| 1137 ((and (<= byte-listN (symbol-value op)) | |
| 1138 (<= (symbol-value op) byte-insertN)) | |
| 1139 (setq pc (+ 2 pc)) | |
| 1140 (cons off (cons (symbol-value op) bytes))) | |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1141 ((= byte-multiple-value-call (symbol-value op)) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1142 (setq pc (1+ pc)) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1143 ;; Ignore off. |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1144 (cons (symbol-value op) bytes)) |
| 428 | 1145 ((< off 6) |
| 1146 (setq pc (1+ pc)) | |
| 1147 (cons (+ (symbol-value op) off) bytes)) | |
| 1148 ((< off 256) | |
| 1149 (setq pc (+ 2 pc)) | |
| 1150 (cons off (cons (+ (symbol-value op) 6) bytes))) | |
| 1151 (t | |
| 1152 (setq pc (+ 3 pc)) | |
| 1153 (cons (lsh off -8) | |
| 1154 (cons (logand off 255) | |
| 1155 (cons (+ (symbol-value op) 7) | |
| 1156 bytes)))))))) | |
| 1157 (setq lap (cdr lap))) | |
| 1158 ;;(if (not (= pc (length bytes))) | |
| 1159 ;; (error "Compiler error: pc mismatch - %s %s" pc (length bytes))) | |
| 1160 (cond (t ;; starting with Emacs 19. | |
| 1161 ;; Make relative jumps | |
| 1162 (setq patchlist (nreverse patchlist)) | |
| 1163 (while (progn | |
| 1164 (setq off 0) ; PC change because of deleted bytes | |
| 1165 (setq rest patchlist) | |
| 1166 (while rest | |
| 1167 (setq tmp (car rest)) | |
| 1168 (and (consp (car tmp)) ; Jump | |
| 1169 (prog1 (null (nth 1 tmp)) ; Absolute jump | |
| 1170 (setq tmp (car tmp))) | |
| 1171 (progn | |
| 1172 (setq rel (- (car (cdr tmp)) (car tmp))) | |
| 1173 (and (<= -129 rel) (< rel 128))) | |
| 1174 (progn | |
| 1175 ;; Convert to relative jump. | |
| 1176 (setcdr (car rest) (cdr (cdr (car rest)))) | |
| 1177 (setcar (cdr (car rest)) | |
| 1178 (+ (car (cdr (car rest))) | |
| 1179 (- byte-rel-goto byte-goto))) | |
| 1180 (setq off (1- off)))) | |
| 1181 (setcar tmp (+ (car tmp) off)) ; Adjust PC | |
| 1182 (setq rest (cdr rest))) | |
| 1183 ;; If optimizing, repeat until no change. | |
| 1184 (and byte-optimize | |
| 1185 (not (zerop off))))))) | |
| 1186 ;; Patch PC into jumps | |
| 1187 (let (bytes) | |
| 1188 (while patchlist | |
| 1189 (setq bytes (car patchlist)) | |
| 1190 (cond ((atom (car bytes))) ; Tag | |
| 1191 ((nth 1 bytes) ; Relative jump | |
| 1192 (setcar bytes (+ (- (car (cdr (car bytes))) (car (car bytes))) | |
| 1193 128))) | |
| 1194 (t ; Absolute jump | |
| 1195 (setq pc (car (cdr (car bytes)))) ; Pick PC from tag | |
| 1196 (setcar (cdr bytes) (logand pc 255)) | |
| 1197 (setcar bytes (lsh pc -8)))) | |
| 1198 (setq patchlist (cdr patchlist)))) | |
| 1199 (concat (nreverse bytes)))) | |
| 1200 | |
| 1201 | |
| 1202 ;;; byte compiler messages | |
| 1203 | |
| 1204 (defvar byte-compile-current-form nil) | |
| 1205 (defvar byte-compile-current-file nil) | |
| 1206 (defvar byte-compile-dest-file nil) | |
| 1207 | |
| 1208 (defmacro byte-compile-log (format-string &rest args) | |
| 1209 `(when (and byte-optimize (memq byte-optimize-log '(t source))) | |
| 1210 (let ((print-escape-newlines t) | |
| 1211 (print-level 4) | |
| 1212 (print-length 4)) | |
| 1213 (byte-compile-log-1 (format ,format-string ,@args))))) | |
| 1214 | |
| 1215 (defconst byte-compile-last-warned-form 'nothing) | |
| 1216 | |
| 1217 ;; Log a message STRING in *Compile-Log*. | |
| 1218 ;; Also log the current function and file if not already done. | |
| 1219 (defun byte-compile-log-1 (string &optional fill) | |
| 1220 (let* ((this-form (or byte-compile-current-form "toplevel forms")) | |
| 1221 (while-compiling-msg | |
| 1222 (when (or byte-compile-current-file | |
| 1223 (not (eq this-form byte-compile-last-warned-form))) | |
| 1224 (format | |
| 1225 "While compiling %s%s:" | |
| 1226 this-form | |
| 1227 (cond | |
| 1228 ((stringp byte-compile-current-file) | |
| 1229 (concat " in file " byte-compile-current-file)) | |
| 1230 ((bufferp byte-compile-current-file) | |
| 1231 (concat " in buffer " | |
| 1232 (buffer-name byte-compile-current-file))) | |
| 1233 ("")))))) | |
| 1234 (if noninteractive | |
| 1235 (progn | |
| 1236 (when while-compiling-msg (message "%s" while-compiling-msg)) | |
| 1237 (message " %s" string)) | |
| 1238 (with-current-buffer (get-buffer-create "*Compile-Log*") | |
| 1239 (goto-char (point-max)) | |
| 1240 (when byte-compile-current-file | |
| 1241 (when (> (point-max) (point-min)) | |
| 1242 (insert "\n\^L\n")) | |
| 1243 (insert (current-time-string) "\n")) | |
| 1244 (when while-compiling-msg (insert while-compiling-msg "\n")) | |
| 1245 (insert " " string "\n") | |
| 1246 (when (and fill (not (string-match "\n" string))) | |
| 1247 (let ((fill-prefix " ") | |
| 1248 (fill-column 78)) | |
| 1249 (fill-paragraph nil))))) | |
| 1250 (setq byte-compile-current-file nil) | |
| 1251 (setq byte-compile-last-warned-form this-form))) | |
| 1252 | |
| 1253 ;; Log the start of a file in *Compile-Log*, and mark it as done. | |
| 1254 ;; But do nothing in batch mode. | |
| 1255 (defun byte-compile-log-file () | |
| 1256 (when (and byte-compile-current-file (not noninteractive)) | |
| 1257 (with-current-buffer (get-buffer-create "*Compile-Log*") | |
| 1258 (when (> (point-max) (point-min)) | |
| 1259 (goto-char (point-max)) | |
| 1260 (insert "\n\^L\n")) | |
| 1261 (insert "Compiling " | |
| 1262 (if (stringp byte-compile-current-file) | |
| 1263 (concat "file " byte-compile-current-file) | |
| 1264 (concat "buffer " (buffer-name byte-compile-current-file))) | |
| 1265 " at " (current-time-string) "\n") | |
| 1266 (setq byte-compile-current-file nil)))) | |
| 1267 | |
| 502 | 1268 (defvar byte-compile-inbuffer) |
| 1269 (defvar byte-compile-outbuffer) | |
| 1270 | |
| 428 | 1271 (defun byte-compile-warn (format &rest args) |
| 1272 (setq format (apply 'format format args)) | |
| 1273 (if byte-compile-error-on-warn | |
| 1274 (error "%s" format) ; byte-compile-file catches and logs it | |
| 1275 (byte-compile-log-1 (concat "** " format) t) | |
| 502 | 1276 |
| 1277 ;; This was a first attempt to add line numbers to the | |
| 1278 ;; byte-compilation output. Unfortunately, it doesn't work | |
| 1279 ;; perfectly: it reports the line number at the end of the form | |
| 1280 ;; (which may be an entire function), rather than the line number | |
| 1281 ;; of the actual problem. Doing this right is hard because we | |
| 1282 ;; currently use the built-in Lisp parser to parse the entire form | |
| 1283 ;; at once. What we basically need is a whole separate parser | |
| 1284 ;; that annotates its output with line numbers. For example, we | |
| 1285 ;; might modify the parser in lread.c so that, with the right | |
| 1286 ;; option set, it replaces every Lisp object contained in the | |
| 1287 ;; structure it returns with a cons of that object and the line | |
| 1288 ;; number it was found on (determined by counting newlines, | |
| 1289 ;; starting from some arbitrary point). You then have two | |
| 1290 ;; options: (a) Modify the byte compiler so that everything that | |
| 1291 ;; compiles a form deals with the new annotated form rather than | |
| 1292 ;; the old one, or (b) The byte compiler saves this structure | |
| 1293 ;; while converting it into a normal structure that's given to the | |
| 1294 ;; various form handlers, which need no (or less) modification. | |
| 1295 ;; In the former case, finding the line number is trivial because | |
| 1296 ;; it's in the form. In the latter case, finding the line number | |
| 1297 ;; depends on having a unique Lisp object that can be looked up in | |
| 1298 ;; the annotated structure -- i.e. a list, vector, or string. | |
| 1299 ;; You'd have to look at the various places where errors are spit | |
| 1300 ;; out (not very many, really), and make sure that such a unique | |
| 1301 ;; object is available. Then you do a depth-first search through | |
| 1302 ;; the annotated structure to find the object. | |
| 1303 ;; | |
| 1304 ;; An alternative way of doing (b) that's probably much more | |
| 1305 ;; efficient (and easier to implement) is simply to have the | |
| 1306 ;; parser in lread.c annotate every unique object using a separate | |
| 1307 ;; hash table. This also eliminates the need for a search to find | |
| 1308 ;; the line number. In order to be fine-grained enough to get at | |
| 1309 ;; every symbol in a form -- e.g. if we want to pinpoint a | |
| 1310 ;; particular undefined variable in a function call -- we need to | |
| 1311 ;; annotate every cons, not just each list. We still have | |
| 1312 ;; (probably unimportant) problems with vectors, since all we have | |
| 1313 ;; is the start of the vector. If we cared about this, we could | |
| 1314 ;; store in the hash table a list of the line numbers for each | |
| 1315 ;; item in the vector, not just its start. | |
| 1316 ;; | |
| 1317 ;; --ben | |
| 1318 | |
| 1319 ; (byte-compile-log-1 (concat "** line: " | |
| 1320 ; (save-excursion | |
| 1321 ; (set-buffer byte-compile-inbuffer) | |
| 1322 ; (int-to-string (line-number))) | |
| 1323 ; " " | |
| 1324 ; format) t) | |
| 428 | 1325 ;;; RMS says: |
| 1326 ;;; It is useless to flash warnings too fast to be read. | |
| 1327 ;;; Besides, they will all be shown at the end. | |
| 1328 ;;; and comments out the next two lines. | |
| 1329 (or noninteractive ; already written on stdout. | |
| 1330 (message "Warning: %s" format)))) | |
| 1331 | |
| 1332 ;;; This function should be used to report errors that have halted | |
| 1333 ;;; compilation of the current file. | |
| 1334 (defun byte-compile-report-error (error-info) | |
| 1335 (setq byte-compiler-error-flag t) | |
| 1336 (byte-compile-log-1 | |
| 1337 (concat "!! " | |
| 1338 (format (if (cdr error-info) "%s (%s)" "%s") | |
| 1339 (get (car error-info) 'error-message) | |
| 442 | 1340 (prin1-to-string (cdr error-info))))) |
| 1341 (if stack-trace-on-error | |
| 1342 (backtrace nil t))) | |
| 428 | 1343 |
| 1344 ;;; Used by make-obsolete. | |
| 1345 (defun byte-compile-obsolete (form) | |
| 1346 (let ((new (get (car form) 'byte-obsolete-info))) | |
| 1347 (if (memq 'obsolete byte-compile-warnings) | |
| 1348 (byte-compile-warn "%s is an obsolete function; %s" (car form) | |
| 1349 (if (stringp (car new)) | |
| 1350 (car new) | |
| 1351 (format "use %s instead." (car new))))) | |
| 1352 (funcall (or (cdr new) 'byte-compile-normal-call) form))) | |
| 1353 | |
| 1354 ;;; Used by make-obsolete. | |
| 1355 (defun byte-compile-compatible (form) | |
| 1356 (let ((new (get (car form) 'byte-compatible-info))) | |
| 1357 (if (memq 'pedantic byte-compile-warnings) | |
| 1358 (byte-compile-warn "%s is provided for compatibility; %s" (car form) | |
| 1359 (if (stringp (car new)) | |
| 1360 (car new) | |
| 1361 (format "use %s instead." (car new))))) | |
| 1362 (funcall (or (cdr new) 'byte-compile-normal-call) form))) | |
| 1363 | |
| 1364 ;; Compiler options | |
| 1365 | |
| 1366 (defconst byte-compiler-legal-options | |
| 1367 '((optimize byte-optimize (t nil source byte) val) | |
|
5503
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
1368 (file-format byte-compile-emacs19-compatibility (emacs20) |
| 428 | 1369 (eq val 'emacs19)) |
| 1370 (delete-errors byte-compile-delete-errors (t nil) val) | |
| 1371 (verbose byte-compile-verbose (t nil) val) | |
| 1372 (new-bytecodes byte-compile-new-bytecodes (t nil) val) | |
| 1373 (warnings byte-compile-warnings | |
|
4719
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
1374 ((callargs subr-callargs redefine free-vars unused-vars |
|
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
1375 unresolved discarded-consing quoted-lambda)) |
| 428 | 1376 val))) |
| 1377 | |
| 1378 ;; XEmacs addition | |
| 1379 (defconst byte-compiler-obsolete-options | |
|
5503
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
1380 '((new-bytecodes t) (byte-compile-emacs19-compatibility nil))) |
| 428 | 1381 |
| 1382 (defun byte-compiler-options-handler (&rest args) | |
| 1383 (let (key val desc choices) | |
| 1384 (while args | |
| 1385 (if (or (atom (car args)) (nthcdr 2 (car args)) (null (cdr (car args)))) | |
| 1386 (error "malformed byte-compiler-option %s" (car args))) | |
| 1387 (setq key (car (car args)) | |
| 1388 val (car (cdr (car args))) | |
| 1389 desc (assq key byte-compiler-legal-options)) | |
| 1390 (or desc | |
| 1391 (error "unknown byte-compiler option %s" key)) | |
| 1392 (if (assq key byte-compiler-obsolete-options) | |
| 1393 (byte-compile-warn "%s is an obsolete byte-compiler option." key)) | |
| 1394 (setq choices (nth 2 desc)) | |
| 1395 (if (consp (car choices)) | |
| 1396 (let* (this | |
| 1397 (handler 'cons) | |
| 1398 (var (nth 1 desc)) | |
| 1399 (ret (and (memq (car val) '(+ -)) | |
| 1400 (copy-sequence (if (eq t (symbol-value var)) | |
| 1401 (car choices) | |
| 1402 (symbol-value var)))))) | |
| 1403 (setq choices (car choices)) | |
| 1404 (while val | |
| 1405 (setq this (car val)) | |
| 1406 (cond ((memq this choices) | |
| 1407 (setq ret (funcall handler this ret))) | |
| 1408 ((eq this '+) (setq handler 'cons)) | |
| 1409 ((eq this '-) (setq handler 'delq)) | |
| 1410 ((error "%s only accepts %s." key choices))) | |
| 1411 (setq val (cdr val))) | |
| 1412 (set (nth 1 desc) ret)) | |
| 1413 (or (memq val choices) | |
| 1414 (error "%s must be one of %s." key choices)) | |
| 1415 (set (nth 1 desc) (eval (nth 3 desc)))) | |
| 1416 (setq args (cdr args))) | |
| 1417 nil)) | |
| 1418 | |
| 1419 ;;; sanity-checking arglists | |
| 1420 | |
| 1421 (defun byte-compile-fdefinition (name macro-p) | |
| 1422 (let* ((list (if (memq macro-p '(nil subr)) | |
| 1423 byte-compile-function-environment | |
| 1424 byte-compile-macro-environment)) | |
| 1425 (env (cdr (assq name list)))) | |
| 1426 (or env | |
| 1427 (let ((fn name)) | |
| 1428 (while (and (symbolp fn) | |
| 1429 (fboundp fn) | |
| 1430 (or (symbolp (symbol-function fn)) | |
| 1431 (consp (symbol-function fn)) | |
| 1432 (and (not macro-p) | |
| 1433 (compiled-function-p (symbol-function fn))) | |
| 1434 (and (eq macro-p 'subr) (subrp fn)))) | |
| 1435 (setq fn (symbol-function fn))) | |
| 1436 (if (or (and (not macro-p) (compiled-function-p fn)) | |
| 1437 (and (eq macro-p 'subr) (subrp fn))) | |
| 1438 fn | |
| 1439 (and (consp fn) | |
| 1440 (not (eq macro-p 'subr)) | |
| 1441 (if (eq 'macro (car fn)) | |
| 1442 (cdr fn) | |
| 1443 (if macro-p | |
| 1444 nil | |
| 1445 (if (eq 'autoload (car fn)) | |
| 1446 nil | |
| 1447 fn))))))))) | |
| 1448 | |
| 1449 (defun byte-compile-arglist-signature (arglist) | |
| 1450 (let ((args 0) | |
| 1451 opts | |
| 1452 restp) | |
| 1453 (while arglist | |
| 1454 (cond ((eq (car arglist) '&optional) | |
| 1455 (or opts (setq opts 0))) | |
| 1456 ((eq (car arglist) '&rest) | |
| 1457 (if (cdr arglist) | |
| 1458 (setq restp t | |
| 1459 arglist nil))) | |
| 1460 (t | |
| 1461 (if opts | |
| 1462 (setq opts (1+ opts)) | |
| 1463 (setq args (1+ args))))) | |
| 1464 (setq arglist (cdr arglist))) | |
| 1465 (cons args (if restp nil (if opts (+ args opts) args))))) | |
| 1466 | |
| 1467 | |
| 1468 (defun byte-compile-arglist-signatures-congruent-p (old new) | |
| 1469 (not (or | |
| 1470 (> (car new) (car old)) ; requires more args now | |
| 1471 (and (null (cdr old)) ; tooks rest-args, doesn't any more | |
| 1472 (cdr new)) | |
| 1473 (and (cdr new) (cdr old) ; can't take as many args now | |
| 1474 (< (cdr new) (cdr old))) | |
| 1475 ))) | |
| 1476 | |
| 1477 (defun byte-compile-arglist-signature-string (signature) | |
| 1478 (cond ((null (cdr signature)) | |
| 1479 (format "%d+" (car signature))) | |
| 1480 ((= (car signature) (cdr signature)) | |
| 1481 (format "%d" (car signature))) | |
| 1482 (t (format "%d-%d" (car signature) (cdr signature))))) | |
| 1483 | |
| 1484 | |
| 1485 ;; Warn if the form is calling a function with the wrong number of arguments. | |
| 1486 (defun byte-compile-callargs-warn (form) | |
| 1487 (let* ((def (or (byte-compile-fdefinition (car form) nil) | |
| 1488 (byte-compile-fdefinition (car form) t))) | |
| 1489 (sig (and def (byte-compile-arglist-signature | |
| 1490 (if (eq 'lambda (car-safe def)) | |
| 1491 (nth 1 def) | |
| 1492 (if (compiled-function-p def) | |
| 1493 (compiled-function-arglist def) | |
| 1494 '(&rest def)))))) | |
| 1495 (ncall (length (cdr form)))) | |
| 1496 (if (and (null def) | |
| 1497 (fboundp 'subr-min-args) | |
| 1498 (setq def (byte-compile-fdefinition (car form) 'subr))) | |
| 1499 (setq sig (cons (subr-min-args def) (subr-max-args def)))) | |
| 1500 (if sig | |
| 1501 (if (or (< ncall (car sig)) | |
| 1502 (and (cdr sig) (> ncall (cdr sig)))) | |
| 1503 (byte-compile-warn | |
| 1504 "%s called with %d argument%s, but %s %s" | |
| 1505 (car form) ncall | |
| 1506 (if (= 1 ncall) "" "s") | |
| 1507 (if (< ncall (car sig)) | |
| 1508 "requires" | |
| 1509 "accepts only") | |
| 1510 (byte-compile-arglist-signature-string sig))) | |
| 1511 (or (fboundp (car form)) ; might be a subr or autoload. | |
| 1512 ;; ## this doesn't work with recursion. | |
| 1513 (eq (car form) byte-compile-current-form) | |
| 1514 ;; It's a currently-undefined function. | |
| 1515 ;; Remember number of args in call. | |
| 1516 (let ((cons (assq (car form) byte-compile-unresolved-functions)) | |
| 1517 (n (length (cdr form)))) | |
| 1518 (if cons | |
| 1519 (or (memq n (cdr cons)) | |
| 1520 (setcdr cons (cons n (cdr cons)))) | |
| 1521 (setq byte-compile-unresolved-functions | |
| 1522 (cons (list (car form) n) | |
| 1523 byte-compile-unresolved-functions)))))))) | |
| 1524 | |
| 1525 ;; Warn if the function or macro is being redefined with a different | |
| 1526 ;; number of arguments. | |
| 1527 (defun byte-compile-arglist-warn (form macrop) | |
| 1528 (let ((old (byte-compile-fdefinition (nth 1 form) macrop))) | |
| 1529 (if old | |
| 1530 (let ((sig1 (byte-compile-arglist-signature | |
| 1531 (if (eq 'lambda (car-safe old)) | |
| 1532 (nth 1 old) | |
| 1533 (if (compiled-function-p old) | |
| 1534 (compiled-function-arglist old) | |
| 1535 '(&rest def))))) | |
| 1536 (sig2 (byte-compile-arglist-signature (nth 2 form)))) | |
| 1537 (or (byte-compile-arglist-signatures-congruent-p sig1 sig2) | |
| 1538 (byte-compile-warn "%s %s used to take %s %s, now takes %s" | |
| 1539 (if (eq (car form) 'defun) "function" "macro") | |
| 1540 (nth 1 form) | |
| 1541 (byte-compile-arglist-signature-string sig1) | |
| 1542 (if (equal sig1 '(1 . 1)) "argument" "arguments") | |
| 1543 (byte-compile-arglist-signature-string sig2)))) | |
| 1544 ;; This is the first definition. See if previous calls are compatible. | |
| 1545 (let ((calls (assq (nth 1 form) byte-compile-unresolved-functions)) | |
| 1546 nums sig min max) | |
| 1547 (if calls | |
| 1548 (progn | |
| 1549 (setq sig (byte-compile-arglist-signature (nth 2 form)) | |
| 1550 nums (sort (copy-sequence (cdr calls)) (function <)) | |
| 1551 min (car nums) | |
| 1552 max (car (nreverse nums))) | |
| 1553 (if (or (< min (car sig)) | |
| 1554 (and (cdr sig) (> max (cdr sig)))) | |
| 1555 (byte-compile-warn | |
| 1556 "%s being defined to take %s%s, but was previously called with %s" | |
| 1557 (nth 1 form) | |
| 1558 (byte-compile-arglist-signature-string sig) | |
| 1559 (if (equal sig '(1 . 1)) " arg" " args") | |
| 1560 (byte-compile-arglist-signature-string (cons min max)))) | |
| 1561 | |
| 1562 (setq byte-compile-unresolved-functions | |
|
5652
cc6f0266bc36
Avoid #'delq in core Lisp, for the sake of style, a very slightly smaller binary
Aidan Kehoe <kehoea@parhasard.net>
parents:
5651
diff
changeset
|
1563 (delete* calls byte-compile-unresolved-functions))))) |
| 428 | 1564 ))) |
| 1565 | |
| 1566 ;; If we have compiled any calls to functions which are not known to be | |
| 1567 ;; defined, issue a warning enumerating them. | |
| 1568 ;; `unresolved' in the list `byte-compile-warnings' disables this. | |
| 1569 (defun byte-compile-warn-about-unresolved-functions (&optional msg) | |
| 1570 (if (memq 'unresolved byte-compile-warnings) | |
| 1571 (let ((byte-compile-current-form (or msg "the end of the data"))) | |
| 1572 ;; First delete the autoloads from the list. | |
| 1573 (if byte-compile-autoload-environment | |
| 1574 (let ((rest byte-compile-unresolved-functions)) | |
| 1575 (while rest | |
| 1576 (if (assq (car (car rest)) byte-compile-autoload-environment) | |
| 1577 (setq byte-compile-unresolved-functions | |
|
5652
cc6f0266bc36
Avoid #'delq in core Lisp, for the sake of style, a very slightly smaller binary
Aidan Kehoe <kehoea@parhasard.net>
parents:
5651
diff
changeset
|
1578 (delete* (car rest) byte-compile-unresolved-functions))) |
| 428 | 1579 (setq rest (cdr rest))))) |
| 1580 ;; Now warn. | |
| 1581 (if (cdr byte-compile-unresolved-functions) | |
| 1582 (let* ((str "The following functions are not known to be defined: ") | |
| 1583 (L (+ (length str) 5)) | |
| 1584 (rest (reverse byte-compile-unresolved-functions)) | |
| 1585 s) | |
| 1586 (while rest | |
| 1587 (setq s (symbol-name (car (car rest))) | |
| 1588 L (+ L (length s) 2) | |
| 1589 rest (cdr rest)) | |
| 1590 (if (<= L (1- fill-column)) | |
| 1591 (setq str (concat str " " s (and rest ","))) | |
| 1592 (setq str (concat str "\n " s (and rest ",")) | |
| 1593 L (+ (length s) 4)))) | |
| 1594 (byte-compile-warn "%s" str)) | |
| 1595 (if byte-compile-unresolved-functions | |
| 1596 (byte-compile-warn "the function %s is not known to be defined." | |
| 1597 (car (car byte-compile-unresolved-functions))))))) | |
| 1598 nil) | |
| 1599 | |
| 1600 (defun byte-compile-defvar-p (var) | |
| 1601 ;; Whether the byte compiler thinks that non-lexical references to this | |
| 1602 ;; variable are ok. | |
| 1603 (or (globally-boundp var) | |
| 1604 (let ((rest byte-compile-bound-variables)) | |
| 1605 (while (and rest var) | |
| 1606 (if (and (eq var (car-safe (car rest))) | |
| 1607 (not (= 0 (logand (cdr (car rest)) | |
| 1608 byte-compile-global-bit)))) | |
| 1609 (setq var nil)) | |
| 1610 (setq rest (cdr rest))) | |
| 1611 ;; if var is nil at this point, it's a defvar in this file. | |
| 444 | 1612 (not var)) |
| 1613 ;; Perhaps (eval-when-compile (defvar foo)) | |
| 1614 (and (boundp 'current-load-list) | |
| 1615 (memq var current-load-list)))) | |
| 428 | 1616 |
| 1617 | |
| 1618 ;;; If we have compiled bindings of variables which have no referents, warn. | |
| 1619 (defun byte-compile-warn-about-unused-variables () | |
| 1620 (let ((rest byte-compile-bound-variables) | |
| 1621 (unreferenced '()) | |
| 1622 cell) | |
| 1623 (while (and rest | |
| 1624 ;; only warn about variables whose lifetime is now ending, | |
| 1625 ;; that is, variables from the lexical scope that is now | |
| 1626 ;; terminating. (Think nested lets.) | |
| 1627 (not (eq (car rest) 'new-scope))) | |
| 1628 (setq cell (car rest)) | |
| 1629 (if (and (= 0 (logand byte-compile-referenced-bit (cdr cell))) | |
| 1630 ;; Don't warn about declared-but-unused arguments, | |
| 1631 ;; for two reasons: first, the arglist structure | |
| 1632 ;; might be imposed by external forces, and we don't | |
| 1633 ;; have (declare (ignore x)) yet; and second, inline | |
| 1634 ;; expansion produces forms like | |
| 1635 ;; ((lambda (arg) (byte-code "..." [arg])) x) | |
| 1636 ;; which we can't (ok, well, don't) recognize as | |
| 1637 ;; containing a reference to arg, so every inline | |
| 1638 ;; expansion would generate a warning. (If we had | |
| 1639 ;; `ignore' then inline expansion could emit an | |
| 1640 ;; ignore declaration.) | |
| 1641 (= 0 (logand byte-compile-arglist-bit (cdr cell))) | |
| 1642 ;; Don't warn about defvars because this is a | |
| 1643 ;; legitimate special binding. | |
| 1644 (not (byte-compile-defvar-p (car cell)))) | |
| 1645 (setq unreferenced (cons (car cell) unreferenced))) | |
| 1646 (setq rest (cdr rest))) | |
| 1647 (setq unreferenced (nreverse unreferenced)) | |
| 1648 (while unreferenced | |
| 1649 (byte-compile-warn | |
| 1650 (format "variable %s bound but not referenced" (car unreferenced))) | |
| 1651 (setq unreferenced (cdr unreferenced))))) | |
| 1652 | |
| 1653 | |
| 1654 (defmacro byte-compile-constant-symbol-p (symbol) | |
| 1655 `(or (keywordp ,symbol) (memq ,symbol '(nil t)))) | |
| 1656 | |
| 1657 (defmacro byte-compile-constp (form) | |
| 1658 ;; Returns non-nil if FORM is a constant. | |
|
5282
dcc34e28cd84
Warn at byte-compile in #'the if FORM constant & not TYPE; fix byte-compile-constp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5269
diff
changeset
|
1659 `(cond ((consp ,form) (memq (car ,form) '(quote function))) |
| 428 | 1660 ((symbolp ,form) (byte-compile-constant-symbol-p ,form)) |
| 1661 (t))) | |
| 1662 | |
| 1663 (defmacro byte-compile-close-variables (&rest body) | |
| 1664 `(let | |
| 1665 (;; | |
| 1666 ;; Close over these variables to encapsulate the | |
| 1667 ;; compilation state | |
| 1668 ;; | |
| 1669 (byte-compile-macro-environment | |
| 1670 ;; Copy it because the compiler may patch into the | |
| 1671 ;; macroenvironment. | |
| 1672 (copy-alist byte-compile-initial-macro-environment)) | |
| 1673 (byte-compile-function-environment nil) | |
| 1674 (byte-compile-autoload-environment nil) | |
| 1675 (byte-compile-unresolved-functions nil) | |
| 1676 (byte-compile-bound-variables nil) | |
| 1677 (byte-compile-free-references nil) | |
| 1678 (byte-compile-free-assignments nil) | |
| 1679 ;; | |
| 1680 ;; Close over these variables so that `byte-compiler-options' | |
| 1681 ;; can change them on a per-file basis. | |
| 1682 ;; | |
| 1683 (byte-compile-verbose byte-compile-verbose) | |
| 1684 (byte-optimize byte-optimize) | |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1685 (byte-compile-checks-on-load |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
1686 byte-compile-checks-on-load) |
| 428 | 1687 (byte-compile-dynamic byte-compile-dynamic) |
| 1688 (byte-compile-dynamic-docstrings | |
| 1689 byte-compile-dynamic-docstrings) | |
| 1690 (byte-compile-warnings (if (eq byte-compile-warnings t) | |
| 1691 byte-compile-default-warnings | |
| 1692 byte-compile-warnings)) | |
| 1693 (byte-compile-file-domain nil)) | |
| 1694 (prog1 | |
| 1695 (progn ,@body) | |
| 1696 (if (memq 'unused-vars byte-compile-warnings) | |
| 1697 ;; done compiling in this scope, warn now. | |
| 1698 (byte-compile-warn-about-unused-variables))))) | |
| 1699 | |
| 1700 | |
| 1701 (defmacro displaying-byte-compile-warnings (&rest body) | |
| 1702 `(let* ((byte-compile-log-buffer (get-buffer-create "*Compile-Log*")) | |
| 1703 (byte-compile-point-max-prev (point-max byte-compile-log-buffer))) | |
| 1704 ;; Log the file name or buffer name. | |
| 1705 (byte-compile-log-file) | |
| 1706 ;; Record how much is logged now. | |
| 1707 ;; We will display the log buffer if anything more is logged | |
| 1708 ;; before the end of BODY. | |
| 1709 (defvar byte-compile-warnings-beginning) | |
| 1710 (let ((byte-compile-warnings-beginning | |
| 1711 (if (boundp 'byte-compile-warnings-beginning) | |
| 1712 byte-compile-warnings-beginning | |
| 1713 (point-max byte-compile-log-buffer)))) | |
| 1714 | |
| 1715 (unwind-protect | |
| 442 | 1716 (call-with-condition-handler |
|
5656
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
1717 #'byte-compile-report-error |
| 442 | 1718 #'(lambda () |
| 1719 (progn ,@body))) | |
| 428 | 1720 ;; Always set point in log to start of interesting output. |
| 1721 (with-current-buffer byte-compile-log-buffer | |
| 1722 (let ((show-begin | |
| 1723 (progn (goto-char byte-compile-point-max-prev) | |
| 1724 (skip-chars-forward "\^L\n") | |
| 1725 (point)))) | |
| 1726 ;; If there were compilation warnings, display them. | |
| 1727 (if temp-buffer-show-function | |
| 1728 (let ((show-buffer (get-buffer-create "*Compile-Log-Show*"))) | |
| 1729 ;; Always clean show-buffer, even when not displaying it, | |
| 1730 ;; so that misleading previous messages aren't left around. | |
| 1731 (with-current-buffer show-buffer | |
| 1732 (setq buffer-read-only nil) | |
| 1733 (erase-buffer)) | |
| 1734 (copy-to-buffer show-buffer show-begin (point-max)) | |
| 1735 (when (< byte-compile-warnings-beginning (point-max)) | |
| 1736 (funcall temp-buffer-show-function show-buffer))) | |
| 1737 (when (< byte-compile-warnings-beginning (point-max)) | |
| 1738 (select-window | |
| 1739 (prog1 (selected-window) | |
| 1740 (select-window (display-buffer (current-buffer))) | |
| 1741 (goto-char show-begin) | |
| 1742 (recenter 1))))))))))) | |
| 1743 | |
| 1744 | |
| 1745 ;;;###autoload | |
| 1746 (defun byte-force-recompile (directory) | |
| 1747 "Recompile every `.el' file in DIRECTORY that already has a `.elc' file. | |
| 1748 Files in subdirectories of DIRECTORY are processed also." | |
| 1749 (interactive "DByte force recompile (directory): ") | |
| 442 | 1750 (byte-recompile-directory directory nil nil t)) |
| 428 | 1751 |
| 1752 ;;;###autoload | |
| 1753 (defun byte-recompile-directory (directory &optional arg norecursion force) | |
| 1754 "Recompile every `.el' file in DIRECTORY that needs recompilation. | |
| 1755 This is if a `.elc' file exists but is older than the `.el' file. | |
| 444 | 1756 Files in subdirectories of DIRECTORY are also processed unless |
| 1757 optional argument NORECURSION is non-nil. | |
| 428 | 1758 |
| 1759 If the `.elc' file does not exist, normally the `.el' file is *not* compiled. | |
| 1760 But a prefix argument (optional second arg) means ask user, | |
| 1761 for each such `.el' file, whether to compile it. Prefix argument 0 means | |
| 1762 don't ask and compile the file anyway. | |
| 1763 | |
| 1764 A nonzero prefix argument also means ask about each subdirectory. | |
| 1765 | |
| 444 | 1766 If the fourth optional argument FORCE is non-nil, |
| 428 | 1767 recompile every `.el' file that already has a `.elc' file." |
| 1768 (interactive "DByte recompile directory: \nP") | |
| 1769 (if arg | |
| 1770 (setq arg (prefix-numeric-value arg))) | |
| 1771 (if noninteractive | |
| 1772 nil | |
| 1773 (save-some-buffers) | |
| 1774 (redraw-modeline)) | |
| 1775 (let ((directories (list (expand-file-name directory))) | |
| 1776 (file-count 0) | |
| 1777 (dir-count 0) | |
| 1778 last-dir) | |
| 1779 (displaying-byte-compile-warnings | |
| 1780 (while directories | |
| 1781 (setq directory (file-name-as-directory (car directories))) | |
| 1782 (or noninteractive (message "Checking %s..." directory)) | |
| 1783 (let ((files (directory-files directory)) | |
| 1784 source dest) | |
| 1785 (while files | |
| 1786 (setq source (expand-file-name (car files) directory)) | |
| 1787 (if (and (not (member (car files) '("." ".." "RCS" "CVS" "SCCS"))) | |
| 1788 ;; Stay away from directory back-links, etc: | |
| 1789 (not (file-symlink-p source)) | |
| 1790 (file-directory-p source) | |
| 1791 byte-recompile-directory-recursively) | |
| 1792 ;; This file is a subdirectory. Handle them differently. | |
| 1793 (if (or (null arg) | |
| 1794 (eq arg 0) | |
| 1795 (y-or-n-p (concat "Check " source "? "))) | |
| 1796 (setq directories | |
| 1797 (nconc directories (list source)))) | |
| 1798 ;; It is an ordinary file. Decide whether to compile it. | |
| 1799 (if (and (string-match emacs-lisp-file-regexp source) | |
| 1800 (not (auto-save-file-name-p source)) | |
| 502 | 1801 ;; make sure not a mule file we can't handle. |
| 1802 (or (not byte-recompile-ignore-uncompilable-mule-files) | |
| 1803 (featurep 'mule) | |
| 1804 (not (find-coding-system-magic-cookie-in-file | |
| 1805 source))) | |
| 428 | 1806 (setq dest (byte-compile-dest-file source)) |
| 1807 (if (file-exists-p dest) | |
| 1808 ;; File was already compiled. | |
| 1809 (or force (file-newer-than-file-p source dest)) | |
| 1810 ;; No compiled file exists yet. | |
| 1811 (and arg | |
| 1812 (or (eq 0 arg) | |
| 1813 (y-or-n-p (concat "Compile " source "? ")))))) | |
| 1814 (progn ;(if (and noninteractive (not byte-compile-verbose)) | |
| 1815 ; (message "Compiling %s..." source)) | |
| 1816 ; we do this in byte-compile-file. | |
| 1817 (if byte-recompile-directory-ignore-errors-p | |
| 1818 (batch-byte-compile-1 source) | |
| 1819 (byte-compile-file source)) | |
| 1820 (or noninteractive | |
| 1821 (message "Checking %s..." directory)) | |
| 1822 (setq file-count (1+ file-count)) | |
| 1823 (if (not (eq last-dir directory)) | |
| 1824 (setq last-dir directory | |
| 1825 dir-count (1+ dir-count))) | |
| 1826 ))) | |
| 1827 (setq files (cdr files)))) | |
| 1828 (setq directories (cdr directories)))) | |
| 1829 (message "Done (Total of %d file%s compiled%s)" | |
| 1830 file-count (if (= file-count 1) "" "s") | |
| 1831 (if (> dir-count 1) (format " in %d directories" dir-count) "")))) | |
| 1832 | |
| 1833 ;;;###autoload | |
| 1834 (defun byte-recompile-file (filename &optional force) | |
| 1835 "Recompile a file of Lisp code named FILENAME if it needs recompilation. | |
| 1836 This is if the `.elc' file exists but is older than the `.el' file. | |
| 1837 | |
| 1838 If the `.elc' file does not exist, normally the `.el' file is *not* | |
| 1839 compiled. But a prefix argument (optional second arg) means ask user | |
| 1840 whether to compile it. Prefix argument 0 don't ask and recompile anyway." | |
| 1841 (interactive "fByte recompile file: \nP") | |
| 1842 (let ((dest)) | |
| 1843 (if (and (string-match emacs-lisp-file-regexp filename) | |
| 1844 (not (auto-save-file-name-p filename)) | |
| 1845 (setq dest (byte-compile-dest-file filename)) | |
| 1846 (if (file-exists-p dest) | |
| 1847 (file-newer-than-file-p filename dest) | |
| 1848 (and force | |
| 1849 (or (eq 0 force) | |
| 502 | 1850 (y-or-n-p (concat "Compile " filename "? "))))) |
| 1851 (or (not byte-recompile-ignore-uncompilable-mule-files) | |
| 1852 (featurep 'mule) | |
| 1853 (not (find-coding-system-magic-cookie-in-file filename)))) | |
| 428 | 1854 (byte-compile-file filename)))) |
| 1855 | |
| 1856 ;;;###autoload | |
| 1857 (defun byte-compile-file (filename &optional load) | |
| 1858 "Compile a file of Lisp code named FILENAME into a file of byte code. | |
| 1859 The output file's name is made by appending `c' to the end of FILENAME. | |
| 1860 With prefix arg (noninteractively: 2nd arg), load the file after compiling." | |
| 1861 ;; (interactive "fByte compile file: \nP") | |
| 1862 (interactive | |
| 1863 (let ((file buffer-file-name) | |
| 1864 (file-name nil) | |
| 1865 (file-dir nil)) | |
| 1866 (and file | |
| 1867 (eq (cdr (assq 'major-mode (buffer-local-variables))) | |
| 1868 'emacs-lisp-mode) | |
| 1869 (setq file-name (file-name-nondirectory file) | |
| 1870 file-dir (file-name-directory file))) | |
| 1871 (list (read-file-name (if current-prefix-arg | |
| 1872 "Byte compile and load file: " | |
| 1873 "Byte compile file: ") | |
| 1874 file-dir nil nil file-name) | |
| 1875 current-prefix-arg))) | |
| 1876 ;; Expand now so we get the current buffer's defaults | |
| 1877 (setq filename (expand-file-name filename)) | |
| 1878 | |
| 1879 ;; If we're compiling a file that's in a buffer and is modified, offer | |
| 1880 ;; to save it first. | |
| 1881 (or noninteractive | |
| 1882 (let ((b (get-file-buffer (expand-file-name filename)))) | |
| 1883 (if (and b (buffer-modified-p b) | |
| 1884 (y-or-n-p (format "save buffer %s first? " (buffer-name b)))) | |
| 1885 (save-excursion (set-buffer b) (save-buffer))))) | |
| 1886 | |
| 1887 (if (or noninteractive byte-compile-verbose) ; XEmacs change | |
| 1888 (message "Compiling %s..." filename)) | |
| 1889 (let (;;(byte-compile-current-file (file-name-nondirectory filename)) | |
| 1890 (byte-compile-current-file filename) | |
| 1891 target-file input-buffer output-buffer | |
| 1892 byte-compile-dest-file) | |
| 1893 (setq target-file (byte-compile-dest-file filename)) | |
| 1894 (setq byte-compile-dest-file target-file) | |
| 1895 (save-excursion | |
| 1896 (setq input-buffer (get-buffer-create " *Compiler Input*")) | |
| 1897 (set-buffer input-buffer) | |
| 1898 (erase-buffer) | |
| 1899 (insert-file-contents filename) | |
| 1900 ;; Run hooks including the uncompression hook. | |
| 1901 ;; If they change the file name, then change it for the output also. | |
| 1902 (let ((buffer-file-name filename) | |
| 1903 (default-major-mode 'emacs-lisp-mode) | |
| 1904 (enable-local-eval nil)) | |
| 1905 (normal-mode) | |
| 1906 (setq filename buffer-file-name))) | |
| 1907 (setq byte-compiler-error-flag nil) | |
| 1908 ;; It is important that input-buffer not be current at this call, | |
| 1909 ;; so that the value of point set in input-buffer | |
| 1910 ;; within byte-compile-from-buffer lingers in that buffer. | |
| 1911 (setq output-buffer (byte-compile-from-buffer input-buffer filename)) | |
| 1912 (if byte-compiler-error-flag | |
| 1913 nil | |
| 1914 (if byte-compile-verbose | |
| 1915 (message "Compiling %s...done" filename)) | |
| 1916 (kill-buffer input-buffer) | |
| 1917 (save-excursion | |
| 1918 (set-buffer output-buffer) | |
| 1919 (goto-char (point-max)) | |
| 1920 (insert "\n") ; aaah, unix. | |
| 1921 (setq target-file (byte-compile-dest-file filename)) | |
| 1922 (unless byte-compile-overwrite-file | |
| 1923 (ignore-file-errors (delete-file target-file))) | |
| 1924 (if (file-writable-p target-file) | |
|
4529
6f41fb7f3a65
Protect .elc encoding from latin-unity.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4392
diff
changeset
|
1925 ;; 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
|
1926 ;; 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
|
1927 (let ((write-region-pre-hook nil)) |
|
6f41fb7f3a65
Protect .elc encoding from latin-unity.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4392
diff
changeset
|
1928 (write-region 1 (point-max) target-file)) |
| 428 | 1929 ;; This is just to give a better error message than write-region |
| 1930 (signal 'file-error | |
| 1931 (list "Opening output file" | |
| 1932 (if (file-exists-p target-file) | |
| 1933 "cannot overwrite file" | |
| 1934 "directory not writable or nonexistent") | |
| 1935 target-file))) | |
| 1936 (or byte-compile-overwrite-file | |
| 1937 (condition-case () | |
| 1938 (set-file-modes target-file (file-modes filename)) | |
| 1939 (error nil))) | |
| 1940 (kill-buffer (current-buffer))) | |
| 1941 (if (and byte-compile-generate-call-tree | |
| 1942 (or (eq t byte-compile-generate-call-tree) | |
| 1943 (y-or-n-p (format "Report call tree for %s? " filename)))) | |
| 1944 (save-excursion | |
| 1945 (display-call-tree filename))) | |
| 1946 (if load | |
| 1947 (load target-file)) | |
| 1948 t))) | |
| 1949 | |
| 1950 ;; RMS comments the next two out. | |
| 1951 | |
| 1952 ;;;###autoload | |
| 1953 (defun byte-compile-and-load-file (&optional filename) | |
| 1954 "Compile a file of Lisp code named FILENAME into a file of byte code, | |
| 1955 and then load it. The output file's name is made by appending \"c\" to | |
| 1956 the end of FILENAME." | |
| 1957 (interactive) | |
| 1958 (if filename ; I don't get it, (interactive-p) doesn't always work | |
| 1959 (byte-compile-file filename t) | |
| 1960 (let ((current-prefix-arg '(4))) | |
| 1961 (call-interactively 'byte-compile-file)))) | |
| 1962 | |
| 1963 ;;;###autoload | |
| 1964 (defun byte-compile-buffer (&optional buffer) | |
| 1965 "Byte-compile and evaluate contents of BUFFER (default: the current buffer)." | |
| 1966 (interactive "bByte compile buffer: ") | |
| 1967 (setq buffer (if buffer (get-buffer buffer) (current-buffer))) | |
| 1968 (message "Compiling %s..." buffer) | |
| 1969 (let* ((filename (or (buffer-file-name buffer) | |
| 1970 (prin1-to-string buffer))) | |
| 1971 (byte-compile-current-file buffer)) | |
| 1972 (byte-compile-from-buffer buffer filename t)) | |
| 1973 (message "Compiling %s...done" buffer) | |
| 1974 t) | |
| 1975 | |
| 1976 ;;; compiling a single function | |
| 1977 ;;;###autoload | |
| 1978 (defun compile-defun (&optional arg) | |
| 1979 "Compile and evaluate the current top-level form. | |
| 1980 Print the result in the minibuffer. | |
| 1981 With argument, insert value in current buffer after the form." | |
| 1982 (interactive "P") | |
| 1983 (save-excursion | |
| 1984 (end-of-defun) | |
| 1985 (beginning-of-defun) | |
| 1986 (let* ((byte-compile-current-file (buffer-file-name)) | |
| 1987 (load-file-name (buffer-file-name)) | |
| 1988 (byte-compile-last-warned-form 'nothing) | |
| 1989 (value (eval (displaying-byte-compile-warnings | |
| 1990 (byte-compile-sexp (read (current-buffer)) | |
| 1991 "toplevel forms"))))) | |
| 1992 (cond (arg | |
| 1993 (message "Compiling from buffer... done.") | |
| 1994 (prin1 value (current-buffer)) | |
| 1995 (insert "\n")) | |
| 1996 ((message "%s" (prin1-to-string value))))))) | |
| 1997 | |
| 1998 (defun byte-compile-from-buffer (byte-compile-inbuffer filename &optional eval) | |
| 1999 ;; buffer --> output-buffer, or buffer --> eval form, return nil | |
| 2000 (let (byte-compile-outbuffer | |
| 2001 ;; Prevent truncation of flonums and lists as we read and print them | |
| 2002 (float-output-format nil) | |
| 2003 (case-fold-search nil) | |
| 2004 (print-length nil) | |
| 2005 (print-level nil) | |
| 2006 ;; Simulate entry to byte-compile-top-level | |
| 2007 (byte-compile-constants nil) | |
| 2008 (byte-compile-variables nil) | |
| 2009 (byte-compile-tag-number 0) | |
| 2010 (byte-compile-depth 0) | |
| 2011 (byte-compile-maxdepth 0) | |
| 2012 (byte-compile-output nil) | |
| 2013 ;; #### This is bound in b-c-close-variables. | |
| 2014 ;; (byte-compile-warnings (if (eq byte-compile-warnings t) | |
| 2015 ;; byte-compile-warning-types | |
| 2016 ;; byte-compile-warnings)) | |
|
4623
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2017 (byte-compile-force-escape-quoted byte-compile-force-escape-quoted) |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2018 (byte-compile-using-dynamic nil)) |
| 428 | 2019 (byte-compile-close-variables |
| 2020 (save-excursion | |
| 2021 (setq byte-compile-outbuffer | |
| 2022 (set-buffer (get-buffer-create " *Compiler Output*"))) | |
| 2023 (erase-buffer) | |
| 2024 ;; (emacs-lisp-mode) | |
| 2025 (setq case-fold-search nil) | |
| 2026 (and filename | |
| 2027 (not eval) | |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2028 (byte-compile-maybe-reset-coding byte-compile-inbuffer |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2029 byte-compile-outbuffer)) |
|
4623
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2030 (setq byte-compile-using-dynamic |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2031 (or (symbol-value-in-buffer 'byte-compile-dynamic |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2032 byte-compile-inbuffer) |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2033 (symbol-value-in-buffer 'byte-compile-dynamic-docstrings |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2034 byte-compile-inbuffer))) |
| 428 | 2035 ;; This is a kludge. Some operating systems (OS/2, DOS) need to |
| 2036 ;; write files containing binary information specially. | |
| 2037 ;; Under most circumstances, such files will be in binary | |
| 2038 ;; overwrite mode, so those OS's use that flag to guess how | |
| 2039 ;; they should write their data. Advise them that .elc files | |
| 2040 ;; need to be written carefully. | |
| 2041 (setq overwrite-mode 'overwrite-mode-binary)) | |
| 2042 (displaying-byte-compile-warnings | |
| 2043 (save-excursion | |
|
4623
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2044 ;; All our save-excursions may have led to a less-than-useful |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2045 ;; value for point in the outbuffer: |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2046 (goto-char (point-max byte-compile-outbuffer) byte-compile-outbuffer) |
| 428 | 2047 (set-buffer byte-compile-inbuffer) |
| 2048 (goto-char 1) | |
| 2049 | |
| 2050 ;; Compile the forms from the input buffer. | |
| 2051 (while (progn | |
| 2052 (while (progn (skip-chars-forward " \t\n\^L") | |
| 2053 (looking-at ";")) | |
| 2054 (forward-line 1)) | |
| 2055 (not (eobp))) | |
|
5568
b039c0f018b8
Error if byte-compiling a form hasn't wrapped byte-compile-inbuffer.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5566
diff
changeset
|
2056 (byte-compile-file-form (read byte-compile-inbuffer)) |
|
b039c0f018b8
Error if byte-compiling a form hasn't wrapped byte-compile-inbuffer.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5566
diff
changeset
|
2057 (or (eq byte-compile-inbuffer (current-buffer)) |
|
b039c0f018b8
Error if byte-compiling a form hasn't wrapped byte-compile-inbuffer.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5566
diff
changeset
|
2058 (error 'invalid-state |
|
b039c0f018b8
Error if byte-compiling a form hasn't wrapped byte-compile-inbuffer.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5566
diff
changeset
|
2059 "byte compiling didn't save-excursion appropriately" |
|
b039c0f018b8
Error if byte-compiling a form hasn't wrapped byte-compile-inbuffer.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5566
diff
changeset
|
2060 (current-buffer)))) |
| 428 | 2061 |
| 2062 ;; Compile pending forms at end of file. | |
| 2063 (byte-compile-flush-pending) | |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2064 (byte-compile-insert-header filename byte-compile-inbuffer |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2065 byte-compile-outbuffer) |
| 428 | 2066 (byte-compile-warn-about-unresolved-functions) |
| 2067 ;; Should we always do this? When calling multiple files, it | |
| 2068 ;; would be useful to delay this warning until all have | |
| 2069 ;; been compiled. | |
| 2070 (setq byte-compile-unresolved-functions nil))) | |
| 2071 (save-excursion | |
| 2072 (set-buffer byte-compile-outbuffer) | |
|
4623
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2073 (goto-char (point-min)) |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2074 (when (and (or byte-compile-using-dynamic |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2075 (eq buffer-file-coding-system 'raw-text-unix)) |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2076 (re-search-forward "[^\x00-\xff]" nil t)) |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2077 (when (or noninteractive byte-compile-verbose) |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2078 (message |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2079 "%s: includes char above ?\\xFF, recompiling sans dynamic features." |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2080 filename)) |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2081 (set-symbol-value-in-buffer 'byte-compile-dynamic nil |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2082 byte-compile-inbuffer) |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2083 (set-symbol-value-in-buffer 'byte-compile-dynamic-docstrings nil |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2084 byte-compile-inbuffer) |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2085 (setq byte-compile-force-escape-quoted t |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2086 byte-compile-outbuffer |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2087 (byte-compile-from-buffer byte-compile-inbuffer |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2088 filename eval))))) |
| 428 | 2089 (if (not eval) |
| 2090 byte-compile-outbuffer | |
| 2091 (let (form) | |
| 2092 (while (condition-case nil | |
| 2093 (progn (setq form (read byte-compile-outbuffer)) | |
| 2094 t) | |
| 2095 (end-of-file nil)) | |
| 2096 (eval form))) | |
| 2097 (kill-buffer byte-compile-outbuffer) | |
| 2098 nil))) | |
| 2099 | |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2100 (defvar byte-compile-checks-and-comments-space 475 |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2101 "Number of octets of space for checks and comments; used by the dynamic |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2102 docstrings code.") |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2103 |
| 428 | 2104 (defun byte-compile-insert-header (filename byte-compile-inbuffer |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2105 byte-compile-outbuffer) |
| 428 | 2106 (set-buffer byte-compile-inbuffer) |
|
4686
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2107 (let (comments) |
| 428 | 2108 (set-buffer byte-compile-outbuffer) |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2109 (delete-region 1 (1+ byte-compile-checks-and-comments-space)) |
| 428 | 2110 (goto-char 1) |
| 2111 ;; | |
| 2112 ;; The magic number of .elc files is ";ELC", or 0x3B454C43. After that is | |
| 2113 ;; the file-format version number (19 or 20) as a byte, followed by some | |
| 2114 ;; nulls. The primary motivation for doing this is to get some binary | |
| 2115 ;; characters up in the first line of the file so that `diff' will simply | |
| 2116 ;; say "Binary files differ" instead of actually doing a diff of two .elc | |
| 2117 ;; files. An extra benefit is that you can add this to /etc/magic: | |
| 2118 ;; | |
| 613 | 2119 ;; 0 string ;ELC XEmacs Lisp compiled file, |
| 428 | 2120 ;; >4 byte x version %d |
| 2121 ;; | |
| 2122 (insert | |
| 2123 ";ELC" | |
|
5503
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
2124 20 |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2125 "\000\000\000\n") |
|
5573
f0f1fd0d8486
Remove ELC files from `binary-file-regexps', many of them are escape-quoted.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5568
diff
changeset
|
2126 (insert (format ";;;###coding system: %s\n" |
|
f0f1fd0d8486
Remove ELC files from `binary-file-regexps', many of them are escape-quoted.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5568
diff
changeset
|
2127 (coding-system-name buffer-file-coding-system))) |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2128 (insert (format |
|
4686
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2129 "\n(or %s\n (error \"Loading this file requires %s\"))\n" |
|
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2130 (let ((print-readably t)) |
|
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2131 (prin1-to-string (if (> (length |
|
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2132 byte-compile-checks-on-load) |
|
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2133 1) |
|
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2134 (cons 'and |
|
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2135 (setq byte-compile-checks-on-load |
|
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2136 (reverse |
|
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2137 byte-compile-checks-on-load))) |
|
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2138 (car byte-compile-checks-on-load)))) |
|
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2139 (loop |
|
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2140 for check in byte-compile-checks-on-load |
|
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2141 with seen-first = nil |
|
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2142 with res = "" |
|
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2143 do |
|
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2144 (if seen-first |
|
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2145 (setq res (concat res ", ")) |
|
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2146 (setq seen-first t)) |
|
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2147 ;; Print featurep calls differently: |
|
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2148 (if (and (eq (car check) 'featurep) |
|
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2149 (eq (car (second check)) 'quote) |
|
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2150 (symbolp (second (second check)))) |
|
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2151 (setq res (concat res |
|
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2152 (symbol-name (second (second check))))) |
|
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2153 (setq res (concat res |
|
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2154 (let ((print-readably t)) |
|
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2155 (prin1-to-string check))))) |
|
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
2156 finally return res))) |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2157 (setq comments |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2158 (with-string-as-buffer-contents "" |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2159 (insert "\n;;; compiled by " |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2160 (or (and (boundp 'user-mail-address) user-mail-address) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2161 (concat (user-login-name) "@" (system-name))) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2162 " on " |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2163 (current-time-string) "\n;;; from file " filename "\n") |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2164 (insert ";;; emacs version " emacs-version ".\n") |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2165 (insert ";;; bytecomp version " byte-compile-version "\n;;; " |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2166 (cond |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2167 ((eq byte-optimize 'source) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2168 "source-level optimization only") |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2169 ((eq byte-optimize 'byte) "byte-level optimization only") |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2170 (byte-optimize "optimization is on") |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2171 (t "optimization is off")) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2172 "\n"))) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2173 |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2174 ;; We won't trip this unless the byte-compiler changes, in which case |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2175 ;; it's just a matter of upping the space. |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2176 (assert (natnump (- (1+ byte-compile-checks-and-comments-space) (point))) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2177 t "Not enough space for the feature checks!") |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2178 |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2179 (if (natnump (- (1+ byte-compile-checks-and-comments-space) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2180 (+ (point) (length comments)))) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2181 (insert comments)) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2182 (insert-char ?\ (- (1+ byte-compile-checks-and-comments-space) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2183 (point))))) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2184 |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2185 (defun byte-compile-maybe-reset-coding (byte-compile-inbuffer |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2186 byte-compile-outbuffer) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2187 ;; We also reserve some space for the feature checks: |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2188 (goto-char 1) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2189 (insert-char ?\ byte-compile-checks-and-comments-space) |
| 771 | 2190 (if (or (featurep '(not mule)) ;; Don't scan buffer if we are not muleized |
|
4623
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2191 (and |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2192 (not byte-compile-force-escape-quoted) |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2193 (save-excursion |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2194 (set-buffer byte-compile-inbuffer) |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2195 (goto-char (point-min)) |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2196 ;; Look for any non-Latin-1 literals or Unicode character |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2197 ;; escapes. Any such occurrences in a @#COUNT comment will lead |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2198 ;; to an escape-quoted coding cookie being inserted, but this is |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2199 ;; not true of ordinary comments. |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2200 (let ((non-latin-1-re |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2201 (concat "[^\000-\377]" |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2202 #r"\|\\u[0-9a-fA-F]\{4,4\}\|\\U[0-9a-fA-F]" |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2203 "\\{8,8\\}")) |
|
4623
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2204 (case-fold-search nil)) |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2205 (catch 'need-to-escape-quote |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2206 (while (re-search-forward non-latin-1-re nil t) |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2207 (skip-chars-backward "^;" (point-at-bol)) |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2208 (if (bolp) (throw 'need-to-escape-quote nil)) |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2209 (forward-line 1)) |
|
a9f83990e6bf
Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4539
diff
changeset
|
2210 t))))) |
| 771 | 2211 (setq buffer-file-coding-system 'raw-text-unix) |
| 2212 (setq buffer-file-coding-system 'escape-quoted) | |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2213 (pushnew '(featurep 'mule) byte-compile-checks-on-load) |
| 771 | 2214 (save-excursion |
| 2215 (set-buffer byte-compile-inbuffer) | |
| 2216 (setq byte-compile-dynamic nil | |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
2217 byte-compile-dynamic-docstrings nil)))) |
| 428 | 2218 |
| 2219 (defun byte-compile-output-file-form (form) | |
| 2220 ;; writes the given form to the output buffer, being careful of docstrings | |
| 2221 ;; in defun, defmacro, defvar, defconst and autoload because make-docfile is | |
| 2222 ;; so amazingly stupid. | |
| 2223 ;; defalias calls are output directly by byte-compile-file-form-defmumble; | |
| 2224 ;; it does not pay to first build the defalias in defmumble and then parse | |
| 2225 ;; it here. | |
|
4539
061e030e3270
Fix some bugs in load-history construction, built-in symbol file names.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4529
diff
changeset
|
2226 (if (and (memq (car-safe form) '(defun defmacro defvar defconst autoload |
|
061e030e3270
Fix some bugs in load-history construction, built-in symbol file names.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4529
diff
changeset
|
2227 custom-declare-variable)) |
| 428 | 2228 (stringp (nth 3 form))) |
| 2229 (byte-compile-output-docform nil nil '("\n(" 3 ")") form nil | |
|
4539
061e030e3270
Fix some bugs in load-history construction, built-in symbol file names.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4529
diff
changeset
|
2230 (memq (car form) |
|
061e030e3270
Fix some bugs in load-history construction, built-in symbol file names.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4529
diff
changeset
|
2231 '(autoload custom-declare-variable))) |
|
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5548
diff
changeset
|
2232 (let* ((print-escape-newlines t) |
|
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5548
diff
changeset
|
2233 (print-length nil) |
|
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5548
diff
changeset
|
2234 (print-level nil) |
|
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5548
diff
changeset
|
2235 (print-readably t) ; print #[] for bytecode, 'x for (quote x) |
|
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5548
diff
changeset
|
2236 (print-gensym byte-compile-print-gensym) |
|
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5548
diff
changeset
|
2237 (print-continuous-numbering print-gensym) |
|
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5548
diff
changeset
|
2238 (print-circle t)) |
|
5391
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2239 (when byte-compile-output-preface |
|
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2240 (princ "\n(progn " byte-compile-outbuffer) |
|
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2241 (prin1 byte-compile-output-preface byte-compile-outbuffer)) |
| 428 | 2242 (princ "\n" byte-compile-outbuffer) |
| 2243 (prin1 form byte-compile-outbuffer) | |
|
5391
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2244 (when byte-compile-output-preface (princ ")" byte-compile-outbuffer)) |
| 428 | 2245 nil))) |
| 2246 | |
| 2247 (defun byte-compile-output-docform (preface name info form specindex quoted) | |
| 2248 "Print a form with a doc string. INFO is (prefix doc-index postfix). | |
| 2249 If PREFACE and NAME are non-nil, print them too, | |
| 2250 before INFO and the FORM but after the doc string itself. | |
| 2251 If SPECINDEX is non-nil, it is the index in FORM | |
| 2252 of the function bytecode string. In that case, | |
| 2253 we output that argument and the following argument (the constants vector) | |
| 2254 together, for lazy loading. | |
| 2255 QUOTED says that we have to put a quote before the | |
| 2256 list that represents a doc string reference. | |
| 2257 `autoload' needs that." | |
| 2258 ;; We need to examine byte-compile-dynamic-docstrings | |
| 2259 ;; in the input buffer (now current), not in the output buffer. | |
| 2260 (let ((dynamic-docstrings byte-compile-dynamic-docstrings)) | |
| 2261 (set-buffer | |
| 2262 (prog1 (current-buffer) | |
| 2263 (set-buffer byte-compile-outbuffer) | |
| 2264 (let (position) | |
| 2265 | |
| 2266 ;; Insert the doc string, and make it a comment with #@LENGTH. | |
| 2267 (and (>= (nth 1 info) 0) | |
| 2268 dynamic-docstrings | |
| 2269 (progn | |
| 2270 ;; Make the doc string start at beginning of line | |
| 2271 ;; for make-docfile's sake. | |
| 2272 (insert "\n") | |
| 2273 (setq position | |
| 2274 (byte-compile-output-as-comment | |
| 2275 (nth (nth 1 info) form) nil)) | |
| 2276 ;; If the doc string starts with * (a user variable), | |
| 2277 ;; negate POSITION. | |
| 2278 (if (and (stringp (nth (nth 1 info) form)) | |
| 2279 (> (length (nth (nth 1 info) form)) 0) | |
| 2280 (char= (aref (nth (nth 1 info) form) 0) ?*)) | |
| 2281 (setq position (- position))))) | |
|
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5548
diff
changeset
|
2282 (byte-compile-flush-pending) |
|
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5548
diff
changeset
|
2283 (let* ((print-escape-newlines t) |
|
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5548
diff
changeset
|
2284 (print-readably t) ; print #[] for bytecode, 'x for (quote x) |
|
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5548
diff
changeset
|
2285 (print-gensym byte-compile-print-gensym) |
|
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5548
diff
changeset
|
2286 (print-continuous-numbering print-gensym) |
|
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5548
diff
changeset
|
2287 (print-circle t) |
|
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5548
diff
changeset
|
2288 (index 0)) |
|
5391
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2289 (when byte-compile-output-preface |
|
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2290 (princ "\n(progn " byte-compile-outbuffer) |
|
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2291 (prin1 byte-compile-output-preface byte-compile-outbuffer)) |
|
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2292 (if preface |
|
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2293 (progn |
|
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2294 (insert preface) |
|
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2295 (prin1 name byte-compile-outbuffer))) |
|
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2296 (insert (car info)) |
| 428 | 2297 (prin1 (car form) byte-compile-outbuffer) |
| 2298 (while (setq form (cdr form)) | |
| 2299 (setq index (1+ index)) | |
| 2300 (insert " ") | |
| 2301 (cond ((and (numberp specindex) (= index specindex)) | |
| 2302 (let ((position | |
| 2303 (byte-compile-output-as-comment | |
| 2304 (cons (car form) (nth 1 form)) | |
| 2305 t))) | |
| 2306 (princ (format "(#$ . %d) nil" position) | |
| 2307 byte-compile-outbuffer) | |
| 2308 (setq form (cdr form)) | |
| 2309 (setq index (1+ index)))) | |
| 2310 ((= index (nth 1 info)) | |
| 2311 (if position | |
| 2312 (princ (format (if quoted "'(#$ . %d)" "(#$ . %d)") | |
| 2313 position) | |
| 2314 byte-compile-outbuffer) | |
| 2315 (let ((print-escape-newlines nil)) | |
| 2316 (goto-char (prog1 (1+ (point)) | |
| 2317 (prin1 (car form) | |
| 2318 byte-compile-outbuffer))) | |
| 2319 (insert "\\\n") | |
| 2320 (goto-char (point-max))))) | |
| 2321 (t | |
| 2322 (prin1 (car form) byte-compile-outbuffer))))) | |
|
5391
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2323 (insert (nth 2 info)) |
|
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2324 (when byte-compile-output-preface |
|
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2325 (princ ")" byte-compile-outbuffer)))))) |
| 428 | 2326 nil) |
| 2327 | |
| 2328 (defun byte-compile-keep-pending (form &optional handler) | |
| 2329 (if (memq byte-optimize '(t source)) | |
| 2330 (setq form (byte-optimize-form form t))) | |
| 2331 (if handler | |
| 2332 (let ((for-effect t)) | |
| 2333 ;; To avoid consing up monstrously large forms at load time, we split | |
| 2334 ;; the output regularly. | |
| 2335 (and (memq (car-safe form) '(fset defalias define-function)) | |
| 2336 (nthcdr 300 byte-compile-output) | |
| 2337 (byte-compile-flush-pending)) | |
| 2338 (funcall handler form) | |
| 2339 (when for-effect | |
| 2340 (byte-compile-discard))) | |
| 2341 (byte-compile-form form t)) | |
| 2342 nil) | |
| 2343 | |
| 2344 (defun byte-compile-flush-pending () | |
| 2345 (if byte-compile-output | |
| 2346 (let ((form (byte-compile-out-toplevel t 'file))) | |
| 2347 (cond ((eq (car-safe form) 'progn) | |
|
4783
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4775
diff
changeset
|
2348 (mapc 'byte-compile-output-file-form (cdr form))) |
| 428 | 2349 (form |
| 2350 (byte-compile-output-file-form form))) | |
| 2351 (setq byte-compile-constants nil | |
| 2352 byte-compile-variables nil | |
| 2353 byte-compile-depth 0 | |
| 2354 byte-compile-maxdepth 0 | |
| 2355 byte-compile-output nil)))) | |
| 2356 | |
| 2357 (defun byte-compile-file-form (form) | |
| 2358 (let ((byte-compile-current-form nil) ; close over this for warnings. | |
|
5391
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2359 (byte-compile-output-preface nil) |
| 428 | 2360 handler) |
| 2361 (cond | |
| 2362 ((not (consp form)) | |
| 2363 (byte-compile-keep-pending form)) | |
| 2364 ((and (symbolp (car form)) | |
| 2365 (setq handler (get (car form) 'byte-hunk-handler))) | |
| 2366 (cond ((setq form (funcall handler form)) | |
| 2367 (byte-compile-flush-pending) | |
| 2368 (byte-compile-output-file-form form)))) | |
| 2369 ((eq form (setq form (macroexpand form byte-compile-macro-environment))) | |
| 2370 (byte-compile-keep-pending form)) | |
| 2371 (t | |
| 2372 (byte-compile-file-form form))))) | |
| 2373 | |
| 2374 ;; Functions and variables with doc strings must be output separately, | |
| 2375 ;; so make-docfile can recognize them. Most other things can be output | |
| 2376 ;; as byte-code. | |
| 2377 | |
| 2378 (put 'defsubst 'byte-hunk-handler 'byte-compile-file-form-defsubst) | |
| 2379 (defun byte-compile-file-form-defsubst (form) | |
| 2380 (cond ((assq (nth 1 form) byte-compile-unresolved-functions) | |
| 2381 (setq byte-compile-current-form (nth 1 form)) | |
| 2382 (byte-compile-warn "defsubst %s was used before it was defined" | |
| 2383 (nth 1 form)))) | |
| 2384 (byte-compile-file-form | |
| 2385 (macroexpand form byte-compile-macro-environment)) | |
| 2386 ;; Return nil so the form is not output twice. | |
| 2387 nil) | |
| 2388 | |
| 2389 (put 'autoload 'byte-hunk-handler 'byte-compile-file-form-autoload) | |
| 2390 (defun byte-compile-file-form-autoload (form) | |
| 2391 ;; | |
| 2392 ;; If this is an autoload of a macro, and all arguments are constants (that | |
| 2393 ;; is, there is no hairy computation going on here) then evaluate the form | |
| 2394 ;; at compile-time. This is so that we can make use of macros which we | |
| 2395 ;; have autoloaded from the file being compiled. Normal function autoloads | |
| 2396 ;; are not automatically evaluated at compile time, because there's not | |
| 2397 ;; much point to it (so why bother cluttering up the compile-time namespace.) | |
| 2398 ;; | |
| 2399 ;; If this is an autoload of a function, then record its definition in the | |
| 2400 ;; byte-compile-autoload-environment to suppress any `not known to be | |
| 2401 ;; defined' warnings at the end of this file (this only matters for | |
| 2402 ;; functions which are autoloaded and compiled in the same file, if the | |
| 2403 ;; autoload already exists in the compilation environment, we wouldn't have | |
| 2404 ;; warned anyway.) | |
| 2405 ;; | |
| 2406 (let* ((name (if (byte-compile-constp (nth 1 form)) | |
| 2407 (eval (nth 1 form)))) | |
| 2408 ;; In v19, the 5th arg to autoload can be t, nil, 'macro, or 'keymap. | |
| 2409 (macrop (and (byte-compile-constp (nth 5 form)) | |
| 2410 (memq (eval (nth 5 form)) '(t macro)))) | |
| 2411 ;; (functionp (and (byte-compile-constp (nth 5 form)) | |
| 2412 ;; (eq 'nil (eval (nth 5 form))))) | |
| 2413 ) | |
| 2414 (if (and macrop | |
| 2415 (let ((form form)) | |
| 2416 ;; all forms are constant | |
| 2417 (while (if (setq form (cdr form)) | |
| 2418 (byte-compile-constp (car form)))) | |
| 2419 (null form))) | |
| 440 | 2420 ;; eval the macro autoload into the compilation environment |
| 428 | 2421 (eval form)) |
| 2422 | |
| 2423 (if name | |
| 2424 (let ((old (assq name byte-compile-autoload-environment))) | |
| 2425 (cond (old | |
| 2426 (if (memq 'redefine byte-compile-warnings) | |
| 2427 (byte-compile-warn "multiple autoloads for %s" name)) | |
| 2428 (setcdr old form)) | |
| 2429 (t | |
| 2430 ;; We only use the names in the autoload environment, but | |
| 2431 ;; it might be useful to have the bodies some day. | |
| 2432 (setq byte-compile-autoload-environment | |
| 2433 (cons (cons name form) | |
| 2434 byte-compile-autoload-environment))))))) | |
| 2435 ;; | |
| 2436 ;; Now output the form. | |
| 2437 (if (stringp (nth 3 form)) | |
| 2438 form | |
| 2439 ;; No doc string, so we can compile this as a normal form. | |
| 2440 (byte-compile-keep-pending form 'byte-compile-normal-call))) | |
| 2441 | |
| 442 | 2442 (put 'defvar 'byte-hunk-handler 'byte-compile-file-form-defvar-or-defconst) |
| 2443 (put 'defconst 'byte-hunk-handler 'byte-compile-file-form-defvar-or-defconst) | |
| 2444 (defun byte-compile-file-form-defvar-or-defconst (form) | |
| 2445 ;; (defvar|defconst VAR [VALUE [DOCSTRING]]) | |
| 428 | 2446 (if (> (length form) 4) |
| 442 | 2447 (byte-compile-warn |
| 2448 "%s %s called with %d arguments, but accepts only %s" | |
| 2449 (car form) (nth 1 form) (length (cdr form)) 3)) | |
| 428 | 2450 (if (and (> (length form) 3) (not (stringp (nth 3 form)))) |
| 2451 (byte-compile-warn "Third arg to %s %s is not a string: %s" | |
| 2452 (car form) (nth 1 form) (nth 3 form))) | |
| 2453 (if (null (nth 3 form)) | |
| 2454 ;; Since there is no doc string, we can compile this as a normal form, | |
| 2455 ;; and not do a file-boundary. | |
| 2456 (byte-compile-keep-pending form) | |
| 2457 (if (memq 'free-vars byte-compile-warnings) | |
| 2458 (setq byte-compile-bound-variables | |
| 2459 (cons (cons (nth 1 form) byte-compile-global-bit) | |
| 2460 byte-compile-bound-variables))) | |
| 2461 (cond ((consp (nth 2 form)) | |
| 2462 (setq form (copy-sequence form)) | |
| 2463 (setcar (cdr (cdr form)) | |
| 2464 (byte-compile-top-level (nth 2 form) nil 'file)))) | |
| 2465 | |
| 2466 ;; The following turns out not to be necessary, since we emit a call to | |
| 2467 ;; defvar, which can hack Vfile_domain by itself! | |
| 2468 ;; | |
| 2469 ;; If a file domain has been set, emit (put 'VAR 'variable-domain ...) | |
| 2470 ;; after this defvar. | |
| 2471 ; (if byte-compile-file-domain | |
| 2472 ; (progn | |
| 2473 ; ;; Actually, this will emit the (put ...) before the (defvar ...) | |
| 2474 ; ;; but I don't think that can matter in this case. | |
| 2475 ; (byte-compile-keep-pending | |
| 2476 ; (list 'put (list 'quote (nth 1 form)) ''variable-domain | |
| 2477 ; (list 'quote byte-compile-file-domain))))) | |
| 2478 form)) | |
| 2479 | |
| 2480 (put 'require 'byte-hunk-handler 'byte-compile-file-form-eval-boundary) | |
| 2481 (defun byte-compile-file-form-eval-boundary (form) | |
| 2482 (eval form) | |
| 2483 (byte-compile-keep-pending form 'byte-compile-normal-call)) | |
| 2484 | |
|
5651
ae2fdb1fd9e0
Improve for-effect handling in a few places, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5650
diff
changeset
|
2485 (put 'progn 'byte-hunk-handler 'byte-compile-file-form-progn) |
|
ae2fdb1fd9e0
Improve for-effect handling in a few places, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5650
diff
changeset
|
2486 (put 'prog1 'byte-hunk-handler 'byte-compile-file-form-progn) |
|
ae2fdb1fd9e0
Improve for-effect handling in a few places, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5650
diff
changeset
|
2487 (put 'prog2 'byte-hunk-handler 'byte-compile-file-form-progn) |
|
ae2fdb1fd9e0
Improve for-effect handling in a few places, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5650
diff
changeset
|
2488 (defun byte-compile-file-form-progn (form) |
|
ae2fdb1fd9e0
Improve for-effect handling in a few places, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5650
diff
changeset
|
2489 (mapc 'byte-compile-file-form (cdr form)) |
|
ae2fdb1fd9e0
Improve for-effect handling in a few places, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5650
diff
changeset
|
2490 ;; Return nil so the forms are not output twice. |
|
ae2fdb1fd9e0
Improve for-effect handling in a few places, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5650
diff
changeset
|
2491 nil) |
| 428 | 2492 |
| 2493 ;; This handler is not necessary, but it makes the output from dont-compile | |
| 2494 ;; and similar macros cleaner. | |
| 2495 (put 'eval 'byte-hunk-handler 'byte-compile-file-form-eval) | |
| 2496 (defun byte-compile-file-form-eval (form) | |
| 2497 (if (eq (car-safe (nth 1 form)) 'quote) | |
| 2498 (nth 1 (nth 1 form)) | |
| 2499 (byte-compile-keep-pending form))) | |
| 2500 | |
| 2501 (put 'defun 'byte-hunk-handler 'byte-compile-file-form-defun) | |
| 2502 (defun byte-compile-file-form-defun (form) | |
| 2503 (byte-compile-file-form-defmumble form nil)) | |
| 2504 | |
| 2505 (put 'defmacro 'byte-hunk-handler 'byte-compile-file-form-defmacro) | |
| 2506 (defun byte-compile-file-form-defmacro (form) | |
| 2507 (byte-compile-file-form-defmumble form t)) | |
| 2508 | |
| 2509 (defun byte-compile-file-form-defmumble (form macrop) | |
| 2510 (let* ((name (car (cdr form))) | |
| 2511 (this-kind (if macrop 'byte-compile-macro-environment | |
| 2512 'byte-compile-function-environment)) | |
| 2513 (that-kind (if macrop 'byte-compile-function-environment | |
| 2514 'byte-compile-macro-environment)) | |
| 2515 (this-one (assq name (symbol-value this-kind))) | |
| 2516 (that-one (assq name (symbol-value that-kind))) | |
| 2517 (byte-compile-free-references nil) | |
| 2518 (byte-compile-free-assignments nil)) | |
| 2519 | |
| 2520 ;; When a function or macro is defined, add it to the call tree so that | |
| 2521 ;; we can tell when functions are not used. | |
| 2522 (if byte-compile-generate-call-tree | |
| 2523 (or (assq name byte-compile-call-tree) | |
| 2524 (setq byte-compile-call-tree | |
| 2525 (cons (list name nil nil) byte-compile-call-tree)))) | |
| 2526 | |
| 2527 (setq byte-compile-current-form name) ; for warnings | |
| 2528 (when (memq 'redefine byte-compile-warnings) | |
| 2529 (byte-compile-arglist-warn form macrop)) | |
| 2530 (defvar filename) ; #### filename used free | |
| 2531 (when byte-compile-verbose | |
| 2532 (message "Compiling %s... (%s)" | |
| 2533 (if filename (file-name-nondirectory filename) "") | |
| 2534 (nth 1 form))) | |
| 2535 (cond (that-one | |
| 2536 (when (and (memq 'redefine byte-compile-warnings) | |
| 2537 ;; hack hack: don't warn when compiling the stubs in | |
| 2538 ;; bytecomp-runtime... | |
| 2539 (not (assq (nth 1 form) | |
| 2540 byte-compile-initial-macro-environment))) | |
| 2541 (byte-compile-warn | |
| 2542 "%s defined multiple times, as both function and macro" | |
| 2543 (nth 1 form))) | |
| 2544 (setcdr that-one nil)) | |
| 2545 (this-one | |
| 2546 (when (and (memq 'redefine byte-compile-warnings) | |
| 2547 ;; hack: don't warn when compiling the magic internal | |
| 2548 ;; byte-compiler macros in bytecomp-runtime.el... | |
| 2549 (not (assq (nth 1 form) | |
| 2550 byte-compile-initial-macro-environment))) | |
| 2551 (byte-compile-warn "%s %s defined multiple times in this file" | |
| 2552 (if macrop "macro" "function") | |
| 2553 (nth 1 form)))) | |
| 2554 ((and (fboundp name) | |
| 2555 (or (subrp (symbol-function name)) | |
| 2556 (eq (car-safe (symbol-function name)) | |
| 2557 (if macrop 'lambda 'macro)))) | |
| 2558 (if (memq 'redefine byte-compile-warnings) | |
| 2559 (byte-compile-warn "%s %s being redefined as a %s" | |
| 2560 (if (subrp (symbol-function name)) | |
| 2561 "subr" | |
| 2562 (if macrop "function" "macro")) | |
| 2563 (nth 1 form) | |
| 2564 (if macrop "macro" "function"))) | |
| 2565 ;; shadow existing definition | |
| 2566 (set this-kind | |
| 2567 (cons (cons name nil) (symbol-value this-kind))))) | |
| 2568 (let ((body (nthcdr 3 form))) | |
| 2569 (if (and (stringp (car body)) | |
| 2570 (symbolp (car-safe (cdr-safe body))) | |
| 2571 (car-safe (cdr-safe body)) | |
| 2572 (stringp (car-safe (cdr-safe (cdr-safe body))))) | |
| 2573 (byte-compile-warn "Probable `\"' without `\\' in doc string of %s" | |
| 2574 (nth 1 form)))) | |
|
5506
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2575 |
|
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2576 ;; Generate code for declarations in macro definitions. |
|
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2577 ;; Remove declarations from the body of the macro definition. |
|
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2578 (when macrop |
|
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2579 (let ((byte-compile-defmacro-body (nthcdr 3 form))) |
|
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2580 (if (stringp (car byte-compile-defmacro-body)) |
|
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2581 (setq byte-compile-defmacro-body (nthcdr 4 form))) |
|
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2582 (when (and (consp byte-compile-defmacro-body) |
|
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2583 (eq 'declare (car-safe (car byte-compile-defmacro-body)))) |
|
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2584 (if (eq 'declare (car-safe (car-safe |
|
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2585 (cdr byte-compile-defmacro-body)))) |
|
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2586 (byte-compile-warn "Multiple macro-specific `declare' calls \ |
|
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2587 not supported by XEmacs.")) |
|
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2588 (setq byte-compile-output-preface |
|
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2589 (byte-compile-top-level |
|
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2590 `(progn (and macro-declaration-function |
|
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2591 (funcall macro-declaration-function |
|
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2592 ',name |
|
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2593 ',(car byte-compile-defmacro-body))) |
|
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5503
diff
changeset
|
2594 ,byte-compile-output-preface) t 'file))))) |
| 428 | 2595 (let* ((new-one (byte-compile-lambda (cons 'lambda (nthcdr 2 form)))) |
|
5106
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2596 (code (byte-compile-byte-code-maker new-one)) |
|
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2597 (docform-info |
|
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2598 (cond ((atom code) ; compiled-function-p |
|
5391
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2599 (if macrop '(" '(macro . #[" 4 "]))") '(" #[" 4 "])"))) |
|
5106
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2600 ((eq (car code) 'quote) |
|
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2601 (setq code new-one) |
|
5391
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2602 (if macrop '(" '(macro " 2 "))") '(" '(" 2 "))"))) |
|
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2603 ((if macrop '(" (cons 'macro (" 5 ")))") '(" (" 5 "))")))))) |
| 428 | 2604 (if this-one |
| 2605 (setcdr this-one new-one) | |
| 2606 (set this-kind | |
| 2607 (cons (cons name new-one) (symbol-value this-kind)))) | |
| 2608 (if (and (stringp (nth 3 form)) | |
| 2609 (eq 'quote (car-safe code)) | |
| 2610 (eq 'lambda (car-safe (nth 1 code)))) | |
| 2611 (cons (car form) | |
|
5106
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2612 (cons name (cdr (nth 1 code)))) |
| 428 | 2613 (byte-compile-flush-pending) |
| 2614 (if (not (stringp (nth 3 form))) | |
|
5106
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2615 ;; No doc string. Provide -1 as the "doc string index" so that |
|
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2616 ;; no element will be treated as a doc string by |
|
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2617 ;; byte-compile-output-doc-form. |
|
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2618 (setq docform-info (list (first docform-info) -1 |
|
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2619 (third docform-info)))) |
|
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2620 (byte-compile-output-docform |
|
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2621 "\n(defalias '" |
|
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2622 name |
|
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2623 docform-info |
|
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2624 ;; The result of byte-compile-byte-code-maker is either a |
|
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2625 ;; compiled-function object, or a list of some kind. If it's not a |
|
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2626 ;; cons, we must coerce it into a list of the elements to be |
|
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2627 ;; printed to the file. |
|
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2628 (if (consp code) |
|
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2629 code |
|
5391
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2630 (list* (compiled-function-arglist code) |
|
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2631 (compiled-function-instructions code) |
|
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2632 (compiled-function-constants code) |
|
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2633 (compiled-function-stack-depth code) |
|
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
2634 (compiled-function-doc-string code) |
|
5106
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2635 (if (commandp code) |
|
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2636 (list (nth 1 (compiled-function-interactive code)))))) |
|
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2637 (and (atom code) byte-compile-dynamic |
|
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2638 1) |
| 428 | 2639 nil)) |
|
5106
8c3671b62dad
Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
2640 nil))) |
| 428 | 2641 |
| 2642 ;; Print Lisp object EXP in the output file, inside a comment, | |
| 2643 ;; and return the file position it will have. | |
| 2644 ;; If QUOTED is non-nil, print with quoting; otherwise, print without quoting. | |
| 2645 (defun byte-compile-output-as-comment (exp quoted) | |
| 2646 (let ((position (point))) | |
| 2647 (set-buffer | |
| 2648 (prog1 (current-buffer) | |
| 2649 (set-buffer byte-compile-outbuffer) | |
| 2650 | |
| 2651 ;; Insert EXP, and make it a comment with #@LENGTH. | |
| 2652 (insert " ") | |
| 2653 (if quoted | |
| 2654 (prin1 exp byte-compile-outbuffer) | |
| 2655 (princ exp byte-compile-outbuffer)) | |
| 2656 (goto-char position) | |
| 2657 ;; Quote certain special characters as needed. | |
| 2658 ;; get_doc_string in doc.c does the unquoting. | |
| 2659 (while (search-forward "\^A" nil t) | |
| 2660 (replace-match "\^A\^A" t t)) | |
| 2661 (goto-char position) | |
| 2662 (while (search-forward "\000" nil t) | |
| 2663 (replace-match "\^A0" t t)) | |
| 2664 (goto-char position) | |
| 2665 (while (search-forward "\037" nil t) | |
| 2666 (replace-match "\^A_" t t)) | |
| 2667 (goto-char (point-max)) | |
| 2668 (insert "\037") | |
| 2669 (goto-char position) | |
| 2670 (insert "#@" (format "%d" (- (point-max) position))) | |
| 2671 | |
| 2672 ;; Save the file position of the object. | |
| 2673 ;; Note we should add 1 to skip the space | |
| 2674 ;; that we inserted before the actual doc string, | |
| 2675 ;; and subtract 1 to convert from an 1-origin Emacs position | |
| 2676 ;; to a file position; they cancel. | |
| 2677 (setq position (point)) | |
| 2678 (goto-char (point-max)))) | |
| 2679 position)) | |
| 2680 | |
| 2681 | |
| 2682 | |
| 2683 ;; The `domain' declaration. This is legal only at top-level in a file, and | |
| 2684 ;; should generally be the first form in the file. It is not legal inside | |
| 2685 ;; function bodies. | |
| 2686 | |
| 2687 (put 'domain 'byte-hunk-handler 'byte-compile-file-form-domain) | |
| 2688 (defun byte-compile-file-form-domain (form) | |
| 2689 (if (not (null (cdr (cdr form)))) | |
| 2690 (byte-compile-warn "domain used with too many arguments: %s" form)) | |
| 2691 (let ((domain (nth 1 form))) | |
| 2692 (or (null domain) | |
| 2693 (stringp domain) | |
| 2694 (progn | |
| 2695 (byte-compile-warn | |
| 2696 "argument to `domain' declaration must be a literal string: %s" | |
| 2697 form) | |
| 2698 (setq domain nil))) | |
| 2699 (setq byte-compile-file-domain domain)) | |
| 2700 (byte-compile-keep-pending form 'byte-compile-normal-call)) | |
| 2701 | |
| 2702 (defun byte-compile-domain (form) | |
| 2703 (byte-compile-warn "The `domain' declaration is legal only at top-level: %s" | |
| 2704 (let ((print-escape-newlines t) | |
| 2705 (print-level 4) | |
| 2706 (print-length 4)) | |
| 2707 (prin1-to-string form))) | |
| 2708 (byte-compile-normal-call | |
| 2709 (list 'signal ''error | |
| 2710 (list 'quote (list "`domain' used inside a function" form))))) | |
| 2711 | |
| 2712 ;; This is part of bytecomp.el in 19.35: | |
| 2713 (put 'custom-declare-variable 'byte-hunk-handler | |
| 2714 'byte-compile-file-form-custom-declare-variable) | |
| 2715 (defun byte-compile-file-form-custom-declare-variable (form) | |
| 4289 | 2716 ;; XEmacs change; our implementation byte compiles and gives warnings |
| 2717 ;; about the default value code, which GNU's doesn't. | |
| 2718 (let* ((quoted-default (car-safe (cdr-safe (cdr-safe form)))) | |
| 2719 (to-examine (car-safe (cdr-safe quoted-default)))) | |
| 2720 (if (memq 'free-vars byte-compile-warnings) | |
| 2721 (setq byte-compile-bound-variables | |
| 2722 (cons (cons (nth 1 (nth 1 form)) | |
| 2723 byte-compile-global-bit) | |
| 2724 byte-compile-bound-variables))) | |
| 2725 ;; Byte compile anything that smells like a lambda. I initially | |
| 2726 ;; considered limiting it to the :initialize, :set and :get args, but | |
| 2727 ;; that's not amazingly forward-compatible, and anyone expecting other | |
| 2728 ;; things to be stored as data, not code, is unrealistic. | |
| 2729 (loop | |
| 2730 for entry in-ref (nthcdr 4 form) | |
| 2731 do (cond ((and (eq 'function (car-safe entry)) | |
| 2732 (consp (car-safe (cdr-safe entry)))) | |
| 2733 (setf entry (copy-sequence entry)) | |
| 2734 (setcar (cdr entry) (byte-compile-lambda (car (cdr entry))))) | |
| 2735 ((and (eq 'lambda (car-safe entry))) | |
| 2736 (setf entry (byte-compile-lambda entry))))) | |
| 2737 ;; Byte compile the default value, as we do for defvar. | |
| 2738 (when (consp (cdr-safe to-examine)) | |
| 2739 (setq form (copy-sequence form)) | |
| 2740 (setcdr (third form) | |
| 2741 (list (byte-compile-top-level to-examine nil 'file))) | |
| 2742 ;; And save a value to be examined in the custom UI, if that differs | |
| 2743 ;; from the init value. | |
| 2744 (unless (equal to-examine (car-safe (cdr (third form)))) | |
| 4304 | 2745 (setcdr (third form) |
| 2746 (list (byte-compile-top-level | |
| 2747 ;; This is ugly. custom-declare-variable errors if | |
| 2748 ;; it's passed a keyword it doesn't know about, and | |
| 2749 ;; so to make this code run on 21.4, we add code to | |
| 2750 ;; modify the standard-value property to the | |
| 2751 ;; byte-compiled value for DEFAULT. | |
| 2752 `(prog2 (put ,(second form) 'standard-value | |
| 2753 '(,to-examine)) | |
| 2754 ,to-examine) | |
| 2755 nil 'file))))) | |
| 4289 | 2756 form)) |
| 428 | 2757 |
| 2758 ;;;###autoload | |
| 2759 (defun byte-compile (form) | |
| 2760 "If FORM is a symbol, byte-compile its function definition. | |
| 2761 If FORM is a lambda or a macro, byte-compile it as a function." | |
| 2762 (displaying-byte-compile-warnings | |
| 2763 (byte-compile-close-variables | |
| 2764 (let* ((fun (if (symbolp form) | |
| 2765 (and (fboundp form) (symbol-function form)) | |
| 2766 form)) | |
| 2767 (macro (eq (car-safe fun) 'macro))) | |
| 2768 (if macro | |
| 2769 (setq fun (cdr fun))) | |
| 2770 (cond ((eq (car-safe fun) 'lambda) | |
| 2771 (setq fun (if macro | |
| 2772 (cons 'macro (byte-compile-lambda fun)) | |
| 2773 (byte-compile-lambda fun))) | |
| 2774 (if (symbolp form) | |
| 2775 (defalias form fun) | |
| 2776 fun))))))) | |
| 2777 | |
| 2778 ;;;###autoload | |
| 2779 (defun byte-compile-sexp (sexp &optional msg) | |
| 2780 "Compile and return SEXP." | |
| 2781 (displaying-byte-compile-warnings | |
| 2782 (byte-compile-close-variables | |
| 2783 (prog1 | |
| 2784 (byte-compile-top-level sexp) | |
| 2785 (byte-compile-warn-about-unresolved-functions msg))))) | |
| 2786 | |
| 2787 ;; Given a function made by byte-compile-lambda, make a form which produces it. | |
| 2788 (defun byte-compile-byte-code-maker (fun) | |
| 2789 (cond | |
| 2790 ;; ## atom is faster than compiled-func-p. | |
| 2791 ((atom fun) ; compiled-function-p | |
| 2792 fun) | |
| 2793 ;; b-c-lambda didn't produce a compiled-function, so it must be a trivial | |
| 2794 ;; function. | |
| 2795 ((let (tmp) | |
| 2796 (if (and (setq tmp (assq 'byte-code (cdr-safe (cdr fun)))) | |
| 2797 (null (cdr (memq tmp fun)))) | |
| 2798 ;; Generate a make-byte-code call. | |
| 2799 (let* ((interactive (assq 'interactive (cdr (cdr fun))))) | |
| 2800 (nconc (list 'make-byte-code | |
| 2801 (list 'quote (nth 1 fun)) ;arglist | |
| 2802 (nth 1 tmp) ;instructions | |
| 2803 (nth 2 tmp) ;constants | |
| 2804 (nth 3 tmp)) ;stack-depth | |
| 2805 (cond ((stringp (nth 2 fun)) | |
| 2806 (list (nth 2 fun))) ;docstring | |
| 2807 (interactive | |
| 2808 (list nil))) | |
| 2809 (cond (interactive | |
| 2810 (list (if (or (null (nth 1 interactive)) | |
| 2811 (stringp (nth 1 interactive))) | |
| 2812 (nth 1 interactive) | |
| 2813 ;; Interactive spec is a list or a variable | |
| 2814 ;; (if it is correct). | |
| 2815 (list 'quote (nth 1 interactive)))))))) | |
| 2816 ;; a non-compiled function (probably trivial) | |
| 2817 (list 'quote fun)))))) | |
| 2818 | |
| 2819 ;; Byte-compile a lambda-expression and return a valid function. | |
| 2820 ;; The value is usually a compiled function but may be the original | |
| 2821 ;; lambda-expression. | |
|
5593
4218b56833b3
Give the label name when warning or erroring, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5579
diff
changeset
|
2822 (defun byte-compile-lambda (fun &optional name) |
| 428 | 2823 (or (eq 'lambda (car-safe fun)) |
| 2824 (error "not a lambda -- %s" (prin1-to-string fun))) | |
|
5593
4218b56833b3
Give the label name when warning or erroring, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5579
diff
changeset
|
2825 (let* ((byte-compile-current-form (or name byte-compile-current-form)) |
|
4218b56833b3
Give the label name when warning or erroring, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5579
diff
changeset
|
2826 (arglist (nth 1 fun)) |
| 428 | 2827 (byte-compile-bound-variables |
| 2828 (let ((new-bindings | |
| 2829 (mapcar #'(lambda (x) (cons x byte-compile-arglist-bit)) | |
| 2830 (and (memq 'free-vars byte-compile-warnings) | |
|
5652
cc6f0266bc36
Avoid #'delq in core Lisp, for the sake of style, a very slightly smaller binary
Aidan Kehoe <kehoea@parhasard.net>
parents:
5651
diff
changeset
|
2831 (remove* '&rest (remove* '&optional arglist)))))) |
| 428 | 2832 (nconc new-bindings |
| 2833 (cons 'new-scope byte-compile-bound-variables)))) | |
| 2834 (body (cdr (cdr fun))) | |
| 2835 (doc (if (stringp (car body)) | |
| 2836 (prog1 (car body) | |
| 1548 | 2837 ;; Discard the doc string |
| 2838 ;; only if it is not the only element of the body. | |
| 2839 (if (cdr body) | |
| 2840 (setq body (cdr body)))))) | |
|
4639
7757334005ae
bytecomp.el: always check code in (interactive SEXP) for sanity
Aidan Kehoe <kehoea@parhasard.net>
parents:
4623
diff
changeset
|
2841 (int (assq 'interactive body)) compiled-int) |
| 428 | 2842 (dolist (arg arglist) |
| 2843 (cond ((not (symbolp arg)) | |
| 2844 (byte-compile-warn "non-symbol in arglist: %S" arg)) | |
| 2845 ((byte-compile-constant-symbol-p arg) | |
| 2846 (byte-compile-warn "constant symbol in arglist: %s" arg)) | |
| 2847 ((and (char= ?\& (aref (symbol-name arg) 0)) | |
| 2848 (not (eq arg '&optional)) | |
| 2849 (not (eq arg '&rest))) | |
| 2850 (byte-compile-warn "unrecognized `&' keyword in arglist: %s" | |
| 2851 arg)))) | |
| 2852 (cond (int | |
| 2853 ;; Skip (interactive) if it is in front (the most usual location). | |
| 2854 (if (eq int (car body)) | |
| 2855 (setq body (cdr body))) | |
| 2856 (cond ((consp (cdr int)) | |
| 2857 (if (cdr (cdr int)) | |
| 2858 (byte-compile-warn "malformed interactive spec: %s" | |
| 2859 (prin1-to-string int))) | |
|
4639
7757334005ae
bytecomp.el: always check code in (interactive SEXP) for sanity
Aidan Kehoe <kehoea@parhasard.net>
parents:
4623
diff
changeset
|
2860 ;; If the interactive spec is a call to `list', don't |
|
7757334005ae
bytecomp.el: always check code in (interactive SEXP) for sanity
Aidan Kehoe <kehoea@parhasard.net>
parents:
4623
diff
changeset
|
2861 ;; store the compiled form, because `call-interactively' |
|
7757334005ae
bytecomp.el: always check code in (interactive SEXP) for sanity
Aidan Kehoe <kehoea@parhasard.net>
parents:
4623
diff
changeset
|
2862 ;; looks at the args of `list' and treats certain |
|
7757334005ae
bytecomp.el: always check code in (interactive SEXP) for sanity
Aidan Kehoe <kehoea@parhasard.net>
parents:
4623
diff
changeset
|
2863 ;; functions specially. Compiling it is nonetheless |
|
7757334005ae
bytecomp.el: always check code in (interactive SEXP) for sanity
Aidan Kehoe <kehoea@parhasard.net>
parents:
4623
diff
changeset
|
2864 ;; useful for warnings. |
| 428 | 2865 (let ((form (nth 1 int))) |
| 2866 (while (or (eq (car-safe form) 'let) | |
| 2867 (eq (car-safe form) 'let*) | |
| 2868 (eq (car-safe form) 'save-excursion)) | |
| 2869 (while (consp (cdr form)) | |
| 2870 (setq form (cdr form))) | |
| 2871 (setq form (car form))) | |
|
4639
7757334005ae
bytecomp.el: always check code in (interactive SEXP) for sanity
Aidan Kehoe <kehoea@parhasard.net>
parents:
4623
diff
changeset
|
2872 (setq compiled-int |
|
7757334005ae
bytecomp.el: always check code in (interactive SEXP) for sanity
Aidan Kehoe <kehoea@parhasard.net>
parents:
4623
diff
changeset
|
2873 (byte-compile-top-level (nth 1 int))) |
| 428 | 2874 (or (eq (car-safe form) 'list) |
|
4639
7757334005ae
bytecomp.el: always check code in (interactive SEXP) for sanity
Aidan Kehoe <kehoea@parhasard.net>
parents:
4623
diff
changeset
|
2875 (setq int (list 'interactive compiled-int))))) |
| 428 | 2876 ((cdr int) |
| 2877 (byte-compile-warn "malformed interactive spec: %s" | |
| 2878 (prin1-to-string int)))))) | |
| 2879 (let ((compiled (byte-compile-top-level (cons 'progn body) nil 'lambda))) | |
| 2880 (if (memq 'unused-vars byte-compile-warnings) | |
| 2881 ;; done compiling in this scope, warn now. | |
| 2882 (byte-compile-warn-about-unused-variables)) | |
| 2883 (if (eq 'byte-code (car-safe compiled)) | |
| 2884 (apply 'make-byte-code | |
| 2885 (append (list arglist) | |
| 2886 ;; byte-string, constants-vector, stack depth | |
| 2887 (cdr compiled) | |
| 2888 ;; optionally, the doc string. | |
| 2889 (if (or doc int) | |
| 2890 (list doc)) | |
| 2891 ;; optionally, the interactive spec. | |
| 2892 (if int | |
| 2893 (list (nth 1 int))))) | |
| 2894 (setq compiled | |
| 2895 (nconc (if int (list int)) | |
| 2896 (cond ((eq (car-safe compiled) 'progn) (cdr compiled)) | |
| 2897 (compiled (list compiled))))) | |
| 2898 (nconc (list 'lambda arglist) | |
| 2899 (if (or doc (stringp (car compiled))) | |
| 2900 (cons doc (cond (compiled) | |
| 2901 (body (list nil)))) | |
| 2902 compiled)))))) | |
| 2903 | |
| 2904 (defun byte-compile-constants-vector () | |
| 2905 ;; Builds the constants-vector from the current variables and constants. | |
| 2906 ;; This modifies the constants from (const . nil) to (const . offset). | |
| 2907 ;; To keep the byte-codes to look up the vector as short as possible: | |
| 2908 ;; First 6 elements are vars, as there are one-byte varref codes for those. | |
| 2909 ;; Next up to byte-constant-limit are constants, still with one-byte codes. | |
| 2910 ;; Next variables again, to get 2-byte codes for variable lookup. | |
| 2911 ;; The rest of the constants and variables need 3-byte byte-codes. | |
| 2912 (let* ((i -1) | |
| 2913 (rest (nreverse byte-compile-variables)) ; nreverse because the first | |
| 2914 (other (nreverse byte-compile-constants)) ; vars often are used most. | |
| 2915 ret tmp | |
| 2916 (limits '(5 ; Use the 1-byte varref codes, | |
| 2917 63 ; 1-constlim ; 1-byte byte-constant codes, | |
| 2918 255 ; 2-byte varref codes, | |
| 2919 65535)) ; 3-byte codes for the rest. | |
| 2920 limit) | |
| 2921 (while (or rest other) | |
| 2922 (setq limit (car limits)) | |
| 2923 (while (and rest (not (eq i limit))) | |
| 2924 (if (setq tmp (assq (car (car rest)) ret)) | |
| 2925 (setcdr (car rest) (cdr tmp)) | |
| 2926 (setcdr (car rest) (setq i (1+ i))) | |
| 2927 (setq ret (cons (car rest) ret))) | |
| 2928 (setq rest (cdr rest))) | |
| 2929 (setq limits (cdr limits) | |
| 2930 rest (prog1 other | |
| 2931 (setq other rest)))) | |
| 2932 (apply 'vector (nreverse (mapcar 'car ret))))) | |
| 2933 | |
| 2934 ;; Given an expression FORM, compile it and return an equivalent byte-code | |
| 2935 ;; expression (a call to the function byte-code). | |
| 2936 (defun byte-compile-top-level (form &optional for-effect output-type) | |
| 2937 ;; OUTPUT-TYPE advises about how form is expected to be used: | |
| 2938 ;; 'eval or nil -> a single form, | |
| 2939 ;; 'progn or t -> a list of forms, | |
| 2940 ;; 'lambda -> body of a lambda, | |
| 2941 ;; 'file -> used at file-level. | |
| 2942 (let ((byte-compile-constants nil) | |
| 2943 (byte-compile-variables nil) | |
| 2944 (byte-compile-tag-number 0) | |
| 2945 (byte-compile-depth 0) | |
| 2946 (byte-compile-maxdepth 0) | |
| 2947 (byte-compile-output nil)) | |
| 2948 (if (memq byte-optimize '(t source)) | |
| 2949 (setq form (byte-optimize-form form for-effect))) | |
| 2950 (while (and (eq (car-safe form) 'progn) (null (cdr (cdr form)))) | |
| 2951 (setq form (nth 1 form))) | |
| 2952 (if (and (eq 'byte-code (car-safe form)) | |
| 2953 (not (memq byte-optimize '(t byte))) | |
| 2954 (stringp (nth 1 form)) | |
| 2955 (vectorp (nth 2 form)) | |
| 2956 (natnump (nth 3 form))) | |
| 2957 form | |
| 2958 (byte-compile-form form for-effect) | |
| 2959 (byte-compile-out-toplevel for-effect output-type)))) | |
| 2960 | |
| 2961 (defun byte-compile-out-toplevel (&optional for-effect output-type) | |
| 2962 (if for-effect | |
| 2963 ;; The stack is empty. Push a value to be returned from (byte-code ..). | |
| 2964 (if (eq (car (car byte-compile-output)) 'byte-discard) | |
| 2965 (setq byte-compile-output (cdr byte-compile-output)) | |
| 2966 (byte-compile-push-constant | |
| 2967 ;; Push any constant - preferably one which already is used, and | |
| 2968 ;; a number or symbol - ie not some big sequence. The return value | |
| 2969 ;; isn't returned, but it would be a shame if some textually large | |
| 2970 ;; constant was not optimized away because we chose to return it. | |
| 2971 (and (not (assq nil byte-compile-constants)) ; Nil is often there. | |
| 2972 (let ((tmp (reverse byte-compile-constants))) | |
| 2973 (while (and tmp (not (or (symbolp (car (car tmp))) | |
| 2974 (numberp (car (car tmp)))))) | |
| 2975 (setq tmp (cdr tmp))) | |
| 2976 (car (car tmp))))))) | |
| 2977 (byte-compile-out 'byte-return 0) | |
| 2978 (setq byte-compile-output (nreverse byte-compile-output)) | |
| 2979 (if (memq byte-optimize '(t byte)) | |
| 2980 (setq byte-compile-output | |
| 2981 (byte-optimize-lapcode byte-compile-output for-effect))) | |
| 2982 | |
| 2983 ;; Decompile trivial functions: | |
| 2984 ;; only constants and variables, or a single funcall except in lambdas. | |
| 2985 ;; Except for Lisp_Compiled objects, forms like (foo "hi") | |
| 2986 ;; are still quicker than (byte-code "..." [foo "hi"] 2). | |
| 2987 ;; Note that even (quote foo) must be parsed just as any subr by the | |
| 2988 ;; interpreter, so quote should be compiled into byte-code in some contexts. | |
| 2989 ;; What to leave uncompiled: | |
| 2990 ;; lambda -> never. we used to leave it uncompiled if the body was | |
| 2991 ;; a single atom, but that causes confusion if the docstring | |
| 2992 ;; uses the (file . pos) syntax. Besides, now that we have | |
| 2993 ;; the Lisp_Compiled type, the compiled form is faster. | |
| 2994 ;; eval -> atom, quote or (function atom atom atom) | |
| 2995 ;; progn -> as <<same-as-eval>> or (progn <<same-as-eval>> atom) | |
| 2996 ;; file -> as progn, but takes both quotes and atoms, and longer forms. | |
| 2997 (let (rest | |
| 2998 (maycall (not (eq output-type 'lambda))) ; t if we may make a funcall. | |
| 2999 tmp body) | |
| 3000 (cond | |
| 3001 ;; #### This should be split out into byte-compile-nontrivial-function-p. | |
| 3002 ((or (eq output-type 'lambda) | |
| 3003 (nthcdr (if (eq output-type 'file) 50 8) byte-compile-output) | |
| 3004 (assq 'TAG byte-compile-output) ; Not necessary, but speeds up a bit. | |
| 3005 (not (setq tmp (assq 'byte-return byte-compile-output))) | |
| 3006 (progn | |
| 3007 (setq rest (nreverse | |
| 3008 (cdr (memq tmp (reverse byte-compile-output))))) | |
| 3009 (while (cond | |
| 3010 ((memq (car (car rest)) '(byte-varref byte-constant)) | |
| 3011 (setq tmp (car (cdr (car rest)))) | |
| 3012 (if (if (eq (car (car rest)) 'byte-constant) | |
| 3013 (or (consp tmp) | |
| 3014 (and (symbolp tmp) | |
| 3015 (not (byte-compile-constant-symbol-p tmp))))) | |
| 3016 (if maycall | |
| 3017 (setq body (cons (list 'quote tmp) body))) | |
| 3018 (setq body (cons tmp body)))) | |
| 3019 ((and maycall | |
| 3020 ;; Allow a funcall if at most one atom follows it. | |
| 3021 (null (nthcdr 3 rest)) | |
|
5503
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
3022 (setq tmp (get (car (car rest)) 'byte-opcode-invert)) |
| 428 | 3023 (or (null (cdr rest)) |
| 3024 (and (memq output-type '(file progn t)) | |
| 3025 (cdr (cdr rest)) | |
| 3026 (eq (car (nth 1 rest)) 'byte-discard) | |
| 3027 (progn (setq rest (cdr rest)) t)))) | |
| 3028 (setq maycall nil) ; Only allow one real function call. | |
| 3029 (setq body (nreverse body)) | |
| 3030 (setq body (list | |
| 3031 (if (and (eq tmp 'funcall) | |
| 3032 (eq (car-safe (car body)) 'quote)) | |
| 3033 (cons (nth 1 (car body)) (cdr body)) | |
| 3034 (cons tmp body)))) | |
| 3035 (or (eq output-type 'file) | |
|
5652
cc6f0266bc36
Avoid #'delq in core Lisp, for the sake of style, a very slightly smaller binary
Aidan Kehoe <kehoea@parhasard.net>
parents:
5651
diff
changeset
|
3036 (notany #'consp (cdar body))))) |
| 428 | 3037 (setq rest (cdr rest))) |
| 3038 rest)) | |
| 3039 (let ((byte-compile-vector (byte-compile-constants-vector))) | |
| 3040 (list 'byte-code (byte-compile-lapcode byte-compile-output) | |
| 3041 byte-compile-vector byte-compile-maxdepth))) | |
| 3042 ;; it's a trivial function | |
| 3043 ((cdr body) (cons 'progn (nreverse body))) | |
| 3044 ((car body))))) | |
| 3045 | |
| 3046 ;; Given BODY, compile it and return a new body. | |
| 3047 (defun byte-compile-top-level-body (body &optional for-effect) | |
| 3048 (setq body (byte-compile-top-level (cons 'progn body) for-effect t)) | |
| 3049 (cond ((eq (car-safe body) 'progn) | |
| 3050 (cdr body)) | |
| 3051 (body | |
| 3052 (list body)))) | |
| 3053 | |
| 3054 ;; This is the recursive entry point for compiling each subform of an | |
| 3055 ;; expression. | |
| 3056 ;; If for-effect is non-nil, byte-compile-form will output a byte-discard | |
| 3057 ;; before terminating (ie. no value will be left on the stack). | |
| 3058 ;; A byte-compile handler may, when for-effect is non-nil, choose output code | |
| 3059 ;; which does not leave a value on the stack, and then set for-effect to nil | |
| 3060 ;; (to prevent byte-compile-form from outputting the byte-discard). | |
| 3061 ;; If a handler wants to call another handler, it should do so via | |
| 3062 ;; byte-compile-form, or take extreme care to handle for-effect correctly. | |
| 3063 ;; (Use byte-compile-form-do-effect to reset the for-effect flag too.) | |
| 3064 ;; | |
| 3065 (defun byte-compile-form (form &optional for-effect) | |
| 3066 (setq form (macroexpand form byte-compile-macro-environment)) | |
| 3067 (cond ((not (consp form)) | |
| 3068 (cond ((or (not (symbolp form)) | |
| 3069 (byte-compile-constant-symbol-p form)) | |
| 3070 (byte-compile-constant form)) | |
| 3071 ((and for-effect byte-compile-delete-errors) | |
| 3072 (setq for-effect nil)) | |
| 3073 (t (byte-compile-variable-ref 'byte-varref form)))) | |
| 3074 ((symbolp (car form)) | |
| 3075 (let* ((fn (car form)) | |
| 3076 (handler (get fn 'byte-compile))) | |
| 3077 (if (memq fn '(t nil)) | |
| 3078 (byte-compile-warn "%s called as a function" fn)) | |
|
5503
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
3079 (if handler |
| 428 | 3080 (funcall handler form) |
| 3081 (if (memq 'callargs byte-compile-warnings) | |
| 3082 (byte-compile-callargs-warn form)) | |
| 3083 (byte-compile-normal-call form)))) | |
|
5656
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
3084 ((and (eq (car-safe (car form)) 'lambda) |
| 428 | 3085 ;; if the form comes out the same way it went in, that's |
| 3086 ;; because it was malformed, and we couldn't unfold it. | |
| 3087 (not (eq form (setq form (byte-compile-unfold-lambda form))))) | |
| 3088 (byte-compile-form form for-effect) | |
| 3089 (setq for-effect nil)) | |
| 3090 ((byte-compile-normal-call form))) | |
| 3091 (when for-effect | |
| 3092 (byte-compile-discard))) | |
| 3093 | |
|
5294
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3094 ;; Generate the list of functions with keyword arguments like so: |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3095 ;; |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3096 ;; (delete-duplicates |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3097 ;; (sort* |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3098 ;; (loop |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3099 ;; for symbol being each symbol in obarray |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3100 ;; with arglist = nil |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3101 ;; if (and (fboundp symbol) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3102 ;; (ignore-errors (setq symbol (indirect-function symbol))) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3103 ;; (cond |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3104 ;; ((and (subrp symbol) (setq symbol (intern (subr-name symbol))))) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3105 ;; ((and (compiled-function-p symbol) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3106 ;; (setq symbol (compiled-function-annotation symbol))))) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3107 ;; (setq arglist (function-arglist symbol)) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3108 ;; (setq arglist (ignore-errors (read-from-string arglist))) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3109 ;; (setq arglist (car arglist)) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3110 ;; (setq arglist (position '&key arglist))) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3111 ;; collect (cons symbol arglist)) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3112 ;; #'string-lessp |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3113 ;; :key #'car) :test #'eq :key #'car) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3114 ;; |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3115 ;; That won't include those that take advantage of cl-seq.el's |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3116 ;; cl-parsing-keywords macro, but the below list does. |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3117 |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3118 (map nil |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3119 (function* |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3120 (lambda ((function . nargs)) |
|
5656
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
3121 ;; Document that FUNCTION, a symbol, describes a function taking |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
3122 ;; keyword arguments from the argument index described by NARGS. |
|
5294
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3123 (put function 'byte-compile-keyword-start nargs))) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3124 '((adjoin . 3) (assoc* . 3) (assoc-if . 3) (assoc-if-not . 3) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3125 (count . 3) (count-if . 3) (count-if-not . 3) (define-behavior . 3) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3126 (define-behavior-group . 2) (delete* . 3) (delete-duplicates . 2) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3127 (delete-if . 3) (delete-if-not . 3) (fill . 3) (find . 3) (find-if . 3) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3128 (find-if-not . 3) (internal-make-translation-table . 1) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3129 (make-Print-context . 1) (make-hash-table . 1) (make-saved-window . 1) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3130 (make-window-configuration . 1) (member* . 3) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3131 (member-if . 3) (member-if-not . 3) (merge . 5) (nsublis . 3) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3132 (nsubst . 4) (nsubst-if . 4) (nsubst-if-not . 4) (nsubstitute . 4) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3133 (nsubstitute-if . 4) (nsubstitute-if-not . 4) (override-behavior . 2) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3134 (position . 3) (position-if . 3) (position-if-not . 3) (rassoc* . 3) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3135 (rassoc-if . 3) (rassoc-if-not . 3) (reduce . 3) (remove* . 3) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3136 (remove-duplicates . 2) (remove-if . 3) (remove-if-not . 3) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3137 (replace . 3) (sort* . 3) (stable-sort . 3) (sublis . 3) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3138 (subsetp . 3) (subst . 4) (subst-if . 4) (subst-if-not . 4) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3139 (substitute . 4) (substitute-if . 4) (substitute-if-not . 4) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3140 (tree-equal . 3))) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3141 |
| 428 | 3142 (defun byte-compile-normal-call (form) |
|
5358
31475de17064
#'byte-compile-normal-call; only examine properties of (car FORM) if a symbol
Aidan Kehoe <kehoea@parhasard.net>
parents:
5356
diff
changeset
|
3143 (and (symbolp (car form)) (get (car form) 'byte-compile-keyword-start) |
|
5294
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3144 (let ((plist (nthcdr (get (car form) 'byte-compile-keyword-start) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3145 form))) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3146 (symbol-macrolet |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3147 ((not-present '#:not-present)) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3148 (if (not (valid-plist-p plist)) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3149 (byte-compile-warn |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3150 "#'%s: ill-formed keyword argument list: %S" (car form) plist) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3151 (and |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3152 (memq 'callargs byte-compile-warnings) |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3153 (map nil |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3154 (function* |
|
bbff29a01820
Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5282
diff
changeset
|
3155 (lambda ((function . nargs)) |
|
5548
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
3156 (let ((value (plist-get plist function not-present))) |
|
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
3157 (when (and (not (eq value not-present)) |
|
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
3158 (byte-compile-constp value)) |
|
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
3159 (byte-compile-callargs-warn |
|
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
3160 (cons (eval value) |
|
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
3161 (member* |
|
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
3162 nargs |
|
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
3163 ;; Dummy arguments. There's no need for |
|
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
3164 ;; it to be longer than even 2, now, but |
|
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
3165 ;; very little harm in it. |
|
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
3166 '(9 8 7 6 5 4 3 2 1)))) |
|
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
3167 (when (and (eq (car-safe value) 'quote) |
|
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
3168 (eq (car-safe (nth 1 value)) 'lambda) |
|
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
3169 (or |
|
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
3170 (null (memq 'quoted-lambda |
|
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
3171 byte-compile-warnings)) |
|
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
3172 (byte-compile-warn |
|
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
3173 "Passing a quoted lambda to #'%s, \ |
|
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
3174 keyword %s, forcing function quoting" (car form) function))) |
|
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
3175 (setcar value 'function)))))) |
|
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
3176 '((:key . 1) (:test . 2) (:test-not . 2) (:if . 1) |
|
b90c153730c7
Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5506
diff
changeset
|
3177 (:if-not . 1)))))))) |
| 428 | 3178 (if byte-compile-generate-call-tree |
| 3179 (byte-compile-annotate-call-tree form)) | |
| 3180 (byte-compile-push-constant (car form)) | |
|
4783
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4775
diff
changeset
|
3181 (mapc 'byte-compile-form (cdr form)) ; wasteful, but faster. |
| 428 | 3182 (byte-compile-out 'byte-call (length (cdr form)))) |
| 3183 | |
| 3184 ;; kludge added to XEmacs to work around the bogosities of a nonlexical lisp. | |
| 3185 (or (fboundp 'globally-boundp) (fset 'globally-boundp 'boundp)) | |
| 3186 | |
| 3187 (defun byte-compile-variable-ref (base-op var &optional varbind-flags) | |
| 3188 (if (or (not (symbolp var)) (byte-compile-constant-symbol-p var)) | |
| 3189 (byte-compile-warn | |
| 3190 (case base-op | |
| 3191 (byte-varref "Variable reference to %s %s") | |
| 3192 (byte-varset "Attempt to set %s %s") | |
| 3193 (byte-varbind "Attempt to let-bind %s %s")) | |
| 3194 (if (symbolp var) "constant symbol" "non-symbol") | |
| 3195 var) | |
| 3196 (if (and (get var 'byte-obsolete-variable) | |
| 3197 (memq 'obsolete byte-compile-warnings)) | |
| 3198 (let ((ob (get var 'byte-obsolete-variable))) | |
| 3199 (byte-compile-warn "%s is an obsolete variable; %s" var | |
| 3200 (if (stringp ob) | |
| 3201 ob | |
| 3202 (format "use %s instead." ob))))) | |
| 3203 (if (and (get var 'byte-compatible-variable) | |
| 3204 (memq 'pedantic byte-compile-warnings)) | |
| 3205 (let ((ob (get var 'byte-compatible-variable))) | |
| 3206 (byte-compile-warn "%s is provided for compatibility; %s" var | |
| 3207 (if (stringp ob) | |
| 3208 ob | |
| 3209 (format "use %s instead." ob))))) | |
| 3210 (if (memq 'free-vars byte-compile-warnings) | |
| 3211 (if (eq base-op 'byte-varbind) | |
| 3212 (setq byte-compile-bound-variables | |
| 3213 (cons (cons var (or varbind-flags 0)) | |
| 3214 byte-compile-bound-variables)) | |
| 3215 (or (globally-boundp var) | |
| 3216 (let ((cell (assq var byte-compile-bound-variables))) | |
| 3217 (if cell (setcdr cell | |
| 3218 (logior (cdr cell) | |
| 3219 (if (eq base-op 'byte-varset) | |
| 3220 byte-compile-assigned-bit | |
| 3221 byte-compile-referenced-bit))))) | |
| 444 | 3222 (and (boundp 'current-load-list) |
| 3223 (memq var current-load-list)) | |
| 428 | 3224 (if (eq base-op 'byte-varset) |
| 3225 (or (memq var byte-compile-free-assignments) | |
| 3226 (progn | |
| 3227 (byte-compile-warn "assignment to free variable %s" | |
| 3228 var) | |
| 3229 (setq byte-compile-free-assignments | |
| 3230 (cons var byte-compile-free-assignments)))) | |
| 3231 (or (memq var byte-compile-free-references) | |
| 3232 (progn | |
| 3233 (byte-compile-warn "reference to free variable %s" var) | |
| 3234 (setq byte-compile-free-references | |
| 3235 (cons var byte-compile-free-references))))))))) | |
| 3236 (let ((tmp (assq var byte-compile-variables))) | |
| 3237 (or tmp | |
| 3238 (setq tmp (list var) | |
| 3239 byte-compile-variables (cons tmp byte-compile-variables))) | |
| 3240 (byte-compile-out base-op tmp))) | |
| 3241 | |
| 3242 (defmacro byte-compile-get-constant (const) | |
| 3243 `(or (if (stringp ,const) | |
| 3244 (assoc ,const byte-compile-constants) | |
| 3245 (assq ,const byte-compile-constants)) | |
| 3246 (car (setq byte-compile-constants | |
| 3247 (cons (list ,const) byte-compile-constants))))) | |
| 3248 | |
| 3249 ;; Use this when the value of a form is a constant. This obeys for-effect. | |
| 3250 (defun byte-compile-constant (const) | |
| 3251 (if for-effect | |
| 3252 (setq for-effect nil) | |
| 3253 (byte-compile-out 'byte-constant (byte-compile-get-constant const)))) | |
| 3254 | |
| 3255 ;; Use this for a constant that is not the value of its containing form. | |
| 3256 ;; This ignores for-effect. | |
| 3257 (defun byte-compile-push-constant (const) | |
| 3258 (let ((for-effect nil)) | |
| 3259 (inline (byte-compile-constant const)))) | |
| 3260 | |
| 3261 | |
| 3262 ;; Compile those primitive ordinary functions | |
| 3263 ;; which have special byte codes just for speed. | |
| 3264 | |
| 3265 (defmacro byte-defop-compiler (function &optional compile-handler) | |
| 3266 ;; add a compiler-form for FUNCTION. | |
| 446 | 3267 ;; If FUNCTION is a symbol, then the variable "byte-SYMBOL" must name |
| 3268 ;; the opcode to be used. If is a list, the first element | |
| 428 | 3269 ;; is the function and the second element is the bytecode-symbol. |
| 3270 ;; COMPILE-HANDLER is the function to use to compile this byte-op, or | |
| 3271 ;; may be the abbreviations 0, 1, 2, 3, 0-1, 1-2, 2-3, 0+1, 1+1, 2+1, | |
| 3272 ;; 0-1+1, 1-2+1, 2-3+1, 0+2, or 1+2. If it is nil, then the handler is | |
| 3273 ;; "byte-compile-SYMBOL." | |
| 3274 (let (opcode) | |
| 3275 (if (symbolp function) | |
| 3276 (setq opcode (intern (concat "byte-" (symbol-name function)))) | |
| 3277 (setq opcode (car (cdr function)) | |
| 3278 function (car function))) | |
| 3279 (let ((fnform | |
| 3280 (list 'put (list 'quote function) ''byte-compile | |
| 3281 (list 'quote | |
| 3282 (or (cdr (assq compile-handler | |
| 3283 '((0 . byte-compile-no-args) | |
| 3284 (1 . byte-compile-one-arg) | |
| 3285 (2 . byte-compile-two-args) | |
| 3286 (3 . byte-compile-three-args) | |
| 3287 (0-1 . byte-compile-zero-or-one-arg) | |
| 3288 (1-2 . byte-compile-one-or-two-args) | |
| 3289 (2-3 . byte-compile-two-or-three-args) | |
| 3290 (0+1 . byte-compile-no-args-with-one-extra) | |
| 3291 (1+1 . byte-compile-one-arg-with-one-extra) | |
| 3292 (2+1 . byte-compile-two-args-with-one-extra) | |
| 3293 (0-1+1 . byte-compile-zero-or-one-arg-with-one-extra) | |
| 3294 (1-2+1 . byte-compile-one-or-two-args-with-one-extra) | |
| 3295 (2-3+1 . byte-compile-two-or-three-args-with-one-extra) | |
| 3296 (0+2 . byte-compile-no-args-with-two-extra) | |
| 3297 (1+2 . byte-compile-one-arg-with-two-extra) | |
| 3298 | |
| 3299 ))) | |
| 3300 compile-handler | |
| 3301 (intern (concat "byte-compile-" | |
| 3302 (symbol-name function)))))))) | |
| 3303 (if opcode | |
| 3304 (list 'progn fnform | |
| 3305 (list 'put (list 'quote function) | |
| 3306 ''byte-opcode (list 'quote opcode)) | |
| 3307 (list 'put (list 'quote opcode) | |
| 3308 ''byte-opcode-invert (list 'quote function))) | |
| 3309 fnform)))) | |
| 3310 | |
| 3311 (defmacro byte-defop-compiler-1 (function &optional compile-handler) | |
| 3312 (list 'byte-defop-compiler (list function nil) compile-handler)) | |
| 3313 | |
| 3314 | |
| 3315 (put 'byte-call 'byte-opcode-invert 'funcall) | |
| 3316 (put 'byte-list1 'byte-opcode-invert 'list) | |
| 3317 (put 'byte-list2 'byte-opcode-invert 'list) | |
| 3318 (put 'byte-list3 'byte-opcode-invert 'list) | |
| 3319 (put 'byte-list4 'byte-opcode-invert 'list) | |
| 3320 (put 'byte-listN 'byte-opcode-invert 'list) | |
| 3321 (put 'byte-concat2 'byte-opcode-invert 'concat) | |
| 3322 (put 'byte-concat3 'byte-opcode-invert 'concat) | |
| 3323 (put 'byte-concat4 'byte-opcode-invert 'concat) | |
| 3324 (put 'byte-concatN 'byte-opcode-invert 'concat) | |
| 3325 (put 'byte-insertN 'byte-opcode-invert 'insert) | |
| 3326 | |
| 3327 ;; How old is this stuff? -slb | |
| 3328 ;(byte-defop-compiler (dot byte-point) 0+1) | |
| 3329 ;(byte-defop-compiler (dot-max byte-point-max) 0+1) | |
| 3330 ;(byte-defop-compiler (dot-min byte-point-min) 0+1) | |
| 3331 (byte-defop-compiler point 0+1) | |
|
5503
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
3332 (byte-defop-compiler eq 2) |
| 428 | 3333 (byte-defop-compiler point-max 0+1) |
| 3334 (byte-defop-compiler point-min 0+1) | |
| 3335 (byte-defop-compiler following-char 0+1) | |
| 3336 (byte-defop-compiler preceding-char 0+1) | |
| 3337 (byte-defop-compiler current-column 0+1) | |
| 3338 ;; FSF has special function here; generalized here by the 1+2 stuff. | |
| 3339 (byte-defop-compiler (indent-to-column byte-indent-to) 1+2) | |
| 3340 (byte-defop-compiler indent-to 1+2) | |
|
5503
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
3341 (byte-defop-compiler equal 2) |
| 428 | 3342 (byte-defop-compiler eolp 0+1) |
| 3343 (byte-defop-compiler eobp 0+1) | |
| 3344 (byte-defop-compiler bolp 0+1) | |
| 3345 (byte-defop-compiler bobp 0+1) | |
| 3346 (byte-defop-compiler current-buffer 0) | |
| 3347 ;;(byte-defop-compiler read-char 0) ;; obsolete | |
|
5503
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
3348 (byte-defop-compiler memq 2) |
| 428 | 3349 (byte-defop-compiler interactive-p 0) |
| 3350 (byte-defop-compiler widen 0+1) | |
| 3351 (byte-defop-compiler end-of-line 0-1+1) | |
| 3352 (byte-defop-compiler forward-char 0-1+1) | |
| 3353 (byte-defop-compiler forward-line 0-1+1) | |
| 3354 (byte-defop-compiler symbolp 1) | |
| 3355 (byte-defop-compiler consp 1) | |
| 3356 (byte-defop-compiler stringp 1) | |
| 3357 (byte-defop-compiler listp 1) | |
| 3358 (byte-defop-compiler not 1) | |
| 3359 (byte-defop-compiler (null byte-not) 1) | |
| 3360 (byte-defop-compiler car 1) | |
| 3361 (byte-defop-compiler cdr 1) | |
| 3362 (byte-defop-compiler length 1) | |
|
5562
855b667dea13
Drop cl-macro-environment in favour of byte-compile-macro-environment.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
3363 (byte-defop-compiler symbol-value 1) |
| 428 | 3364 (byte-defop-compiler symbol-function 1) |
| 3365 (byte-defop-compiler (1+ byte-add1) 1) | |
| 3366 (byte-defop-compiler (1- byte-sub1) 1) | |
| 3367 (byte-defop-compiler goto-char 1+1) | |
| 3368 (byte-defop-compiler char-after 0-1+1) | |
| 3369 (byte-defop-compiler set-buffer 1) | |
| 3370 ;;(byte-defop-compiler set-mark 1) ;; obsolete | |
| 2217 | 3371 (byte-defop-compiler forward-word 0-1+1) |
| 428 | 3372 (byte-defop-compiler char-syntax 1+1) |
| 3373 (byte-defop-compiler nreverse 1) | |
| 3374 (byte-defop-compiler car-safe 1) | |
| 3375 (byte-defop-compiler cdr-safe 1) | |
| 3376 (byte-defop-compiler numberp 1) | |
|
4885
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
3377 (byte-defop-compiler fixnump 1) |
| 428 | 3378 (byte-defop-compiler skip-chars-forward 1-2+1) |
| 3379 (byte-defop-compiler skip-chars-backward 1-2+1) | |
|
5301
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
3380 (byte-defop-compiler eq 2) |
|
5503
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
3381 ; (byte-defop-compiler old-eq 2) |
|
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
3382 ; (byte-defop-compiler old-memq 2) |
| 428 | 3383 (byte-defop-compiler cons 2) |
| 3384 (byte-defop-compiler aref 2) | |
| 3385 (byte-defop-compiler get 2+1) | |
| 3386 (byte-defop-compiler nth 2) | |
|
5089
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3387 (byte-defop-compiler subseq byte-compile-subseq) |
|
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3388 (byte-defop-compiler (substring byte-subseq) 2-3) |
| 428 | 3389 (byte-defop-compiler (move-marker byte-set-marker) 2-3) |
| 3390 (byte-defop-compiler set-marker 2-3) | |
| 3391 (byte-defop-compiler match-beginning 1) | |
| 3392 (byte-defop-compiler match-end 1) | |
| 3393 (byte-defop-compiler upcase 1+1) | |
| 3394 (byte-defop-compiler downcase 1+1) | |
| 3395 (byte-defop-compiler string= 2) | |
| 3396 (byte-defop-compiler string< 2) | |
| 3397 (byte-defop-compiler (string-equal byte-string=) 2) | |
| 3398 (byte-defop-compiler (string-lessp byte-string<) 2) | |
|
5503
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
3399 ; (byte-defop-compiler old-equal 2) |
| 428 | 3400 (byte-defop-compiler nthcdr 2) |
| 3401 (byte-defop-compiler elt 2) | |
|
5503
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
3402 (byte-defop-compiler old-member 2) |
|
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
3403 (byte-defop-compiler old-assq 2) |
| 428 | 3404 (byte-defop-compiler (rplaca byte-setcar) 2) |
| 3405 (byte-defop-compiler (rplacd byte-setcdr) 2) | |
| 3406 (byte-defop-compiler setcar 2) | |
| 3407 (byte-defop-compiler setcdr 2) | |
| 3408 (byte-defop-compiler delete-region 2+1) | |
| 3409 (byte-defop-compiler narrow-to-region 2+1) | |
| 3410 (byte-defop-compiler (% byte-rem) 2) | |
| 3411 (byte-defop-compiler aset 3) | |
| 3412 | |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3413 (byte-defop-compiler-1 bind-multiple-value-limits) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3414 (byte-defop-compiler multiple-value-list-internal) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3415 (byte-defop-compiler-1 multiple-value-call) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3416 (byte-defop-compiler throw) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3417 |
|
5503
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
3418 (byte-defop-compiler member 2) |
|
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
3419 (byte-defop-compiler assq 2) |
| 428 | 3420 |
| 3421 ;;####(byte-defop-compiler move-to-column 1) | |
| 3422 (byte-defop-compiler-1 interactive byte-compile-noop) | |
| 3423 (byte-defop-compiler-1 domain byte-compile-domain) | |
| 3424 | |
| 3425 ;; As of GNU Emacs 19.18 and Lucid Emacs 19.8, mod and % are different: `%' | |
| 3426 ;; means integral remainder and may have a negative result; `mod' is always | |
| 3427 ;; positive, and accepts floating point args. All code which uses `mod' and | |
| 3428 ;; requires the new interpretation must be compiled with bytecomp version 2.18 | |
| 3429 ;; or newer, or the emitted code will run the byte-code for `%' instead of an | |
| 3430 ;; actual call to `mod'. So be careful of compiling new code with an old | |
| 3431 ;; compiler. Note also that `%' is more efficient than `mod' because the | |
| 3432 ;; former is byte-coded and the latter is not. | |
| 3433 ;;(byte-defop-compiler (mod byte-rem) 2) | |
| 3434 | |
| 3435 | |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3436 (defun byte-compile-warn-wrong-args (form n) |
| 428 | 3437 (when (memq 'subr-callargs byte-compile-warnings) |
| 3438 (byte-compile-warn "%s called with %d arg%s, but requires %s" | |
| 3439 (car form) (length (cdr form)) | |
|
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5358
diff
changeset
|
3440 (if (eql 1 (length (cdr form))) "" "s") n))) |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3441 |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3442 (defun byte-compile-subr-wrong-args (form n) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
3443 (byte-compile-warn-wrong-args form n) |
| 428 | 3444 ;; get run-time wrong-number-of-args error. |
| 3445 (byte-compile-normal-call form)) | |
| 3446 | |
| 3447 (defun byte-compile-no-args (form) | |
| 3448 (case (length (cdr form)) | |
| 3449 (0 (byte-compile-out (get (car form) 'byte-opcode) 0)) | |
| 3450 (t (byte-compile-subr-wrong-args form "none")))) | |
| 3451 | |
| 3452 (defun byte-compile-one-arg (form) | |
| 3453 (case (length (cdr form)) | |
| 3454 (1 (byte-compile-form (car (cdr form))) ;; Push the argument | |
| 3455 (byte-compile-out (get (car form) 'byte-opcode) 0)) | |
| 3456 (t (byte-compile-subr-wrong-args form 1)))) | |
| 3457 | |
| 3458 (defun byte-compile-two-args (form) | |
| 3459 (case (length (cdr form)) | |
| 3460 (2 (byte-compile-form (nth 1 form)) ;; Push the arguments | |
| 3461 (byte-compile-form (nth 2 form)) | |
| 3462 (byte-compile-out (get (car form) 'byte-opcode) 0)) | |
| 3463 (t (byte-compile-subr-wrong-args form 2)))) | |
| 3464 | |
| 3465 (defun byte-compile-three-args (form) | |
| 3466 (case (length (cdr form)) | |
| 3467 (3 (byte-compile-form (nth 1 form)) ;; Push the arguments | |
| 3468 (byte-compile-form (nth 2 form)) | |
| 3469 (byte-compile-form (nth 3 form)) | |
| 3470 (byte-compile-out (get (car form) 'byte-opcode) 0)) | |
| 3471 (t (byte-compile-subr-wrong-args form 3)))) | |
| 3472 | |
| 3473 (defun byte-compile-zero-or-one-arg (form) | |
| 3474 (case (length (cdr form)) | |
| 3475 (0 (byte-compile-one-arg (append form '(nil)))) | |
| 3476 (1 (byte-compile-one-arg form)) | |
| 3477 (t (byte-compile-subr-wrong-args form "0-1")))) | |
| 3478 | |
| 3479 (defun byte-compile-one-or-two-args (form) | |
| 3480 (case (length (cdr form)) | |
| 3481 (1 (byte-compile-two-args (append form '(nil)))) | |
| 3482 (2 (byte-compile-two-args form)) | |
| 3483 (t (byte-compile-subr-wrong-args form "1-2")))) | |
| 3484 | |
| 3485 (defun byte-compile-two-or-three-args (form) | |
| 3486 (case (length (cdr form)) | |
| 3487 (2 (byte-compile-three-args (append form '(nil)))) | |
| 3488 (3 (byte-compile-three-args form)) | |
| 3489 (t (byte-compile-subr-wrong-args form "2-3")))) | |
| 3490 | |
| 3491 ;; from Ben Wing <ben@xemacs.org>: some inlined functions have extra | |
| 3492 ;; optional args added to them in XEmacs 19.12. Changing the byte | |
| 3493 ;; interpreter to deal with these args would be wrong and cause | |
| 3494 ;; incompatibility, so we generate non-inlined calls for those cases. | |
| 3495 ;; Without the following functions, spurious warnings will be generated; | |
| 3496 ;; however, they would still compile correctly because | |
| 3497 ;; `byte-compile-subr-wrong-args' also converts the call to non-inlined. | |
| 3498 | |
| 3499 (defun byte-compile-no-args-with-one-extra (form) | |
| 3500 (case (length (cdr form)) | |
| 3501 (0 (byte-compile-no-args form)) | |
| 446 | 3502 (1 (if (eq nil (nth 1 form)) |
| 3503 (byte-compile-no-args (butlast form)) | |
| 3504 (byte-compile-normal-call form))) | |
| 428 | 3505 (t (byte-compile-subr-wrong-args form "0-1")))) |
| 3506 | |
| 3507 (defun byte-compile-one-arg-with-one-extra (form) | |
| 3508 (case (length (cdr form)) | |
| 3509 (1 (byte-compile-one-arg form)) | |
| 446 | 3510 (2 (if (eq nil (nth 2 form)) |
| 3511 (byte-compile-one-arg (butlast form)) | |
| 3512 (byte-compile-normal-call form))) | |
| 428 | 3513 (t (byte-compile-subr-wrong-args form "1-2")))) |
| 3514 | |
| 3515 (defun byte-compile-two-args-with-one-extra (form) | |
| 3516 (case (length (cdr form)) | |
| 3517 (2 (byte-compile-two-args form)) | |
| 446 | 3518 (3 (if (eq nil (nth 3 form)) |
| 3519 (byte-compile-two-args (butlast form)) | |
| 3520 (byte-compile-normal-call form))) | |
| 428 | 3521 (t (byte-compile-subr-wrong-args form "2-3")))) |
| 3522 | |
| 3523 (defun byte-compile-zero-or-one-arg-with-one-extra (form) | |
| 3524 (case (length (cdr form)) | |
| 3525 (0 (byte-compile-one-arg (append form '(nil)))) | |
| 3526 (1 (byte-compile-one-arg form)) | |
| 446 | 3527 (2 (if (eq nil (nth 2 form)) |
| 3528 (byte-compile-one-arg (butlast form)) | |
| 3529 (byte-compile-normal-call form))) | |
| 428 | 3530 (t (byte-compile-subr-wrong-args form "0-2")))) |
| 3531 | |
| 3532 (defun byte-compile-one-or-two-args-with-one-extra (form) | |
| 3533 (case (length (cdr form)) | |
| 3534 (1 (byte-compile-two-args (append form '(nil)))) | |
| 3535 (2 (byte-compile-two-args form)) | |
| 446 | 3536 (3 (if (eq nil (nth 3 form)) |
| 3537 (byte-compile-two-args (butlast form)) | |
| 3538 (byte-compile-normal-call form))) | |
| 428 | 3539 (t (byte-compile-subr-wrong-args form "1-3")))) |
| 3540 | |
| 3541 (defun byte-compile-two-or-three-args-with-one-extra (form) | |
| 3542 (case (length (cdr form)) | |
| 3543 (2 (byte-compile-three-args (append form '(nil)))) | |
| 3544 (3 (byte-compile-three-args form)) | |
| 446 | 3545 (4 (if (eq nil (nth 4 form)) |
| 3546 (byte-compile-three-args (butlast form)) | |
| 3547 (byte-compile-normal-call form))) | |
| 428 | 3548 (t (byte-compile-subr-wrong-args form "2-4")))) |
| 3549 | |
| 3550 (defun byte-compile-no-args-with-two-extra (form) | |
| 3551 (case (length (cdr form)) | |
| 3552 (0 (byte-compile-no-args form)) | |
| 3553 ((1 2) (byte-compile-normal-call form)) | |
| 3554 (t (byte-compile-subr-wrong-args form "0-2")))) | |
| 3555 | |
| 3556 (defun byte-compile-one-arg-with-two-extra (form) | |
| 3557 (case (length (cdr form)) | |
| 3558 (1 (byte-compile-one-arg form)) | |
| 3559 ((2 3) (byte-compile-normal-call form)) | |
| 3560 (t (byte-compile-subr-wrong-args form "1-3")))) | |
| 3561 | |
| 3562 (defun byte-compile-noop (form) | |
| 3563 (byte-compile-constant nil)) | |
| 3564 | |
| 3565 (defun byte-compile-discard () | |
| 3566 (byte-compile-out 'byte-discard 0)) | |
| 3567 | |
| 446 | 3568 (defun byte-compile-max (form) |
| 3569 (let ((args (cdr form))) | |
| 428 | 3570 (case (length args) |
| 446 | 3571 (0 (byte-compile-subr-wrong-args form "1 or more")) |
| 3572 (1 (byte-compile-form (car args)) | |
| 3573 (when (not byte-compile-delete-errors) | |
| 3574 (byte-compile-out 'byte-dup 0) | |
| 3575 (byte-compile-out 'byte-max 0))) | |
| 428 | 3576 (t (byte-compile-form (car args)) |
| 446 | 3577 (dolist (elt (cdr args)) |
| 3578 (byte-compile-form elt) | |
| 3579 (byte-compile-out 'byte-max 0)))))) | |
| 3580 | |
| 3581 (defun byte-compile-min (form) | |
| 3582 (let ((args (cdr form))) | |
| 3583 (case (length args) | |
| 3584 (0 (byte-compile-subr-wrong-args form "1 or more")) | |
| 3585 (1 (byte-compile-form (car args)) | |
| 3586 (when (not byte-compile-delete-errors) | |
| 3587 (byte-compile-out 'byte-dup 0) | |
| 3588 (byte-compile-out 'byte-min 0))) | |
| 3589 (t (byte-compile-form (car args)) | |
| 3590 (dolist (elt (cdr args)) | |
| 3591 (byte-compile-form elt) | |
| 3592 (byte-compile-out 'byte-min 0)))))) | |
| 428 | 3593 |
| 3594 | |
| 3595 ;; more complicated compiler macros | |
| 3596 | |
| 3597 (byte-defop-compiler list) | |
| 3598 (byte-defop-compiler concat) | |
| 3599 (byte-defop-compiler fset) | |
| 3600 (byte-defop-compiler insert) | |
| 3601 (byte-defop-compiler-1 function byte-compile-function-form) | |
| 446 | 3602 (byte-defop-compiler max) |
| 3603 (byte-defop-compiler min) | |
| 3604 (byte-defop-compiler (+ byte-plus) byte-compile-plus) | |
| 3605 (byte-defop-compiler-1 - byte-compile-minus) | |
| 3606 (byte-defop-compiler (* byte-mult) byte-compile-mult) | |
| 3607 (byte-defop-compiler (/ byte-quo) byte-compile-quo) | |
| 428 | 3608 (byte-defop-compiler nconc) |
| 3609 (byte-defop-compiler-1 beginning-of-line) | |
| 3610 | |
| 3611 (byte-defop-compiler (= byte-eqlsign) byte-compile-arithcompare) | |
| 3612 (byte-defop-compiler (< byte-lss) byte-compile-arithcompare) | |
| 3613 (byte-defop-compiler (> byte-gtr) byte-compile-arithcompare) | |
| 3614 (byte-defop-compiler (<= byte-leq) byte-compile-arithcompare) | |
| 3615 (byte-defop-compiler (>= byte-geq) byte-compile-arithcompare) | |
| 3616 | |
| 3617 (defun byte-compile-arithcompare (form) | |
| 3618 (case (length (cdr form)) | |
| 3619 (0 (byte-compile-subr-wrong-args form "1 or more")) | |
| 549 | 3620 (1 (if byte-compile-delete-errors |
| 3621 (byte-compile-constant t) | |
| 3622 (byte-compile-normal-call form))) | |
| 428 | 3623 (2 (byte-compile-two-args form)) |
| 3624 (t (byte-compile-normal-call form)))) | |
| 3625 | |
| 3626 (byte-defop-compiler /= byte-compile-/=) | |
| 3627 | |
| 3628 (defun byte-compile-/= (form) | |
| 3629 (case (length (cdr form)) | |
| 3630 (0 (byte-compile-subr-wrong-args form "1 or more")) | |
| 3631 (1 (byte-compile-constant t)) | |
| 3632 ;; optimize (/= X Y) to (not (= X Y)) | |
| 3633 (2 (byte-compile-form-do-effect `(not (= ,@(cdr form))))) | |
| 3634 (t (byte-compile-normal-call form)))) | |
| 3635 | |
| 3636 ;; buffer-substring now has its own function. This used to be | |
| 3637 ;; 2+1, but now all args are optional. | |
| 3638 (byte-defop-compiler buffer-substring) | |
| 3639 | |
| 3640 (defun byte-compile-buffer-substring (form) | |
| 3641 ;; buffer-substring used to take exactly two args, but now takes 0-3. | |
| 3642 ;; convert 0-2 to two args and use special bytecode operand. | |
| 3643 ;; convert 3 args to a normal call. | |
| 3644 (case (length (cdr form)) | |
| 3645 (0 (byte-compile-two-args (append form '(nil nil)))) | |
| 3646 (1 (byte-compile-two-args (append form '(nil)))) | |
| 3647 (2 (byte-compile-two-args form)) | |
| 3648 (3 (byte-compile-normal-call form)) | |
| 3649 (t (byte-compile-subr-wrong-args form "0-3")))) | |
| 3650 | |
| 3651 (defun byte-compile-list (form) | |
| 3652 (let* ((args (cdr form)) | |
| 3653 (nargs (length args))) | |
| 3654 (cond | |
|
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5358
diff
changeset
|
3655 ((eql nargs 0) |
| 428 | 3656 (byte-compile-constant nil)) |
| 3657 ((< nargs 5) | |
|
4783
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4775
diff
changeset
|
3658 (mapc 'byte-compile-form args) |
| 428 | 3659 (byte-compile-out |
| 3660 (aref [byte-list1 byte-list2 byte-list3 byte-list4] (1- nargs)) | |
| 3661 0)) | |
| 3662 ((< nargs 256) | |
|
4783
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4775
diff
changeset
|
3663 (mapc 'byte-compile-form args) |
| 428 | 3664 (byte-compile-out 'byte-listN nargs)) |
| 3665 (t (byte-compile-normal-call form))))) | |
| 3666 | |
| 3667 (defun byte-compile-concat (form) | |
| 3668 (let* ((args (cdr form)) | |
| 3669 (nargs (length args))) | |
| 3670 ;; Concat of one arg is not a no-op if arg is not a string. | |
| 3671 (cond | |
| 3672 ((memq nargs '(2 3 4)) | |
|
4783
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4775
diff
changeset
|
3673 (mapc 'byte-compile-form args) |
| 428 | 3674 (byte-compile-out |
| 3675 (aref [byte-concat2 byte-concat3 byte-concat4] (- nargs 2)) | |
| 3676 0)) | |
| 3677 ((eq nargs 0) | |
| 3678 (byte-compile-form "")) | |
| 3679 ((< nargs 256) | |
|
4783
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4775
diff
changeset
|
3680 (mapc 'byte-compile-form args) |
| 428 | 3681 (byte-compile-out 'byte-concatN nargs)) |
| 3682 ((byte-compile-normal-call form))))) | |
| 3683 | |
| 446 | 3684 (defun byte-compile-plus (form) |
| 3685 (let ((args (cdr form))) | |
| 3686 (case (length args) | |
| 3687 (0 (byte-compile-constant 0)) | |
| 3688 (1 (byte-compile-plus (append form '(0)))) | |
| 3689 (t (byte-compile-form (car args)) | |
| 3690 (dolist (elt (cdr args)) | |
| 3691 (case elt | |
| 3692 (0 (when (not byte-compile-delete-errors) | |
| 3693 (byte-compile-constant 0) | |
| 3694 (byte-compile-out 'byte-plus 0))) | |
| 3695 (+1 (byte-compile-out 'byte-add1 0)) | |
| 3696 (-1 (byte-compile-out 'byte-sub1 0)) | |
| 3697 (t | |
| 3698 (byte-compile-form elt) | |
| 3699 (byte-compile-out 'byte-plus 0)))))))) | |
| 3700 | |
| 428 | 3701 (defun byte-compile-minus (form) |
| 3702 (let ((args (cdr form))) | |
| 3703 (case (length args) | |
| 3704 (0 (byte-compile-subr-wrong-args form "1 or more")) | |
| 3705 (1 (byte-compile-form (car args)) | |
| 3706 (byte-compile-out 'byte-negate 0)) | |
| 3707 (t (byte-compile-form (car args)) | |
| 3708 (dolist (elt (cdr args)) | |
| 446 | 3709 (case elt |
| 3710 (0 (when (not byte-compile-delete-errors) | |
| 3711 (byte-compile-constant 0) | |
| 3712 (byte-compile-out 'byte-diff 0))) | |
| 3713 (+1 (byte-compile-out 'byte-sub1 0)) | |
| 3714 (-1 (byte-compile-out 'byte-add1 0)) | |
| 3715 (t | |
| 3716 (byte-compile-form elt) | |
| 3717 (byte-compile-out 'byte-diff 0)))))))) | |
| 3718 | |
| 3719 (defun byte-compile-mult (form) | |
| 3720 (let ((args (cdr form))) | |
| 3721 (case (length args) | |
| 3722 (0 (byte-compile-constant 1)) | |
| 3723 (1 (byte-compile-mult (append form '(1)))) | |
| 3724 (t (byte-compile-form (car args)) | |
| 3725 (dolist (elt (cdr args)) | |
| 3726 (case elt | |
| 3727 (1 (when (not byte-compile-delete-errors) | |
| 3728 (byte-compile-constant 1) | |
| 3729 (byte-compile-out 'byte-mult 0))) | |
| 3730 (-1 (byte-compile-out 'byte-negate 0)) | |
| 3731 (2 (byte-compile-out 'byte-dup 0) | |
| 3732 (byte-compile-out 'byte-plus 0)) | |
| 3733 (t | |
| 3734 (byte-compile-form elt) | |
| 3735 (byte-compile-out 'byte-mult 0)))))))) | |
| 428 | 3736 |
| 3737 (defun byte-compile-quo (form) | |
| 3738 (let ((args (cdr form))) | |
| 3739 (case (length args) | |
| 3740 (0 (byte-compile-subr-wrong-args form "1 or more")) | |
| 3741 (1 (byte-compile-constant 1) | |
| 3742 (byte-compile-form (car args)) | |
| 3743 (byte-compile-out 'byte-quo 0)) | |
| 3744 (t (byte-compile-form (car args)) | |
| 3745 (dolist (elt (cdr args)) | |
| 446 | 3746 (case elt |
| 3747 (+1 (when (not byte-compile-delete-errors) | |
| 3748 (byte-compile-constant 1) | |
| 3749 (byte-compile-out 'byte-quo 0))) | |
| 3750 (-1 (byte-compile-out 'byte-negate 0)) | |
| 3751 (t | |
| 3752 (when (and (numberp elt) (= elt 0)) | |
| 3753 (byte-compile-warn "Attempt to divide by zero: %s" form)) | |
| 3754 (byte-compile-form elt) | |
| 3755 (byte-compile-out 'byte-quo 0)))))))) | |
| 428 | 3756 |
| 3757 (defun byte-compile-nconc (form) | |
| 3758 (let ((args (cdr form))) | |
| 3759 (case (length args) | |
| 3760 (0 (byte-compile-constant nil)) | |
| 3761 ;; nconc of one arg is a noop, even if that arg isn't a list. | |
| 3762 (1 (byte-compile-form (car args))) | |
| 3763 (t (byte-compile-form (car args)) | |
| 3764 (dolist (elt (cdr args)) | |
| 3765 (byte-compile-form elt) | |
| 3766 (byte-compile-out 'byte-nconc 0)))))) | |
| 3767 | |
| 3768 (defun byte-compile-fset (form) | |
| 3769 ;; warn about forms like (fset 'foo '(lambda () ...)) | |
| 3770 ;; (where the lambda expression is non-trivial...) | |
| 3771 ;; Except don't warn if the first argument is 'make-byte-code, because | |
| 3772 ;; I'm sick of getting mail asking me whether that warning is a problem. | |
| 3773 (let ((fn (nth 2 form)) | |
| 3774 body) | |
| 3775 (when (and (eq (car-safe fn) 'quote) | |
| 3776 (eq (car-safe (setq fn (nth 1 fn))) 'lambda) | |
| 3777 (not (eq (car-safe (cdr-safe (nth 1 form))) 'make-byte-code))) | |
| 3778 (setq body (cdr (cdr fn))) | |
| 3779 (if (stringp (car body)) (setq body (cdr body))) | |
| 3780 (if (eq 'interactive (car-safe (car body))) (setq body (cdr body))) | |
| 3781 (if (and (consp (car body)) | |
|
4719
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
3782 (not (eq 'byte-code (car (car body)))) |
|
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
3783 (memq 'quoted-lambda byte-compile-warnings)) |
| 428 | 3784 (byte-compile-warn |
| 3785 "A quoted lambda form is the second argument of fset. This is probably | |
| 3786 not what you want, as that lambda cannot be compiled. Consider using | |
| 3787 the syntax (function (lambda (...) ...)) instead.")))) | |
| 3788 (byte-compile-two-args form)) | |
| 3789 | |
|
5089
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3790 (defun byte-compile-subseq (form) |
|
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3791 (byte-compile-two-or-three-args form) |
|
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3792 ;; Check that XEmacs supports the substring-subseq equivalence. |
|
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3793 (pushnew '(eq 'subseq (symbol-function 'substring)) |
|
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3794 byte-compile-checks-on-load :test #'equal)) |
|
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4996
diff
changeset
|
3795 |
|
4743
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3796 (defmacro byte-compile-funarg-n (&rest n) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3797 `#'(lambda (form) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3798 ,@(loop |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3799 for en in n |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3800 collect `(let ((fn (nth ,en form))) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3801 (when (and (eq (car-safe fn) 'quote) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3802 (eq (car-safe (nth 1 fn)) 'lambda) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3803 (or |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3804 (null (memq 'quoted-lambda |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3805 byte-compile-warnings)) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3806 (byte-compile-warn |
|
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3807 "Passing a quoted lambda (arg %d) to #'%s, \ |
|
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3808 forcing function quoting" ,en (car form)))) |
|
4743
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3809 (setcar fn 'function)))) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3810 (byte-compile-normal-call form))) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3811 |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3812 ;; (mapcar '(lambda (x) ..) ..) ==> (mapcar (function (lambda (x) ..)) ..) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3813 ;; for cases where it's guaranteed that first arg will be used as a lambda. |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3814 (defalias 'byte-compile-funarg (byte-compile-funarg-n 1)) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3815 |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3816 ;; (sort ... '(lambda (x) ..)) ==> (sort ... (function (lambda (x) ..))) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3817 ;; for cases where it's guaranteed that second arg will be used as a lambda. |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3818 (defalias 'byte-compile-funarg-2 (byte-compile-funarg-n 2)) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3819 |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3820 ;; For #'merge, basically. |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3821 (defalias 'byte-compile-funarg-4 (byte-compile-funarg-n 4)) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3822 |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3823 ;; For #'call-with-condition-handler, basically. |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3824 (defalias 'byte-compile-funarg-1-2 (byte-compile-funarg-n 1 2)) |
| 428 | 3825 |
|
4716
dca5bb2adff1
Don't cons with #'mapcar calls where the result is discarded,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4686
diff
changeset
|
3826 ;; XEmacs change; don't cons up the list if it's going to be immediately |
|
4743
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3827 ;; discarded. GNU give a warning in `byte-compile-normal-call' instead, and |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
3828 ;; only for #'mapcar. |
|
4719
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
3829 (defun byte-compile-maybe-mapc (form) |
|
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
3830 (and for-effect |
|
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
3831 (or (null (memq 'discarded-consing byte-compile-warnings)) |
|
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
3832 (byte-compile-warn |
|
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
3833 "Discarding the result of #'%s; maybe you meant #'mapc?" |
|
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
3834 (car form))) |
|
4995
8431b52e43b1
Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4885
diff
changeset
|
3835 (setq form (cons 'mapc (cdr form)))) |
|
4716
dca5bb2adff1
Don't cons with #'mapcar calls where the result is discarded,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4686
diff
changeset
|
3836 (byte-compile-funarg form)) |
|
dca5bb2adff1
Don't cons with #'mapcar calls where the result is discarded,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4686
diff
changeset
|
3837 |
|
dca5bb2adff1
Don't cons with #'mapcar calls where the result is discarded,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4686
diff
changeset
|
3838 (defun byte-compile-maplist (form) |
|
4719
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
3839 (and for-effect |
|
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
3840 (or (null (memq 'discarded-consing byte-compile-warnings)) |
|
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
3841 (byte-compile-warn |
|
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
3842 "Discarding the result of #'maplist; maybe you meant #'mapl?")) |
|
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
3843 (setq form (cons 'mapl (cdr form)))) |
|
4716
dca5bb2adff1
Don't cons with #'mapcar calls where the result is discarded,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4686
diff
changeset
|
3844 (byte-compile-funarg form)) |
|
dca5bb2adff1
Don't cons with #'mapcar calls where the result is discarded,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4686
diff
changeset
|
3845 |
|
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3846 ;; For when calls to #'sort or #'mapcar have more than two args, something |
|
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3847 ;; recent XEmacs can handle, but GNU and 21.4 can't. |
|
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3848 (defmacro byte-compile-maybe-add-* (complex max) |
|
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3849 `#'(lambda (form) |
|
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3850 (when (> (length (cdr form)) ,max) |
|
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3851 (when (memq 'callargs byte-compile-warnings) |
|
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3852 (byte-compile-warn |
|
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3853 "#'%s called with %d arguments, using #'%s instead" |
|
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3854 (car form) (length (cdr form)) ',complex)) |
|
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3855 (setq form (cons ',complex (cdr form)))) |
|
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3856 (funcall (or (get ',complex 'byte-compile) |
|
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3857 'byte-compile-normal-call) form))) |
|
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3858 |
|
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3859 (defalias 'byte-compile-mapcar (byte-compile-maybe-add-* mapcar* 2)) |
|
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3860 |
|
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3861 (defalias 'byte-compile-sort (byte-compile-maybe-add-* sort* 2)) |
|
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3862 |
|
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3863 (defalias 'byte-compile-fillarray (byte-compile-maybe-add-* fill 2)) |
|
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
3864 |
| 428 | 3865 ;; (function foo) must compile like 'foo, not like (symbol-function 'foo). |
| 3866 ;; Otherwise it will be incompatible with the interpreter, | |
| 3867 ;; and (funcall (function foo)) will lose with autoloads. | |
| 3868 | |
| 3869 (defun byte-compile-function-form (form) | |
|
5265
5663ae9a8989
Warn at compile time, error at runtime, with (quote X Y), (function X Y).
Aidan Kehoe <kehoea@parhasard.net>
parents:
5263
diff
changeset
|
3870 (if (cddr form) |
|
5663ae9a8989
Warn at compile time, error at runtime, with (quote X Y), (function X Y).
Aidan Kehoe <kehoea@parhasard.net>
parents:
5263
diff
changeset
|
3871 (byte-compile-normal-call |
|
5663ae9a8989
Warn at compile time, error at runtime, with (quote X Y), (function X Y).
Aidan Kehoe <kehoea@parhasard.net>
parents:
5263
diff
changeset
|
3872 `(signal 'wrong-number-of-arguments '(function ,(length (cdr form))))) |
|
5574
d4f334808463
Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5573
diff
changeset
|
3873 (byte-compile-constant (if (eq 'lambda (car-safe (nth 1 form))) |
|
d4f334808463
Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5573
diff
changeset
|
3874 (byte-compile-lambda (nth 1 form)) |
|
d4f334808463
Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5573
diff
changeset
|
3875 (nth 1 form))))) |
| 428 | 3876 |
| 3877 (defun byte-compile-insert (form) | |
| 3878 (cond ((null (cdr form)) | |
| 3879 (byte-compile-constant nil)) | |
| 3880 ((<= (length form) 256) | |
|
4783
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4775
diff
changeset
|
3881 (mapc 'byte-compile-form (cdr form)) |
| 428 | 3882 (if (cdr (cdr form)) |
| 3883 (byte-compile-out 'byte-insertN (length (cdr form))) | |
| 3884 (byte-compile-out 'byte-insert 0))) | |
|
5652
cc6f0266bc36
Avoid #'delq in core Lisp, for the sake of style, a very slightly smaller binary
Aidan Kehoe <kehoea@parhasard.net>
parents:
5651
diff
changeset
|
3885 ((some #'consp (cddr form)) |
| 428 | 3886 (byte-compile-normal-call form)) |
| 3887 ;; We can split it; there is no function call after inserting 1st arg. | |
| 3888 (t | |
| 3889 (while (setq form (cdr form)) | |
| 3890 (byte-compile-form (car form)) | |
| 3891 (byte-compile-out 'byte-insert 0) | |
| 3892 (when (cdr form) | |
| 3893 (byte-compile-discard)))))) | |
| 3894 | |
| 3895 ;; alas, the old (pre-19.12, and all existing versions of FSFmacs 19) | |
| 3896 ;; byte compiler will generate incorrect code for | |
| 3897 ;; (beginning-of-line nil buffer) because it buggily doesn't | |
| 3898 ;; check the number of arguments passed to beginning-of-line. | |
| 3899 | |
| 3900 (defun byte-compile-beginning-of-line (form) | |
| 3901 (let ((len (length form))) | |
| 3902 (cond ((> len 3) | |
| 3903 (byte-compile-subr-wrong-args form "0-2")) | |
|
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5358
diff
changeset
|
3904 ((or (eql len 3) (not (byte-compile-constp (nth 1 form)))) |
| 428 | 3905 (byte-compile-normal-call form)) |
| 3906 (t | |
| 3907 (byte-compile-form | |
| 3908 (list 'forward-line | |
| 3909 (if (integerp (setq form (or (eval (nth 1 form)) 1))) | |
| 3910 (1- form) | |
| 3911 (byte-compile-warn | |
| 3912 "Non-numeric arg to beginning-of-line: %s" form) | |
| 3913 (list '1- (list 'quote form)))) | |
| 3914 t) | |
| 3915 (byte-compile-constant nil))))) | |
| 3916 | |
| 3917 | |
| 3918 (byte-defop-compiler set) | |
| 3919 (byte-defop-compiler-1 setq) | |
| 3920 (byte-defop-compiler-1 set-default) | |
| 3921 (byte-defop-compiler-1 setq-default) | |
| 3922 | |
| 3923 (byte-defop-compiler-1 quote) | |
| 3924 (byte-defop-compiler-1 quote-form) | |
| 3925 | |
| 3926 (defun byte-compile-setq (form) | |
| 3927 (let ((args (cdr form)) var val) | |
| 3928 (if (null args) | |
| 3929 ;; (setq), with no arguments. | |
| 3930 (byte-compile-form nil for-effect) | |
| 3931 (while args | |
| 3932 (setq var (pop args)) | |
| 3933 (if (null args) | |
| 3934 ;; Odd number of args? Let `set' get the error. | |
| 3935 (byte-compile-form `(set ',var) for-effect) | |
| 3936 (setq val (pop args)) | |
|
5344
2a54dfbe434f
Don't quote keywords, they've been self-quoting for well over a decade.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5301
diff
changeset
|
3937 (byte-compile-form val) |
|
2a54dfbe434f
Don't quote keywords, they've been self-quoting for well over a decade.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5301
diff
changeset
|
3938 (unless (or args for-effect) |
|
2a54dfbe434f
Don't quote keywords, they've been self-quoting for well over a decade.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5301
diff
changeset
|
3939 (byte-compile-out 'byte-dup 0)) |
|
2a54dfbe434f
Don't quote keywords, they've been self-quoting for well over a decade.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5301
diff
changeset
|
3940 (byte-compile-variable-ref 'byte-varset var))))) |
| 428 | 3941 (setq for-effect nil)) |
| 3942 | |
| 3943 (defun byte-compile-set (form) | |
| 3944 ;; Compile (set 'foo x) as (setq foo x) for trivially better code and so | |
| 3945 ;; that we get applicable warnings. Compile everything else (including | |
| 3946 ;; malformed calls) like a normal 2-arg byte-coded function. | |
| 3947 (let ((symform (nth 1 form)) | |
| 3948 (valform (nth 2 form)) | |
| 3949 sym) | |
|
5344
2a54dfbe434f
Don't quote keywords, they've been self-quoting for well over a decade.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5301
diff
changeset
|
3950 (if (and (eql (length form) 3) |
|
2a54dfbe434f
Don't quote keywords, they've been self-quoting for well over a decade.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5301
diff
changeset
|
3951 (eql (safe-length symform) 2) |
| 428 | 3952 (eq (car symform) 'quote) |
|
5344
2a54dfbe434f
Don't quote keywords, they've been self-quoting for well over a decade.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5301
diff
changeset
|
3953 (symbolp (setq sym (car (cdr symform))))) |
| 428 | 3954 (byte-compile-setq `(setq ,sym ,valform)) |
| 3955 (byte-compile-two-args form)))) | |
| 3956 | |
| 3957 (defun byte-compile-setq-default (form) | |
| 3958 (let ((args (cdr form))) | |
| 3959 (if (null args) | |
| 3960 ;; (setq-default), with no arguments. | |
| 3961 (byte-compile-form nil for-effect) | |
| 3962 ;; emit multiple calls to `set-default' if necessary | |
| 3963 (while args | |
| 3964 (byte-compile-form | |
| 3965 ;; Odd number of args? Let `set-default' get the error. | |
| 3966 `(set-default ',(pop args) ,@(if args (list (pop args)) nil)) | |
| 3967 (if args t for-effect))))) | |
| 3968 (setq for-effect nil)) | |
| 3969 | |
| 3970 (defun byte-compile-set-default (form) | |
| 3971 (let* ((args (cdr form)) | |
| 3972 (nargs (length args)) | |
| 3973 (var (car args))) | |
|
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5358
diff
changeset
|
3974 (when (and (eql (safe-length var) 2) (eq (car var) 'quote)) |
| 428 | 3975 (let ((sym (nth 1 var))) |
| 3976 (cond | |
| 3977 ((not (symbolp sym)) | |
| 3978 (byte-compile-warn "Attempt to set-globally non-symbol %s" sym)) | |
| 3979 ((byte-compile-constant-symbol-p sym) | |
| 3980 (byte-compile-warn "Attempt to set-globally constant symbol %s" sym)) | |
| 3981 ((let ((cell (assq sym byte-compile-bound-variables))) | |
| 3982 (and cell | |
| 3983 (setcdr cell (logior (cdr cell) byte-compile-assigned-bit)) | |
| 3984 t))) | |
| 3985 ;; notice calls to set-default/setq-default for variables which | |
| 3986 ;; have not been declared with defvar/defconst. | |
| 3987 ((globally-boundp sym)) ; OK | |
| 3988 ((not (memq 'free-vars byte-compile-warnings))) ; warnings suppressed? | |
| 3989 ((memq sym byte-compile-free-assignments)) ; already warned about sym | |
| 3990 (t | |
| 3991 (byte-compile-warn "assignment to free variable %s" sym) | |
| 3992 (push sym byte-compile-free-assignments))))) | |
|
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5358
diff
changeset
|
3993 (if (eql nargs 2) |
| 428 | 3994 ;; now emit a normal call to set-default |
| 3995 (byte-compile-normal-call form) | |
| 3996 (byte-compile-subr-wrong-args form 2)))) | |
| 3997 | |
| 3998 | |
| 3999 (defun byte-compile-quote (form) | |
|
5265
5663ae9a8989
Warn at compile time, error at runtime, with (quote X Y), (function X Y).
Aidan Kehoe <kehoea@parhasard.net>
parents:
5263
diff
changeset
|
4000 (if (cddr form) |
|
5663ae9a8989
Warn at compile time, error at runtime, with (quote X Y), (function X Y).
Aidan Kehoe <kehoea@parhasard.net>
parents:
5263
diff
changeset
|
4001 (byte-compile-normal-call |
|
5663ae9a8989
Warn at compile time, error at runtime, with (quote X Y), (function X Y).
Aidan Kehoe <kehoea@parhasard.net>
parents:
5263
diff
changeset
|
4002 `(signal 'wrong-number-of-arguments '(quote ,(length (cdr form))))) |
|
5663ae9a8989
Warn at compile time, error at runtime, with (quote X Y), (function X Y).
Aidan Kehoe <kehoea@parhasard.net>
parents:
5263
diff
changeset
|
4003 (byte-compile-constant (car (cdr form))))) |
| 428 | 4004 |
| 4005 (defun byte-compile-quote-form (form) | |
|
5265
5663ae9a8989
Warn at compile time, error at runtime, with (quote X Y), (function X Y).
Aidan Kehoe <kehoea@parhasard.net>
parents:
5263
diff
changeset
|
4006 (if (cddr form) |
|
5663ae9a8989
Warn at compile time, error at runtime, with (quote X Y), (function X Y).
Aidan Kehoe <kehoea@parhasard.net>
parents:
5263
diff
changeset
|
4007 (byte-compile-normal-call |
|
5663ae9a8989
Warn at compile time, error at runtime, with (quote X Y), (function X Y).
Aidan Kehoe <kehoea@parhasard.net>
parents:
5263
diff
changeset
|
4008 `(signal 'wrong-number-of-arguments '(quote ,(length (cdr form))))) |
|
5663ae9a8989
Warn at compile time, error at runtime, with (quote X Y), (function X Y).
Aidan Kehoe <kehoea@parhasard.net>
parents:
5263
diff
changeset
|
4009 (byte-compile-constant (byte-compile-top-level (nth 1 form))))) |
| 428 | 4010 |
| 4011 ;;; control structures | |
| 4012 | |
| 4013 (defun byte-compile-body (body &optional for-effect) | |
| 4014 (while (cdr body) | |
| 4015 (byte-compile-form (car body) t) | |
| 4016 (setq body (cdr body))) | |
| 4017 (byte-compile-form (car body) for-effect)) | |
| 4018 | |
| 4019 (proclaim-inline byte-compile-body-do-effect) | |
| 4020 (defun byte-compile-body-do-effect (body) | |
| 4021 (byte-compile-body body for-effect) | |
| 4022 (setq for-effect nil)) | |
| 4023 | |
| 4024 (proclaim-inline byte-compile-form-do-effect) | |
| 4025 (defun byte-compile-form-do-effect (form) | |
| 4026 (byte-compile-form form for-effect) | |
| 4027 (setq for-effect nil)) | |
| 4028 | |
| 4029 (byte-defop-compiler-1 inline byte-compile-progn) | |
| 4030 (byte-defop-compiler-1 progn) | |
| 4031 (byte-defop-compiler-1 prog1) | |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4032 (byte-defop-compiler-1 multiple-value-prog1) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4033 (byte-defop-compiler-1 values) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4034 (byte-defop-compiler-1 values-list) |
| 428 | 4035 (byte-defop-compiler-1 prog2) |
| 4036 (byte-defop-compiler-1 if) | |
| 4037 (byte-defop-compiler-1 cond) | |
| 4038 (byte-defop-compiler-1 and) | |
| 4039 (byte-defop-compiler-1 or) | |
| 4040 (byte-defop-compiler-1 while) | |
| 4041 (byte-defop-compiler-1 funcall) | |
| 4042 (byte-defop-compiler-1 apply byte-compile-funarg) | |
|
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
4043 (byte-defop-compiler-1 mapcar byte-compile-mapcar) |
|
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
4044 (byte-defop-compiler-1 mapcar* byte-compile-maybe-mapc) |
| 428 | 4045 (byte-defop-compiler-1 mapatoms byte-compile-funarg) |
| 4046 (byte-defop-compiler-1 mapconcat byte-compile-funarg) | |
|
4743
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4047 (byte-defop-compiler-1 mapc byte-compile-funarg) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4048 (byte-defop-compiler-1 maphash byte-compile-funarg) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4049 (byte-defop-compiler-1 map-char-table byte-compile-funarg) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4050 (byte-defop-compiler-1 mapvector byte-compile-maybe-mapc) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4051 (byte-defop-compiler-1 mapc-internal byte-compile-funarg) |
|
4716
dca5bb2adff1
Don't cons with #'mapcar calls where the result is discarded,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4686
diff
changeset
|
4052 (byte-defop-compiler-1 maplist byte-compile-maplist) |
|
dca5bb2adff1
Don't cons with #'mapcar calls where the result is discarded,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4686
diff
changeset
|
4053 (byte-defop-compiler-1 mapl byte-compile-funarg) |
|
dca5bb2adff1
Don't cons with #'mapcar calls where the result is discarded,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4686
diff
changeset
|
4054 (byte-defop-compiler-1 mapcan byte-compile-funarg) |
|
dca5bb2adff1
Don't cons with #'mapcar calls where the result is discarded,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4686
diff
changeset
|
4055 (byte-defop-compiler-1 mapcon byte-compile-funarg) |
|
4719
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
4056 (byte-defop-compiler-1 map-database byte-compile-funarg) |
|
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
4057 (byte-defop-compiler-1 map-extent-children byte-compile-funarg) |
|
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
4058 (byte-defop-compiler-1 map-extents byte-compile-funarg) |
|
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
4059 (byte-defop-compiler-1 map-plist byte-compile-funarg) |
|
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
4060 (byte-defop-compiler-1 map-range-table byte-compile-funarg) |
|
bd51ab22afa8
Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4716
diff
changeset
|
4061 (byte-defop-compiler-1 map-syntax-table byte-compile-funarg) |
|
4743
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4062 |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4063 (byte-defop-compiler-1 remove-if byte-compile-funarg) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4064 (byte-defop-compiler-1 remove-if-not byte-compile-funarg) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4065 (byte-defop-compiler-1 delete-if byte-compile-funarg) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4066 (byte-defop-compiler-1 delete-if-not byte-compile-funarg) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4067 (byte-defop-compiler-1 find-if byte-compile-funarg) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4068 (byte-defop-compiler-1 find-if-not byte-compile-funarg) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4069 (byte-defop-compiler-1 position-if byte-compile-funarg) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4070 (byte-defop-compiler-1 position-if-not byte-compile-funarg) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4071 (byte-defop-compiler-1 count-if byte-compile-funarg) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4072 (byte-defop-compiler-1 count-if-not byte-compile-funarg) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4073 (byte-defop-compiler-1 member-if byte-compile-funarg) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4074 (byte-defop-compiler-1 member-if-not byte-compile-funarg) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4075 (byte-defop-compiler-1 assoc-if byte-compile-funarg) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4076 (byte-defop-compiler-1 assoc-if-not byte-compile-funarg) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4077 (byte-defop-compiler-1 rassoc-if byte-compile-funarg) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4078 (byte-defop-compiler-1 rassoc-if-not byte-compile-funarg) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4079 (byte-defop-compiler-1 reduce byte-compile-funarg) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4080 (byte-defop-compiler-1 some byte-compile-funarg) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4081 (byte-defop-compiler-1 every byte-compile-funarg) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4082 (byte-defop-compiler-1 notany byte-compile-funarg) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4083 (byte-defop-compiler-1 notevery byte-compile-funarg) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4084 |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4085 (byte-defop-compiler-1 walk-windows byte-compile-funarg) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4086 (byte-defop-compiler-1 get-window-with-predicate byte-compile-funarg) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4087 |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4088 (byte-defop-compiler-1 map byte-compile-funarg-2) |
|
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
4089 (byte-defop-compiler-1 map-into byte-compile-funarg-2) |
|
4743
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4090 (byte-defop-compiler-1 apropos-internal byte-compile-funarg-2) |
|
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
4091 (byte-defop-compiler-1 sort byte-compile-sort) |
|
4743
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4092 (byte-defop-compiler-1 sort* byte-compile-funarg-2) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4093 (byte-defop-compiler-1 stable-sort byte-compile-funarg-2) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4094 (byte-defop-compiler-1 substitute-if byte-compile-funarg-2) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4095 (byte-defop-compiler-1 substitute-if-not byte-compile-funarg-2) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4096 (byte-defop-compiler-1 nsubstitute-if byte-compile-funarg-2) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4097 (byte-defop-compiler-1 nsubstitute-if-not byte-compile-funarg-2) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4098 (byte-defop-compiler-1 subst-if byte-compile-funarg-2) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4099 (byte-defop-compiler-1 subst-if-not byte-compile-funarg-2) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4100 (byte-defop-compiler-1 nsubst-if byte-compile-funarg-2) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4101 (byte-defop-compiler-1 nsubst-if-not byte-compile-funarg-2) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4102 |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4103 (byte-defop-compiler-1 merge byte-compile-funarg-4) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4104 |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4105 (byte-defop-compiler-1 call-with-condition-handler byte-compile-funarg-1-2) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4106 (byte-defop-compiler-1 mapcar-extents byte-compile-funarg-1-2) |
|
776bbf454f3a
Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4719
diff
changeset
|
4107 |
| 428 | 4108 (byte-defop-compiler-1 let) |
| 4109 (byte-defop-compiler-1 let*) | |
| 4110 | |
|
4885
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4111 (byte-defop-compiler-1 integerp) |
|
5301
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4112 (byte-defop-compiler-1 eql) |
|
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5106
diff
changeset
|
4113 (byte-defop-compiler-1 fillarray) |
|
5753
dbd8305e13cb
Warn about non-string non-integer ARG to #'gensym, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5723
diff
changeset
|
4114 (byte-defop-compiler-1 gensym) |
|
4885
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4115 |
| 428 | 4116 (defun byte-compile-progn (form) |
| 4117 (byte-compile-body-do-effect (cdr form))) | |
| 4118 | |
| 4119 (defun byte-compile-prog1 (form) | |
| 4120 (setq form (cdr form)) | |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4121 ;; #'prog1 never returns multiple values: |
|
4686
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
4122 (byte-compile-form-do-effect `(or ,(pop form) nil)) |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4123 (byte-compile-body form t)) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4124 |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4125 (defun byte-compile-multiple-value-prog1 (form) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4126 (setq form (cdr form)) |
| 428 | 4127 (byte-compile-form-do-effect (pop form)) |
| 4128 (byte-compile-body form t)) | |
| 4129 | |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4130 (defun byte-compile-values (form) |
|
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5358
diff
changeset
|
4131 (if (eql 2 (length form)) |
|
4686
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
4132 (if (byte-compile-constp (second form)) |
|
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
4133 (byte-compile-form-do-effect (second form)) |
|
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
4134 ;; #'or compiles to bytecode, #'values doesn't: |
|
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
4135 (byte-compile-form-do-effect `(or ,(second form) nil))) |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4136 (byte-compile-normal-call form))) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4137 |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4138 (defun byte-compile-values-list (form) |
|
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5358
diff
changeset
|
4139 (if (and (eql 2 (length form)) |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4140 (or (null (second form)) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4141 (and (consp (second form)) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4142 (eq (car (second form)) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4143 'quote) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4144 (not (symbolp (car-safe (cdr (second form)))))))) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4145 (byte-compile-form-do-effect (car-safe (cdr (second form)))) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4146 (byte-compile-normal-call form))) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4147 |
| 428 | 4148 (defun byte-compile-prog2 (form) |
| 4149 (setq form (cdr form)) | |
| 4150 (byte-compile-form (pop form) t) | |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4151 ;; #'prog2 never returns multiple values: |
|
4686
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4683
diff
changeset
|
4152 (byte-compile-form-do-effect `(or ,(pop form) nil)) |
| 428 | 4153 (byte-compile-body form t)) |
| 4154 | |
| 4155 (defmacro byte-compile-goto-if (cond discard tag) | |
| 4156 `(byte-compile-goto | |
| 4157 (if ,cond | |
| 4158 (if ,discard 'byte-goto-if-not-nil 'byte-goto-if-not-nil-else-pop) | |
| 4159 (if ,discard 'byte-goto-if-nil 'byte-goto-if-nil-else-pop)) | |
| 4160 ,tag)) | |
| 4161 | |
| 4162 (defun byte-compile-if (form) | |
| 4163 (byte-compile-form (car (cdr form))) | |
|
5723
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4164 ;; Check whether we have `(if (fboundp ...' or `(if (boundp ...' |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4165 ;; and avoid warnings about the relevent symbols in the consequent. |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4166 (let* ((clause (nth 1 form)) |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4167 (fbound (if (eq 'fboundp (car-safe clause)) |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4168 (and (eq 'quote (car-safe (nth 1 clause))) |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4169 ;; Ignore if the symbol is already on the |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4170 ;; unresolved list. |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4171 (not (assq |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4172 (nth 1 (nth 1 clause)) ; the relevant symbol |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4173 byte-compile-unresolved-functions)) |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4174 (nth 1 (nth 1 clause))))) |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4175 (bound (if (eq 'boundp (car-safe clause)) |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4176 (and (eq 'quote (car-safe (nth 1 clause))) |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4177 (nth 1 (nth 1 clause))))) |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4178 (donetag (byte-compile-make-tag))) |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4179 (if (null (nthcdr 3 form)) |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4180 ;; No else-forms |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4181 (progn |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4182 (byte-compile-goto-if nil for-effect donetag) |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4183 ;; Maybe add to the bound list. |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4184 (let ((byte-compile-bound-variables |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4185 (if bound |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4186 (cons bound byte-compile-bound-variables) |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4187 byte-compile-bound-variables))) |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4188 (byte-compile-form (nth 2 form) for-effect)) |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4189 ;; Maybe remove the function symbol from the unresolved list. |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4190 (if fbound |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4191 (setq byte-compile-unresolved-functions |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4192 (delq (assq fbound byte-compile-unresolved-functions) |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4193 byte-compile-unresolved-functions))) |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4194 (byte-compile-out-tag donetag)) |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4195 (let ((elsetag (byte-compile-make-tag))) |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4196 (byte-compile-goto 'byte-goto-if-nil elsetag) |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4197 ;; As above for the first form. |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4198 (let ((byte-compile-bound-variables |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4199 (if bound |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4200 (cons bound byte-compile-bound-variables) |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4201 byte-compile-bound-variables))) |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4202 (byte-compile-form (nth 2 form) for-effect)) |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4203 (if fbound |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4204 (setq byte-compile-unresolved-functions |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4205 (delq (assq fbound byte-compile-unresolved-functions) |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4206 byte-compile-unresolved-functions))) |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4207 (byte-compile-goto 'byte-goto donetag) |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4208 (byte-compile-out-tag elsetag) |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4209 (byte-compile-body (cdr (cdr (cdr form))) for-effect) |
|
b3a2bff825c8
Make f?boundp less necessary.
Mike Sperber <sperber@deinprogramm.de>
parents:
5656
diff
changeset
|
4210 (byte-compile-out-tag donetag)))) |
| 428 | 4211 (setq for-effect nil)) |
| 4212 | |
| 4213 (defun byte-compile-cond (clauses) | |
| 4214 (let ((donetag (byte-compile-make-tag)) | |
| 4215 nexttag clause) | |
| 4216 (while (setq clauses (cdr clauses)) | |
| 4217 (setq clause (car clauses)) | |
| 4218 (cond ((or (eq (car clause) t) | |
| 4219 (and (eq (car-safe (car clause)) 'quote) | |
| 4220 (car-safe (cdr-safe (car clause))))) | |
| 4221 ;; Unconditional clause | |
| 4222 (setq clause (cons t clause) | |
| 4223 clauses nil)) | |
| 4224 ((cdr clauses) | |
| 4225 (byte-compile-form (car clause)) | |
| 4226 (if (null (cdr clause)) | |
| 4227 ;; First clause is a singleton. | |
| 4228 (byte-compile-goto-if t for-effect donetag) | |
| 4229 (setq nexttag (byte-compile-make-tag)) | |
| 4230 (byte-compile-goto 'byte-goto-if-nil nexttag) | |
| 4231 (byte-compile-body (cdr clause) for-effect) | |
| 4232 (byte-compile-goto 'byte-goto donetag) | |
| 4233 (byte-compile-out-tag nexttag))))) | |
| 4234 ;; Last clause | |
| 4235 (and (cdr clause) (not (eq (car clause) t)) | |
| 4236 (progn (byte-compile-form (car clause)) | |
| 4237 (byte-compile-goto-if nil for-effect donetag) | |
| 4238 (setq clause (cdr clause)))) | |
| 4239 (byte-compile-body-do-effect clause) | |
| 4240 (byte-compile-out-tag donetag))) | |
| 4241 | |
| 4242 (defun byte-compile-and (form) | |
| 4243 (let ((failtag (byte-compile-make-tag)) | |
| 4244 (args (cdr form))) | |
| 4245 (if (null args) | |
| 4246 (byte-compile-form-do-effect t) | |
| 4247 (while (cdr args) | |
| 4248 (byte-compile-form (car args)) | |
| 4249 (byte-compile-goto-if nil for-effect failtag) | |
| 4250 (setq args (cdr args))) | |
| 4251 (byte-compile-form-do-effect (car args)) | |
| 4252 (byte-compile-out-tag failtag)))) | |
| 4253 | |
| 4254 (defun byte-compile-or (form) | |
| 4255 (let ((wintag (byte-compile-make-tag)) | |
| 4256 (args (cdr form))) | |
| 4257 (if (null args) | |
| 4258 (byte-compile-form-do-effect nil) | |
| 4259 (while (cdr args) | |
| 4260 (byte-compile-form (car args)) | |
| 4261 (byte-compile-goto-if t for-effect wintag) | |
| 4262 (setq args (cdr args))) | |
| 4263 (byte-compile-form-do-effect (car args)) | |
| 4264 (byte-compile-out-tag wintag)))) | |
| 4265 | |
| 4266 (defun byte-compile-while (form) | |
| 4267 (let ((endtag (byte-compile-make-tag)) | |
| 4268 (looptag (byte-compile-make-tag))) | |
| 4269 (byte-compile-out-tag looptag) | |
| 4270 (byte-compile-form (car (cdr form))) | |
| 4271 (byte-compile-goto-if nil for-effect endtag) | |
| 4272 (byte-compile-body (cdr (cdr form)) t) | |
| 4273 (byte-compile-goto 'byte-goto looptag) | |
| 4274 (byte-compile-out-tag endtag) | |
| 4275 (setq for-effect nil))) | |
| 4276 | |
| 4277 (defun byte-compile-funcall (form) | |
|
5566
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
4278 (if (and (memq 'callargs byte-compile-warnings) |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
4279 (byte-compile-constp (second form))) |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
4280 (byte-compile-callargs-warn (cons (cl-const-expr-val (second form)) |
|
4654c01af32b
Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5562
diff
changeset
|
4281 (nthcdr 2 form)))) |
|
5656
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
4282 (mapc 'byte-compile-form (cdr form)) |
|
e9c3fe82127d
Co-operate with the byte-optimizer in the bytecomp.el labels implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5652
diff
changeset
|
4283 (byte-compile-out 'byte-call (length (cdr (cdr form))))) |
| 428 | 4284 |
| 4285 (defun byte-compile-let (form) | |
| 4286 ;; First compute the binding values in the old scope. | |
| 4287 (let ((varlist (car (cdr form)))) | |
| 4288 (while varlist | |
| 4289 (if (consp (car varlist)) | |
| 4290 (byte-compile-form (car (cdr (car varlist)))) | |
| 4291 (byte-compile-push-constant nil)) | |
| 4292 (setq varlist (cdr varlist)))) | |
| 4293 (let ((byte-compile-bound-variables | |
| 4294 (cons 'new-scope byte-compile-bound-variables)) | |
| 4295 (varlist (reverse (car (cdr form)))) | |
| 4296 (extra-flags | |
| 4297 ;; If this let is of the form (let (...) (byte-code ...)) | |
| 4298 ;; then assume that it is the result of a transformation of | |
| 4299 ;; ((lambda (...) (byte-code ... )) ...) and thus compile | |
| 4300 ;; the variable bindings as if they were arglist bindings | |
| 4301 ;; (which matters for what warnings.) | |
| 4302 (if (eq 'byte-code (car-safe (nth 2 form))) | |
| 4303 byte-compile-arglist-bit | |
| 4304 nil))) | |
| 4305 (while varlist | |
| 4306 (byte-compile-variable-ref 'byte-varbind | |
| 4307 (if (consp (car varlist)) | |
| 4308 (car (car varlist)) | |
| 4309 (car varlist)) | |
| 4310 extra-flags) | |
| 4311 (setq varlist (cdr varlist))) | |
| 4312 (byte-compile-body-do-effect (cdr (cdr form))) | |
| 4313 (if (memq 'unused-vars byte-compile-warnings) | |
| 4314 ;; done compiling in this scope, warn now. | |
| 4315 (byte-compile-warn-about-unused-variables)) | |
| 4316 (byte-compile-out 'byte-unbind (length (car (cdr form)))))) | |
| 4317 | |
| 4318 (defun byte-compile-let* (form) | |
| 4319 (let ((byte-compile-bound-variables | |
| 4320 (cons 'new-scope byte-compile-bound-variables)) | |
| 4321 (varlist (copy-sequence (car (cdr form))))) | |
| 4322 (while varlist | |
| 4323 (if (atom (car varlist)) | |
| 4324 (byte-compile-push-constant nil) | |
| 4325 (byte-compile-form (car (cdr (car varlist)))) | |
| 4326 (setcar varlist (car (car varlist)))) | |
| 4327 (byte-compile-variable-ref 'byte-varbind (car varlist)) | |
| 4328 (setq varlist (cdr varlist))) | |
| 4329 (byte-compile-body-do-effect (cdr (cdr form))) | |
| 4330 (if (memq 'unused-vars byte-compile-warnings) | |
| 4331 ;; done compiling in this scope, warn now. | |
| 4332 (byte-compile-warn-about-unused-variables)) | |
| 4333 (byte-compile-out 'byte-unbind (length (car (cdr form)))))) | |
| 4334 | |
|
4885
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4335 ;; We've renamed the integerp bytecode to fixnump, and changed its semantics |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4336 ;; accordingly. This means #'integerp itself can't be as fast as it used to |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4337 ;; be, since it no longer has a bytecode to itself. As it happens, though, |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4338 ;; most of the non-core calls to #'integerp are in contexts where it is |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4339 ;; either going to receive a fixnum, or something non-numeric entirely; the |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4340 ;; contexts where it needs to distinguish between an integer and a float are |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4341 ;; very rare. So, we can have (integerp X) compile to: |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4342 ;; |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4343 ;; (or (fixnump X) (and (numberp X) (funcall #'integerp X))) |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4344 ;; |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4345 ;; without the multiple evaluation of X, and where #'fixnump and #'numberp |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4346 ;; both have bytecodes. We ignore for-effect, because byte-optimize.el will |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4347 ;; delete this call in its presence. |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4348 ;; |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4349 ;; This approach is byte-code compatible with 21.4 and with earlier 21.5 |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4350 ;; (except that earlier 21.5 with bignum support will confuse Bfixnump and |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4351 ;; Bintegerp; which it did in dealing with byte-compiled code from 21.4 |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4352 ;; anyway). |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4353 |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4354 (defun byte-compile-integerp (form) |
|
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5358
diff
changeset
|
4355 (if (not (eql (length form) 2)) |
|
4885
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4356 (byte-compile-subr-wrong-args form 1) |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4357 (let ((donetag (byte-compile-make-tag)) |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4358 (wintag (byte-compile-make-tag)) |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4359 (failtag (byte-compile-make-tag))) |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4360 (byte-compile-constant 'integerp) |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4361 (byte-compile-form (second form)) |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4362 (byte-compile-out 'byte-dup 0) |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4363 (byte-compile-out 'byte-fixnump 0) |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4364 (byte-compile-goto 'byte-goto-if-not-nil wintag) |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4365 (byte-compile-out 'byte-dup 0) |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4366 (byte-compile-out 'byte-numberp 0) |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4367 (byte-compile-goto 'byte-goto-if-nil failtag) |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4368 (byte-compile-out 'byte-call 1) |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4369 ;; At this point, the only thing from this function remaining on the |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4370 ;; stack is the return value of the called #'integerp, which reflects |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4371 ;; exactly what we want. Go directly to donetag, do not discard |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4372 ;; anything. |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4373 (byte-compile-goto 'byte-goto donetag) |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4374 (byte-compile-out-tag failtag) |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4375 (byte-compile-discard) |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4376 (byte-compile-discard) |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4377 (byte-compile-constant nil) |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4378 (byte-compile-goto 'byte-goto donetag) |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4379 (byte-compile-out-tag wintag) |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4380 (byte-compile-discard) |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4381 (byte-compile-discard) |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4382 (byte-compile-constant t) |
|
6772ce4d982b
Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
4383 (byte-compile-out-tag donetag)))) |
| 428 | 4384 |
|
5301
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4385 (defun byte-compile-eql (form) |
|
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4386 (if (eql 3 (length form)) |
|
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4387 (let ((donetag (byte-compile-make-tag)) |
|
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4388 (eqtag (byte-compile-make-tag))) |
|
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4389 (mapc 'byte-compile-form (cdr form)) |
|
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4390 (byte-compile-out 'byte-dup 0) |
|
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4391 (byte-compile-out 'byte-numberp 0) |
|
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4392 (byte-compile-goto 'byte-goto-if-nil eqtag) |
|
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4393 (byte-compile-out 'byte-dup 0) |
|
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4394 (byte-compile-out 'byte-fixnump 0) |
|
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4395 (byte-compile-goto 'byte-goto-if-not-nil eqtag) |
|
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4396 (byte-compile-out 'byte-equal 0) |
|
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4397 (byte-compile-goto 'byte-goto donetag) |
|
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4398 (byte-compile-out-tag eqtag) |
|
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4399 (byte-compile-out 'byte-eq 0) |
|
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4400 (byte-compile-out-tag donetag)) |
|
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4401 (byte-compile-subr-wrong-args form 2))) |
|
ec05a30f7148
Fix a bytecomp.el bug compiling #'eql, which was masked by cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5294
diff
changeset
|
4402 |
|
5753
dbd8305e13cb
Warn about non-string non-integer ARG to #'gensym, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5723
diff
changeset
|
4403 (defun byte-compile-gensym (form) |
|
dbd8305e13cb
Warn about non-string non-integer ARG to #'gensym, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5723
diff
changeset
|
4404 (when for-effect |
|
dbd8305e13cb
Warn about non-string non-integer ARG to #'gensym, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5723
diff
changeset
|
4405 (byte-compile-warn "%s: %S: called for-effect, unlikely to be useful" |
|
dbd8305e13cb
Warn about non-string non-integer ARG to #'gensym, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5723
diff
changeset
|
4406 (car form) form)) |
|
dbd8305e13cb
Warn about non-string non-integer ARG to #'gensym, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5723
diff
changeset
|
4407 (when (and (cdr form) (cl-const-expr-p (nth 1 form)) |
|
dbd8305e13cb
Warn about non-string non-integer ARG to #'gensym, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5723
diff
changeset
|
4408 (not (typep (cl-const-expr-val (nth 1 form) '#:not-constant) |
|
dbd8305e13cb
Warn about non-string non-integer ARG to #'gensym, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5723
diff
changeset
|
4409 '(or string integer)))) |
|
dbd8305e13cb
Warn about non-string non-integer ARG to #'gensym, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5723
diff
changeset
|
4410 (byte-compile-warn "%s: %s: only strings and integers valid for ARG" |
|
dbd8305e13cb
Warn about non-string non-integer ARG to #'gensym, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5723
diff
changeset
|
4411 (car form) |
|
dbd8305e13cb
Warn about non-string non-integer ARG to #'gensym, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5723
diff
changeset
|
4412 (let ((print-readably t)) |
|
dbd8305e13cb
Warn about non-string non-integer ARG to #'gensym, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5723
diff
changeset
|
4413 (prin1-to-string (nth 1 form))))) |
|
dbd8305e13cb
Warn about non-string non-integer ARG to #'gensym, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5723
diff
changeset
|
4414 (byte-compile-normal-call form)) |
|
dbd8305e13cb
Warn about non-string non-integer ARG to #'gensym, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5723
diff
changeset
|
4415 |
| 428 | 4416 ;;(byte-defop-compiler-1 /= byte-compile-negated) |
| 4417 (byte-defop-compiler-1 atom byte-compile-negated) | |
| 4418 (byte-defop-compiler-1 nlistp byte-compile-negated) | |
| 4419 | |
| 4420 ;;(put '/= 'byte-compile-negated-op '=) | |
| 4421 (put 'atom 'byte-compile-negated-op 'consp) | |
| 4422 (put 'nlistp 'byte-compile-negated-op 'listp) | |
| 4423 | |
| 4424 (defun byte-compile-negated (form) | |
| 4425 (byte-compile-form-do-effect (byte-compile-negation-optimizer form))) | |
| 4426 | |
| 4427 ;; Even when optimization is off, atom is optimized to (not (consp ...)). | |
| 4428 (defun byte-compile-negation-optimizer (form) | |
| 4429 ;; an optimizer for forms where <form1> is less efficient than (not <form2>) | |
| 4430 (list 'not | |
| 4431 (cons (or (get (car form) 'byte-compile-negated-op) | |
| 4432 (error | |
| 4433 "Compiler error: `%s' has no `byte-compile-negated-op' property" | |
| 4434 (car form))) | |
| 4435 (cdr form)))) | |
| 4436 | |
|
4905
755ae5b97edb
Change "special form" to "special operator" in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4885
diff
changeset
|
4437 ;;; other tricky macro-like special-operators |
| 428 | 4438 |
| 4439 (byte-defop-compiler-1 catch) | |
| 4440 (byte-defop-compiler-1 unwind-protect) | |
| 4441 (byte-defop-compiler-1 condition-case) | |
| 4442 (byte-defop-compiler-1 save-excursion) | |
| 4443 (byte-defop-compiler-1 save-current-buffer) | |
| 4444 (byte-defop-compiler-1 save-restriction) | |
| 4445 (byte-defop-compiler-1 with-output-to-temp-buffer) | |
| 4446 ;; no track-mouse. | |
| 4447 | |
|
5356
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4448 (defvar byte-compile-active-blocks nil) |
|
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4449 |
| 428 | 4450 (defun byte-compile-catch (form) |
|
5356
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4451 "Byte-compile and return a `catch' from. |
|
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4452 |
|
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4453 If FORM is the result of macroexpanding a `block' form (the TAG argument is |
|
5376
4b529b940e2e
Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5374
diff
changeset
|
4454 a quoted symbol with a `cl-block-name' property) and there is no |
|
5356
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4455 corresponding `return-from' within the block--or equivalently, it was |
|
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4456 optimized away--just byte compile and return the BODY." |
|
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4457 (let* ((symbol (car-safe (cdr-safe (nth 1 form)))) |
|
5376
4b529b940e2e
Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5374
diff
changeset
|
4458 (not-present '#:not-present) |
|
5642
5bda701e9e7c
Be more careful about non-quoted-symbol TAGs, #'byte-compile-catch
Aidan Kehoe <kehoea@parhasard.net>
parents:
5637
diff
changeset
|
4459 (block (cond ((null symbol) not-present) |
|
5bda701e9e7c
Be more careful about non-quoted-symbol TAGs, #'byte-compile-catch
Aidan Kehoe <kehoea@parhasard.net>
parents:
5637
diff
changeset
|
4460 ((not (symbolp symbol)) not-present) |
|
5bda701e9e7c
Be more careful about non-quoted-symbol TAGs, #'byte-compile-catch
Aidan Kehoe <kehoea@parhasard.net>
parents:
5637
diff
changeset
|
4461 (t (get symbol 'cl-block-name not-present)))) |
|
5376
4b529b940e2e
Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5374
diff
changeset
|
4462 (elt (and (not (eq block not-present)) (list block))) |
|
5356
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4463 (byte-compile-active-blocks |
|
5376
4b529b940e2e
Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5374
diff
changeset
|
4464 (if elt |
|
5356
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4465 (cons elt byte-compile-active-blocks) |
|
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4466 byte-compile-active-blocks)) |
|
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4467 (body |
|
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4468 (byte-compile-top-level (cons 'progn (cddr form)) |
|
5377
eac2e6bd5b2c
Correct some minor problems in my last change.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5376
diff
changeset
|
4469 (and (not elt) for-effect)))) |
|
5376
4b529b940e2e
Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5374
diff
changeset
|
4470 (if (and elt (not (cdr elt))) |
|
5356
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4471 ;; A lexical block without any contained return-from clauses: |
|
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4472 (byte-compile-form body) |
|
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4473 ;; A normal catch call, or a lexical block with a contained |
|
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4474 ;; return-from clause. |
|
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4475 (byte-compile-form (car (cdr form))) |
|
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4476 (byte-compile-push-constant body) |
|
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4477 (byte-compile-out 'byte-catch 0)))) |
|
5353
38e24b8be4ea
Improve the lexical scoping in #'block, #'return-from.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5344
diff
changeset
|
4478 |
| 428 | 4479 (defun byte-compile-unwind-protect (form) |
| 4480 (byte-compile-push-constant | |
| 4481 (byte-compile-top-level-body (cdr (cdr form)) t)) | |
| 4482 (byte-compile-out 'byte-unwind-protect 0) | |
| 4483 (byte-compile-form-do-effect (car (cdr form))) | |
| 4484 (byte-compile-out 'byte-unbind 1)) | |
| 4485 | |
| 4486 ;;(defun byte-compile-track-mouse (form) | |
| 4487 ;; (byte-compile-form | |
| 4488 ;; (list | |
| 4489 ;; 'funcall | |
| 4490 ;; (list 'quote | |
| 4491 ;; (list 'lambda nil | |
| 4492 ;; (cons 'track-mouse | |
| 4493 ;; (byte-compile-top-level-body (cdr form)))))))) | |
| 4494 | |
| 4495 (defun byte-compile-condition-case (form) | |
| 4496 (let* ((var (nth 1 form)) | |
| 4497 (byte-compile-bound-variables | |
| 4498 (if var | |
| 4499 (cons (cons var 0) | |
| 4500 (cons 'new-scope byte-compile-bound-variables)) | |
| 4501 (cons 'new-scope byte-compile-bound-variables)))) | |
| 4502 (or (symbolp var) | |
| 4503 (byte-compile-warn | |
| 4504 "%s is not a variable-name or nil (in condition-case)" | |
| 4505 (prin1-to-string var))) | |
| 4506 (byte-compile-push-constant var) | |
| 4507 (byte-compile-push-constant (byte-compile-top-level | |
| 4508 (nth 2 form) for-effect)) | |
| 4509 (let ((clauses (cdr (cdr (cdr form)))) | |
| 4510 compiled-clauses) | |
| 4511 (while clauses | |
| 4512 (let* ((clause (car clauses)) | |
| 4513 (condition (car clause))) | |
| 4514 (cond ((not (or (symbolp condition) | |
| 4515 (and (listp condition) | |
| 4516 (let ((syms condition) (ok t)) | |
| 4517 (while syms | |
| 4518 (if (not (symbolp (car syms))) | |
| 4519 (setq ok nil)) | |
| 4520 (setq syms (cdr syms))) | |
| 4521 ok)))) | |
| 4522 (byte-compile-warn | |
| 4523 "%s is not a symbol naming a condition or a list of such (in condition-case)" | |
| 4524 (prin1-to-string condition))) | |
| 4525 ;; ((not (or (eq condition 't) | |
| 4526 ;; (and (stringp (get condition 'error-message)) | |
| 4527 ;; (consp (get condition 'error-conditions))))) | |
| 4528 ;; (byte-compile-warn | |
| 4529 ;; "%s is not a known condition name (in condition-case)" | |
| 4530 ;; condition)) | |
| 4531 ) | |
| 4532 (setq compiled-clauses | |
| 4533 (cons (cons condition | |
| 4534 (byte-compile-top-level-body | |
| 4535 (cdr clause) for-effect)) | |
| 4536 compiled-clauses))) | |
| 4537 (setq clauses (cdr clauses))) | |
| 4538 (byte-compile-push-constant (nreverse compiled-clauses))) | |
| 4539 (if (memq 'unused-vars byte-compile-warnings) | |
| 4540 ;; done compiling in this scope, warn now. | |
| 4541 (byte-compile-warn-about-unused-variables)) | |
| 4542 (byte-compile-out 'byte-condition-case 0))) | |
| 4543 | |
| 4544 | |
| 4545 (defun byte-compile-save-excursion (form) | |
| 4546 (byte-compile-out 'byte-save-excursion 0) | |
| 4547 (byte-compile-body-do-effect (cdr form)) | |
| 4548 (byte-compile-out 'byte-unbind 1)) | |
| 4549 | |
| 4550 (defun byte-compile-save-restriction (form) | |
| 4551 (byte-compile-out 'byte-save-restriction 0) | |
| 4552 (byte-compile-body-do-effect (cdr form)) | |
| 4553 (byte-compile-out 'byte-unbind 1)) | |
| 4554 | |
| 4555 (defun byte-compile-save-current-buffer (form) | |
|
5503
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
4556 (byte-compile-out 'byte-save-current-buffer 0) |
|
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
4557 (byte-compile-body-do-effect (cdr form)) |
|
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
4558 (byte-compile-out 'byte-unbind 1)) |
| 428 | 4559 |
| 4560 (defun byte-compile-with-output-to-temp-buffer (form) | |
| 4561 (byte-compile-form (car (cdr form))) | |
| 4562 (byte-compile-out 'byte-temp-output-buffer-setup 0) | |
| 4563 (byte-compile-body (cdr (cdr form))) | |
| 4564 (byte-compile-out 'byte-temp-output-buffer-show 0)) | |
|
5391
f9dc75bdbdc4
Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5377
diff
changeset
|
4565 |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4566 (defun byte-compile-multiple-value-call (form) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4567 (if (< (length form) 2) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4568 (progn |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4569 (byte-compile-warn-wrong-args form 1) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4570 (byte-compile-normal-call |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4571 `(signal 'wrong-number-of-arguments '(,(car form) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4572 ,(length (cdr form)))))) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4573 (setq form (cdr form)) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4574 (byte-compile-form (car form)) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4575 (byte-compile-push-constant 0) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4576 (byte-compile-variable-ref 'byte-varref 'multiple-values-limit) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4577 ;; bind-multiple-value-limits leaves two existing values on the stack, |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4578 ;; and pushes a new value, the specpdl_depth() at the time it was |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4579 ;; called. |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4580 (byte-compile-out 'byte-bind-multiple-value-limits 0) |
|
4783
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4775
diff
changeset
|
4581 (mapc 'byte-compile-form (cdr form)) |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4582 ;; Most of the other code puts this sort of value in the program stream, |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4583 ;; not pushing it on the stack. |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4584 (byte-compile-push-constant (+ 3 (length form))) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4585 (byte-compile-out 'byte-multiple-value-call (+ 3 (length form))) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4586 (pushnew '(subrp (symbol-function 'multiple-value-call)) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4587 byte-compile-checks-on-load |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4588 :test #'equal))) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4589 |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4590 (defun byte-compile-multiple-value-list-internal (form) |
|
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5358
diff
changeset
|
4591 (if (not (eql 4 (length form))) |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4592 (progn |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4593 (byte-compile-warn-wrong-args form 3) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4594 (byte-compile-normal-call |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4595 `(signal 'wrong-number-of-arguments '(,(car form) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4596 ,(length (cdr form)))))) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4597 (byte-compile-form (nth 1 form)) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4598 (byte-compile-form (nth 2 form)) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4599 (byte-compile-out 'byte-bind-multiple-value-limits 0) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4600 (byte-compile-form (nth 3 form)) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4601 (byte-compile-out (get (car form) 'byte-opcode) 0) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4602 (pushnew '(subrp (symbol-function 'multiple-value-call)) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4603 byte-compile-checks-on-load |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4604 :test #'equal))) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4605 |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4606 (defun byte-compile-throw (form) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4607 ;; We can't use byte-compile-two-args for throw because in the event that |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4608 ;; the form does not have two args, it tries to #'funcall it expecting a |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4609 ;; runtime wrong-number-of-arguments error. Now that #'throw is a special |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4610 ;; form, it provokes an invalid-function error instead (or at least it |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4611 ;; should; there's a kludge around for the moment in eval.c that avoids |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4612 ;; that, but this file should not assume that that will always be there). |
|
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5358
diff
changeset
|
4613 (if (not (eql 2 (length (cdr form)))) |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4614 (progn |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4615 (byte-compile-warn-wrong-args form 2) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4616 (byte-compile-normal-call |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4617 `(signal 'wrong-number-of-arguments '(,(car form) |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4618 ,(length (cdr form)))))) |
|
5356
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4619 ;; If this form was macroexpanded from `return-from', mark the |
|
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4620 ;; corresponding block as having been referenced. |
|
5dd1ba5e0113
Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5353
diff
changeset
|
4621 (let* ((symbol (car-safe (cdr-safe (nth 1 form)))) |
|
5376
4b529b940e2e
Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5374
diff
changeset
|
4622 (not-present '#:not-present) |
|
5377
eac2e6bd5b2c
Correct some minor problems in my last change.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5376
diff
changeset
|
4623 (block (if (and symbol (symbolp symbol)) |
|
eac2e6bd5b2c
Correct some minor problems in my last change.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5376
diff
changeset
|
4624 (get symbol 'cl-block-name not-present) |
|
eac2e6bd5b2c
Correct some minor problems in my last change.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5376
diff
changeset
|
4625 not-present)) |
|
5376
4b529b940e2e
Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5374
diff
changeset
|
4626 (assq (and (not (eq block not-present)) |
|
4b529b940e2e
Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5374
diff
changeset
|
4627 (assq block byte-compile-active-blocks)))) |
|
5377
eac2e6bd5b2c
Correct some minor problems in my last change.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5376
diff
changeset
|
4628 (if assq |
|
eac2e6bd5b2c
Correct some minor problems in my last change.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5376
diff
changeset
|
4629 (setcdr assq t) |
|
eac2e6bd5b2c
Correct some minor problems in my last change.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5376
diff
changeset
|
4630 (if (not (eq block not-present)) |
|
eac2e6bd5b2c
Correct some minor problems in my last change.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5376
diff
changeset
|
4631 ;; No corresponding enclosing block. |
|
eac2e6bd5b2c
Correct some minor problems in my last change.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5376
diff
changeset
|
4632 (byte-compile-warn "return-from: no enclosing block named `%s'" |
|
eac2e6bd5b2c
Correct some minor problems in my last change.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5376
diff
changeset
|
4633 block)))) |
|
5376
4b529b940e2e
Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5374
diff
changeset
|
4634 (mapc 'byte-compile-form (cdr form)) ;; Push the arguments |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4635 (byte-compile-out (get (car form) 'byte-opcode) 0) |
|
5376
4b529b940e2e
Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5374
diff
changeset
|
4636 (pushnew '(null (function-max-args 'throw)) byte-compile-checks-on-load |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4637 :test #'equal))) |
| 428 | 4638 |
| 4639 ;;; top-level forms elsewhere | |
| 4640 | |
| 4641 (byte-defop-compiler-1 defun) | |
| 4642 (byte-defop-compiler-1 defmacro) | |
| 4643 (byte-defop-compiler-1 defvar) | |
| 442 | 4644 (byte-defop-compiler-1 defvar byte-compile-defvar-or-defconst) |
| 4645 (byte-defop-compiler-1 defconst byte-compile-defvar-or-defconst) | |
| 428 | 4646 (byte-defop-compiler-1 autoload) |
| 4647 ;; According to Mly this can go now that lambda is a macro | |
| 4648 ;(byte-defop-compiler-1 lambda byte-compile-lambda-form) | |
| 4649 (byte-defop-compiler-1 defalias) | |
| 4650 (byte-defop-compiler-1 define-function) | |
| 4651 | |
| 4652 (defun byte-compile-defun (form) | |
| 4653 ;; This is not used for file-level defuns with doc strings. | |
| 4654 (byte-compile-two-args ; Use this to avoid byte-compile-fset's warning. | |
| 4655 (list 'fset (list 'quote (nth 1 form)) | |
| 4656 (byte-compile-byte-code-maker | |
| 4657 (byte-compile-lambda (cons 'lambda (cdr (cdr form))))))) | |
| 4658 (byte-compile-discard) | |
| 4659 (byte-compile-constant (nth 1 form))) | |
| 4660 | |
| 4661 (defun byte-compile-defmacro (form) | |
| 4662 ;; This is not used for file-level defmacros with doc strings. | |
| 4663 (byte-compile-body-do-effect | |
| 4664 (list (list 'fset (list 'quote (nth 1 form)) | |
| 4665 (let ((code (byte-compile-byte-code-maker | |
| 4666 (byte-compile-lambda | |
| 4667 (cons 'lambda (cdr (cdr form))))))) | |
| 4668 (if (eq (car-safe code) 'make-byte-code) | |
| 4669 (list 'cons ''macro code) | |
| 4670 (list 'quote (cons 'macro (eval code)))))) | |
| 4671 (list 'quote (nth 1 form))))) | |
| 4672 | |
| 442 | 4673 (defun byte-compile-defvar-or-defconst (form) |
| 4674 ;; This is not used for file-level defvar/defconsts with doc strings: | |
| 4675 ;; byte-compile-file-form-defvar-or-defconst will be used in that case. | |
| 4676 ;; (defvar|defconst VAR [VALUE [DOCSTRING]]) | |
| 4677 (let ((fun (nth 0 form)) | |
| 4678 (var (nth 1 form)) | |
| 428 | 4679 (value (nth 2 form)) |
| 4680 (string (nth 3 form))) | |
| 442 | 4681 (when (> (length form) 4) |
| 4682 (byte-compile-warn | |
| 4683 "%s %s called with %d arguments, but accepts only %s" | |
| 4684 fun var (length (cdr form)) 3)) | |
| 4685 (when (memq 'free-vars byte-compile-warnings) | |
| 4686 (push (cons var byte-compile-global-bit) byte-compile-bound-variables)) | |
| 428 | 4687 (byte-compile-body-do-effect |
| 442 | 4688 (list |
| 4689 ;; Put the defined variable in this library's load-history entry | |
| 444 | 4690 ;; just as a real defvar would, but only in top-level forms with values. |
| 4691 (when (and (> (length form) 2) | |
| 4692 (null byte-compile-current-form)) | |
| 442 | 4693 `(push ',var current-load-list)) |
| 4694 (when (> (length form) 3) | |
| 4695 (when (and string (not (stringp string))) | |
| 4696 (byte-compile-warn "Third arg to %s %s is not a string: %s" | |
| 4697 fun var string)) | |
| 4698 `(put ',var 'variable-documentation ,string)) | |
| 4699 (if (cdr (cdr form)) ; `value' provided | |
| 4700 (if (eq fun 'defconst) | |
| 4701 ;; `defconst' sets `var' unconditionally. | |
| 4702 `(setq ,var ,value) | |
| 4703 ;; `defvar' sets `var' only when unbound. | |
| 1672 | 4704 `(if (not (default-boundp ',var)) (set-default ',var ,value)))) |
| 442 | 4705 `',var)))) |
| 428 | 4706 |
| 4707 (defun byte-compile-autoload (form) | |
| 4708 (and (byte-compile-constp (nth 1 form)) | |
| 4709 (byte-compile-constp (nth 5 form)) | |
| 4710 (memq (eval (nth 5 form)) '(t macro)) ; macro-p | |
| 4711 (not (fboundp (eval (nth 1 form)))) | |
| 4712 (byte-compile-warn | |
| 4713 "The compiler ignores `autoload' except at top level. You should | |
| 4714 probably put the autoload of the macro `%s' at top-level." | |
| 4715 (eval (nth 1 form)))) | |
| 4716 (byte-compile-normal-call form)) | |
| 4717 | |
| 4718 ;; Lambda's in valid places are handled as special cases by various code. | |
| 4719 ;; The ones that remain are errors. | |
| 4720 ;; According to Mly this can go now that lambda is a macro | |
| 4721 ;(defun byte-compile-lambda-form (form) | |
| 4722 ; (byte-compile-warn | |
| 4723 ; "`lambda' used in function position is invalid: probably you mean #'%s" | |
| 4724 ; (let ((print-escape-newlines t) | |
| 4725 ; (print-level 4) | |
| 4726 ; (print-length 4)) | |
| 4727 ; (prin1-to-string form))) | |
| 4728 ; (byte-compile-normal-call | |
| 4729 ; (list 'signal ''error | |
| 4730 ; (list 'quote (list "`lambda' used in function position" form))))) | |
| 4731 | |
| 4732 ;; Compile normally, but deal with warnings for the function being defined. | |
| 4733 (defun byte-compile-defalias (form) | |
| 4734 (if (and (consp (cdr form)) (consp (nth 1 form)) | |
| 4735 (eq (car (nth 1 form)) 'quote) | |
| 4736 (consp (cdr (nth 1 form))) | |
| 4737 (symbolp (nth 1 (nth 1 form))) | |
| 4738 (consp (nthcdr 2 form)) | |
| 4739 (consp (nth 2 form)) | |
| 4740 (eq (car (nth 2 form)) 'quote) | |
| 4741 (consp (cdr (nth 2 form))) | |
| 4742 (symbolp (nth 1 (nth 2 form)))) | |
| 4743 (progn | |
| 4744 (byte-compile-defalias-warn (nth 1 (nth 1 form)) | |
| 4745 (nth 1 (nth 2 form))) | |
| 4746 (setq byte-compile-function-environment | |
| 4747 (cons (cons (nth 1 (nth 1 form)) | |
| 4748 (nth 1 (nth 2 form))) | |
| 4749 byte-compile-function-environment)))) | |
| 4750 (byte-compile-normal-call form)) | |
| 4751 | |
| 4752 (defun byte-compile-define-function (form) | |
| 4753 (byte-compile-defalias form)) | |
| 4754 | |
| 4755 ;; Turn off warnings about prior calls to the function being defalias'd. | |
| 4756 ;; This could be smarter and compare those calls with | |
| 4757 ;; the function it is being aliased to. | |
| 4758 (defun byte-compile-defalias-warn (new alias) | |
| 4759 (let ((calls (assq new byte-compile-unresolved-functions))) | |
| 4760 (if calls | |
| 4761 (setq byte-compile-unresolved-functions | |
|
5652
cc6f0266bc36
Avoid #'delq in core Lisp, for the sake of style, a very slightly smaller binary
Aidan Kehoe <kehoea@parhasard.net>
parents:
5651
diff
changeset
|
4762 (delete* calls byte-compile-unresolved-functions))))) |
| 428 | 4763 |
| 4764 ;;; tags | |
| 4765 | |
| 4766 ;; Note: Most operations will strip off the 'TAG, but it speeds up | |
| 4767 ;; optimization to have the 'TAG as a part of the tag. | |
| 4768 ;; Tags will be (TAG . (tag-number . stack-depth)). | |
| 4769 (defun byte-compile-make-tag () | |
| 4770 (list 'TAG (setq byte-compile-tag-number (1+ byte-compile-tag-number)))) | |
| 4771 | |
| 4772 | |
| 4773 (defun byte-compile-out-tag (tag) | |
| 4774 (push tag byte-compile-output) | |
| 4775 (if (cdr (cdr tag)) | |
| 4776 (progn | |
| 4777 ;; ## remove this someday | |
| 4778 (and byte-compile-depth | |
| 4779 (not (= (cdr (cdr tag)) byte-compile-depth)) | |
| 4780 (error "Compiler bug: depth conflict at tag %d" (car (cdr tag)))) | |
| 4781 (setq byte-compile-depth (cdr (cdr tag)))) | |
| 4782 (setcdr (cdr tag) byte-compile-depth))) | |
| 4783 | |
| 4784 (defun byte-compile-goto (opcode tag) | |
| 4785 (push (cons opcode tag) byte-compile-output) | |
| 4786 (setcdr (cdr tag) (if (memq opcode byte-goto-always-pop-ops) | |
| 4787 (1- byte-compile-depth) | |
| 4788 byte-compile-depth)) | |
| 4789 (setq byte-compile-depth (and (not (eq opcode 'byte-goto)) | |
| 4790 (1- byte-compile-depth)))) | |
| 4791 | |
| 4792 (defun byte-compile-out (opcode offset) | |
| 4793 (push (cons opcode offset) byte-compile-output) | |
| 4794 (case opcode | |
| 4795 (byte-call | |
| 4796 (setq byte-compile-depth (- byte-compile-depth offset))) | |
| 4797 (byte-return | |
| 4798 ;; This is actually an unnecessary case, because there should be | |
| 4799 ;; no more opcodes behind byte-return. | |
| 4800 (setq byte-compile-depth nil)) | |
|
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4801 (byte-multiple-value-call |
|
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4639
diff
changeset
|
4802 (setq byte-compile-depth (- byte-compile-depth offset))) |
| 428 | 4803 (t |
| 4804 (setq byte-compile-depth (+ byte-compile-depth | |
| 4805 (or (aref byte-stack+-info | |
| 4806 (symbol-value opcode)) | |
| 4807 (- (1- offset)))) | |
| 4808 byte-compile-maxdepth (max byte-compile-depth | |
| 4809 byte-compile-maxdepth)))) | |
| 4810 ;;(if (< byte-compile-depth 0) (error "Compiler error: stack underflow")) | |
| 4811 ) | |
| 4812 | |
| 4813 | |
| 4814 ;;; call tree stuff | |
| 4815 | |
| 4816 (defun byte-compile-annotate-call-tree (form) | |
| 4817 (let (entry) | |
| 4818 ;; annotate the current call | |
| 4819 (if (setq entry (assq (car form) byte-compile-call-tree)) | |
| 4820 (or (memq byte-compile-current-form (nth 1 entry)) ;callers | |
| 4821 (setcar (cdr entry) | |
| 4822 (cons byte-compile-current-form (nth 1 entry)))) | |
| 4823 (push (list (car form) (list byte-compile-current-form) nil) | |
| 4824 byte-compile-call-tree)) | |
| 4825 ;; annotate the current function | |
| 4826 (if (setq entry (assq byte-compile-current-form byte-compile-call-tree)) | |
| 4827 (or (memq (car form) (nth 2 entry)) ;called | |
| 4828 (setcar (cdr (cdr entry)) | |
| 4829 (cons (car form) (nth 2 entry)))) | |
| 4830 (push (list byte-compile-current-form nil (list (car form))) | |
| 4831 byte-compile-call-tree)))) | |
| 4832 | |
| 4833 ;; Renamed from byte-compile-report-call-tree | |
| 4834 ;; to avoid interfering with completion of byte-compile-file. | |
| 4835 ;;;###autoload | |
| 4836 (defun display-call-tree (&optional filename) | |
| 4837 "Display a call graph of a specified file. | |
| 4838 This lists which functions have been called, what functions called | |
| 4839 them, and what functions they call. The list includes all functions | |
| 4840 whose definitions have been compiled in this Emacs session, as well as | |
| 4841 all functions called by those functions. | |
| 4842 | |
| 4843 The call graph does not include macros, inline functions, or | |
| 4844 primitives that the byte-code interpreter knows about directly \(eq, | |
| 4845 cons, etc.\). | |
| 4846 | |
| 4847 The call tree also lists those functions which are not known to be called | |
| 4848 \(that is, to which no calls have been compiled\), and which cannot be | |
| 4849 invoked interactively." | |
| 4850 (interactive) | |
| 4851 (message "Generating call tree...") | |
| 4852 (with-output-to-temp-buffer "*Call-Tree*" | |
| 4853 (set-buffer "*Call-Tree*") | |
| 4854 (erase-buffer) | |
| 4855 (message "Generating call tree... (sorting on %s)" | |
| 4856 byte-compile-call-tree-sort) | |
| 4857 (insert "Call tree for " | |
| 4858 (cond ((null byte-compile-current-file) (or filename "???")) | |
| 4859 ((stringp byte-compile-current-file) | |
| 4860 byte-compile-current-file) | |
| 4861 (t (buffer-name byte-compile-current-file))) | |
| 4862 " sorted on " | |
| 4863 (prin1-to-string byte-compile-call-tree-sort) | |
| 4864 ":\n\n") | |
| 4865 (if byte-compile-call-tree-sort | |
| 4866 (setq byte-compile-call-tree | |
| 4867 (sort byte-compile-call-tree | |
| 4868 (cond | |
| 4869 ((eq byte-compile-call-tree-sort 'callers) | |
| 4870 #'(lambda (x y) (< (length (nth 1 x)) | |
| 4871 (length (nth 1 y))))) | |
| 4872 ((eq byte-compile-call-tree-sort 'calls) | |
| 4873 #'(lambda (x y) (< (length (nth 2 x)) | |
| 4874 (length (nth 2 y))))) | |
| 4875 ((eq byte-compile-call-tree-sort 'calls+callers) | |
| 4876 #'(lambda (x y) (< (+ (length (nth 1 x)) | |
| 4877 (length (nth 2 x))) | |
| 4878 (+ (length (nth 1 y)) | |
| 4879 (length (nth 2 y)))))) | |
| 4880 ((eq byte-compile-call-tree-sort 'name) | |
| 4881 #'(lambda (x y) (string< (car x) | |
| 4882 (car y)))) | |
| 4883 (t (error | |
| 4884 "`byte-compile-call-tree-sort': `%s' - unknown sort mode" | |
| 4885 byte-compile-call-tree-sort)))))) | |
| 4886 (message "Generating call tree...") | |
| 4887 (let ((rest byte-compile-call-tree) | |
| 4888 (b (current-buffer)) | |
| 4889 f p | |
| 4890 callers calls) | |
| 4891 (while rest | |
| 4892 (prin1 (car (car rest)) b) | |
| 4893 (setq callers (nth 1 (car rest)) | |
| 4894 calls (nth 2 (car rest))) | |
| 4895 (insert "\t" | |
| 4896 (cond ((not (fboundp (setq f (car (car rest))))) | |
| 4897 (if (null f) | |
| 4898 " <top level>";; shouldn't insert nil then, actually -sk | |
| 4899 " <not defined>")) | |
| 4900 ((subrp (setq f (symbol-function f))) | |
| 4901 " <subr>") | |
| 4902 ((symbolp f) | |
| 4903 (format " ==> %s" f)) | |
| 4904 ((compiled-function-p f) | |
| 4905 "<compiled function>") | |
| 4906 ((not (consp f)) | |
| 4907 "<malformed function>") | |
| 4908 ((eq 'macro (car f)) | |
| 4909 (if (or (compiled-function-p (cdr f)) | |
| 4910 (assq 'byte-code (cdr (cdr (cdr f))))) | |
| 4911 " <compiled macro>" | |
| 4912 " <macro>")) | |
| 4913 ((assq 'byte-code (cdr (cdr f))) | |
| 4914 "<compiled lambda>") | |
| 4915 ((eq 'lambda (car f)) | |
| 4916 "<function>") | |
| 4917 (t "???")) | |
| 4918 (format " (%d callers + %d calls = %d)" | |
| 4919 ;; Does the optimizer eliminate common subexpressions?-sk | |
| 4920 (length callers) | |
| 4921 (length calls) | |
| 4922 (+ (length callers) (length calls))) | |
| 4923 "\n") | |
| 4924 (if callers | |
| 4925 (progn | |
| 4926 (insert " called by:\n") | |
| 4927 (setq p (point)) | |
| 4928 (insert " " (if (car callers) | |
| 4929 (mapconcat 'symbol-name callers ", ") | |
| 4930 "<top level>")) | |
| 4931 (let ((fill-prefix " ")) | |
| 4932 (fill-region-as-paragraph p (point))))) | |
| 4933 (if calls | |
| 4934 (progn | |
| 4935 (insert " calls:\n") | |
| 4936 (setq p (point)) | |
| 4937 (insert " " (mapconcat 'symbol-name calls ", ")) | |
| 4938 (let ((fill-prefix " ")) | |
| 4939 (fill-region-as-paragraph p (point))))) | |
| 4940 (insert "\n") | |
| 4941 (setq rest (cdr rest))) | |
| 4942 | |
| 4943 (message "Generating call tree...(finding uncalled functions...)") | |
| 4944 (setq rest byte-compile-call-tree) | |
| 4945 (let ((uncalled nil)) | |
| 4946 (while rest | |
| 4947 (or (nth 1 (car rest)) | |
| 4948 (null (setq f (car (car rest)))) | |
| 4949 (byte-compile-fdefinition f t) | |
| 4950 (commandp (byte-compile-fdefinition f nil)) | |
| 4951 (setq uncalled (cons f uncalled))) | |
| 4952 (setq rest (cdr rest))) | |
| 4953 (if uncalled | |
| 4954 (let ((fill-prefix " ")) | |
| 4955 (insert "Noninteractive functions not known to be called:\n ") | |
| 4956 (setq p (point)) | |
| 4957 (insert (mapconcat 'symbol-name (nreverse uncalled) ", ")) | |
| 4958 (fill-region-as-paragraph p (point))))) | |
| 4959 ) | |
| 4960 (message "Generating call tree...done.") | |
| 4961 )) | |
| 4962 | |
| 4963 | |
| 4964 ;;; by crl@newton.purdue.edu | |
| 4965 ;;; Only works noninteractively. | |
| 4966 ;;;###autoload | |
| 4967 (defun batch-byte-compile () | |
| 4968 "Run `byte-compile-file' on the files remaining on the command line. | |
| 4969 Use this from the command line, with `-batch'; | |
| 4970 it won't work in an interactive Emacs. | |
| 4971 Each file is processed even if an error occurred previously. | |
| 444 | 4972 For example, invoke \"xemacs -batch -f batch-byte-compile $emacs/ ~/*.el\"." |
| 428 | 4973 ;; command-line-args-left is what is left of the command line (from |
| 4974 ;; startup.el) | |
| 4975 (defvar command-line-args-left) ;Avoid 'free variable' warning | |
| 4976 (if (not noninteractive) | |
| 4977 (error "`batch-byte-compile' is to be used only with -batch")) | |
| 4978 (let ((error nil)) | |
| 4979 (while command-line-args-left | |
| 442 | 4980 (if (null (batch-byte-compile-one-file)) |
| 4981 (setq error t))) | |
| 428 | 4982 (message "Done") |
| 4983 (kill-emacs (if error 1 0)))) | |
| 4984 | |
| 442 | 4985 ;;;###autoload |
| 4986 (defun batch-byte-compile-one-file () | |
| 4987 "Run `byte-compile-file' on a single file remaining on the command line. | |
| 4988 Use this from the command line, with `-batch'; | |
| 4989 it won't work in an interactive Emacs." | |
| 4990 ;; command-line-args-left is what is left of the command line (from | |
| 4991 ;; startup.el) | |
| 4992 (defvar command-line-args-left) ;Avoid 'free variable' warning | |
| 4993 (if (not noninteractive) | |
| 4994 (error "`batch-byte-compile-one-file' is to be used only with -batch")) | |
| 4995 (let (error | |
| 4996 (file-to-process (car command-line-args-left))) | |
| 4997 (setq command-line-args-left (cdr command-line-args-left)) | |
| 4998 (if (file-directory-p (expand-file-name file-to-process)) | |
| 4999 (let ((files (directory-files file-to-process)) | |
| 5000 source dest) | |
| 5001 (while files | |
| 5002 (if (and (string-match emacs-lisp-file-regexp (car files)) | |
| 5003 (not (auto-save-file-name-p (car files))) | |
| 5004 (setq source (expand-file-name | |
| 5005 (car files) | |
| 5006 file-to-process)) | |
| 5007 (setq dest (byte-compile-dest-file source)) | |
| 5008 (file-exists-p dest) | |
| 5009 (file-newer-than-file-p source dest)) | |
| 5010 (if (null (batch-byte-compile-1 source)) | |
| 5011 (setq error t))) | |
| 5012 (setq files (cdr files))) | |
| 5013 (null error)) | |
| 5014 (batch-byte-compile-1 file-to-process)))) | |
| 5015 | |
| 428 | 5016 (defun batch-byte-compile-1 (file) |
| 5017 (condition-case err | |
| 5018 (progn (byte-compile-file file) t) | |
| 5019 (error | |
| 5020 (princ ">>Error occurred processing ") | |
| 5021 (princ file) | |
| 5022 (princ ": ") | |
| 5023 (if (fboundp 'display-error) ; XEmacs 19.8+ | |
| 5024 (display-error err nil) | |
| 5025 (princ (or (get (car err) 'error-message) (car err))) | |
|
4783
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4775
diff
changeset
|
5026 (mapc #'(lambda (x) (princ " ") (prin1 x)) (cdr err))) |
| 428 | 5027 (princ "\n") |
| 5028 nil))) | |
| 5029 | |
| 5030 ;;;###autoload | |
| 5031 (defun batch-byte-recompile-directory-norecurse () | |
| 5032 "Same as `batch-byte-recompile-directory' but without recursion." | |
| 5033 (setq byte-recompile-directory-recursively nil) | |
| 5034 (batch-byte-recompile-directory)) | |
| 5035 | |
| 5036 ;;;###autoload | |
|
5650
7fa8667cdaa7
Imitate GNU Emacs API for `batch-byte-recompile-directory'.
Mike Sperber <sperber@deinprogramm.de>
parents:
5642
diff
changeset
|
5037 (defun batch-byte-recompile-directory (&optional arg) |
| 428 | 5038 "Runs `byte-recompile-directory' on the dirs remaining on the command line. |
| 5039 Must be used only with `-batch', and kills Emacs on completion. | |
|
5650
7fa8667cdaa7
Imitate GNU Emacs API for `batch-byte-recompile-directory'.
Mike Sperber <sperber@deinprogramm.de>
parents:
5642
diff
changeset
|
5040 For example, invoke `xemacs -batch -f batch-byte-recompile-directory .'. |
|
7fa8667cdaa7
Imitate GNU Emacs API for `batch-byte-recompile-directory'.
Mike Sperber <sperber@deinprogramm.de>
parents:
5642
diff
changeset
|
5041 |
|
7fa8667cdaa7
Imitate GNU Emacs API for `batch-byte-recompile-directory'.
Mike Sperber <sperber@deinprogramm.de>
parents:
5642
diff
changeset
|
5042 The optional argument is passed to `byte-recompile-directory' as the |
|
7fa8667cdaa7
Imitate GNU Emacs API for `batch-byte-recompile-directory'.
Mike Sperber <sperber@deinprogramm.de>
parents:
5642
diff
changeset
|
5043 prefix argument; see the documentation there for its meaing. |
|
7fa8667cdaa7
Imitate GNU Emacs API for `batch-byte-recompile-directory'.
Mike Sperber <sperber@deinprogramm.de>
parents:
5642
diff
changeset
|
5044 In particular, passing 0 means to compile files for which no `.elc' files |
|
7fa8667cdaa7
Imitate GNU Emacs API for `batch-byte-recompile-directory'.
Mike Sperber <sperber@deinprogramm.de>
parents:
5642
diff
changeset
|
5045 exist." |
| 428 | 5046 ;; command-line-args-left is what is left of the command line (startup.el) |
| 5047 (defvar command-line-args-left) ;Avoid 'free variable' warning | |
| 5048 (if (not noninteractive) | |
| 5049 (error "batch-byte-recompile-directory is to be used only with -batch")) | |
| 5050 (or command-line-args-left | |
| 5051 (setq command-line-args-left '("."))) | |
| 5052 (let ((byte-recompile-directory-ignore-errors-p t)) | |
| 5053 (while command-line-args-left | |
|
5650
7fa8667cdaa7
Imitate GNU Emacs API for `batch-byte-recompile-directory'.
Mike Sperber <sperber@deinprogramm.de>
parents:
5642
diff
changeset
|
5054 (byte-recompile-directory (car command-line-args-left) arg) |
| 428 | 5055 (setq command-line-args-left (cdr command-line-args-left)))) |
| 5056 (kill-emacs 0)) | |
| 5057 | |
| 5058 (make-obsolete 'elisp-compile-defun 'compile-defun) | |
| 5059 (make-obsolete 'byte-compile-report-call-tree 'display-call-tree) | |
| 5060 | |
| 5061 ;; other make-obsolete calls in obsolete.el. | |
| 5062 | |
| 5063 (provide 'byte-compile) | |
| 5064 (provide 'bytecomp) | |
| 5065 | |
| 5066 | |
| 5067 ;;; report metering (see the hacks in bytecode.c) | |
| 5068 | |
| 5069 (if (boundp 'byte-code-meter) | |
| 5070 (defun byte-compile-report-ops () | |
| 5071 (defvar byte-code-meter) | |
| 5072 (with-output-to-temp-buffer "*Meter*" | |
| 5073 (set-buffer "*Meter*") | |
| 5074 (let ((i 0) n op off) | |
| 5075 (while (< i 256) | |
| 5076 (setq n (aref (aref byte-code-meter 0) i) | |
| 5077 off nil) | |
| 5078 (if t ;(not (zerop n)) | |
| 5079 (progn | |
| 5080 (setq op i) | |
| 5081 (setq off nil) | |
| 5082 (cond ((< op byte-nth) | |
| 5083 (setq off (logand op 7)) | |
| 5084 (setq op (logand op 248))) | |
| 5085 ((>= op byte-constant) | |
| 5086 (setq off (- op byte-constant) | |
| 5087 op byte-constant))) | |
| 5088 (setq op (aref byte-code-vector op)) | |
| 5089 (insert (format "%-4d" i)) | |
| 5090 (insert (symbol-name op)) | |
| 5091 (if off (insert " [" (int-to-string off) "]")) | |
| 5092 (indent-to 40) | |
| 5093 (insert (int-to-string n) "\n"))) | |
| 5094 (setq i (1+ i))))))) | |
| 5095 | |
| 5096 | |
| 5097 ;; To avoid "lisp nesting exceeds max-lisp-eval-depth" when bytecomp compiles | |
| 5098 ;; itself, compile some of its most used recursive functions (at load time). | |
| 5099 ;; | |
| 5100 (eval-when-compile | |
| 5101 (or (compiled-function-p (symbol-function 'byte-compile-form)) | |
| 5102 (let ((byte-optimize nil) ; do it fast | |
| 5103 (byte-compile-warnings nil)) | |
|
5503
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
5104 (map nil (if noninteractive |
|
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
5105 #'byte-compile |
|
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
5106 #'(lambda (x) |
|
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
5107 (message "compiling %s..." x) |
|
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
5108 (byte-compile x) |
|
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
5109 (message "compiling %s...done" x))) |
|
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
5110 '(byte-compile-normal-call |
|
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
5111 byte-compile-form |
|
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
5112 byte-compile-body |
|
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
5113 ;; Inserted some more than necessary, to speed it up. |
|
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
5114 byte-compile-top-level |
|
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
5115 byte-compile-out-toplevel |
|
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
5116 byte-compile-constant |
|
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
5117 byte-compile-variable-ref))))) |
|
7b5946dbfb96
Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5475
diff
changeset
|
5118 |
|
5637
a366601407c2
Add an explicit autoload for #'cl-compile-time-init, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5632
diff
changeset
|
5119 ;;; Some packages byte-compile with -no-autoloads, so this is necessary: |
|
a366601407c2
Add an explicit autoload for #'cl-compile-time-init, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5632
diff
changeset
|
5120 (autoload 'cl-compile-time-init "cl-macs") |
|
a366601407c2
Add an explicit autoload for #'cl-compile-time-init, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5632
diff
changeset
|
5121 |
|
5632
bd80d9103fc8
Integrate CL code better into core, remove obsolete compatibility code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5613
diff
changeset
|
5122 ;; XEmacs; call this explicitly, don't implement it using bytecomp-load-hook. |
|
bd80d9103fc8
Integrate CL code better into core, remove obsolete compatibility code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5613
diff
changeset
|
5123 (cl-compile-time-init) |
| 428 | 5124 |
|
4683
0cc9d22c3732
Be more reliable about loading cl-macs at byte-compile time, cl.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
5125 (run-hooks 'bytecomp-load-hook) |
|
0cc9d22c3732
Be more reliable about loading cl-macs at byte-compile time, cl.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
5126 |
| 428 | 5127 ;;; bytecomp.el ends here |
