Sophie

Sophie

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

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.2.&#160;The compiler mimics human C programmer</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="ch27.html" title="Chapter&#160;4.&#160;The compiler"><link rel="next" href="ch27s03.html" title="4.3.&#160;Implementation of Compiled Closures"></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.2.&#160;The compiler mimics human C programmer</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch27.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="ch27s03.html">Next</a></td></tr></table><hr></div><div class="section" title="4.2.&#160;The compiler mimics human C programmer"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="Internals-The-compiler-mimics-human-C-programmer"></a>4.2.&#160;The compiler mimics human C programmer</h2></div></div></div><p>The format of the intermediate C code generated by the <span class="application">ECL</span> compiler is the
  same as the hand-coded C code of the <span class="application">ECL</span> source programs.  For example,
  supposing that the Lisp source file contains the
  following function definition:</p><pre class="programlisting">
   (defvar *delta* 2)
   (defun add1 (x) (+ *delta* x))
  </pre><p class="continues">The compiler generates the following intermediate C code.</p><pre class="screen">
   /*	function definition for ADD1                                  */
   static cl_object L1(cl_object V1)
   { VT2 VLEX2 CLSR2
   cl_object value0;
   value0=number_plus(symbol_value(VV[0]),V1); NVALUES=1;
   return value0;
   }
   /*      initialization of this module                                 */
   void init_CODE(cl_object flag)
   { VT1 CLSR1
   cl_object value0;
   if (!FIXNUMP(flag)){
   Cblock=flag;
   #ifndef ECL_DYNAMIC_VV
   flag-&gt;cblock.data = VV;
   #endif
   flag-&gt;cblock.self_destruct=0;
   flag-&gt;cblock.data_size = VM;
   flag-&gt;cblock.data_text = compiler_data_text;
   flag-&gt;cblock.data_text_size = compiler_data_text_size;
   return;}
   #ifdef ECL_DYNAMIC_VV
   VV = Cblock-&gt;cblock.data;
   #endif
   T0= MAKE_FIXNUM(2);
   si_Xmake_special(VV[0])
   if(SYM_VAL(T0)!=OBJNULL) cl_setq(VV[0],T0);
   cl_def_c_function(VV[1],(void*)L1,1);
   }
  </pre><p>The C function <code class="literal">L1</code> implements the Lisp function <code class="literal">add1</code>.
  This relation is established by <code class="literal">cl_def_c_function</code> in the
  initialization function <code class="literal">init_CODE</code>, which is invoked at load
  time.  There, the vector <code class="literal">VV</code> consists of Lisp objects;
  <code class="literal">VV[0]</code> and <code class="literal">VV[1]</code> in this example hold the Lisp symbols
  <code class="literal">*delta*</code> and <code class="literal">add1</code>. <code class="literal">VM</code> in the definition of
  <code class="literal">L1</code> is a C macro declared in the corresponding H-file.  The
  actual value of <code class="literal">VM</code> is the number of value stack locations used
  by this module, i.e., 2 in this example.  Thus the following macro
  definition is found in the H-file.</p><pre class="screen">
   #define VM 2
  </pre></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch27.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="ch27s03.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter&#160;4.&#160;The compiler&#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.3.&#160;Implementation of Compiled Closures</td></tr></table></div></body></html>