annotate lisp/bytecomp.el @ 5613:a944c124b2d3

Be more careful about what we shadow, #'byte-compile-eval. 2011-12-13 Aidan Kehoe <kehoea@parhasard.net> * bytecomp.el (byte-compile-eval): When evaluating code at compile time, don't put those macros in the macro environment that only make sense when creating byte-compiled output.
author Aidan Kehoe <kehoea@parhasard.net>
date Tue, 13 Dec 2011 20:42:30 +0000
parents 2c20bc575989
children bd80d9103fc8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 ;;; bytecomp.el --- compilation of Lisp code into byte code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 ;;; Copyright (C) 1985-1987, 1991-1994 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 ;;; Copyright (C) 1996 Ben Wing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
6 ;; Authors: Jamie Zawinski <jwz@jwz.org>
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 ;; Hallvard Furuseth <hbf@ulrik.uio.no>
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
8 ;; Ben Wing <ben@xemacs.org>
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
9 ;; Martin Buchholz <martin@xemacs.org>
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
10 ;; Richard Stallman <rms@gnu.org>
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
11 ;; Keywords: internal lisp
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 ;; This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5269
diff changeset
17 ;; XEmacs is free software: you can redistribute it and/or modify it
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5269
diff changeset
18 ;; under the terms of the GNU General Public License as published by the
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5269
diff changeset
19 ;; Free Software Foundation, either version 3 of the License, or (at your
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5269
diff changeset
20 ;; option) any later version.
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5269
diff changeset
21
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5269
diff changeset
22 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5269
diff changeset
23 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5269
diff changeset
24 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5269
diff changeset
25 ;; for more details.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 ;; You should have received a copy of the GNU General Public License
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5269
diff changeset
28 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 ;;; Synched up with: FSF 19.30.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 ;;; Commentary:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 ;; The Emacs Lisp byte compiler. This crunches lisp source into a
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
35 ;; sort of p-code (`bytecode') which takes up less space and can be
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
36 ;; interpreted faster. First, the source code forms are converted to
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
37 ;; an intermediate form, `lapcode' [`LAP' == `Lisp Assembly Program']
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
38 ;; which is much easier to manipulate than bytecode. Then the lapcode
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
39 ;; is converted to bytecode, which can be considered to be actual
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
40 ;; machine language. Optimizations can occur at either the source
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
41 ;; level or the lapcode level.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
42
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
43 ;; The user entry points are byte-compile-file,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 ;; byte-recompile-directory and byte-compile-buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 ;;; Code:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 ;;; ========================================================================
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 ;;; Entry points:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 ;;; byte-recompile-directory, byte-compile-file,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 ;;; batch-byte-compile, batch-byte-recompile-directory,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 ;;; byte-compile, compile-defun,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 ;;; display-call-tree
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 ;;; RMS says:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 ;;; (byte-compile-buffer and byte-compile-and-load-file were turned off
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 ;;; because they are not terribly useful and get in the way of completion.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 ;;; But I'm leaving them. --ben
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 ;;; This version of the byte compiler has the following improvements:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 ;;; + optimization of compiled code:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 ;;; - removal of unreachable code;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 ;;; - removal of calls to side-effectless functions whose return-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 ;;; is unused;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 ;;; - compile-time evaluation of safe constant forms, such as (consp nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 ;;; and (ash 1 6);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 ;;; - open-coding of literal lambdas;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 ;;; - peephole optimization of emitted code;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 ;;; - trivial functions are left uncompiled for speed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 ;;; + support for inline functions;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 ;;; + compile-time evaluation of arbitrary expressions;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 ;;; + compile-time warning messages for:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 ;;; - functions being redefined with incompatible arglists;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 ;;; - functions being redefined as macros, or vice-versa;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 ;;; - functions or macros defined multiple times in the same file;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 ;;; - functions being called with the incorrect number of arguments;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 ;;; - functions being called which are not defined globally, in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 ;;; file, or as autoloads;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 ;;; - assignment and reference of undeclared free variables;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 ;;; - various syntax errors;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 ;;; + correct compilation of nested defuns, defmacros, defvars and defsubsts;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 ;;; + correct compilation of top-level uses of macros;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 ;;; + the ability to generate a histogram of functions called.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 ;;; User customization variables:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 ;;; byte-compile-verbose Whether to report the function currently being
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 ;;; compiled in the minibuffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 ;;; byte-optimize Whether to do optimizations; this may be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 ;;; t, nil, 'source, or 'byte;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 ;;; byte-optimize-log Whether to report (in excruciating detail)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 ;;; exactly which optimizations have been made.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 ;;; This may be t, nil, 'source, or 'byte;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 ;;; byte-compile-error-on-warn Whether to stop compilation when a warning is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 ;;; produced;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 ;;; byte-compile-delete-errors Whether the optimizer may delete calls or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 ;;; variable references that are side-effect-free
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 ;;; except that they may return an error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 ;;; byte-compile-generate-call-tree Whether to generate a histogram of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 ;;; function calls. This can be useful for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 ;;; finding unused functions, as well as simple
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 ;;; performance metering.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 ;;; byte-compile-warnings List of warnings to issue, or t. May contain
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 ;;; 'free-vars (references to variables not in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 ;;; current lexical scope)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 ;;; 'unused-vars (non-global variables bound but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 ;;; not referenced)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 ;;; 'unresolved (calls to unknown functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 ;;; 'callargs (lambda calls with args that don't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 ;;; match the lambda's definition)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 ;;; 'subr-callargs (calls to subrs with args that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 ;;; don't match the subr's definition)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 ;;; 'redefine (function cell redefined from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 ;;; a macro to a lambda or vice versa,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 ;;; or redefined to take other args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 ;;; 'obsolete (obsolete variables and functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 ;;; 'pedantic (references to Emacs-compatible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 ;;; symbols)
4719
bd51ab22afa8 Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4716
diff changeset
118 ;;; 'discarded-consing (use of mapcar instead of
bd51ab22afa8 Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4716
diff changeset
119 ;;; mapc, and similar)
bd51ab22afa8 Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4716
diff changeset
120 ;;; 'quoted-lambda (quoting a lambda expression
bd51ab22afa8 Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4716
diff changeset
121 ;;; as data, not as a function,
bd51ab22afa8 Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4716
diff changeset
122 ;;; and using it in a function
bd51ab22afa8 Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4716
diff changeset
123 ;;; context )
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 ;;; emacs-lisp-file-regexp Regexp for the extension of source-files;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
125 ;;; see also the function `byte-compile-dest-file'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 ;;; byte-compile-overwrite-file If nil, delete old .elc files before saving.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 ;;; Most of the above parameters can also be set on a file-by-file basis; see
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 ;;; the documentation of the `byte-compiler-options' macro.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 ;;; New Features:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 ;;; o The form `defsubst' is just like `defun', except that the function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 ;;; generated will be open-coded in compiled code which uses it. This
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 ;;; means that no function call will be generated, it will simply be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 ;;; spliced in. Lisp functions calls are very slow, so this can be a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 ;;; big win.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 ;;; You can generally accomplish the same thing with `defmacro', but in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 ;;; that case, the defined procedure can't be used as an argument to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 ;;; mapcar, etc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 ;;; o You can make a given function be inline even if it has already been
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 ;;; defined with `defun' by using the `proclaim-inline' form like so:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 ;;; (proclaim-inline my-function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 ;;; This is, in fact, exactly what `defsubst' does. To make a function no
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 ;;; longer be inline, you must use `proclaim-notinline'. Beware that if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 ;;; you define a function with `defsubst' and later redefine it with
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
149 ;;; `defun', it will still be open-coded until you use `proclaim-notinline'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 ;;; o You can also open-code one particular call to a function without
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 ;;; open-coding all calls. Use the 'inline' form to do this, like so:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 ;;; (inline (foo 1 2 3)) ;; `foo' will be open-coded
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 ;;; or...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 ;;; (inline ;; `foo' and `baz' will be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 ;;; (foo 1 2 3 (bar 5)) ;; open-coded, but `bar' will not.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 ;;; (baz 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 ;;; o It is possible to open-code a function in the same file it is defined
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 ;;; in without having to load that file before compiling it. the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 ;;; byte-compiler has been modified to remember function definitions in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 ;;; the compilation environment in the same way that it remembers macro
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 ;;; definitions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 ;;; o Forms like ((lambda ...) ...) are open-coded.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 ;;;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
168 ;;; o The form `eval-when-compile' is like `progn', except that the body
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 ;;; is evaluated at compile-time. When it appears at top-level, this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 ;;; is analogous to the Common Lisp idiom (eval-when (compile) ...).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 ;;; When it does not appear at top-level, it is similar to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 ;;; Common Lisp #. reader macro (but not in interpreted code).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 ;;;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
174 ;;; o The form `eval-and-compile' is similar to `eval-when-compile',
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
175 ;;; but the whole form is evalled both at compile-time and at run-time.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 ;;; o The command M-x byte-compile-and-load-file does what you'd think.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 ;;;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
179 ;;; o The command `compile-defun' is analogous to `eval-defun'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 ;;;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
181 ;;; o If you run `byte-compile-file' on a filename which is visited in a
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 ;;; buffer, and that buffer is modified, you are asked whether you want
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 ;;; to save the buffer before compiling.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 ;;; o You can add this to /etc/magic to make file(1) recognize the files
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 ;;; generated by this compiler:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 ;;;
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 549
diff changeset
188 ;;; 0 string ;ELC XEmacs Lisp compiled file,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 ;;; >4 byte x version %d
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 ;;; TO DO:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 ;;; o Should implement declarations and proclamations, notably special,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 ;;; unspecial, and ignore. Do this in such a way as to not break cl.el.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 ;;; o The bound-but-not-used warnings are not issued for variables whose
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 ;;; bindings were established in the arglist, due to the lack of an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 ;;; ignore declaration. Once ignore exists, this should be turned on.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 ;;; o Warn about functions and variables defined but not used?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 ;;; Maybe add some kind of `export' declaration for this?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 ;;; (With interactive functions being automatically exported?)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 ;;; o Any reference to a variable, even one which is a no-op, will cause
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 ;;; the warning not to be given. Possibly we could use the for-effect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 ;;; flag to determine when this reference is useless; possibly more
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 ;;; complex flow analysis would be necessary.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 ;;; o If the optimizer deletes a variable reference, we might be left with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 ;;; a bound-but-not-referenced warning. Generally this is ok, but not if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 ;;; it's a synergistic result of macroexpansion. Need some way to note
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 ;;; that a varref is being optimized away? Of course it would be nice to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 ;;; optimize away the binding too, someday, but it's unsafe today.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 ;;; o (See byte-optimize.el for the optimization TODO list.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 (require 'backquote)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 (or (fboundp 'defsubst)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 ;; This really ought to be loaded already!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 (load-library "bytecomp-runtime"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
218 (defvar emacs-lisp-file-regexp "\\.el$"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 "*Regexp which matches Emacs Lisp source files.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 You may want to redefine `byte-compile-dest-file' if you change this.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 ;; This enables file name handlers such as jka-compr
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 ;; to remove parts of the file name that should not be copied
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 ;; through to the output file name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 (defun byte-compiler-base-file-name (filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 (let ((handler (find-file-name-handler filename
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 'byte-compiler-base-file-name)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 (if handler
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 (funcall handler 'byte-compiler-base-file-name filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 filename)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 (unless (fboundp 'byte-compile-dest-file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 ;; The user may want to redefine this along with emacs-lisp-file-regexp,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 ;; so only define it if it is undefined.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 (defun byte-compile-dest-file (filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 "Convert an Emacs Lisp source file name to a compiled file name."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 (setq filename (byte-compiler-base-file-name filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 (setq filename (file-name-sans-versions filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 (if (string-match emacs-lisp-file-regexp filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 (concat (substring filename 0 (match-beginning 0)) ".elc")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 (concat filename ".elc"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 ;; This can be the 'byte-compile property of any symbol.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 (autoload 'byte-compile-inline-expand "byte-optimize")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 ;; This is the entrypoint to the lapcode optimizer pass1.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 (autoload 'byte-optimize-form "byte-optimize")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 ;; This is the entrypoint to the lapcode optimizer pass2.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 (autoload 'byte-optimize-lapcode "byte-optimize")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 (autoload 'byte-compile-unfold-lambda "byte-optimize")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 ;; This is the entry point to the decompiler, which is used by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 ;; disassembler. The disassembler just requires 'byte-compile, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 ;; that doesn't define this function, so this seems to be a reasonable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 ;; thing to do.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 (autoload 'byte-decompile-bytecode "byte-optimize")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 (defvar byte-compile-verbose
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 (and (not noninteractive) (> (device-baud-rate) search-slow-speed))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 "*Non-nil means print messages describing progress of byte-compiler.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 (defvar byte-compile-print-gensym t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 "*Non-nil means generate code that creates unique symbols at run-time.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 This is achieved by printing uninterned symbols using the `#:SYMBOL'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 notation, so that they will be read uninterned when run.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 With this feature, code that uses uninterned symbols in macros will
5503
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
268 not be runnable under pre-21.0 XEmacsen.")
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 (defvar byte-optimize t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 "*Enables optimization in the byte compiler.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 nil means don't do any optimization.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 t means do all optimizations.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 `source' means do source-level optimizations only.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 `byte' means do code-level optimizations only.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 (defvar byte-compile-delete-errors t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 "*If non-nil, the optimizer may delete forms that may signal an error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 This includes variable references and calls to functions such as `car'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 ;; XEmacs addition
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 (defvar byte-compile-new-bytecodes nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 "This is completely ignored. It is only around for backwards
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 compatibility.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
286 (defvar byte-compile-checks-on-load '((featurep 'xemacs))
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
287 "A list of expressions to check when first loading a file.
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
288 Emacs will throw an error if any of them fail; checks will be made in
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
289 reverse order.")
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 ;; FSF enables byte-compile-dynamic-docstrings but not byte-compile-dynamic
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 ;; by default. This would be a reasonable conservative approach except
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 ;; for the fact that if you enable either of these, you get incompatible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 ;; byte code that can't be read by XEmacs 19.13 or before or FSF 19.28 or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 ;; before.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 ;; Therefore, neither is enabled for 19.14. Both are enabled for 20.0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 ;; because we have no reason to be conservative about changing the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 ;; way things work. (Ben)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 ;; However, I don't think that defaulting byte-compile-dynamic to nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 ;; is a compatibility issue - rather it is a performance issue.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 ;; Therefore I am setting byte-compile-dynamic back to nil. (mrb)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 (defvar byte-compile-dynamic nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 "*If non-nil, compile function bodies so they load lazily.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 They are hidden comments in the compiled file, and brought into core when the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 function is called.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 To enable this option, make it a file-local variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 in the source file you want it to apply to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 For example, add -*-byte-compile-dynamic: t;-*- on the first line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 When this option is true, if you load the compiled file and then move it,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 the functions you loaded will not be able to run.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 (defvar byte-compile-dynamic-docstrings (emacs-version>= 20)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 "*If non-nil, compile doc strings for lazy access.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 We bury the doc strings of functions and variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 inside comments in the file, and bring them into core only when they
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 are actually needed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 When this option is true, if you load the compiled file and then move it,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 you won't be able to find the documentation of anything in that file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 To disable this option for a certain file, make it a file-local variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 in the source file. For example, add this to the first line:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 -*-byte-compile-dynamic-docstrings:nil;-*-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 You can also set the variable globally.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 This option is enabled by default because it reduces Emacs memory usage.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 (defvar byte-optimize-log nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 "*If true, the byte-compiler will log its optimizations into *Compile-Log*.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 If this is 'source, then only source-level optimizations will be logged.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 If it is 'byte, then only byte-level optimizations will be logged.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 (defvar byte-compile-error-on-warn nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 "*If true, the byte-compiler reports warnings with `error'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 ;; byte-compile-warning-types in FSF.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 (defvar byte-compile-default-warnings
4719
bd51ab22afa8 Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4716
diff changeset
343 '(redefine callargs subr-callargs free-vars unresolved unused-vars obsolete
bd51ab22afa8 Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4716
diff changeset
344 discarded-consing quoted-lambda)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 "*The warnings used when byte-compile-warnings is t.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 (defvar byte-compile-warnings t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 "*List of warnings that the compiler should issue (t for the default set).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 Elements of the list may be:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 free-vars references to variables not in the current lexical scope.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 unused-vars references to non-global variables bound but not referenced.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 unresolved calls to unknown functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 callargs lambda calls with args that don't match the definition.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 subr-callargs calls to subrs with args that don't match the definition.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 redefine function cell redefined from a macro to a lambda or vice
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 versa, or redefined to take a different number of arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 obsolete use of an obsolete function or variable.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 pedantic warn of use of compatible symbols.
4719
bd51ab22afa8 Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4716
diff changeset
360 discarded-consing
bd51ab22afa8 Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4716
diff changeset
361 calls to (some) functions that allocate memory, where that
bd51ab22afa8 Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4716
diff changeset
362 memory is immediately discarded; canonically, the use of
bd51ab22afa8 Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4716
diff changeset
363 mapcar instead of mapc
bd51ab22afa8 Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4716
diff changeset
364 quoted-lambda passing a lambda expression not quoted as a function, as a
bd51ab22afa8 Make it possible to silence warnings issued when #'mapcar's result is discarded.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4716
diff changeset
365 function argument
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 The default set is specified by `byte-compile-default-warnings' and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 normally encompasses all possible warnings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 See also the macro `byte-compiler-options'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 (defvar byte-compile-generate-call-tree nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 "*Non-nil means collect call-graph information when compiling.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 This records functions that were called and from where.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 If the value is t, compilation displays the call graph when it finishes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 If the value is neither t nor nil, compilation asks you whether to display
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 the graph.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 The call tree only lists functions called, not macros used. Those functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 which the byte-code interpreter knows about directly (eq, cons, etc.) are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 not reported.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 The call tree also lists those functions which are not known to be called
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 \(that is, to which no calls have been compiled). Functions which can be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 invoked interactively are excluded from this list.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 (defconst byte-compile-call-tree nil "Alist of functions and their call tree.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 Each element looks like
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 \(FUNCTION CALLERS CALLS\)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 where CALLERS is a list of functions that call FUNCTION, and CALLS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 is a list of functions for which calls were generated while compiling
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 FUNCTION.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 (defvar byte-compile-call-tree-sort 'name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 "*If non-nil, sort the call tree.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 The values `name', `callers', `calls', `calls+callers'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 specify different fields to sort on.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 (defvar byte-compile-overwrite-file t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 "If nil, old .elc files are deleted before the new is saved, and .elc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 files will have the same modes as the corresponding .el file. Otherwise,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 existing .elc files will simply be overwritten, and the existing modes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 will not be changed. If this variable is nil, then an .elc file which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 is a symbolic link will be turned into a normal file, instead of the file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 which the link points to being overwritten.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 (defvar byte-recompile-directory-ignore-errors-p nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 "If true, then `byte-recompile-directory' will continue compiling even
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 when an error occurs in a file. This is bound to t by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 `batch-byte-recompile-directory'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
414 (defvar byte-recompile-ignore-uncompilable-mule-files t
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
415 "If non-nil, `byte-recompile-*' ignores non-ASCII .el files in a non-Mule
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
416 XEmacs. This assumes that such files have a -*- coding: ??? -*- magic
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
417 cookie in their first line or a ;;;###coding system: magic cookie
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
418 early in the file.")
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
419
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 (defvar byte-recompile-directory-recursively t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 "*If true, then `byte-recompile-directory' will recurse on subdirectories.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 (defvar byte-compile-constants nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 "list of all constants encountered during compilation of this form")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 (defvar byte-compile-variables nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 "list of all variables encountered during compilation of this form")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 (defvar byte-compile-bound-variables nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 "Alist of variables bound in the context of the current form,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 that is, the current lexical environment. This list lives partly
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 on the specbind stack. The cdr of each cell is an integer bitmask.")
5391
f9dc75bdbdc4 Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5377
diff changeset
431 (defvar byte-compile-output-preface nil
f9dc75bdbdc4 Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5377
diff changeset
432 "Form to output before current by `byte-compile-output-file-form'
f9dc75bdbdc4 Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5377
diff changeset
433 This is used for implementing `load-time-value'.")
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434
4623
a9f83990e6bf Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4539
diff changeset
435 (defvar byte-compile-force-escape-quoted nil
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
436 "If t, `byte-compile-maybe-reset-coding' always chooses `escape-quoted'
4623
a9f83990e6bf Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4539
diff changeset
437
a9f83990e6bf Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4539
diff changeset
438 This is for situations where the byte compiler output file needs to be
a9f83990e6bf Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4539
diff changeset
439 able to encode character values above ?\\xFF, but this cannot be
a9f83990e6bf Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4539
diff changeset
440 easily determined from the input file.")
a9f83990e6bf Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4539
diff changeset
441
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 (defconst byte-compile-referenced-bit 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 (defconst byte-compile-assigned-bit 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 (defconst byte-compile-arglist-bit 4)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 (defconst byte-compile-global-bit 8)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 (defvar byte-compile-free-references)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 (defvar byte-compile-free-assignments)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 (defvar byte-compiler-error-flag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
452 ;;; A form of eval that includes the currently defined macro definitions.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
453 ;;; This helps implement the promise made in the Lispref:
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
454 ;;;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
455 ;;; "If a file being compiled contains a `defmacro' form, the macro is
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
456 ;;; defined temporarily for the rest of the compilation of that file."
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
457 (defun byte-compile-eval (form)
5613
a944c124b2d3 Be more careful about what we shadow, #'byte-compile-eval.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5612
diff changeset
458 (let ((save-macro-environment nil)
a944c124b2d3 Be more careful about what we shadow, #'byte-compile-eval.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5612
diff changeset
459 ;; These are macros in byte-compile-initial-macro-environment that
a944c124b2d3 Be more careful about what we shadow, #'byte-compile-eval.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5612
diff changeset
460 ;; shouldn't be shadowed when calling #'byte-compile-eval, since
a944c124b2d3 Be more careful about what we shadow, #'byte-compile-eval.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5612
diff changeset
461 ;; such code is interpreted, not compiled.
a944c124b2d3 Be more careful about what we shadow, #'byte-compile-eval.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5612
diff changeset
462 ;; #### Consider giving this a docstring and a top-level value.
a944c124b2d3 Be more careful about what we shadow, #'byte-compile-eval.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5612
diff changeset
463 (byte-compile-no-shadow '(load-time-value labels flet)))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
464 (unwind-protect
5503
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
465 (loop
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
466 for (sym . def) in byte-compile-macro-environment
5613
a944c124b2d3 Be more careful about what we shadow, #'byte-compile-eval.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5612
diff changeset
467 do (when (and (symbolp sym) (not (memq sym byte-compile-no-shadow)))
5503
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
468 (push
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
469 (if (fboundp sym)
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
470 (cons sym (symbol-function sym))
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
471 sym)
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
472 save-macro-environment)
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
473 (fset sym (cons 'macro def)))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
474 finally return (eval form))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
475 (dolist (elt save-macro-environment)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
476 (if (symbolp elt)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
477 (fmakunbound elt)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
478 (fset (car elt) (cdr elt)))))))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
479
5566
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
480 (defvar for-effect) ; ## Kludge! This should be an arg, not a special.
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
481
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 (defconst byte-compile-initial-macro-environment
5263
0d436a78c514 Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5182
diff changeset
483 `((byte-compiler-options
0d436a78c514 Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5182
diff changeset
484 . ,#'(lambda (&rest forms)
0d436a78c514 Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5182
diff changeset
485 (apply 'byte-compiler-options-handler forms)))
0d436a78c514 Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5182
diff changeset
486 (eval-when-compile
0d436a78c514 Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5182
diff changeset
487 . ,#'(lambda (&rest body)
0d436a78c514 Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5182
diff changeset
488 (list 'quote (byte-compile-eval (cons 'progn body)))))
0d436a78c514 Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5182
diff changeset
489 (eval-and-compile
0d436a78c514 Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5182
diff changeset
490 . ,#'(lambda (&rest body)
0d436a78c514 Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5182
diff changeset
491 (byte-compile-eval (cons 'progn body))
0d436a78c514 Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5182
diff changeset
492 (cons 'progn body)))
0d436a78c514 Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5182
diff changeset
493 (the .
5269
90a0084b3541 Rephrase the #'the docstring, make it nicer while byte-compiling.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5265
diff changeset
494 ,#'(lambda (type form)
5282
dcc34e28cd84 Warn at byte-compile in #'the if FORM constant & not TYPE; fix byte-compile-constp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5269
diff changeset
495 (if (cl-const-expr-p form)
dcc34e28cd84 Warn at byte-compile in #'the if FORM constant & not TYPE; fix byte-compile-constp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5269
diff changeset
496 (or (eval (cl-make-type-test form type))
dcc34e28cd84 Warn at byte-compile in #'the if FORM constant & not TYPE; fix byte-compile-constp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5269
diff changeset
497 (byte-compile-warn
dcc34e28cd84 Warn at byte-compile in #'the if FORM constant & not TYPE; fix byte-compile-constp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5269
diff changeset
498 "%s is not of type %s" form type)))
5263
0d436a78c514 Add an implementation for #'the, cl-macs.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5182
diff changeset
499 (if byte-compile-delete-errors
5269
90a0084b3541 Rephrase the #'the docstring, make it nicer while byte-compiling.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5265
diff changeset
500 form
5562
855b667dea13 Drop cl-macro-environment in favour of byte-compile-macro-environment.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5560
diff changeset
501 (funcall (cdr (symbol-function 'the)) type form))))
5574
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
502 (declare
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
503 . ,#'(lambda (&rest specs)
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
504 (while specs
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
505 (if (listp cl-declare-stack) (push (car specs) cl-declare-stack))
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
506 (cl-do-proclaim (pop specs) nil))))
5562
855b667dea13 Drop cl-macro-environment in favour of byte-compile-macro-environment.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5560
diff changeset
507 (load-time-value
5579
3e621ba12d36 Don't byte-compile at macroexpansion time, load-time-vale.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5577
diff changeset
508 . ,(symbol-macrolet ((wrapper '#:load-time-value))
3e621ba12d36 Don't byte-compile at macroexpansion time, load-time-vale.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5577
diff changeset
509 (put wrapper 'byte-compile
3e621ba12d36 Don't byte-compile at macroexpansion time, load-time-vale.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5577
diff changeset
510 #'(lambda (form)
3e621ba12d36 Don't byte-compile at macroexpansion time, load-time-vale.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5577
diff changeset
511 (let* ((gensym (gensym))
3e621ba12d36 Don't byte-compile at macroexpansion time, load-time-vale.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5577
diff changeset
512 (byte-compile-bound-variables
3e621ba12d36 Don't byte-compile at macroexpansion time, load-time-vale.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5577
diff changeset
513 (acons gensym byte-compile-global-bit
3e621ba12d36 Don't byte-compile at macroexpansion time, load-time-vale.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5577
diff changeset
514 byte-compile-bound-variables)))
3e621ba12d36 Don't byte-compile at macroexpansion time, load-time-vale.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5577
diff changeset
515 (setq byte-compile-output-preface
3e621ba12d36 Don't byte-compile at macroexpansion time, load-time-vale.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5577
diff changeset
516 (byte-compile-top-level
3e621ba12d36 Don't byte-compile at macroexpansion time, load-time-vale.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5577
diff changeset
517 `(progn
3e621ba12d36 Don't byte-compile at macroexpansion time, load-time-vale.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5577
diff changeset
518 (setq ,gensym (progn ,(second form)))
3e621ba12d36 Don't byte-compile at macroexpansion time, load-time-vale.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5577
diff changeset
519 ,byte-compile-output-preface)
3e621ba12d36 Don't byte-compile at macroexpansion time, load-time-vale.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5577
diff changeset
520 t 'file))
3e621ba12d36 Don't byte-compile at macroexpansion time, load-time-vale.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5577
diff changeset
521 (byte-compile-form `(symbol-value ',gensym) nil))))
3e621ba12d36 Don't byte-compile at macroexpansion time, load-time-vale.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5577
diff changeset
522 #'(lambda (form &optional read-only)
3e621ba12d36 Don't byte-compile at macroexpansion time, load-time-vale.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5577
diff changeset
523 (list wrapper form))))
5562
855b667dea13 Drop cl-macro-environment in favour of byte-compile-macro-environment.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5560
diff changeset
524 (labels
855b667dea13 Drop cl-macro-environment in favour of byte-compile-macro-environment.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5560
diff changeset
525 . ,#'(lambda (bindings &rest body)
5566
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
526 (let* ((names (mapcar 'car bindings))
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
527 (lambdas (mapcar
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
528 (function*
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
529 (lambda ((name . definition))
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
530 (cons 'lambda (cdr (cl-transform-lambda
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
531 definition name)))))
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
532 bindings))
5562
855b667dea13 Drop cl-macro-environment in favour of byte-compile-macro-environment.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5560
diff changeset
533 (placeholders
5566
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
534 (mapcar #'(lambda (lambda)
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
535 (make-byte-code (second lambda) "\xc0\x87"
5574
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
536 ;; This list is used for
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
537 ;; the byte-optimize
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
538 ;; property, if the
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
539 ;; function is to be
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
540 ;; inlined. See
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
541 ;; cl-do-proclaim.
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
542 (vector nil) 1))
5566
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
543 lambdas))
5562
855b667dea13 Drop cl-macro-environment in favour of byte-compile-macro-environment.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5560
diff changeset
544 (byte-compile-macro-environment
5566
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
545 (pairlis names (mapcar
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
546 #'(lambda (placeholder)
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
547 `(lambda (&rest cl-labels-args)
5574
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
548 ;; Be careful not to quote
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
549 ;; PLACEHOLDER, otherwise
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
550 ;; byte-optimize-funcall inlines
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
551 ;; it.
5566
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
552 (list* 'funcall ,placeholder
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
553 cl-labels-args)))
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
554 placeholders)
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
555 byte-compile-macro-environment))
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
556 (gensym (gensym)))
5574
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
557 (labels
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
558 ((byte-compile-transform-labels (form names lambdas
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
559 placeholders)
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
560 (let* ((inline
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
561 (mapcan
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
562 #'(lambda (name placeholder lambda)
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
563 (and
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
564 (eq
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
565 (getf (aref
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
566 (compiled-function-constants
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
567 placeholder) 0)
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
568 'byte-optimizer)
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
569 'byte-compile-inline-expand)
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
570 `(((function ,placeholder)
5593
4218b56833b3 Give the label name when warning or erroring, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5579
diff changeset
571 ,(byte-compile-lambda lambda name)
5574
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
572 (function ,lambda)))))
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
573 names placeholders lambdas))
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
574 (compiled
5593
4218b56833b3 Give the label name when warning or erroring, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5579
diff changeset
575 (mapcar* #'byte-compile-lambda
4218b56833b3 Give the label name when warning or erroring, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5579
diff changeset
576 (if (not inline)
4218b56833b3 Give the label name when warning or erroring, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5579
diff changeset
577 lambdas
4218b56833b3 Give the label name when warning or erroring, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5579
diff changeset
578 ;; See further down for the
5574
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
579 ;; rationale of the sublis calls.
5593
4218b56833b3 Give the label name when warning or erroring, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5579
diff changeset
580 (sublis (pairlis
4218b56833b3 Give the label name when warning or erroring, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5579
diff changeset
581 (mapcar #'cadar inline)
4218b56833b3 Give the label name when warning or erroring, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5579
diff changeset
582 (mapcar #'third inline))
4218b56833b3 Give the label name when warning or erroring, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5579
diff changeset
583 (sublis
4218b56833b3 Give the label name when warning or erroring, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5579
diff changeset
584 (pairlis
4218b56833b3 Give the label name when warning or erroring, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5579
diff changeset
585 (mapcar #'car inline)
4218b56833b3 Give the label name when warning or erroring, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5579
diff changeset
586 (mapcar #'second inline))
4218b56833b3 Give the label name when warning or erroring, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5579
diff changeset
587 lambdas :test #'equal)
4218b56833b3 Give the label name when warning or erroring, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5579
diff changeset
588 :test #'eq))
4218b56833b3 Give the label name when warning or erroring, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5579
diff changeset
589 names))
5574
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
590 elt)
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
591 (mapc #'(lambda (placeholder function)
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
592 (nsubst function placeholder compiled
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
593 :test #'eq
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
594 :descend-structures t))
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
595 placeholders compiled)
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
596 (when inline
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
597 (dolist (triad inline)
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
598 (nsubst (setq elt (elt compiled
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
599 (position (cadar triad)
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
600 placeholders)))
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
601 (second triad) compiled :test #'eq
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
602 :descend-structures t)
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
603 (setf (second triad) elt))
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
604 ;; For inlined labels: first, replace uses of
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
605 ;; the placeholder in places where it's not an
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
606 ;; evident, explicit funcall (that is, where
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
607 ;; it is not to be inlined) with the compiled
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
608 ;; function:
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
609 (setq form (sublis
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
610 (pairlis (mapcar #'car inline)
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
611 (mapcar #'second inline))
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
612 form :test #'equal)
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
613 ;; Now replace uses of the placeholder
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
614 ;; where it is an evident funcall with the
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
615 ;; lambda, quoted as a function, to allow
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
616 ;; byte-optimize-funcall to do its
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
617 ;; thing. Note that the lambdas still have
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
618 ;; the placeholders, so there's no risk
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
619 ;; of recursive inlining.
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
620 form (sublis (pairlis
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
621 (mapcar #'cadar inline)
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
622 (mapcar #'third inline))
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
623 form :test #'eq)))
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
624 (sublis (pairlis placeholders compiled) form
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
625 :test #'eq))))
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
626 (put gensym 'byte-compile
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
627 #'(lambda (form)
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
628 (let* ((names (cadr (cl-pop2 form)))
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
629 (lambdas (mapcar #'cadr (cdr (pop form))))
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
630 (placeholders (cadr (pop form))))
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
631 (byte-compile-body-do-effect
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
632 (byte-compile-transform-labels form names
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
633 lambdas
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
634 placeholders)))))
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
635 (put gensym 'byte-hunk-handler
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
636 #'(lambda (form)
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
637 (let* ((names (cadr (cl-pop2 form)))
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
638 (lambdas (mapcar #'cadr (cdr (pop form))))
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
639 (placeholders (cadr (pop form))))
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
640 (byte-compile-file-form
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
641 (cons 'progn
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
642 (byte-compile-transform-labels
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
643 form names lambdas placeholders))))))
5612
2c20bc575989 Use the old #'labels implementation if #'lexical-let changes lambdas.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5593
diff changeset
644 (setq body
2c20bc575989 Use the old #'labels implementation if #'lexical-let changes lambdas.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5593
diff changeset
645 (cl-macroexpand-all `(,gensym ',names (list ,@lambdas)
2c20bc575989 Use the old #'labels implementation if #'lexical-let changes lambdas.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5593
diff changeset
646 ',placeholders ,@body)
2c20bc575989 Use the old #'labels implementation if #'lexical-let changes lambdas.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5593
diff changeset
647 byte-compile-macro-environment))
2c20bc575989 Use the old #'labels implementation if #'lexical-let changes lambdas.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5593
diff changeset
648 (if (position 'lambda (mapcar #'(lambda (object)
2c20bc575989 Use the old #'labels implementation if #'lexical-let changes lambdas.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5593
diff changeset
649 (car-safe (cdr-safe
2c20bc575989 Use the old #'labels implementation if #'lexical-let changes lambdas.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5593
diff changeset
650 object)))
2c20bc575989 Use the old #'labels implementation if #'lexical-let changes lambdas.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5593
diff changeset
651 (cdr (third body)))
2c20bc575989 Use the old #'labels implementation if #'lexical-let changes lambdas.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5593
diff changeset
652 :key #'car-safe :test-not #'eq)
2c20bc575989 Use the old #'labels implementation if #'lexical-let changes lambdas.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5593
diff changeset
653 ;; #'lexical-let has worked its magic, not all the
2c20bc575989 Use the old #'labels implementation if #'lexical-let changes lambdas.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5593
diff changeset
654 ;; lambdas are lambdas. Give up on pre-compiling the
2c20bc575989 Use the old #'labels implementation if #'lexical-let changes lambdas.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5593
diff changeset
655 ;; labels.
2c20bc575989 Use the old #'labels implementation if #'lexical-let changes lambdas.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5593
diff changeset
656 (setq names (mapcar #'copy-symbol names)
2c20bc575989 Use the old #'labels implementation if #'lexical-let changes lambdas.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5593
diff changeset
657 lambdas (cdr (third body))
2c20bc575989 Use the old #'labels implementation if #'lexical-let changes lambdas.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5593
diff changeset
658 body (sublis (pairlis placeholders names)
2c20bc575989 Use the old #'labels implementation if #'lexical-let changes lambdas.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5593
diff changeset
659 (nthcdr 4 body) :test #'eq)
2c20bc575989 Use the old #'labels implementation if #'lexical-let changes lambdas.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5593
diff changeset
660 lambdas (sublis (pairlis placeholders names)
2c20bc575989 Use the old #'labels implementation if #'lexical-let changes lambdas.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5593
diff changeset
661 lambdas :test #'eq)
2c20bc575989 Use the old #'labels implementation if #'lexical-let changes lambdas.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5593
diff changeset
662 body (cl-macroexpand-all
2c20bc575989 Use the old #'labels implementation if #'lexical-let changes lambdas.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5593
diff changeset
663 `(lexical-let
2c20bc575989 Use the old #'labels implementation if #'lexical-let changes lambdas.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5593
diff changeset
664 ,names
2c20bc575989 Use the old #'labels implementation if #'lexical-let changes lambdas.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5593
diff changeset
665 (setf ,@(mapcan #'list names lambdas))
2c20bc575989 Use the old #'labels implementation if #'lexical-let changes lambdas.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5593
diff changeset
666 ,@body)
2c20bc575989 Use the old #'labels implementation if #'lexical-let changes lambdas.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5593
diff changeset
667 byte-compile-macro-environment))
2c20bc575989 Use the old #'labels implementation if #'lexical-let changes lambdas.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5593
diff changeset
668 body)))))
5566
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
669 (flet .
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
670 ,#'(lambda (bindings &rest body)
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
671 (let* ((names (mapcar 'car bindings))
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
672 (lambdas (mapcar
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
673 (function*
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
674 (lambda ((function . definition))
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
675 (cons 'lambda (cdr (cl-transform-lambda
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
676 definition function)))))
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
677 bindings))
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
678 (gensym (gensym)))
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
679 (put gensym 'byte-compile-flet-environment
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
680 (pairlis names lambdas))
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
681 (put gensym 'byte-compile
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
682 #'(lambda (form)
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
683 (let* ((byte-compile-flet-environment
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
684 (get (car form) 'byte-compile-flet-environment))
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
685 (byte-compile-function-environment
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
686 (append byte-compile-flet-environment
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
687 byte-compile-function-environment))
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
688 name)
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
689 (dolist (acons byte-compile-flet-environment)
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
690 (setq name (car acons))
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
691 (if (and (memq 'redefine byte-compile-warnings)
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
692 (or (cdr
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
693 (assq name
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
694 byte-compile-macro-environment))
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
695 (eq 'macro
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
696 (ignore-errors
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
697 (car (symbol-function name))))))
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
698 ;; XEmacs change; this is a warning, not an
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
699 ;; error. The only use case for #'flet instead
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
700 ;; of #'labels is to shadow a dynamically
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
701 ;; bound function at runtime, and it's
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
702 ;; reasonable to do this even if that symbol
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
703 ;; has a macro binding at compile time.
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
704 (byte-compile-warn
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
705 "flet: redefining macro %s as a function"
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
706 name))
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
707 (if (get name 'byte-opcode)
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
708 (byte-compile-warn
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
709 "flet: %s has a byte code, consider #'labels"
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
710 name))
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
711 (if (get name 'byte-compile)
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
712 (byte-compile-warn
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
713 "flet: %s has a byte-compile method,
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
714 consider #'labels" name)))
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
715 (byte-compile-form (second form)))))
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
716 `(,gensym (letf* ,(mapcar* #'(lambda (name lambda)
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
717 `((symbol-function ',name)
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
718 ,lambda)) names lambdas)
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
719 ,@body))))))
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
720
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 "The default macro-environment passed to macroexpand by the compiler.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 Placing a macro here will cause a macro to have different semantics when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 expanded by the compiler as when expanded by the interpreter.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 (defvar byte-compile-function-environment nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 "Alist of functions defined in the file being compiled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 This is so we can inline them when necessary.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 Each element looks like (FUNCTIONNAME . DEFINITION). It is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 \(FUNCTIONNAME . nil) when a function is redefined as a macro.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 (defvar byte-compile-autoload-environment nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 "Alist of functions and macros defined by autoload in the file being compiled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 This is so we can suppress warnings about calls to these functions, even though
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 they do not have `real' definitions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 Each element looks like (FUNCTIONNAME . CALL-TO-AUTOLOAD).")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 (defvar byte-compile-unresolved-functions nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 "Alist of undefined functions to which calls have been compiled (used for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 warnings when the function is later defined with incorrect args).")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 (defvar byte-compile-file-domain) ; domain of file being compiled
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 (defvar byte-compile-tag-number 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 (defvar byte-compile-output nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 "Alist describing contents to put in byte code string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 Each element is (INDEX . VALUE)")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 (defvar byte-compile-depth 0 "Current depth of execution stack.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 (defvar byte-compile-maxdepth 0 "Maximum depth of execution stack.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 ;;; The byte codes; this information is duplicated in bytecode.c
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 (defconst byte-code-vector nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 "An array containing byte-code names indexed by byte-code values.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 (defconst byte-stack+-info nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 "An array with the stack adjustment for each byte-code.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 (defmacro byte-defop (opcode stack-adjust opname &optional docstring)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 ;; This is a speed-hack for building the byte-code-vector at compile-time.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 ;; We fill in the vector at macroexpand-time, and then after the last call
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 ;; to byte-defop, we write the vector out as a constant instead of writing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 ;; out a bunch of calls to aset.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 ;; Actually, we don't fill in the vector itself, because that could make
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 ;; it problematic to compile big changes to this compiler; we store the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 ;; values on its plist, and remove them later in -extrude.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 (let ((v1 (or (get 'byte-code-vector 'tmp-compile-time-value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 (put 'byte-code-vector 'tmp-compile-time-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 (make-vector 256 nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 (v2 (or (get 'byte-stack+-info 'tmp-compile-time-value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 (put 'byte-stack+-info 'tmp-compile-time-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 (make-vector 256 nil)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 (aset v1 opcode opname)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 (aset v2 opcode stack-adjust))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 (if docstring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 (list 'defconst opname opcode (concat "Byte code opcode " docstring "."))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 (list 'defconst opname opcode)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 (defmacro byte-extrude-byte-code-vectors ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 (prog1 (list 'setq 'byte-code-vector
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 (get 'byte-code-vector 'tmp-compile-time-value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 'byte-stack+-info
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 (get 'byte-stack+-info 'tmp-compile-time-value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 (remprop 'byte-code-vector 'tmp-compile-time-value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 (remprop 'byte-stack+-info 'tmp-compile-time-value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 ;; unused: 0-7
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 ;; These opcodes are special in that they pack their argument into the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 ;; opcode word.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 (byte-defop 8 1 byte-varref "for variable reference")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 (byte-defop 16 -1 byte-varset "for setting a variable")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 (byte-defop 24 -1 byte-varbind "for binding a variable")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 (byte-defop 32 0 byte-call "for calling a function")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 (byte-defop 40 0 byte-unbind "for unbinding special bindings")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 ;; codes 8-47 are consumed by the preceding opcodes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 ;; unused: 48-55
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 (byte-defop 56 -1 byte-nth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 (byte-defop 57 0 byte-symbolp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 (byte-defop 58 0 byte-consp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 (byte-defop 59 0 byte-stringp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 (byte-defop 60 0 byte-listp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 (byte-defop 61 -1 byte-old-eq)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 (byte-defop 62 -1 byte-old-memq)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 (byte-defop 63 0 byte-not)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 (byte-defop 64 0 byte-car)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 (byte-defop 65 0 byte-cdr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 (byte-defop 66 -1 byte-cons)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 (byte-defop 67 0 byte-list1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 (byte-defop 68 -1 byte-list2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 (byte-defop 69 -2 byte-list3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 (byte-defop 70 -3 byte-list4)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 (byte-defop 71 0 byte-length)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 (byte-defop 72 -1 byte-aref)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 (byte-defop 73 -2 byte-aset)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 (byte-defop 74 0 byte-symbol-value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 (byte-defop 75 0 byte-symbol-function) ; this was commented out
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 (byte-defop 76 -1 byte-set)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 (byte-defop 77 -1 byte-fset) ; this was commented out
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 (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
825 (byte-defop 79 -2 byte-subseq)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 (byte-defop 80 -1 byte-concat2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 (byte-defop 81 -2 byte-concat3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 (byte-defop 82 -3 byte-concat4)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 (byte-defop 83 0 byte-sub1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 (byte-defop 84 0 byte-add1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 (byte-defop 85 -1 byte-eqlsign)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 (byte-defop 86 -1 byte-gtr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 (byte-defop 87 -1 byte-lss)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 (byte-defop 88 -1 byte-leq)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 (byte-defop 89 -1 byte-geq)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 (byte-defop 90 -1 byte-diff)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 (byte-defop 91 0 byte-negate)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 (byte-defop 92 -1 byte-plus)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 (byte-defop 93 -1 byte-max)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 (byte-defop 94 -1 byte-min)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 (byte-defop 95 -1 byte-mult)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 (byte-defop 96 1 byte-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 (byte-defop 97 -1 byte-eq) ; new as of v20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 (byte-defop 98 0 byte-goto-char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 (byte-defop 99 0 byte-insert)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 (byte-defop 100 1 byte-point-max)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 (byte-defop 101 1 byte-point-min)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 (byte-defop 102 0 byte-char-after)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 (byte-defop 103 1 byte-following-char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 (byte-defop 104 1 byte-preceding-char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 (byte-defop 105 1 byte-current-column)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 (byte-defop 106 0 byte-indent-to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 (byte-defop 107 -1 byte-equal) ; new as of v20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 (byte-defop 108 1 byte-eolp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 (byte-defop 109 1 byte-eobp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 (byte-defop 110 1 byte-bolp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 (byte-defop 111 1 byte-bobp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 (byte-defop 112 1 byte-current-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 (byte-defop 113 0 byte-set-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 (byte-defop 114 0 byte-save-current-buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 "To make a binding to record the current buffer.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 ;;(byte-defop 114 1 byte-read-char-OBSOLETE) ;obsolete as of v19
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 (byte-defop 115 -1 byte-memq) ; new as of v20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 (byte-defop 116 1 byte-interactive-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 (byte-defop 117 0 byte-forward-char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 (byte-defop 118 0 byte-forward-word)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 (byte-defop 119 -1 byte-skip-chars-forward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 (byte-defop 120 -1 byte-skip-chars-backward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 (byte-defop 121 0 byte-forward-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 (byte-defop 122 0 byte-char-syntax)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 (byte-defop 123 -1 byte-buffer-substring)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 (byte-defop 124 -1 byte-delete-region)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 (byte-defop 125 -1 byte-narrow-to-region)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 (byte-defop 126 1 byte-widen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 (byte-defop 127 0 byte-end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 ;; unused: 128
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 ;; These store their argument in the next two bytes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 (byte-defop 129 1 byte-constant2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 "for reference to a constant with vector index >= byte-constant-limit")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 (byte-defop 130 0 byte-goto "for unconditional jump")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 (byte-defop 131 -1 byte-goto-if-nil "to pop value and jump if it's nil")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 (byte-defop 132 -1 byte-goto-if-not-nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 "to pop value and jump if it's not nil")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 (byte-defop 133 -1 byte-goto-if-nil-else-pop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 "to examine top-of-stack, jump and don't pop it if it's nil,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 otherwise pop it")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 (byte-defop 134 -1 byte-goto-if-not-nil-else-pop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 "to examine top-of-stack, jump and don't pop it if it's non-nil,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 otherwise pop it")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 (byte-defop 135 -1 byte-return "to pop a value and return it from `byte-code'")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 (byte-defop 136 -1 byte-discard "to discard one value from stack")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 (byte-defop 137 1 byte-dup "to duplicate the top of the stack")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 (byte-defop 138 0 byte-save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 "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
900 (byte-defop 139 0 byte-save-window-excursion ; almost obsolete
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 "to make a binding to record entire window configuration")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 (byte-defop 140 0 byte-save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 "to make a binding to record the current buffer clipping restrictions")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 (byte-defop 141 -1 byte-catch
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 "for catch. Takes, on stack, the tag and an expression for the body")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 (byte-defop 142 -1 byte-unwind-protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 "for unwind-protect. Takes, on stack, an expression for the unwind-action")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 ;; For condition-case. Takes, on stack, the variable to bind,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 ;; an expression for the body, and a list of clauses.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 (byte-defop 143 -2 byte-condition-case)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 ;; For entry to with-output-to-temp-buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 ;; Takes, on stack, the buffer name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 ;; Binds standard-output and does some other things.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 ;; Returns with temp buffer on the stack in place of buffer name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 (byte-defop 144 0 byte-temp-output-buffer-setup)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 ;; For exit from with-output-to-temp-buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 ;; Expects the temp buffer on the stack underneath value to return.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 ;; Pops them both, then pushes the value back on.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 ;; Unbinds standard-output and makes the temp buffer visible.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 (byte-defop 145 -1 byte-temp-output-buffer-show)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 ;; To unbind back to the beginning of this frame.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 ;; Not used yet, but will be needed for tail-recursion elimination.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 (byte-defop 146 0 byte-unbind-all)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 (byte-defop 147 -2 byte-set-marker)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 (byte-defop 148 0 byte-match-beginning)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 (byte-defop 149 0 byte-match-end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 (byte-defop 150 0 byte-upcase)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 (byte-defop 151 0 byte-downcase)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 (byte-defop 152 -1 byte-string=)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 (byte-defop 153 -1 byte-string<)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 (byte-defop 154 -1 byte-old-equal)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 (byte-defop 155 -1 byte-nthcdr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 (byte-defop 156 -1 byte-elt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 (byte-defop 157 -1 byte-old-member)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 (byte-defop 158 -1 byte-old-assq)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 (byte-defop 159 0 byte-nreverse)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 (byte-defop 160 -1 byte-setcar)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 (byte-defop 161 -1 byte-setcdr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 (byte-defop 162 0 byte-car-safe)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 (byte-defop 163 0 byte-cdr-safe)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 (byte-defop 164 -1 byte-nconc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 (byte-defop 165 -1 byte-quo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 (byte-defop 166 -1 byte-rem)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 (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
950 (byte-defop 168 0 byte-fixnump)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 ;; unused: 169
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 ;; These are not present in FSF.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 (byte-defop 170 0 byte-rel-goto)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 (byte-defop 171 -1 byte-rel-goto-if-nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 (byte-defop 172 -1 byte-rel-goto-if-not-nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 (byte-defop 173 -1 byte-rel-goto-if-nil-else-pop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 (byte-defop 174 -1 byte-rel-goto-if-not-nil-else-pop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 (byte-defop 175 nil byte-listN)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 (byte-defop 176 nil byte-concatN)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 (byte-defop 177 nil byte-insertN)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
966 (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
967 (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
968 (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
969 (byte-defop 181 -1 byte-throw)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 ;; these ops are new to v20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 (byte-defop 182 -1 byte-member)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 (byte-defop 183 -1 byte-assq)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 ;; unused: 184-191
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 (byte-defop 192 1 byte-constant "for reference to a constant")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 ;; codes 193-255 are consumed by byte-constant.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 (defconst byte-constant-limit 64
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 "Exclusive maximum index usable in the `byte-constant' opcode.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
982 (defconst byte-goto-ops
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
983 '(byte-goto byte-goto-if-nil byte-goto-if-not-nil
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
984 byte-goto-if-nil-else-pop
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
985 byte-goto-if-not-nil-else-pop)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 "List of byte-codes whose offset is a pc.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 (defconst byte-goto-always-pop-ops
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
989 '(byte-goto-if-nil byte-goto-if-not-nil))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 (defconst byte-rel-goto-ops
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
992 '(byte-rel-goto byte-rel-goto-if-nil byte-rel-goto-if-not-nil
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
993 byte-rel-goto-if-nil-else-pop byte-rel-goto-if-not-nil-else-pop)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 "byte-codes for relative jumps.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 (byte-extrude-byte-code-vectors)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998 ;;; lapcode generator
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000 ;;; the byte-compiler now does source -> lapcode -> bytecode instead of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 ;;; source -> bytecode, because it's a lot easier to make optimizations
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002 ;;; on lapcode than on bytecode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004 ;;; Elements of the lapcode list are of the form (<instruction> . <parameter>)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005 ;;; where instruction is a symbol naming a byte-code instruction,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006 ;;; and parameter is an argument to that instruction, if any.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008 ;;; The instruction can be the pseudo-op TAG, which means that this position
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 ;;; in the instruction stream is a target of a goto. (car PARAMETER) will be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 ;;; the PC for this location, and the whole instruction "(TAG pc)" will be the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011 ;;; parameter for some goto op.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013 ;;; If the operation is varbind, varref, varset or push-constant, then the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 ;;; parameter is (variable/constant . index_in_constant_vector).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016 ;;; First, the source code is macroexpanded and optimized in various ways.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 ;;; Then the resultant code is compiled into lapcode. Another set of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 ;;; optimizations are then run over the lapcode. Then the variables and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019 ;;; constants referenced by the lapcode are collected and placed in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 ;;; constants-vector. (This happens now so that variables referenced by dead
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021 ;;; code don't consume space.) And finally, the lapcode is transformed into
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1022 ;;; compacted byte-code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024 ;;; A distinction is made between variables and constants because the variable-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025 ;;; referencing instructions are more sensitive to the variables being near the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 ;;; front of the constants-vector than the constant-referencing instructions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 ;;; Also, this lets us notice references to free variables.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029 (defun byte-compile-lapcode (lap)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030 "Turns lapcode into bytecode. The lapcode is destroyed."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031 ;; Lapcode modifications: changes the ID of a tag to be the tag's PC.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032 (let ((pc 0) ; Program counter
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033 op off ; Operation & offset
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 (bytes '()) ; Put the output bytes here
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035 (patchlist nil) ; List of tags and goto's to patch
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036 rest rel tmp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 (while lap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038 (setq op (car (car lap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039 off (cdr (car lap)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1040 (cond ((not (symbolp op))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041 (error "Non-symbolic opcode `%s'" op))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042 ((eq op 'TAG)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043 (setcar off pc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 (push off patchlist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 ((memq op byte-goto-ops)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 (setq pc (+ pc 3))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047 (setq bytes (cons (cons pc (cdr off))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 (cons nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049 (cons (symbol-value op) bytes))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050 (push bytes patchlist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052 (setq bytes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1053 (cond ((cond ((consp off)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1054 ;; Variable or constant reference
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055 (setq off (cdr off))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056 (eq op 'byte-constant)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057 (cond ((< off byte-constant-limit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058 (setq pc (1+ pc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059 (cons (+ byte-constant off) bytes))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1060 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061 (setq pc (+ 3 pc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1062 (cons (lsh off -8)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1063 (cons (logand off 255)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1064 (cons byte-constant2 bytes))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065 ((and (<= byte-listN (symbol-value op))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1066 (<= (symbol-value op) byte-insertN))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1067 (setq pc (+ 2 pc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1068 (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
1069 ((= 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
1070 (setq pc (1+ pc))
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
1071 ;; Ignore off.
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
1072 (cons (symbol-value op) bytes))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1073 ((< off 6)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1074 (setq pc (1+ pc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1075 (cons (+ (symbol-value op) off) bytes))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1076 ((< off 256)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1077 (setq pc (+ 2 pc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1078 (cons off (cons (+ (symbol-value op) 6) bytes)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1079 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1080 (setq pc (+ 3 pc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1081 (cons (lsh off -8)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1082 (cons (logand off 255)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1083 (cons (+ (symbol-value op) 7)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1084 bytes))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1085 (setq lap (cdr lap)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1086 ;;(if (not (= pc (length bytes)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1087 ;; (error "Compiler error: pc mismatch - %s %s" pc (length bytes)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1088 (cond (t ;; starting with Emacs 19.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1089 ;; Make relative jumps
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1090 (setq patchlist (nreverse patchlist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1091 (while (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1092 (setq off 0) ; PC change because of deleted bytes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1093 (setq rest patchlist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1094 (while rest
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1095 (setq tmp (car rest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096 (and (consp (car tmp)) ; Jump
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1097 (prog1 (null (nth 1 tmp)) ; Absolute jump
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098 (setq tmp (car tmp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1100 (setq rel (- (car (cdr tmp)) (car tmp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1101 (and (<= -129 rel) (< rel 128)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1102 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1103 ;; Convert to relative jump.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1104 (setcdr (car rest) (cdr (cdr (car rest))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105 (setcar (cdr (car rest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106 (+ (car (cdr (car rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1107 (- byte-rel-goto byte-goto)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1108 (setq off (1- off))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1109 (setcar tmp (+ (car tmp) off)) ; Adjust PC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1110 (setq rest (cdr rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1111 ;; If optimizing, repeat until no change.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1112 (and byte-optimize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1113 (not (zerop off)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1114 ;; Patch PC into jumps
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115 (let (bytes)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116 (while patchlist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1117 (setq bytes (car patchlist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1118 (cond ((atom (car bytes))) ; Tag
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119 ((nth 1 bytes) ; Relative jump
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120 (setcar bytes (+ (- (car (cdr (car bytes))) (car (car bytes)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121 128)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1122 (t ; Absolute jump
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1123 (setq pc (car (cdr (car bytes)))) ; Pick PC from tag
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1124 (setcar (cdr bytes) (logand pc 255))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1125 (setcar bytes (lsh pc -8))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1126 (setq patchlist (cdr patchlist))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1127 (concat (nreverse bytes))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1128
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1129
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1130 ;;; byte compiler messages
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1131
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1132 (defvar byte-compile-current-form nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1133 (defvar byte-compile-current-file nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1134 (defvar byte-compile-dest-file nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1135
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1136 (defmacro byte-compile-log (format-string &rest args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1137 `(when (and byte-optimize (memq byte-optimize-log '(t source)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1138 (let ((print-escape-newlines t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1139 (print-level 4)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1140 (print-length 4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1141 (byte-compile-log-1 (format ,format-string ,@args)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1143 (defconst byte-compile-last-warned-form 'nothing)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145 ;; Log a message STRING in *Compile-Log*.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1146 ;; Also log the current function and file if not already done.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1147 (defun byte-compile-log-1 (string &optional fill)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1148 (let* ((this-form (or byte-compile-current-form "toplevel forms"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1149 (while-compiling-msg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1150 (when (or byte-compile-current-file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1151 (not (eq this-form byte-compile-last-warned-form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1152 (format
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1153 "While compiling %s%s:"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1154 this-form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1155 (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1156 ((stringp byte-compile-current-file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157 (concat " in file " byte-compile-current-file))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1158 ((bufferp byte-compile-current-file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1159 (concat " in buffer "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1160 (buffer-name byte-compile-current-file)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161 (""))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1162 (if noninteractive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1163 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1164 (when while-compiling-msg (message "%s" while-compiling-msg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165 (message " %s" string))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1166 (with-current-buffer (get-buffer-create "*Compile-Log*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1167 (goto-char (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1168 (when byte-compile-current-file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1169 (when (> (point-max) (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170 (insert "\n\^L\n"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171 (insert (current-time-string) "\n"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172 (when while-compiling-msg (insert while-compiling-msg "\n"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1173 (insert " " string "\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1174 (when (and fill (not (string-match "\n" string)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1175 (let ((fill-prefix " ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1176 (fill-column 78))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1177 (fill-paragraph nil)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178 (setq byte-compile-current-file nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1179 (setq byte-compile-last-warned-form this-form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1180
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1181 ;; Log the start of a file in *Compile-Log*, and mark it as done.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182 ;; But do nothing in batch mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1183 (defun byte-compile-log-file ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1184 (when (and byte-compile-current-file (not noninteractive))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1185 (with-current-buffer (get-buffer-create "*Compile-Log*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1186 (when (> (point-max) (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1187 (goto-char (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188 (insert "\n\^L\n"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189 (insert "Compiling "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190 (if (stringp byte-compile-current-file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1191 (concat "file " byte-compile-current-file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1192 (concat "buffer " (buffer-name byte-compile-current-file)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1193 " at " (current-time-string) "\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1194 (setq byte-compile-current-file nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1195
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1196 (defvar byte-compile-inbuffer)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1197 (defvar byte-compile-outbuffer)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1198
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199 (defun byte-compile-warn (format &rest args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1200 (setq format (apply 'format format args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1201 (if byte-compile-error-on-warn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1202 (error "%s" format) ; byte-compile-file catches and logs it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1203 (byte-compile-log-1 (concat "** " format) t)
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1204
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1205 ;; This was a first attempt to add line numbers to the
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1206 ;; byte-compilation output. Unfortunately, it doesn't work
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1207 ;; perfectly: it reports the line number at the end of the form
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1208 ;; (which may be an entire function), rather than the line number
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1209 ;; of the actual problem. Doing this right is hard because we
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1210 ;; currently use the built-in Lisp parser to parse the entire form
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1211 ;; at once. What we basically need is a whole separate parser
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1212 ;; that annotates its output with line numbers. For example, we
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1213 ;; might modify the parser in lread.c so that, with the right
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1214 ;; option set, it replaces every Lisp object contained in the
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1215 ;; structure it returns with a cons of that object and the line
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1216 ;; number it was found on (determined by counting newlines,
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1217 ;; starting from some arbitrary point). You then have two
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1218 ;; options: (a) Modify the byte compiler so that everything that
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1219 ;; compiles a form deals with the new annotated form rather than
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1220 ;; the old one, or (b) The byte compiler saves this structure
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1221 ;; while converting it into a normal structure that's given to the
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1222 ;; various form handlers, which need no (or less) modification.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1223 ;; In the former case, finding the line number is trivial because
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1224 ;; it's in the form. In the latter case, finding the line number
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1225 ;; depends on having a unique Lisp object that can be looked up in
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1226 ;; the annotated structure -- i.e. a list, vector, or string.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1227 ;; You'd have to look at the various places where errors are spit
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1228 ;; out (not very many, really), and make sure that such a unique
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1229 ;; object is available. Then you do a depth-first search through
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1230 ;; the annotated structure to find the object.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1231 ;;
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1232 ;; An alternative way of doing (b) that's probably much more
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1233 ;; efficient (and easier to implement) is simply to have the
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1234 ;; parser in lread.c annotate every unique object using a separate
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1235 ;; hash table. This also eliminates the need for a search to find
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1236 ;; the line number. In order to be fine-grained enough to get at
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1237 ;; every symbol in a form -- e.g. if we want to pinpoint a
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1238 ;; particular undefined variable in a function call -- we need to
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1239 ;; annotate every cons, not just each list. We still have
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1240 ;; (probably unimportant) problems with vectors, since all we have
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1241 ;; is the start of the vector. If we cared about this, we could
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1242 ;; store in the hash table a list of the line numbers for each
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1243 ;; item in the vector, not just its start.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1244 ;;
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1245 ;; --ben
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1246
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1247 ; (byte-compile-log-1 (concat "** line: "
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1248 ; (save-excursion
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1249 ; (set-buffer byte-compile-inbuffer)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1250 ; (int-to-string (line-number)))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1251 ; " "
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1252 ; format) t)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1253 ;;; RMS says:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1254 ;;; It is useless to flash warnings too fast to be read.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1255 ;;; Besides, they will all be shown at the end.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1256 ;;; and comments out the next two lines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1257 (or noninteractive ; already written on stdout.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1258 (message "Warning: %s" format))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1259
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1260 ;;; This function should be used to report errors that have halted
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1261 ;;; compilation of the current file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1262 (defun byte-compile-report-error (error-info)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1263 (setq byte-compiler-error-flag t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1264 (byte-compile-log-1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1265 (concat "!! "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1266 (format (if (cdr error-info) "%s (%s)" "%s")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1267 (get (car error-info) 'error-message)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1268 (prin1-to-string (cdr error-info)))))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1269 (if stack-trace-on-error
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1270 (backtrace nil t)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1271
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1272 ;;; Used by make-obsolete.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1273 (defun byte-compile-obsolete (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1274 (let ((new (get (car form) 'byte-obsolete-info)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1275 (if (memq 'obsolete byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1276 (byte-compile-warn "%s is an obsolete function; %s" (car form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1277 (if (stringp (car new))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1278 (car new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1279 (format "use %s instead." (car new)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1280 (funcall (or (cdr new) 'byte-compile-normal-call) form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1281
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1282 ;;; Used by make-obsolete.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1283 (defun byte-compile-compatible (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1284 (let ((new (get (car form) 'byte-compatible-info)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1285 (if (memq 'pedantic byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1286 (byte-compile-warn "%s is provided for compatibility; %s" (car form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1287 (if (stringp (car new))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1288 (car new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1289 (format "use %s instead." (car new)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1290 (funcall (or (cdr new) 'byte-compile-normal-call) form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1291
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1292 ;; Compiler options
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1293
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1294 (defconst byte-compiler-legal-options
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1295 '((optimize byte-optimize (t nil source byte) val)
5503
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
1296 (file-format byte-compile-emacs19-compatibility (emacs20)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1297 (eq val 'emacs19))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1298 (delete-errors byte-compile-delete-errors (t nil) val)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1299 (verbose byte-compile-verbose (t nil) val)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1300 (new-bytecodes byte-compile-new-bytecodes (t nil) val)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1301 (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
1302 ((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
1303 unresolved discarded-consing quoted-lambda))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1304 val)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1305
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1306 ;; XEmacs addition
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1307 (defconst byte-compiler-obsolete-options
5503
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
1308 '((new-bytecodes t) (byte-compile-emacs19-compatibility nil)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1309
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1310 (defun byte-compiler-options-handler (&rest args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1311 (let (key val desc choices)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1312 (while args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1313 (if (or (atom (car args)) (nthcdr 2 (car args)) (null (cdr (car args))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1314 (error "malformed byte-compiler-option %s" (car args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1315 (setq key (car (car args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1316 val (car (cdr (car args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1317 desc (assq key byte-compiler-legal-options))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1318 (or desc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1319 (error "unknown byte-compiler option %s" key))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1320 (if (assq key byte-compiler-obsolete-options)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1321 (byte-compile-warn "%s is an obsolete byte-compiler option." key))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1322 (setq choices (nth 2 desc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1323 (if (consp (car choices))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1324 (let* (this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1325 (handler 'cons)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1326 (var (nth 1 desc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1327 (ret (and (memq (car val) '(+ -))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1328 (copy-sequence (if (eq t (symbol-value var))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1329 (car choices)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1330 (symbol-value var))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1331 (setq choices (car choices))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1332 (while val
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1333 (setq this (car val))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1334 (cond ((memq this choices)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1335 (setq ret (funcall handler this ret)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1336 ((eq this '+) (setq handler 'cons))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1337 ((eq this '-) (setq handler 'delq))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1338 ((error "%s only accepts %s." key choices)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1339 (setq val (cdr val)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1340 (set (nth 1 desc) ret))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1341 (or (memq val choices)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1342 (error "%s must be one of %s." key choices))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1343 (set (nth 1 desc) (eval (nth 3 desc))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1344 (setq args (cdr args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1345 nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1346
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1347 ;;; sanity-checking arglists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1348
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1349 (defun byte-compile-fdefinition (name macro-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1350 (let* ((list (if (memq macro-p '(nil subr))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1351 byte-compile-function-environment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1352 byte-compile-macro-environment))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1353 (env (cdr (assq name list))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1354 (or env
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1355 (let ((fn name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1356 (while (and (symbolp fn)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1357 (fboundp fn)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1358 (or (symbolp (symbol-function fn))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1359 (consp (symbol-function fn))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1360 (and (not macro-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1361 (compiled-function-p (symbol-function fn)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1362 (and (eq macro-p 'subr) (subrp fn))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1363 (setq fn (symbol-function fn)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1364 (if (or (and (not macro-p) (compiled-function-p fn))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1365 (and (eq macro-p 'subr) (subrp fn)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1366 fn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1367 (and (consp fn)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1368 (not (eq macro-p 'subr))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1369 (if (eq 'macro (car fn))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1370 (cdr fn)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1371 (if macro-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1372 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1373 (if (eq 'autoload (car fn))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1374 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1375 fn)))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1376
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1377 (defun byte-compile-arglist-signature (arglist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1378 (let ((args 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1379 opts
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1380 restp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1381 (while arglist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1382 (cond ((eq (car arglist) '&optional)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1383 (or opts (setq opts 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1384 ((eq (car arglist) '&rest)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1385 (if (cdr arglist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1386 (setq restp t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1387 arglist nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1388 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1389 (if opts
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1390 (setq opts (1+ opts))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1391 (setq args (1+ args)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1392 (setq arglist (cdr arglist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1393 (cons args (if restp nil (if opts (+ args opts) args)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1394
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1395
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1396 (defun byte-compile-arglist-signatures-congruent-p (old new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1397 (not (or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1398 (> (car new) (car old)) ; requires more args now
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1399 (and (null (cdr old)) ; tooks rest-args, doesn't any more
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1400 (cdr new))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1401 (and (cdr new) (cdr old) ; can't take as many args now
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1402 (< (cdr new) (cdr old)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1403 )))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1404
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1405 (defun byte-compile-arglist-signature-string (signature)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1406 (cond ((null (cdr signature))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1407 (format "%d+" (car signature)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1408 ((= (car signature) (cdr signature))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1409 (format "%d" (car signature)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1410 (t (format "%d-%d" (car signature) (cdr signature)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1411
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1412
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1413 ;; Warn if the form is calling a function with the wrong number of arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1414 (defun byte-compile-callargs-warn (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1415 (let* ((def (or (byte-compile-fdefinition (car form) nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1416 (byte-compile-fdefinition (car form) t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1417 (sig (and def (byte-compile-arglist-signature
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1418 (if (eq 'lambda (car-safe def))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1419 (nth 1 def)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1420 (if (compiled-function-p def)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1421 (compiled-function-arglist def)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1422 '(&rest def))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1423 (ncall (length (cdr form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1424 (if (and (null def)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1425 (fboundp 'subr-min-args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1426 (setq def (byte-compile-fdefinition (car form) 'subr)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1427 (setq sig (cons (subr-min-args def) (subr-max-args def))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1428 (if sig
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1429 (if (or (< ncall (car sig))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1430 (and (cdr sig) (> ncall (cdr sig))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1431 (byte-compile-warn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1432 "%s called with %d argument%s, but %s %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1433 (car form) ncall
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1434 (if (= 1 ncall) "" "s")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1435 (if (< ncall (car sig))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1436 "requires"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1437 "accepts only")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1438 (byte-compile-arglist-signature-string sig)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1439 (or (fboundp (car form)) ; might be a subr or autoload.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1440 ;; ## this doesn't work with recursion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1441 (eq (car form) byte-compile-current-form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1442 ;; It's a currently-undefined function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1443 ;; Remember number of args in call.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1444 (let ((cons (assq (car form) byte-compile-unresolved-functions))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1445 (n (length (cdr form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1446 (if cons
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1447 (or (memq n (cdr cons))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1448 (setcdr cons (cons n (cdr cons))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1449 (setq byte-compile-unresolved-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1450 (cons (list (car form) n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1451 byte-compile-unresolved-functions))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1452
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1453 ;; Warn if the function or macro is being redefined with a different
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1454 ;; number of arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1455 (defun byte-compile-arglist-warn (form macrop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1456 (let ((old (byte-compile-fdefinition (nth 1 form) macrop)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1457 (if old
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1458 (let ((sig1 (byte-compile-arglist-signature
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1459 (if (eq 'lambda (car-safe old))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1460 (nth 1 old)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1461 (if (compiled-function-p old)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1462 (compiled-function-arglist old)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1463 '(&rest def)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1464 (sig2 (byte-compile-arglist-signature (nth 2 form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1465 (or (byte-compile-arglist-signatures-congruent-p sig1 sig2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1466 (byte-compile-warn "%s %s used to take %s %s, now takes %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1467 (if (eq (car form) 'defun) "function" "macro")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1468 (nth 1 form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1469 (byte-compile-arglist-signature-string sig1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1470 (if (equal sig1 '(1 . 1)) "argument" "arguments")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1471 (byte-compile-arglist-signature-string sig2))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1472 ;; This is the first definition. See if previous calls are compatible.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1473 (let ((calls (assq (nth 1 form) byte-compile-unresolved-functions))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1474 nums sig min max)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1475 (if calls
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1476 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1477 (setq sig (byte-compile-arglist-signature (nth 2 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1478 nums (sort (copy-sequence (cdr calls)) (function <))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1479 min (car nums)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1480 max (car (nreverse nums)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1481 (if (or (< min (car sig))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1482 (and (cdr sig) (> max (cdr sig))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1483 (byte-compile-warn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1484 "%s being defined to take %s%s, but was previously called with %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1485 (nth 1 form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1486 (byte-compile-arglist-signature-string sig)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1487 (if (equal sig '(1 . 1)) " arg" " args")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1488 (byte-compile-arglist-signature-string (cons min max))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1489
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1490 (setq byte-compile-unresolved-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1491 (delq calls byte-compile-unresolved-functions)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1492 )))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1493
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1494 ;; If we have compiled any calls to functions which are not known to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1495 ;; defined, issue a warning enumerating them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1496 ;; `unresolved' in the list `byte-compile-warnings' disables this.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1497 (defun byte-compile-warn-about-unresolved-functions (&optional msg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1498 (if (memq 'unresolved byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1499 (let ((byte-compile-current-form (or msg "the end of the data")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1500 ;; First delete the autoloads from the list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1501 (if byte-compile-autoload-environment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1502 (let ((rest byte-compile-unresolved-functions))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1503 (while rest
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1504 (if (assq (car (car rest)) byte-compile-autoload-environment)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1505 (setq byte-compile-unresolved-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1506 (delq (car rest) byte-compile-unresolved-functions)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1507 (setq rest (cdr rest)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1508 ;; Now warn.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1509 (if (cdr byte-compile-unresolved-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1510 (let* ((str "The following functions are not known to be defined: ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1511 (L (+ (length str) 5))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1512 (rest (reverse byte-compile-unresolved-functions))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1513 s)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1514 (while rest
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1515 (setq s (symbol-name (car (car rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1516 L (+ L (length s) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1517 rest (cdr rest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1518 (if (<= L (1- fill-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1519 (setq str (concat str " " s (and rest ",")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1520 (setq str (concat str "\n " s (and rest ","))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1521 L (+ (length s) 4))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1522 (byte-compile-warn "%s" str))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1523 (if byte-compile-unresolved-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1524 (byte-compile-warn "the function %s is not known to be defined."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1525 (car (car byte-compile-unresolved-functions)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1526 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1527
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1528 (defun byte-compile-defvar-p (var)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1529 ;; Whether the byte compiler thinks that non-lexical references to this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1530 ;; variable are ok.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1531 (or (globally-boundp var)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1532 (let ((rest byte-compile-bound-variables))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1533 (while (and rest var)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1534 (if (and (eq var (car-safe (car rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1535 (not (= 0 (logand (cdr (car rest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1536 byte-compile-global-bit))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1537 (setq var nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1538 (setq rest (cdr rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1539 ;; if var is nil at this point, it's a defvar in this file.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1540 (not var))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1541 ;; Perhaps (eval-when-compile (defvar foo))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1542 (and (boundp 'current-load-list)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1543 (memq var current-load-list))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1544
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1545
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1546 ;;; If we have compiled bindings of variables which have no referents, warn.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1547 (defun byte-compile-warn-about-unused-variables ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1548 (let ((rest byte-compile-bound-variables)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1549 (unreferenced '())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1550 cell)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1551 (while (and rest
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1552 ;; only warn about variables whose lifetime is now ending,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1553 ;; that is, variables from the lexical scope that is now
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1554 ;; terminating. (Think nested lets.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1555 (not (eq (car rest) 'new-scope)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1556 (setq cell (car rest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1557 (if (and (= 0 (logand byte-compile-referenced-bit (cdr cell)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1558 ;; Don't warn about declared-but-unused arguments,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1559 ;; for two reasons: first, the arglist structure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1560 ;; might be imposed by external forces, and we don't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1561 ;; have (declare (ignore x)) yet; and second, inline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1562 ;; expansion produces forms like
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1563 ;; ((lambda (arg) (byte-code "..." [arg])) x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1564 ;; which we can't (ok, well, don't) recognize as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1565 ;; containing a reference to arg, so every inline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1566 ;; expansion would generate a warning. (If we had
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1567 ;; `ignore' then inline expansion could emit an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1568 ;; ignore declaration.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1569 (= 0 (logand byte-compile-arglist-bit (cdr cell)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1570 ;; Don't warn about defvars because this is a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1571 ;; legitimate special binding.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1572 (not (byte-compile-defvar-p (car cell))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1573 (setq unreferenced (cons (car cell) unreferenced)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1574 (setq rest (cdr rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1575 (setq unreferenced (nreverse unreferenced))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1576 (while unreferenced
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1577 (byte-compile-warn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1578 (format "variable %s bound but not referenced" (car unreferenced)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1579 (setq unreferenced (cdr unreferenced)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1580
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1581
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1582 (defmacro byte-compile-constant-symbol-p (symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1583 `(or (keywordp ,symbol) (memq ,symbol '(nil t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1584
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1585 (defmacro byte-compile-constp (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1586 ;; 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
1587 `(cond ((consp ,form) (memq (car ,form) '(quote function)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1588 ((symbolp ,form) (byte-compile-constant-symbol-p ,form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1589 (t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1590
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1591 (defmacro byte-compile-close-variables (&rest body)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1592 `(let
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1593 (;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1594 ;; Close over these variables to encapsulate the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1595 ;; compilation state
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1596 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1597 (byte-compile-macro-environment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1598 ;; Copy it because the compiler may patch into the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1599 ;; macroenvironment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1600 (copy-alist byte-compile-initial-macro-environment))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1601 (byte-compile-function-environment nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1602 (byte-compile-autoload-environment nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1603 (byte-compile-unresolved-functions nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1604 (byte-compile-bound-variables nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1605 (byte-compile-free-references nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1606 (byte-compile-free-assignments nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1607 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1608 ;; Close over these variables so that `byte-compiler-options'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1609 ;; can change them on a per-file basis.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1610 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1611 (byte-compile-verbose byte-compile-verbose)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1612 (byte-optimize byte-optimize)
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
1613 (byte-compile-checks-on-load
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
1614 byte-compile-checks-on-load)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1615 (byte-compile-dynamic byte-compile-dynamic)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1616 (byte-compile-dynamic-docstrings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1617 byte-compile-dynamic-docstrings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1618 (byte-compile-warnings (if (eq byte-compile-warnings t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1619 byte-compile-default-warnings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1620 byte-compile-warnings))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1621 (byte-compile-file-domain nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1622 (prog1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1623 (progn ,@body)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1624 (if (memq 'unused-vars byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1625 ;; done compiling in this scope, warn now.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1626 (byte-compile-warn-about-unused-variables)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1627
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1628
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1629 (defmacro displaying-byte-compile-warnings (&rest body)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1630 `(let* ((byte-compile-log-buffer (get-buffer-create "*Compile-Log*"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1631 (byte-compile-point-max-prev (point-max byte-compile-log-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1632 ;; Log the file name or buffer name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1633 (byte-compile-log-file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1634 ;; Record how much is logged now.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1635 ;; We will display the log buffer if anything more is logged
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1636 ;; before the end of BODY.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1637 (defvar byte-compile-warnings-beginning)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1638 (let ((byte-compile-warnings-beginning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1639 (if (boundp 'byte-compile-warnings-beginning)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1640 byte-compile-warnings-beginning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1641 (point-max byte-compile-log-buffer))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1642
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1643 (unwind-protect
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1644 (call-with-condition-handler
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1645 #'(lambda (error-info)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1646 (byte-compile-report-error error-info))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1647 #'(lambda ()
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1648 (progn ,@body)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1649 ;; Always set point in log to start of interesting output.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1650 (with-current-buffer byte-compile-log-buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1651 (let ((show-begin
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1652 (progn (goto-char byte-compile-point-max-prev)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1653 (skip-chars-forward "\^L\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1654 (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1655 ;; If there were compilation warnings, display them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1656 (if temp-buffer-show-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1657 (let ((show-buffer (get-buffer-create "*Compile-Log-Show*")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1658 ;; Always clean show-buffer, even when not displaying it,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1659 ;; so that misleading previous messages aren't left around.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1660 (with-current-buffer show-buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1661 (setq buffer-read-only nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1662 (erase-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1663 (copy-to-buffer show-buffer show-begin (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1664 (when (< byte-compile-warnings-beginning (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1665 (funcall temp-buffer-show-function show-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1666 (when (< byte-compile-warnings-beginning (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1667 (select-window
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1668 (prog1 (selected-window)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1669 (select-window (display-buffer (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1670 (goto-char show-begin)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1671 (recenter 1)))))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1672
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1673
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1674 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1675 (defun byte-force-recompile (directory)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1676 "Recompile every `.el' file in DIRECTORY that already has a `.elc' file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1677 Files in subdirectories of DIRECTORY are processed also."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1678 (interactive "DByte force recompile (directory): ")
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1679 (byte-recompile-directory directory nil nil t))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1680
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1681 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1682 (defun byte-recompile-directory (directory &optional arg norecursion force)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1683 "Recompile every `.el' file in DIRECTORY that needs recompilation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1684 This is if a `.elc' file exists but is older than the `.el' file.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1685 Files in subdirectories of DIRECTORY are also processed unless
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1686 optional argument NORECURSION is non-nil.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1687
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1688 If the `.elc' file does not exist, normally the `.el' file is *not* compiled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1689 But a prefix argument (optional second arg) means ask user,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1690 for each such `.el' file, whether to compile it. Prefix argument 0 means
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1691 don't ask and compile the file anyway.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1692
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1693 A nonzero prefix argument also means ask about each subdirectory.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1694
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1695 If the fourth optional argument FORCE is non-nil,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1696 recompile every `.el' file that already has a `.elc' file."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1697 (interactive "DByte recompile directory: \nP")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1698 (if arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1699 (setq arg (prefix-numeric-value arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1700 (if noninteractive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1701 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1702 (save-some-buffers)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1703 (redraw-modeline))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1704 (let ((directories (list (expand-file-name directory)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1705 (file-count 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1706 (dir-count 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1707 last-dir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1708 (displaying-byte-compile-warnings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1709 (while directories
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1710 (setq directory (file-name-as-directory (car directories)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1711 (or noninteractive (message "Checking %s..." directory))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1712 (let ((files (directory-files directory))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1713 source dest)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1714 (while files
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1715 (setq source (expand-file-name (car files) directory))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1716 (if (and (not (member (car files) '("." ".." "RCS" "CVS" "SCCS")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1717 ;; Stay away from directory back-links, etc:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1718 (not (file-symlink-p source))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1719 (file-directory-p source)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1720 byte-recompile-directory-recursively)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1721 ;; This file is a subdirectory. Handle them differently.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1722 (if (or (null arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1723 (eq arg 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1724 (y-or-n-p (concat "Check " source "? ")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1725 (setq directories
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1726 (nconc directories (list source))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1727 ;; It is an ordinary file. Decide whether to compile it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1728 (if (and (string-match emacs-lisp-file-regexp source)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1729 (not (auto-save-file-name-p source))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1730 ;; make sure not a mule file we can't handle.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1731 (or (not byte-recompile-ignore-uncompilable-mule-files)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1732 (featurep 'mule)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1733 (not (find-coding-system-magic-cookie-in-file
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1734 source)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1735 (setq dest (byte-compile-dest-file source))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1736 (if (file-exists-p dest)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1737 ;; File was already compiled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1738 (or force (file-newer-than-file-p source dest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1739 ;; No compiled file exists yet.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1740 (and arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1741 (or (eq 0 arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1742 (y-or-n-p (concat "Compile " source "? "))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1743 (progn ;(if (and noninteractive (not byte-compile-verbose))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1744 ; (message "Compiling %s..." source))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1745 ; we do this in byte-compile-file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1746 (if byte-recompile-directory-ignore-errors-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1747 (batch-byte-compile-1 source)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1748 (byte-compile-file source))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1749 (or noninteractive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1750 (message "Checking %s..." directory))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1751 (setq file-count (1+ file-count))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1752 (if (not (eq last-dir directory))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1753 (setq last-dir directory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1754 dir-count (1+ dir-count)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1755 )))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1756 (setq files (cdr files))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1757 (setq directories (cdr directories))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1758 (message "Done (Total of %d file%s compiled%s)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1759 file-count (if (= file-count 1) "" "s")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1760 (if (> dir-count 1) (format " in %d directories" dir-count) ""))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1761
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1762 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1763 (defun byte-recompile-file (filename &optional force)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1764 "Recompile a file of Lisp code named FILENAME if it needs recompilation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1765 This is if the `.elc' file exists but is older than the `.el' file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1766
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1767 If the `.elc' file does not exist, normally the `.el' file is *not*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1768 compiled. But a prefix argument (optional second arg) means ask user
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1769 whether to compile it. Prefix argument 0 don't ask and recompile anyway."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1770 (interactive "fByte recompile file: \nP")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1771 (let ((dest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1772 (if (and (string-match emacs-lisp-file-regexp filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1773 (not (auto-save-file-name-p filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1774 (setq dest (byte-compile-dest-file filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1775 (if (file-exists-p dest)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1776 (file-newer-than-file-p filename dest)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1777 (and force
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1778 (or (eq 0 force)
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1779 (y-or-n-p (concat "Compile " filename "? ")))))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1780 (or (not byte-recompile-ignore-uncompilable-mule-files)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1781 (featurep 'mule)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1782 (not (find-coding-system-magic-cookie-in-file filename))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1783 (byte-compile-file filename))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1784
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1785 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1786 (defun byte-compile-file (filename &optional load)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1787 "Compile a file of Lisp code named FILENAME into a file of byte code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1788 The output file's name is made by appending `c' to the end of FILENAME.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1789 With prefix arg (noninteractively: 2nd arg), load the file after compiling."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1790 ;; (interactive "fByte compile file: \nP")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1791 (interactive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1792 (let ((file buffer-file-name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1793 (file-name nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1794 (file-dir nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1795 (and file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1796 (eq (cdr (assq 'major-mode (buffer-local-variables)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1797 'emacs-lisp-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1798 (setq file-name (file-name-nondirectory file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1799 file-dir (file-name-directory file)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1800 (list (read-file-name (if current-prefix-arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1801 "Byte compile and load file: "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1802 "Byte compile file: ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1803 file-dir nil nil file-name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1804 current-prefix-arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1805 ;; Expand now so we get the current buffer's defaults
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1806 (setq filename (expand-file-name filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1807
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1808 ;; If we're compiling a file that's in a buffer and is modified, offer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1809 ;; to save it first.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1810 (or noninteractive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1811 (let ((b (get-file-buffer (expand-file-name filename))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1812 (if (and b (buffer-modified-p b)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1813 (y-or-n-p (format "save buffer %s first? " (buffer-name b))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1814 (save-excursion (set-buffer b) (save-buffer)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1815
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1816 (if (or noninteractive byte-compile-verbose) ; XEmacs change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1817 (message "Compiling %s..." filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1818 (let (;;(byte-compile-current-file (file-name-nondirectory filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1819 (byte-compile-current-file filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1820 target-file input-buffer output-buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1821 byte-compile-dest-file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1822 (setq target-file (byte-compile-dest-file filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1823 (setq byte-compile-dest-file target-file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1824 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1825 (setq input-buffer (get-buffer-create " *Compiler Input*"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1826 (set-buffer input-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1827 (erase-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1828 (insert-file-contents filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1829 ;; Run hooks including the uncompression hook.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1830 ;; If they change the file name, then change it for the output also.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1831 (let ((buffer-file-name filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1832 (default-major-mode 'emacs-lisp-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1833 (enable-local-eval nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1834 (normal-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1835 (setq filename buffer-file-name)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1836 (setq byte-compiler-error-flag nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1837 ;; It is important that input-buffer not be current at this call,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1838 ;; so that the value of point set in input-buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1839 ;; within byte-compile-from-buffer lingers in that buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1840 (setq output-buffer (byte-compile-from-buffer input-buffer filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1841 (if byte-compiler-error-flag
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1842 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1843 (if byte-compile-verbose
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1844 (message "Compiling %s...done" filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1845 (kill-buffer input-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1846 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1847 (set-buffer output-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1848 (goto-char (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1849 (insert "\n") ; aaah, unix.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1850 (setq target-file (byte-compile-dest-file filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1851 (unless byte-compile-overwrite-file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1852 (ignore-file-errors (delete-file target-file)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1853 (if (file-writable-p target-file)
4529
6f41fb7f3a65 Protect .elc encoding from latin-unity.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4392
diff changeset
1854 ;; 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
1855 ;; 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
1856 (let ((write-region-pre-hook nil))
6f41fb7f3a65 Protect .elc encoding from latin-unity.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4392
diff changeset
1857 (write-region 1 (point-max) target-file))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1858 ;; This is just to give a better error message than write-region
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1859 (signal 'file-error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1860 (list "Opening output file"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1861 (if (file-exists-p target-file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1862 "cannot overwrite file"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1863 "directory not writable or nonexistent")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1864 target-file)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1865 (or byte-compile-overwrite-file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1866 (condition-case ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1867 (set-file-modes target-file (file-modes filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1868 (error nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1869 (kill-buffer (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1870 (if (and byte-compile-generate-call-tree
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1871 (or (eq t byte-compile-generate-call-tree)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1872 (y-or-n-p (format "Report call tree for %s? " filename))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1873 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1874 (display-call-tree filename)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1875 (if load
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1876 (load target-file))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1877 t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1878
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1879 ;; RMS comments the next two out.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1880
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1881 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1882 (defun byte-compile-and-load-file (&optional filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1883 "Compile a file of Lisp code named FILENAME into a file of byte code,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1884 and then load it. The output file's name is made by appending \"c\" to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1885 the end of FILENAME."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1886 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1887 (if filename ; I don't get it, (interactive-p) doesn't always work
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1888 (byte-compile-file filename t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1889 (let ((current-prefix-arg '(4)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1890 (call-interactively 'byte-compile-file))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1891
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1892 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1893 (defun byte-compile-buffer (&optional buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1894 "Byte-compile and evaluate contents of BUFFER (default: the current buffer)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1895 (interactive "bByte compile buffer: ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1896 (setq buffer (if buffer (get-buffer buffer) (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1897 (message "Compiling %s..." buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1898 (let* ((filename (or (buffer-file-name buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1899 (prin1-to-string buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1900 (byte-compile-current-file buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1901 (byte-compile-from-buffer buffer filename t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1902 (message "Compiling %s...done" buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1903 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1904
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1905 ;;; compiling a single function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1906 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1907 (defun compile-defun (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1908 "Compile and evaluate the current top-level form.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1909 Print the result in the minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1910 With argument, insert value in current buffer after the form."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1911 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1912 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1913 (end-of-defun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1914 (beginning-of-defun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1915 (let* ((byte-compile-current-file (buffer-file-name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1916 (load-file-name (buffer-file-name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1917 (byte-compile-last-warned-form 'nothing)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1918 (value (eval (displaying-byte-compile-warnings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1919 (byte-compile-sexp (read (current-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1920 "toplevel forms")))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1921 (cond (arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1922 (message "Compiling from buffer... done.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1923 (prin1 value (current-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1924 (insert "\n"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1925 ((message "%s" (prin1-to-string value)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1926
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1927 (defun byte-compile-from-buffer (byte-compile-inbuffer filename &optional eval)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1928 ;; buffer --> output-buffer, or buffer --> eval form, return nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1929 (let (byte-compile-outbuffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1930 ;; Prevent truncation of flonums and lists as we read and print them
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1931 (float-output-format nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1932 (case-fold-search nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1933 (print-length nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1934 (print-level nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1935 ;; Simulate entry to byte-compile-top-level
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1936 (byte-compile-constants nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1937 (byte-compile-variables nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1938 (byte-compile-tag-number 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1939 (byte-compile-depth 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1940 (byte-compile-maxdepth 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1941 (byte-compile-output nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1942 ;; #### This is bound in b-c-close-variables.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1943 ;; (byte-compile-warnings (if (eq byte-compile-warnings t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1944 ;; byte-compile-warning-types
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1945 ;; byte-compile-warnings))
4623
a9f83990e6bf Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4539
diff changeset
1946 (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
1947 (byte-compile-using-dynamic nil))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1948 (byte-compile-close-variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1949 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1950 (setq byte-compile-outbuffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1951 (set-buffer (get-buffer-create " *Compiler Output*")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1952 (erase-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1953 ;; (emacs-lisp-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1954 (setq case-fold-search nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1955 (and filename
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1956 (not eval)
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
1957 (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
1958 byte-compile-outbuffer))
4623
a9f83990e6bf Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4539
diff changeset
1959 (setq byte-compile-using-dynamic
a9f83990e6bf Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4539
diff changeset
1960 (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
1961 byte-compile-inbuffer)
a9f83990e6bf Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4539
diff changeset
1962 (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
1963 byte-compile-inbuffer)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1964 ;; This is a kludge. Some operating systems (OS/2, DOS) need to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1965 ;; write files containing binary information specially.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1966 ;; Under most circumstances, such files will be in binary
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1967 ;; overwrite mode, so those OS's use that flag to guess how
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1968 ;; they should write their data. Advise them that .elc files
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1969 ;; need to be written carefully.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1970 (setq overwrite-mode 'overwrite-mode-binary))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1971 (displaying-byte-compile-warnings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1972 (save-excursion
4623
a9f83990e6bf Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4539
diff changeset
1973 ;; 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
1974 ;; 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
1975 (goto-char (point-max byte-compile-outbuffer) byte-compile-outbuffer)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1976 (set-buffer byte-compile-inbuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1977 (goto-char 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1978
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1979 ;; Compile the forms from the input buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1980 (while (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1981 (while (progn (skip-chars-forward " \t\n\^L")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1982 (looking-at ";"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1983 (forward-line 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1984 (not (eobp)))
5568
b039c0f018b8 Error if byte-compiling a form hasn't wrapped byte-compile-inbuffer.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5566
diff changeset
1985 (byte-compile-file-form (read byte-compile-inbuffer))
b039c0f018b8 Error if byte-compiling a form hasn't wrapped byte-compile-inbuffer.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5566
diff changeset
1986 (or (eq byte-compile-inbuffer (current-buffer))
b039c0f018b8 Error if byte-compiling a form hasn't wrapped byte-compile-inbuffer.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5566
diff changeset
1987 (error 'invalid-state
b039c0f018b8 Error if byte-compiling a form hasn't wrapped byte-compile-inbuffer.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5566
diff changeset
1988 "byte compiling didn't save-excursion appropriately"
b039c0f018b8 Error if byte-compiling a form hasn't wrapped byte-compile-inbuffer.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5566
diff changeset
1989 (current-buffer))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1990
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1991 ;; Compile pending forms at end of file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1992 (byte-compile-flush-pending)
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
1993 (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
1994 byte-compile-outbuffer)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1995 (byte-compile-warn-about-unresolved-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1996 ;; Should we always do this? When calling multiple files, it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1997 ;; would be useful to delay this warning until all have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1998 ;; been compiled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1999 (setq byte-compile-unresolved-functions nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2000 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2001 (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
2002 (goto-char (point-min))
a9f83990e6bf Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4539
diff changeset
2003 (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
2004 (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
2005 (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
2006 (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
2007 (message
a9f83990e6bf Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4539
diff changeset
2008 "%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
2009 filename))
a9f83990e6bf Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4539
diff changeset
2010 (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
2011 byte-compile-inbuffer)
a9f83990e6bf Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4539
diff changeset
2012 (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
2013 byte-compile-inbuffer)
a9f83990e6bf Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4539
diff changeset
2014 (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
2015 byte-compile-outbuffer
a9f83990e6bf Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4539
diff changeset
2016 (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
2017 filename eval)))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2018 (if (not eval)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2019 byte-compile-outbuffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2020 (let (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2021 (while (condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2022 (progn (setq form (read byte-compile-outbuffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2023 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2024 (end-of-file nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2025 (eval form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2026 (kill-buffer byte-compile-outbuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2027 nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2028
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
2029 (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
2030 "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
2031 docstrings code.")
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
2032
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2033 (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
2034 byte-compile-outbuffer)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2035 (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
2036 (let (comments)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2037 (set-buffer byte-compile-outbuffer)
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
2038 (delete-region 1 (1+ byte-compile-checks-and-comments-space))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2039 (goto-char 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2040 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2041 ;; The magic number of .elc files is ";ELC", or 0x3B454C43. After that is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2042 ;; the file-format version number (19 or 20) as a byte, followed by some
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2043 ;; nulls. The primary motivation for doing this is to get some binary
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2044 ;; characters up in the first line of the file so that `diff' will simply
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2045 ;; say "Binary files differ" instead of actually doing a diff of two .elc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2046 ;; files. An extra benefit is that you can add this to /etc/magic:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2047 ;;
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 549
diff changeset
2048 ;; 0 string ;ELC XEmacs Lisp compiled file,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2049 ;; >4 byte x version %d
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2050 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2051 (insert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2052 ";ELC"
5503
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
2053 20
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
2054 "\000\000\000\n")
5573
f0f1fd0d8486 Remove ELC files from `binary-file-regexps', many of them are escape-quoted.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5568
diff changeset
2055 (insert (format ";;;###coding system: %s\n"
f0f1fd0d8486 Remove ELC files from `binary-file-regexps', many of them are escape-quoted.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5568
diff changeset
2056 (coding-system-name buffer-file-coding-system)))
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
2057 (insert (format
4686
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2058 "\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
2059 (let ((print-readably t))
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2060 (prin1-to-string (if (> (length
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2061 byte-compile-checks-on-load)
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2062 1)
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2063 (cons 'and
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2064 (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
2065 (reverse
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2066 byte-compile-checks-on-load)))
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2067 (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
2068 (loop
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2069 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
2070 with seen-first = nil
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2071 with res = ""
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2072 do
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2073 (if seen-first
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2074 (setq res (concat res ", "))
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2075 (setq seen-first t))
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2076 ;; Print featurep calls differently:
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2077 (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
2078 (eq (car (second check)) 'quote)
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2079 (symbolp (second (second check))))
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2080 (setq res (concat res
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2081 (symbol-name (second (second check)))))
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2082 (setq res (concat res
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2083 (let ((print-readably t))
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2084 (prin1-to-string check)))))
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2085 finally return res)))
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
2086 (setq comments
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
2087 (with-string-as-buffer-contents ""
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
2088 (insert "\n;;; compiled by "
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
2089 (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
2090 (concat (user-login-name) "@" (system-name)))
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
2091 " on "
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
2092 (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
2093 (insert ";;; emacs version " emacs-version ".\n")
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
2094 (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
2095 (cond
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
2096 ((eq byte-optimize 'source)
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
2097 "source-level optimization only")
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
2098 ((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
2099 (byte-optimize "optimization is on")
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
2100 (t "optimization is off"))
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
2101 "\n")))
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
2102
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
2103 ;; 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
2104 ;; 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
2105 (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
2106 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
2107
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
2108 (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
2109 (+ (point) (length comments))))
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
2110 (insert comments))
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
2111 (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
2112 (point)))))
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
2113
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
2114 (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
2115 byte-compile-outbuffer)
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
2116 ;; 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
2117 (goto-char 1)
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
2118 (insert-char ?\ byte-compile-checks-and-comments-space)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
2119 (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
2120 (and
a9f83990e6bf Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4539
diff changeset
2121 (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
2122 (save-excursion
a9f83990e6bf Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4539
diff changeset
2123 (set-buffer byte-compile-inbuffer)
a9f83990e6bf Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4539
diff changeset
2124 (goto-char (point-min))
a9f83990e6bf Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4539
diff changeset
2125 ;; 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
2126 ;; 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
2127 ;; 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
2128 ;; not true of ordinary comments.
a9f83990e6bf Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4539
diff changeset
2129 (let ((non-latin-1-re
a9f83990e6bf Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4539
diff changeset
2130 (concat "[^\000-\377]"
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
2131 #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
2132 "\\{8,8\\}"))
4623
a9f83990e6bf Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4539
diff changeset
2133 (case-fold-search nil))
a9f83990e6bf Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4539
diff changeset
2134 (catch 'need-to-escape-quote
a9f83990e6bf Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4539
diff changeset
2135 (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
2136 (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
2137 (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
2138 (forward-line 1))
a9f83990e6bf Fix a byte compiler bug with characters above ?\xFF.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4539
diff changeset
2139 t)))))
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
2140 (setq buffer-file-coding-system 'raw-text-unix)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
2141 (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
2142 (pushnew '(featurep 'mule) byte-compile-checks-on-load)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
2143 (save-excursion
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
2144 (set-buffer byte-compile-inbuffer)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
2145 (setq byte-compile-dynamic nil
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
2146 byte-compile-dynamic-docstrings nil))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2147
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2148 (defun byte-compile-output-file-form (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2149 ;; writes the given form to the output buffer, being careful of docstrings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2150 ;; in defun, defmacro, defvar, defconst and autoload because make-docfile is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2151 ;; so amazingly stupid.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2152 ;; defalias calls are output directly by byte-compile-file-form-defmumble;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2153 ;; it does not pay to first build the defalias in defmumble and then parse
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2154 ;; 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
2155 (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
2156 custom-declare-variable))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2157 (stringp (nth 3 form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2158 (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
2159 (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
2160 '(autoload custom-declare-variable)))
5560
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5548
diff changeset
2161 (let* ((print-escape-newlines t)
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5548
diff changeset
2162 (print-length nil)
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5548
diff changeset
2163 (print-level nil)
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5548
diff changeset
2164 (print-readably t) ; print #[] for bytecode, 'x for (quote x)
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5548
diff changeset
2165 (print-gensym byte-compile-print-gensym)
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5548
diff changeset
2166 (print-continuous-numbering print-gensym)
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5548
diff changeset
2167 (print-circle t))
5391
f9dc75bdbdc4 Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5377
diff changeset
2168 (when byte-compile-output-preface
f9dc75bdbdc4 Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5377
diff changeset
2169 (princ "\n(progn " byte-compile-outbuffer)
f9dc75bdbdc4 Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5377
diff changeset
2170 (prin1 byte-compile-output-preface byte-compile-outbuffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2171 (princ "\n" byte-compile-outbuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2172 (prin1 form byte-compile-outbuffer)
5391
f9dc75bdbdc4 Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5377
diff changeset
2173 (when byte-compile-output-preface (princ ")" byte-compile-outbuffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2174 nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2175
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2176 (defun byte-compile-output-docform (preface name info form specindex quoted)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2177 "Print a form with a doc string. INFO is (prefix doc-index postfix).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2178 If PREFACE and NAME are non-nil, print them too,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2179 before INFO and the FORM but after the doc string itself.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2180 If SPECINDEX is non-nil, it is the index in FORM
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2181 of the function bytecode string. In that case,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2182 we output that argument and the following argument (the constants vector)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2183 together, for lazy loading.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2184 QUOTED says that we have to put a quote before the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2185 list that represents a doc string reference.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2186 `autoload' needs that."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2187 ;; We need to examine byte-compile-dynamic-docstrings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2188 ;; in the input buffer (now current), not in the output buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2189 (let ((dynamic-docstrings byte-compile-dynamic-docstrings))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2190 (set-buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2191 (prog1 (current-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2192 (set-buffer byte-compile-outbuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2193 (let (position)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2194
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2195 ;; Insert the doc string, and make it a comment with #@LENGTH.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2196 (and (>= (nth 1 info) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2197 dynamic-docstrings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2198 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2199 ;; Make the doc string start at beginning of line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2200 ;; for make-docfile's sake.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2201 (insert "\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2202 (setq position
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2203 (byte-compile-output-as-comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2204 (nth (nth 1 info) form) nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2205 ;; If the doc string starts with * (a user variable),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2206 ;; negate POSITION.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2207 (if (and (stringp (nth (nth 1 info) form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2208 (> (length (nth (nth 1 info) form)) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2209 (char= (aref (nth (nth 1 info) form) 0) ?*))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2210 (setq position (- position)))))
5560
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5548
diff changeset
2211 (byte-compile-flush-pending)
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5548
diff changeset
2212 (let* ((print-escape-newlines t)
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5548
diff changeset
2213 (print-readably t) ; print #[] for bytecode, 'x for (quote x)
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5548
diff changeset
2214 (print-gensym byte-compile-print-gensym)
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5548
diff changeset
2215 (print-continuous-numbering print-gensym)
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5548
diff changeset
2216 (print-circle t)
58b38d5b32d0 Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5548
diff changeset
2217 (index 0))
5391
f9dc75bdbdc4 Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5377
diff changeset
2218 (when byte-compile-output-preface
f9dc75bdbdc4 Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5377
diff changeset
2219 (princ "\n(progn " byte-compile-outbuffer)
f9dc75bdbdc4 Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5377
diff changeset
2220 (prin1 byte-compile-output-preface byte-compile-outbuffer))
f9dc75bdbdc4 Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5377
diff changeset
2221 (if preface
f9dc75bdbdc4 Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5377
diff changeset
2222 (progn
f9dc75bdbdc4 Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5377
diff changeset
2223 (insert preface)
f9dc75bdbdc4 Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5377
diff changeset
2224 (prin1 name byte-compile-outbuffer)))
f9dc75bdbdc4 Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5377
diff changeset
2225 (insert (car info))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2226 (prin1 (car form) byte-compile-outbuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2227 (while (setq form (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2228 (setq index (1+ index))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2229 (insert " ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2230 (cond ((and (numberp specindex) (= index specindex))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2231 (let ((position
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2232 (byte-compile-output-as-comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2233 (cons (car form) (nth 1 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2234 t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2235 (princ (format "(#$ . %d) nil" position)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2236 byte-compile-outbuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2237 (setq form (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2238 (setq index (1+ index))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2239 ((= index (nth 1 info))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2240 (if position
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2241 (princ (format (if quoted "'(#$ . %d)" "(#$ . %d)")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2242 position)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2243 byte-compile-outbuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2244 (let ((print-escape-newlines nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2245 (goto-char (prog1 (1+ (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2246 (prin1 (car form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2247 byte-compile-outbuffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2248 (insert "\\\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2249 (goto-char (point-max)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2250 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2251 (prin1 (car form) byte-compile-outbuffer)))))
5391
f9dc75bdbdc4 Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5377
diff changeset
2252 (insert (nth 2 info))
f9dc75bdbdc4 Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5377
diff changeset
2253 (when byte-compile-output-preface
f9dc75bdbdc4 Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5377
diff changeset
2254 (princ ")" byte-compile-outbuffer))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2255 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2256
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2257 (defun byte-compile-keep-pending (form &optional handler)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2258 (if (memq byte-optimize '(t source))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2259 (setq form (byte-optimize-form form t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2260 (if handler
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2261 (let ((for-effect t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2262 ;; To avoid consing up monstrously large forms at load time, we split
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2263 ;; the output regularly.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2264 (and (memq (car-safe form) '(fset defalias define-function))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2265 (nthcdr 300 byte-compile-output)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2266 (byte-compile-flush-pending))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2267 (funcall handler form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2268 (when for-effect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2269 (byte-compile-discard)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2270 (byte-compile-form form t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2271 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2272
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2273 (defun byte-compile-flush-pending ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2274 (if byte-compile-output
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2275 (let ((form (byte-compile-out-toplevel t 'file)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2276 (cond ((eq (car-safe form) 'progn)
4783
e29fcfd8df5f Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4775
diff changeset
2277 (mapc 'byte-compile-output-file-form (cdr form)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2278 (form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2279 (byte-compile-output-file-form form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2280 (setq byte-compile-constants nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2281 byte-compile-variables nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2282 byte-compile-depth 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2283 byte-compile-maxdepth 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2284 byte-compile-output nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2285
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2286 (defun byte-compile-file-form (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2287 (let ((byte-compile-current-form nil) ; close over this for warnings.
5391
f9dc75bdbdc4 Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5377
diff changeset
2288 (byte-compile-output-preface nil)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2289 handler)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2290 (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2291 ((not (consp form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2292 (byte-compile-keep-pending form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2293 ((and (symbolp (car form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2294 (setq handler (get (car form) 'byte-hunk-handler)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2295 (cond ((setq form (funcall handler form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2296 (byte-compile-flush-pending)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2297 (byte-compile-output-file-form form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2298 ((eq form (setq form (macroexpand form byte-compile-macro-environment)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2299 (byte-compile-keep-pending form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2300 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2301 (byte-compile-file-form form)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2302
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2303 ;; Functions and variables with doc strings must be output separately,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2304 ;; so make-docfile can recognize them. Most other things can be output
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2305 ;; as byte-code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2306
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2307 (put 'defsubst 'byte-hunk-handler 'byte-compile-file-form-defsubst)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2308 (defun byte-compile-file-form-defsubst (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2309 (cond ((assq (nth 1 form) byte-compile-unresolved-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2310 (setq byte-compile-current-form (nth 1 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2311 (byte-compile-warn "defsubst %s was used before it was defined"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2312 (nth 1 form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2313 (byte-compile-file-form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2314 (macroexpand form byte-compile-macro-environment))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2315 ;; Return nil so the form is not output twice.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2316 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2317
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2318 (put 'autoload 'byte-hunk-handler 'byte-compile-file-form-autoload)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2319 (defun byte-compile-file-form-autoload (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2320 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2321 ;; If this is an autoload of a macro, and all arguments are constants (that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2322 ;; is, there is no hairy computation going on here) then evaluate the form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2323 ;; at compile-time. This is so that we can make use of macros which we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2324 ;; have autoloaded from the file being compiled. Normal function autoloads
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2325 ;; are not automatically evaluated at compile time, because there's not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2326 ;; much point to it (so why bother cluttering up the compile-time namespace.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2327 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2328 ;; If this is an autoload of a function, then record its definition in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2329 ;; byte-compile-autoload-environment to suppress any `not known to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2330 ;; defined' warnings at the end of this file (this only matters for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2331 ;; functions which are autoloaded and compiled in the same file, if the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2332 ;; autoload already exists in the compilation environment, we wouldn't have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2333 ;; warned anyway.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2334 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2335 (let* ((name (if (byte-compile-constp (nth 1 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2336 (eval (nth 1 form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2337 ;; In v19, the 5th arg to autoload can be t, nil, 'macro, or 'keymap.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2338 (macrop (and (byte-compile-constp (nth 5 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2339 (memq (eval (nth 5 form)) '(t macro))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2340 ;; (functionp (and (byte-compile-constp (nth 5 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2341 ;; (eq 'nil (eval (nth 5 form)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2342 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2343 (if (and macrop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2344 (let ((form form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2345 ;; all forms are constant
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2346 (while (if (setq form (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2347 (byte-compile-constp (car form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2348 (null form)))
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
2349 ;; eval the macro autoload into the compilation environment
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2350 (eval form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2351
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2352 (if name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2353 (let ((old (assq name byte-compile-autoload-environment)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2354 (cond (old
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2355 (if (memq 'redefine byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2356 (byte-compile-warn "multiple autoloads for %s" name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2357 (setcdr old form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2358 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2359 ;; We only use the names in the autoload environment, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2360 ;; it might be useful to have the bodies some day.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2361 (setq byte-compile-autoload-environment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2362 (cons (cons name form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2363 byte-compile-autoload-environment)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2364 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2365 ;; Now output the form.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2366 (if (stringp (nth 3 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2367 form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2368 ;; No doc string, so we can compile this as a normal form.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2369 (byte-compile-keep-pending form 'byte-compile-normal-call)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2370
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2371 (put 'defvar 'byte-hunk-handler 'byte-compile-file-form-defvar-or-defconst)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2372 (put 'defconst 'byte-hunk-handler 'byte-compile-file-form-defvar-or-defconst)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2373 (defun byte-compile-file-form-defvar-or-defconst (form)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2374 ;; (defvar|defconst VAR [VALUE [DOCSTRING]])
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2375 (if (> (length form) 4)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2376 (byte-compile-warn
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2377 "%s %s called with %d arguments, but accepts only %s"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2378 (car form) (nth 1 form) (length (cdr form)) 3))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2379 (if (and (> (length form) 3) (not (stringp (nth 3 form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2380 (byte-compile-warn "Third arg to %s %s is not a string: %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2381 (car form) (nth 1 form) (nth 3 form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2382 (if (null (nth 3 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2383 ;; Since there is no doc string, we can compile this as a normal form,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2384 ;; and not do a file-boundary.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2385 (byte-compile-keep-pending form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2386 (if (memq 'free-vars byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2387 (setq byte-compile-bound-variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2388 (cons (cons (nth 1 form) byte-compile-global-bit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2389 byte-compile-bound-variables)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2390 (cond ((consp (nth 2 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2391 (setq form (copy-sequence form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2392 (setcar (cdr (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2393 (byte-compile-top-level (nth 2 form) nil 'file))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2394
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2395 ;; The following turns out not to be necessary, since we emit a call to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2396 ;; defvar, which can hack Vfile_domain by itself!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2397 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2398 ;; If a file domain has been set, emit (put 'VAR 'variable-domain ...)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2399 ;; after this defvar.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2400 ; (if byte-compile-file-domain
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2401 ; (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2402 ; ;; Actually, this will emit the (put ...) before the (defvar ...)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2403 ; ;; but I don't think that can matter in this case.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2404 ; (byte-compile-keep-pending
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2405 ; (list 'put (list 'quote (nth 1 form)) ''variable-domain
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2406 ; (list 'quote byte-compile-file-domain)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2407 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2408
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2409 (put 'require 'byte-hunk-handler 'byte-compile-file-form-eval-boundary)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2410 (defun byte-compile-file-form-eval-boundary (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2411 (eval form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2412 (byte-compile-keep-pending form 'byte-compile-normal-call))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2413
4686
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2414 ;; 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
2415 (put 'progn 'byte-hunk-handler
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2416 #'(lambda (form)
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2417 (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
2418 ;; 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
2419 nil))
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2420
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2421 (put 'prog1 'byte-hunk-handler
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2422 #'(lambda (form)
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2423 (when (first form)
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2424 (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
2425 (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
2426 nil)))
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2427
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2428 (put 'prog2 'byte-hunk-handler
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2429 #'(lambda (form)
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2430 (when (first form)
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2431 (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
2432 (when (second form)
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2433 (setq form (cdr form))
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
2434 (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
2435 (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
2436 nil))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2437
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2438 ;; This handler is not necessary, but it makes the output from dont-compile
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2439 ;; and similar macros cleaner.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2440 (put 'eval 'byte-hunk-handler 'byte-compile-file-form-eval)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2441 (defun byte-compile-file-form-eval (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2442 (if (eq (car-safe (nth 1 form)) 'quote)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2443 (nth 1 (nth 1 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2444 (byte-compile-keep-pending form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2445
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2446 (put 'defun 'byte-hunk-handler 'byte-compile-file-form-defun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2447 (defun byte-compile-file-form-defun (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2448 (byte-compile-file-form-defmumble form nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2449
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2450 (put 'defmacro 'byte-hunk-handler 'byte-compile-file-form-defmacro)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2451 (defun byte-compile-file-form-defmacro (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2452 (byte-compile-file-form-defmumble form t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2453
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2454 (defun byte-compile-file-form-defmumble (form macrop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2455 (let* ((name (car (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2456 (this-kind (if macrop 'byte-compile-macro-environment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2457 'byte-compile-function-environment))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2458 (that-kind (if macrop 'byte-compile-function-environment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2459 'byte-compile-macro-environment))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2460 (this-one (assq name (symbol-value this-kind)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2461 (that-one (assq name (symbol-value that-kind)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2462 (byte-compile-free-references nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2463 (byte-compile-free-assignments nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2464
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2465 ;; When a function or macro is defined, add it to the call tree so that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2466 ;; we can tell when functions are not used.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2467 (if byte-compile-generate-call-tree
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2468 (or (assq name byte-compile-call-tree)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2469 (setq byte-compile-call-tree
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2470 (cons (list name nil nil) byte-compile-call-tree))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2471
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2472 (setq byte-compile-current-form name) ; for warnings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2473 (when (memq 'redefine byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2474 (byte-compile-arglist-warn form macrop))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2475 (defvar filename) ; #### filename used free
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2476 (when byte-compile-verbose
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2477 (message "Compiling %s... (%s)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2478 (if filename (file-name-nondirectory filename) "")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2479 (nth 1 form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2480 (cond (that-one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2481 (when (and (memq 'redefine byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2482 ;; hack hack: don't warn when compiling the stubs in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2483 ;; bytecomp-runtime...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2484 (not (assq (nth 1 form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2485 byte-compile-initial-macro-environment)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2486 (byte-compile-warn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2487 "%s defined multiple times, as both function and macro"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2488 (nth 1 form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2489 (setcdr that-one nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2490 (this-one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2491 (when (and (memq 'redefine byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2492 ;; hack: don't warn when compiling the magic internal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2493 ;; byte-compiler macros in bytecomp-runtime.el...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2494 (not (assq (nth 1 form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2495 byte-compile-initial-macro-environment)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2496 (byte-compile-warn "%s %s defined multiple times in this file"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2497 (if macrop "macro" "function")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2498 (nth 1 form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2499 ((and (fboundp name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2500 (or (subrp (symbol-function name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2501 (eq (car-safe (symbol-function name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2502 (if macrop 'lambda 'macro))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2503 (if (memq 'redefine byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2504 (byte-compile-warn "%s %s being redefined as a %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2505 (if (subrp (symbol-function name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2506 "subr"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2507 (if macrop "function" "macro"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2508 (nth 1 form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2509 (if macrop "macro" "function")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2510 ;; shadow existing definition
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2511 (set this-kind
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2512 (cons (cons name nil) (symbol-value this-kind)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2513 (let ((body (nthcdr 3 form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2514 (if (and (stringp (car body))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2515 (symbolp (car-safe (cdr-safe body)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2516 (car-safe (cdr-safe body))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2517 (stringp (car-safe (cdr-safe (cdr-safe body)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2518 (byte-compile-warn "Probable `\"' without `\\' in doc string of %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2519 (nth 1 form))))
5506
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5503
diff changeset
2520
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5503
diff changeset
2521 ;; Generate code for declarations in macro definitions.
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5503
diff changeset
2522 ;; Remove declarations from the body of the macro definition.
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5503
diff changeset
2523 (when macrop
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5503
diff changeset
2524 (let ((byte-compile-defmacro-body (nthcdr 3 form)))
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5503
diff changeset
2525 (if (stringp (car byte-compile-defmacro-body))
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5503
diff changeset
2526 (setq byte-compile-defmacro-body (nthcdr 4 form)))
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5503
diff changeset
2527 (when (and (consp byte-compile-defmacro-body)
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5503
diff changeset
2528 (eq 'declare (car-safe (car byte-compile-defmacro-body))))
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5503
diff changeset
2529 (if (eq 'declare (car-safe (car-safe
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5503
diff changeset
2530 (cdr byte-compile-defmacro-body))))
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5503
diff changeset
2531 (byte-compile-warn "Multiple macro-specific `declare' calls \
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5503
diff changeset
2532 not supported by XEmacs."))
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5503
diff changeset
2533 (setq byte-compile-output-preface
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5503
diff changeset
2534 (byte-compile-top-level
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5503
diff changeset
2535 `(progn (and macro-declaration-function
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5503
diff changeset
2536 (funcall macro-declaration-function
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5503
diff changeset
2537 ',name
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5503
diff changeset
2538 ',(car byte-compile-defmacro-body)))
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5503
diff changeset
2539 ,byte-compile-output-preface) t 'file)))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2540 (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
2541 (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
2542 (docform-info
8c3671b62dad Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5089
diff changeset
2543 (cond ((atom code) ; compiled-function-p
5391
f9dc75bdbdc4 Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5377
diff changeset
2544 (if macrop '(" '(macro . #[" 4 "]))") '(" #[" 4 "])")))
5106
8c3671b62dad Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5089
diff changeset
2545 ((eq (car code) 'quote)
8c3671b62dad Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5089
diff changeset
2546 (setq code new-one)
5391
f9dc75bdbdc4 Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5377
diff changeset
2547 (if macrop '(" '(macro " 2 "))") '(" '(" 2 "))")))
f9dc75bdbdc4 Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5377
diff changeset
2548 ((if macrop '(" (cons 'macro (" 5 ")))") '(" (" 5 "))"))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2549 (if this-one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2550 (setcdr this-one new-one)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2551 (set this-kind
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2552 (cons (cons name new-one) (symbol-value this-kind))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2553 (if (and (stringp (nth 3 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2554 (eq 'quote (car-safe code))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2555 (eq 'lambda (car-safe (nth 1 code))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2556 (cons (car form)
5106
8c3671b62dad Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5089
diff changeset
2557 (cons name (cdr (nth 1 code))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2558 (byte-compile-flush-pending)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2559 (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
2560 ;; 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
2561 ;; 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
2562 ;; byte-compile-output-doc-form.
8c3671b62dad Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5089
diff changeset
2563 (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
2564 (third docform-info))))
8c3671b62dad Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5089
diff changeset
2565 (byte-compile-output-docform
8c3671b62dad Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5089
diff changeset
2566 "\n(defalias '"
8c3671b62dad Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5089
diff changeset
2567 name
8c3671b62dad Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5089
diff changeset
2568 docform-info
8c3671b62dad Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5089
diff changeset
2569 ;; 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
2570 ;; 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
2571 ;; 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
2572 ;; printed to the file.
8c3671b62dad Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5089
diff changeset
2573 (if (consp code)
8c3671b62dad Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5089
diff changeset
2574 code
5391
f9dc75bdbdc4 Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5377
diff changeset
2575 (list* (compiled-function-arglist code)
f9dc75bdbdc4 Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5377
diff changeset
2576 (compiled-function-instructions code)
f9dc75bdbdc4 Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5377
diff changeset
2577 (compiled-function-constants code)
f9dc75bdbdc4 Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5377
diff changeset
2578 (compiled-function-stack-depth code)
f9dc75bdbdc4 Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5377
diff changeset
2579 (compiled-function-doc-string code)
5106
8c3671b62dad Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5089
diff changeset
2580 (if (commandp code)
8c3671b62dad Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5089
diff changeset
2581 (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
2582 (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
2583 1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2584 nil))
5106
8c3671b62dad Remove #'byte-compile-compiled-obj-to-list, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5089
diff changeset
2585 nil)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2586
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2587 ;; Print Lisp object EXP in the output file, inside a comment,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2588 ;; and return the file position it will have.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2589 ;; If QUOTED is non-nil, print with quoting; otherwise, print without quoting.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2590 (defun byte-compile-output-as-comment (exp quoted)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2591 (let ((position (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2592 (set-buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2593 (prog1 (current-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2594 (set-buffer byte-compile-outbuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2595
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2596 ;; Insert EXP, and make it a comment with #@LENGTH.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2597 (insert " ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2598 (if quoted
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2599 (prin1 exp byte-compile-outbuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2600 (princ exp byte-compile-outbuffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2601 (goto-char position)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2602 ;; Quote certain special characters as needed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2603 ;; get_doc_string in doc.c does the unquoting.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2604 (while (search-forward "\^A" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2605 (replace-match "\^A\^A" t t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2606 (goto-char position)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2607 (while (search-forward "\000" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2608 (replace-match "\^A0" t t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2609 (goto-char position)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2610 (while (search-forward "\037" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2611 (replace-match "\^A_" t t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2612 (goto-char (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2613 (insert "\037")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2614 (goto-char position)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2615 (insert "#@" (format "%d" (- (point-max) position)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2616
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2617 ;; Save the file position of the object.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2618 ;; Note we should add 1 to skip the space
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2619 ;; that we inserted before the actual doc string,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2620 ;; and subtract 1 to convert from an 1-origin Emacs position
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2621 ;; to a file position; they cancel.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2622 (setq position (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2623 (goto-char (point-max))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2624 position))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2625
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2626
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2627
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2628 ;; The `domain' declaration. This is legal only at top-level in a file, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2629 ;; should generally be the first form in the file. It is not legal inside
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2630 ;; function bodies.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2631
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2632 (put 'domain 'byte-hunk-handler 'byte-compile-file-form-domain)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2633 (defun byte-compile-file-form-domain (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2634 (if (not (null (cdr (cdr form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2635 (byte-compile-warn "domain used with too many arguments: %s" form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2636 (let ((domain (nth 1 form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2637 (or (null domain)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2638 (stringp domain)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2639 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2640 (byte-compile-warn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2641 "argument to `domain' declaration must be a literal string: %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2642 form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2643 (setq domain nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2644 (setq byte-compile-file-domain domain))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2645 (byte-compile-keep-pending form 'byte-compile-normal-call))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2646
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2647 (defun byte-compile-domain (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2648 (byte-compile-warn "The `domain' declaration is legal only at top-level: %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2649 (let ((print-escape-newlines t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2650 (print-level 4)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2651 (print-length 4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2652 (prin1-to-string form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2653 (byte-compile-normal-call
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2654 (list 'signal ''error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2655 (list 'quote (list "`domain' used inside a function" form)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2656
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2657 ;; This is part of bytecomp.el in 19.35:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2658 (put 'custom-declare-variable 'byte-hunk-handler
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2659 'byte-compile-file-form-custom-declare-variable)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2660 (defun byte-compile-file-form-custom-declare-variable (form)
4289
20accccbebd6 [xemacs-hg @ 2007-11-27 22:15:32 by aidan]
aidan
parents: 3948
diff changeset
2661 ;; XEmacs change; our implementation byte compiles and gives warnings
20accccbebd6 [xemacs-hg @ 2007-11-27 22:15:32 by aidan]
aidan
parents: 3948
diff changeset
2662 ;; about the default value code, which GNU's doesn't.
20accccbebd6 [xemacs-hg @ 2007-11-27 22:15:32 by aidan]
aidan
parents: 3948
diff changeset
2663 (let* ((quoted-default (car-safe (cdr-safe (cdr-safe form))))
20accccbebd6 [xemacs-hg @ 2007-11-27 22:15:32 by aidan]
aidan
parents: 3948
diff changeset
2664 (to-examine (car-safe (cdr-safe quoted-default))))
20accccbebd6 [xemacs-hg @ 2007-11-27 22:15:32 by aidan]
aidan
parents: 3948
diff changeset
2665 (if (memq 'free-vars byte-compile-warnings)
20accccbebd6 [xemacs-hg @ 2007-11-27 22:15:32 by aidan]
aidan
parents: 3948
diff changeset
2666 (setq byte-compile-bound-variables
20accccbebd6 [xemacs-hg @ 2007-11-27 22:15:32 by aidan]
aidan
parents: 3948
diff changeset
2667 (cons (cons (nth 1 (nth 1 form))
20accccbebd6 [xemacs-hg @ 2007-11-27 22:15:32 by aidan]
aidan
parents: 3948
diff changeset
2668 byte-compile-global-bit)
20accccbebd6 [xemacs-hg @ 2007-11-27 22:15:32 by aidan]
aidan
parents: 3948
diff changeset
2669 byte-compile-bound-variables)))
20accccbebd6 [xemacs-hg @ 2007-11-27 22:15:32 by aidan]
aidan
parents: 3948
diff changeset
2670 ;; Byte compile anything that smells like a lambda. I initially
20accccbebd6 [xemacs-hg @ 2007-11-27 22:15:32 by aidan]
aidan
parents: 3948
diff changeset
2671 ;; considered limiting it to the :initialize, :set and :get args, but
20accccbebd6 [xemacs-hg @ 2007-11-27 22:15:32 by aidan]
aidan
parents: 3948
diff changeset
2672 ;; that's not amazingly forward-compatible, and anyone expecting other
20accccbebd6 [xemacs-hg @ 2007-11-27 22:15:32 by aidan]
aidan
parents: 3948
diff changeset
2673 ;; things to be stored as data, not code, is unrealistic.
20accccbebd6 [xemacs-hg @ 2007-11-27 22:15:32 by aidan]
aidan
parents: 3948
diff changeset
2674 (loop
20accccbebd6 [xemacs-hg @ 2007-11-27 22:15:32 by aidan]
aidan
parents: 3948
diff changeset
2675 for entry in-ref (nthcdr 4 form)
20accccbebd6 [xemacs-hg @ 2007-11-27 22:15:32 by aidan]
aidan
parents: 3948
diff changeset
2676 do (cond ((and (eq 'function (car-safe entry))
20accccbebd6 [xemacs-hg @ 2007-11-27 22:15:32 by aidan]
aidan
parents: 3948
diff changeset
2677 (consp (car-safe (cdr-safe entry))))
20accccbebd6 [xemacs-hg @ 2007-11-27 22:15:32 by aidan]
aidan
parents: 3948
diff changeset
2678 (setf entry (copy-sequence entry))
20accccbebd6 [xemacs-hg @ 2007-11-27 22:15:32 by aidan]
aidan
parents: 3948
diff changeset
2679 (setcar (cdr entry) (byte-compile-lambda (car (cdr entry)))))
20accccbebd6 [xemacs-hg @ 2007-11-27 22:15:32 by aidan]
aidan
parents: 3948
diff changeset
2680 ((and (eq 'lambda (car-safe entry)))
20accccbebd6 [xemacs-hg @ 2007-11-27 22:15:32 by aidan]
aidan
parents: 3948
diff changeset
2681 (setf entry (byte-compile-lambda entry)))))
20accccbebd6 [xemacs-hg @ 2007-11-27 22:15:32 by aidan]
aidan
parents: 3948
diff changeset
2682 ;; Byte compile the default value, as we do for defvar.
20accccbebd6 [xemacs-hg @ 2007-11-27 22:15:32 by aidan]
aidan
parents: 3948
diff changeset
2683 (when (consp (cdr-safe to-examine))
20accccbebd6 [xemacs-hg @ 2007-11-27 22:15:32 by aidan]
aidan
parents: 3948
diff changeset
2684 (setq form (copy-sequence form))
20accccbebd6 [xemacs-hg @ 2007-11-27 22:15:32 by aidan]
aidan
parents: 3948
diff changeset
2685 (setcdr (third form)
20accccbebd6 [xemacs-hg @ 2007-11-27 22:15:32 by aidan]
aidan
parents: 3948
diff changeset
2686 (list (byte-compile-top-level to-examine nil 'file)))
20accccbebd6 [xemacs-hg @ 2007-11-27 22:15:32 by aidan]
aidan
parents: 3948
diff changeset
2687 ;; And save a value to be examined in the custom UI, if that differs
20accccbebd6 [xemacs-hg @ 2007-11-27 22:15:32 by aidan]
aidan
parents: 3948
diff changeset
2688 ;; from the init value.
20accccbebd6 [xemacs-hg @ 2007-11-27 22:15:32 by aidan]
aidan
parents: 3948
diff changeset
2689 (unless (equal to-examine (car-safe (cdr (third form))))
4304
4ac3a83867c6 [xemacs-hg @ 2007-12-04 20:35:30 by aidan]
aidan
parents: 4298
diff changeset
2690 (setcdr (third form)
4ac3a83867c6 [xemacs-hg @ 2007-12-04 20:35:30 by aidan]
aidan
parents: 4298
diff changeset
2691 (list (byte-compile-top-level
4ac3a83867c6 [xemacs-hg @ 2007-12-04 20:35:30 by aidan]
aidan
parents: 4298
diff changeset
2692 ;; This is ugly. custom-declare-variable errors if
4ac3a83867c6 [xemacs-hg @ 2007-12-04 20:35:30 by aidan]
aidan
parents: 4298
diff changeset
2693 ;; it's passed a keyword it doesn't know about, and
4ac3a83867c6 [xemacs-hg @ 2007-12-04 20:35:30 by aidan]
aidan
parents: 4298
diff changeset
2694 ;; so to make this code run on 21.4, we add code to
4ac3a83867c6 [xemacs-hg @ 2007-12-04 20:35:30 by aidan]
aidan
parents: 4298
diff changeset
2695 ;; modify the standard-value property to the
4ac3a83867c6 [xemacs-hg @ 2007-12-04 20:35:30 by aidan]
aidan
parents: 4298
diff changeset
2696 ;; byte-compiled value for DEFAULT.
4ac3a83867c6 [xemacs-hg @ 2007-12-04 20:35:30 by aidan]
aidan
parents: 4298
diff changeset
2697 `(prog2 (put ,(second form) 'standard-value
4ac3a83867c6 [xemacs-hg @ 2007-12-04 20:35:30 by aidan]
aidan
parents: 4298
diff changeset
2698 '(,to-examine))
4ac3a83867c6 [xemacs-hg @ 2007-12-04 20:35:30 by aidan]
aidan
parents: 4298
diff changeset
2699 ,to-examine)
4ac3a83867c6 [xemacs-hg @ 2007-12-04 20:35:30 by aidan]
aidan
parents: 4298
diff changeset
2700 nil 'file)))))
4289
20accccbebd6 [xemacs-hg @ 2007-11-27 22:15:32 by aidan]
aidan
parents: 3948
diff changeset
2701 form))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2702
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2703 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2704 (defun byte-compile (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2705 "If FORM is a symbol, byte-compile its function definition.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2706 If FORM is a lambda or a macro, byte-compile it as a function."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2707 (displaying-byte-compile-warnings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2708 (byte-compile-close-variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2709 (let* ((fun (if (symbolp form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2710 (and (fboundp form) (symbol-function form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2711 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2712 (macro (eq (car-safe fun) 'macro)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2713 (if macro
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2714 (setq fun (cdr fun)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2715 (cond ((eq (car-safe fun) 'lambda)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2716 (setq fun (if macro
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2717 (cons 'macro (byte-compile-lambda fun))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2718 (byte-compile-lambda fun)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2719 (if (symbolp form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2720 (defalias form fun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2721 fun)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2722
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2723 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2724 (defun byte-compile-sexp (sexp &optional msg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2725 "Compile and return SEXP."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2726 (displaying-byte-compile-warnings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2727 (byte-compile-close-variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2728 (prog1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2729 (byte-compile-top-level sexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2730 (byte-compile-warn-about-unresolved-functions msg)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2731
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2732 ;; Given a function made by byte-compile-lambda, make a form which produces it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2733 (defun byte-compile-byte-code-maker (fun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2734 (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2735 ;; ## atom is faster than compiled-func-p.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2736 ((atom fun) ; compiled-function-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2737 fun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2738 ;; b-c-lambda didn't produce a compiled-function, so it must be a trivial
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2739 ;; function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2740 ((let (tmp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2741 (if (and (setq tmp (assq 'byte-code (cdr-safe (cdr fun))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2742 (null (cdr (memq tmp fun))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2743 ;; Generate a make-byte-code call.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2744 (let* ((interactive (assq 'interactive (cdr (cdr fun)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2745 (nconc (list 'make-byte-code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2746 (list 'quote (nth 1 fun)) ;arglist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2747 (nth 1 tmp) ;instructions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2748 (nth 2 tmp) ;constants
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2749 (nth 3 tmp)) ;stack-depth
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2750 (cond ((stringp (nth 2 fun))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2751 (list (nth 2 fun))) ;docstring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2752 (interactive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2753 (list nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2754 (cond (interactive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2755 (list (if (or (null (nth 1 interactive))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2756 (stringp (nth 1 interactive)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2757 (nth 1 interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2758 ;; Interactive spec is a list or a variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2759 ;; (if it is correct).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2760 (list 'quote (nth 1 interactive))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2761 ;; a non-compiled function (probably trivial)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2762 (list 'quote fun))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2763
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2764 ;; Byte-compile a lambda-expression and return a valid function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2765 ;; The value is usually a compiled function but may be the original
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2766 ;; lambda-expression.
5593
4218b56833b3 Give the label name when warning or erroring, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5579
diff changeset
2767 (defun byte-compile-lambda (fun &optional name)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2768 (or (eq 'lambda (car-safe fun))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2769 (error "not a lambda -- %s" (prin1-to-string fun)))
5593
4218b56833b3 Give the label name when warning or erroring, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5579
diff changeset
2770 (let* ((byte-compile-current-form (or name byte-compile-current-form))
4218b56833b3 Give the label name when warning or erroring, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5579
diff changeset
2771 (arglist (nth 1 fun))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2772 (byte-compile-bound-variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2773 (let ((new-bindings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2774 (mapcar #'(lambda (x) (cons x byte-compile-arglist-bit))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2775 (and (memq 'free-vars byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2776 (delq '&rest (delq '&optional
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2777 (copy-sequence arglist)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2778 (nconc new-bindings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2779 (cons 'new-scope byte-compile-bound-variables))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2780 (body (cdr (cdr fun)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2781 (doc (if (stringp (car body))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2782 (prog1 (car body)
1548
5365af805d4c [xemacs-hg @ 2003-06-30 09:24:47 by stephent]
stephent
parents: 1315
diff changeset
2783 ;; Discard the doc string
5365af805d4c [xemacs-hg @ 2003-06-30 09:24:47 by stephent]
stephent
parents: 1315
diff changeset
2784 ;; only if it is not the only element of the body.
5365af805d4c [xemacs-hg @ 2003-06-30 09:24:47 by stephent]
stephent
parents: 1315
diff changeset
2785 (if (cdr body)
5365af805d4c [xemacs-hg @ 2003-06-30 09:24:47 by stephent]
stephent
parents: 1315
diff changeset
2786 (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
2787 (int (assq 'interactive body)) compiled-int)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2788 (dolist (arg arglist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2789 (cond ((not (symbolp arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2790 (byte-compile-warn "non-symbol in arglist: %S" arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2791 ((byte-compile-constant-symbol-p arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2792 (byte-compile-warn "constant symbol in arglist: %s" arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2793 ((and (char= ?\& (aref (symbol-name arg) 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2794 (not (eq arg '&optional))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2795 (not (eq arg '&rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2796 (byte-compile-warn "unrecognized `&' keyword in arglist: %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2797 arg))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2798 (cond (int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2799 ;; Skip (interactive) if it is in front (the most usual location).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2800 (if (eq int (car body))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2801 (setq body (cdr body)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2802 (cond ((consp (cdr int))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2803 (if (cdr (cdr int))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2804 (byte-compile-warn "malformed interactive spec: %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2805 (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
2806 ;; 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
2807 ;; 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
2808 ;; 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
2809 ;; 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
2810 ;; useful for warnings.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2811 (let ((form (nth 1 int)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2812 (while (or (eq (car-safe form) 'let)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2813 (eq (car-safe form) 'let*)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2814 (eq (car-safe form) 'save-excursion))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2815 (while (consp (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2816 (setq form (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2817 (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
2818 (setq compiled-int
7757334005ae bytecomp.el: always check code in (interactive SEXP) for sanity
Aidan Kehoe <kehoea@parhasard.net>
parents: 4623
diff changeset
2819 (byte-compile-top-level (nth 1 int)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2820 (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
2821 (setq int (list 'interactive compiled-int)))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2822 ((cdr int)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2823 (byte-compile-warn "malformed interactive spec: %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2824 (prin1-to-string int))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2825 (let ((compiled (byte-compile-top-level (cons 'progn body) nil 'lambda)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2826 (if (memq 'unused-vars byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2827 ;; done compiling in this scope, warn now.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2828 (byte-compile-warn-about-unused-variables))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2829 (if (eq 'byte-code (car-safe compiled))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2830 (apply 'make-byte-code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2831 (append (list arglist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2832 ;; byte-string, constants-vector, stack depth
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2833 (cdr compiled)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2834 ;; optionally, the doc string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2835 (if (or doc int)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2836 (list doc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2837 ;; optionally, the interactive spec.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2838 (if int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2839 (list (nth 1 int)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2840 (setq compiled
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2841 (nconc (if int (list int))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2842 (cond ((eq (car-safe compiled) 'progn) (cdr compiled))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2843 (compiled (list compiled)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2844 (nconc (list 'lambda arglist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2845 (if (or doc (stringp (car compiled)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2846 (cons doc (cond (compiled)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2847 (body (list nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2848 compiled))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2849
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2850 (defun byte-compile-constants-vector ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2851 ;; Builds the constants-vector from the current variables and constants.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2852 ;; This modifies the constants from (const . nil) to (const . offset).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2853 ;; To keep the byte-codes to look up the vector as short as possible:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2854 ;; First 6 elements are vars, as there are one-byte varref codes for those.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2855 ;; Next up to byte-constant-limit are constants, still with one-byte codes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2856 ;; Next variables again, to get 2-byte codes for variable lookup.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2857 ;; The rest of the constants and variables need 3-byte byte-codes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2858 (let* ((i -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2859 (rest (nreverse byte-compile-variables)) ; nreverse because the first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2860 (other (nreverse byte-compile-constants)) ; vars often are used most.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2861 ret tmp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2862 (limits '(5 ; Use the 1-byte varref codes,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2863 63 ; 1-constlim ; 1-byte byte-constant codes,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2864 255 ; 2-byte varref codes,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2865 65535)) ; 3-byte codes for the rest.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2866 limit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2867 (while (or rest other)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2868 (setq limit (car limits))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2869 (while (and rest (not (eq i limit)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2870 (if (setq tmp (assq (car (car rest)) ret))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2871 (setcdr (car rest) (cdr tmp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2872 (setcdr (car rest) (setq i (1+ i)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2873 (setq ret (cons (car rest) ret)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2874 (setq rest (cdr rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2875 (setq limits (cdr limits)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2876 rest (prog1 other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2877 (setq other rest))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2878 (apply 'vector (nreverse (mapcar 'car ret)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2879
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2880 ;; Given an expression FORM, compile it and return an equivalent byte-code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2881 ;; expression (a call to the function byte-code).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2882 (defun byte-compile-top-level (form &optional for-effect output-type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2883 ;; OUTPUT-TYPE advises about how form is expected to be used:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2884 ;; 'eval or nil -> a single form,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2885 ;; 'progn or t -> a list of forms,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2886 ;; 'lambda -> body of a lambda,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2887 ;; 'file -> used at file-level.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2888 (let ((byte-compile-constants nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2889 (byte-compile-variables nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2890 (byte-compile-tag-number 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2891 (byte-compile-depth 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2892 (byte-compile-maxdepth 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2893 (byte-compile-output nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2894 (if (memq byte-optimize '(t source))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2895 (setq form (byte-optimize-form form for-effect)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2896 (while (and (eq (car-safe form) 'progn) (null (cdr (cdr form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2897 (setq form (nth 1 form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2898 (if (and (eq 'byte-code (car-safe form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2899 (not (memq byte-optimize '(t byte)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2900 (stringp (nth 1 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2901 (vectorp (nth 2 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2902 (natnump (nth 3 form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2903 form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2904 (byte-compile-form form for-effect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2905 (byte-compile-out-toplevel for-effect output-type))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2906
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2907 (defun byte-compile-out-toplevel (&optional for-effect output-type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2908 (if for-effect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2909 ;; The stack is empty. Push a value to be returned from (byte-code ..).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2910 (if (eq (car (car byte-compile-output)) 'byte-discard)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2911 (setq byte-compile-output (cdr byte-compile-output))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2912 (byte-compile-push-constant
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2913 ;; Push any constant - preferably one which already is used, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2914 ;; a number or symbol - ie not some big sequence. The return value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2915 ;; isn't returned, but it would be a shame if some textually large
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2916 ;; constant was not optimized away because we chose to return it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2917 (and (not (assq nil byte-compile-constants)) ; Nil is often there.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2918 (let ((tmp (reverse byte-compile-constants)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2919 (while (and tmp (not (or (symbolp (car (car tmp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2920 (numberp (car (car tmp))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2921 (setq tmp (cdr tmp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2922 (car (car tmp)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2923 (byte-compile-out 'byte-return 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2924 (setq byte-compile-output (nreverse byte-compile-output))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2925 (if (memq byte-optimize '(t byte))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2926 (setq byte-compile-output
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2927 (byte-optimize-lapcode byte-compile-output for-effect)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2928
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2929 ;; Decompile trivial functions:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2930 ;; only constants and variables, or a single funcall except in lambdas.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2931 ;; Except for Lisp_Compiled objects, forms like (foo "hi")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2932 ;; are still quicker than (byte-code "..." [foo "hi"] 2).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2933 ;; Note that even (quote foo) must be parsed just as any subr by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2934 ;; interpreter, so quote should be compiled into byte-code in some contexts.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2935 ;; What to leave uncompiled:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2936 ;; lambda -> never. we used to leave it uncompiled if the body was
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2937 ;; a single atom, but that causes confusion if the docstring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2938 ;; uses the (file . pos) syntax. Besides, now that we have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2939 ;; the Lisp_Compiled type, the compiled form is faster.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2940 ;; eval -> atom, quote or (function atom atom atom)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2941 ;; progn -> as <<same-as-eval>> or (progn <<same-as-eval>> atom)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2942 ;; file -> as progn, but takes both quotes and atoms, and longer forms.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2943 (let (rest
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2944 (maycall (not (eq output-type 'lambda))) ; t if we may make a funcall.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2945 tmp body)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2946 (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2947 ;; #### This should be split out into byte-compile-nontrivial-function-p.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2948 ((or (eq output-type 'lambda)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2949 (nthcdr (if (eq output-type 'file) 50 8) byte-compile-output)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2950 (assq 'TAG byte-compile-output) ; Not necessary, but speeds up a bit.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2951 (not (setq tmp (assq 'byte-return byte-compile-output)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2952 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2953 (setq rest (nreverse
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2954 (cdr (memq tmp (reverse byte-compile-output)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2955 (while (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2956 ((memq (car (car rest)) '(byte-varref byte-constant))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2957 (setq tmp (car (cdr (car rest))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2958 (if (if (eq (car (car rest)) 'byte-constant)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2959 (or (consp tmp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2960 (and (symbolp tmp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2961 (not (byte-compile-constant-symbol-p tmp)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2962 (if maycall
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2963 (setq body (cons (list 'quote tmp) body)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2964 (setq body (cons tmp body))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2965 ((and maycall
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2966 ;; Allow a funcall if at most one atom follows it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2967 (null (nthcdr 3 rest))
5503
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
2968 (setq tmp (get (car (car rest)) 'byte-opcode-invert))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2969 (or (null (cdr rest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2970 (and (memq output-type '(file progn t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2971 (cdr (cdr rest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2972 (eq (car (nth 1 rest)) 'byte-discard)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2973 (progn (setq rest (cdr rest)) t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2974 (setq maycall nil) ; Only allow one real function call.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2975 (setq body (nreverse body))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2976 (setq body (list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2977 (if (and (eq tmp 'funcall)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2978 (eq (car-safe (car body)) 'quote))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2979 (cons (nth 1 (car body)) (cdr body))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2980 (cons tmp body))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2981 (or (eq output-type 'file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2982 (not (delq nil (mapcar 'consp (cdr (car body))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2983 (setq rest (cdr rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2984 rest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2985 (let ((byte-compile-vector (byte-compile-constants-vector)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2986 (list 'byte-code (byte-compile-lapcode byte-compile-output)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2987 byte-compile-vector byte-compile-maxdepth)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2988 ;; it's a trivial function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2989 ((cdr body) (cons 'progn (nreverse body)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2990 ((car body)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2991
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2992 ;; Given BODY, compile it and return a new body.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2993 (defun byte-compile-top-level-body (body &optional for-effect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2994 (setq body (byte-compile-top-level (cons 'progn body) for-effect t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2995 (cond ((eq (car-safe body) 'progn)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2996 (cdr body))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2997 (body
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2998 (list body))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2999
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3000 ;; This is the recursive entry point for compiling each subform of an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3001 ;; expression.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3002 ;; If for-effect is non-nil, byte-compile-form will output a byte-discard
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3003 ;; before terminating (ie. no value will be left on the stack).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3004 ;; A byte-compile handler may, when for-effect is non-nil, choose output code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3005 ;; which does not leave a value on the stack, and then set for-effect to nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3006 ;; (to prevent byte-compile-form from outputting the byte-discard).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3007 ;; If a handler wants to call another handler, it should do so via
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3008 ;; byte-compile-form, or take extreme care to handle for-effect correctly.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3009 ;; (Use byte-compile-form-do-effect to reset the for-effect flag too.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3010 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3011 (defun byte-compile-form (form &optional for-effect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3012 (setq form (macroexpand form byte-compile-macro-environment))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3013 (cond ((not (consp form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3014 (cond ((or (not (symbolp form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3015 (byte-compile-constant-symbol-p form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3016 (byte-compile-constant form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3017 ((and for-effect byte-compile-delete-errors)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3018 (setq for-effect nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3019 (t (byte-compile-variable-ref 'byte-varref form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3020 ((symbolp (car form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3021 (let* ((fn (car form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3022 (handler (get fn 'byte-compile)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3023 (if (memq fn '(t nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3024 (byte-compile-warn "%s called as a function" fn))
5503
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
3025 (if handler
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3026 (funcall handler form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3027 (if (memq 'callargs byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3028 (byte-compile-callargs-warn form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3029 (byte-compile-normal-call form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3030 ((and (or (compiled-function-p (car form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3031 (eq (car-safe (car form)) 'lambda))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3032 ;; if the form comes out the same way it went in, that's
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3033 ;; because it was malformed, and we couldn't unfold it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3034 (not (eq form (setq form (byte-compile-unfold-lambda form)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3035 (byte-compile-form form for-effect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3036 (setq for-effect nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3037 ((byte-compile-normal-call form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3038 (when for-effect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3039 (byte-compile-discard)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3040
5294
bbff29a01820 Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5282
diff changeset
3041 ;; 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
3042 ;;
bbff29a01820 Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5282
diff changeset
3043 ;; (delete-duplicates
bbff29a01820 Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5282
diff changeset
3044 ;; (sort*
bbff29a01820 Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5282
diff changeset
3045 ;; (loop
bbff29a01820 Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5282
diff changeset
3046 ;; 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
3047 ;; with arglist = nil
bbff29a01820 Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5282
diff changeset
3048 ;; 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
3049 ;; (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
3050 ;; (cond
bbff29a01820 Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5282
diff changeset
3051 ;; ((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
3052 ;; ((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
3053 ;; (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
3054 ;; (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
3055 ;; (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
3056 ;; (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
3057 ;; (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
3058 ;; 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
3059 ;; #'string-lessp
bbff29a01820 Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5282
diff changeset
3060 ;; :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
3061 ;;
bbff29a01820 Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5282
diff changeset
3062 ;; 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
3063 ;; 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
3064
bbff29a01820 Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5282
diff changeset
3065 (map nil
bbff29a01820 Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5282
diff changeset
3066 (function*
bbff29a01820 Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5282
diff changeset
3067 (lambda ((function . nargs))
bbff29a01820 Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5282
diff changeset
3068 ;; 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
3069 ;; 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
3070 ;; 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
3071 (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
3072 '((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
3073 (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
3074 (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
3075 (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
3076 (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
3077 (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
3078 (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
3079 (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
3080 (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
3081 (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
3082 (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
3083 (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
3084 (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
3085 (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
3086 (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
3087 (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
3088 (tree-equal . 3)))
bbff29a01820 Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5282
diff changeset
3089
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3090 (defun byte-compile-normal-call (form)
5358
31475de17064 #'byte-compile-normal-call; only examine properties of (car FORM) if a symbol
Aidan Kehoe <kehoea@parhasard.net>
parents: 5356
diff changeset
3091 (and (symbolp (car form)) (get (car form) 'byte-compile-keyword-start)
5294
bbff29a01820 Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5282
diff changeset
3092 (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
3093 form)))
bbff29a01820 Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5282
diff changeset
3094 (symbol-macrolet
bbff29a01820 Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5282
diff changeset
3095 ((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
3096 (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
3097 (byte-compile-warn
bbff29a01820 Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5282
diff changeset
3098 "#'%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
3099 (and
bbff29a01820 Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5282
diff changeset
3100 (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
3101 (map nil
bbff29a01820 Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5282
diff changeset
3102 (function*
bbff29a01820 Add compiler macros and compilation sanity-checks for functions with keywords.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5282
diff changeset
3103 (lambda ((function . nargs))
5548
b90c153730c7 Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5506
diff changeset
3104 (let ((value (plist-get plist function not-present)))
b90c153730c7 Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5506
diff changeset
3105 (when (and (not (eq value not-present))
b90c153730c7 Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5506
diff changeset
3106 (byte-compile-constp value))
b90c153730c7 Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5506
diff changeset
3107 (byte-compile-callargs-warn
b90c153730c7 Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5506
diff changeset
3108 (cons (eval value)
b90c153730c7 Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5506
diff changeset
3109 (member*
b90c153730c7 Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5506
diff changeset
3110 nargs
b90c153730c7 Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5506
diff changeset
3111 ;; Dummy arguments. There's no need for
b90c153730c7 Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5506
diff changeset
3112 ;; it to be longer than even 2, now, but
b90c153730c7 Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5506
diff changeset
3113 ;; very little harm in it.
b90c153730c7 Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5506
diff changeset
3114 '(9 8 7 6 5 4 3 2 1))))
b90c153730c7 Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5506
diff changeset
3115 (when (and (eq (car-safe value) 'quote)
b90c153730c7 Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5506
diff changeset
3116 (eq (car-safe (nth 1 value)) 'lambda)
b90c153730c7 Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5506
diff changeset
3117 (or
b90c153730c7 Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5506
diff changeset
3118 (null (memq 'quoted-lambda
b90c153730c7 Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5506
diff changeset
3119 byte-compile-warnings))
b90c153730c7 Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5506
diff changeset
3120 (byte-compile-warn
b90c153730c7 Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5506
diff changeset
3121 "Passing a quoted lambda to #'%s, \
b90c153730c7 Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5506
diff changeset
3122 keyword %s, forcing function quoting" (car form) function)))
b90c153730c7 Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5506
diff changeset
3123 (setcar value 'function))))))
b90c153730c7 Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5506
diff changeset
3124 '((:key . 1) (:test . 2) (:test-not . 2) (:if . 1)
b90c153730c7 Do the quoted-lambda check when functions take :if, :test, :key arguments, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5506
diff changeset
3125 (:if-not . 1))))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3126 (if byte-compile-generate-call-tree
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3127 (byte-compile-annotate-call-tree form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3128 (byte-compile-push-constant (car form))
4783
e29fcfd8df5f Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4775
diff changeset
3129 (mapc 'byte-compile-form (cdr form)) ; wasteful, but faster.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3130 (byte-compile-out 'byte-call (length (cdr form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3131
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3132 ;; kludge added to XEmacs to work around the bogosities of a nonlexical lisp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3133 (or (fboundp 'globally-boundp) (fset 'globally-boundp 'boundp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3134
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3135 (defun byte-compile-variable-ref (base-op var &optional varbind-flags)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3136 (if (or (not (symbolp var)) (byte-compile-constant-symbol-p var))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3137 (byte-compile-warn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3138 (case base-op
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3139 (byte-varref "Variable reference to %s %s")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3140 (byte-varset "Attempt to set %s %s")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3141 (byte-varbind "Attempt to let-bind %s %s"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3142 (if (symbolp var) "constant symbol" "non-symbol")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3143 var)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3144 (if (and (get var 'byte-obsolete-variable)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3145 (memq 'obsolete byte-compile-warnings))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3146 (let ((ob (get var 'byte-obsolete-variable)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3147 (byte-compile-warn "%s is an obsolete variable; %s" var
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3148 (if (stringp ob)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3149 ob
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3150 (format "use %s instead." ob)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3151 (if (and (get var 'byte-compatible-variable)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3152 (memq 'pedantic byte-compile-warnings))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3153 (let ((ob (get var 'byte-compatible-variable)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3154 (byte-compile-warn "%s is provided for compatibility; %s" var
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3155 (if (stringp ob)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3156 ob
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3157 (format "use %s instead." ob)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3158 (if (memq 'free-vars byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3159 (if (eq base-op 'byte-varbind)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3160 (setq byte-compile-bound-variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3161 (cons (cons var (or varbind-flags 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3162 byte-compile-bound-variables))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3163 (or (globally-boundp var)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3164 (let ((cell (assq var byte-compile-bound-variables)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3165 (if cell (setcdr cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3166 (logior (cdr cell)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3167 (if (eq base-op 'byte-varset)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3168 byte-compile-assigned-bit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3169 byte-compile-referenced-bit)))))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3170 (and (boundp 'current-load-list)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3171 (memq var current-load-list))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3172 (if (eq base-op 'byte-varset)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3173 (or (memq var byte-compile-free-assignments)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3174 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3175 (byte-compile-warn "assignment to free variable %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3176 var)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3177 (setq byte-compile-free-assignments
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3178 (cons var byte-compile-free-assignments))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3179 (or (memq var byte-compile-free-references)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3180 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3181 (byte-compile-warn "reference to free variable %s" var)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3182 (setq byte-compile-free-references
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3183 (cons var byte-compile-free-references)))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3184 (let ((tmp (assq var byte-compile-variables)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3185 (or tmp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3186 (setq tmp (list var)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3187 byte-compile-variables (cons tmp byte-compile-variables)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3188 (byte-compile-out base-op tmp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3189
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3190 (defmacro byte-compile-get-constant (const)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3191 `(or (if (stringp ,const)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3192 (assoc ,const byte-compile-constants)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3193 (assq ,const byte-compile-constants))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3194 (car (setq byte-compile-constants
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3195 (cons (list ,const) byte-compile-constants)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3196
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3197 ;; Use this when the value of a form is a constant. This obeys for-effect.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3198 (defun byte-compile-constant (const)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3199 (if for-effect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3200 (setq for-effect nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3201 (byte-compile-out 'byte-constant (byte-compile-get-constant const))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3202
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3203 ;; Use this for a constant that is not the value of its containing form.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3204 ;; This ignores for-effect.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3205 (defun byte-compile-push-constant (const)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3206 (let ((for-effect nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3207 (inline (byte-compile-constant const))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3208
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3209
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3210 ;; Compile those primitive ordinary functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3211 ;; which have special byte codes just for speed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3212
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3213 (defmacro byte-defop-compiler (function &optional compile-handler)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3214 ;; add a compiler-form for FUNCTION.
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3215 ;; If FUNCTION is a symbol, then the variable "byte-SYMBOL" must name
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3216 ;; the opcode to be used. If is a list, the first element
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3217 ;; is the function and the second element is the bytecode-symbol.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3218 ;; COMPILE-HANDLER is the function to use to compile this byte-op, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3219 ;; may be the abbreviations 0, 1, 2, 3, 0-1, 1-2, 2-3, 0+1, 1+1, 2+1,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3220 ;; 0-1+1, 1-2+1, 2-3+1, 0+2, or 1+2. If it is nil, then the handler is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3221 ;; "byte-compile-SYMBOL."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3222 (let (opcode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3223 (if (symbolp function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3224 (setq opcode (intern (concat "byte-" (symbol-name function))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3225 (setq opcode (car (cdr function))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3226 function (car function)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3227 (let ((fnform
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3228 (list 'put (list 'quote function) ''byte-compile
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3229 (list 'quote
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3230 (or (cdr (assq compile-handler
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3231 '((0 . byte-compile-no-args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3232 (1 . byte-compile-one-arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3233 (2 . byte-compile-two-args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3234 (3 . byte-compile-three-args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3235 (0-1 . byte-compile-zero-or-one-arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3236 (1-2 . byte-compile-one-or-two-args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3237 (2-3 . byte-compile-two-or-three-args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3238 (0+1 . byte-compile-no-args-with-one-extra)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3239 (1+1 . byte-compile-one-arg-with-one-extra)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3240 (2+1 . byte-compile-two-args-with-one-extra)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3241 (0-1+1 . byte-compile-zero-or-one-arg-with-one-extra)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3242 (1-2+1 . byte-compile-one-or-two-args-with-one-extra)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3243 (2-3+1 . byte-compile-two-or-three-args-with-one-extra)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3244 (0+2 . byte-compile-no-args-with-two-extra)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3245 (1+2 . byte-compile-one-arg-with-two-extra)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3246
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3247 )))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3248 compile-handler
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3249 (intern (concat "byte-compile-"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3250 (symbol-name function))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3251 (if opcode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3252 (list 'progn fnform
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3253 (list 'put (list 'quote function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3254 ''byte-opcode (list 'quote opcode))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3255 (list 'put (list 'quote opcode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3256 ''byte-opcode-invert (list 'quote function)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3257 fnform))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3258
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3259 (defmacro byte-defop-compiler-1 (function &optional compile-handler)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3260 (list 'byte-defop-compiler (list function nil) compile-handler))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3261
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3262
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3263 (put 'byte-call 'byte-opcode-invert 'funcall)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3264 (put 'byte-list1 'byte-opcode-invert 'list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3265 (put 'byte-list2 'byte-opcode-invert 'list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3266 (put 'byte-list3 'byte-opcode-invert 'list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3267 (put 'byte-list4 'byte-opcode-invert 'list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3268 (put 'byte-listN 'byte-opcode-invert 'list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3269 (put 'byte-concat2 'byte-opcode-invert 'concat)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3270 (put 'byte-concat3 'byte-opcode-invert 'concat)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3271 (put 'byte-concat4 'byte-opcode-invert 'concat)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3272 (put 'byte-concatN 'byte-opcode-invert 'concat)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3273 (put 'byte-insertN 'byte-opcode-invert 'insert)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3274
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3275 ;; How old is this stuff? -slb
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3276 ;(byte-defop-compiler (dot byte-point) 0+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3277 ;(byte-defop-compiler (dot-max byte-point-max) 0+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3278 ;(byte-defop-compiler (dot-min byte-point-min) 0+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3279 (byte-defop-compiler point 0+1)
5503
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
3280 (byte-defop-compiler eq 2)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3281 (byte-defop-compiler point-max 0+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3282 (byte-defop-compiler point-min 0+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3283 (byte-defop-compiler following-char 0+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3284 (byte-defop-compiler preceding-char 0+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3285 (byte-defop-compiler current-column 0+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3286 ;; FSF has special function here; generalized here by the 1+2 stuff.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3287 (byte-defop-compiler (indent-to-column byte-indent-to) 1+2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3288 (byte-defop-compiler indent-to 1+2)
5503
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
3289 (byte-defop-compiler equal 2)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3290 (byte-defop-compiler eolp 0+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3291 (byte-defop-compiler eobp 0+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3292 (byte-defop-compiler bolp 0+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3293 (byte-defop-compiler bobp 0+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3294 (byte-defop-compiler current-buffer 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3295 ;;(byte-defop-compiler read-char 0) ;; obsolete
5503
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
3296 (byte-defop-compiler memq 2)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3297 (byte-defop-compiler interactive-p 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3298 (byte-defop-compiler widen 0+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3299 (byte-defop-compiler end-of-line 0-1+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3300 (byte-defop-compiler forward-char 0-1+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3301 (byte-defop-compiler forward-line 0-1+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3302 (byte-defop-compiler symbolp 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3303 (byte-defop-compiler consp 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3304 (byte-defop-compiler stringp 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3305 (byte-defop-compiler listp 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3306 (byte-defop-compiler not 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3307 (byte-defop-compiler (null byte-not) 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3308 (byte-defop-compiler car 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3309 (byte-defop-compiler cdr 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3310 (byte-defop-compiler length 1)
5562
855b667dea13 Drop cl-macro-environment in favour of byte-compile-macro-environment.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5560
diff changeset
3311 (byte-defop-compiler symbol-value 1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3312 (byte-defop-compiler symbol-function 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3313 (byte-defop-compiler (1+ byte-add1) 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3314 (byte-defop-compiler (1- byte-sub1) 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3315 (byte-defop-compiler goto-char 1+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3316 (byte-defop-compiler char-after 0-1+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3317 (byte-defop-compiler set-buffer 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3318 ;;(byte-defop-compiler set-mark 1) ;; obsolete
2217
701dcae521bd [xemacs-hg @ 2004-08-13 21:19:14 by james]
james
parents: 1672
diff changeset
3319 (byte-defop-compiler forward-word 0-1+1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3320 (byte-defop-compiler char-syntax 1+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3321 (byte-defop-compiler nreverse 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3322 (byte-defop-compiler car-safe 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3323 (byte-defop-compiler cdr-safe 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3324 (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
3325 (byte-defop-compiler fixnump 1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3326 (byte-defop-compiler skip-chars-forward 1-2+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3327 (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
3328 (byte-defop-compiler eq 2)
5503
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
3329 ; (byte-defop-compiler old-eq 2)
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
3330 ; (byte-defop-compiler old-memq 2)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3331 (byte-defop-compiler cons 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3332 (byte-defop-compiler aref 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3333 (byte-defop-compiler get 2+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3334 (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
3335 (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
3336 (byte-defop-compiler (substring byte-subseq) 2-3)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3337 (byte-defop-compiler (move-marker byte-set-marker) 2-3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3338 (byte-defop-compiler set-marker 2-3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3339 (byte-defop-compiler match-beginning 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3340 (byte-defop-compiler match-end 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3341 (byte-defop-compiler upcase 1+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3342 (byte-defop-compiler downcase 1+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3343 (byte-defop-compiler string= 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3344 (byte-defop-compiler string< 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3345 (byte-defop-compiler (string-equal byte-string=) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3346 (byte-defop-compiler (string-lessp byte-string<) 2)
5503
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
3347 ; (byte-defop-compiler old-equal 2)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3348 (byte-defop-compiler nthcdr 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3349 (byte-defop-compiler elt 2)
5503
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
3350 (byte-defop-compiler old-member 2)
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
3351 (byte-defop-compiler old-assq 2)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3352 (byte-defop-compiler (rplaca byte-setcar) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3353 (byte-defop-compiler (rplacd byte-setcdr) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3354 (byte-defop-compiler setcar 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3355 (byte-defop-compiler setcdr 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3356 (byte-defop-compiler delete-region 2+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3357 (byte-defop-compiler narrow-to-region 2+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3358 (byte-defop-compiler (% byte-rem) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3359 (byte-defop-compiler aset 3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3360
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
3361 (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
3362 (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
3363 (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
3364 (byte-defop-compiler throw)
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
3365
5503
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
3366 (byte-defop-compiler member 2)
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
3367 (byte-defop-compiler assq 2)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3368
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3369 ;;####(byte-defop-compiler move-to-column 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3370 (byte-defop-compiler-1 interactive byte-compile-noop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3371 (byte-defop-compiler-1 domain byte-compile-domain)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3372
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3373 ;; As of GNU Emacs 19.18 and Lucid Emacs 19.8, mod and % are different: `%'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3374 ;; means integral remainder and may have a negative result; `mod' is always
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3375 ;; positive, and accepts floating point args. All code which uses `mod' and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3376 ;; requires the new interpretation must be compiled with bytecomp version 2.18
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3377 ;; or newer, or the emitted code will run the byte-code for `%' instead of an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3378 ;; actual call to `mod'. So be careful of compiling new code with an old
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3379 ;; compiler. Note also that `%' is more efficient than `mod' because the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3380 ;; former is byte-coded and the latter is not.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3381 ;;(byte-defop-compiler (mod byte-rem) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3382
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3383
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
3384 (defun byte-compile-warn-wrong-args (form n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3385 (when (memq 'subr-callargs byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3386 (byte-compile-warn "%s called with %d arg%s, but requires %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3387 (car form) (length (cdr form))
5366
f00192e1cd49 Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents: 5358
diff changeset
3388 (if (eql 1 (length (cdr form))) "" "s") n)))
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
3389
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
3390 (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
3391 (byte-compile-warn-wrong-args form n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3392 ;; get run-time wrong-number-of-args error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3393 (byte-compile-normal-call form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3394
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3395 (defun byte-compile-no-args (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3396 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3397 (0 (byte-compile-out (get (car form) 'byte-opcode) 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3398 (t (byte-compile-subr-wrong-args form "none"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3399
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3400 (defun byte-compile-one-arg (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3401 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3402 (1 (byte-compile-form (car (cdr form))) ;; Push the argument
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3403 (byte-compile-out (get (car form) 'byte-opcode) 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3404 (t (byte-compile-subr-wrong-args form 1))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3405
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3406 (defun byte-compile-two-args (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3407 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3408 (2 (byte-compile-form (nth 1 form)) ;; Push the arguments
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3409 (byte-compile-form (nth 2 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3410 (byte-compile-out (get (car form) 'byte-opcode) 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3411 (t (byte-compile-subr-wrong-args form 2))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3412
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3413 (defun byte-compile-three-args (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3414 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3415 (3 (byte-compile-form (nth 1 form)) ;; Push the arguments
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3416 (byte-compile-form (nth 2 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3417 (byte-compile-form (nth 3 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3418 (byte-compile-out (get (car form) 'byte-opcode) 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3419 (t (byte-compile-subr-wrong-args form 3))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3420
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3421 (defun byte-compile-zero-or-one-arg (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3422 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3423 (0 (byte-compile-one-arg (append form '(nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3424 (1 (byte-compile-one-arg form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3425 (t (byte-compile-subr-wrong-args form "0-1"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3426
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3427 (defun byte-compile-one-or-two-args (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3428 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3429 (1 (byte-compile-two-args (append form '(nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3430 (2 (byte-compile-two-args form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3431 (t (byte-compile-subr-wrong-args form "1-2"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3432
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3433 (defun byte-compile-two-or-three-args (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3434 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3435 (2 (byte-compile-three-args (append form '(nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3436 (3 (byte-compile-three-args form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3437 (t (byte-compile-subr-wrong-args form "2-3"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3438
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3439 ;; from Ben Wing <ben@xemacs.org>: some inlined functions have extra
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3440 ;; optional args added to them in XEmacs 19.12. Changing the byte
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3441 ;; interpreter to deal with these args would be wrong and cause
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3442 ;; incompatibility, so we generate non-inlined calls for those cases.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3443 ;; Without the following functions, spurious warnings will be generated;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3444 ;; however, they would still compile correctly because
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3445 ;; `byte-compile-subr-wrong-args' also converts the call to non-inlined.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3446
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3447 (defun byte-compile-no-args-with-one-extra (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3448 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3449 (0 (byte-compile-no-args form))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3450 (1 (if (eq nil (nth 1 form))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3451 (byte-compile-no-args (butlast form))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3452 (byte-compile-normal-call form)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3453 (t (byte-compile-subr-wrong-args form "0-1"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3454
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3455 (defun byte-compile-one-arg-with-one-extra (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3456 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3457 (1 (byte-compile-one-arg form))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3458 (2 (if (eq nil (nth 2 form))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3459 (byte-compile-one-arg (butlast form))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3460 (byte-compile-normal-call form)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3461 (t (byte-compile-subr-wrong-args form "1-2"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3462
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3463 (defun byte-compile-two-args-with-one-extra (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3464 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3465 (2 (byte-compile-two-args form))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3466 (3 (if (eq nil (nth 3 form))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3467 (byte-compile-two-args (butlast form))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3468 (byte-compile-normal-call form)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3469 (t (byte-compile-subr-wrong-args form "2-3"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3470
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3471 (defun byte-compile-zero-or-one-arg-with-one-extra (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3472 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3473 (0 (byte-compile-one-arg (append form '(nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3474 (1 (byte-compile-one-arg form))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3475 (2 (if (eq nil (nth 2 form))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3476 (byte-compile-one-arg (butlast form))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3477 (byte-compile-normal-call form)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3478 (t (byte-compile-subr-wrong-args form "0-2"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3479
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3480 (defun byte-compile-one-or-two-args-with-one-extra (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3481 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3482 (1 (byte-compile-two-args (append form '(nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3483 (2 (byte-compile-two-args form))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3484 (3 (if (eq nil (nth 3 form))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3485 (byte-compile-two-args (butlast form))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3486 (byte-compile-normal-call form)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3487 (t (byte-compile-subr-wrong-args form "1-3"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3488
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3489 (defun byte-compile-two-or-three-args-with-one-extra (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3490 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3491 (2 (byte-compile-three-args (append form '(nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3492 (3 (byte-compile-three-args form))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3493 (4 (if (eq nil (nth 4 form))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3494 (byte-compile-three-args (butlast form))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3495 (byte-compile-normal-call form)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3496 (t (byte-compile-subr-wrong-args form "2-4"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3497
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3498 (defun byte-compile-no-args-with-two-extra (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3499 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3500 (0 (byte-compile-no-args form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3501 ((1 2) (byte-compile-normal-call form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3502 (t (byte-compile-subr-wrong-args form "0-2"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3503
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3504 (defun byte-compile-one-arg-with-two-extra (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3505 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3506 (1 (byte-compile-one-arg form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3507 ((2 3) (byte-compile-normal-call form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3508 (t (byte-compile-subr-wrong-args form "1-3"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3509
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3510 (defun byte-compile-noop (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3511 (byte-compile-constant nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3512
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3513 (defun byte-compile-discard ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3514 (byte-compile-out 'byte-discard 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3515
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3516 (defun byte-compile-max (form)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3517 (let ((args (cdr form)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3518 (case (length args)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3519 (0 (byte-compile-subr-wrong-args form "1 or more"))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3520 (1 (byte-compile-form (car args))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3521 (when (not byte-compile-delete-errors)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3522 (byte-compile-out 'byte-dup 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3523 (byte-compile-out 'byte-max 0)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3524 (t (byte-compile-form (car args))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3525 (dolist (elt (cdr args))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3526 (byte-compile-form elt)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3527 (byte-compile-out 'byte-max 0))))))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3528
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3529 (defun byte-compile-min (form)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3530 (let ((args (cdr form)))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3531 (case (length args)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3532 (0 (byte-compile-subr-wrong-args form "1 or more"))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3533 (1 (byte-compile-form (car args))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3534 (when (not byte-compile-delete-errors)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3535 (byte-compile-out 'byte-dup 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3536 (byte-compile-out 'byte-min 0)))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3537 (t (byte-compile-form (car args))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3538 (dolist (elt (cdr args))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3539 (byte-compile-form elt)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3540 (byte-compile-out 'byte-min 0))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3541
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3542
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3543 ;; more complicated compiler macros
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3544
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3545 (byte-defop-compiler list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3546 (byte-defop-compiler concat)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3547 (byte-defop-compiler fset)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3548 (byte-defop-compiler insert)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3549 (byte-defop-compiler-1 function byte-compile-function-form)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3550 (byte-defop-compiler max)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3551 (byte-defop-compiler min)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3552 (byte-defop-compiler (+ byte-plus) byte-compile-plus)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3553 (byte-defop-compiler-1 - byte-compile-minus)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3554 (byte-defop-compiler (* byte-mult) byte-compile-mult)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3555 (byte-defop-compiler (/ byte-quo) byte-compile-quo)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3556 (byte-defop-compiler nconc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3557 (byte-defop-compiler-1 beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3558
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3559 (byte-defop-compiler (= byte-eqlsign) byte-compile-arithcompare)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3560 (byte-defop-compiler (< byte-lss) byte-compile-arithcompare)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3561 (byte-defop-compiler (> byte-gtr) byte-compile-arithcompare)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3562 (byte-defop-compiler (<= byte-leq) byte-compile-arithcompare)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3563 (byte-defop-compiler (>= byte-geq) byte-compile-arithcompare)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3564
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3565 (defun byte-compile-arithcompare (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3566 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3567 (0 (byte-compile-subr-wrong-args form "1 or more"))
549
2b0ea82d329f [xemacs-hg @ 2001-05-21 01:54:03 by martinb]
martinb
parents: 502
diff changeset
3568 (1 (if byte-compile-delete-errors
2b0ea82d329f [xemacs-hg @ 2001-05-21 01:54:03 by martinb]
martinb
parents: 502
diff changeset
3569 (byte-compile-constant t)
2b0ea82d329f [xemacs-hg @ 2001-05-21 01:54:03 by martinb]
martinb
parents: 502
diff changeset
3570 (byte-compile-normal-call form)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3571 (2 (byte-compile-two-args form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3572 (t (byte-compile-normal-call form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3573
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3574 (byte-defop-compiler /= byte-compile-/=)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3575
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3576 (defun byte-compile-/= (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3577 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3578 (0 (byte-compile-subr-wrong-args form "1 or more"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3579 (1 (byte-compile-constant t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3580 ;; optimize (/= X Y) to (not (= X Y))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3581 (2 (byte-compile-form-do-effect `(not (= ,@(cdr form)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3582 (t (byte-compile-normal-call form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3583
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3584 ;; buffer-substring now has its own function. This used to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3585 ;; 2+1, but now all args are optional.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3586 (byte-defop-compiler buffer-substring)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3587
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3588 (defun byte-compile-buffer-substring (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3589 ;; buffer-substring used to take exactly two args, but now takes 0-3.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3590 ;; convert 0-2 to two args and use special bytecode operand.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3591 ;; convert 3 args to a normal call.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3592 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3593 (0 (byte-compile-two-args (append form '(nil nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3594 (1 (byte-compile-two-args (append form '(nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3595 (2 (byte-compile-two-args form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3596 (3 (byte-compile-normal-call form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3597 (t (byte-compile-subr-wrong-args form "0-3"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3598
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3599 (defun byte-compile-list (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3600 (let* ((args (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3601 (nargs (length args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3602 (cond
5366
f00192e1cd49 Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents: 5358
diff changeset
3603 ((eql nargs 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3604 (byte-compile-constant nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3605 ((< nargs 5)
4783
e29fcfd8df5f Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4775
diff changeset
3606 (mapc 'byte-compile-form args)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3607 (byte-compile-out
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3608 (aref [byte-list1 byte-list2 byte-list3 byte-list4] (1- nargs))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3609 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3610 ((< nargs 256)
4783
e29fcfd8df5f Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4775
diff changeset
3611 (mapc 'byte-compile-form args)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3612 (byte-compile-out 'byte-listN nargs))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3613 (t (byte-compile-normal-call form)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3614
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3615 (defun byte-compile-concat (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3616 (let* ((args (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3617 (nargs (length args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3618 ;; Concat of one arg is not a no-op if arg is not a string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3619 (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3620 ((memq nargs '(2 3 4))
4783
e29fcfd8df5f Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4775
diff changeset
3621 (mapc 'byte-compile-form args)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3622 (byte-compile-out
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3623 (aref [byte-concat2 byte-concat3 byte-concat4] (- nargs 2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3624 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3625 ((eq nargs 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3626 (byte-compile-form ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3627 ((< nargs 256)
4783
e29fcfd8df5f Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4775
diff changeset
3628 (mapc 'byte-compile-form args)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3629 (byte-compile-out 'byte-concatN nargs))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3630 ((byte-compile-normal-call form)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3631
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3632 (defun byte-compile-plus (form)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3633 (let ((args (cdr form)))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3634 (case (length args)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3635 (0 (byte-compile-constant 0))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3636 (1 (byte-compile-plus (append form '(0))))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3637 (t (byte-compile-form (car args))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3638 (dolist (elt (cdr args))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3639 (case elt
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3640 (0 (when (not byte-compile-delete-errors)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3641 (byte-compile-constant 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3642 (byte-compile-out 'byte-plus 0)))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3643 (+1 (byte-compile-out 'byte-add1 0))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3644 (-1 (byte-compile-out 'byte-sub1 0))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3645 (t
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3646 (byte-compile-form elt)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3647 (byte-compile-out 'byte-plus 0))))))))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3648
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3649 (defun byte-compile-minus (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3650 (let ((args (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3651 (case (length args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3652 (0 (byte-compile-subr-wrong-args form "1 or more"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3653 (1 (byte-compile-form (car args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3654 (byte-compile-out 'byte-negate 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3655 (t (byte-compile-form (car args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3656 (dolist (elt (cdr args))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3657 (case elt
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3658 (0 (when (not byte-compile-delete-errors)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3659 (byte-compile-constant 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3660 (byte-compile-out 'byte-diff 0)))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3661 (+1 (byte-compile-out 'byte-sub1 0))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3662 (-1 (byte-compile-out 'byte-add1 0))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3663 (t
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3664 (byte-compile-form elt)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3665 (byte-compile-out 'byte-diff 0))))))))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3666
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3667 (defun byte-compile-mult (form)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3668 (let ((args (cdr form)))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3669 (case (length args)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3670 (0 (byte-compile-constant 1))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3671 (1 (byte-compile-mult (append form '(1))))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3672 (t (byte-compile-form (car args))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3673 (dolist (elt (cdr args))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3674 (case elt
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3675 (1 (when (not byte-compile-delete-errors)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3676 (byte-compile-constant 1)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3677 (byte-compile-out 'byte-mult 0)))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3678 (-1 (byte-compile-out 'byte-negate 0))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3679 (2 (byte-compile-out 'byte-dup 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3680 (byte-compile-out 'byte-plus 0))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3681 (t
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3682 (byte-compile-form elt)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3683 (byte-compile-out 'byte-mult 0))))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3684
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3685 (defun byte-compile-quo (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3686 (let ((args (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3687 (case (length args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3688 (0 (byte-compile-subr-wrong-args form "1 or more"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3689 (1 (byte-compile-constant 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3690 (byte-compile-form (car args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3691 (byte-compile-out 'byte-quo 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3692 (t (byte-compile-form (car args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3693 (dolist (elt (cdr args))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3694 (case elt
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3695 (+1 (when (not byte-compile-delete-errors)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3696 (byte-compile-constant 1)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3697 (byte-compile-out 'byte-quo 0)))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3698 (-1 (byte-compile-out 'byte-negate 0))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3699 (t
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3700 (when (and (numberp elt) (= elt 0))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3701 (byte-compile-warn "Attempt to divide by zero: %s" form))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3702 (byte-compile-form elt)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3703 (byte-compile-out 'byte-quo 0))))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3704
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3705 (defun byte-compile-nconc (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3706 (let ((args (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3707 (case (length args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3708 (0 (byte-compile-constant nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3709 ;; nconc of one arg is a noop, even if that arg isn't a list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3710 (1 (byte-compile-form (car args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3711 (t (byte-compile-form (car args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3712 (dolist (elt (cdr args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3713 (byte-compile-form elt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3714 (byte-compile-out 'byte-nconc 0))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3715
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3716 (defun byte-compile-fset (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3717 ;; warn about forms like (fset 'foo '(lambda () ...))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3718 ;; (where the lambda expression is non-trivial...)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3719 ;; Except don't warn if the first argument is 'make-byte-code, because
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3720 ;; I'm sick of getting mail asking me whether that warning is a problem.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3721 (let ((fn (nth 2 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3722 body)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3723 (when (and (eq (car-safe fn) 'quote)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3724 (eq (car-safe (setq fn (nth 1 fn))) 'lambda)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3725 (not (eq (car-safe (cdr-safe (nth 1 form))) 'make-byte-code)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3726 (setq body (cdr (cdr fn)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3727 (if (stringp (car body)) (setq body (cdr body)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3728 (if (eq 'interactive (car-safe (car body))) (setq body (cdr body)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3729 (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
3730 (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
3731 (memq 'quoted-lambda byte-compile-warnings))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3732 (byte-compile-warn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3733 "A quoted lambda form is the second argument of fset. This is probably
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3734 not what you want, as that lambda cannot be compiled. Consider using
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3735 the syntax (function (lambda (...) ...)) instead."))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3736 (byte-compile-two-args form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3737
5089
99f8ebc082d9 Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4996
diff changeset
3738 (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
3739 (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
3740 ;; 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
3741 (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
3742 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
3743
4743
776bbf454f3a Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4719
diff changeset
3744 (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
3745 `#'(lambda (form)
776bbf454f3a Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4719
diff changeset
3746 ,@(loop
776bbf454f3a Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4719
diff changeset
3747 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
3748 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
3749 (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
3750 (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
3751 (or
776bbf454f3a Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4719
diff changeset
3752 (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
3753 byte-compile-warnings))
776bbf454f3a Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4719
diff changeset
3754 (byte-compile-warn
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5106
diff changeset
3755 "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
3756 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
3757 (setcar fn 'function))))
776bbf454f3a Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4719
diff changeset
3758 (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
3759
776bbf454f3a Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4719
diff changeset
3760 ;; (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
3761 ;; 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
3762 (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
3763
776bbf454f3a Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4719
diff changeset
3764 ;; (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
3765 ;; 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
3766 (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
3767
776bbf454f3a Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4719
diff changeset
3768 ;; For #'merge, basically.
776bbf454f3a Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4719
diff changeset
3769 (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
3770
776bbf454f3a Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4719
diff changeset
3771 ;; 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
3772 (defalias 'byte-compile-funarg-1-2 (byte-compile-funarg-n 1 2))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3773
4716
dca5bb2adff1 Don't cons with #'mapcar calls where the result is discarded,
Aidan Kehoe <kehoea@parhasard.net>
parents: 4686
diff changeset
3774 ;; 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
3775 ;; 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
3776 ;; 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
3777 (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
3778 (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
3779 (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
3780 (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
3781 "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
3782 (car form)))
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4885
diff changeset
3783 (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
3784 (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
3785
dca5bb2adff1 Don't cons with #'mapcar calls where the result is discarded,
Aidan Kehoe <kehoea@parhasard.net>
parents: 4686
diff changeset
3786 (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
3787 (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
3788 (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
3789 (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
3790 "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
3791 (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
3792 (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
3793
5182
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5106
diff changeset
3794 ;; 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
3795 ;; 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
3796 (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
3797 `#'(lambda (form)
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5106
diff changeset
3798 (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
3799 (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
3800 (byte-compile-warn
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5106
diff changeset
3801 "#'%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
3802 (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
3803 (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
3804 (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
3805 '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
3806
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5106
diff changeset
3807 (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
3808
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5106
diff changeset
3809 (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
3810
2e528066e2fc Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5106
diff changeset
3811 (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
3812
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3813 ;; (function foo) must compile like 'foo, not like (symbol-function 'foo).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3814 ;; Otherwise it will be incompatible with the interpreter,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3815 ;; and (funcall (function foo)) will lose with autoloads.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3816
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3817 (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
3818 (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
3819 (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
3820 `(signal 'wrong-number-of-arguments '(function ,(length (cdr form)))))
5574
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
3821 (byte-compile-constant (if (eq 'lambda (car-safe (nth 1 form)))
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
3822 (byte-compile-lambda (nth 1 form))
d4f334808463 Support inlining labels, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5573
diff changeset
3823 (nth 1 form)))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3824
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3825 (defun byte-compile-insert (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3826 (cond ((null (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3827 (byte-compile-constant nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3828 ((<= (length form) 256)
4783
e29fcfd8df5f Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4775
diff changeset
3829 (mapc 'byte-compile-form (cdr form))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3830 (if (cdr (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3831 (byte-compile-out 'byte-insertN (length (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3832 (byte-compile-out 'byte-insert 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3833 ((memq t (mapcar 'consp (cdr (cdr form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3834 (byte-compile-normal-call form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3835 ;; We can split it; there is no function call after inserting 1st arg.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3836 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3837 (while (setq form (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3838 (byte-compile-form (car form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3839 (byte-compile-out 'byte-insert 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3840 (when (cdr form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3841 (byte-compile-discard))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3842
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3843 ;; alas, the old (pre-19.12, and all existing versions of FSFmacs 19)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3844 ;; byte compiler will generate incorrect code for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3845 ;; (beginning-of-line nil buffer) because it buggily doesn't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3846 ;; check the number of arguments passed to beginning-of-line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3847
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3848 (defun byte-compile-beginning-of-line (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3849 (let ((len (length form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3850 (cond ((> len 3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3851 (byte-compile-subr-wrong-args form "0-2"))
5366
f00192e1cd49 Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents: 5358
diff changeset
3852 ((or (eql len 3) (not (byte-compile-constp (nth 1 form))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3853 (byte-compile-normal-call form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3854 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3855 (byte-compile-form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3856 (list 'forward-line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3857 (if (integerp (setq form (or (eval (nth 1 form)) 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3858 (1- form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3859 (byte-compile-warn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3860 "Non-numeric arg to beginning-of-line: %s" form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3861 (list '1- (list 'quote form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3862 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3863 (byte-compile-constant nil)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3864
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3865
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3866 (byte-defop-compiler set)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3867 (byte-defop-compiler-1 setq)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3868 (byte-defop-compiler-1 set-default)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3869 (byte-defop-compiler-1 setq-default)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3870
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3871 (byte-defop-compiler-1 quote)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3872 (byte-defop-compiler-1 quote-form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3873
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3874 (defun byte-compile-setq (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3875 (let ((args (cdr form)) var val)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3876 (if (null args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3877 ;; (setq), with no arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3878 (byte-compile-form nil for-effect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3879 (while args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3880 (setq var (pop args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3881 (if (null args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3882 ;; Odd number of args? Let `set' get the error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3883 (byte-compile-form `(set ',var) for-effect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3884 (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
3885 (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
3886 (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
3887 (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
3888 (byte-compile-variable-ref 'byte-varset var)))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3889 (setq for-effect nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3890
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3891 (defun byte-compile-set (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3892 ;; Compile (set 'foo x) as (setq foo x) for trivially better code and so
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3893 ;; that we get applicable warnings. Compile everything else (including
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3894 ;; malformed calls) like a normal 2-arg byte-coded function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3895 (let ((symform (nth 1 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3896 (valform (nth 2 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3897 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
3898 (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
3899 (eql (safe-length symform) 2)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3900 (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
3901 (symbolp (setq sym (car (cdr symform)))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3902 (byte-compile-setq `(setq ,sym ,valform))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3903 (byte-compile-two-args form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3904
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3905 (defun byte-compile-setq-default (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3906 (let ((args (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3907 (if (null args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3908 ;; (setq-default), with no arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3909 (byte-compile-form nil for-effect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3910 ;; emit multiple calls to `set-default' if necessary
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3911 (while args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3912 (byte-compile-form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3913 ;; Odd number of args? Let `set-default' get the error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3914 `(set-default ',(pop args) ,@(if args (list (pop args)) nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3915 (if args t for-effect)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3916 (setq for-effect nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3917
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3918 (defun byte-compile-set-default (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3919 (let* ((args (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3920 (nargs (length args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3921 (var (car args)))
5366
f00192e1cd49 Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents: 5358
diff changeset
3922 (when (and (eql (safe-length var) 2) (eq (car var) 'quote))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3923 (let ((sym (nth 1 var)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3924 (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3925 ((not (symbolp sym))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3926 (byte-compile-warn "Attempt to set-globally non-symbol %s" sym))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3927 ((byte-compile-constant-symbol-p sym)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3928 (byte-compile-warn "Attempt to set-globally constant symbol %s" sym))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3929 ((let ((cell (assq sym byte-compile-bound-variables)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3930 (and cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3931 (setcdr cell (logior (cdr cell) byte-compile-assigned-bit))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3932 t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3933 ;; notice calls to set-default/setq-default for variables which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3934 ;; have not been declared with defvar/defconst.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3935 ((globally-boundp sym)) ; OK
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3936 ((not (memq 'free-vars byte-compile-warnings))) ; warnings suppressed?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3937 ((memq sym byte-compile-free-assignments)) ; already warned about sym
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3938 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3939 (byte-compile-warn "assignment to free variable %s" sym)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3940 (push sym byte-compile-free-assignments)))))
5366
f00192e1cd49 Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents: 5358
diff changeset
3941 (if (eql nargs 2)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3942 ;; now emit a normal call to set-default
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3943 (byte-compile-normal-call form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3944 (byte-compile-subr-wrong-args form 2))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3945
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3946
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3947 (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
3948 (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
3949 (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
3950 `(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
3951 (byte-compile-constant (car (cdr form)))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3952
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3953 (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
3954 (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
3955 (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
3956 `(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
3957 (byte-compile-constant (byte-compile-top-level (nth 1 form)))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3958
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3959 ;;; control structures
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3960
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3961 (defun byte-compile-body (body &optional for-effect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3962 (while (cdr body)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3963 (byte-compile-form (car body) t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3964 (setq body (cdr body)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3965 (byte-compile-form (car body) for-effect))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3966
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3967 (proclaim-inline byte-compile-body-do-effect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3968 (defun byte-compile-body-do-effect (body)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3969 (byte-compile-body body for-effect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3970 (setq for-effect nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3971
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3972 (proclaim-inline byte-compile-form-do-effect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3973 (defun byte-compile-form-do-effect (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3974 (byte-compile-form form for-effect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3975 (setq for-effect nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3976
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3977 (byte-defop-compiler-1 inline byte-compile-progn)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3978 (byte-defop-compiler-1 progn)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3979 (byte-defop-compiler-1 prog1)
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
3980 (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
3981 (byte-defop-compiler-1 values)
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
3982 (byte-defop-compiler-1 values-list)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3983 (byte-defop-compiler-1 prog2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3984 (byte-defop-compiler-1 if)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3985 (byte-defop-compiler-1 cond)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3986 (byte-defop-compiler-1 and)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3987 (byte-defop-compiler-1 or)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3988 (byte-defop-compiler-1 while)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3989 (byte-defop-compiler-1 funcall)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3990 (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
3991 (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
3992 (byte-defop-compiler-1 mapcar* byte-compile-maybe-mapc)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3993 (byte-defop-compiler-1 mapatoms byte-compile-funarg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3994 (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
3995 (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
3996 (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
3997 (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
3998 (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
3999 (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
4000 (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
4001 (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
4002 (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
4003 (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
4004 (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
4005 (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
4006 (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
4007 (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
4008 (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
4009 (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
4010
776bbf454f3a Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4719
diff changeset
4011 (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
4012 (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
4013 (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
4014 (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
4015 (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
4016 (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
4017 (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
4018 (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
4019 (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
4020 (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
4021 (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
4022 (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
4023 (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
4024 (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
4025 (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
4026 (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
4027 (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
4028 (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
4029 (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
4030 (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
4031 (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
4032
776bbf454f3a Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4719
diff changeset
4033 (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
4034 (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
4035
776bbf454f3a Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4719
diff changeset
4036 (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
4037 (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
4038 (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
4039 (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
4040 (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
4041 (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
4042 (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
4043 (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
4044 (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
4045 (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
4046 (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
4047 (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
4048 (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
4049 (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
4050
776bbf454f3a Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4719
diff changeset
4051 (byte-defop-compiler-1 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
4052
776bbf454f3a Be much more comprehensive in our use of byte-compile-funarg.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4719
diff changeset
4053 (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
4054 (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
4055
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4056 (byte-defop-compiler-1 let)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4057 (byte-defop-compiler-1 let*)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4058
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4783
diff changeset
4059 (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
4060 (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
4061 (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
4062
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4063 (defun byte-compile-progn (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4064 (byte-compile-body-do-effect (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4065
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4066 (defun byte-compile-prog1 (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4067 (setq form (cdr form))
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4068 ;; #'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
4069 (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
4070 (byte-compile-body form t))
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4071
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4072 (defun byte-compile-multiple-value-prog1 (form)
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4073 (setq form (cdr form))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4074 (byte-compile-form-do-effect (pop form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4075 (byte-compile-body form t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4076
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4077 (defun byte-compile-values (form)
5366
f00192e1cd49 Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents: 5358
diff changeset
4078 (if (eql 2 (length form))
4686
cdabd56ce1b5 Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4683
diff changeset
4079 (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
4080 (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
4081 ;; #'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
4082 (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
4083 (byte-compile-normal-call form)))
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4084
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4085 (defun byte-compile-values-list (form)
5366
f00192e1cd49 Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents: 5358
diff changeset
4086 (if (and (eql 2 (length form))
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4087 (or (null (second form))
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4088 (and (consp (second form))
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4089 (eq (car (second form))
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4090 'quote)
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4091 (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
4092 (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
4093 (byte-compile-normal-call form)))
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4094
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4095 (defun byte-compile-prog2 (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4096 (setq form (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4097 (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
4098 ;; #'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
4099 (byte-compile-form-do-effect `(or ,(pop form) nil))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4100 (byte-compile-body form t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4101
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4102 (defmacro byte-compile-goto-if (cond discard tag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4103 `(byte-compile-goto
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4104 (if ,cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4105 (if ,discard 'byte-goto-if-not-nil 'byte-goto-if-not-nil-else-pop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4106 (if ,discard 'byte-goto-if-nil 'byte-goto-if-nil-else-pop))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4107 ,tag))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4108
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4109 (defun byte-compile-if (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4110 (byte-compile-form (car (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4111 (if (null (nthcdr 3 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4112 ;; No else-forms
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4113 (let ((donetag (byte-compile-make-tag)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4114 (byte-compile-goto-if nil for-effect donetag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4115 (byte-compile-form (nth 2 form) for-effect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4116 (byte-compile-out-tag donetag))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4117 (let ((donetag (byte-compile-make-tag)) (elsetag (byte-compile-make-tag)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4118 (byte-compile-goto 'byte-goto-if-nil elsetag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4119 (byte-compile-form (nth 2 form) for-effect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4120 (byte-compile-goto 'byte-goto donetag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4121 (byte-compile-out-tag elsetag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4122 (byte-compile-body (cdr (cdr (cdr form))) for-effect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4123 (byte-compile-out-tag donetag)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4124 (setq for-effect nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4125
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4126 (defun byte-compile-cond (clauses)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4127 (let ((donetag (byte-compile-make-tag))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4128 nexttag clause)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4129 (while (setq clauses (cdr clauses))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4130 (setq clause (car clauses))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4131 (cond ((or (eq (car clause) t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4132 (and (eq (car-safe (car clause)) 'quote)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4133 (car-safe (cdr-safe (car clause)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4134 ;; Unconditional clause
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4135 (setq clause (cons t clause)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4136 clauses nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4137 ((cdr clauses)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4138 (byte-compile-form (car clause))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4139 (if (null (cdr clause))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4140 ;; First clause is a singleton.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4141 (byte-compile-goto-if t for-effect donetag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4142 (setq nexttag (byte-compile-make-tag))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4143 (byte-compile-goto 'byte-goto-if-nil nexttag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4144 (byte-compile-body (cdr clause) for-effect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4145 (byte-compile-goto 'byte-goto donetag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4146 (byte-compile-out-tag nexttag)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4147 ;; Last clause
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4148 (and (cdr clause) (not (eq (car clause) t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4149 (progn (byte-compile-form (car clause))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4150 (byte-compile-goto-if nil for-effect donetag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4151 (setq clause (cdr clause))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4152 (byte-compile-body-do-effect clause)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4153 (byte-compile-out-tag donetag)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4154
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4155 (defun byte-compile-and (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4156 (let ((failtag (byte-compile-make-tag))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4157 (args (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4158 (if (null args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4159 (byte-compile-form-do-effect t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4160 (while (cdr args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4161 (byte-compile-form (car args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4162 (byte-compile-goto-if nil for-effect failtag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4163 (setq args (cdr args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4164 (byte-compile-form-do-effect (car args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4165 (byte-compile-out-tag failtag))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4166
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4167 (defun byte-compile-or (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4168 (let ((wintag (byte-compile-make-tag))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4169 (args (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4170 (if (null args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4171 (byte-compile-form-do-effect nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4172 (while (cdr args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4173 (byte-compile-form (car args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4174 (byte-compile-goto-if t for-effect wintag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4175 (setq args (cdr args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4176 (byte-compile-form-do-effect (car args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4177 (byte-compile-out-tag wintag))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4178
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4179 (defun byte-compile-while (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4180 (let ((endtag (byte-compile-make-tag))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4181 (looptag (byte-compile-make-tag)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4182 (byte-compile-out-tag looptag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4183 (byte-compile-form (car (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4184 (byte-compile-goto-if nil for-effect endtag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4185 (byte-compile-body (cdr (cdr form)) t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4186 (byte-compile-goto 'byte-goto looptag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4187 (byte-compile-out-tag endtag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4188 (setq for-effect nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4189
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4190 (defun byte-compile-funcall (form)
5566
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
4191 (if (and (memq 'callargs byte-compile-warnings)
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
4192 (byte-compile-constp (second form)))
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
4193 (byte-compile-callargs-warn (cons (cl-const-expr-val (second form))
4654c01af32b Improve the implementation, documentation of #'labels, #'flet.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5562
diff changeset
4194 (nthcdr 2 form))))
5575
89cb6a66a61f Force unfolding of (funcall #'(lambda () ...) if optimising, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5574
diff changeset
4195 (if (and byte-optimize
89cb6a66a61f Force unfolding of (funcall #'(lambda () ...) if optimising, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5574
diff changeset
4196 (eq 'function (car-safe (cadr form)))
89cb6a66a61f Force unfolding of (funcall #'(lambda () ...) if optimising, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5574
diff changeset
4197 (eq 'lambda (car-safe (cadadr form)))
89cb6a66a61f Force unfolding of (funcall #'(lambda () ...) if optimising, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5574
diff changeset
4198 (or
89cb6a66a61f Force unfolding of (funcall #'(lambda () ...) if optimising, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5574
diff changeset
4199 (not (eq (setq form (cons (cadadr form) (cddr form)))
89cb6a66a61f Force unfolding of (funcall #'(lambda () ...) if optimising, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5574
diff changeset
4200 (setq form (byte-compile-unfold-lambda form))))
89cb6a66a61f Force unfolding of (funcall #'(lambda () ...) if optimising, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5574
diff changeset
4201 (prog1 nil (setq form `(funcall #',(car form) ,@(cdr form))))))
5577
0b6e7ae1e78f Update a comment with a better understanding of the optimizer, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5575
diff changeset
4202 ;; The byte-compile part of the #'labels implementation, above,
0b6e7ae1e78f Update a comment with a better understanding of the optimizer, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5575
diff changeset
4203 ;; happens after macroexpansion and after the source optimizer has
0b6e7ae1e78f Update a comment with a better understanding of the optimizer, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5575
diff changeset
4204 ;; done its thing. When labels are to be made inline we can have code
0b6e7ae1e78f Update a comment with a better understanding of the optimizer, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5575
diff changeset
4205 ;; that looks like (funcall #'(lambda ...) ...), when the code that
0b6e7ae1e78f Update a comment with a better understanding of the optimizer, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5575
diff changeset
4206 ;; the optimizer saw looked like (funcall #<compiled-function ...>
0b6e7ae1e78f Update a comment with a better understanding of the optimizer, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5575
diff changeset
4207 ;; ...).
0b6e7ae1e78f Update a comment with a better understanding of the optimizer, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5575
diff changeset
4208 ;;
0b6e7ae1e78f Update a comment with a better understanding of the optimizer, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5575
diff changeset
4209 ;; So, the optimizer doesn't have the opportunity to transform the
0b6e7ae1e78f Update a comment with a better understanding of the optimizer, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5575
diff changeset
4210 ;; former to (let (...) ...), and it's reasonable to do that here (since
0b6e7ae1e78f Update a comment with a better understanding of the optimizer, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5575
diff changeset
4211 ;; the labels implementation doesn't change other code that would need
0b6e7ae1e78f Update a comment with a better understanding of the optimizer, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5575
diff changeset
4212 ;; running through the optimizer; the lambda itself has already been
0b6e7ae1e78f Update a comment with a better understanding of the optimizer, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5575
diff changeset
4213 ;; through the optimizer).
0b6e7ae1e78f Update a comment with a better understanding of the optimizer, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5575
diff changeset
4214 ;;
0b6e7ae1e78f Update a comment with a better understanding of the optimizer, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5575
diff changeset
4215 ;; Equally reasonable, and conceptually a bit clearer, would be to do
0b6e7ae1e78f Update a comment with a better understanding of the optimizer, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5575
diff changeset
4216 ;; the transformation to (funcall #'(lambda ...) ...) in the
0b6e7ae1e78f Update a comment with a better understanding of the optimizer, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5575
diff changeset
4217 ;; byte-optimizer, breaking most of the #'sublis calls out of the
0b6e7ae1e78f Update a comment with a better understanding of the optimizer, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5575
diff changeset
4218 ;; byte-compile method.
5575
89cb6a66a61f Force unfolding of (funcall #'(lambda () ...) if optimising, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5574
diff changeset
4219 (byte-compile-form form)
89cb6a66a61f Force unfolding of (funcall #'(lambda () ...) if optimising, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5574
diff changeset
4220 (mapc 'byte-compile-form (cdr form))
89cb6a66a61f Force unfolding of (funcall #'(lambda () ...) if optimising, bytecomp.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5574
diff changeset
4221 (byte-compile-out 'byte-call (length (cdr (cdr form))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4222
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4223
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4224 (defun byte-compile-let (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4225 ;; First compute the binding values in the old scope.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4226 (let ((varlist (car (cdr form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4227 (while varlist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4228 (if (consp (car varlist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4229 (byte-compile-form (car (cdr (car varlist))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4230 (byte-compile-push-constant nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4231 (setq varlist (cdr varlist))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4232 (let ((byte-compile-bound-variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4233 (cons 'new-scope byte-compile-bound-variables))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4234 (varlist (reverse (car (cdr form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4235 (extra-flags
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4236 ;; If this let is of the form (let (...) (byte-code ...))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4237 ;; then assume that it is the result of a transformation of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4238 ;; ((lambda (...) (byte-code ... )) ...) and thus compile
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4239 ;; the variable bindings as if they were arglist bindings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4240 ;; (which matters for what warnings.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4241 (if (eq 'byte-code (car-safe (nth 2 form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4242 byte-compile-arglist-bit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4243 nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4244 (while varlist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4245 (byte-compile-variable-ref 'byte-varbind
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4246 (if (consp (car varlist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4247 (car (car varlist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4248 (car varlist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4249 extra-flags)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4250 (setq varlist (cdr varlist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4251 (byte-compile-body-do-effect (cdr (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4252 (if (memq 'unused-vars byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4253 ;; done compiling in this scope, warn now.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4254 (byte-compile-warn-about-unused-variables))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4255 (byte-compile-out 'byte-unbind (length (car (cdr form))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4256
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4257 (defun byte-compile-let* (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4258 (let ((byte-compile-bound-variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4259 (cons 'new-scope byte-compile-bound-variables))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4260 (varlist (copy-sequence (car (cdr form)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4261 (while varlist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4262 (if (atom (car varlist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4263 (byte-compile-push-constant nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4264 (byte-compile-form (car (cdr (car varlist))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4265 (setcar varlist (car (car varlist))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4266 (byte-compile-variable-ref 'byte-varbind (car varlist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4267 (setq varlist (cdr varlist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4268 (byte-compile-body-do-effect (cdr (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4269 (if (memq 'unused-vars byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4270 ;; done compiling in this scope, warn now.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4271 (byte-compile-warn-about-unused-variables))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4272 (byte-compile-out 'byte-unbind (length (car (cdr form))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4273
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4783
diff changeset
4274 ;; 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
4275 ;; 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
4276 ;; 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
4277 ;; 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
4278 ;; 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
4279 ;; 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
4280 ;; 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
4281 ;;
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4783
diff changeset
4282 ;; (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
4283 ;;
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4783
diff changeset
4284 ;; 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
4285 ;; 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
4286 ;; 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
4287 ;;
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4783
diff changeset
4288 ;; 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
4289 ;; (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
4290 ;; 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
4291 ;; anyway).
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4783
diff changeset
4292
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4783
diff changeset
4293 (defun byte-compile-integerp (form)
5366
f00192e1cd49 Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents: 5358
diff changeset
4294 (if (not (eql (length form) 2))
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4783
diff changeset
4295 (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
4296 (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
4297 (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
4298 (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
4299 (byte-compile-constant 'integerp)
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4783
diff changeset
4300 (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
4301 (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
4302 (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
4303 (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
4304 (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
4305 (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
4306 (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
4307 (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
4308 ;; 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
4309 ;; 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
4310 ;; 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
4311 ;; anything.
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4783
diff changeset
4312 (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
4313 (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
4314 (byte-compile-discard)
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4783
diff changeset
4315 (byte-compile-discard)
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4783
diff changeset
4316 (byte-compile-constant nil)
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4783
diff changeset
4317 (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
4318 (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
4319 (byte-compile-discard)
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4783
diff changeset
4320 (byte-compile-discard)
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4783
diff changeset
4321 (byte-compile-constant t)
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4783
diff changeset
4322 (byte-compile-out-tag donetag))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4323
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
4324 (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
4325 (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
4326 (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
4327 (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
4328 (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
4329 (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
4330 (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
4331 (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
4332 (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
4333 (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
4334 (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
4335 (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
4336 (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
4337 (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
4338 (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
4339 (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
4340 (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
4341
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4342 ;;(byte-defop-compiler-1 /= byte-compile-negated)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4343 (byte-defop-compiler-1 atom byte-compile-negated)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4344 (byte-defop-compiler-1 nlistp byte-compile-negated)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4345
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4346 ;;(put '/= 'byte-compile-negated-op '=)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4347 (put 'atom 'byte-compile-negated-op 'consp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4348 (put 'nlistp 'byte-compile-negated-op 'listp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4349
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4350 (defun byte-compile-negated (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4351 (byte-compile-form-do-effect (byte-compile-negation-optimizer form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4352
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4353 ;; Even when optimization is off, atom is optimized to (not (consp ...)).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4354 (defun byte-compile-negation-optimizer (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4355 ;; an optimizer for forms where <form1> is less efficient than (not <form2>)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4356 (list 'not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4357 (cons (or (get (car form) 'byte-compile-negated-op)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4358 (error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4359 "Compiler error: `%s' has no `byte-compile-negated-op' property"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4360 (car form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4361 (cdr form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4362
4905
755ae5b97edb Change "special form" to "special operator" in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4885
diff changeset
4363 ;;; other tricky macro-like special-operators
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4364
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4365 (byte-defop-compiler-1 catch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4366 (byte-defop-compiler-1 unwind-protect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4367 (byte-defop-compiler-1 condition-case)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4368 (byte-defop-compiler-1 save-excursion)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4369 (byte-defop-compiler-1 save-current-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4370 (byte-defop-compiler-1 save-restriction)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4371 (byte-defop-compiler-1 with-output-to-temp-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4372 ;; no track-mouse.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4373
5356
5dd1ba5e0113 Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5353
diff changeset
4374 (defvar byte-compile-active-blocks nil)
5dd1ba5e0113 Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5353
diff changeset
4375
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4376 (defun byte-compile-catch (form)
5356
5dd1ba5e0113 Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5353
diff changeset
4377 "Byte-compile and return a `catch' from.
5dd1ba5e0113 Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5353
diff changeset
4378
5dd1ba5e0113 Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5353
diff changeset
4379 If FORM is the result of macroexpanding a `block' form (the TAG argument is
5376
4b529b940e2e Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5374
diff changeset
4380 a quoted symbol with a `cl-block-name' property) and there is no
5356
5dd1ba5e0113 Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5353
diff changeset
4381 corresponding `return-from' within the block--or equivalently, it was
5dd1ba5e0113 Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5353
diff changeset
4382 optimized away--just byte compile and return the BODY."
5dd1ba5e0113 Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5353
diff changeset
4383 (let* ((symbol (car-safe (cdr-safe (nth 1 form))))
5376
4b529b940e2e Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5374
diff changeset
4384 (not-present '#:not-present)
4b529b940e2e Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5374
diff changeset
4385 (block (and symbol (symbolp symbol)
4b529b940e2e Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5374
diff changeset
4386 (get symbol 'cl-block-name not-present)))
4b529b940e2e Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5374
diff changeset
4387 (elt (and (not (eq block not-present)) (list block)))
5356
5dd1ba5e0113 Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5353
diff changeset
4388 (byte-compile-active-blocks
5376
4b529b940e2e Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5374
diff changeset
4389 (if elt
5356
5dd1ba5e0113 Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5353
diff changeset
4390 (cons elt byte-compile-active-blocks)
5dd1ba5e0113 Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5353
diff changeset
4391 byte-compile-active-blocks))
5dd1ba5e0113 Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5353
diff changeset
4392 (body
5dd1ba5e0113 Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5353
diff changeset
4393 (byte-compile-top-level (cons 'progn (cddr form))
5377
eac2e6bd5b2c Correct some minor problems in my last change.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5376
diff changeset
4394 (and (not elt) for-effect))))
5376
4b529b940e2e Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5374
diff changeset
4395 (if (and elt (not (cdr elt)))
5356
5dd1ba5e0113 Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5353
diff changeset
4396 ;; A lexical block without any contained return-from clauses:
5dd1ba5e0113 Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5353
diff changeset
4397 (byte-compile-form body)
5dd1ba5e0113 Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5353
diff changeset
4398 ;; A normal catch call, or a lexical block with a contained
5dd1ba5e0113 Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5353
diff changeset
4399 ;; return-from clause.
5dd1ba5e0113 Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5353
diff changeset
4400 (byte-compile-form (car (cdr form)))
5dd1ba5e0113 Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5353
diff changeset
4401 (byte-compile-push-constant body)
5dd1ba5e0113 Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5353
diff changeset
4402 (byte-compile-out 'byte-catch 0))))
5353
38e24b8be4ea Improve the lexical scoping in #'block, #'return-from.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5344
diff changeset
4403
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4404 (defun byte-compile-unwind-protect (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4405 (byte-compile-push-constant
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4406 (byte-compile-top-level-body (cdr (cdr form)) t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4407 (byte-compile-out 'byte-unwind-protect 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4408 (byte-compile-form-do-effect (car (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4409 (byte-compile-out 'byte-unbind 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4410
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4411 ;;(defun byte-compile-track-mouse (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4412 ;; (byte-compile-form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4413 ;; (list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4414 ;; 'funcall
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4415 ;; (list 'quote
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4416 ;; (list 'lambda nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4417 ;; (cons 'track-mouse
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4418 ;; (byte-compile-top-level-body (cdr form))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4419
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4420 (defun byte-compile-condition-case (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4421 (let* ((var (nth 1 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4422 (byte-compile-bound-variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4423 (if var
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4424 (cons (cons var 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4425 (cons 'new-scope byte-compile-bound-variables))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4426 (cons 'new-scope byte-compile-bound-variables))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4427 (or (symbolp var)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4428 (byte-compile-warn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4429 "%s is not a variable-name or nil (in condition-case)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4430 (prin1-to-string var)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4431 (byte-compile-push-constant var)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4432 (byte-compile-push-constant (byte-compile-top-level
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4433 (nth 2 form) for-effect))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4434 (let ((clauses (cdr (cdr (cdr form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4435 compiled-clauses)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4436 (while clauses
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4437 (let* ((clause (car clauses))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4438 (condition (car clause)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4439 (cond ((not (or (symbolp condition)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4440 (and (listp condition)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4441 (let ((syms condition) (ok t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4442 (while syms
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4443 (if (not (symbolp (car syms)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4444 (setq ok nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4445 (setq syms (cdr syms)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4446 ok))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4447 (byte-compile-warn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4448 "%s is not a symbol naming a condition or a list of such (in condition-case)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4449 (prin1-to-string condition)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4450 ;; ((not (or (eq condition 't)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4451 ;; (and (stringp (get condition 'error-message))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4452 ;; (consp (get condition 'error-conditions)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4453 ;; (byte-compile-warn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4454 ;; "%s is not a known condition name (in condition-case)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4455 ;; condition))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4456 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4457 (setq compiled-clauses
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4458 (cons (cons condition
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4459 (byte-compile-top-level-body
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4460 (cdr clause) for-effect))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4461 compiled-clauses)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4462 (setq clauses (cdr clauses)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4463 (byte-compile-push-constant (nreverse compiled-clauses)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4464 (if (memq 'unused-vars byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4465 ;; done compiling in this scope, warn now.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4466 (byte-compile-warn-about-unused-variables))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4467 (byte-compile-out 'byte-condition-case 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4468
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4469
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4470 (defun byte-compile-save-excursion (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4471 (byte-compile-out 'byte-save-excursion 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4472 (byte-compile-body-do-effect (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4473 (byte-compile-out 'byte-unbind 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4474
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4475 (defun byte-compile-save-restriction (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4476 (byte-compile-out 'byte-save-restriction 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4477 (byte-compile-body-do-effect (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4478 (byte-compile-out 'byte-unbind 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4479
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4480 (defun byte-compile-save-current-buffer (form)
5503
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
4481 (byte-compile-out 'byte-save-current-buffer 0)
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
4482 (byte-compile-body-do-effect (cdr form))
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
4483 (byte-compile-out 'byte-unbind 1))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4484
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4485 (defun byte-compile-with-output-to-temp-buffer (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4486 (byte-compile-form (car (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4487 (byte-compile-out 'byte-temp-output-buffer-setup 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4488 (byte-compile-body (cdr (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4489 (byte-compile-out 'byte-temp-output-buffer-show 0))
5391
f9dc75bdbdc4 Implement #'load-time-value less hackishly, by modifying the byte compiler.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5377
diff changeset
4490
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4491 (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
4492 (if (< (length form) 2)
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4493 (progn
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4494 (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
4495 (byte-compile-normal-call
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4496 `(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
4497 ,(length (cdr form))))))
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4498 (setq form (cdr form))
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4499 (byte-compile-form (car form))
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4500 (byte-compile-push-constant 0)
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4501 (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
4502 ;; 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
4503 ;; 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
4504 ;; called.
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4505 (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
4506 (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
4507 ;; 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
4508 ;; not pushing it on the stack.
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4509 (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
4510 (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
4511 (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
4512 byte-compile-checks-on-load
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4513 :test #'equal)))
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4514
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4515 (defun byte-compile-multiple-value-list-internal (form)
5366
f00192e1cd49 Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents: 5358
diff changeset
4516 (if (not (eql 4 (length form)))
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4517 (progn
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4518 (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
4519 (byte-compile-normal-call
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4520 `(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
4521 ,(length (cdr form))))))
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4522 (byte-compile-form (nth 1 form))
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4523 (byte-compile-form (nth 2 form))
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4524 (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
4525 (byte-compile-form (nth 3 form))
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4526 (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
4527 (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
4528 byte-compile-checks-on-load
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4529 :test #'equal)))
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4530
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4531 (defun byte-compile-throw (form)
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4532 ;; 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
4533 ;; 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
4534 ;; 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
4535 ;; 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
4536 ;; 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
4537 ;; that, but this file should not assume that that will always be there).
5366
f00192e1cd49 Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents: 5358
diff changeset
4538 (if (not (eql 2 (length (cdr form))))
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4539 (progn
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4540 (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
4541 (byte-compile-normal-call
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4542 `(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
4543 ,(length (cdr form))))))
5356
5dd1ba5e0113 Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5353
diff changeset
4544 ;; If this form was macroexpanded from `return-from', mark the
5dd1ba5e0113 Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5353
diff changeset
4545 ;; corresponding block as having been referenced.
5dd1ba5e0113 Be better about eliminating `block's that are not `return-from'd, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5353
diff changeset
4546 (let* ((symbol (car-safe (cdr-safe (nth 1 form))))
5376
4b529b940e2e Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5374
diff changeset
4547 (not-present '#:not-present)
5377
eac2e6bd5b2c Correct some minor problems in my last change.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5376
diff changeset
4548 (block (if (and symbol (symbolp symbol))
eac2e6bd5b2c Correct some minor problems in my last change.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5376
diff changeset
4549 (get symbol 'cl-block-name not-present)
eac2e6bd5b2c Correct some minor problems in my last change.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5376
diff changeset
4550 not-present))
5376
4b529b940e2e Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5374
diff changeset
4551 (assq (and (not (eq block not-present))
4b529b940e2e Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5374
diff changeset
4552 (assq block byte-compile-active-blocks))))
5377
eac2e6bd5b2c Correct some minor problems in my last change.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5376
diff changeset
4553 (if assq
eac2e6bd5b2c Correct some minor problems in my last change.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5376
diff changeset
4554 (setcdr assq t)
eac2e6bd5b2c Correct some minor problems in my last change.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5376
diff changeset
4555 (if (not (eq block not-present))
eac2e6bd5b2c Correct some minor problems in my last change.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5376
diff changeset
4556 ;; No corresponding enclosing block.
eac2e6bd5b2c Correct some minor problems in my last change.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5376
diff changeset
4557 (byte-compile-warn "return-from: no enclosing block named `%s'"
eac2e6bd5b2c Correct some minor problems in my last change.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5376
diff changeset
4558 block))))
5376
4b529b940e2e Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5374
diff changeset
4559 (mapc 'byte-compile-form (cdr form)) ;; Push the arguments
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4560 (byte-compile-out (get (car form) 'byte-opcode) 0)
5376
4b529b940e2e Eliminate unused blocks named nil, too, cl-macs.el, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5374
diff changeset
4561 (pushnew '(null (function-max-args 'throw)) byte-compile-checks-on-load
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4562 :test #'equal)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4563
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4564 ;;; top-level forms elsewhere
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4565
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4566 (byte-defop-compiler-1 defun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4567 (byte-defop-compiler-1 defmacro)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4568 (byte-defop-compiler-1 defvar)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4569 (byte-defop-compiler-1 defvar byte-compile-defvar-or-defconst)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4570 (byte-defop-compiler-1 defconst byte-compile-defvar-or-defconst)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4571 (byte-defop-compiler-1 autoload)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4572 ;; According to Mly this can go now that lambda is a macro
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4573 ;(byte-defop-compiler-1 lambda byte-compile-lambda-form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4574 (byte-defop-compiler-1 defalias)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4575 (byte-defop-compiler-1 define-function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4576
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4577 (defun byte-compile-defun (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4578 ;; This is not used for file-level defuns with doc strings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4579 (byte-compile-two-args ; Use this to avoid byte-compile-fset's warning.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4580 (list 'fset (list 'quote (nth 1 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4581 (byte-compile-byte-code-maker
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4582 (byte-compile-lambda (cons 'lambda (cdr (cdr form)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4583 (byte-compile-discard)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4584 (byte-compile-constant (nth 1 form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4585
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4586 (defun byte-compile-defmacro (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4587 ;; This is not used for file-level defmacros with doc strings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4588 (byte-compile-body-do-effect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4589 (list (list 'fset (list 'quote (nth 1 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4590 (let ((code (byte-compile-byte-code-maker
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4591 (byte-compile-lambda
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4592 (cons 'lambda (cdr (cdr form)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4593 (if (eq (car-safe code) 'make-byte-code)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4594 (list 'cons ''macro code)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4595 (list 'quote (cons 'macro (eval code))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4596 (list 'quote (nth 1 form)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4597
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4598 (defun byte-compile-defvar-or-defconst (form)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4599 ;; This is not used for file-level defvar/defconsts with doc strings:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4600 ;; byte-compile-file-form-defvar-or-defconst will be used in that case.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4601 ;; (defvar|defconst VAR [VALUE [DOCSTRING]])
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4602 (let ((fun (nth 0 form))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4603 (var (nth 1 form))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4604 (value (nth 2 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4605 (string (nth 3 form)))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4606 (when (> (length form) 4)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4607 (byte-compile-warn
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4608 "%s %s called with %d arguments, but accepts only %s"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4609 fun var (length (cdr form)) 3))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4610 (when (memq 'free-vars byte-compile-warnings)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4611 (push (cons var byte-compile-global-bit) byte-compile-bound-variables))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4612 (byte-compile-body-do-effect
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4613 (list
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4614 ;; Put the defined variable in this library's load-history entry
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
4615 ;; just as a real defvar would, but only in top-level forms with values.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
4616 (when (and (> (length form) 2)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
4617 (null byte-compile-current-form))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4618 `(push ',var current-load-list))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4619 (when (> (length form) 3)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4620 (when (and string (not (stringp string)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4621 (byte-compile-warn "Third arg to %s %s is not a string: %s"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4622 fun var string))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4623 `(put ',var 'variable-documentation ,string))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4624 (if (cdr (cdr form)) ; `value' provided
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4625 (if (eq fun 'defconst)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4626 ;; `defconst' sets `var' unconditionally.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4627 `(setq ,var ,value)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4628 ;; `defvar' sets `var' only when unbound.
1672
3776a1115180 [xemacs-hg @ 2003-09-09 13:37:19 by michaels]
michaels
parents: 1548
diff changeset
4629 `(if (not (default-boundp ',var)) (set-default ',var ,value))))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4630 `',var))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4631
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4632 (defun byte-compile-autoload (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4633 (and (byte-compile-constp (nth 1 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4634 (byte-compile-constp (nth 5 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4635 (memq (eval (nth 5 form)) '(t macro)) ; macro-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4636 (not (fboundp (eval (nth 1 form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4637 (byte-compile-warn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4638 "The compiler ignores `autoload' except at top level. You should
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4639 probably put the autoload of the macro `%s' at top-level."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4640 (eval (nth 1 form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4641 (byte-compile-normal-call form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4642
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4643 ;; Lambda's in valid places are handled as special cases by various code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4644 ;; The ones that remain are errors.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4645 ;; According to Mly this can go now that lambda is a macro
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4646 ;(defun byte-compile-lambda-form (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4647 ; (byte-compile-warn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4648 ; "`lambda' used in function position is invalid: probably you mean #'%s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4649 ; (let ((print-escape-newlines t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4650 ; (print-level 4)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4651 ; (print-length 4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4652 ; (prin1-to-string form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4653 ; (byte-compile-normal-call
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4654 ; (list 'signal ''error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4655 ; (list 'quote (list "`lambda' used in function position" form)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4656
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4657 ;; Compile normally, but deal with warnings for the function being defined.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4658 (defun byte-compile-defalias (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4659 (if (and (consp (cdr form)) (consp (nth 1 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4660 (eq (car (nth 1 form)) 'quote)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4661 (consp (cdr (nth 1 form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4662 (symbolp (nth 1 (nth 1 form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4663 (consp (nthcdr 2 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4664 (consp (nth 2 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4665 (eq (car (nth 2 form)) 'quote)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4666 (consp (cdr (nth 2 form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4667 (symbolp (nth 1 (nth 2 form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4668 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4669 (byte-compile-defalias-warn (nth 1 (nth 1 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4670 (nth 1 (nth 2 form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4671 (setq byte-compile-function-environment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4672 (cons (cons (nth 1 (nth 1 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4673 (nth 1 (nth 2 form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4674 byte-compile-function-environment))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4675 (byte-compile-normal-call form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4676
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4677 (defun byte-compile-define-function (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4678 (byte-compile-defalias form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4679
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4680 ;; Turn off warnings about prior calls to the function being defalias'd.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4681 ;; This could be smarter and compare those calls with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4682 ;; the function it is being aliased to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4683 (defun byte-compile-defalias-warn (new alias)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4684 (let ((calls (assq new byte-compile-unresolved-functions)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4685 (if calls
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4686 (setq byte-compile-unresolved-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4687 (delq calls byte-compile-unresolved-functions)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4688
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4689 ;;; tags
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4690
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4691 ;; Note: Most operations will strip off the 'TAG, but it speeds up
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4692 ;; optimization to have the 'TAG as a part of the tag.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4693 ;; Tags will be (TAG . (tag-number . stack-depth)).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4694 (defun byte-compile-make-tag ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4695 (list 'TAG (setq byte-compile-tag-number (1+ byte-compile-tag-number))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4696
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4697
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4698 (defun byte-compile-out-tag (tag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4699 (push tag byte-compile-output)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4700 (if (cdr (cdr tag))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4701 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4702 ;; ## remove this someday
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4703 (and byte-compile-depth
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4704 (not (= (cdr (cdr tag)) byte-compile-depth))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4705 (error "Compiler bug: depth conflict at tag %d" (car (cdr tag))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4706 (setq byte-compile-depth (cdr (cdr tag))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4707 (setcdr (cdr tag) byte-compile-depth)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4708
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4709 (defun byte-compile-goto (opcode tag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4710 (push (cons opcode tag) byte-compile-output)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4711 (setcdr (cdr tag) (if (memq opcode byte-goto-always-pop-ops)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4712 (1- byte-compile-depth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4713 byte-compile-depth))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4714 (setq byte-compile-depth (and (not (eq opcode 'byte-goto))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4715 (1- byte-compile-depth))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4716
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4717 (defun byte-compile-out (opcode offset)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4718 (push (cons opcode offset) byte-compile-output)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4719 (case opcode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4720 (byte-call
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4721 (setq byte-compile-depth (- byte-compile-depth offset)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4722 (byte-return
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4723 ;; This is actually an unnecessary case, because there should be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4724 ;; no more opcodes behind byte-return.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4725 (setq byte-compile-depth nil))
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4726 (byte-multiple-value-call
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4639
diff changeset
4727 (setq byte-compile-depth (- byte-compile-depth offset)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4728 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4729 (setq byte-compile-depth (+ byte-compile-depth
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4730 (or (aref byte-stack+-info
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4731 (symbol-value opcode))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4732 (- (1- offset))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4733 byte-compile-maxdepth (max byte-compile-depth
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4734 byte-compile-maxdepth))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4735 ;;(if (< byte-compile-depth 0) (error "Compiler error: stack underflow"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4736 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4737
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4738
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4739 ;;; call tree stuff
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4740
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4741 (defun byte-compile-annotate-call-tree (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4742 (let (entry)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4743 ;; annotate the current call
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4744 (if (setq entry (assq (car form) byte-compile-call-tree))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4745 (or (memq byte-compile-current-form (nth 1 entry)) ;callers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4746 (setcar (cdr entry)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4747 (cons byte-compile-current-form (nth 1 entry))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4748 (push (list (car form) (list byte-compile-current-form) nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4749 byte-compile-call-tree))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4750 ;; annotate the current function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4751 (if (setq entry (assq byte-compile-current-form byte-compile-call-tree))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4752 (or (memq (car form) (nth 2 entry)) ;called
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4753 (setcar (cdr (cdr entry))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4754 (cons (car form) (nth 2 entry))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4755 (push (list byte-compile-current-form nil (list (car form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4756 byte-compile-call-tree))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4757
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4758 ;; Renamed from byte-compile-report-call-tree
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4759 ;; to avoid interfering with completion of byte-compile-file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4760 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4761 (defun display-call-tree (&optional filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4762 "Display a call graph of a specified file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4763 This lists which functions have been called, what functions called
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4764 them, and what functions they call. The list includes all functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4765 whose definitions have been compiled in this Emacs session, as well as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4766 all functions called by those functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4767
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4768 The call graph does not include macros, inline functions, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4769 primitives that the byte-code interpreter knows about directly \(eq,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4770 cons, etc.\).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4771
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4772 The call tree also lists those functions which are not known to be called
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4773 \(that is, to which no calls have been compiled\), and which cannot be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4774 invoked interactively."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4775 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4776 (message "Generating call tree...")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4777 (with-output-to-temp-buffer "*Call-Tree*"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4778 (set-buffer "*Call-Tree*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4779 (erase-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4780 (message "Generating call tree... (sorting on %s)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4781 byte-compile-call-tree-sort)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4782 (insert "Call tree for "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4783 (cond ((null byte-compile-current-file) (or filename "???"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4784 ((stringp byte-compile-current-file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4785 byte-compile-current-file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4786 (t (buffer-name byte-compile-current-file)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4787 " sorted on "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4788 (prin1-to-string byte-compile-call-tree-sort)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4789 ":\n\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4790 (if byte-compile-call-tree-sort
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4791 (setq byte-compile-call-tree
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4792 (sort byte-compile-call-tree
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4793 (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4794 ((eq byte-compile-call-tree-sort 'callers)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4795 #'(lambda (x y) (< (length (nth 1 x))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4796 (length (nth 1 y)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4797 ((eq byte-compile-call-tree-sort 'calls)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4798 #'(lambda (x y) (< (length (nth 2 x))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4799 (length (nth 2 y)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4800 ((eq byte-compile-call-tree-sort 'calls+callers)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4801 #'(lambda (x y) (< (+ (length (nth 1 x))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4802 (length (nth 2 x)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4803 (+ (length (nth 1 y))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4804 (length (nth 2 y))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4805 ((eq byte-compile-call-tree-sort 'name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4806 #'(lambda (x y) (string< (car x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4807 (car y))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4808 (t (error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4809 "`byte-compile-call-tree-sort': `%s' - unknown sort mode"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4810 byte-compile-call-tree-sort))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4811 (message "Generating call tree...")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4812 (let ((rest byte-compile-call-tree)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4813 (b (current-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4814 f p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4815 callers calls)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4816 (while rest
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4817 (prin1 (car (car rest)) b)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4818 (setq callers (nth 1 (car rest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4819 calls (nth 2 (car rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4820 (insert "\t"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4821 (cond ((not (fboundp (setq f (car (car rest)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4822 (if (null f)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4823 " <top level>";; shouldn't insert nil then, actually -sk
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4824 " <not defined>"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4825 ((subrp (setq f (symbol-function f)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4826 " <subr>")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4827 ((symbolp f)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4828 (format " ==> %s" f))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4829 ((compiled-function-p f)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4830 "<compiled function>")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4831 ((not (consp f))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4832 "<malformed function>")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4833 ((eq 'macro (car f))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4834 (if (or (compiled-function-p (cdr f))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4835 (assq 'byte-code (cdr (cdr (cdr f)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4836 " <compiled macro>"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4837 " <macro>"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4838 ((assq 'byte-code (cdr (cdr f)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4839 "<compiled lambda>")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4840 ((eq 'lambda (car f))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4841 "<function>")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4842 (t "???"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4843 (format " (%d callers + %d calls = %d)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4844 ;; Does the optimizer eliminate common subexpressions?-sk
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4845 (length callers)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4846 (length calls)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4847 (+ (length callers) (length calls)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4848 "\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4849 (if callers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4850 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4851 (insert " called by:\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4852 (setq p (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4853 (insert " " (if (car callers)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4854 (mapconcat 'symbol-name callers ", ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4855 "<top level>"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4856 (let ((fill-prefix " "))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4857 (fill-region-as-paragraph p (point)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4858 (if calls
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4859 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4860 (insert " calls:\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4861 (setq p (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4862 (insert " " (mapconcat 'symbol-name calls ", "))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4863 (let ((fill-prefix " "))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4864 (fill-region-as-paragraph p (point)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4865 (insert "\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4866 (setq rest (cdr rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4867
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4868 (message "Generating call tree...(finding uncalled functions...)")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4869 (setq rest byte-compile-call-tree)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4870 (let ((uncalled nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4871 (while rest
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4872 (or (nth 1 (car rest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4873 (null (setq f (car (car rest))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4874 (byte-compile-fdefinition f t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4875 (commandp (byte-compile-fdefinition f nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4876 (setq uncalled (cons f uncalled)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4877 (setq rest (cdr rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4878 (if uncalled
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4879 (let ((fill-prefix " "))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4880 (insert "Noninteractive functions not known to be called:\n ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4881 (setq p (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4882 (insert (mapconcat 'symbol-name (nreverse uncalled) ", "))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4883 (fill-region-as-paragraph p (point)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4884 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4885 (message "Generating call tree...done.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4886 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4887
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4888
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4889 ;;; by crl@newton.purdue.edu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4890 ;;; Only works noninteractively.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4891 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4892 (defun batch-byte-compile ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4893 "Run `byte-compile-file' on the files remaining on the command line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4894 Use this from the command line, with `-batch';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4895 it won't work in an interactive Emacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4896 Each file is processed even if an error occurred previously.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
4897 For example, invoke \"xemacs -batch -f batch-byte-compile $emacs/ ~/*.el\"."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4898 ;; command-line-args-left is what is left of the command line (from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4899 ;; startup.el)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4900 (defvar command-line-args-left) ;Avoid 'free variable' warning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4901 (if (not noninteractive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4902 (error "`batch-byte-compile' is to be used only with -batch"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4903 (let ((error nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4904 (while command-line-args-left
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4905 (if (null (batch-byte-compile-one-file))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4906 (setq error t)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4907 (message "Done")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4908 (kill-emacs (if error 1 0))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4909
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4910 ;;;###autoload
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4911 (defun batch-byte-compile-one-file ()
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4912 "Run `byte-compile-file' on a single file remaining on the command line.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4913 Use this from the command line, with `-batch';
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4914 it won't work in an interactive Emacs."
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4915 ;; command-line-args-left is what is left of the command line (from
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4916 ;; startup.el)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4917 (defvar command-line-args-left) ;Avoid 'free variable' warning
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4918 (if (not noninteractive)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4919 (error "`batch-byte-compile-one-file' is to be used only with -batch"))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4920 (let (error
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4921 (file-to-process (car command-line-args-left)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4922 (setq command-line-args-left (cdr command-line-args-left))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4923 (if (file-directory-p (expand-file-name file-to-process))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4924 (let ((files (directory-files file-to-process))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4925 source dest)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4926 (while files
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4927 (if (and (string-match emacs-lisp-file-regexp (car files))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4928 (not (auto-save-file-name-p (car files)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4929 (setq source (expand-file-name
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4930 (car files)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4931 file-to-process))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4932 (setq dest (byte-compile-dest-file source))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4933 (file-exists-p dest)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4934 (file-newer-than-file-p source dest))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4935 (if (null (batch-byte-compile-1 source))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4936 (setq error t)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4937 (setq files (cdr files)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4938 (null error))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4939 (batch-byte-compile-1 file-to-process))))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4940
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4941 (defun batch-byte-compile-1 (file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4942 (condition-case err
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4943 (progn (byte-compile-file file) t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4944 (error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4945 (princ ">>Error occurred processing ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4946 (princ file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4947 (princ ": ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4948 (if (fboundp 'display-error) ; XEmacs 19.8+
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4949 (display-error err nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4950 (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
4951 (mapc #'(lambda (x) (princ " ") (prin1 x)) (cdr err)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4952 (princ "\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4953 nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4954
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4955 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4956 (defun batch-byte-recompile-directory-norecurse ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4957 "Same as `batch-byte-recompile-directory' but without recursion."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4958 (setq byte-recompile-directory-recursively nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4959 (batch-byte-recompile-directory))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4960
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4961 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4962 (defun batch-byte-recompile-directory ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4963 "Runs `byte-recompile-directory' on the dirs remaining on the command line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4964 Must be used only with `-batch', and kills Emacs on completion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4965 For example, invoke `xemacs -batch -f batch-byte-recompile-directory .'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4966 ;; command-line-args-left is what is left of the command line (startup.el)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4967 (defvar command-line-args-left) ;Avoid 'free variable' warning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4968 (if (not noninteractive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4969 (error "batch-byte-recompile-directory is to be used only with -batch"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4970 (or command-line-args-left
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4971 (setq command-line-args-left '(".")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4972 (let ((byte-recompile-directory-ignore-errors-p t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4973 (while command-line-args-left
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4974 (byte-recompile-directory (car command-line-args-left))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4975 (setq command-line-args-left (cdr command-line-args-left))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4976 (kill-emacs 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4977
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4978 (make-obsolete 'elisp-compile-defun 'compile-defun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4979 (make-obsolete 'byte-compile-report-call-tree 'display-call-tree)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4980
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4981 ;; other make-obsolete calls in obsolete.el.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4982
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4983 (provide 'byte-compile)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4984 (provide 'bytecomp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4985
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4986
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4987 ;;; report metering (see the hacks in bytecode.c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4988
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4989 (if (boundp 'byte-code-meter)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4990 (defun byte-compile-report-ops ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4991 (defvar byte-code-meter)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4992 (with-output-to-temp-buffer "*Meter*"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4993 (set-buffer "*Meter*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4994 (let ((i 0) n op off)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4995 (while (< i 256)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4996 (setq n (aref (aref byte-code-meter 0) i)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4997 off nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4998 (if t ;(not (zerop n))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4999 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5000 (setq op i)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5001 (setq off nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5002 (cond ((< op byte-nth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5003 (setq off (logand op 7))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5004 (setq op (logand op 248)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5005 ((>= op byte-constant)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5006 (setq off (- op byte-constant)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5007 op byte-constant)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5008 (setq op (aref byte-code-vector op))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5009 (insert (format "%-4d" i))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5010 (insert (symbol-name op))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5011 (if off (insert " [" (int-to-string off) "]"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5012 (indent-to 40)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5013 (insert (int-to-string n) "\n")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5014 (setq i (1+ i)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5015
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5016
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5017 ;; To avoid "lisp nesting exceeds max-lisp-eval-depth" when bytecomp compiles
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5018 ;; itself, compile some of its most used recursive functions (at load time).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5019 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5020 (eval-when-compile
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5021 (or (compiled-function-p (symbol-function 'byte-compile-form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5022 (let ((byte-optimize nil) ; do it fast
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5023 (byte-compile-warnings nil))
5503
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
5024 (map nil (if noninteractive
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
5025 #'byte-compile
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
5026 #'(lambda (x)
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
5027 (message "compiling %s..." x)
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
5028 (byte-compile x)
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
5029 (message "compiling %s...done" x)))
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
5030 '(byte-compile-normal-call
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
5031 byte-compile-form
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
5032 byte-compile-body
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
5033 ;; Inserted some more than necessary, to speed it up.
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
5034 byte-compile-top-level
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
5035 byte-compile-out-toplevel
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
5036 byte-compile-constant
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
5037 byte-compile-variable-ref)))))
7b5946dbfb96 Drop support for generating code appropriate for Emacs 19, bytecomp.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5475
diff changeset
5038
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5039
4683
0cc9d22c3732 Be more reliable about loading cl-macs at byte-compile time, cl.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4677
diff changeset
5040 (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
5041
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5042 ;;; bytecomp.el ends here