COS 441 Exam Stuff David Walker TAL Logistics

  • Slides: 24
Download presentation
COS 441 Exam Stuff David Walker TAL

COS 441 Exam Stuff David Walker TAL

Logistics • take-home exam will become available on the course • • • web

Logistics • take-home exam will become available on the course • • • web site Jan 15 -18 write down when you download & when you turn in • email to kenny or deliver to his office by hand you have 24 hours to complete the exam content: anything from class, assignments, or assigned textbook readings TAL 2

Content: Pre-midterm • Judgments, inductive definitions, proofs by induction • • • (Chapter 3)

Content: Pre-midterm • Judgments, inductive definitions, proofs by induction • • • (Chapter 3) Intuitionistic logic: formulas, proof checking & the Curry-Howard isomorphism Untyped lambda calculus, operational semantics, properties, encodings (Chapter 5) Typed lambda calculus: syntax, operational semantics, typing rules, properties including type safety, progress, preservation, canonical forms, substitution, inversion principles, etc. (Chapter 8, 9, 11) Typed datastructures: tuples, sums (Chapter 11) Implementation of programming language concepts (syntax, substitution, operational semantics, type checking) TAL 3

Content: Post-midterm • recursive types (Chap 20. 1, 20. 2) • effectful computations: references,

Content: Post-midterm • recursive types (Chap 20. 1, 20. 2) • effectful computations: references, exceptions, semantics using • • • evaluation contexts (Chap 13, 14; evaluation contexts note above) quantified types: universal polymorphism, existential types, type inference (Chap 22. 1 -22. 6, 23. 1 -23. 5, 24) subtyping: subtyping relations, co-, contra-, and in-variance, subsumption rule, proving soundness of declarative system, showing subtyping rules are “bad”, don’t worry about relating declarative and algorithmic subtyping formally (Chap 15. 1 -5, 16. 13) class-based, object-oriented languages: featherweight Java (Chap 19. 1 -19. 5) applications of operational semantics & type systems: stack inspection stuff we cover today in lecture implementation of any of the concepts above TAL 4

Typed Assembly Language David Walker Slides stolen from: Greg Morrisett TAL

Typed Assembly Language David Walker Slides stolen from: Greg Morrisett TAL

Types “Type systems for programming languages are a syntactic mechanism for enforcing abstraction. ”

Types “Type systems for programming languages are a syntactic mechanism for enforcing abstraction. ” J. Reynolds TAL 6

What is TAL? A type system for assembly language(s): • built-in abstractions (tuple, code)

What is TAL? A type system for assembly language(s): • built-in abstractions (tuple, code) • operators to build new abstractions ( , , l) • annotations on assembly code • an abstraction checker Thm: well-annotated code cannot violate abstractions. TAL 7

What We Did [popl 98, toplas 99 & others] Theory: • small RISC-style assembly

What We Did [popl 98, toplas 99 & others] Theory: • small RISC-style assembly language • compiler from System F to TAL • soundness and preservation theorems Practice: • most of IA 32 (32 -bit Intel x 86) • more type constructors • everything you can think of and more • safe C compiler • ~40, 000 LOC & compiles itself TAL 8

Why Type Assembly? Theory: • simplifies proofs of compiler correctness • deeper understanding of

Why Type Assembly? Theory: • simplifies proofs of compiler correctness • deeper understanding of compilation Practice: • compiler debugging • software-based protection TAL 9

Type-Based Protection (JVM) JVM verifier System Interface Low-Level IL “Kernel” Java Source javac Optimizer

Type-Based Protection (JVM) JVM verifier System Interface Low-Level IL “Kernel” Java Source javac Optimizer JVM bytecodes Binary TAL System Binary 10

JVM Pros & Cons Pros: • portable • hype: $, tools, libraries, books, training

JVM Pros & Cons Pros: • portable • hype: $, tools, libraries, books, training Cons: • trusted computing base includes JIT • requires many run-time tests • “down” casts, arrays, null pointers, etc. • only suitable for Java (too high-level) • no formal spec (when we started with TAL) TAL 11

Ideally: verifier Your favorite language Low-Level IL (SSA) “Kernel” System Interface System Binary optimizer

Ideally: verifier Your favorite language Low-Level IL (SSA) “Kernel” System Interface System Binary optimizer machine code TAL 12

Rest of the Lecture: Examples • TAL core types: • bytes, tuples, code, •

Rest of the Lecture: Examples • TAL core types: • bytes, tuples, code, • Control-Flow: • calling conventions, stacks, exns • I won’t get to: • closures, objects, modules, type analysis, ADTs TAL 13

