15-411: Dynamic Semantics Jan Ho ff mann Dynamic Semantics Static - - PowerPoint PPT Presentation

15 411 dynamic semantics
SMART_READER_LITE
LIVE PREVIEW

15-411: Dynamic Semantics Jan Ho ff mann Dynamic Semantics Static - - PowerPoint PPT Presentation

15-411: Dynamic Semantics Jan Ho ff mann Dynamic Semantics Static semantics: definition of valid programs Dynamic semantics: definition of how programs are executed So far: Dynamic semantics is given in English on lab handouts This


slide-1
SLIDE 1

15-411: Dynamic Semantics

Jan Hoffmann

slide-2
SLIDE 2

Dynamic Semantics

  • Static semantics: definition of valid programs
  • Dynamic semantics: definition of how programs are executed
  • So far: Dynamic semantics is given in English on lab handouts
  • This only works since you know how C programs should behave
  • Sometimes needed to consult the reference compiler
  • A description in English will always be ambiguous

➡ Need precise ways of defining the meaning of programs

slide-3
SLIDE 3

Types of (Formal) Dynamic Semantics

  • Denotational Semantics: Abstract and elegant.
  • Each part of a program is associated with a denotation (math. object)
  • For example: a procedure is associated with a mathematical function
  • Axiomatic Semantics: Strongly related to program logic.
  • Gives meaning to phrases using logical axioms
  • The meaning is identical to the set of properties that can be proved
  • Operational Semantics: Describes how programs are executed
  • Related to interpretation and abstract machines
  • Most popular and flexible form of semantics
slide-4
SLIDE 4

Types of (Formal) Dynamic Semantics

  • Denotational Semantics: Abstract and elegant.
  • Each part of a program is associated with a denotation (math. object)
  • For example: a procedure is associated with a mathematical function
  • Axiomatic Semantics: Strongly related to program logic.
  • Gives meaning to phrases using logical axioms
  • The meaning is identical to the set of properties that can be proved
  • Operational Semantics: Describes how programs are executed
  • Related to interpretation and abstract machines
  • Most popular and flexible form of semantics

Dana Scott

slide-5
SLIDE 5

Types of (Formal) Dynamic Semantics

  • Denotational Semantics: Abstract and elegant.
  • Each part of a program is associated with a denotation (math. object)
  • For example: a procedure is associated with a mathematical function
  • Axiomatic Semantics: Strongly related to program logic.
  • Gives meaning to phrases using logical axioms
  • The meaning is identical to the set of properties that can be proved
  • Operational Semantics: Describes how programs are executed
  • Related to interpretation and abstract machines
  • Most popular and flexible form of semantics

Dana Scott Tony Hoare

slide-6
SLIDE 6

Types of (Formal) Dynamic Semantics

  • Denotational Semantics: Abstract and elegant.
  • Each part of a program is associated with a denotation (math. object)
  • For example: a procedure is associated with a mathematical function
  • Axiomatic Semantics: Strongly related to program logic.
  • Gives meaning to phrases using logical axioms
  • The meaning is identical to the set of properties that can be proved
  • Operational Semantics: Describes how programs are executed
  • Related to interpretation and abstract machines
  • Most popular and flexible form of semantics

Dana Scott Tony Hoare Bob Harper

slide-7
SLIDE 7

Operational Semantics

  • Many different styles
  • Natural semantics (or big-step semantics)
  • Structural operational semantics
  • Substructural operational semantics
  • Abstract machine (or small-step semantics)
  • We will use small-step semantics
  • Very general: can describe non-termination, concurrency, …
  • Low-level and elaborate
slide-8
SLIDE 8

Operational Semantics

  • Many different styles
  • Natural semantics (or big-step semantics)
  • Structural operational semantics
  • Substructural operational semantics
  • Abstract machine (or small-step semantics)
  • We will use small-step semantics
  • Very general: can describe non-termination, concurrency, …
  • Low-level and elaborate

Frank Pfenning

slide-9
SLIDE 9

Evaluating Expressions

slide-10
SLIDE 10

Continuations

Want to model a single evaluation step

e → e0

slide-11
SLIDE 11

Continuations

Want to model a single evaluation step For example: ((4 + 5) ∗ 10 + 2) → (9 ∗ 10 + 2)

e → e0

slide-12
SLIDE 12

Continuations

Want to model a single evaluation step For example: ((4 + 5) ∗ 10 + 2) → (9 ∗ 10 + 2)

e → e0

How can we find the right place at which to make the step?

slide-13
SLIDE 13

Continuations

Want to model a single evaluation step For example: ((4 + 5) ∗ 10 + 2) → (9 ∗ 10 + 2)

e → e0

How can we find the right place at which to make the step? Use a continuation K:

e B K

“Evaluate expression e and pass the result to K” The continuation has a ‘hole’ for the result value of e.

slide-14
SLIDE 14

Continuations

Want to model a single evaluation step For example: ((4 + 5) ∗ 10 + 2) → (9 ∗ 10 + 2)

e → e0

How can we find the right place at which to make the step? Use a continuation K:

e B K

“Evaluate expression e and pass the result to K” The continuation has a ‘hole’ for the result value of e. A stack of partial computations.

slide-15
SLIDE 15

Evaluation Rules: Addition

e1 + e2 B K − → e1 B (_ + e2 , K)

slide-16
SLIDE 16

Evaluation Rules: Addition

e1 + e2 B K − → e1 B (_ + e2 , K)

First evaluate e1.

slide-17
SLIDE 17

Evaluation Rules: Addition

e1 + e2 B K − → e1 B (_ + e2 , K)

First evaluate e1. Plug the result here.

slide-18
SLIDE 18

Evaluation Rules: Addition

e1 + e2 B K − → e1 B (_ + e2 , K)

First evaluate e1. Plug the result here.

c1 B (_ + e2 , K) − → e2 B (c1 + _ , K)

slide-19
SLIDE 19

Evaluation Rules: Addition

e1 + e2 B K − → e1 B (_ + e2 , K)

First evaluate e1. Plug the result here.

c1 B (_ + e2 , K) − → e2 B (c1 + _ , K)

e is a constant.

slide-20
SLIDE 20

Evaluation Rules: Addition

e1 + e2 B K − → e1 B (_ + e2 , K)

First evaluate e1. Plug the result here.

c1 B (_ + e2 , K) − → e2 B (c1 + _ , K)

e is a constant. Continuation is an addition.

slide-21
SLIDE 21

Evaluation Rules: Addition

e1 + e2 B K − → e1 B (_ + e2 , K)

First evaluate e1. Plug the result here.

c1 B (_ + e2 , K) − → e2 B (c1 + _ , K)

e is a constant. Continuation is an addition. Continue with evaluating e2.

slide-22
SLIDE 22

Evaluation Rules: Addition

e1 + e2 B K − → e1 B (_ + e2 , K)

First evaluate e1. Plug the result here.

c1 B (_ + e2 , K) − → e2 B (c1 + _ , K)

e is a constant. Continuation is an addition. Continue with evaluating e2. Plug the result here.

slide-23
SLIDE 23

Evaluation Rules: Addition

e1 + e2 B K − → e1 B (_ + e2 , K)

First evaluate e1. Plug the result here.

c1 B (_ + e2 , K) − → e2 B (c1 + _ , K)

e is a constant. Continuation is an addition. Continue with evaluating e2. Plug the result here. c2 B (c1 + _ , K) − → c B K (c = c1 + c2 mod 232)

slide-24
SLIDE 24

Evaluation Rules: Addition

e1 + e2 B K − → e1 B (_ + e2 , K)

First evaluate e1. Plug the result here.

c1 B (_ + e2 , K) − → e2 B (c1 + _ , K)

