Are there native code compilers for Lisp? To which extent can it even be compiled, with all it's dynamic nature, garbage collection, macros and what else?
Join Stack Overflow to learn, share knowledge, and build your career.
locked by Flexo♦ Sep 27 '13 at 15:43This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. More info: help center. |
|||||||||||||||||
|
|||||||||||||||||
|
Many Lisp compilers compile to 'native' code. 'Native' means here 'machine code' (x86 in 32bit or 64bit mode, PowerPC, SPARC, ...). Other questions:
A simple way to see the compiled code for functions is to use the Common Lisp function DISASSEMBLE. Example in Clozure CL on an x86-64 Mac
...
The output of DISASSEMBLE obviously depends on the processor architecture, the OS, the used Lisp compiler and the current optimization settings. |
|||||||||
|
|
Don't forget Chicken Scheme. |
|||||
|
|
There a many Lisp compilers that compile to native code. CMUCL, SBCL, ClozureCL are known among the open-source Lisp compilers. Garbage collection is not an obstacle to compilation to native code. Also, in some cases Lisp can use stack allocation that does not need GC and may greatly improve performance (using dynamic-extent declaration; at least SBCL supports this). Macros (and any code that is run at read-time (read macros and read-eval), compile-time (macros, compiler macros, code in eval-when)) require incremental compilation (first macro-function has to be compiled, and then code that uses macro can be compiled). This somewhat complicates compilation, but it is not too much a problem. Also, macros and compiler macros even help the compilation process because they allow programmer to write code generators and code optimizers, essentially customizing the compiler. So the compiler is more complicated than some simpler languages (like C), but complexity is manageable (see Design of CMU Common Lisp). Dynamic nature of Common Lisp is controllable and designed to be effeciently compilable. In contrast to some other dynamic languages (e.g., Python), dynamism is restricted (e.g., you can not take the current lexical environment at run-time) which give compilers some freedom to optimize. |
|||||||||||||
|
|
Yes. See http://en.wikipedia.org/wiki/Common_Lisp . It mentions that Steel Bank Common Lisp (a fairly popular implementation) compiles everything to native by default. The fact that garbage collections and such are used is not an obstacle to native code. That just means some kind of runtime is needed. But so what? Even C has a runtime. |
|||
|
|
|
There are huge numbers of Lisp compilers to native code, see http://www.thefreecountry.com/compilers/commonlisp.shtml and e.g. the CMU Common Lisp Compiler. |
|||
|
|
|
You bet. Chez Scheme (a commercial compiler) is one of the better ones. Gambit and Larceny are research compilers that also generate native code. |
|||||
|