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