Parcourir la source

5.5 compilation

jordyn il y a 4 ans
Parent
commit
f0cf2a0df5
3 fichiers modifiés avec 117 ajouts et 0 suppressions
  1. 37 0
      5/5/jord/lecture.org
  2. 0 0
      5/5/jord/note
  3. 80 0
      5/5/jord/notes.org

+ 37 - 0
5/5/jord/lecture.org

@@ -0,0 +1,37 @@
+* Lecture 10A: Compilation
+https://youtu.be/TqO6V3qR9Ws
+text § 5.5
+
+we are bridging the gap between a high level language like lisp and a
+low level language
+
+before we did this with register machine emulation by writing an
+interpreter to raise the machine to the level of the languages we want
+to write
+
+we can also go the other way, compiling the high level lisp down to
+lower level machine code
+
+interpretation vs. compilation
+
+wow some crazy outfits today... those sunglasses, that tie, the
+headscarf??? wtf lol. it must be halloween or some corporate
+event. the baseball (?) outfit is cute. bolo tie and starry vest. lots
+and lots of sunglasses.
+
+"it's a wretched wretched compiler"
+
+from 20 or so instructions, the compiler distilled it down to three
+  that is, the less wretched compiler
+
+--> break
+
+"im going to give no details" the details are in the book
+
+the interpreter is maximally pessimistic, so always saves state
+
+the compiler can prune those out
+
+"a good lisp compiler can absorb an arbitrary amount of effort"
+the reason fortran is faster than lisp is the effort invested in
+fortran compilers is significantly greater

+ 0 - 0
5/5/jord/note


+ 80 - 0
5/5/jord/notes.org

@@ -0,0 +1,80 @@
+* 5.5 Compilation
+5.4 implemented scheme on a register machine
+
+this section shows how to translate a scheme program to register
+  machine language
+
+programs written in machine language are sequences of instructions
+that use the machine's data paths
+
+compilation translates a given source language into an equivalent
+program (object program) written in native machine language
+
+lisps tend to utilize the complimentary benefits of compilation and
+interpretation in concert with each other
+
+** 5.5.1 structure of the compiler
+the compile procedure is the top-level dispatch in the compiler
+
+similar to the interpreters
+
+compile takes target and linkage as arguments
+
+  - target :: the register in which the compiled code shall return the
+              value of the expression
+  - linkage :: how the code shall proceed when finished with execution
+
+the code generator returns on instruction soquence containing the
+object code it has generated for the expression
+
+smart use of preserving to save and restore registers optimises stack
+operations
+
+an instruction sequence is made up of:
+  - the registers it needs
+  - the registers it modifies
+  - its instructions (statements)
+
+** 5.5.2 compiling expressions
+here we define linkage for the code generators and its use in simple
+expressions, conditional expressions, sequences, lambdas
+
+** 5.5.3 compiling combinations
+the essence of compilation is procedure applications
+
+"the code that handles procedure application is the most subtle part
+of the compiler"
+
+** 5.5.4 combining instruction sequences
+herein are the details for how instruction sequences are represented
+and combined. see text.
+
+** 5.5.5 an example of compiled code
+see text.
+
+** 5.5.6 lexical addressing
+one of the most common compiler optimizations is in variable lookup.
+
+this uses some neat hack that remembers what frame and what order
+variables come to speed things up. the compiler can do this with a
+data structure called the "compile time environment" which keeps track
+of what variables are where, when.
+
+** 5.5.7 interfacing compiled code to the evaluator
+they have not yet explained how to load compiled code or how to run
+it. well, you hook it into the pre-defined explicit-control-evaluator
+machine. 
+
+an interpreter raises the machine to the level of the user;
+a compiler lowers the user's program to the machine.
+
+scheme itself is a family of abstractions erected on machine language.
+
+c and c++ programs "lead fast and dangerous lives" because their
+compilers do little error checking.
+
+we can compile the compiler itself and use it to compile other lisp
+programs.
+
+(fin)
+