Jeremy Siek 6 سال پیش
والد
کامیت
9f675869f6
2فایلهای تغییر یافته به همراه97 افزوده شده و 56 حذف شده
  1. 15 12
      book.tex
  2. 82 44
      notes.md

+ 15 - 12
book.tex

@@ -106,6 +106,8 @@ moredelim=[is][\color{red}]{~}{~}
   Carl Factora \\
   Carl Factora \\
   Andre Kuhlenschmidt \\
   Andre Kuhlenschmidt \\
   Michael M. Vitousek \\
   Michael M. Vitousek \\
+  Michael Vollmer \\
+  Ryan Scott \\
   Cameron Swords
   Cameron Swords
    }
    }
 
 
@@ -152,10 +154,10 @@ few monolithic passes for reasons of compile-time efficiency.)  Kent,
 with later help from his students Dipanwita Sarkar and Andrew Keep,
 with later help from his students Dipanwita Sarkar and Andrew Keep,
 developed infrastructure to support this approach and evolved the
 developed infrastructure to support this approach and evolved the
 course, first to use micro-sized passes and then into even smaller
 course, first to use micro-sized passes and then into even smaller
-nano passes~\citep{Sarkar:2004fk,Keep:2012aa}. Jeremy Siek took this
-compiler course in the early 2000's, as part of his Ph.D. studies at
-Indiana University. Needless to say, Jeremy enjoyed the course
-immensely.
+nano passes~\citep{Sarkar:2004fk,Keep:2012aa}. Jeremy Siek was a
+student in this compiler course in the early 2000's, as part of his
+Ph.D. studies at Indiana University. Needless to say, Jeremy enjoyed
+the course immensely!
 
 
 One of Jeremy's classmates, Abdulaziz Ghuloum, observed that the
 One of Jeremy's classmates, Abdulaziz Ghuloum, observed that the
 front-to-back organization of the course made it difficult for
 front-to-back organization of the course made it difficult for
@@ -184,12 +186,12 @@ organization to a back-to-front organization. Seeing how well the
 incremental approach worked at Colorado, he started porting and
 incremental approach worked at Colorado, he started porting and
 adapting the structure of the Colorado course back into the land of
 adapting the structure of the Colorado course back into the land of
 Scheme. In the meantime Indiana had moved on from Scheme to Racket, so
 Scheme. In the meantime Indiana had moved on from Scheme to Racket, so
-the course is now about compiling a subset of Racket to the x86
-assembly language and the compiler is implemented in
+the course is now about compiling a subset of Racket (and Typed
+Racket) to the x86 assembly language. The compiler is implemented in
 Racket~\citep{plt-tr}.
 Racket~\citep{plt-tr}.
 
 
 This is the textbook for the incremental version of the compiler
 This is the textbook for the incremental version of the compiler
-course at Indiana University (Spring 2016 - Fall 2018) and it is the
+course at Indiana University (Spring 2016 - present) and it is the
 first open textbook for an Indiana compiler course.  With this book we
 first open textbook for an Indiana compiler course.  With this book we
 hope to make the Indiana compiler course available to people that have
 hope to make the Indiana compiler course available to people that have
 not had the chance to study in Bloomington in person.  Many of the
 not had the chance to study in Bloomington in person.  Many of the
@@ -208,11 +210,12 @@ allocation to Sudoku (Chapter~\ref{ch:register-allocation}).
 The material in this book is challenging but rewarding. It is meant to
 The material in this book is challenging but rewarding. It is meant to
 prepare students for a lifelong career in programming languages.  We do
 prepare students for a lifelong career in programming languages.  We do
 not recommend this book for students who want to dabble in programming
 not recommend this book for students who want to dabble in programming