e is a constant. Continuation is an addition. Continue with evaluating e2. Plug the result here. Two constants c2 B (c1 + _ , K) − → c B K (c = c1 + c2 mod 232)

slide-25
SLIDE 25

Evaluation Rules: Addition

e1 + e2 B K − → e1 B (_ + e2 , K)

First evaluate e1. Plug the result here.

c1 B (_ + e2 , K) − → e2 B (c1 + _ , K)

e is a constant. Continuation is an addition. Continue with evaluating e2. Plug the result here. Two constants Actual addition. c2 B (c1 + _ , K) − → c B K (c = c1 + c2 mod 232)

slide-26
SLIDE 26

Evaluation Rules: Binary Operations

e1 e2 B K

  • !

e1 B (_ e2 , K) B B

  • B
  • !

B

  • c1 B (_ e2 , K)
  • !

e2 B (c1 _ , K) B B B

  • !

B

  • c2 B (c1 _ , K)
  • !

c B K (c = c1 c2 mod 232) Arithmetic operations are treated like addition Arithmetic is modulo 232 to match our x86 architecture

slide-27
SLIDE 27

Evaluation Rules: Binary Operations

e1 e2 B K

  • !

e1 B (_ e2 , K) B B

  • B
  • !

B

  • c1 B (_ e2 , K)
  • !

e2 B (c1 _ , K) B B B

  • !

B

  • c2 B (c1 _ , K)
  • !

c B K (c = c1 c2 mod 232) Arithmetic operations are treated like addition Arithmetic is modulo 232 to match our x86 architecture What about effects?

slide-28
SLIDE 28

Evaluation Rules: Binops with Effects

In case of an arithmetic exception: Abort the computation and
 report and error

e1 ↵ e2 B K

  • !

e1 B (_ ↵ e2 , K) B B ↵ B

  • !

B ↵ c1 B (_ ↵ e2 , K)

  • !

e2 B (c1 ↵ _ , K) B B ↵

  • !

↵ c2 B (c1 ↵ _ , K)

  • !

c B K (c = c1 ↵ c2) B ↵

  • !

↵ c2 B (c1 ↵ _ , K)

  • !

exception(arith) (c1 ↵ c2 undefined)

There is no rule for further evaluating an exception.

slide-29
SLIDE 29

Example Evaluation

((4 + 5) ⇤ 10) + 2 B ·

  • !

(4 + 5) ⇤ 10 B _ + 2

  • !

(4 + 5) ⇤ 10 B _ + 2

  • !

4 + 5 B _ ⇤ 10 , _ + 2

  • !

4 B _ + 5 , _ ⇤ 10 , _ + 2

  • !

5 B 4 + _ , _ ⇤ 10 , _ + 2

  • !

9 B _ ⇤ 10 , _ + 2

  • !

10 B 9 ⇤ _ , _ + 2

  • !

90 B _ + 2

  • !

2 B 90 + _

  • !

92 B ·

slide-30
SLIDE 30

Example Evaluation

((4 + 5) ⇤ 10) + 2 B ·

  • !

(4 + 5) ⇤ 10 B _ + 2

  • !

(4 + 5) ⇤ 10 B _ + 2

  • !

4 + 5 B _ ⇤ 10 , _ + 2

  • !

4 B _ + 5 , _ ⇤ 10 , _ + 2

  • !

5 B 4 + _ , _ ⇤ 10 , _ + 2

  • !

9 B _ ⇤ 10 , _ + 2

  • !

10 B 9 ⇤ _ , _ + 2

  • !

90 B _ + 2

  • !

2 B 90 + _

  • !

92 B ·

slide-31
SLIDE 31

Example Evaluation

((4 + 5) ⇤ 10) + 2 B ·

  • !

(4 + 5) ⇤ 10 B _ + 2

  • !

(4 + 5) ⇤ 10 B _ + 2

  • !

4 + 5 B _ ⇤ 10 , _ + 2

  • !

4 B _ + 5 , _ ⇤ 10 , _ + 2

  • !

5 B 4 + _ , _ ⇤ 10 , _ + 2

  • !

9 B _ ⇤ 10 , _ + 2

  • !

10 B 9 ⇤ _ , _ + 2

  • !

90 B _ + 2

  • !

2 B 90 + _

  • !

92 B ·

slide-32
SLIDE 32

Example Evaluation

((4 + 5) ⇤ 10) + 2 B ·

  • !

(4 + 5) ⇤ 10 B _ + 2

  • !

(4 + 5) ⇤ 10 B _ + 2

  • !

4 + 5 B _ ⇤ 10 , _ + 2

  • !

4 B _ + 5 , _ ⇤ 10 , _ + 2

  • !

5 B 4 + _ , _ ⇤ 10 , _ + 2

  • !

9 B _ ⇤ 10 , _ + 2

  • !

10 B 9 ⇤ _ , _ + 2

  • !

90 B _ + 2

  • !

2 B 90 + _

  • !

92 B ·

slide-33
SLIDE 33

Example Evaluation

((4 + 5) ⇤ 10) + 2 B ·

  • !

(4 + 5) ⇤ 10 B _ + 2

  • !

(4 + 5) ⇤ 10 B _ + 2

  • !

4 + 5 B _ ⇤ 10 , _ + 2

  • !

4 B _ + 5 , _ ⇤ 10 , _ + 2

  • !

5 B 4 + _ , _ ⇤ 10 , _ + 2

  • !

9 B _ ⇤ 10 , _ + 2

  • !

10 B 9 ⇤ _ , _ + 2

  • !

90 B _ + 2

  • !

2 B 90 + _

  • !

92 B ·

slide-34
SLIDE 34

Example Evaluation

((4 + 5) ⇤ 10) + 2 B ·

  • !

(4 + 5) ⇤ 10 B _ + 2

  • !

(4 + 5) ⇤ 10 B _ + 2

  • !

4 + 5 B _ ⇤ 10 , _ + 2

  • !

4 B _ + 5 , _ ⇤ 10 , _ + 2

  • !

5 B 4 + _ , _ ⇤ 10 , _ + 2

  • !

9 B _ ⇤ 10 , _ + 2

  • !

10 B 9 ⇤ _ , _ + 2

  • !

90 B _ + 2

  • !

2 B 90 + _

  • !

92 B ·

slide-35
SLIDE 35

Example Evaluation

((4 + 5) ⇤ 10) + 2 B ·

  • !

(4 + 5) ⇤ 10 B _ + 2

  • !

(4 + 5) ⇤ 10 B _ + 2

  • !

4 + 5 B _ ⇤ 10 , _ + 2

  • !

4 B _ + 5 , _ ⇤ 10 , _ + 2

  • !

5 B 4 + _ , _ ⇤ 10 , _ + 2

  • !

9 B _ ⇤ 10 , _ + 2

  • !

10 B 9 ⇤ _ , _ + 2

  • !

90 B _ + 2

  • !

2 B 90 + _

  • !

92 B ·

slide-36
SLIDE 36

Example Evaluation

((4 + 5) ⇤ 10) + 2 B ·

  • !

(4 + 5) ⇤ 10 B _ + 2

  • !

(4 + 5) ⇤ 10 B _ + 2

  • !

4 + 5 B _ ⇤ 10 , _ + 2

  • !

4 B _ + 5 , _ ⇤ 10 , _ + 2

  • !

5 B 4 + _ , _ ⇤ 10 , _ + 2

  • !

9 B _ ⇤ 10 , _ + 2

  • !

10 B 9 ⇤ _ , _ + 2

  • !

90 B _ + 2

  • !

2 B 90 + _

  • !

92 B ·

slide-37
SLIDE 37

Example Evaluation

((4 + 5) ⇤ 10) + 2 B ·

  • !

