[contents]

SAMPLE GENERATED C CODE

The details of how Lisp code appears when translated to C depends on the code being translated. It is not simply a matter of translating one Lisp form pattern directly into another C statement pattern.

However, there are some general statements that can be made about the translation:

The above outline may be modified by information that the compile-file can determine while processing the file, and between Eclipse releases. In particular, we expect the details of how this outline is followed to change as we provide more efficient or more readable implementations in future releases.
Here is a sample Lisp source file.
(in-package :user)			;The initializer for the
					;generated code BINDS *package*

;;; Here's some top-level code that gets executed at load time in
;;; Lisp, or at initialization time in the generated C code.
(print 'hello)				;In the generated code,
(write-line "This is a string")		;literals are initialized  
(print 42)				;before user code.

(let ((x (foo 42))			;Call to unknown function.
      (y (bar "This is a string")))	;Literals are coalesced.
  (when (baz x)
    (print y)))
      

;;; A silly function with fairly complicated argument parsing.
(defun foo-bar (x &optional (y 1) &rest keys
		  &key (a 'base-char) &allow-other-keys)
  (multiple-value-call 'some-function
    (block foo
      (if (minusp y)
	  (setq y x)
	  (return-from foo (values y keys))))
    (baz y)
    42
    #'(lambda (arg)			;A closure over a.
	(make-array arg :element-type a)))) ;Keyword arg.


Here is the C code produced with:
   (compile-file "sample"
                 :output-file "sample.c"
                 :external-format :ascii)
The result is shown with exactly the same indentation produced by Eclipse. No additional hand whitespace formatting has been performed for presentation here.

Please note that details such as function argument parsing, the creation or elimination of temporary variables, and the C compile-time vs. C initialization-time (i.e. startup) initialization of Lisp literals may vary in future versions.

/* Generated by Eclipse Common Lisp 1.0 for howard on circe.
   Friday the twelfth of September, 1997, 4:45:46 pm CDT. */
#include <eclipse.h>

clObject clCar(clProto), clCharpSimpleBaseString(clProto),
  clExtraArgs(clProto), clIntern(clProto), clKeyArg(clProto),
  clMakeArray(clProto), clMakeKeyword(clProto), clMinusp(clProto),
  clMissingArgs(clProto), clPkg(clProto), clPrint(clProto),
  clValues(clProto), clWriteLine(clProto);

extern clObject clstarPACKAGEstar, clBASE_CHAR;

static clObject I_1, I_42, keyA, keyELEMENT_TYPE, keyUSER, PKG_USER,
  STR_A__7, STR_BAR__4, STR_BAZ__5, STR_ELEMENT_TYPE__9,
  STR_FOO_BAR__6, STR_FOO__3, STR_HELLO__1, STR_SOME_FUNCTION__8,
  STR_This_is_a_string__2, STR_USER__0, usrBAR, usrBAZ, usrFOO,
  usrFOO_BAR, usrHELLO, usrSOME_FUNCTION;

clDeclareEnv(usrFooBar_Lambda);
static clObject usrFooBar_Lambda(clVaAlist) clVaDcl
{ clUseEnv(usrFooBar_Lambda);
  { clObject CL_ap, arg;
    { clBeginParse(_ap);
      clSetq(arg,
             (_clPresentp(clSetq(CL_ap, clGetObjectArg(_ap))) ? CL_ap :
              clMissingArgs(clNIL)));
      if (clTrue(clSetq(CL_ap, clVlist(_ap))))
        { clObject CL_0; clSetq(CL_0, CL_ap); clExtraArgs(CL_0); }
      clEndParse(_ap); }
    { clObject CL_2;
      clSetq(CL_2, clEnv(0, *a));
      return(clMakeArray(arg, keyELEMENT_TYPE, CL_2, clEOA)); } } }

clObject usrFooBar(clVaAlist) clVaDcl
{ clObject CL_ap, x, y, keys, *a = clMakeBinding();
  { clBeginParse(_ap);
    clSetq(x,
           (_clPresentp(clSetq(CL_ap, clGetObjectArg(_ap))) ? CL_ap :
            clMissingArgs(clNIL)));
    clSetq(y,
           (_clPresentp(clSetq(CL_ap, clGetObjectArg(_ap))) ? CL_ap :
            I_1));
    clSetq(keys, clVlist(_ap));
    if (clTrue(clSetq(CL_ap, clKeyArg(keyA, keys, clEOA))))
      { clObject CL_0;
        clSetq(CL_0, CL_ap);
        clSetq(*a, clCar(CL_0, clEOA)); }
    else
      clSetq(*a, clBASE_CHAR);
    clEndParse(_ap); }
  { clMultipleValueCall(cl_MVC);
    clSetq(cl_MVC, usrSOME_FUNCTION);
    { clObject CL_test;
      { clObject CL_0;
        clSetq(CL_0, y);
        clSetq(CL_test, clMinusp(CL_0, clEOA)); }
      if (clTrue(CL_test))
        clValues1(clSetq(y, x));
      else
        { { clObject CL_0;
            clSetq(CL_0, y);
            clValues(CL_0, keys, clEOA); }
          clLocalReturn(FOO); } }
    clBlockEnd(FOO);
    clAccumulateValues(cl_MVC);
    { clObject CL_0;
      clSetq(CL_0, y);
      clFuncallFunction(clFdefinition(usrBAZ, clEOA), CL_0, clEOA); }
    clAccumulateValues(cl_MVC);
    clValues1(I_42);
    clAccumulateValues(cl_MVC);
    clValues1(clMakeClosure(1,
                            usrFooBar_Lambda,
                            &clEnvHook(usrFooBar_Lambda),
                            &*a));
    clAccumulateValues(cl_MVC);
    return(clMultipleValueFuncall(cl_MVC)); } }

void usrSample() 
{ clDbind(clstarPACKAGEstar);
  clDbind(clstarREADTABLEstar);
  clDbind(clstarLOAD_TRUENAMEstar);
  clDbind(clstarLOAD_PATHNAMEstar);
  clSetq(STR_USER__0,
         clCharpSimpleBaseString("USER"));
  clSetq(keyUSER, clMakeKeyword(STR_USER__0, clEOA));
  clSetq(STR_HELLO__1,
         clCharpSimpleBaseString("HELLO"));
  clSetq(PKG_USER, clPkg(STR_USER__0, clEOA));
  clSetq(usrHELLO, clIntern(STR_HELLO__1, PKG_USER, clEOA));
  clSetq(STR_This_is_a_string__2,
         clCharpSimpleBaseString("This is a string"));
  clSetq(I_42, clIntFixnum(42));
  clSetq(STR_FOO__3,
         clCharpSimpleBaseString("FOO"));
  clSetq(usrFOO, clIntern(STR_FOO__3, PKG_USER, clEOA));
  clSetq(STR_BAR__4,
         clCharpSimpleBaseString("BAR"));
  clSetq(usrBAR, clIntern(STR_BAR__4, PKG_USER, clEOA));
  clSetq(STR_BAZ__5,
         clCharpSimpleBaseString("BAZ"));
  clSetq(usrBAZ, clIntern(STR_BAZ__5, PKG_USER, clEOA));
  clSetq(STR_FOO_BAR__6,
         clCharpSimpleBaseString("FOO-BAR"));
  clSetq(usrFOO_BAR, clIntern(STR_FOO_BAR__6, PKG_USER, clEOA));
  clSetq(I_1, clIntFixnum(1));
  clSetq(STR_A__7,
         clCharpSimpleBaseString("A"));
  clSetq(keyA, clMakeKeyword(STR_A__7, clEOA));
  clSetq(STR_SOME_FUNCTION__8,
         clCharpSimpleBaseString("SOME-FUNCTION"));
  clSetq(usrSOME_FUNCTION,
         clIntern(STR_SOME_FUNCTION__8, PKG_USER, clEOA));
  clSetq(STR_ELEMENT_TYPE__9,
         clCharpSimpleBaseString("ELEMENT-TYPE"));
  clSetq(keyELEMENT_TYPE, clMakeKeyword(STR_ELEMENT_TYPE__9, clEOA));

  clSetSymbolValueValue(clstarPACKAGEstar, clPkg(keyUSER, clEOA));
  clPrint(usrHELLO, clEOA);
  clWriteLine(STR_This_is_a_string__2, clEOA);
  clPrint(I_42, clEOA);
  { clObject x, y;
    clSetq(x,
           clFuncallFunction(clFdefinition(usrFOO, clEOA),
                             I_42,
                             clEOA));
    clSetq(y,
           clFuncallFunction(clFdefinition(usrBAR, clEOA),
                             STR_This_is_a_string__2,
                             clEOA));
    if (clTrue(clFuncallFunction(clFdefinition(usrBAZ, clEOA),
                                 x,
                                 clEOA)))
      clPrint(y, clEOA); }
  clSetSymbolFunctionValue(usrFOO_BAR,
                           clMakeClosure(0, usrFooBar, clNULL_HOOK));
  usrFOO_BAR;
  clUnwind(4); }

[contents]