annotate man/lispref/compile.texi @ 5585:86d6adeb1cf4

Refactor check for Xaw3d.
author Stephen J. Turnbull <stephen@xemacs.org>
date Fri, 14 Oct 2011 03:54:46 +0900
parents a46c5c8d6564
children 9fae6227ede5
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 @c -*-texinfo-*-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 @c This is part of the XEmacs Lisp Reference Manual.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 @c See the file lispref.texi for copying conditions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 @setfilename ../../info/compile.info
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 @node Byte Compilation, Debugging, Loading, Top
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 @chapter Byte Compilation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 @cindex byte-code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 @cindex compilation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 XEmacs Lisp has a @dfn{compiler} that translates functions written
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 in Lisp into a special representation called @dfn{byte-code} that can be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 executed more efficiently. The compiler replaces Lisp function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 definitions with byte-code. When a byte-coded function is called, its
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 definition is evaluated by the @dfn{byte-code interpreter}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 Because the byte-compiled code is evaluated by the byte-code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 interpreter, instead of being executed directly by the machine's
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 hardware (as true compiled code is), byte-code is completely
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 transportable from machine to machine without recompilation. It is not,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 however, as fast as true compiled code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 In general, any version of Emacs can run byte-compiled code produced
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 by recent earlier versions of Emacs, but the reverse is not true. In
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 particular, if you compile a program with XEmacs 20, the compiled code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 may not run in earlier versions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 The first time a compiled-function object is executed, the byte-code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 instructions are validated and the byte-code is further optimized. An
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 @code{invalid-byte-code} error is signaled if the byte-code is invalid,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 for example if it contains invalid opcodes. This usually means a bug in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 the byte compiler.
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 @iftex
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 @xref{Docs and Compilation}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 @end iftex
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 @xref{Compilation Errors}, for how to investigate errors occurring in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 byte compilation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 @menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 * Speed of Byte-Code:: An example of speedup from byte compilation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 * Compilation Functions:: Byte compilation functions.
1103
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
44 * Compilation Options:: Controlling the byte compiler's behavior.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 * Docs and Compilation:: Dynamic loading of documentation strings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 * Dynamic Loading:: Dynamic loading of individual functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 * Eval During Compile:: Code to be evaluated when you compile.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 * Compiled-Function Objects:: The data type used for byte-compiled functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 * Disassembly:: Disassembling byte-code; how to read byte-code.
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
50 * Different Behavior:: When compiled code gives different results.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 @end menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 @node Speed of Byte-Code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 @section Performance of Byte-Compiled Code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 A byte-compiled function is not as efficient as a primitive function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 written in C, but runs much faster than the version written in Lisp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 Here is an example:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 (defun silly-loop (n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 "Return time before and after N iterations of a loop."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 (let ((t1 (current-time-string)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 (while (> (setq n (1- n))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 (list t1 (current-time-string))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 @result{} silly-loop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 (silly-loop 5000000)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 @result{} ("Mon Sep 14 15:51:49 1998"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 "Mon Sep 14 15:52:07 1998") ; @r{18 seconds}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 (byte-compile 'silly-loop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 @result{} #<compiled-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 (n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 "...(23)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 [current-time-string t1 n 0]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 "Return time before and after N iterations of a loop.">
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 (silly-loop 5000000)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 @result{} ("Mon Sep 14 15:53:43 1998"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 "Mon Sep 14 15:53:49 1998") ; @r{6 seconds}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 In this example, the interpreted code required 18 seconds to run,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 whereas the byte-compiled code required 6 seconds. These results are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 representative, but actual results will vary greatly.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 @node Compilation Functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 @comment node-name, next, previous, up
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 @section The Compilation Functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 @cindex compilation functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 You can byte-compile an individual function or macro definition with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 the @code{byte-compile} function. You can compile a whole file with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 @code{byte-compile-file}, or several files with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 @code{byte-recompile-directory} or @code{batch-byte-compile}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 When you run the byte compiler, you may get warnings in a buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 called @samp{*Compile-Log*}. These report things in your program that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 suggest a problem but are not necessarily erroneous.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 @cindex macro compilation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 Be careful when byte-compiling code that uses macros. Macro calls are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 expanded when they are compiled, so the macros must already be defined
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 for proper compilation. For more details, see @ref{Compiling Macros}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 Normally, compiling a file does not evaluate the file's contents or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 load the file. But it does execute any @code{require} calls at top
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 level in the file. One way to ensure that necessary macro definitions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 are available during compilation is to @code{require} the file that defines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 them (@pxref{Named Features}). To avoid loading the macro definition files
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 when someone @emph{runs} the compiled program, write
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 @code{eval-when-compile} around the @code{require} calls (@pxref{Eval
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 During Compile}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 @defun byte-compile symbol
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 This function byte-compiles the function definition of @var{symbol},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 replacing the previous definition with the compiled one. The function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 definition of @var{symbol} must be the actual code for the function;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 i.e., the compiler does not follow indirection to another symbol.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 @code{byte-compile} returns the new, compiled definition of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 @var{symbol}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 If @var{symbol}'s definition is a compiled-function object,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 @code{byte-compile} does nothing and returns @code{nil}. Lisp records
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 only one function definition for any symbol, and if that is already
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 compiled, non-compiled code is not available anywhere. So there is no
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 way to ``compile the same definition again.''
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 (defun factorial (integer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 "Compute factorial of INTEGER."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 (if (= 1 integer) 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 (* integer (factorial (1- integer)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 @result{} factorial
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 (byte-compile 'factorial)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 @result{} #<compiled-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 (integer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 "...(21)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 [integer 1 factorial]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 "Compute factorial of INTEGER.">
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 @end example
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 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 The result is a compiled-function object. The string it contains is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 the actual byte-code; each character in it is an instruction or an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 operand of an instruction. The vector contains all the constants,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 variable names and function names used by the function, except for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 certain primitives that are coded as special instructions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 @deffn Command compile-defun &optional arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 This command reads the defun containing point, compiles it, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 evaluates the result. If you use this on a defun that is actually a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 function definition, the effect is to install a compiled version of that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 @c XEmacs feature
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 If @var{arg} is non-@code{nil}, the result is inserted in the current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 buffer after the form; otherwise, it is printed in the minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 @deffn Command byte-compile-file filename &optional load
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 This function compiles a file of Lisp code named @var{filename} into
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 a file of byte-code. The output file's name is made by appending
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 @samp{c} to the end of @var{filename}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 @c XEmacs feature
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 If @code{load} is non-@code{nil}, the file is loaded after having been
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 compiled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 Compilation works by reading the input file one form at a time. If it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 is a definition of a function or macro, the compiled function or macro
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 definition is written out. Other forms are batched together, then each
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 batch is compiled, and written so that its compiled code will be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 executed when the file is read. All comments are discarded when the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 input file is read.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 This command returns @code{t}. When called interactively, it prompts
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 for the file name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 % ls -l push*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 -rw-r--r-- 1 lewis 791 Oct 5 20:31 push.el
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 (byte-compile-file "~/emacs/push.el")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 @result{} t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 % ls -l push*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 -rw-r--r-- 1 lewis 791 Oct 5 20:31 push.el
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 -rw-r--r-- 1 lewis 638 Oct 8 20:25 push.elc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 @c flag is not optional in FSF Emacs
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
218 @deffn Command byte-recompile-directory directory &optional flag norecursion force
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 @cindex library compilation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 This function recompiles every @samp{.el} file in @var{directory} that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 needs recompilation. A file needs recompilation if a @samp{.elc} file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 exists but is older than the @samp{.el} file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
224 Files in subdirectories of @var{directory} are also processed unless
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
225 optional argument @var{norecursion} is non-@code{nil}.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
226
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 When a @samp{.el} file has no corresponding @samp{.elc} file, then
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 @var{flag} says what to do. If it is @code{nil}, these files are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 ignored. If it is non-@code{nil}, the user is asked whether to compile
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 each such file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
232 If the fourth optional argument @var{force} is non-@code{nil},
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
233 recompile every @samp{.el} file that already has a @samp{.elc} file.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
234
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 The return value of this command is unpredictable.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 @defun batch-byte-compile
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 This function runs @code{byte-compile-file} on files specified on the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 command line. This function must be used only in a batch execution of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 Emacs, as it kills Emacs on completion. An error in one file does not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 prevent processing of subsequent files. (The file that gets the error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 will not, of course, produce any compiled code.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 @example
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
246 % xemacs -batch -f batch-byte-compile *.el
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 @c XEmacs feature
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 @defun batch-byte-recompile-directory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 This function is similar to @code{batch-byte-compile} but runs the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 command @code{byte-recompile-directory} on the files remaining on the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 command line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 @c XEmacs feature
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 @defvar byte-recompile-directory-ignore-errors-p
1103
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
259 When non-@code{nil}, @code{byte-recompile-directory} will continue
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
260 compiling even when an error occurs in a file. Default: @code{nil}, but
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
261 bound to @code{t} by @code{batch-byte-recompile-directory}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263
1103
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
264 @c XEmacs feature (?)
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
265 @defvar byte-recompile-directory-recursively
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
266 When non-@code{nil}, @code{byte-recompile-directory} will recurse on
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
267 subdirectories. Default: @code{t}.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
268 @end defvar
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
269
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
270
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
271 @defun byte-code instructions constants stack-depth
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 @cindex byte-code interpreter
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 This function actually interprets byte-code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 Don't call this function yourself. Only the byte compiler knows how to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 generate valid calls to this function.
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 In newer Emacs versions (19 and up), byte code is usually executed as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 part of a compiled-function object, and only rarely due to an explicit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 call to @code{byte-code}. A byte-compiled function was once actually
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 defined with a body that calls @code{byte-code}, but in recent versions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 of Emacs @code{byte-code} is only used to run isolated fragments of lisp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 code without an associated argument list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284
1103
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
285 @node Compilation Options
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
286 @section Options for the Byte Compiler
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
287 @cindex compilation options
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
288
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
289 Warning: this node is a quick draft based on docstrings. There may be
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
290 inaccuracies, as the docstrings occasionally disagree with each other.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
291 This has not been checked yet.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
292
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
293 The byte compiler and optimizer are controlled by the following
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
294 variables. The @code{byte-compiler-options} macro described below
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
295 provides a convenient way to set most of them on a file-by-file basis.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
296
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
297 @defvar emacs-lisp-file-regexp
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
298 Regexp which matches Emacs Lisp source files.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
299 You may want to redefine @code{byte-compile-dest-file} if you change
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
300 this. Default: @code{"\\.el$"}.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
301 @end defvar
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
302
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
303 @defun byte-compile-dest-file filename
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
304 Convert an Emacs Lisp source file name to a compiled file name. This
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
305 function may be redefined by the user, if necessary, for compatibility
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
306 with @code{emacs-lisp-file-regexp}.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
307 @end defun
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
308
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
309 @c ;; This can be the 'byte-compile property of any symbol.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
310 @c (autoload 'byte-compile-inline-expand "byte-optimize")
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
311
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
312 @defvar byte-compile-verbose
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
313 When non-@code{nil}, print messages describing progress of
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
314 byte-compiler. Default: @code{t} if interactive on a not-too-slow
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
315 terminal (see @code{search-slow-speed}), otherwise @code{nil}.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
316 @end defvar
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
317
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
318 @defvar byte-optimize
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
319 Level of optimization in the byte compiler.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
320
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
321 @table @code
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
322 @item nil
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
323 Do no optimization.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
324
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
325 @item t
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
326 Do all optimizations.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
327
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
328 @item source
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
329 Do optimizations manipulating the source code only.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
330
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
331 @item byte
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
332 Do optimizations manipulating the byte code (actually, LAP code) only.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
333 @end table
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
334 Default: @code{t}.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
335 @end defvar
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
336
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
337 @defvar byte-compile-delete-errors
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
338 When non-@code{nil}, the optimizer may delete forms that may signal an
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
339 error if that is the only change in the function's behavior.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
340 This includes variable references and calls to functions such as
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
341 @code{car}.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
342 Default: @code{t}.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
343 @end defvar
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
344
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
345 @defvar byte-optimize-log nil
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
346 When non-@code{nil}, the byte-compiler logs optimizations into
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
347 @file{*Compile-Log*}.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
348
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
349 @table @code
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
350 @item nil
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
351 Log no optimization.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
352
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
353 @item t
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
354 Log all optimizations.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
355
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
356 @item source
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
357 Log optimizations manipulating the source code only.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
358
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
359 @item byte
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
360 Log optimizations manipulating the byte code (actually, LAP code) only.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
361 @end table
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
362 Default: @code{nil}.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
363 @end defvar
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
364
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
365 @defvar byte-compile-error-on-warn
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
366 When non-@code{nil}, the byte-compiler reports warnings with @code{error}.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
367 Default: @code{nil}.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
368 @end defvar
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
369
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
370 @defvar byte-compile-default-warnings
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
371 The warnings used when @code{byte-compile-warnings} is @code{t}. Called
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
372 @code{byte-compile-warning-types} in GNU Emacs.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
373 Default: @code{(redefine callargs subr-callargs free-vars unresolved
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
374 unused-vars obsolete)}.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
375 @end defvar
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
376
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
377 @defvar byte-compile-warnings
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
378
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
379 List of warnings that the compiler should issue (@code{t} for the
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
380 default set). Elements of the list may be:
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
381
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
382 @table @code
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
383 @item free-vars
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
384 References to variables not in the current lexical scope.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
385
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
386 @item unused-vars
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
387 References to non-global variables bound but not referenced.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
388
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
389 @item unresolved
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
390 Calls to unknown functions.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
391
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
392 @item callargs
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
393 Lambda calls with args that don't match the definition.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
394
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
395 @item subr-callargs
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
396 Calls to subrs with args that don't match the definition.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
397
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
398 @item redefine
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
399 Function cell redefined from a macro to a lambda or vice
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
400 versa, or redefined to take a different number of arguments.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
401
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
402 @item obsolete
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
403 Use of an obsolete function or variable.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
404
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
405 @item pedantic
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
406 Warn of use of compatible symbols.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
407 @end table
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
408
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
409 The default set is specified by @code{byte-compile-default-warnings} and
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
410 normally encompasses all possible warnings.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
411
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
412 See also the macro @code{byte-compiler-options}. Default: @code{t}.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
413 @end defvar
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
414
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
415 The compiler can generate a call graph, which gives information about
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
416 which functions call which functions.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
417
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
418 @defvar byte-compile-generate-call-tree
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
419 When non-@code{nil}, the compiler generates a call graph. This records
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
420 functions that were called and from where. If the value is @code{t},
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
421 compilation displays the call graph when it finishes. If the value is
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
422 neither @code{t} nor @code{nil}, compilation asks you whether to display
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
423 the graph.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
424
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
425 The call tree only lists functions called, not macros used. Those
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
426 functions which the byte-code interpreter knows about directly
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
427 (@code{eq}, @code{cons}, etc.) are not reported.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
428
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
429 The call tree also lists those functions which are not known to be called
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
430 (that is, to which no calls have been compiled). Functions which can be
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
431 invoked interactively are excluded from this list. Default: @code{nil}.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
432 @end defvar
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
433
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
434 @defvar byte-compile-call-tree nil
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
435
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
436 Alist of functions and their call tree, used internally.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
437 Each element takes the form
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
438
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
439 (@var{function} @var{callers} @var{calls})
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
440
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
441 where @var{callers} is a list of functions that call @var{function}, and
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
442 @var{calls} is a list of functions for which calls were generated while
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
443 compiling @var{function}.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
444 @end defvar
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
445
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
446 @defvar byte-compile-call-tree-sort
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
447 When non-@code{nil}, sort the call tree. The values @code{name},
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
448 @code{callers}, @code{calls}, and @code{calls+callers} specify different
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
449 fields to sort on.") Default: @code{name}.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
450 @end defvar
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
451
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
452 @code{byte-compile-overwrite-file} controls treatment of existing
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
453 compiled files.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
454
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
455 @defvar byte-compile-overwrite-file
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
456 When non-@code{nil}, do not preserve backups of @file{.elc}s.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
457 Precisely, if @code{nil}, old @file{.elc} files are deleted before the
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
458 new one is saved, and @file{.elc} files will have the same modes as the
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
459 corresponding @file{.el} file. Otherwise, existing @file{.elc} files
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
460 will simply be overwritten, and the existing modes will not be changed.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
461 If this variable is @code{nil}, then an @file{.elc} file which is a
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
462 symbolic link will be turned into a normal file, instead of the file
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
463 which the link points to being overwritten. Default: @code{t}.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
464 @end defvar
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
465
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
466 Variables controlling recompiling directories are described elsewhere
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
467 @xref{Compilation Functions}. They are
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
468 @code{byte-recompile-directory-ignore-errors-p} and
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
469 @code{byte-recompile-directory-recursively}.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
470
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
471 The dynamic loading features are described elsewhere. These are
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
472 controlled by the variables @code{byte-compile-dynamic} (@pxref{Dynamic
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
473 Loading}) and @code{byte-compile-dynamic-docstrings} (@pxref{Docs and
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
474 Compilation}).
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
475
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
476 The byte compiler is a relatively recent development, and has evolved
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
477 significantly over the period covering Emacs versions 19 and 20. The
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
478 following variables control use of newer functionality by the byte
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
479 compiler. These are rarely needed since the release of XEmacs 21.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
480
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
481 Another set of compatibility issues arises between Mule and non-Mule
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
482 XEmacsen; there are no known compatibility issues specific to the byte
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
483 compiler. There are also compatibility issues between XEmacs and GNU
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
484 Emacs's versions of the byte compiler. While almost all of the byte
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
485 codes are the same, and code compiled by one version often runs
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
486 perfectly well on the other, this is very dangerous, and can result in
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
487 crashes or data loss. Always recompile your Lisp when moving between
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
488 XEmacs and GNU Emacs.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
489
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
490 @defvar byte-compile-single-version nil
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
491 When non-@code{nil}, the choice of emacs version (v19 or v20) byte-codes
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
492 will be hard-coded into bytecomp when it compiles itself. If the
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
493 compiler itself is compiled with optimization, this causes a speedup.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
494 Default: @code{nil}.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
495 @end defvar
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
496
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
497 @defvar byte-compile-emacs19-compatibility
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
498 When non-@code{nil} generate output that can run in Emacs 19.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
499 Default: @code{nil} when Emacs version is 20 or above, otherwise
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
500 @code{t}.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
501 @end defvar
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
502
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
503 @defvar byte-compile-print-gensym
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
504 When non-@code{nil}, the compiler may generate code that creates unique
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
505 symbols at run-time. This is achieved by printing uninterned symbols
2960
9151417c3852 [xemacs-hg @ 2005-09-27 21:43:19 by adrian]
adrian
parents: 2949
diff changeset
506 using the @code{#:@var{symbol}} notation, so that they will be read
2949
4b7e0ff1958a [xemacs-hg @ 2005-09-25 21:40:17 by adrian]
adrian
parents: 1103
diff changeset
507 uninterned when run.
1103
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
508
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
509 With this feature, code that uses uninterned symbols in macros will
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
510 not be runnable under pre-21.0 XEmacsen.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
511
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
512 Default: When @code{byte-compile-emacs19-compatibility} is non-nil, this
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
513 variable is ignored and considered to be @code{nil}. Otherwise
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
514 @code{t}.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
515 @end defvar
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
516
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
517 @defvar byte-compile-new-bytecodes
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
518 This is completely ignored. For backwards compatibility.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
519 @end defvar
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
520
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
521 @defun byte-compiler-options &rest args
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
522 Set some compilation-parameters for this file.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
523 This will affect only the file in which it appears; this does nothing when
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
524 evaluated, or when loaded from a @file{.el} file.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
525
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
526 Each argument to this macro must be a list of a key and a value.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
527 (#### Need to check whether the newer variables are settable here.)
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
528
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
529 @example
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
530 Keys: Values: Corresponding variable:
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
531
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
532 verbose t, nil byte-compile-verbose
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
533 optimize t, nil, source, byte byte-optimize
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
534 warnings list of warnings byte-compile-warnings
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
535 file-format emacs19, emacs20 byte-compile-emacs19-compatibility
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
536 @end example
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
537
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
538 The value specified with the @code{warnings}option must be a list,
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
539 containing some subset of the following flags:
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
540
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
541 @example
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
542 free-vars references to variables not in the current lexical scope.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
543 unused-vars references to non-global variables bound but not referenced.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
544 unresolved calls to unknown functions.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
545 callargs lambda calls with args that don't match the definition.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
546 redefine function cell redefined from a macro to a lambda or vice
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
547 versa, or redefined to take a different number of arguments.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
548 @end example
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
549
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
550 If the first element if the list is @code{+} or `@code{} then the
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
551 specified elements are added to or removed from the current set of
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
552 warnings, instead of the entire set of warnings being overwritten.
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
553 (#### Need to check whether the newer warnings are settable here.)
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
554
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
555 For example, something like this might appear at the top of a source file:
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
556
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
557 @example
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
558 (byte-compiler-options
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
559 (optimize t)
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
560 (warnings (- callargs)) ; Don't warn about arglist mismatch
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
561 (warnings (+ unused-vars)) ; Do warn about unused bindings
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
562 (file-format emacs19))
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
563 @end example
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
564 @end defun
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
565
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 @node Docs and Compilation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 @section Documentation Strings and Compilation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 @cindex dynamic loading of documentation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 Functions and variables loaded from a byte-compiled file access their
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 documentation strings dynamically from the file whenever needed. This
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 saves space within Emacs, and makes loading faster because the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 documentation strings themselves need not be processed while loading the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 file. Actual access to the documentation strings becomes slower as a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 result, but normally not enough to bother users.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 Dynamic access to documentation strings does have drawbacks:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 @itemize @bullet
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 If you delete or move the compiled file after loading it, Emacs can no
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 longer access the documentation strings for the functions and variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 in the file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 If you alter the compiled file (such as by compiling a new version),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 then further access to documentation strings in this file will give
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 nonsense results.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 @end itemize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 If your site installs Emacs following the usual procedures, these
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 problems will never normally occur. Installing a new version uses a new
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 directory with a different name; as long as the old version remains
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 installed, its files will remain unmodified in the places where they are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 expected to be.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 However, if you have built Emacs yourself and use it from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 directory where you built it, you will experience this problem
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 occasionally if you edit and recompile Lisp files. When it happens, you
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 can cure the problem by reloading the file after recompiling it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 Versions of Emacs up to and including XEmacs 19.14 and FSF Emacs 19.28
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 do not support the dynamic docstrings feature, and so will not be able
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 to load bytecode created by more recent Emacs versions. You can turn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 off the dynamic docstring feature by setting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 @code{byte-compile-dynamic-docstrings} to @code{nil}. Once this is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 done, you can compile files that will load into older Emacs versions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 You can do this globally, or for one source file by specifying a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 file-local binding for the variable. Here's one way to do that:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 -*-byte-compile-dynamic-docstrings: nil;-*-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 @defvar byte-compile-dynamic-docstrings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 If this is non-@code{nil}, the byte compiler generates compiled files
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 that are set up for dynamic loading of documentation strings.
1103
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
618 Default: t.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 @cindex @samp{#@@@var{count}}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 @cindex @samp{#$}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 The dynamic documentation string feature writes compiled files that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 use a special Lisp reader construct, @samp{#@@@var{count}}. This
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 construct skips the next @var{count} characters. It also uses the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 @samp{#$} construct, which stands for ``the name of this file, as a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 string.'' It is best not to use these constructs in Lisp source files.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 @node Dynamic Loading
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 @section Dynamic Loading of Individual Functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 @cindex dynamic loading of functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 @cindex lazy loading
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 When you compile a file, you can optionally enable the @dfn{dynamic
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 function loading} feature (also known as @dfn{lazy loading}). With
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 dynamic function loading, loading the file doesn't fully read the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 function definitions in the file. Instead, each function definition
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 contains a place-holder which refers to the file. The first time each
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 function is called, it reads the full definition from the file, to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 replace the place-holder.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 The advantage of dynamic function loading is that loading the file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 becomes much faster. This is a good thing for a file which contains
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 many separate commands, provided that using one of them does not imply
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 you will soon (or ever) use the rest. A specialized mode which provides
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 many keyboard commands often has that usage pattern: a user may invoke
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 the mode, but use only a few of the commands it provides.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 The dynamic loading feature has certain disadvantages:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 @itemize @bullet
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 If you delete or move the compiled file after loading it, Emacs can no
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 longer load the remaining function definitions not already loaded.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 If you alter the compiled file (such as by compiling a new version),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 then trying to load any function not already loaded will get nonsense
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 results.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 @end itemize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 If you compile a new version of the file, the best thing to do is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 immediately load the new compiled file. That will prevent any future
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 problems.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 The byte compiler uses the dynamic function loading feature if the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 variable @code{byte-compile-dynamic} is non-@code{nil} at compilation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 time. Do not set this variable globally, since dynamic loading is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 desirable only for certain files. Instead, enable the feature for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 specific source files with file-local variable bindings, like this:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 -*-byte-compile-dynamic: t;-*-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 @defvar byte-compile-dynamic
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 If this is non-@code{nil}, the byte compiler generates compiled files
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 that are set up for dynamic function loading.
1103
80d9ab2e9855 [xemacs-hg @ 2002-11-12 03:57:44 by stephent]
stephent
parents: 446
diff changeset
679 Default: nil.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 @defun fetch-bytecode function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 This immediately finishes loading the definition of @var{function} from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 its byte-compiled file, if it is not fully loaded already. The argument
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 @var{function} may be a compiled-function object or a function name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 @node Eval During Compile
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 @section Evaluation During Compilation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 These features permit you to write code to be evaluated during
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 compilation of a program.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693
5547
a46c5c8d6564 Avoid calling various macros "special operators" in the manuals.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5361
diff changeset
694 @defmac eval-and-compile body
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 This form marks @var{body} to be evaluated both when you compile the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 containing code and when you run it (whether compiled or not).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 You can get a similar result by putting @var{body} in a separate file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 and referring to that file with @code{require}. Using @code{require} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 preferable if there is a substantial amount of code to be executed in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 this way.
5547
a46c5c8d6564 Avoid calling various macros "special operators" in the manuals.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5361
diff changeset
702 @end defmac
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703
5547
a46c5c8d6564 Avoid calling various macros "special operators" in the manuals.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5361
diff changeset
704 @defmac eval-when-compile body
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 This form marks @var{body} to be evaluated at compile time and not when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 the compiled program is loaded. The result of evaluation by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 compiler becomes a constant which appears in the compiled program. When
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 the program is interpreted, not compiled at all, @var{body} is evaluated
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 normally.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 At top level, this is analogous to the Common Lisp idiom
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 @code{(eval-when (compile eval) @dots{})}. Elsewhere, the Common Lisp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 @samp{#.} reader macro (but not when interpreting) is closer to what
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 @code{eval-when-compile} does.
5547
a46c5c8d6564 Avoid calling various macros "special operators" in the manuals.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5361
diff changeset
715 @end defmac
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 @node Compiled-Function Objects
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 @section Compiled-Function Objects
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 @cindex compiled function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 @cindex byte-code function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 Byte-compiled functions have a special data type: they are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 @dfn{compiled-function objects}. The evaluator handles this data type
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 specially when it appears as a function to be called.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 The printed representation for a compiled-function object normally
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 begins with @samp{#<compiled-function} and ends with @samp{>}. However,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 if the variable @code{print-readably} is non-@code{nil}, the object is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 printed beginning with @samp{#[} and ending with @samp{]}. This
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 representation can be read directly by the Lisp reader, and is used in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 byte-compiled files (those ending in @samp{.elc}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 In Emacs version 18, there was no compiled-function object data type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 compiled functions used the function @code{byte-code} to run the byte
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 code.
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 A compiled-function object has a number of different attributes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 They are:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 @table @var
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 @item arglist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 The list of argument symbols.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 @item instructions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 The string containing the byte-code instructions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 @item constants
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 The vector of Lisp objects referenced by the byte code. These include
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 symbols used as function names and variable names.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
751 @item stack-depth
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 The maximum stack size this function needs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 @item doc-string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 The documentation string (if any); otherwise, @code{nil}. The value may
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 be a number or a list, in case the documentation string is stored in a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 file. Use the function @code{documentation} to get the real
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 documentation string (@pxref{Accessing Documentation}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 @item interactive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 The interactive spec (if any). This can be a string or a Lisp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 expression. It is @code{nil} for a function that isn't interactive.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 @item domain
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 The domain (if any). This is only meaningful if I18N3 (message-translation)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 support was compiled into XEmacs. This is a string defining which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 domain to find the translation for the documentation string and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 interactive prompt. @xref{Domain Specification}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 Here's an example of a compiled-function object, in printed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 representation. It is the definition of the command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 @code{backward-sexp}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 (symbol-function 'backward-sexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 @result{} #<compiled-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 "...(15)" [arg 1 forward-sexp] 2 854740 "_p">
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 The primitive way to create a compiled-function object is with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 @code{make-byte-code}:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
785 @defun make-byte-code arglist instructions constants stack-depth &optional doc-string interactive
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 This function constructs and returns a compiled-function object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 with the specified attributes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 @emph{Please note:} Unlike all other Emacs-lisp functions, calling this with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 five arguments is @emph{not} the same as calling it with six arguments,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 the last of which is @code{nil}. If the @var{interactive} arg is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 specified as @code{nil}, then that means that this function was defined
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 with @code{(interactive)}. If the arg is not specified, then that means
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 the function is not interactive. This is terrible behavior which is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 retained for compatibility with old @samp{.elc} files which expected
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 these semantics.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 You should not try to come up with the elements for a compiled-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 object yourself, because if they are inconsistent, XEmacs may crash
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 when you call the function. Always leave it to the byte compiler to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 create these objects; it makes the elements consistent (we hope).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 The following primitives are provided for accessing the elements of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 a compiled-function object.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 @defun compiled-function-arglist function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 This function returns the argument list of compiled-function object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 @var{function}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 @defun compiled-function-instructions function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 This function returns a string describing the byte-code instructions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 of compiled-function object @var{function}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 @defun compiled-function-constants function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 This function returns the vector of Lisp objects referenced by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 compiled-function object @var{function}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
822 @defun compiled-function-stack-depth function
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 This function returns the maximum stack size needed by compiled-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 object @var{function}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 @defun compiled-function-doc-string function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 This function returns the doc string of compiled-function object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 @var{function}, if available.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 @defun compiled-function-interactive function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 This function returns the interactive spec of compiled-function object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 @var{function}, if any. The return value is @code{nil} or a two-element
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 list, the first element of which is the symbol @code{interactive} and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 the second element is the interactive spec (a string or Lisp form).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 @defun compiled-function-domain function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 This function returns the domain of compiled-function object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 @var{function}, if any. The result will be a string or @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 @xref{Domain Specification}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 @node Disassembly
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 @section Disassembled Byte-Code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 @cindex disassembled byte-code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 People do not write byte-code; that job is left to the byte compiler.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 But we provide a disassembler to satisfy a cat-like curiosity. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 disassembler converts the byte-compiled code into humanly readable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 form.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 The byte-code interpreter is implemented as a simple stack machine.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 It pushes values onto a stack of its own, then pops them off to use them
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 in calculations whose results are themselves pushed back on the stack.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 When a byte-code function returns, it pops a value off the stack and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 returns it as the value of the function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 In addition to the stack, byte-code functions can use, bind, and set
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 ordinary Lisp variables, by transferring values between variables and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 the stack.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 @deffn Command disassemble object &optional stream
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 This function prints the disassembled code for @var{object}. If
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 @var{stream} is supplied, then output goes there. Otherwise, the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 disassembled code is printed to the stream @code{standard-output}. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 argument @var{object} can be a function name or a lambda expression.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 As a special exception, if this function is used interactively,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 it outputs to a buffer named @samp{*Disassemble*}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 Here are two examples of using the @code{disassemble} function. We
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 have added explanatory comments to help you relate the byte-code to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 Lisp source; these do not appear in the output of @code{disassemble}.
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 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 (defun factorial (integer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 "Compute factorial of an integer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 (if (= 1 integer) 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 (* integer (factorial (1- integer)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 @result{} factorial
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 (factorial 4)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 @result{} 24
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 (disassemble 'factorial)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 @print{} byte-code for factorial:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 doc: Compute factorial of an integer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 args: (integer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 0 varref integer ; @r{Get value of @code{integer}}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 ; @r{from the environment}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 ; @r{and push the value}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 ; @r{onto the stack.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 1 constant 1 ; @r{Push 1 onto stack.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 2 eqlsign ; @r{Pop top two values off stack,}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 ; @r{compare them,}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 ; @r{and push result onto stack.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 3 goto-if-nil 1 ; @r{Pop and test top of stack;}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 ; @r{if @code{nil},}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 ; @r{go to label 1 (which is also byte 7),}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 ; @r{else continue.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 5 constant 1 ; @r{Push 1 onto top of stack.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 6 return ; @r{Return the top element}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 ; @r{of the stack.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 7:1 varref integer ; @r{Push value of @code{integer} onto stack.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 8 constant factorial ; @r{Push @code{factorial} onto stack.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 9 varref integer ; @r{Push value of @code{integer} onto stack.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 10 sub1 ; @r{Pop @code{integer}, decrement value,}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 ; @r{push new value onto stack.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 ; @r{Stack now contains:}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 ; @minus{} @r{decremented value of @code{integer}}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 ; @minus{} @r{@code{factorial}}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 ; @minus{} @r{value of @code{integer}}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 15 call 1 ; @r{Call function @code{factorial} using}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 ; @r{the first (i.e., the top) element}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 ; @r{of the stack as the argument;}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 ; @r{push returned value onto stack.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 ; @r{Stack now contains:}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 ; @minus{} @r{result of recursive}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 ; @r{call to @code{factorial}}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 ; @minus{} @r{value of @code{integer}}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 12 mult ; @r{Pop top two values off the stack,}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 ; @r{multiply them,}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 ; @r{pushing the result onto the stack.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 13 return ; @r{Return the top element}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 ; @r{of the stack.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 The @code{silly-loop} function is somewhat more complex:
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 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 (defun silly-loop (n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 "Return time before and after N iterations of a loop."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 (let ((t1 (current-time-string)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 (while (> (setq n (1- n))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 (list t1 (current-time-string))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 @result{} silly-loop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 (disassemble 'silly-loop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 @print{} byte-code for silly-loop:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 doc: Return time before and after N iterations of a loop.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990 args: (n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992 0 constant current-time-string ; @r{Push}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 ; @r{@code{current-time-string}}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 ; @r{onto top of stack.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998 1 call 0 ; @r{Call @code{current-time-string}}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999 ; @r{ with no argument,}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000 ; @r{ pushing result onto stack.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004 2 varbind t1 ; @r{Pop stack and bind @code{t1}}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005 ; @r{to popped value.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006 @end group
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 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 3:1 varref n ; @r{Get value of @code{n} from}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 ; @r{the environment and push}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011 ; @r{the value onto the stack.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015 4 sub1 ; @r{Subtract 1 from top of stack.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019 5 dup ; @r{Duplicate the top of the stack;}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 ; @r{i.e., copy the top of}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021 ; @r{the stack and push the}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1022 ; @r{copy onto the stack.}
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 6 varset n ; @r{Pop the top of the stack,}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025 ; @r{and set @code{n} to the value.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 ; @r{In effect, the sequence @code{dup varset}}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028 ; @r{copies the top of the stack}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029 ; @r{into the value of @code{n}}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030 ; @r{without popping it.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 7 constant 0 ; @r{Push 0 onto stack.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036 8 gtr ; @r{Pop top two values off stack,}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 ; @r{test if @var{n} is greater than 0}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038 ; @r{and push result onto stack.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1040
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042 9 goto-if-not-nil 1 ; @r{Goto label 1 (byte 3) if @code{n} <= 0}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043 ; @r{(this exits the while loop).}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 ; @r{else pop top of stack}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 ; @r{and continue}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049 11 varref t1 ; @r{Push value of @code{t1} onto stack.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1053 12 constant current-time-string ; @r{Push}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1054 ; @r{@code{current-time-string}}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055 ; @r{onto top of stack.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059 13 call 0 ; @r{Call @code{current-time-string} again.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1060
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061 14 unbind 1 ; @r{Unbind @code{t1} in local environment.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1062 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1063
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1064 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065 15 list2 ; @r{Pop top two elements off stack,}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1066 ; @r{create a list of them,}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1067 ; @r{and push list onto stack.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1068 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1069
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1070 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071 16 return ; @r{Return the top element of the stack.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1072
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1073 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1074 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1075 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1076
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1077
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1078 @node Different Behavior
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1079 @section Different Behavior
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1080
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1081 The intent is that compiled byte-code and the corresponding code
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1082 executed by the Lisp interpreter produce identical results. However,
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1083 there are some circumstances where the results will differ.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1084
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1085 @itemize @bullet
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1086 @item
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1087 Arithmetic operations may be rearranged for efficiency or compile-time
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1088 evaluation. When floating point numbers are involved, this may produce
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1089 different values or an overflow.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1090 @item
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1091 Some arithmetic operations may be optimized away. For example, the
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1092 expression @code{(+ x)} may be optimized to simply @code{x}. If the
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1093 value of @code{x} is a marker, then the value will be a marker instead
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1094 of an integer. If the value of @samp{x} is a cons cell, then the
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1095 interpreter will issue an error, while the bytecode will not.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1096
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1097 If you're trying to use @samp{(+ @var{object} 0)} to convert
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1098 @var{object} to integer, consider using an explicit conversion function,
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1099 which is clearer and guaranteed to work.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1100 Instead of @samp{(+ @var{marker} 0)}, use @samp{(marker-position @var{marker})}.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1101 Instead of @samp{(+ @var{char} 0)}, use @samp{(char-int @var{char})}.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1102 @end itemize
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1103
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1104 For maximal equivalence between interpreted and compiled code, the
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1105 variables @code{byte-compile-delete-errors} and
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1106 @code{byte-compile-optimize} can be set to @code{nil}, but this is not
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1107 recommended.