(4 + 5) ⇤ 10 B _ + 2

  • !

(4 + 5) ⇤ 10 B _ + 2

  • !

4 + 5 B _ ⇤ 10 , _ + 2

  • !

4 B _ + 5 , _ ⇤ 10 , _ + 2

  • !

5 B 4 + _ , _ ⇤ 10 , _ + 2

  • !

9 B _ ⇤ 10 , _ + 2

  • !

10 B 9 ⇤ _ , _ + 2

  • !

90 B _ + 2

  • !

2 B 90 + _

  • !

92 B ·

slide-38
SLIDE 38

Example Evaluation

((4 + 5) ⇤ 10) + 2 B ·

  • !

(4 + 5) ⇤ 10 B _ + 2

  • !

(4 + 5) ⇤ 10 B _ + 2

  • !

4 + 5 B _ ⇤ 10 , _ + 2

  • !

4 B _ + 5 , _ ⇤ 10 , _ + 2

  • !

5 B 4 + _ , _ ⇤ 10 , _ + 2

  • !

9 B _ ⇤ 10 , _ + 2

  • !

10 B 9 ⇤ _ , _ + 2

  • !

90 B _ + 2

  • !

2 B 90 + _

  • !

92 B ·

slide-39
SLIDE 39

Example Evaluation

((4 + 5) ⇤ 10) + 2 B ·

  • !

(4 + 5) ⇤ 10 B _ + 2

  • !

(4 + 5) ⇤ 10 B _ + 2

  • !

4 + 5 B _ ⇤ 10 , _ + 2

  • !

4 B _ + 5 , _ ⇤ 10 , _ + 2

  • !

5 B 4 + _ , _ ⇤ 10 , _ + 2

  • !

9 B _ ⇤ 10 , _ + 2

  • !

10 B 9 ⇤ _ , _ + 2

  • !

90 B _ + 2

  • !

2 B 90 + _

  • !

92 B ·

slide-40
SLIDE 40

Evaluation Rules: End of and Evaluation

c B ·

  • !

value(c)

If we reach a constant and the empty continuation then we stop

slide-41
SLIDE 41

Evaluation Rules: Boolean Expressions

True and false are also values

e1 && e2 B K

  • !

e1 B (_ && e2 , K) B B B

  • !

B false B (_ && e2 , K)

  • !

false B K B B B

  • !

B true B (_ && e2 , K)

  • !

e2 B K

(We could also use 1 and 0 but distinguishing helps detect errors.)

slide-42
SLIDE 42

Evaluation Rules: Boolean Expressions

True and false are also values

e1 && e2 B K

  • !

e1 B (_ && e2 , K) B B B

  • !

B false B (_ && e2 , K)

  • !

false B K B B B

  • !

B true B (_ && e2 , K)

  • !

e2 B K

Notice the short- cutting. (We could also use 1 and 0 but distinguishing helps detect errors.)

slide-43
SLIDE 43

Variables and Environments

How do we evaluate variable?

slide-44
SLIDE 44

Variables and Environments

x B K − → ? How do we evaluate variable?

slide-45
SLIDE 45

Variables and Environments

x B K − → ? How do we evaluate variable? Need to have a environment that maps variables to values

slide-46
SLIDE 46

Variables and Environments

x B K − → ? How do we evaluate variable?

η ::= · | η, x 7! v

Need to have a environment that maps variables to values

slide-47
SLIDE 47

Variables and Environments

x B K − → ? How do we evaluate variable?

η ::= · | η, x 7! v

Need to have a environment that maps variables to values The machine state consists now of an expression, a continuation, and an environment

slide-48
SLIDE 48

Variables and Environments

x B K − → ? How do we evaluate variable?

η ::= · | η, x 7! v

Need to have a environment that maps variables to values

η ` e B K

The machine state consists now of an expression, a continuation, and an environment

slide-49
SLIDE 49

Variables and Environments II

The rules we have seen so far just carry over

η ` e1 e2 B K

  • !

η ` e1 B (_ e2 , K) B B

`

  • B
  • !

` B

  • η ` c1 B (_ e2 , K)
  • !

η ` e2 B (c1 _ , K) B B ` B

  • !

` B

  • η ` c2 B (c1 _ , K)
  • !

η ` c B K (c = c1 c2 mod 232)

slide-50
SLIDE 50

Variables and Environments II

The rules we have seen so far just carry over

η ` e1 e2 B K

  • !

η ` e1 B (_ e2 , K) B B

`

  • B
  • !

` B

  • η ` c1 B (_ e2 , K)
  • !

η ` e2 B (c1 _ , K) B B ` B

  • !

` B

  • η ` c2 B (c1 _ , K)
  • !

η ` c B K (c = c1 c2 mod 232)

η ` x B K

  • !

η ` η(x) B K

Variables are simply looked up

slide-51
SLIDE 51

Variables and Environments II

The rules we have seen so far just carry over

η ` e1 e2 B K

  • !

η ` e1 B (_ e2 , K) B B

`

  • B
  • !

` B

  • η ` c1 B (_ e2 , K)
  • !

η ` e2 B (c1 _ , K) B B ` B

  • !

` B

  • η ` c2 B (c1 _ , K)
  • !

η ` c B K (c = c1 c2 mod 232)

η ` x B K

  • !

η ` η(x) B K

Variables are simply looked up We assume programs passed the semantic check and vars are always defined.

slide-52
SLIDE 52

Variables and Environments II

The rules we have seen so far just carry over

η ` e1 e2 B K

  • !

η ` e1 B (_ e2 , K) B B

`

  • B
  • !

` B

  • η ` c1 B (_ e2 , K)
  • !

η ` e2 B (c1 _ , K) B B ` B

  • !

` B

  • η ` c2 B (c1 _ , K)
  • !

η ` c B K (c = c1 c2 mod 232)

η ` x B K

  • !

η ` η(x) B K

Variables are simply looked up We assume programs passed the semantic check and vars are always defined. The environment never changes when evaluating expressions

slide-53
SLIDE 53

Executing Statements

slide-54
SLIDE 54

Executing Statements I

η ` s I K

Executions of statements don’t pass values to the continuation Statements have usually an effect on the environment Machine configurations:

slide-55
SLIDE 55

Executing Statements I

η ` s I K

Executions of statements don’t pass values to the continuation Statements have usually an effect on the environment Machine configurations: Continuations contain statements.

slide-56
SLIDE 56

Executing Statements I

η ` s I K

Executions of statements don’t pass values to the continuation Statements have usually an effect on the environment Machine configurations: Continuations contain statements. Sequences: η ` seq(s1, s2) I K

  • !

η ` s1 I (s2 , K) ` I

  • !

` I

slide-57
SLIDE 57

Executing Statements I

η ` s I K

Executions of statements don’t pass values to the continuation Statements have usually an effect on the environment Machine configurations: Continuations contain statements. Sequences: η ` seq(s1, s2) I K

  • !

η ` s1 I (s2 , K) ` I

  • !

` I Nops: `

1 2 I

  • !

`

1 I 2

η ` nop I (s , K)

  • !

η ` s I K

slide-58
SLIDE 58

Executing Statements I

η ` s I K

Executions of statements don’t pass values to the continuation Statements have usually an effect on the environment Machine configurations: Continuations contain statements. Sequences: η ` seq(s1, s2) I K

  • !

η ` s1 I (s2 , K) ` I

  • !

` I Nops: `

1 2 I

  • !

`

1 I 2

η ` nop I (s , K)

  • !

η ` s I K A terminating execution ends with a nop.

slide-59
SLIDE 59

Executing Statements II

Interaction with expressions is straightforward Assignments:

