However, there are some general statements that can be made about the translation:
clObject is defined in
eclipse.h, and defines the type of all Lisp data.
#include <eclipse.h> appears at the top of the
generated C file, followed by extern references to Lisp
library functions and data.
(defun foo-bar ...) =>
clObject usrFooBar(...)
Each Lisp function compiled to C uses varargs, and begins with a compound C statement block that parses the arguments (including optional, keyword and supplied-p arguments).
In addition to the C functions corresponding the various Lisp functions, Eclipse defines an initialization function for each Lisp source file translated to C. This initialization function takes no arguments, and returns no values. When called in a C program, it provides the same behavior that the Lisp load function would provide when loading the original Lisp file. This includes all explicit load-time behavior, such as assigning function properties, etc.
The name of the initialization function can be controled by arguments to compile-file, but the default is based on the name of the file being compiled to C. The initialization function appears at the end of the generated C file.
The Eclipse compile-file function may coalesce similar literals that appear in the same source file, taking care to compute the proper ordering between components of (possibly circular) compound objects.
Any initialization of literals appears first within the initialization function, followed by code generated from explicit load-time user code.
Again, the Eclipse library naming convention is used to define the names of C identifiers corresponding to Lisp variables, named blocks, go tags, etc. In general, the C identifiers for variables are the same as the name in Lisp, in lower case, with dashes replaced by underscores.
C macros are defined in eclipse.h to implement Lisp
constructions such as catch, block,
unwind-protect, multiple value handling, etc.
Otherwise, the arguments to function calls in C appear as they do
in the original Lisp source code, terminated by the special `symbol',
clEOA, to mark the end-of-arguments.
Lisp functions known to be compiled to C (such as those defined by ANSI) are called directly. Other functions are called by funcalling the closure stored in an fdefinition.
(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.
(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); }