-languages.  Because the book uses the Racket language both for the
-implementation of the compiler and for the language that is compiled,
-a student should be proficient with Racket (or Scheme) prior to
-reading this book. There are many other excellent resources for
-learning Scheme and
+languages.
+
+The book uses the Racket language both for the implementation of the
+compiler and for the language that is compiled, so a student should be
+proficient with Racket (or Scheme) prior to reading this book. There
+are many other excellent resources for learning Scheme and
 Racket~\citep{Dybvig:1987aa,Abelson:1996uq,Friedman:1996aa,Felleisen:2001aa,Felleisen:2013aa,Flatt:2014aa}. It
 Racket~\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
 is helpful but not necessary for the student to have prior exposure to
 x86 (or x86-64) assembly language~\citep{Intel:2015aa}, as one might
 x86 (or x86-64) assembly language~\citep{Intel:2015aa}, as one might

+ 82 - 44
notes.md

@@ -3,7 +3,7 @@
 
 
 
 
 --------------------------------------------------------------------------------
 --------------------------------------------------------------------------------
-R1:
+R1: Integers and Variables
 
 
     exp ::= x | n | (op exp*) | (let ([x exp]) exp)
     exp ::= x | n | (op exp*) | (let ([x exp]) exp)
     R1 ::= (program exp)
     R1 ::= (program exp)
@@ -31,7 +31,7 @@ V
     exp ::= arg | (op arg*)
     exp ::= arg | (op arg*)
     stmt ::= (assign x exp)
     stmt ::= (assign x exp)
     tail ::= (return exp) | (seq stmt tail)
     tail ::= (return exp) | (seq stmt tail)
-    C0 ::= (program () tail)
+    C0 ::= (program () ((label . tail)*))
 
 
 uncover-locals
 uncover-locals
 |
 |
@@ -41,7 +41,7 @@ V
     exp ::= arg | (op arg*)
     exp ::= arg | (op arg*)
     stmt ::= (assign x exp)
     stmt ::= (assign x exp)
     tail ::= (return exp) | (seq stmt tail)
     tail ::= (return exp) | (seq stmt tail)
-    C0 ::= (program ((locals . x*)) tail)
+    C0 ::= (program ((locals . x*)) ((label . tail)*))
     
     
 select-instructions
 select-instructions
 |
 |
@@ -50,15 +50,16 @@ V
     imm ::= (var x) | (reg r) | (deref r n) | (int n)
     imm ::= (var x) | (reg r) | (deref r n) | (int n)
     instr ::= (addq imm imm) | (retq) | ...
     instr ::= (addq imm imm) | (retq) | ...
     block ::= (block () instr*)
     block ::= (block () instr*)
-    x86 ::= (program ((locals . x*)) block)
+    x86 ::= (program ((locals . x*)) ((label . block)*))
 
 
 assign-homes
 assign-homes
 |
 |
 V
 V
 
 
     imm ::= (reg r) | (deref r n) | (int n)
     imm ::= (reg r) | (deref r n) | (int n)
-    instr ::= ...
-    x86 ::= (program ((stack-space . n)) block)
+    instr ::= (addq imm imm) | ...
+    block ::= (block () instr*) 
+    x86 ::= (program ((stack-space . n)) ((label . block)*))
     
     
 patch-instructions
 patch-instructions
 |
 |
@@ -74,7 +75,7 @@ V
 
 
 --------------------------------------------------------------------------------
 --------------------------------------------------------------------------------
 
 
-R2:
+R2: Booleans and Conditionals
 
 
     exp ::= x | n | #t | #f | (op exp*) | (let ([x exp]) exp) | (if exp exp exp)
     exp ::= x | n | #t | #f | (op exp*) | (let ([x exp]) exp) | (if exp exp exp)
     R2 ::= (program exp)
     R2 ::= (program exp)
@@ -103,7 +104,7 @@ V
     tail ::= (return exp) | (seq stmt tail)
     tail ::= (return exp) | (seq stmt tail)
            | (goto label) | (if (op arg*) ((goto label)) ((goto label)))
            | (goto label) | (if (op arg*) ((goto label)) ((goto label)))
     stmt ::= (assign x exp)
     stmt ::= (assign x exp)