η ` assign(x, e) I K

  • !

η ` e B (assign(x, _) , K) ` B

  • !

7! ` I ` I

  • !

` B η ` v B (assign(x, _) , K)

  • !

η[x 7! v] ` nop I K

slide-60
SLIDE 60

Executing Statements II

Interaction with expressions is straightforward Assignments:

η ` assign(x, e) I K

  • !

η ` e B (assign(x, _) , K) ` B

  • !

7! ` I ` I

  • !

` B η ` v B (assign(x, _) , K)

  • !

η[x 7! v] ` nop I K

slide-61
SLIDE 61

Executing Statements II

Interaction with expressions is straightforward Assignments:

η ` assign(x, e) I K

  • !

η ` e B (assign(x, _) , K) ` B

  • !

7! ` I ` I

  • !

` B η ` v B (assign(x, _) , K)

  • !

η[x 7! v] ` nop I K

Update the environment with new mapping.

slide-62
SLIDE 62

Executing Statements III

Conditionals:

η ` if(e, s1, s2) I K

  • !

η ` e B (if(_, s1, s2) , K) ` B

  • !

` I ` I

  • !

` B η ` true B (if(_, s1, s2), K)

  • !

η ` s1 I K η ` false B (if( , s , s ), K)

  • !

η ` s I K ` B

  • !

` I η ` false B (if(_, s1, s2), K)

  • !

η ` s2 I K

slide-63
SLIDE 63

Executing Statements IV

Loops:

  • m?

η ` while(e, s) I K

  • !
slide-64
SLIDE 64

Executing Statements IV

Loops:

  • m?

η ` while(e, s) I K

  • !

while(e, s) ⌘ if(e, seq(s, while(e, s)), nop)

Not that the following statements are equivalent:

slide-65
SLIDE 65

Executing Statements IV

Loops:

  • m?

η ` while(e, s) I K

  • !

η ` while(e, s) I K

  • !

η ` if(e, seq(s, while(e, s)), nop) I K while(e, s) ⌘ if(e, seq(s, while(e, s)), nop) Not that the following statements are equivalent:

slide-66
SLIDE 66

Executing Statements IV

Loops:

  • m?

η ` while(e, s) I K

  • !

η ` while(e, s) I K

  • !

η ` if(e, seq(s, while(e, s)), nop) I K while(e, s) ⌘ if(e, seq(s, while(e, s)), nop) Not that the following statements are equivalent:

transitions s0

  • !

s1

  • !

s2

  • !

· · · without final states are just nop I · and except

Non-termination: We can make an infinite number of steps without reaching a final state

slide-67
SLIDE 67

Executing Statements V

Assertions: η ` assert(e) I K

  • !

η ` e B (assert(_), K) B I ` I

  • !

` B η ` true B (assert(_), K)

  • !

η ` nop I K B η ` true B (assert(_), K)

  • !

η ` nop I K η ` false B (assert(_), K)

  • !

exception(abort)

slide-68
SLIDE 68

Executing Statements V

Assertions: η ` assert(e) I K

  • !

η ` e B (assert(_), K) B I ` I

  • !

` B η ` true B (assert(_), K)

  • !

η ` nop I K B η ` true B (assert(_), K)

  • !

η ` nop I K η ` false B (assert(_), K)

  • !

exception(abort) η ` decl(x, τ, s) I K

  • !

η[x 7! nothing] ` s I K Declarations:

slide-69
SLIDE 69

Executing Statements V

Assertions: η ` assert(e) I K

  • !

η ` e B (assert(_), K) B I ` I

  • !

` B η ` true B (assert(_), K)

  • !

η ` nop I K B η ` true B (assert(_), K)

  • !

η ` nop I K η ` false B (assert(_), K)

  • !

exception(abort) η ` decl(x, τ, s) I K

  • !

η[x 7! nothing] ` s I K Declarations: If C0 had shadowing then we would have to save and restore the previous value of x.

slide-70
SLIDE 70

Executing Statements V

Assertions: η ` assert(e) I K

  • !

η ` e B (assert(_), K) B I ` I

  • !

` B η ` true B (assert(_), K)

  • !

η ` nop I K B η ` true B (assert(_), K)

  • !

η ` nop I K η ` false B (assert(_), K)

  • !

exception(abort) Final states:

  • !

just nop I · and · · · and exception(E), caused by a failing η ` decl(x, τ, s) I K

  • !

η[x 7! nothing] ` s I K Declarations: If C0 had shadowing then we would have to save and restore the previous value of x.

slide-71
SLIDE 71

Example: Infinite Loop

[x7!1] ` while(x > 0, s) I ·

  • !

[x7!1] ` if(x>0, seq(s, while(x>0, s)), nop) I ·

  • !

[x7!1] ` x > 0 B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` x B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 1 B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 0 B 1 > _; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` true B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` seq(s, while(x > 0, s)) I ·

  • !

[x7!1] ` assign(x, x + 1)) I while(x > 0, assign(x, x + 1))

  • !

[x7!1] ` x + 1 B assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` x B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B 1 + _; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 2 B assign(x, _)); while(x > 0, s)

  • !

[x7!2] ` nop I while(x > 0, s)

  • !

[x7!2] ` while(x > 0, s) I · · · ·

statement while(x > 0, assign(x, x + 1)) execution, we obtion the following execution; and η = [x7!1]. execution; where s ⌘

slide-72
SLIDE 72

Example: Infinite Loop

[x7!1] ` while(x > 0, s) I ·

  • !

[x7!1] ` if(x>0, seq(s, while(x>0, s)), nop) I ·

  • !

[x7!1] ` x > 0 B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` x B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 1 B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 0 B 1 > _; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` true B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` seq(s, while(x > 0, s)) I ·

  • !

[x7!1] ` assign(x, x + 1)) I while(x > 0, assign(x, x + 1))

  • !

[x7!1] ` x + 1 B assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` x B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B 1 + _; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 2 B assign(x, _)); while(x > 0, s)

  • !

[x7!2] ` nop I while(x > 0, s)

  • !

[x7!2] ` while(x > 0, s) I · · · ·

statement while(x > 0, assign(x, x + 1)) execution, we obtion the following execution; and η = [x7!1]. execution; where s ⌘

slide-73
SLIDE 73

Example: Infinite Loop

[x7!1] ` while(x > 0, s) I ·

  • !

[x7!1] ` if(x>0, seq(s, while(x>0, s)), nop) I ·

  • !

[x7!1] ` x > 0 B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` x B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 1 B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 0 B 1 > _; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` true B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` seq(s, while(x > 0, s)) I ·

  • !

[x7!1] ` assign(x, x + 1)) I while(x > 0, assign(x, x + 1))

  • !

[x7!1] ` x + 1 B assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` x B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B 1 + _; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 2 B assign(x, _)); while(x > 0, s)

  • !

[x7!2] ` nop I while(x > 0, s)

  • !

[x7!2] ` while(x > 0, s) I · · · ·

statement while(x > 0, assign(x, x + 1)) execution, we obtion the following execution; and η = [x7!1]. execution; where s ⌘

slide-74
SLIDE 74

Example: Infinite Loop

[x7!1] ` while(x > 0, s) I ·

  • !

[x7!1] ` if(x>0, seq(s, while(x>0, s)), nop) I ·

  • !

[x7!1] ` x > 0 B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` x B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 1 B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 0 B 1 > _; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` true B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` seq(s, while(x > 0, s)) I ·

  • !

[x7!1] ` assign(x, x + 1)) I while(x > 0, assign(x, x + 1))

  • !

[x7!1] ` x + 1 B assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` x B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B 1 + _; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 2 B assign(x, _)); while(x > 0, s)

  • !

[x7!2] ` nop I while(x > 0, s)

  • !

[x7!2] ` while(x > 0, s) I · · · ·

