<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>4.2. 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 4. The compiler"><link rel="prev" href="ch27.html" title="Chapter 4. The compiler"><link rel="next" href="ch27s03.html" title="4.3. 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. The compiler mimics human C programmer</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch27.html">Prev</a> </td><th width="60%" align="center">Chapter 4. The compiler</th><td width="20%" align="right"> <a accesskey="n" href="ch27s03.html">Next</a></td></tr></table><hr></div><div class="section" title="4.2. 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. 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->cblock.data = VV; #endif flag->cblock.self_destruct=0; flag->cblock.data_size = VM; flag->cblock.data_text = compiler_data_text; flag->cblock.data_text_size = compiler_data_text_size; return;} #ifdef ECL_DYNAMIC_VV VV = Cblock->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> </td><td width="20%" align="center"><a accesskey="u" href="ch27.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch27s03.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 4. The compiler </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 4.3. Implementation of Compiled Closures</td></tr></table></div></body></html>