[Ecls-list] Embedding ECL interpreter in a C++ application

worm worm at arrakis.es
Wed Mar 3 15:11:04 UTC 2004


Remitente: Michael O'Connor <moconnor59 at yahoo.com>
Fecha: Miércoles, Marzo 3, 2004 6:30 pm

> I was directed to an application called xchatlisp
> which does a similar thing to what I'm trying to do.
> From that I can see that I need to call cl_boot() to
> initialise the ECL interpreter, and cl_load() to get
> it to read / compile / run a lisp file.
>
> However I need to be able to split the read / compile
> stages from the run stage (because the app is required
> to run the same lisp program repeatedly on different
> data sets, and I want to avoid the overhead of reading
> / compiling the file on each run). I'm unable to
> figure out what function calls are needed to perform
> these tasks separately, any pointers would be much
> appreciated.

Just use any Common Lisp function you want. They are all
available to the C programmer. For instance, the following
is a dummy top level that is used to bootstrap ECL

static cl_object si_simple_toplevel ()
{
	cl_object sentence;
	int i;

	/* Simple minded top level loop */
	printf(";*** Lisp core booted ****\nECLS (Embeddable Common Lisp)  %d
pages\n", MAXPAGE);
	fflush(stdout);
	for (i = 1; i<fix(si_argc()); i++) {
	  cl_object arg = si_argv(MAKE_FIXNUM(i));
	  cl_load(1, arg);
	}
	while (1) {
	  printf("\n> ");
	  sentence = cl_read(3, Cnil, Cnil, OBJNULL);
	  if (sentence == OBJNULL)
	     return0();
	  prin1(si_safe_eval(1, sentence), Cnil);
	}
}

As you see, there exists a C function cl_read() which implements
the functionality of the READ function of common lisp. There
exists also a function si_safe_eval() which implements EVAL
and captures most errors. These two functions are exported to
the lisp world, and take a variable number of arguments. Then the
function prin1() is a simplified version of cl_prin1() (which also
exists) and which implements the functionality of PRIN1... And so
on and so forth.

For more details about how to construct lisp forms other than using
cl_read(), have a look at the developers guide.

Juanjo
 





More information about the ecl-devel mailing list