~ubuntu-branches/ubuntu/vivid/gcl/vivid

« back to all changes in this revision

Viewing changes to info/compile.texi

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2002-03-04 14:29:59 UTC
  • Revision ID: james.westby@ubuntu.com-20020304142959-dey14w08kr7lldu3
Tags: upstream-2.5.0.cvs20020219
ImportĀ upstreamĀ versionĀ 2.5.0.cvs20020219

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
@node Compilation, Symbols, Special Forms and Functions, Top
 
2
@chapter Compilation
 
3
 
 
4
@defun COMPILE (name &optional (definition nil))
 
5
Package:LISP
 
6
 
 
7
If DEFINITION is NIL, NAME must be the name of a not-yet-compiled
 
8
function.  In this case, COMPILE compiles the function, installs the compiled
 
9
function as the global function definition of NAME, and returns NAME.
 
10
If DEFINITION is non-NIL, it must be a lambda expression and NAME must be
 
11
a symbol.  COMPILE compiles the lambda expression, installs the compiled
 
12
function as the function definition of NAME, and returns NAME.
 
13
There is only one exception for this:  If NAME is NIL, then the compiled
 
14
function is not installed but is simply returned as the value of COMPILE.
 
15
     In any case, COMPILE creates temporary files whose filenames are
 
16
"gazonk***".  By default, i.e. if :LEAVE-GAZONK is not supplied or is
 
17
NIL, these files are automatically deleted after compilation.
 
18
 
 
19
 
 
20
@end defun
 
21
 
 
22
@deffn {Special Form} EVAL-WHEN 
 
23
Package:LISP
 
24
 
 
25
Syntax:
 
26
@example
 
27
(eval-when (@{situation@}*) @{form@}*)
 
28
@end example
 
29
 
 
30
A situation must be either COMPILE, LOAD, or EVAL.  The interpreter evaluates
 
31
only when EVAL is specified.  If COMPILE is specified, FORMs are evaluated
 
32
at compile time.  If LOAD is specified, the compiler arranges so that FORMs
 
33
be evaluated when the compiled code is loaded.
 
34
 
 
35
 
 
36
@end deffn
 
37
 
 
38
@defun COMPILE-FILE (input-pathname &key output-file (load nil) (message-file nil)  ;GCL specific keywords: system-p c-debug c-file h-file data-file)
 
39
Package:LISP
 
40
 
 
41
 
 
42
Compiles the file specified by INPUT-PATHNAME and generates a fasl file
 
43
specified by OUTPUT-FILE.  If the filetype is not specified in INPUT-PATHNAME,
 
44
then ".lsp" is used as the default file type for the source file.  :LOAD
 
45
specifies whether to load the generated fasl file after compilation.
 
46
:MESSAGE-FILE specifies the log file for the compiler messages.  It defaults to
 
47
the value of the variable COMPILER:*DEFAULT-MESSAGE-FILE*.  A non-NIL value of
 
48
COMPILER::*COMPILE-PRINT* forces the compiler to indicate the form currently
 
49
being compiled.  More keyword parameters are accepted, depending on the
 
50
version.  Most versions of GCL can receive :O-FILE, :C-FILE, :H-FILE, and
 
51
:DATA-FILE keyword parameters, with which you can control the intermediate
 
52
files generated by the GCL compiler.  Also :C-DEBUG will pass the -g flag to
 
53
the C compiler.
 
54
 
 
55
 
 
56
By top level forms in a file, we mean the value of *top-level-forms* after
 
57
doing (TF form) for each form read from a file.  We define TF as follows:
 