-    C1 ::= (program ((type . type) (flow-graph . ((label . tail)*))) tail)
+    C1 ::= (program ((type . type)) ((label . tail)*))
 
 
 optimize-jumps
 optimize-jumps
 |
 |
@@ -120,9 +121,8 @@ V
     tail ::= (return exp) | (seq stmt tail)
     tail ::= (return exp) | (seq stmt tail)
            | (goto label) | (if (op exp*) ((goto label)) ((goto label)))
            | (goto label) | (if (op exp*) ((goto label)) ((goto label)))
     stmt ::= (assign x exp)
     stmt ::= (assign x exp)
-    C1 ::= (program ((type . type) (flow-graph . ((label . tail)*))
-                     (locals . x*)) 
-                    tail)
+    C1 ::= (program ((type . type) (locals . x*)) 
+                    ((label . tail)*))
 
 
 select-instructions
 select-instructions
 |
 |
@@ -130,8 +130,8 @@ V
 
 
     imm ::= (var x) | (deref r n) | (int n)
     imm ::= (var x) | (deref r n) | (int n)
     instr ::= (addq imm imm) | ... | (jmp label) | (jmp-if cc label) | (retq) 
     instr ::= (addq imm imm) | ... | (jmp label) | (jmp-if cc label) | (retq) 
-    x86 ::= (program ((locals . x*) (type . type) 
-                      (flow-graph . ((label . instr*)*))) instr*)
+    block ::= (block () instr*)
+    x86 ::= (program ((locals . x*) (type . type)) ((label . block)*))
 
 
 uncover-live
 uncover-live
 |
 |
@@ -139,18 +139,16 @@ V
 
 
     imm ::= (var x) | (deref r n) | (int n)
     imm ::= (var x) | (deref r n) | (int n)
     instr ::= (addq imm imm) | (jmp label) | (jmp-if cc label) | (retq)
     instr ::= (addq imm imm) | (jmp label) | (jmp-if cc label) | (retq)
-	block ::= (block (lives ls*) instr*)
-    x86 ::= (program ((locals . x*) (type . type)
-                      (flow-graph . ([label . block]*))) block)
+    block ::= (block (lives ls*) instr*)
+    x86 ::= (program ((locals . x*) (type . type)) ((label . block)*))
 
 
 build-interference
 build-interference
 |
 |
 V
 V
 
 
-    x86 ::= (program ((locals . x*) (type . type)
-                      (flow-graph . ([label . block]*))
-						  (conflicts . graph))
-					     block)
+    block ::= (block () instr*)
+    x86 ::= (program ((locals . x*) (type . type) (conflicts . graph))
+                     ((label . block)*))
 
 
 allocate-registers
 allocate-registers
 |
 |
@@ -158,8 +156,9 @@ V
 
 
     imm ::= (reg r) | (deref r n) | (int n)
     imm ::= (reg r) | (deref r n) | (int n)
     instr ::= (addq imm imm) | ... | (jmp label) | (jmp-if cc label) | (retq)
     instr ::= (addq imm imm) | ... | (jmp label) | (jmp-if cc label) | (retq)
-    x86 ::= (program  ((locals . x*) (type . type) 
-                       (flow-graph . ((label . instr*)*))) instr*)
+    block ::= (block () instr*)
+    x86 ::= (program ((locals . x*) (type . type))
+                     ((label . block)*))
     
     
 print-x86
 print-x86
 |
 |
@@ -167,12 +166,12 @@ V
 
 
 --------------------------------------------------------------------------------
 --------------------------------------------------------------------------------
 
 
-R3:
+R3: Vectors
 
 
     exp ::= x | n | #t | #f | (op exp*) | (let ([x exp]) exp) | (if exp exp exp)
     exp ::= x | n | #t | #f | (op exp*) | (let ([x exp]) exp) | (if exp exp exp)
-          | (vector exp+) | (vector-ref exp n) | (vector-set! exp n exp)
+          | (vector exp*) | (vector-ref exp n) | (vector-set! exp n exp)
           | (void)
           | (void)
