Sophie

Sophie

distrib > Fedora > 14 > x86_64 > by-pkgid > e3d62627d1d1aab7ab1be2dd7f65a872 > files > 314

ecl-10.4.1-1.fc14.x86_64.rpm

<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>4.4.&#160;Use of Declarations to Improve Efficiency</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="ch27.html" title="Chapter&#160;4.&#160;The compiler"><link rel="prev" href="ch27s03.html" title="4.3.&#160;Implementation of Compiled Closures"><link rel="next" href="ch27s05.html" title="4.5.&#160;Inspecting generated C code"></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">4.4.&#160;Use of Declarations to Improve Efficiency</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch27s03.html">Prev</a>&#160;</td><th width="60%" align="center">Chapter&#160;4.&#160;The compiler</th><td width="20%" align="right">&#160;<a accesskey="n" href="ch27s05.html">Next</a></td></tr></table><hr></div><div class="section" title="4.4.&#160;Use of Declarations to Improve Efficiency"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="Internals-Use-of-Declarations-to-Improve-Efficiency"></a>4.4.&#160;Use of Declarations to Improve Efficiency</h2></div></div></div><p>Declarations, especially  type  and  function  declarations,
  increase the efficiency of the compiled code.  For example, for the
  following Lisp source file, with two Common-Lisp declarations added,</p><pre class="programlisting">
   (eval-when (compile)
   (proclaim '(function tak (fixnum fixnum fixnum) fixnum))

   (defun tak (x y z)
   (declare (fixnum x y z))
   (if (not (&lt; y x))
   z
   (tak (tak (1- x) y z)
   (tak (1- y) z x)
   (tak (1- z) x y))))
  </pre><p>The compiler generates the following C code:</p><pre class="screen">
   /*      local entry for function TAK                                  */
   static int LI1(register int V1,register int V2,register int V3)
   { VT3 VLEX3 CLSR3
   TTL:
   if (V2 &lt; V1) {
   goto L2;}
   return(V3);
   L2:
   { int V5;
   V5 = LI1((V1)-1,V2,V3);
   { int V6;
   V6 = LI1((V2)-1,V3,V1);
   V3 = LI1((V3)-1,V1,V2);
   V2 = V6;
   V1 = V5;}}
   goto TTL;
   ;;; Note: Tail-recursive call of TAK was replaced by iteration.
   }
  </pre></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch27s03.html">Prev</a>&#160;</td><td width="20%" align="center"><a accesskey="u" href="ch27.html">Up</a></td><td width="40%" align="right">&#160;<a accesskey="n" href="ch27s05.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">4.3.&#160;Implementation of Compiled Closures&#160;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&#160;4.5.&#160;Inspecting generated C code</td></tr></table></div></body></html>