cos 441 exam stuff
DESCRIPTION
COS 441 Exam Stuff. David Walker. 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 - PowerPoint PPT PresentationTRANSCRIPT
COS 441 Exam StuffCOS 441 Exam Stuff
David Walker
TAL2
LogisticsLogistics
• 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
TAL3
Content: Pre-midtermContent: Pre-midterm
• Judgments, inductive definitions, proofs by induction (Chapter 3)
• Intuitionistic logic: formulas, proofs, 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)
TAL4
Content: Post-midtermContent: 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.1-3)
• 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
Typed Assembly LanguageTyped Assembly Language
David Walker
Slides stolen from:Greg Morrisett
TAL6
TypesTypes
“Type systems for programming languages are a syntactic mechanism for enforcing abstraction.”
J. Reynolds
TAL7
What is TAL?What is TAL?
A type system for assembly language(s):•built-in abstractions (tuple,code)
•operators to build new abstractions (,,)
•annotations on assembly code
•an abstraction checker
Thm: well-annotated code cannot violate abstractions.
TAL8
What We Did What We Did [popl 98, toplas 99 & [popl 98, toplas 99 & others]others]
Theory:• small RISC-style assembly language
• compiler from System F to TAL
• soundness and preservation theorems
Practice:• most of IA32 (32-bit Intel x86)
• more type constructors • everything you can think of and more
• safe C compiler • ~40,000LOC & compiles itself
TAL9
Why Type Assembly?Why Type Assembly?
Theory:•simplifies proofs of compiler correctness
•deeper understanding of compilation
Practice:•compiler debugging
•software-based protection
TAL10
Type-Based Protection (JVM)Type-Based Protection (JVM)
Java Source
javac
JVM bytecodes
JVM verifier System Interface
Binary
Optimizer
Low-Level IL
SystemBinary
“Kernel”
TAL11
JVM Pros & ConsJVM 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)
TAL12
Ideally:Ideally:
Your favoritelanguage
Low-Level IL(SSA)
optimizer
machine code
verifier System Interface
SystemBinary“Kernel”
TAL13
Rest of the Lecture: Rest of the Lecture: ExamplesExamples•TAL core types:
•bytes, tuples, code,
•Control-Flow:•calling conventions, stacks, exns
• I won’t get to:•closures, objects, modules, type
analysis, ADTs
TAL14
Simple Built-In TypesSimple Built-In Types
•Bytes: b1, b2, b4
•Tuples: (11,…,n
n)
•Code: {r1:1,…, rn:n}
• like a pre-condition
•argument type of function
•no return type because code doesn’t really return, just jumps somewhere else...
•Polymorphic types: ., .
TAL15
Simple LoopSimple Loopsum: {ecx:b4, ebx:{eax:b4}} ; int sum(int
x) {mov eax,0 ; int a = 0;jmp test ;
loop: {eax:b4, ecx:b4, ebx:{eax:b4}} ; while(!x) {add eax,ecx ; a += x;dec ecx ; x--;FALLTHRU ; }
test: {eax:b4, ecx:b4, ebx:{eax:b4}} ;cmp ecx,0 ;jne loop ; return(a);jmp ebx ; }
TAL16
Allocation:Allocation:
mkpair: {eax:b4, ebx:{eax:(b41, b41)}}
mov ecx,eaxMALLOC eax,8,(b4, b4) ; eax : (b40,
b40)mov [eax+0],ecx ; eax : (b41,
b40)mov [eax+4],ecx ; eax : (b41,
b41)jmp ebx
TAL17
Callee-Saves RegisterCallee-Saves Register
addone: .{eax:b4, ecx:, ebx:{eax:b4, ecx:}}inc eax ; x+1jmp ebx ; return
main: {ebx:{eax:b4}}mov eax,3 mov ecx,ebx ; save main’s return addressmov ebx,done jmp addone[{eax:b4}]
done: {eax:b4,ecx:{eax:b4}}inc eaxjmp ecx
TAL18
In General:In General:
Need to save more stuff (e.g., locals):
MALLOC ecx,4n,(1,…,n) ; frame for storage
mov [ecx+0],r1… ; save locals
mov [ecx+4n-4],rnjmp addone[(1,…,n)]
Heap-AllocatedActivation Records
TAL19
StacksStacks
Want to use stack for activation frames.
Stack types: ::= nil | :: | | 1 @ 2
TAL20
Typing Stack OperationsTyping Stack Operations
{ esp: } { esp: 1::2
::…::i:: }
sub esp,i*4 add esp,i*4{ esp: b40::b40::…::b40:: } { esp :
{ r: , esp: 1::2
::…::i:: } { r: , esp: }
mov [esp+i*4],r push r{ r: , esp: 1
::2::…::1:: } { r: esp: 1:: }
{ esp: 1::2
::…::i1:: } { esp: 1:: }
mov r,[esp+i*4] pop r{ r: i, esp: 1
::2::…::i
1:: } { r: esp: }
TAL21
Recursion thru Stack Recursion thru Stack VariablesVariablesfact: .{eax:b4, esp:{eax:b4, esp:}::}
cmp eax,1 jne L[]
retnL:’.{eax:b4, esp:{eax:b4, esp:’}::’}
push eax dec eaxcall fact[b4::{eax:b4, esp:’}::’]pop ecximul eax,ecxretn
TAL22
Fact FactFact Fact
fact: .{eax:b4, esp:{eax:b4, esp:}::}
Because is abstract, fact cannot read or write this portion of the stack.
Caller’s frame is protected from callee…
TAL26
Other TAL FeaturesOther 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 ...
TAL27
Long Term?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