58
 
 
59
(defun TF (x)
 
60
 (when (consp x)
 
61
  (setq x (macroexpand x))
 
62
  (when (consp x)
 
63
     (cond ((member (car x) '(progn  eval-when))
 
64
            (mapcar 'tf (cdr x)))
 
65
           (t  (push x *top-level-forms*))))))
 
66
 
 
67
Among the common lisp special forms only DEFUN and DEFMACRO will cause actual
 
68
native machine code to be generated.  The rest will be specially treated in an
 
69
init section of the .data file.  This is done so that things like putprop,setq,
 
70
and many other forms would use up space which could not be usefully freed, if
 
71
we were to compile to native machine code.  If you have other `ordinary' top
 
72
level forms which you need to have compiled fully to machine code you may
 
73
either set compiler::*COMPILE-ORDINARIES* to t, or put them inside a
 
74
 
 
75
(PROGN 'COMPILE ...forms-which-need-to-be-compiled)
 
76
 
 
77
The compiler will take each of them and make a temporary function which will be
 
78
compiled and invoked once.  It is permissible to wrap a (PROGN 'COMPILE ..)
 
79
around the whole file.  Currently this construction binds the
 
80
compiler::*COMPILE-ORDINARIES* flag to t.  Setting this flag globally to a non
 
81
nil value to cause all top level forms to generate machine code.  This might be
 
82
useful in a system such as PCL, where a number of top level lambda expressions
 
83
are given.  Note that most common lisps will simply ignore the top level atom
 
84
'compile, since it has no side effects.
 
85
 
 
86
Defentry, clines, and defcfun also result in machine code being generated.
 
87
 
 
88
@unnumbered subsection Evaluation at Compile time
 
89
 
 
90
  In GCL the eval-when behaviour was changed in order to allow
 
91
more efficient init code, and also to bring it into line with the resolution
 
92
passed by the X3j13 committee.  Evaluation at compile time is controlled by
 
93
placing eval-when special forms in the code, or by the value of the variable
 
94
compiler::*eval-when-defaults* [default value :defaults].  If that variable
 
95
has value :defaults, then the following hold:
 
96
 
 
97
@w{Eval at Compile       Type of Top Level Form}@*
 
98
 
 
99
@table @asis
 
100
@item Partial:
 
101
defstructs, defvar, defparameter
 
102
@item Full:
 
103
defmacro, defconstant, defsetf, define-setf-method,
 
104
                        deftype, package ops, proclaim
 
105
@item None:
 
106
defun, others
 
107
@end table
 
108
 
 
109
 
 
110
By `partial' we mean (see the X3J13 Common Lisp document
 
111
(doc/compile-file-handling-of-top-level-forms) for more detail), that functions
 
112
will not be defined, values will not be set, but other miscellaneous compiler
 
113
properties will be set: eg properties to inline expand defstruct accessors and
 
114
testers, defstruct properties allowing subsequent defstructs to include this
 
115
one, any type hierarch information, special variable information will be set up.
 
116
 
 
117
Example:
 
118
@example
 
119
(defun foo () 3)
 
120
(defstruct jo a b)
 
121
@end example
 
122
 
 
123
As a side effect of compiling these two forms, foo would not have its function
 
124
cell changed.  Neither would jo-a, although it would gain a property which
 
125
allows it to expand inline to a structure access.  Thus if it had a previous
 
126
definition (as commonly happens from previously loading the file), this previous
 
127
definition would not be touched, and could well be inconsistent with the
 
128
compiler properties.  Unfortunately this is what the CL standard says to do,
 
129
and I am just trying to follow it.
 
130
 
 
131
If you prefer a more intuitive scheme, of evaling all forms in the file, so
 
132
that there are no inconsistencies, (previous behaviour of AKCL) you may set
 
133
compiler::*eval-when-defaults* to '(compile eval load).
 
134
 
 
135
The variable compiler::*FASD-DATA* [default t] controls whether an ascii output
 
136
is used for the data section of the object file.  The data section will be in
 
137
ascii if *fasd-data* is nil or if the system-p keyword is supplied to
 
138
compile-file and *fasd-data* is not eq to :system-p.
 
139
 
 
140
The old GCL variable *compile-time-too* has disappeared.
 
141
 
 
142
See OPTIMIZE on how to enable warnings of slow constructs.
 
143
 
 
144
 
 
145
 
 
146
@end defun
 
147
 
 
148
 
 
149
 
 
150
 
 
151
 
 
152
 
 
153
 
 
154
 
 
155
 
 
156
 
 
157
 
 
158
 
 
159
 
 
160
 
 
161
 
 
162
 
 
163
 
 
164
 
 
165
 
 
166
 
 
167
@defun PROCLAIM (decl-spec)
 
168
Package:LISP
 
169
 
 
170
Puts the declaration given by DECL-SPEC into effect globally.  See the doc of
 
171
DECLARE for possible DECL-SPECs.
 
172
 
 
173
 
 
174
@end defun
 
175
 
 
176
 
 
177
 
 
178
 
 
179
 
 
180
 
 
181
@defun PROVIDE (module-name)
 
182
Package:LISP
 
183
 
 
184
Adds the specified module to the list of modules maintained in *MODULES*.
 
185
 
 
186
 
 
187
@end defun
 
188
 
 
189
 
 
190
 
 
191
 
 
192
 
 
193
@defun COMPILED-FUNCTION-P (x)
 
194
Package:LISP
 
195
 
 
196
Returns T if X is a compiled function; NIL otherwise.
 
197
 
 
198
 
 
199
@end defun
 
200
 
 
201
 
 
202
 
 
203
 
 
204
@defvar *FEATURES* 
 
205
Package:LISP
 
206
List of symbols that name features of the current version of GCL.
 
207
These features are used to decide the read-time conditionalization facility
 
208
provided by '#+' and '#-' read macros.  When the GCL reader encounters
 
209
@example
 
210
        #+ feature-description form
 
211
@end example
 
212
it reads FORM in the usual manner if FEATURE-DESCRIPTION is true.  Otherwise,
 
213
the reader just skips FORM.
 
214
@example
 
215
        #- feature-description form
 
216
@end example
 
217
is equivalent to
 
218
@example
 
219
        #- (not feature-description) form
 
220
@end example
 
221
A feature-description may be a symbol, which is true only when it is an
 
222
element of *FEATURES*.  Or else, it must be one of the following:
 
223
@example
 
224
(and feature-desciption-1 ... feature-desciption-n)
 
225
(or  feature-desciption-1 ... feature-desciption-n)
 
226
(not feature-desciption)
 
227
@end example
 
228
The AND description is true only when all of its sub-descriptions are true.
 
229
The OR description is true only when at least one of its sub-descriptions is
 
230
true.  The NOT description is true only when its sub-description is false.
 
231
 
 
232
 
 
233
@end defvar
 
234
 
 
235