statement while(x > 0, assign(x, x + 1)) execution, we obtion the following execution; and η = [x7!1]. execution; where s ⌘

slide-75
SLIDE 75

Example: Infinite Loop

[x7!1] ` while(x > 0, s) I ·

  • !

[x7!1] ` if(x>0, seq(s, while(x>0, s)), nop) I ·

  • !

[x7!1] ` x > 0 B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` x B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 1 B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 0 B 1 > _; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` true B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` seq(s, while(x > 0, s)) I ·

  • !

[x7!1] ` assign(x, x + 1)) I while(x > 0, assign(x, x + 1))

  • !

[x7!1] ` x + 1 B assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` x B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B 1 + _; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 2 B assign(x, _)); while(x > 0, s)

  • !

[x7!2] ` nop I while(x > 0, s)

  • !

[x7!2] ` while(x > 0, s) I · · · ·

statement while(x > 0, assign(x, x + 1)) execution, we obtion the following execution; and η = [x7!1]. execution; where s ⌘

slide-76
SLIDE 76

Example: Infinite Loop

[x7!1] ` while(x > 0, s) I ·

  • !

[x7!1] ` if(x>0, seq(s, while(x>0, s)), nop) I ·

  • !

[x7!1] ` x > 0 B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` x B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 1 B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 0 B 1 > _; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` true B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` seq(s, while(x > 0, s)) I ·

  • !

[x7!1] ` assign(x, x + 1)) I while(x > 0, assign(x, x + 1))

  • !

[x7!1] ` x + 1 B assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` x B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B 1 + _; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 2 B assign(x, _)); while(x > 0, s)

  • !

[x7!2] ` nop I while(x > 0, s)

  • !

[x7!2] ` while(x > 0, s) I · · · ·

statement while(x > 0, assign(x, x + 1)) execution, we obtion the following execution; and η = [x7!1]. execution; where s ⌘

slide-77
SLIDE 77

Example: Infinite Loop

[x7!1] ` while(x > 0, s) I ·

  • !

[x7!1] ` if(x>0, seq(s, while(x>0, s)), nop) I ·

  • !

[x7!1] ` x > 0 B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` x B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 1 B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 0 B 1 > _; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` true B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` seq(s, while(x > 0, s)) I ·

  • !

[x7!1] ` assign(x, x + 1)) I while(x > 0, assign(x, x + 1))

  • !

[x7!1] ` x + 1 B assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` x B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B 1 + _; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 2 B assign(x, _)); while(x > 0, s)

  • !

[x7!2] ` nop I while(x > 0, s)

  • !

[x7!2] ` while(x > 0, s) I · · · ·

statement while(x > 0, assign(x, x + 1)) execution, we obtion the following execution; and η = [x7!1]. execution; where s ⌘

slide-78
SLIDE 78

Example: Infinite Loop

[x7!1] ` while(x > 0, s) I ·

  • !

[x7!1] ` if(x>0, seq(s, while(x>0, s)), nop) I ·

  • !

[x7!1] ` x > 0 B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` x B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 1 B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 0 B 1 > _; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` true B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` seq(s, while(x > 0, s)) I ·

  • !

[x7!1] ` assign(x, x + 1)) I while(x > 0, assign(x, x + 1))

  • !

[x7!1] ` x + 1 B assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` x B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B 1 + _; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 2 B assign(x, _)); while(x > 0, s)

  • !

[x7!2] ` nop I while(x > 0, s)

  • !

[x7!2] ` while(x > 0, s) I · · · ·

statement while(x > 0, assign(x, x + 1)) execution, we obtion the following execution; and η = [x7!1]. execution; where s ⌘

slide-79
SLIDE 79

Example: Infinite Loop

[x7!1] ` while(x > 0, s) I ·

  • !

[x7!1] ` if(x>0, seq(s, while(x>0, s)), nop) I ·

  • !

[x7!1] ` x > 0 B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` x B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 1 B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 0 B 1 > _; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` true B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` seq(s, while(x > 0, s)) I ·

  • !

[x7!1] ` assign(x, x + 1)) I while(x > 0, assign(x, x + 1))

  • !

[x7!1] ` x + 1 B assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` x B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B 1 + _; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 2 B assign(x, _)); while(x > 0, s)

  • !

[x7!2] ` nop I while(x > 0, s)

  • !

[x7!2] ` while(x > 0, s) I · · · ·

statement while(x > 0, assign(x, x + 1)) execution, we obtion the following execution; and η = [x7!1]. execution; where s ⌘

slide-80
SLIDE 80

Example: Infinite Loop

[x7!1] ` while(x > 0, s) I ·

  • !

[x7!1] ` if(x>0, seq(s, while(x>0, s)), nop) I ·

  • !

[x7!1] ` x > 0 B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` x B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 1 B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 0 B 1 > _; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` true B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` seq(s, while(x > 0, s)) I ·

  • !

[x7!1] ` assign(x, x + 1)) I while(x > 0, assign(x, x + 1))

  • !

[x7!1] ` x + 1 B assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` x B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B 1 + _; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 2 B assign(x, _)); while(x > 0, s)

  • !

[x7!2] ` nop I while(x > 0, s)

  • !

[x7!2] ` while(x > 0, s) I · · · ·

statement while(x > 0, assign(x, x + 1)) execution, we obtion the following execution; and η = [x7!1]. execution; where s ⌘

slide-81
SLIDE 81

Example: Infinite Loop

[x7!1] ` while(x > 0, s) I ·

  • !

[x7!1] ` if(x>0, seq(s, while(x>0, s)), nop) I ·

  • !

[x7!1] ` x > 0 B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` x B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 1 B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 0 B 1 > _; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` true B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` seq(s, while(x > 0, s)) I ·

  • !

[x7!1] ` assign(x, x + 1)) I while(x > 0, assign(x, x + 1))

  • !

[x7!1] ` x + 1 B assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` x B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B 1 + _; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 2 B assign(x, _)); while(x > 0, s)

  • !

[x7!2] ` nop I while(x > 0, s)

  • !

[x7!2] ` while(x > 0, s) I · · · ·

statement while(x > 0, assign(x, x + 1)) execution, we obtion the following execution; and η = [x7!1]. execution; where s ⌘

slide-82
SLIDE 82

Example: Infinite Loop

[x7!1] ` while(x > 0, s) I ·

  • !

[x7!1] ` if(x>0, seq(s, while(x>0, s)), nop) I ·

  • !

[x7!1] ` x > 0 B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` x B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 1 B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 0 B 1 > _; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` true B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` seq(s, while(x > 0, s)) I ·

  • !

[x7!1] ` assign(x, x + 1)) I while(x > 0, assign(x, x + 1))

  • !

[x7!1] ` x + 1 B assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` x B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B 1 + _; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 2 B assign(x, _)); while(x > 0, s)

  • !

[x7!2] ` nop I while(x > 0, s)

  • !

[x7!2] ` while(x > 0, s) I · · · ·

statement while(x > 0, assign(x, x + 1)) execution, we obtion the following execution; and η = [x7!1]. execution; where s ⌘

slide-83
SLIDE 83

Example: Infinite Loop

[x7!1] ` while(x > 0, s) I ·

  • !

[x7!1] ` if(x>0, seq(s, while(x>0, s)), nop) I ·

  • !

[x7!1] ` x > 0 B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` x B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 1 B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 0 B 1 > _; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` true B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` seq(s, while(x > 0, s)) I ·

  • !

[x7!1] ` assign(x, x + 1)) I while(x > 0, assign(x, x + 1))

  • !

[x7!1] ` x + 1 B assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` x B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B 1 + _; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 2 B assign(x, _)); while(x > 0, s)

  • !

[x7!2] ` nop I while(x > 0, s)

  • !

