• Tidak ada hasil yang ditemukan

CS6848 - Principles of Programming Languages - CSE-IITM

N/A
N/A
Protected

Academic year: 2025

Membagikan "CS6848 - Principles of Programming Languages - CSE-IITM"

Copied!
3
0
0

Teks penuh

(1)

CS6848 - Principles of Programming Languages

Principles of Programming Languages

V. Krishna Nandivada

IIT Madras

*

Typed Assembly Language

What is TAL?

A type system for assembly language(s) Has built-in abstractions (tuple, code) operators to build new abstraction (∀,∃,λ).

annotations on assembly code.

an abstraction checker ( = type checker)

Theorem: Well annotated code cannot violate abstractions.

V.Krishna Nandivada (IIT Madras) CS6848 (IIT Madras) 2 / 1

*

Why Typed Assembly

Theory

Simplifies proofs of compiler correctness Helps in deeper understanding of compilation Practice

Helps in compiler debugging.

Software based protection (code over the wire).

Difference between JVM and TAL?

V.Krishna Nandivada (IIT Madras) CS6848 (IIT Madras) 3 / 1

*

TAL description

v ::= c|l (values)

t ::= Int|Γ (types)

e ::= movrd,rs;e|setrd,v;e|incr;e|jmpr (code) R ::= [r7→v,· · ·] (registerfile)

Γ ::= [r:t,· · ·] (regfiletype)

H ::= [l7→(Γ,e),· · ·] (codeheap)

A ::= [l: Γ,· · ·] (heaptype)

s ::= (H,R,e) (programState)

cranges over constants,lranges over labels (or addresses).

V.Krishna Nandivada (IIT Madras) CS6848 (IIT Madras) 4 / 1

(2)

*

Semantics

A small step operational semantics is given by the reflexive, transitive closure of the relation→V.

V⊆programState×programState

(H,R,movrd,rs;e)→V (H,R[rd7→R(rs)],e) (1)

(H,R,setrd,v;e)→V (H,R[rd7→v],e) (2)

(H,R,incr;e)→V (H,R[r7→ dR(r) +1e],e) (3)

(H,R,jmpr;e)→V (H,R,e),providedR(r) =landH(l) = (Γ,e) (4)

V.Krishna Nandivada (IIT Madras) CS6848 (IIT Madras) 5 / 1

*

Soundness

A program is stuck if there is no program states0 such thats→V s0. A program statesgoes wrong if∃s0:s→V s0 ands0is stuck.

We want to provide type rules so that we can claim that Well typed programs cannot go wrong.

V.Krishna Nandivada (IIT Madras) CS6848 (IIT Madras) 6 / 1

*

Type rules

Type rules for Values:

A`c:Int (5)

A`l: Γ(A(l) = Γ) (6)

Types rules for register files:

A`v:t Γ(r) =t A,Γ`[r7→v]

(7)

Ordering of register file types:

[r1:t1,· · ·rn:tn,· · ·rn+m:tn+m]≤[r1:t1,· · ·rn:tn]wherem≥0 (8)

V.Krishna Nandivada (IIT Madras) CS6848 (IIT Madras) 7 / 1

*

Type rules(cont.)

Type rules for Code:

A,Γ[rd: Γ(rs)]`e A,Γ`movrd,rs;e (9)

A`v:t A,Γ[rd:t]`e A,Γ`setrd,v;e (10)

Γ(r) =Int A,Γvdashe A,Γ`incr;e (11)

Γ(r) = Γ0 Γ≤Γ0 A,Γ`jmpr (12)

Type rules for code heaps:

A,Γ`e A(l) = Γ A`[l7→(Γ,e)]

(13)

V.Krishna Nandivada (IIT Madras) CS6848 (IIT Madras) 8 / 1

(3)

*

Type rules(cont.)

Type rules for the program states:

A`H A,Γ`R A,Γ`e

`(H,R,e) (14)

A program statesis well typed if and only if`s.

Reading exercise: well-typed program state cannot go wrong.

V.Krishna Nandivada (IIT Madras) CS6848 (IIT Madras) 9 / 1

*

Acknowledgements

Lecture notes from Jens Palsberg Slides from David Walker

V.Krishna Nandivada (IIT Madras) CS6848 (IIT Madras) 10 / 1

Referensi

Dokumen terkait

V.Krishna Nandivada IIT Madras CS3400 15 / 35 * Master/Worker template for master int nTasks // Number of tasks int nWorkers // Number of workers public static SharedQueue

* Connection between axiomatic and operational semantics Semantics of Valid assertions Soundness Completeness V.Krishna Nandivada IIT Madras CS6848 IIT Madras 21 / 27 * Validity

Polymorphism - variations Type systems allow single piece of code to be used with multiple types are collectively known as polymorphic systems.. Variations: Parametric polymorphism:

Type systems allow single piece of code to be used with multiple types are collectively known as polymorphic systems.. Parametric polymorphism: Single piece of code to be typed

* JavaCC input One file header token specification for lexical analysis grammar Example of a token specification: TOKEN : { < INTEGER_LITERAL: ["1"-"9"] ["0"-"9"]* | "0" > }

* Examples id=λX.λx:X x id:∀X.X→X type application: id[Int] :Int →Int value application:id[Int]0=0:Int applyTwice=λX.λf :X→X.λa:Xf f a ApplyTwiceInts=applyTwice[Int]

try error withe→e Step e1→e01 trye1withe2→trye01 withe2 V.Krishna Nandivada IIT Madras CS6848 9 / 1 * Exceptions variant 3 - User defined The program point where the exception is

synchronized color { int myColorInt = color.getRGB; String myColorName = color.getName; } Such issues do not arise with immutable objects V.Krishna Nandivada IIT Madras CS6868 -