| 1 |
<?xml version="1.0" encoding="utf-8"?> |
| 2 |
<!DOCTYPE book [ |
| 3 |
<!ENTITY % eclent SYSTEM "ecl.ent"> |
| 4 |
%eclent; |
| 5 |
]> |
| 6 |
<book xmlns="http://docbook.org/ns/docbook" version="5.0" xml:lang="en"> |
| 7 |
<chapter label="7" xml:id="The-compiler"> |
| 8 |
<title>The Compiler</title> |
| 9 |
<para>The &ECL; compiler translates a Lisp program stored in a source file into a C |
| 10 |
program, invokes the C compiler to compile the C program, and then generates an |
| 11 |
object file, called <emphasis>fasl file</emphasis> (or <emphasis>o-file</emphasis> because of the actual |
| 12 |
filetype). The compiled program in a fasl file is loaded by the function |
| 13 |
<literal>load</literal>.</para> |
| 14 |
<para>Ordinarily, the object program generated by the &ECL; compiler scarcely does |
| 15 |
runtime error-checking for runtime efficiency. In addition, Lisp functions in |
| 16 |
the same source file are linked together and some system functions are |
| 17 |
open-coded in-line. To control runtime error checking, supply appropriate |
| 18 |
<literal>optimize</literal> declarations (see Section 7.1).</para> |
| 19 |
<para>The &ECL; compiler processes the <literal>eval-when</literal> special form exactly as |
| 20 |
specified in &Steele84; (see Section 5.3.3 of &Steele84;).</para> |
| 21 |
<para>The &ECL; compiler is invoked by the functions <literal>compile-file</literal>, |
| 22 |
<literal>compile</literal>, and <literal>disassemble</literal> described below. In addition, the |
| 23 |
&ECL; compiler may be invoked directly by the Shell commands <literal>ecl</literal>. |
| 24 |
This command requires the file name of the source file as its |
| 25 |
argument. <literal>ecl</literal> simply adds <literal>.lsp</literal> to the file name argument to |
| 26 |
obtain the full name of the source file.</para> |
| 27 |
<para><screen> |
| 28 |
$ ecl <replaceable>filename</replaceable> |
| 29 |
</screen></para> |
| 30 |
<para role="continues">has the same effect as the compiler invocation <literal>(compile-file |
| 31 |
<replaceable>filename</replaceable>)</literal> from within &ECL;, and</para> |
| 32 |
<para><screen> |
| 33 |
$ ecl -C <replaceable>filename</replaceable> |
| 34 |
</screen></para> |
| 35 |
<para>has the same effects as <literal>(compile-file <replaceable>filename</replaceable> |
| 36 |
:c-file t :h-file t :data-file t)</literal>.</para> |
| 37 |
<blockquote> |
| 38 |
<screen><indexterm role="fn"><primary>compile-file</primary></indexterm>— Function: <function>compile-file</function> <varname>pathname &key :output-file :verbose :print :c-file :h-file :data-file</varname></screen> |
| 39 |
<para><literal>compile-file</literal> compiles the Lisp program stored in the file specified by |
| 40 |
<replaceable>pathname</replaceable>, and generates a binary file. If <replaceable>:verbose</replaceable> is true, a |
| 41 |
message indicating what file is being compiled is printed. If <replaceable>:print</replaceable> |
| 42 |
is true, information about top-level forms in the file being compiled is |
| 43 |
printed. <literal>compile-file</literal> generates the following temporary files:</para> |
| 44 |
<informaltable> |
| 45 |
<tgroup cols="2"> |
| 46 |
<colspec colwidth="16*"></colspec> |
| 47 |
<colspec colwidth="43*"></colspec> |
| 48 |
<tbody> |
| 49 |
<row> |
| 50 |
<entry><emphasis role="bold">Temporary File</emphasis></entry> |
| 51 |
<entry><emphasis role="bold">Contents</emphasis></entry> |
| 52 |
</row> |
| 53 |
<row> |
| 54 |
<entry><replaceable>c-file</replaceable></entry> |
| 55 |
<entry>C version of the Lisp program</entry> |
| 56 |
</row> |
| 57 |
<row> |
| 58 |
<entry><replaceable>h-file</replaceable></entry> |
| 59 |
<entry>The include file referenced in the c-file</entry> |
| 60 |
</row> |
| 61 |
<row> |
| 62 |
<entry><replaceable>data-file</replaceable></entry> |
| 63 |
<entry>The Lisp data to be used at load time</entry> |
| 64 |
</row> |
| 65 |
</tbody> |
| 66 |
</tgroup> |
| 67 |
</informaltable> |
| 68 |
<para>If files of these names already exist, the old files will be deleted first. |
| 69 |
Usually, these intermediate files are automatically deleted after execution of |
| 70 |
<literal>compile-file</literal>.</para> |
| 71 |
<para>The input-file is determined in the usual manner (see Section 2.9), except |
| 72 |
that, if the filetype is not specified, then the default filetype <literal>.lsp</literal> |
| 73 |
will be used. The keyword parameter <literal>:output-file</literal> defines the default |
| 74 |
directory and the default name to be applied to the output files (i.e., the |
| 75 |
fasl file and the temporary files). <replaceable>:output-file</replaceable> itself defaults to |
| 76 |
<replaceable>input-pathname</replaceable>. That is, if <replaceable>:output-file</replaceable> is not supplied, then the |
| 77 |
directory and the name of the input file will be used as the default directory |
| 78 |
and the default name for the output files. The file types of the output files |
| 79 |
are fixed as follows.</para> |
| 80 |
<informaltable> |
| 81 |
<tgroup cols="2"> |
| 82 |
<colspec colwidth="46*"></colspec> |
| 83 |
<colspec colwidth="43*"></colspec> |
| 84 |
<tbody> |
| 85 |
<row> |
| 86 |
<entry><emphasis role="bold">Output File</emphasis></entry> |
| 87 |
<entry><emphasis role="bold">Filetype</emphasis></entry> |
| 88 |
</row> |
| 89 |
<row> |
| 90 |
<entry>fasl file</entry> |
| 91 |
<entry><literal>.o</literal></entry> |
| 92 |
</row> |
| 93 |
<row> |
| 94 |
<entry>c-file</entry> |
| 95 |
<entry><literal>.c</literal></entry> |
| 96 |
</row> |
| 97 |
<row> |
| 98 |
<entry>h-file</entry> |
| 99 |
<entry><literal>.h</literal></entry> |
| 100 |
</row> |
| 101 |
<row> |
| 102 |
<entry>data-file</entry> |
| 103 |
<entry><literal>.data</literal></entry> |
| 104 |
</row> |
| 105 |
</tbody> |
| 106 |
</tgroup> |
| 107 |
</informaltable> |
| 108 |
<para>Each output file can be specified by the corresponding keyword parameter. |
| 109 |
If the value of the keyword parameter is (), then the output file will be |
| 110 |
deleted after execution of <literal>compile-file</literal>. If the value of the |
| 111 |
keyword parameter is <replaceable>T</replaceable>, then the output file will be left in the |
| 112 |
default directory under the default name. Otherwise, the output file will |
| 113 |
be left in the directory under the name specified by the keyword parameter. |
| 114 |
The default value of <replaceable>:output-file</replaceable> is <replaceable>T</replaceable>, and the default values |
| 115 |
of <replaceable>:c-file</replaceable>, <replaceable>::h-file</replaceable>, and <replaceable>:data-file</replaceable> are all ().</para> |
| 116 |
<variablelist> |
| 117 |
<varlistentry> |
| 118 |
<term><literal>(compile-file 'foo)</literal></term> |
| 119 |
<listitem> |
| 120 |
<para>The source file is <literal>FOO.lsp</literal> and the fasl file is <literal>FOO.o</literal> |
| 121 |
both in the current directory.</para> |
| 122 |
</listitem> |
| 123 |
</varlistentry> |
| 124 |
<varlistentry> |
| 125 |
<term><literal>(compile-file 'foo.lish)</literal></term> |
| 126 |
<listitem> |
| 127 |
<para>The source file is <literal>FOO.LISH</literal> and the fasl file is <literal>FOO.o</literal>'.</para> |
| 128 |
</listitem> |
| 129 |
</varlistentry> |
| 130 |
<varlistentry> |
| 131 |
<term><literal>(compile-file "/usr/mas/foo" :output-file "/usr/tai/baa")</literal></term> |
| 132 |
<listitem> |
| 133 |
<para>The source file is <literal>foo.lsp</literal> in the directory <filename>/usr/mas</filename>, and the |
| 134 |
fasl file is <literal>baa.o</literal> in the directory <filename>/usr/tai</filename>.</para> |
| 135 |
</listitem> |
| 136 |
</varlistentry> |
| 137 |
</variablelist> |
| 138 |
</blockquote> |
| 139 |
<blockquote> |
| 140 |
<screen><indexterm role="fn"><primary>compile</primary></indexterm>— Function: <function>compile</function> <varname>name code &optional definition</varname></screen> |
| 141 |
<para>If <replaceable>definition</replaceable> is not supplied, <replaceable>name</replaceable> should be the name of a |
| 142 |
not-yet-compiled function. In this case, compile compiles the function, |
| 143 |
replaces the previous definition of <replaceable>name</replaceable> with the compiled |
| 144 |
function,<emphasis>and</emphasis> returns <replaceable>name</replaceable>. If <replaceable>definition</replaceable> is supplied, it |
| 145 |
should be a lambda-expression to be compiled and <replaceable>name</replaceable> should be a symbol. |
| 146 |
If <replaceable>name</replaceable> is a non-() symbol, then compile installs the compiled |
| 147 |
function as the function definition of <replaceable>name</replaceable> and returns <replaceable>name</replaceable>. If |
| 148 |
<replaceable>name</replaceable> is (), then compile simply returns the compiled function.</para> |
| 149 |
<para>The &ECL; compiler is essentially a file compiler, and forms to be |
| 150 |
compiled are supposed to be stored in a file. Thus compile actually |
| 151 |
creates a source file which contains the form designated by the |
| 152 |
arguments. Then compile calls <literal>compile-file</literal> to get a fasl file, |
| 153 |
which is then loaded into &ECL;. The source file and the fasl file |
| 154 |
are given the names <filename>gazonk.lsp</filename> and <filename>gazonk.fasl</filename>, |
| 155 |
respectively. These files are not deleted automatically after the |
| 156 |
execution of <literal>compile</literal>.</para> |
| 157 |
</blockquote> |
| 158 |
<blockquote> |
| 159 |
<screen><indexterm role="fn"><primary>disassemble</primary></indexterm>— Function: <function>disassemble</function> <varname>&optional thing &key :h-file :data-file</varname></screen> |
| 160 |
<para>This function does not actually disassemble. It always calls the &ECL; |
| 161 |
compiler and prints the contents of the c-file, i.e., the C-language code, |
| 162 |
generated by the &ECL; compiler. If <replaceable>thing</replaceable> is not supplied, or if it is |
| 163 |
(), then the previously compiled form by disassemble will be compiled |
| 164 |
again. If <replaceable>thing</replaceable> is a symbol other than (), then it must be the name |
| 165 |
of a not-yet-compiled function, whose definition is to be compiled. In this |
| 166 |
case, it is an error if the name is associated with a special form or a macro. |
| 167 |
If <replaceable>thing</replaceable> is a lambda-expression <literal>(lambda <replaceable>lambda-list . |
| 168 |
body</replaceable>)</literal>, then <literal>disassemble</literal> first creates a function definition |
| 169 |
<literal>(defun gazonk <replaceable>lambda-list . body</replaceable>)</literal> and this definition is |
| 170 |
compiled. (The function name <literal>gazonk</literal> has no special meanings. Indeed, |
| 171 |
the displayed code is essentially independent of the function name.) |
| 172 |
Otherwise, <replaceable>thing</replaceable> itself will be compiled as a top-level form. In any |
| 173 |
case, <literal>disassemble</literal> does not install the compiled function. |
| 174 |
<literal>disassemble</literal> returns no value.</para> |
| 175 |
<para>No intermediate h-file is created if the keyword parameter <literal>:h-file</literal> is |
| 176 |
() or if <replaceable>:h-file</replaceable> is not supplied. Otherwise, an intermediate h-file |
| 177 |
is created under the name specified by <replaceable>:h-file</replaceable>. Similarly, the |
| 178 |
intermediate data-file is specified by the keyword parameter <replaceable>:data-file</replaceable>.</para> |
| 179 |
</blockquote> |
| 180 |
</chapter> |
| 181 |
<!-- Keep this comment at the end of the file |
| 182 |
Local variables: |
| 183 |
sgml-parent-document: "ecl.xml" |
| 184 |
sgml-indent-step: 1 |
| 185 |
nxml-child-indent: 1 |
| 186 |
nxml-outline-child-indent: 1 |
| 187 |
fill-column: 79 |
| 188 |
End: |
| 189 |
--></book> |