Simple Built-In Types • Bytes: b 1, b 2, b 4 • Tuples: (t

Simple Built-In Types • Bytes: b 1, b 2, b 4 • Tuples: (t 1 f , …, tnf ) (f = 0, 1) • Code: {r 1: t 1, …, rn: tn} 1 n • like a pre-condition • argument type of function • no return type because code doesn’t really return, just jumps somewhere else. . . • Polymorphic types: a. t, a. t TAL 14

Simple Loop sum: {ecx: b 4, ebx: {eax: b 4}} mov eax, 0 jmp

Simple Loop sum: {ecx: b 4, ebx: {eax: b 4}} mov eax, 0 jmp test loop: {eax: b 4, ecx: b 4, ebx: {eax: b 4}} add eax, ecx dec ecx FALLTHRU test: {eax: b 4, ecx: b 4, ebx: {eax: b 4}} cmp ecx, 0 jne loop jmp ebx TAL ; int sum(int x) { ; int a = 0; ; ; while(!x) { ; a += x; ; x--; ; } ; ; ; return(a); ; } 15

Allocation: mkpair: {eax: b 4, ebx: {eax: (b 41, b 41)}} mov MALLOC mov

Allocation: mkpair: {eax: b 4, ebx: {eax: (b 41, b 41)}} mov MALLOC mov jmp ecx, eax, 8, (b 4, b 4) [eax+0], ecx [eax+4], ecx ebx TAL ; eax : (b 40, b 40) ; eax : (b 41, b 41) 16

Callee-Saves Register addone: a. {eax: b 4, ecx: a, ebx: {eax: b 4, ecx:

Callee-Saves Register addone: a. {eax: b 4, ecx: a, ebx: {eax: b 4, ecx: a}} inc eax ; x+1 jmp ebx ; return main: {ebx: {eax: b 4}} mov eax, 3 mov ecx, ebx ; save main’s return address mov ebx, done jmp addone[{eax: b 4}] done: {eax: b 4, ecx: {eax: b 4}} inc eax jmp ecx TAL 17

In General: Need to save more stuff (e. g. , locals): MALLOC mov …

In General: Need to save more stuff (e. g. , locals): MALLOC mov … mov jmp ecx, 4 n, (t 1, …, tn) ; frame for storage [ecx+0], r 1 ; save locals [ecx+4 n-4], rn addone[(t 1, …, tn)] Heap-Allocated Activation Records TAL 18

Stacks Want to use stack for activation frames. Stack types: s : : =

Stacks Want to use stack for activation frames. Stack types: s : : = nil | tf: : s | r | s 1 @ s 2 TAL 19

Typing Stack Operations { esp: s } sub esp, i*4 { esp: b 40:

Typing Stack Operations { esp: s } sub esp, i*4 { esp: b 40: : …: : b 40: : s } { esp: t 1 f: : t 2 f: : …: : tif: : s } add esp, i*4 { esp : s } { r: t, esp: t 1 f: : t 2 f: : …: : tif: : s } mov [esp+i*4], r { r: t, esp: t 1 f: : t 2 f: : …: : t 1: : s } { r: t, esp: s } push r { r: t, esp: t 1: : s } { esp: t 1 f: : t 2 f: : …: : ti 1: : s } mov r, [esp+i*4] { r: ti, esp: t 1 f: : t 2 f: : …: : ti 1: : s } { esp: t 1: : s } pop r { r: t, esp: s } TAL 20

Recursion thru Stack Variables fact: r. {eax: b 4, esp: r}: : r} cmp

Recursion thru Stack Variables fact: r. {eax: b 4, esp: r}: : r} cmp eax, 1 jne L[r] retn L: r’. {eax: b 4, esp: r’}: : r’} push eax dec eax call fact[b 4: : {eax: b 4, esp: r’}: : r’] pop ecx imul eax, ecx retn TAL 21

Fact fact: r. {eax: b 4, esp: r}: : r} Because r is abstract,

Fact fact: r. {eax: b 4, esp: r}: : r} Because r is abstract, fact cannot read or write this portion of the stack. Caller’s frame is protected from callee… TAL 22

Other TAL Features • Module system • • • interfaces, implementations, ADTs Sum type/datatype

Other TAL Features • Module system • • • interfaces, implementations, ADTs Sum type/datatype support Fancy arrays/vector typing (Higher Order) Type constructors Fault tolerance checking Other people still writing papers about more. . . TAL 26

Long Term? Low-level, portable, safe language: • OO-support of Java • typing support of

Long Term? Low-level, portable, safe language: • OO-support of Java • typing support of ML • programmer control of C • good model of space • good model of running time • many optimizations expressible in the language Microsoft research working on a new compiler (Phoenix) to generate TAL 27