<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>Chapter 4. The compiler</title><link rel="stylesheet" href="ecl.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.75.2"><link rel="home" href="index.html" title="The ECL manual"><link rel="up" href="pt03.html" title="Part III. Internals"><link rel="prev" href="ch26s04.html" title="3.4. The interpreter stack"><link rel="next" href="ch27s02.html" title="4.2. The compiler mimics human C programmer"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 4. The compiler</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch26s04.html">Prev</a> </td><th width="60%" align="center">Part III. Internals</th><td width="20%" align="right"> <a accesskey="n" href="ch27s02.html">Next</a></td></tr></table><hr></div><div class="chapter" title="Chapter 4. The compiler"><div class="titlepage"><div><div><h2 class="title"><a name="Internals-the-compiler"></a>Chapter 4. The compiler</h2></div></div></div><div class="toc"><dl><dt><span class="section"><a href="ch27.html#Internals-The-compiler-translates-to-C">4.1. The compiler translates to C</a></span></dt><dt><span class="section"><a href="ch27s02.html">4.2. The compiler mimics human C programmer</a></span></dt><dt><span class="section"><a href="ch27s03.html">4.3. Implementation of Compiled Closures</a></span></dt><dt><span class="section"><a href="ch27s04.html">4.4. Use of Declarations to Improve Efficiency</a></span></dt><dt><span class="section"><a href="ch27s05.html">4.5. Inspecting generated C code</a></span></dt></dl></div><div class="section" title="4.1. The compiler translates to C"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="Internals-The-compiler-translates-to-C"></a>4.1. The compiler translates to C</h2></div></div></div><p>The <span class="application">ECL</span> compiler is essentially a translator from Common-Lisp to C. Given a Lisp source file, the compiler first generates three intermediate files:</p><div class="itemizedlist"><ul class="itemizedlist" type="bullet"><li class="listitem" style="list-style-type: disc"><p>a C-file which consists of the C version of the Lisp program</p></li><li class="listitem" style="list-style-type: disc"><p>an H-file which consists of declarations referenced in the C-file</p></li><li class="listitem" style="list-style-type: disc"><p>a Data-file which consists of Lisp data to be used at load time</p></li></ul></div><p>The <span class="application">ECL</span> compiler then invokes the C compiler to compile the C-file into an object file. Finally, the contents of the Data-file is appended to the object file to make a <span class="emphasis"><em>Fasl-file</em></span>. The generated Fasl-file can be loaded into the <span class="application">ECL</span> system by the Common-Lisp function <code class="literal">load</code>. By default, the three intermediate files are deleted after the compilation, but, if asked, the compiler leaves them.</p><p>The merits of the use of C as the intermediate language are:</p><div class="itemizedlist"><ul class="itemizedlist" type="-"><li class="listitem" style="list-style-type: -"><p>The <span class="application">ECL</span> compiler is highly portable.</p></li><li class="listitem" style="list-style-type: -"><p>Cross compilation is possible, because the contents of the intermediate files are common to all versions of <span class="application">ECL</span>. For example, one can compile his or her Lisp program by the <span class="application">ECL</span> compiler on a Sun, bring the intermediate files to DOS, compile the C-file with the gcc compiler under DOS, and then append the Data-file to the object file. This procedure generates the Fasl-file for the <span class="application">ECL</span> system on DOS. This kind of cross compilation makes it easier to port <span class="application">ECL</span>.</p></li><li class="listitem" style="list-style-type: -"><p>Hardware-dependent optimizations such as register allocations are done by the C compiler.</p></li></ul></div><p>The demerits are:</p><div class="itemizedlist"><ul class="itemizedlist" type="-"><li class="listitem" style="list-style-type: -"><p>At those sites where no C compiler is available, the users cannot compile their Lisp programs.</p></li><li class="listitem" style="list-style-type: -"><p>The compilation time is long. 70% to 80% of the compilation time is used by the C compiler. The <span class="application">ECL</span> compiler is therefore slower than compiler generating machine code directly.</p></li></ul></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch26s04.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="pt03.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch27s02.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">3.4. The interpreter stack </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 4.2. The compiler mimics human C programmer</td></tr></table></div></body></html>