CMSC 430: Introduction to Compilers Functional Thomas Gilray - - PowerPoint PPT Presentation

cmsc 430 introduction to compilers
SMART_READER_LITE
LIVE PREVIEW

CMSC 430: Introduction to Compilers Functional Thomas Gilray - - PowerPoint PPT Presentation

CMSC 430: Introduction to Compilers Functional Thomas Gilray (3:15-4:30p, 4161 AVW ) Javran Cheng (12:30-1:45p, 4103 AVW ) cs.umd.edu/class/fall2017/cmsc430 Why take compilers? Sapir-Whorf Hypothesis At least true for programming


slide-1
SLIDE 1

CMSC 430: Introduction to Compilers

Thomas Gilray (3:15-4:30p, 4161AVW)
 
 Javran Cheng (12:30-1:45p, 4103AVW)

Functional

slide-2
SLIDE 2

cs.umd.edu/class/fall2017/cmsc430

slide-3
SLIDE 3

Why take compilers?

slide-4
SLIDE 4

Sapir-Whorf Hypothesis At least true for programming languages…

slide-5
SLIDE 5

Why take compilers?

  • Likewise, learning how the compiler thinks makes you

a better programmer.

  • Can make smarter use of existing compilers.
  • Will apply many of the same principles elsewhere.
  • You may eventually work on a smaller language, or

perhaps even a large one.

  • Avoid introducing something indecent into the world…
slide-6
SLIDE 6

Such as equality semantics in PHP…

slide-7
SLIDE 7

Lexing Parsing Macros/preprocessing Intermediate representation (IR/IL) Smaller IR Tiny IR (admin bindings) Static single assignment (SSA) Register allocation Code emission (asm)

slide-8
SLIDE 8

Lexing Parsing Macros/preprocessing Intermediate representation (IR/IL) Smaller IR Tiny IR (admin bindings) Static single assignment (SSA) Register allocation Code emission (asm)

slide-9
SLIDE 9

Lexing Parsing Macros/preprocessing Intermediate representation (IR/IL) Smaller IR Tiny IR (admin bindings) Static single assignment (SSA) Register allocation Code emission (asm) evaluate result result’ =

slide-10
SLIDE 10

Lexing Parsing Macros/preprocessing Intermediate representation (IR/IL) Smaller IR Tiny IR (admin bindings) Static single assignment (SSA) Register allocation Code emission (asm) Assignment conversion Continuation-passing style conversion Closure conversion }

slide-11
SLIDE 11

The big idea:

slide-12
SLIDE 12

Compile well

λ

slide-13
SLIDE 13

Then compile almost everything into λ

slide-14
SLIDE 14

Alonzo Church

λ-calculus

slide-15
SLIDE 15

LISP

John McCarthy

slide-16
SLIDE 16

Scheme

Guy Steele Gerald Jay Sussman

slide-17
SLIDE 17

Scheme

Guy Steele Gerald Jay Sussman

I should not design a small language, and I should not design a large one. I need to design a language that can grow.

“ ”

Growing a language. (1998)

slide-18
SLIDE 18

Matthias Felleisen Matthew Flatt

(et al.)

PLT Scheme -> Racket

slide-19
SLIDE 19

Symbolic expressions (s-expr)

( ... )

slide-20
SLIDE 20

(tag children ...)

slide-21
SLIDE 21

Textual encoding for lists/trees

slide-22
SLIDE 22

<tag> children ... </tag>

slide-23
SLIDE 23

<tag id=“child” ...> children ... </tag>

slide-24
SLIDE 24

(tag ([id child] ...) children ...)

slide-25
SLIDE 25

(xexpr->xml ‘(tag ([id child] ...) children ...)) “<tag id=\“child\” ...> children ... </tag>”

slide-26
SLIDE 26

let rec fact n = if n <= 1 then 1 else n * fact (n - 1)
 ...

slide-27
SLIDE 27

let rec fact n = if n <= 1 then 1 else n * fact (n - 1)
 ... let rec fact n if <= n 1 1 * n apply fact

  • n

1 ...

slide-28
SLIDE 28

let rec fact n if <= n 1 1 * n apply fact

  • n

1 (letrec ([fact (λ (n) (if (<= n 1) 1 (* n (fact (- n 1)))))]) ...) ...

slide-29
SLIDE 29

This week.

  • Download and install Racket 6.10
  • Try out DrRacket IDE and the cmd-line Racket REPL.
  • Try examples and start learning the language. It will

simply take some time using the language to learn it.

  • Warm-up assignment 0 is online now. Due Mon, 9/4.
  • Use submit.cs.umd.edu to submit. Start early.
slide-30
SLIDE 30

Let’s try some Racket.