-    R2 ::= (program exp)
+    R3 ::= (program exp)
 
 
 type-check
 type-check
 |
 |
@@ -180,10 +179,10 @@ V
 
 
     type ::= ... | Void | (Vector type*)
     type ::= ... | Void | (Vector type*)
     exp ::= x | n | #t | #f | (op exp*) | (let ([x exp]) exp) | (if exp exp exp)
     exp ::= x | n | #t | #f | (op exp*) | (let ([x exp]) exp) | (if exp exp exp)
-          | (vector exp+) | (vector-ref exp n) | (vector-set! exp n exp)
+          | (vector exp*) | (vector-ref exp n) | (vector-set! exp n exp)
           | (void)
           | (void)
           | (has-type exp type)
           | (has-type exp type)
-    R2 ::= (program ((type . type)) exp)
+    R3 ::= (program ((type . type)) exp)
 
 
 expose-allocation
 expose-allocation
 |
 |
@@ -191,10 +190,10 @@ V
 
 
     type ::= ... | Void | (Vector type*)
     type ::= ... | Void | (Vector type*)
     exp ::= x | n | #t | #f | (op exp*) | (let ([x exp]) exp) | (if exp exp exp)
     exp ::= x | n | #t | #f | (op exp*) | (let ([x exp]) exp) | (if exp exp exp)
-          | (vector exp+) | (vector-ref exp n) | (vector-set! exp n exp)
+          | (vector exp*) | (vector-ref exp n) | (vector-set! exp n exp)
           | (void) | (has-type exp type)
           | (void) | (has-type exp type)
           | (collect n) | (allocate n type) | (global-value x)
           | (collect n) | (allocate n type) | (global-value x)
-    R2 ::= (program ((type . type)) exp)
+    R3 ::= (program ((type . type)) exp)
 
 
 remove-complex-opera*
 remove-complex-opera*
 |
 |
@@ -202,10 +201,10 @@ V
 
 
     arg ::= x | n | #t | #f | (void)
     arg ::= x | n | #t | #f | (void)
     exp ::= arg | (op arg*) | (let ([x exp]) exp) | (if exp exp exp)
     exp ::= arg | (op arg*) | (let ([x exp]) exp) | (if exp exp exp)
-          | (vector exp+) | (vector-ref exp n) | (vector-set! exp n exp)
+          | (vector exp*) | (vector-ref exp n) | (vector-set! exp n exp)
           | (void) | (has-type exp type)
           | (void) | (has-type exp type)
           | (collect n) | (allocate n type) | (global-value x)
           | (collect n) | (allocate n type) | (global-value x)
-    R2 ::= (program ((type . type)) exp)
+    R3 ::= (program ((type . type)) exp)
 
 
 create-CFG
 create-CFG
 |
 |
@@ -217,14 +216,14 @@ V
     tail ::= (goto label) | (if (op arg*) ((goto label)) ((goto label)))
     tail ::= (goto label) | (if (op arg*) ((goto label)) ((goto label)))
           | (return exp) | (seq stmt tail)
           | (return exp) | (seq stmt tail)
     stmt ::= (assign x exp) | (collect n)
     stmt ::= (assign x exp) | (collect n)
-    C1 ::= (program ((type . type) (flow-graph . ((label . tail)*))) tail)
+    C2 ::= (program ((type . type)) ((label . tail)*))
 
 
 uncover-locals
 uncover-locals
 |
 |
 V
 V
 
 
     ...
     ...
-    C1 ::= (program ((locals . ((x . type)*)) (type . type) 
+    C2 ::= (program ((locals . ((x . type)*)) (type . type) 
                      (flow-graph . ((label . tail)*))) tail)
                      (flow-graph . ((label . tail)*))) tail)
 
 
 select-instructions
 select-instructions
