Mechanism by which Common Lisp compiles and loads code into image

627 Views Asked by At

Recently I've been reading on how modern OS load executable programs and allocate memories for them. Unfortunately, I only have a computer science book in Russian as a reference, so, please, correct me if I am wrong, but it appears that modern OS have different sections in an executable program for data and actual processor commands. Furthermore, it is not possible to give the control to data section, i.e. one cannot store the command there. It is also not possible to change the processor command in executable (text) section.

Hence, the question: how does modern compiled CL (SBCL, Clozure-CL) does it? As far as I can understand it creates compiled FASL files and then loads them. But visible FASL files are created when a file is compiled. What happens when the function form is evaluated? Secondly, how does CL load them (at the level of machine/OS commands) so that a correct memory is allocated for them? Also, the old code must be off-loaded somehow.

PS. Of course, this is not an issue for interpreted languages. And things get even more complicated for JIT-compilers.

1

There are 1 best solutions below

2
hr0m On

Maybe this clarifies things: Google Groups

Unlike C you are not compiling your programs, and then executing them. Instead you are working inside the lisp environment. When you have loaded your file into sbcl as above, you can just type

(hello)

And your code will be executed, and the code you run is compiled, and not interpreted. In SBCL you don't need to explicitly compile first, since all code you type or load into sbcl is compiled on the fly. In fact there is no interpreter in sbcl. In other lisp systems you may need to compile explicitly to get the code compiled though.

The fasl file is not executable by itself, it must be used together with sbcl.