[x7!2] ` while(x > 0, s) I · · · ·

statement while(x > 0, assign(x, x + 1)) execution, we obtion the following execution; and η = [x7!1]. execution; where s ⌘

slide-84
SLIDE 84

Example: Infinite Loop

[x7!1] ` while(x > 0, s) I ·

  • !

[x7!1] ` if(x>0, seq(s, while(x>0, s)), nop) I ·

  • !

[x7!1] ` x > 0 B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` x B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 1 B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 0 B 1 > _; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` true B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` seq(s, while(x > 0, s)) I ·

  • !

[x7!1] ` assign(x, x + 1)) I while(x > 0, assign(x, x + 1))

  • !

[x7!1] ` x + 1 B assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` x B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B 1 + _; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 2 B assign(x, _)); while(x > 0, s)

  • !

[x7!2] ` nop I while(x > 0, s)

  • !

[x7!2] ` while(x > 0, s) I · · · ·

statement while(x > 0, assign(x, x + 1)) execution, we obtion the following execution; and η = [x7!1]. execution; where s ⌘

slide-85
SLIDE 85

Example: Infinite Loop

[x7!1] ` while(x > 0, s) I ·

  • !

[x7!1] ` if(x>0, seq(s, while(x>0, s)), nop) I ·

  • !

[x7!1] ` x > 0 B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` x B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 1 B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 0 B 1 > _; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` true B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` seq(s, while(x > 0, s)) I ·

  • !

[x7!1] ` assign(x, x + 1)) I while(x > 0, assign(x, x + 1))

  • !

[x7!1] ` x + 1 B assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` x B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B 1 + _; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 2 B assign(x, _)); while(x > 0, s)

  • !

[x7!2] ` nop I while(x > 0, s)

  • !

[x7!2] ` while(x > 0, s) I · · · ·

statement while(x > 0, assign(x, x + 1)) execution, we obtion the following execution; and η = [x7!1]. execution; where s ⌘

slide-86
SLIDE 86

Example: Infinite Loop

[x7!1] ` while(x > 0, s) I ·

  • !

[x7!1] ` if(x>0, seq(s, while(x>0, s)), nop) I ·

  • !

[x7!1] ` x > 0 B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` x B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 1 B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 0 B 1 > _; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` true B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` seq(s, while(x > 0, s)) I ·

  • !

[x7!1] ` assign(x, x + 1)) I while(x > 0, assign(x, x + 1))

  • !

[x7!1] ` x + 1 B assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` x B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B 1 + _; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 2 B assign(x, _)); while(x > 0, s)

  • !

[x7!2] ` nop I while(x > 0, s)

  • !

[x7!2] ` while(x > 0, s) I · · · ·

statement while(x > 0, assign(x, x + 1)) execution, we obtion the following execution; and η = [x7!1]. execution; where s ⌘

slide-87
SLIDE 87

Example: Infinite Loop

[x7!1] ` while(x > 0, s) I ·

  • !

[x7!1] ` if(x>0, seq(s, while(x>0, s)), nop) I ·

  • !

[x7!1] ` x > 0 B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` x B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 1 B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 0 B 1 > _; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` true B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` seq(s, while(x > 0, s)) I ·

  • !

[x7!1] ` assign(x, x + 1)) I while(x > 0, assign(x, x + 1))

  • !

[x7!1] ` x + 1 B assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` x B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B 1 + _; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 2 B assign(x, _)); while(x > 0, s)

  • !

[x7!2] ` nop I while(x > 0, s)

  • !

[x7!2] ` while(x > 0, s) I · · · ·

statement while(x > 0, assign(x, x + 1)) execution, we obtion the following execution; and η = [x7!1]. execution; where s ⌘

slide-88
SLIDE 88

Example: Infinite Loop

[x7!1] ` while(x > 0, s) I ·

  • !

[x7!1] ` if(x>0, seq(s, while(x>0, s)), nop) I ·

  • !

[x7!1] ` x > 0 B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` x B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 1 B _ > 0; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` 0 B 1 > _; if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` true B if(_, seq(s, while(x > 0, s)), nop)

  • !

[x7!1] ` seq(s, while(x > 0, s)) I ·

  • !

[x7!1] ` assign(x, x + 1)) I while(x > 0, assign(x, x + 1))

  • !

[x7!1] ` x + 1 B assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` x B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B _ + 1; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 1 B 1 + _; assign(x, _)); while(x > 0, s)

  • !

[x7!1] ` 2 B assign(x, _)); while(x > 0, s)

  • !

[x7!2] ` nop I while(x > 0, s)

  • !

[x7!2] ` while(x > 0, s) I · · · ·

statement while(x > 0, assign(x, x + 1)) execution, we obtion the following execution; and η = [x7!1]. execution; where s ⌘

slide-89
SLIDE 89

Functions

slide-90
SLIDE 90

Function Calls

What needs to happen at a function call?

slide-91
SLIDE 91

Function Calls

What needs to happen at a function call?

  • Evaluate the arguments in left-to-right order
slide-92
SLIDE 92

Function Calls

What needs to happen at a function call?

  • Evaluate the arguments in left-to-right order
  • Save the environment of the caller to continue the execution after the

function call

slide-93
SLIDE 93

Function Calls

What needs to happen at a function call?

  • Evaluate the arguments in left-to-right order
  • Save the environment of the caller to continue the execution after the

function call

  • Save the continuation of the callee
slide-94
SLIDE 94

Function Calls

What needs to happen at a function call?

  • Evaluate the arguments in left-to-right order
  • Save the environment of the caller to continue the execution after the

function call

  • Save the continuation of the callee
  • Execute the body in a new environment that maps the formal

parameters to the argument values

slide-95
SLIDE 95

Function Calls

What needs to happen at a function call?

  • Evaluate the arguments in left-to-right order
  • Save the environment of the caller to continue the execution after the

function call

  • Save the continuation of the callee
  • Execute the body in a new environment that maps the formal

parameters to the argument values

  • Pass the return value the the environment of the caller
slide-96
SLIDE 96

Call Stack

We need to keep track of continuations and environment in stack frames Call stack:

S ::= · | S , hη, Ki

slide-97
SLIDE 97

Call Stack

We need to keep track of continuations and environment in stack frames Call stack: Environment

S ::= · | S , hη, Ki

slide-98
SLIDE 98

Call Stack

We need to keep track of continuations and environment in stack frames Call stack: Environment Continuation

S ::= · | S , hη, Ki

slide-99
SLIDE 99

Call Stack

We need to keep track of continuations and environment in stack frames Call stack: Environment Continuation

S ::= · | S , hη, Ki

Configurations:

S ; η ` e B K I ` B S ; η ` s I K

Evaluation Execution

slide-100
SLIDE 100

Call Stack

We need to keep track of continuations and environment in stack frames Call stack: Environment Continuation

S ::= · | S , hη, Ki

Configurations:

S ; η ` e B K I ` B S ; η ` s I K

Evaluation Execution Existing rules can be lifted to the new configurations by
 passing through the call stack

slide-101
SLIDE 101

Rules for Function Calls

We only show the special case of 0 and 2 arguments

slide-102
SLIDE 102

Rules for Function Calls

We only show the special case of 0 and 2 arguments n args is similar.

slide-103
SLIDE 103

Rules for Function Calls