@@ -233,8 +232,9 @@ V
 
 
     imm ::= (var x) | (deref r n) | (int n) | (global-value x)
     imm ::= (var x) | (deref r n) | (int n) | (global-value x)
     instr ::= (addq imm imm) | ... | (jmp label) | (jmp-if cc label) | (retq) 
     instr ::= (addq imm imm) | ... | (jmp label) | (jmp-if cc label) | (retq) 
-    x86-CFG ::= (program ((locals . ((x . type)*)) (type . type) 
-                          (flow-graph . ((label . instr*)*))) instr*)
+    block ::= (block () instr*)
+    x86 ::= (program ((locals . ((x . type)*)) (type . type))
+                     ((label . block)*))
 
 
 uncover-live
 uncover-live
 |
 |
@@ -243,17 +243,17 @@ V
     imm ::= (var x) | (deref r n) | (int n) | (global-value x)
     imm ::= (var x) | (deref r n) | (int n) | (global-value x)
     instr ::= (addq imm imm) | ... | (jmp label) | (jmp-if cc label) | (retq) 
     instr ::= (addq imm imm) | ... | (jmp label) | (jmp-if cc label) | (retq) 
     block ::= (block (lives x**) instr*)
     block ::= (block (lives x**) instr*)
-    x86-CFG ::= (program ((locals . ((x . type)*)) (type . type) 
-                          (flow-graph . ((label . block)*))) block)
+    x86 ::= (program ((locals . ((x . type)*)) (type . type))
+                     ((label . block)*))
 
 
 build-interference
 build-interference
 |
 |
 V
 V
 
 
     ...
     ...
-    x86-CFG ::= (program ((locals . ((x . type)*)) (type . type) 
-                          (conflicts . graph)
-                          (flow-graph . ((label . instr*)*))) instr*)
+    x86 ::= (program ((locals . ((x . type)*)) (type . type) 
+                      (conflicts . graph))
+                     ((label . block)*))
 
 
 build-move-graph
 build-move-graph
 |
 |
@@ -261,8 +261,8 @@ V
 
 
     ...
     ...
     x86-CFG ::= (program ((locals . ((x . type)*)) (type . type) 
     x86-CFG ::= (program ((locals . ((x . type)*)) (type . type) 
-                          (conflicts . graph) (move-graph . graph)
-                          (flow-graph . ((label . instr*)*))) instr*)
+                          (conflicts . graph) (move-graph . graph))
+                         ((label . block)*))
 
 
 allocate-registers
 allocate-registers
 |
 |
@@ -270,8 +270,8 @@ V
 
 
     imm ::= (reg x) | (deref r n) | (int n) | (global-value x)
     imm ::= (reg x) | (deref r n) | (int n) | (global-value x)
     instr ::= (addq imm imm) | ... | (jmp label) | (jmp-if cc label) | (retq) 
     instr ::= (addq imm imm) | ... | (jmp label) | (jmp-if cc label) | (retq) 
-    x86-CFG ::= (program ((locals . ((x . type)*)) (type . type) 
-                          (flow-graph . ((label . instr*)*))) instr*)
+    x86 ::= (program ((locals . ((x . type)*)) (type . type))
+                     ((label . block)*))
 
 
 patch-instructions
 patch-instructions
 |
 |
@@ -280,3 +280,41 @@ V
     same as above
     same as above
 
 
 print-x96
 print-x96
+|
+V
+
+--------------------------------------------------------------------------------
+
+R4: Functions
+
+    type ::= ... | (type* -> type)
+    exp ::= x | n | #t | #f | (op exp*) | (let ([x exp]) exp) | (if exp exp exp)
+          | (vector exp*) | (vector-ref exp n) | (vector-set! exp n exp)
+          | (void)
+          | (exp exp*)
+    def ::= (define (var [var : type]*) : type exp)
+    R4 ::= (program def* exp)
+
+type-check
+|
+V
+
+    R4 ::= (program () def+)
+
+uniquify
+|
+V
+
+    same as above
+
+limit-functions
+|
+V
+
+    same as above, but with a limit on the number of parameters to a function
+
+reveal-functions
+|
+V
+
+    F1