Jeff Dalton <jeff@todday.inf.ed.ac.uk> wrote:
+---------------
| robbiefcarlton@hotmail.com (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.
-Rob
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
"os_flush_icache()"...
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607