Next: , Previous: The compiler translates to C, Up: The compiler


5.2 The compiler mimics human C programmer

The format of the intermediate C code generated by the ECL compiler is the same as the hand-coded C code of the ECL source programs. For example, supposing that the Lisp source file contains the following function definition:

     (defvar *delta* 2)
     (defun add1 (x) (+ *delta* x))

The compiler generates the following intermediate C code.

     /*	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);
     }

The C function L1 implements the Lisp function add1. This relation is established by cl_def_c_function in the initialization function init_CODE, which is invoked at load time. There, the vector VV consists of Lisp objects; VV[0] and VV[1] in this example hold the Lisp symbols *delta* and add1. VM in the definition of L1 is a C macro declared in the corresponding H-file. The actual value of VM 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.

     #define VM 2