|
@@ -105,8 +105,72 @@ University.
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
\chapter*{Preface}
|
|
|
|
|
|
-Talk about nano-pass \citep{Sarkar:2004fk,Keep:2012aa} and incremental
|
|
|
-compilers \citep{Ghuloum:2006bh}.
|
|
|
+The tradition of compiler writing at Indiana University goes back to
|
|
|
+programming language research and courses taught by Daniel Friedman in
|
|
|
+the 1970's. Dan had conducted research on lazy evaluation in the
|
|
|
+context of Lisp~\citep{McCarthy:1960dz} and then studied continuations
|
|
|
+and macros in the context of the Scheme~\citep{Sussman:1975ab}, a
|
|
|
+dialect of Lisp. One of students of those courses, Kent Dybvig, went
|
|
|
+on to build Chez Scheme~\citep{Dybvig:2006aa}, a production-quality
|
|
|
+and efficient compiler for Scheme. After completing his Ph.D. at the
|
|
|
+University of North Carolina, Kent returned to teach at Indiana
|
|
|
+University. Throughout the 1990's and early 2000's, Kent continued
|
|
|
+development of Chez Scheme and rotated with Dan in teaching the
|
|
|
+compiler course.
|
|
|
+
|
|
|
+Thanks to this collaboration between Dan and Kent, the compiler course
|
|
|
+evolved to incorporate novel pedagogical ideas while also including
|
|
|
+elements of effective real-world compilers. One of the pedagogical
|
|
|
+ideas was to split the compiler into many small passes over the input
|
|
|
+program and subsequent intermediate representations, so that the code
|
|
|
+for each pass is easy to understood in isolation. (In contrast, most
|
|
|
+compilers of the time were organized into only a few large passes for
|
|
|
+reasons of compile-time efficiency.) Kent and his students, Dipanwita
|
|
|
+Sarkar and Andrew Keep, developed infrastructure to support this
|
|
|
+approach and evolved the course, first to use micro-sized passes and
|
|
|
+then into even smaller
|
|
|
+nano-passes~\citep{Sarkar:2004fk,Keep:2012aa}. I took this compiler
|
|
|
+course in the early 2000's, as part of my Ph.D. studies at Indiana
|
|
|
+University.
|
|
|
+
|
|
|
+One of my classmates, Abdulaziz Ghuloum, observed that the
|
|
|
+front-to-back organization of the course made it difficult for
|
|
|
+students to understand the rationale for the compiler
|
|
|
+design. Abdulaziz proposed an incremental approach in which the
|
|
|
+students build the compiler in stages, starting by implementing a
|
|
|
+complete compiler for a very small subset of the input language, then
|
|
|
+gradually adding features to the input language and adding or
|
|
|
+modifying passes to handle those features~\citep{Ghuloum:2006bh}.
|
|
|
+
|
|
|
+After graduating from Indiana University in 2005, I went on to teach
|
|
|
+at the University of Colorado. I adapted the nano-pass and incremental
|
|
|
+approaches to compiling a subset of the Python
|
|
|
+language~\citep{Siek:2012ab}. Python and Scheme are quite different
|
|
|
+on the surface but there is a large overlap in the compiler techniques
|
|
|
+required for the two languages. Thus, I was able to teach much of the
|
|
|
+same content from the Indiana compiler course. I very much enjoyed
|
|
|
+teaching the course organized according to the nano-pass and
|
|
|
+incremental approaches, and even better, many of the students learned
|
|
|
+a lot and got excited about compilers. (No, I didn't do a
|
|
|
+quantitative study to support this claim.)
|
|
|
+
|
|
|
+It is now 2016 and I too have returned to teach at Indiana University.
|
|
|
+In my absence the compiler course had switched from the front-to-back
|
|
|
+organization to a back-to-front organization. Seeing how well the
|
|
|
+incremental approach worked at Colorado, I found this rather
|
|
|
+unsatisfactory and have therefore proceeded to reorganize the course,
|
|
|
+porting and adapting the structure of the Colorado course back into
|
|
|
+the land of Scheme. Of course, in the meantime Scheme has been
|
|
|
+superseded by Racket (at least in Indiana), so the course is now about
|
|
|
+implementing, in Racket~\citep{plt-tr}, a subset of Racket.
|
|
|
+
|
|
|
+This is the textbook for the incremental version of the compiler
|
|
|
+course at Indiana Unversity. This book would have been better written
|
|
|
+by Dan, Kent, and Abdulaziz, but it seems that I am the one with the
|
|
|
+time and enthusiasm. With this book I hope to make the Indiana
|
|
|
+compiler course available to people that have not had the chance to
|
|
|
+study here in person.
|
|
|
+
|
|
|
|
|
|
Talk about pre-requisites.
|
|
|
|
|
@@ -132,12 +196,13 @@ Need to give thanks to
|
|
|
\item Abdulaziz Ghuloum
|
|
|
\item Ryan Newton
|
|
|
\item Dipanwita Sarkar
|
|
|
+\item Andrew Keep
|
|
|
\item Oscar Waddell
|
|
|
\end{itemize}
|
|
|
|
|
|
-%\mbox{}\\
|
|
|
-%\noindent Amber Jain \\
|
|
|
-%\noindent \url{http://amberj.devio.us/}
|
|
|
+\mbox{}\\
|
|
|
+\noindent Jeremy G. Siek \\
|
|
|
+\noindent \url{http://homes.soic.indiana.edu/jsiek}
|
|
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
\chapter{Preliminaries}
|
|
@@ -300,7 +365,7 @@ R_0 ::= \Int \mid ({\tt \key{read}}) \mid (\key{-} \; R_0) \mid
|
|
|
\section{S-Expressions}
|
|
|
\label{sec:s-expr}
|
|
|
|
|
|
-Racket, as a descendant of Lisp~\citep{McCarthy:1960dz}, has
|
|
|
+Racket, as a descendant of Lisp, has
|
|
|
convenient support for creating and manipulating abstract syntax trees
|
|
|
with its \emph{symbolic expression} feature, or S-expression for
|
|
|
short. We can create an S-expression simply by writing a backquote
|
|
@@ -528,6 +593,7 @@ of evaluation can make a different.
|
|
|
The behavior of the following program is somewhat subtle because
|
|
|
Racket does not specify an evaluation order for arguments of an
|
|
|
operator such as $-$.
|
|
|
+\marginpar{\scriptsize This is not true of Racket. \\ --Jeremy}
|
|
|
\[
|
|
|
\BINOP{+}{\READ}{\UNIOP{-}{\READ}}
|
|
|
\]
|