|
@@ -107,72 +107,94 @@ University.
|
|
|
|
|
|
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.
|
|
|
+the 1970's and 1980'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.
|
|
|
+elements of effective real-world compilers. One of Dan's 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 would be easy to understood in isolation. (In contrast, most
|
|
|
+compilers of the time were organized into only a few monolithic 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. Needless to say, I enjoyed the course immensely.
|
|
|
|
|
|
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
|
|
|
+students build the compiler in stages; they start 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}.
|
|
|
+in each subsequent stage they add a feature to the input language and
|
|
|
+add or modify passes to handle the new feature~\citep{Ghuloum:2006bh}.
|
|
|
+In this way, the students see how the language features motivate
|
|
|
+aspects of the compiler design.
|
|
|
|
|
|
After graduating from Indiana University in 2005, I went on to teach
|
|
|
-at the University of Colorado. I adapted the nano-pass and incremental
|
|
|
+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.)
|
|
|
+teaching the course organized in this way, 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.
|
|
|
+unsatisfactory and have 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.
|
|
|
+course at Indiana University (Spring 2016) and it is the first attempt
|
|
|
+to create a textbook for the Indiana compiler course. 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. Many of the compiler
|
|
|
+design decisions in this book are drawn from the assignment
|
|
|
+descriptions of \cite{Dybvig:2010aa}. I have captured what I think are
|
|
|
+the most important topics from \cite{Dybvig:2010aa} but have omitted
|
|
|
+topics that I think are less interesting conceptually and I have made
|
|
|
+simplifications to reduce complexity. In this way, this book leans
|
|
|
+more towards pedagogy than towards absolute efficiency. Also, the book
|
|
|
+differs in places where I saw the opportunity to make the topics more
|
|
|
+fun, such as in relating register allocation to Sudoku
|
|
|
+(Chapter~\ref{ch:register-allocation}).
|
|
|
+
|
|
|
+\section*{Prerequisites}
|
|
|
+
|
|
|
+This material in this book is challenging but rewarding. It is meant
|
|
|
+to prepare students for a lifelong career in programming languages. I
|
|
|
+do not recommend this book for students who only want to dabble in
|
|
|
+programming languages. The book uses the Racket language both for the
|
|
|
+implementation of the compiler and for the language that is
|
|
|
+compiled. Thus, a student should be proficient with Racket (or Scheme)
|
|
|
+prior to reading this book. There are many other excellent resources
|
|
|
+for learning Racket and
|
|
|
+Scheme~\citep{Dybvig:1987aa,Abelson:1996uq,Friedman:1996aa,Felleisen:2001aa,Felleisen:2013aa,Flatt:2014aa}. It
|
|
|
+is helpful but not necessary for the student to have prior exposure to
|
|
|
+the x86 (or x86-64) assembly language, as one might get from a
|
|
|
+computer systems course~\citep{Bryant:2005aa,Bryant:2010aa}. This
|
|
|
+book will introduce the basics of the x86-64 assembly language.
|
|
|
|
|
|
%\section*{Structure of book}
|
|
|
% You might want to add short description about each chapter in this book.
|