We only show the special case of 0 and 2 arguments n args is similar. S ; η ` f( ) B K

  • !

(S , hη, Ki) ; · ` s I · (given that is i · ` I · (given that f is defined as f( ){s}) No arguments:

slide-104
SLIDE 104

Rules for Function Calls

We only show the special case of 0 and 2 arguments n args is similar. Store callee’s stack frame S ; η ` f( ) B K

  • !

(S , hη, Ki) ; · ` s I · (given that is i · ` I · (given that f is defined as f( ){s}) No arguments:

slide-105
SLIDE 105

Rules for Function Calls

We only show the special case of 0 and 2 arguments n args is similar. Store callee’s stack frame Evaluate s in empty environment. S ; η ` f( ) B K

  • !

(S , hη, Ki) ; · ` s I · (given that is i · ` I · (given that f is defined as f( ){s}) No arguments:

slide-106
SLIDE 106

Rules for Function Calls

We only show the special case of 0 and 2 arguments n args is similar. Store callee’s stack frame Evaluate s in empty environment. S ; η ` f( ) B K

  • !

(S , hη, Ki) ; · ` s I · (given that is i · ` I · (given that f is defined as f( ){s}) No arguments: S ; η ` f(e1, e2) B K

  • !

S ; η ` e1 B (f(_, e2) , K) B B `

1 2 B

  • !

`

1 B 2

S ; η ` c1 B (f(_, e2) , K)

  • !

S ; η ` e2 B (f(c1, _) , K) B Two arguments:

slide-107
SLIDE 107

Rules for Function Calls

We only show the special case of 0 and 2 arguments n args is similar.

`

1 B 2

  • !

`

2 B 1

S ; η ` c2 B (f(c1, _) , K)

  • !

(S , hη, Ki) ; [x1 7! c1, x2 7! c2] ` s I · (given that is defined as h i 7! 7! ` I · (given that f is defined as f(x1, x2){s})

Store callee’s stack frame Evaluate s in empty environment. S ; η ` f( ) B K

  • !

(S , hη, Ki) ; · ` s I · (given that is i · ` I · (given that f is defined as f( ){s}) No arguments: S ; η ` f(e1, e2) B K

  • !

S ; η ` e1 B (f(_, e2) , K) B B `

1 2 B

  • !

`

1 B 2

S ; η ` c1 B (f(_, e2) , K)

  • !

S ; η ` e2 B (f(c1, _) , K) B Two arguments:

slide-108
SLIDE 108

Rules for Returns

Need to restore continuation and environment and pass return value

S ; η ` return(e) I K

  • !

S ; η ` e B (return(_) , K) B B S ; η ` return(e) I K

  • !

S ; η ` e B (return( S , hη0, K0i ; η ` v B (return(_) , K)

  • !

S ; η0 ` v B K0

slide-109
SLIDE 109

Rules for Returns

Need to restore continuation and environment and pass return value

S ; η ` return(e) I K

  • !

S ; η ` e B (return(_) , K) B B S ; η ` return(e) I K

  • !

S ; η ` e B (return( S , hη0, K0i ; η ` v B (return(_) , K)

  • !

S ; η0 ` v B K0

slide-110
SLIDE 110

Rules for Returns

Need to restore continuation and environment and pass return value

S ; η ` return(e) I K

  • !

S ; η ` e B (return(_) , K) B B S ; η ` return(e) I K

  • !

S ; η ` e B (return( S , hη0, K0i ; η ` v B (return(_) , K)

  • !

S ; η0 ` v B K0

slide-111
SLIDE 111

Rules for Returns

Need to restore continuation and environment and pass return value

S ; η ` return(e) I K

  • !

S ; η ` e B (return(_) , K) B B S ; η ` return(e) I K

  • !

S ; η ` e B (return( S , hη0, K0i ; η ` v B (return(_) , K)

  • !

S ; η0 ` v B K0

Special case: returning void

S , hη0, K0i ; η ` nop I ·

  • !

S ; η0 ` nothing B K0

slide-112
SLIDE 112

Rules for Returns

Need to restore continuation and environment and pass return value Will only be reached by functions without return.

S ; η ` return(e) I K

  • !

S ; η ` e B (return(_) , K) B B S ; η ` return(e) I K

  • !

S ; η ` e B (return( S , hη0, K0i ; η ` v B (return(_) , K)

  • !

S ; η0 ` v B K0

Special case: returning void

S , hη0, K0i ; η ` nop I ·

  • !

S ; η0 ` nothing B K0

slide-113
SLIDE 113

Rules for Returns

Need to restore continuation and environment and pass return value Will only be reached by functions without return.

S ; η ` return(e) I K

  • !

S ; η ` e B (return(_) , K) B B S ; η ` return(e) I K

  • !

S ; η ` e B (return( S , hη0, K0i ; η ` v B (return(_) , K)

  • !

S ; η0 ` v B K0

Special case: returning void

S , hη0, K0i ; η ` nop I ·

  • !

S ; η0 ` nothing B K0

Dummy value

slide-114
SLIDE 114

Rules for Returns

Need to restore continuation and environment and pass return value Will only be reached by functions without return.

S ; η ` return(e) I K

  • !

S ; η ` e B (return(_) , K) B B S ; η ` return(e) I K

  • !

S ; η ` e B (return( S , hη0, K0i ; η ` v B (return(_) , K)

  • !

S ; η0 ` v B K0

Special case: returning void

S , hη0, K0i ; η ` nop I ·

  • !

S ; η0 ` nothing B K0

Dummy value Alternative: elaborate each function that returns void with
 return(nothing) statements.

slide-115
SLIDE 115

Execution of the Main Function

How can we execute a program?

slide-116
SLIDE 116

Execution of the Main Function

How can we execute a program?

· ; · ` main( ) B · B (initial state) final state

slide-117
SLIDE 117

Execution of the Main Function

How can we execute a program?

· ; · ` main( ) B · B (initial state) final state · · ` B · ; η ` c B ·

  • !

value(c) (final state)

slide-118
SLIDE 118

Statics, Dynamics, and Safety

slide-119
SLIDE 119

Overview of Machine States (Configurations)

ST

  • S ; η ` e B K

– Evaluating the expression e with the continuation K

  • S ; η ` s I K

– Evaluating the statement s with the continuation K

  • value(c)

– Final state, return a value

  • exception(E)

– Final state, report an error

slide-120
SLIDE 120

Overview of Machine States (Configurations)

ST

  • S ; η ` e B K

– Evaluating the expression e with the continuation K

  • S ; η ` s I K

– Evaluating the statement s with the continuation K

  • value(c)

– Final state, return a value

  • exception(E)

– Final state, report an error What do we expect from the transitions?

slide-121
SLIDE 121

Overview of Machine States (Configurations)

ST

  • S ; η ` e B K

– Evaluating the expression e with the continuation K

  • S ; η ` s I K

– Evaluating the statement s with the continuation K

  • value(c)

– Final state, return a value

  • exception(E)

– Final state, report an error What do we expect from the transitions? There shouldn’t be more steps after reaching a final state

slide-122
SLIDE 122

Overview of Machine States (Configurations)

ST

  • S ; η ` e B K

– Evaluating the expression e with the continuation K

  • S ; η ` s I K

– Evaluating the statement s with the continuation K

  • value(c)

– Final state, return a value

  • exception(E)

– Final state, report an error What do we expect from the transitions? There shouldn’t be more steps after reaching a final state The language should be deterministic: there at most one transition
 per state

slide-123
SLIDE 123

Progress

There are many non-final states that don’t have transitions, e.g.

slide-124
SLIDE 124

Progress

There are many non-final states that don’t have transitions, e.g. transition: S; η ` 42 B (if(_, s1, s2); K) states are called stuck – it is literally

slide-125
SLIDE 125

Progress

There are many non-final states that don’t have transitions, e.g. transition: S; η ` 42 B (if(_, s1, s2); K) states are called stuck – it is literally and ·; · ` nop I · is what the program

slide-126
SLIDE 126

Progress

Stuck states. There are many non-final states that don’t have transitions, e.g. transition: S; η ` 42 B (if(_, s1, s2); K) states are called stuck – it is literally and ·; · ` nop I · is what the program

slide-127
SLIDE 127

Progress

Stuck states. There are many non-final states that don’t have transitions, e.g. transition: S; η ` 42 B (if(_, s1, s2); K) states are called stuck – it is literally and ·; · ` nop I · is what the program The behavior of these states is undefined.

slide-128
SLIDE 128

Progress

Stuck states. There are many non-final states that don’t have transitions, e.g. transition: S; η ` 42 B (if(_, s1, s2); K) states are called stuck – it is literally and ·; · ` nop I · is what the program The behavior of these states is undefined. Programs that are well-defined according to the static semantics
 should be free of undefined behavior. Central relationship between static and dynamic semantics:

slide-129
SLIDE 129

Progress

Stuck states. There are many non-final states that don’t have transitions, e.g. transition: S; η ` 42 B (if(_, s1, s2); K) states are called stuck – it is literally and ·; · ` nop I · is what the program The behavior of these states is undefined. Programs that are well-defined according to the static semantics
 should be free of undefined behavior. Central relationship between static and dynamic semantics:

Theorem 1 (No undefined behavior) If a program passes all the static semantics, and ·; · ` main( )

  • !

ST 1

  • !

. . .

  • !

ST n then either ST n is a final state or else ST n is not-stuck because there exists a state ST 0 such that ST n

  • !

ST 0.

slide-130
SLIDE 130

Progress

Stuck states. There are many non-final states that don’t have transitions, e.g. transition: S; η ` 42 B (if(_, s1, s2); K) states are called stuck – it is literally and ·; · ` nop I · is what the program Well-typed programs don’t go wrong! The behavior of these states is undefined. Programs that are well-defined according to the static semantics
 should be free of undefined behavior. Central relationship between static and dynamic semantics:

Theorem 1 (No undefined behavior) If a program passes all the static semantics, and ·; · ` main( )

  • !

ST 1

  • !

. . .

  • !

ST n then either ST n is a final state or else ST n is not-stuck because there exists a state ST 0 such that ST n

  • !

ST 0.

slide-131
SLIDE 131

Progress

Stuck states. There are many non-final states that don’t have transitions, e.g. transition: S; η ` 42 B (if(_, s1, s2); K) states are called stuck – it is literally and ·; · ` nop I · is what the program Well-typed programs don’t go wrong! The behavior of these states is undefined. Programs that are well-defined according to the static semantics
 should be free of undefined behavior. Central relationship between static and dynamic semantics:

Theorem 1 (No undefined behavior) If a program passes all the static semantics, and ·; · ` main( )

  • !

ST 1

  • !

. . .

  • !

ST n then either ST n is a final state or else ST n is not-stuck because there exists a state ST 0 such that ST n

  • !

ST 0.

How to prove this?

slide-132
SLIDE 132

Progress

Stuck states. There are many non-final states that don’t have transitions, e.g. transition: S; η ` 42 B (if(_, s1, s2); K) states are called stuck – it is literally and ·; · ` nop I · is what the program Well-typed programs don’t go wrong! The behavior of these states is undefined. Programs that are well-defined according to the static semantics
 should be free of undefined behavior. Central relationship between static and dynamic semantics:

Theorem 1 (No undefined behavior) If a program passes all the static semantics, and ·; · ` main( )

  • !

ST 1

  • !

. . .

  • !

ST n then either ST n is a final state or else ST n is not-stuck because there exists a state ST 0 such that ST n

  • !

ST 0.

How to prove this? 15-312 next term.

slide-133
SLIDE 133

Summary I

Expressions e ::= c | e1 e2 | true | false | e1 && e2 | x | f(e1, e2) | f( ) Statements s ::= nop | seq(s1, s2) | assign(x, e) | decl(x, τ, s) | if(e, s1, s2) | while(e, s) | return(e) | assert(e) Values v ::= c | true | false | nothing Environments η ::= · | η, x 7! c Stacks S ::= · | S , hη, Ki

  • Cont. frames

φ ::= _ e | c _ | _ && e | f(_, e) | f(c, _) | s | assign(x, _) | if(_, s1, s2) | return(_) | assert(_) Continuations K ::= · | φ , K Exceptions E ::= arith | abort | mem

slide-134
SLIDE 134

Summary I

Expressions e ::= c | e1 e2 | true | false | e1 && e2 | x | f(e1, e2) | f( ) Statements s ::= nop | seq(s1, s2) | assign(x, e) | decl(x, τ, s) | if(e, s1, s2) | while(e, s) | return(e) | assert(e) Values v ::= c | true | false | nothing Environments η ::= · | η, x 7! c Stacks S ::= · | S , hη, Ki

  • Cont. frames

φ ::= _ e | c _ | _ && e | f(_, e) | f(c, _) | s | assign(x, _) | if(_, s1, s2) | return(_) | assert(_) Continuations K ::= · | φ , K Exceptions E ::= arith | abort | mem

All ops.

slide-135
SLIDE 135

Summary: Expressions

S ; η ` e1 e2 B K

  • !

S ; η ` e1 B (_ e2 , K) S ; η ` c1 B (_ e2 , K)

  • !

S ; η ` e2 B (c1 _ , K) S ; η ` c2 B (c1 _ , K)

  • !

S ; η ` c B K (c = c1 c2) S ; η ` c2 B (c1 _ , K)

  • !

exception(arith) (c1 c2 undefined) S ; η ` e1 && e2 B K

  • !

S ; η ` e1 B (_ && e2 , K) S ; η ` false B (_ && e2 , K)

  • !

S ; η ` false B K S ; η ` true B (_ && e2 , K)

  • !

S ; η ` e2 B K S ; η ` x B K

  • !

S ; η ` η(x) B K

slide-136
SLIDE 136

Summary: Statements

S ; η ` nop I (s , K)

  • !

S ; η ` s I K S ; η ` assign(x, e) I K

  • !

S ; η ` e B (assign(x, _) , K) S ; η ` c B (assign(x, _) , K)

  • !

S ; η[x 7! c] ` nop I K S ; η ` decl(x, τ, s) I K

  • !

S ; η[x 7! nothing] ` s I K S ; η ` assert(e) I K

  • !

S ; η ` e B (assert(_) , K) S ; η ` true B (assert(_) , K)

  • !

S ; η ` nop I K S ; η ` false B (assert(_) , K)

  • !

exception(abort) S ; η ` if(e, s1, s2) I K

  • !

S ; η ` e B (if(_, s1, s2) , K) S ; η ` true B (if(_, s1, s2), K)

  • !

S ; η ` s1 I K S ; η ` false B (if(_, s1, s2), K)

  • !

S ; η ` s2 I K S ; η ` while(e, s) I K

  • !

S ; η ` if(e, seq(s, while(e, s)), nop) I K

slide-137
SLIDE 137

Summary: Functions

`

  • !

` S ; η ` f(e1, e2) B K

  • !

S ; η ` e1 B (f(_, e2) , K) S ; η ` c1 B (f(_, e2) , K)

  • !

S ; η ` e2 B (f(c1, _) , K) S ; η ` c2 B (f(c1, _) , K)

  • !

(S , hη, Ki) ; [x1 7! c1, x2 7! c2] ` s I · (given that f is defined as f(x1, x2){s}) S ; η ` f( ) B K

  • !

(S , hη, Ki) ; · ` s I · (given that f is defined as f( ){s}) S ; η ` return(e) I K

  • !

S ; η ` e B (return(_) , K) (S , hη0, K0i) ; η ` v B (return(_) , K)

  • !

S ; η0 ` v B K0 · ; η ` c B (return(_) , K)

  • !

value(c)