

How Chicken Scheme compiles to C - gnosis
http://wiki.call-cc.org/chicken-compilation-process

======
spacemanaki
If you're interested by this and haven't seen it already, Marc Feeley's talk
about compiling Scheme to C is really awesome, and has been posted here at
least once. I think it was targeted at people new to Scheme compilers (he
diverges to explain why first class continuations are useful) so it's also
pretty accessible.

[http://www.iro.umontreal.ca/~boucherd/mslug/meetings/2004102...](http://www.iro.umontreal.ca/~boucherd/mslug/meetings/20041020/minutes-
en.html)

------
csl
Nice writeup on their use of the Cheney Trampoline. As is always the case in
such discussions, I'll mention these three fine books for Scheme implementers:

* Lisp in small pieces, by Christian Queinnec

* Compiling with continuations, by Andrew Appel

* Anatomy of Lisp, by John Allen

~~~
jules
If you want to go further, Matt Mights papers on static analysis are
excellent: <http://matt.might.net/#papers>

Older versions of techniques like those described in these papers were the
basis of the Stalin scheme compiler by Sisskind. From Sisskind's research
statement:

Stalin is an optimizing compiler for Scheme that performs whole-program static
analysis and uses the results of that analysis to generate extremely ecient
code. Stalin utilizes a large collection of static-analysis techniques. It
performs a novel form of polyvariant flow analysis that uses iterated
monovariant flow analysis to perform flow-directed splitting: cloning of
specialized copies of procedures and per-call-site assignment of targets to
such clones. It uses the results of flow analysis to perform life-time
analysis, escape analysis, points-to analysis, and must-alias analysis. These
analyses support a novel form of lightweight closure conversion that
eliminates most closure slots, using techniques such as variable globalization
and localization, compresses the static backchain, and usually eliminates most
closures from programs. It also uses the above analyses to support flow-
directed region-based storage management, where run-time garbage collection is
replaced with static allocation and deallocation on a per-abstract-value and
per-program-point basis. It also performs flow-directed lightweight CPS
conversion, using extensions of the techniques pioneered with Screamer, to
support extremely ecient rst-class continuations. Finally, it supports ow-
directed inlining and low-level representation selection to choose the
implementation (or nonimplementation) of tags, tag checking, and tag
dispatching on a per-abstract-value and per-program-point basis. This
eliminates most run-time tags, tag checking, tagging, tag stripping, tag
dispatching, boxing, and unboxing from programs. These analyses and
optimizations allow Stalin to generate extremely efficient code that
outperforms all other Scheme compilers by factors ranging between two and one
hundred, particularly for numerically intensive code. Stalin often generates
code that outperforms handwritten c and Fortran code.

\-- ftp://ftp.ecn.purdue.edu/qobi/research-statement.pdf

Although flow analysis has been extensively published about, I couldn't find
much information using the results of it for the stuff he describes. Does
anybody have pointers?

~~~
csl
Most of this sounds like a _very_ big bag of hefty tricks. Closure conversion,
lambda lifting, escape analysis and allocating on the stack, partial
evaluation, etc.

Maybe there are more clues over at
<https://engineering.purdue.edu/~qobi/papers.html>

------
machrider
Fascinating approach. I would be interested to see benchmarks on the n-Queens
solution in translated C vs hand-written C.

------
aaronblohowiak
This is great! However, I'd love to see this for Stalin.

