Subject: Re: Implementing Lisp in C?
From: (Rob Warnock)
Date: Thu, 08 Apr 2004 05:55:43 -0500
Newsgroups: comp.lang.lisp
Message-ID: <>
Jeff Dalton  <> wrote:
| (robbie carlton) writes:
| > Most of it seems doable, but I'm wondering how to do
| > functions. Is it necessary to use assembly language to dynamically
| > create functions or can it be done in C?
| You shouldn't need any assembler.  C has pointers to functions,
| so you can have a heap-allocated struct that contains such a
| pointer (the struct will be your lisp function), then when
| calling the Lisp function, gab the pointer and call it.

However, note that on some machine architectures it is necessary
to explicitly flush the data cache and/or the instruction cache
(for at least the affected region) *after* putting the instructions
to be executed into the heap-allocated array but *before* calling
the function. Most operating systems provide a user-accessible call
to perform that function.


p.s. For a concrete example of this sort of thing, look in the
CMUCL C sources of the image loader (in "cmucl-18e/src/lisp/")
for references to the routines "sanctify_for_execution()" and

Rob Warnock			<>
627 26th Avenue			<URL:>
San Mateo, CA 94403		(650)572-2607