Example Evaluation ((4 + 5) ⇤ 10) + 2 · B (4 + 5) ⇤ 10 _ + 2 � ! B (4 + 5) ⇤ 10 _ + 2 � ! B 4 + 5 _ ⇤ 10 , _ + 2 � ! B 4 _ + 5 , _ ⇤ 10 , _ + 2 � ! B 5 4 + _ , _ ⇤ 10 , _ + 2 � ! B 9 _ ⇤ 10 , _ + 2 � ! B 10 9 ⇤ _ , _ + 2 � ! B 90 _ + 2 � ! B 2 90 + _ � ! B 92 · � ! B
Example Evaluation ((4 + 5) ⇤ 10) + 2 · B (4 + 5) ⇤ 10 _ + 2 � ! B (4 + 5) ⇤ 10 _ + 2 � ! B 4 + 5 _ ⇤ 10 , _ + 2 � ! B 4 _ + 5 , _ ⇤ 10 , _ + 2 � ! B 5 4 + _ , _ ⇤ 10 , _ + 2 � ! B 9 _ ⇤ 10 , _ + 2 � ! B 10 9 ⇤ _ , _ + 2 � ! B 90 _ + 2 � ! B 2 90 + _ � ! B 92 · � ! B
Example Evaluation ((4 + 5) ⇤ 10) + 2 · B (4 + 5) ⇤ 10 _ + 2 � ! B (4 + 5) ⇤ 10 _ + 2 � ! B 4 + 5 _ ⇤ 10 , _ + 2 � ! B 4 _ + 5 , _ ⇤ 10 , _ + 2 � ! B 5 4 + _ , _ ⇤ 10 , _ + 2 � ! B 9 _ ⇤ 10 , _ + 2 � ! B 10 9 ⇤ _ , _ + 2 � ! B 90 _ + 2 � ! B 2 90 + _ � ! B 92 · � ! B
Example Evaluation ((4 + 5) ⇤ 10) + 2 · B (4 + 5) ⇤ 10 _ + 2 � ! B (4 + 5) ⇤ 10 _ + 2 � ! B 4 + 5 _ ⇤ 10 , _ + 2 � ! B 4 _ + 5 , _ ⇤ 10 , _ + 2 � ! B 5 4 + _ , _ ⇤ 10 , _ + 2 � ! B 9 _ ⇤ 10 , _ + 2 � ! B 10 9 ⇤ _ , _ + 2 � ! B 90 _ + 2 � ! B 2 90 + _ � ! B 92 · � ! B
Example Evaluation ((4 + 5) ⇤ 10) + 2 · B (4 + 5) ⇤ 10 _ + 2 � ! B (4 + 5) ⇤ 10 _ + 2 � ! B 4 + 5 _ ⇤ 10 , _ + 2 � ! B 4 _ + 5 , _ ⇤ 10 , _ + 2 � ! B 5 4 + _ , _ ⇤ 10 , _ + 2 � ! B 9 _ ⇤ 10 , _ + 2 � ! B 10 9 ⇤ _ , _ + 2 � ! B 90 _ + 2 � ! B 2 90 + _ � ! B 92 · � ! B
Example Evaluation ((4 + 5) ⇤ 10) + 2 · B (4 + 5) ⇤ 10 _ + 2 � ! B (4 + 5) ⇤ 10 _ + 2 � ! B 4 + 5 _ ⇤ 10 , _ + 2 � ! B 4 _ + 5 , _ ⇤ 10 , _ + 2 � ! B 5 4 + _ , _ ⇤ 10 , _ + 2 � ! B 9 _ ⇤ 10 , _ + 2 � ! B 10 9 ⇤ _ , _ + 2 � ! B 90 _ + 2 � ! B 2 90 + _ � ! B 92 · � ! B
Example Evaluation ((4 + 5) ⇤ 10) + 2 · B (4 + 5) ⇤ 10 _ + 2 � ! B (4 + 5) ⇤ 10 _ + 2 � ! B 4 + 5 _ ⇤ 10 , _ + 2 � ! B 4 _ + 5 , _ ⇤ 10 , _ + 2 � ! B 5 4 + _ , _ ⇤ 10 , _ + 2 � ! B 9 _ ⇤ 10 , _ + 2 � ! B 10 9 ⇤ _ , _ + 2 � ! B 90 _ + 2 � ! B 2 90 + _ � ! B 92 · � ! B
Example Evaluation ((4 + 5) ⇤ 10) + 2 · B (4 + 5) ⇤ 10 _ + 2 � ! B (4 + 5) ⇤ 10 _ + 2 � ! B 4 + 5 _ ⇤ 10 , _ + 2 � ! B 4 _ + 5 , _ ⇤ 10 , _ + 2 � ! B 5 4 + _ , _ ⇤ 10 , _ + 2 � ! B 9 _ ⇤ 10 , _ + 2 � ! B 10 9 ⇤ _ , _ + 2 � ! B 90 _ + 2 � ! B 2 90 + _ � ! B 92 · � ! B
Evaluation Rules: End of and Evaluation If we reach a constant and the empty continuation then we stop value ( c ) c B · � !
Evaluation Rules: Boolean Expressions e 1 B ( _ && e 2 , K ) e 1 && e 2 B K � ! B B � ! B B false B ( _ && e 2 , K ) false B K � ! B B � ! B B true B ( _ && e 2 , K ) e 2 B K � ! True and false are also values (We could also use 1 and 0 but distinguishing helps detect errors.)
Evaluation Rules: Boolean Expressions e 1 B ( _ && e 2 , K ) e 1 && e 2 B K � ! B B � ! B B Notice the short- false B ( _ && e 2 , K ) false B K � ! cutting. B B � ! B B true B ( _ && e 2 , K ) e 2 B K � ! True and false are also values (We could also use 1 and 0 but distinguishing helps detect errors.)
Variables and Environments How do we evaluate variable?
Variables and Environments How do we evaluate variable? ? x B K − →
Variables and Environments How do we evaluate variable? ? x B K − → Need to have a environment that maps variables to values
Variables and Environments How do we evaluate variable? ? x B K − → Need to have a environment that maps variables to values η ::= · | η , x 7! v
Variables and Environments How do we evaluate variable? ? x B K − → Need to have a environment that maps variables to values η ::= · | η , x 7! v The machine state consists now of an expression, a continuation, and an environment
Variables and Environments How do we evaluate variable? ? x B K − → Need to have a environment that maps variables to values η ::= · | η , x 7! v The machine state consists now of an expression, a continuation, and an environment η ` e B K
Variables and Environments II The rules we have seen so far just carry over η ` e 1 B ( _ � e 2 , K ) η ` e 1 � e 2 B K � ! ` � � ! ` � B B B B η ` c 1 B ( _ � e 2 , K ) η ` e 2 B ( c 1 � _ , K ) � ! ` � � ! ` � B B B B ( c = c 1 � c 2 mod 2 32 ) η ` c 2 B ( c 1 � _ , K ) � ! η ` c B K
Variables and Environments II The rules we have seen so far just carry over η ` e 1 B ( _ � e 2 , K ) η ` e 1 � e 2 B K � ! ` � � ! ` � B B B B η ` c 1 B ( _ � e 2 , K ) η ` e 2 B ( c 1 � _ , K ) � ! ` � � ! ` � B B B B ( c = c 1 � c 2 mod 2 32 ) η ` c 2 B ( c 1 � _ , K ) � ! η ` c B K Variables are simply looked up η ` η ( x ) B K η ` x B K � !
Variables and Environments II The rules we have seen so far just carry over η ` e 1 B ( _ � e 2 , K ) η ` e 1 � e 2 B K � ! ` � � ! ` � B B B B η ` c 1 B ( _ � e 2 , K ) η ` e 2 B ( c 1 � _ , K ) � ! ` � � ! ` � B B B B ( c = c 1 � c 2 mod 2 32 ) η ` c 2 B ( c 1 � _ , K ) � ! η ` c B K We assume programs Variables are simply looked up passed the semantic η ` η ( x ) B K check and vars are η ` x B K � ! always defined.
Variables and Environments II The rules we have seen so far just carry over η ` e 1 B ( _ � e 2 , K ) η ` e 1 � e 2 B K � ! ` � � ! ` � B B B B η ` c 1 B ( _ � e 2 , K ) η ` e 2 B ( c 1 � _ , K ) � ! ` � � ! ` � B B B B ( c = c 1 � c 2 mod 2 32 ) η ` c 2 B ( c 1 � _ , K ) � ! η ` c B K We assume programs Variables are simply looked up passed the semantic η ` η ( x ) B K check and vars are η ` x B K � ! always defined. The environment never changes when evaluating expressions
Executing Statements
Executing Statements I Executions of statements don’t pass values to the continuation Statements have usually an e ff ect on the environment Machine configurations: η ` s I K
Executing Statements I Executions of statements don’t pass values to the continuation Statements have usually an e ff ect on the environment Machine configurations: Continuations contain η ` s I K statements.
Executing Statements I Executions of statements don’t pass values to the continuation Statements have usually an e ff ect on the environment Machine configurations: Continuations contain η ` s I K statements. Sequences: η ` seq ( s 1 , s 2 ) I K η ` s 1 I ( s 2 , K ) � ! ` � ! ` I I
Executing Statements I Executions of statements don’t pass values to the continuation Statements have usually an e ff ect on the environment Machine configurations: Continuations contain η ` s I K statements. Sequences: η ` seq ( s 1 , s 2 ) I K η ` s 1 I ( s 2 , K ) � ! ` � ! ` I I Nops: ` � ! ` 2 I 1 I 1 2 η ` nop I ( s , K ) � ! η ` s I K
Executing Statements I Executions of statements don’t pass values to the continuation Statements have usually an e ff ect on the environment Machine configurations: Continuations contain η ` s I K statements. Sequences: η ` seq ( s 1 , s 2 ) I K η ` s 1 I ( s 2 , K ) � ! ` � ! ` I I A terminating Nops: execution ends ` � ! ` 2 I 1 I 1 2 with a nop. η ` nop I ( s , K ) � ! η ` s I K
Executing Statements II Interaction with expressions is straightforward Assignments: η ` assign ( x, e ) I K η ` e B ( assign ( x, _ ) , K ) � ! ` � ! ` ` � ! 7! ` I B B I η ` v B ( assign ( x, _ ) , K ) η [ x 7! v ] ` nop I K � !
Executing Statements II Interaction with expressions is straightforward Assignments: η ` assign ( x, e ) I K η ` e B ( assign ( x, _ ) , K ) � ! ` � ! ` ` � ! 7! ` I B B I η ` v B ( assign ( x, _ ) , K ) η [ x 7! v ] ` nop I K � !
Executing Statements II Interaction with expressions is straightforward Assignments: η ` assign ( x, e ) I K η ` e B ( assign ( x, _ ) , K ) � ! ` � ! ` ` � ! 7! ` I B B I η ` v B ( assign ( x, _ ) , K ) η [ x 7! v ] ` nop I K � ! Update the environment with new mapping.
Executing Statements III Conditionals: η ` if ( e, s 1 , s 2 ) I K η ` e B ( if ( _ , s 1 , s 2 ) , K ) � ! ` � ! ` B I ` � ! ` I B η ` true B ( if ( _ , s 1 , s 2 ) , K ) � ! η ` s 1 I K η ` false B ( if ( , s , s ) , K ) � ! η ` s I K ` � ! ` B I η ` false B ( if ( _ , s 1 , s 2 ) , K ) � ! η ` s 2 I K
Executing Statements IV Loops: η ` while ( e, s ) I K om? � !
Executing Statements IV Loops: η ` while ( e, s ) I K om? � ! Not that the following statements are equivalent: while ( e, s ) ⌘ if ( e, seq ( s, while ( e, s )) , nop )
Executing Statements IV Loops: η ` while ( e, s ) I K om? � ! Not that the following statements are equivalent: while ( e, s ) ⌘ if ( e, seq ( s, while ( e, s )) , nop ) η ` while ( e, s ) I K η ` if ( e, seq ( s, while ( e, s )) , nop ) I K � !
Executing Statements IV Loops: η ` while ( e, s ) I K om? � ! Not that the following statements are equivalent: while ( e, s ) ⌘ if ( e, seq ( s, while ( e, s )) , nop ) η ` while ( e, s ) I K η ` if ( e, seq ( s, while ( e, s )) , nop ) I K � ! Non-termination: transitions s 0 · · · without � ! � ! � ! s 1 s 2 final states are just nop I · and except We can make an infinite number of steps without reaching a final state
Executing Statements V Assertions: η ` assert ( e ) I K η ` e B ( assert ( _ ) , K ) � ! ` � ! ` I B B I η ` true B ( assert ( _ ) , K ) � ! η ` nop I K η ` true B ( assert ( _ ) , K ) B � ! η ` nop I K η ` false B ( assert ( _ ) , K ) exception ( abort ) � !
Executing Statements V Assertions: η ` assert ( e ) I K η ` e B ( assert ( _ ) , K ) � ! ` � ! ` I B B I η ` true B ( assert ( _ ) , K ) � ! η ` nop I K η ` true B ( assert ( _ ) , K ) B � ! η ` nop I K η ` false B ( assert ( _ ) , K ) exception ( abort ) � ! Declarations: η ` decl ( x, τ , s ) I K � ! η [ x 7! nothing ] ` s I K
Executing Statements V Assertions: η ` assert ( e ) I K η ` e B ( assert ( _ ) , K ) � ! ` � ! ` I B B I η ` true B ( assert ( _ ) , K ) � ! η ` nop I K η ` true B ( assert ( _ ) , K ) B � ! η ` nop I K η ` false B ( assert ( _ ) , K ) exception ( abort ) � ! Declarations: η ` decl ( x, τ , s ) I K � ! η [ x 7! nothing ] ` s I K If C0 had shadowing then we would have to save and restore the previous value of x.
Executing Statements V Assertions: η ` assert ( e ) I K η ` e B ( assert ( _ ) , K ) � ! ` � ! ` I B B I η ` true B ( assert ( _ ) , K ) � ! η ` nop I K η ` true B ( assert ( _ ) , K ) B � ! η ` nop I K η ` false B ( assert ( _ ) , K ) exception ( abort ) � ! Declarations: η ` decl ( x, τ , s ) I K � ! η [ x 7! nothing ] ` s I K If C0 had shadowing then we would have to Final states: � ! save and restore the · · · and exception ( E ) , just nop I · and previous value of x. caused by a failing
Example: Infinite Loop and η = [ x 7! 1] . statement while ( x > 0 , assign ( x, x + 1)) execution; where s ⌘ execution, we obtion the following execution; [ x 7! 1] ` while ( x > 0 , s ) I · � ! [ x 7! 1] ` if ( x> 0 , seq ( s, while ( x> 0 , s )) , nop ) I · � ! [ x 7! 1] ` x > 0 if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` x _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 1 _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 0 1 > _ ; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` true if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` seq ( s, while ( x > 0 , s )) I · � ! [ x 7! 1] ` assign ( x, x + 1)) while ( x > 0 , assign ( x, x + 1)) I � ! [ x 7! 1] ` x + 1 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` x _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 1 + _ ; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 2 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 2] ` nop while ( x > 0 , s ) I � ! [ x 7! 2] ` while ( x > 0 , s ) I · · · ·
Example: Infinite Loop and η = [ x 7! 1] . statement while ( x > 0 , assign ( x, x + 1)) execution; where s ⌘ execution, we obtion the following execution; [ x 7! 1] ` while ( x > 0 , s ) I · � ! [ x 7! 1] ` if ( x> 0 , seq ( s, while ( x> 0 , s )) , nop ) I · � ! [ x 7! 1] ` x > 0 if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` x _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 1 _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 0 1 > _ ; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` true if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` seq ( s, while ( x > 0 , s )) I · � ! [ x 7! 1] ` assign ( x, x + 1)) while ( x > 0 , assign ( x, x + 1)) I � ! [ x 7! 1] ` x + 1 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` x _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 1 + _ ; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 2 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 2] ` nop while ( x > 0 , s ) I � ! [ x 7! 2] ` while ( x > 0 , s ) I · · · ·
Example: Infinite Loop and η = [ x 7! 1] . statement while ( x > 0 , assign ( x, x + 1)) execution; where s ⌘ execution, we obtion the following execution; [ x 7! 1] ` while ( x > 0 , s ) I · � ! [ x 7! 1] ` if ( x> 0 , seq ( s, while ( x> 0 , s )) , nop ) I · � ! [ x 7! 1] ` x > 0 if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` x _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 1 _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 0 1 > _ ; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` true if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` seq ( s, while ( x > 0 , s )) I · � ! [ x 7! 1] ` assign ( x, x + 1)) while ( x > 0 , assign ( x, x + 1)) I � ! [ x 7! 1] ` x + 1 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` x _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 1 + _ ; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 2 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 2] ` nop while ( x > 0 , s ) I � ! [ x 7! 2] ` while ( x > 0 , s ) I · · · ·
Example: Infinite Loop and η = [ x 7! 1] . statement while ( x > 0 , assign ( x, x + 1)) execution; where s ⌘ execution, we obtion the following execution; [ x 7! 1] ` while ( x > 0 , s ) I · � ! [ x 7! 1] ` if ( x> 0 , seq ( s, while ( x> 0 , s )) , nop ) I · � ! [ x 7! 1] ` x > 0 if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` x _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 1 _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 0 1 > _ ; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` true if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` seq ( s, while ( x > 0 , s )) I · � ! [ x 7! 1] ` assign ( x, x + 1)) while ( x > 0 , assign ( x, x + 1)) I � ! [ x 7! 1] ` x + 1 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` x _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 1 + _ ; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 2 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 2] ` nop while ( x > 0 , s ) I � ! [ x 7! 2] ` while ( x > 0 , s ) I · · · ·
Example: Infinite Loop and η = [ x 7! 1] . statement while ( x > 0 , assign ( x, x + 1)) execution; where s ⌘ execution, we obtion the following execution; [ x 7! 1] ` while ( x > 0 , s ) I · � ! [ x 7! 1] ` if ( x> 0 , seq ( s, while ( x> 0 , s )) , nop ) I · � ! [ x 7! 1] ` x > 0 if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` x _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 1 _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 0 1 > _ ; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` true if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` seq ( s, while ( x > 0 , s )) I · � ! [ x 7! 1] ` assign ( x, x + 1)) while ( x > 0 , assign ( x, x + 1)) I � ! [ x 7! 1] ` x + 1 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` x _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 1 + _ ; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 2 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 2] ` nop while ( x > 0 , s ) I � ! [ x 7! 2] ` while ( x > 0 , s ) I · · · ·
Example: Infinite Loop and η = [ x 7! 1] . statement while ( x > 0 , assign ( x, x + 1)) execution; where s ⌘ execution, we obtion the following execution; [ x 7! 1] ` while ( x > 0 , s ) I · � ! [ x 7! 1] ` if ( x> 0 , seq ( s, while ( x> 0 , s )) , nop ) I · � ! [ x 7! 1] ` x > 0 if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` x _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 1 _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 0 1 > _ ; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` true if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` seq ( s, while ( x > 0 , s )) I · � ! [ x 7! 1] ` assign ( x, x + 1)) while ( x > 0 , assign ( x, x + 1)) I � ! [ x 7! 1] ` x + 1 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` x _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 1 + _ ; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 2 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 2] ` nop while ( x > 0 , s ) I � ! [ x 7! 2] ` while ( x > 0 , s ) I · · · ·
Example: Infinite Loop and η = [ x 7! 1] . statement while ( x > 0 , assign ( x, x + 1)) execution; where s ⌘ execution, we obtion the following execution; [ x 7! 1] ` while ( x > 0 , s ) I · � ! [ x 7! 1] ` if ( x> 0 , seq ( s, while ( x> 0 , s )) , nop ) I · � ! [ x 7! 1] ` x > 0 if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` x _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 1 _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 0 1 > _ ; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` true if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` seq ( s, while ( x > 0 , s )) I · � ! [ x 7! 1] ` assign ( x, x + 1)) while ( x > 0 , assign ( x, x + 1)) I � ! [ x 7! 1] ` x + 1 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` x _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 1 + _ ; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 2 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 2] ` nop while ( x > 0 , s ) I � ! [ x 7! 2] ` while ( x > 0 , s ) I · · · ·
Example: Infinite Loop and η = [ x 7! 1] . statement while ( x > 0 , assign ( x, x + 1)) execution; where s ⌘ execution, we obtion the following execution; [ x 7! 1] ` while ( x > 0 , s ) I · � ! [ x 7! 1] ` if ( x> 0 , seq ( s, while ( x> 0 , s )) , nop ) I · � ! [ x 7! 1] ` x > 0 if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` x _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 1 _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 0 1 > _ ; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` true if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` seq ( s, while ( x > 0 , s )) I · � ! [ x 7! 1] ` assign ( x, x + 1)) while ( x > 0 , assign ( x, x + 1)) I � ! [ x 7! 1] ` x + 1 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` x _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 1 + _ ; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 2 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 2] ` nop while ( x > 0 , s ) I � ! [ x 7! 2] ` while ( x > 0 , s ) I · · · ·
Example: Infinite Loop and η = [ x 7! 1] . statement while ( x > 0 , assign ( x, x + 1)) execution; where s ⌘ execution, we obtion the following execution; [ x 7! 1] ` while ( x > 0 , s ) I · � ! [ x 7! 1] ` if ( x> 0 , seq ( s, while ( x> 0 , s )) , nop ) I · � ! [ x 7! 1] ` x > 0 if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` x _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 1 _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 0 1 > _ ; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` true if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` seq ( s, while ( x > 0 , s )) I · � ! [ x 7! 1] ` assign ( x, x + 1)) while ( x > 0 , assign ( x, x + 1)) I � ! [ x 7! 1] ` x + 1 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` x _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 1 + _ ; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 2 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 2] ` nop while ( x > 0 , s ) I � ! [ x 7! 2] ` while ( x > 0 , s ) I · · · ·
Example: Infinite Loop and η = [ x 7! 1] . statement while ( x > 0 , assign ( x, x + 1)) execution; where s ⌘ execution, we obtion the following execution; [ x 7! 1] ` while ( x > 0 , s ) I · � ! [ x 7! 1] ` if ( x> 0 , seq ( s, while ( x> 0 , s )) , nop ) I · � ! [ x 7! 1] ` x > 0 if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` x _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 1 _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 0 1 > _ ; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` true if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` seq ( s, while ( x > 0 , s )) I · � ! [ x 7! 1] ` assign ( x, x + 1)) while ( x > 0 , assign ( x, x + 1)) I � ! [ x 7! 1] ` x + 1 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` x _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 1 + _ ; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 2 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 2] ` nop while ( x > 0 , s ) I � ! [ x 7! 2] ` while ( x > 0 , s ) I · · · ·
Example: Infinite Loop and η = [ x 7! 1] . statement while ( x > 0 , assign ( x, x + 1)) execution; where s ⌘ execution, we obtion the following execution; [ x 7! 1] ` while ( x > 0 , s ) I · � ! [ x 7! 1] ` if ( x> 0 , seq ( s, while ( x> 0 , s )) , nop ) I · � ! [ x 7! 1] ` x > 0 if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` x _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 1 _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 0 1 > _ ; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` true if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` seq ( s, while ( x > 0 , s )) I · � ! [ x 7! 1] ` assign ( x, x + 1)) while ( x > 0 , assign ( x, x + 1)) I � ! [ x 7! 1] ` x + 1 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` x _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 1 + _ ; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 2 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 2] ` nop while ( x > 0 , s ) I � ! [ x 7! 2] ` while ( x > 0 , s ) I · · · ·
Example: Infinite Loop and η = [ x 7! 1] . statement while ( x > 0 , assign ( x, x + 1)) execution; where s ⌘ execution, we obtion the following execution; [ x 7! 1] ` while ( x > 0 , s ) I · � ! [ x 7! 1] ` if ( x> 0 , seq ( s, while ( x> 0 , s )) , nop ) I · � ! [ x 7! 1] ` x > 0 if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` x _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 1 _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 0 1 > _ ; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` true if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` seq ( s, while ( x > 0 , s )) I · � ! [ x 7! 1] ` assign ( x, x + 1)) while ( x > 0 , assign ( x, x + 1)) I � ! [ x 7! 1] ` x + 1 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` x _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 1 + _ ; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 2 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 2] ` nop while ( x > 0 , s ) I � ! [ x 7! 2] ` while ( x > 0 , s ) I · · · ·
Example: Infinite Loop and η = [ x 7! 1] . statement while ( x > 0 , assign ( x, x + 1)) execution; where s ⌘ execution, we obtion the following execution; [ x 7! 1] ` while ( x > 0 , s ) I · � ! [ x 7! 1] ` if ( x> 0 , seq ( s, while ( x> 0 , s )) , nop ) I · � ! [ x 7! 1] ` x > 0 if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` x _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 1 _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 0 1 > _ ; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` true if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` seq ( s, while ( x > 0 , s )) I · � ! [ x 7! 1] ` assign ( x, x + 1)) while ( x > 0 , assign ( x, x + 1)) I � ! [ x 7! 1] ` x + 1 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` x _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 1 + _ ; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 2 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 2] ` nop while ( x > 0 , s ) I � ! [ x 7! 2] ` while ( x > 0 , s ) I · · · ·
Example: Infinite Loop and η = [ x 7! 1] . statement while ( x > 0 , assign ( x, x + 1)) execution; where s ⌘ execution, we obtion the following execution; [ x 7! 1] ` while ( x > 0 , s ) I · � ! [ x 7! 1] ` if ( x> 0 , seq ( s, while ( x> 0 , s )) , nop ) I · � ! [ x 7! 1] ` x > 0 if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` x _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 1 _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 0 1 > _ ; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` true if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` seq ( s, while ( x > 0 , s )) I · � ! [ x 7! 1] ` assign ( x, x + 1)) while ( x > 0 , assign ( x, x + 1)) I � ! [ x 7! 1] ` x + 1 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` x _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 1 + _ ; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 2 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 2] ` nop while ( x > 0 , s ) I � ! [ x 7! 2] ` while ( x > 0 , s ) I · · · ·
Example: Infinite Loop and η = [ x 7! 1] . statement while ( x > 0 , assign ( x, x + 1)) execution; where s ⌘ execution, we obtion the following execution; [ x 7! 1] ` while ( x > 0 , s ) I · � ! [ x 7! 1] ` if ( x> 0 , seq ( s, while ( x> 0 , s )) , nop ) I · � ! [ x 7! 1] ` x > 0 if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` x _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 1 _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 0 1 > _ ; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` true if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` seq ( s, while ( x > 0 , s )) I · � ! [ x 7! 1] ` assign ( x, x + 1)) while ( x > 0 , assign ( x, x + 1)) I � ! [ x 7! 1] ` x + 1 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` x _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 1 + _ ; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 2 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 2] ` nop while ( x > 0 , s ) I � ! [ x 7! 2] ` while ( x > 0 , s ) I · · · ·
Example: Infinite Loop and η = [ x 7! 1] . statement while ( x > 0 , assign ( x, x + 1)) execution; where s ⌘ execution, we obtion the following execution; [ x 7! 1] ` while ( x > 0 , s ) I · � ! [ x 7! 1] ` if ( x> 0 , seq ( s, while ( x> 0 , s )) , nop ) I · � ! [ x 7! 1] ` x > 0 if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` x _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 1 _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 0 1 > _ ; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` true if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` seq ( s, while ( x > 0 , s )) I · � ! [ x 7! 1] ` assign ( x, x + 1)) while ( x > 0 , assign ( x, x + 1)) I � ! [ x 7! 1] ` x + 1 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` x _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 1 + _ ; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 2 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 2] ` nop while ( x > 0 , s ) I � ! [ x 7! 2] ` while ( x > 0 , s ) I · · · ·
Example: Infinite Loop and η = [ x 7! 1] . statement while ( x > 0 , assign ( x, x + 1)) execution; where s ⌘ execution, we obtion the following execution; [ x 7! 1] ` while ( x > 0 , s ) I · � ! [ x 7! 1] ` if ( x> 0 , seq ( s, while ( x> 0 , s )) , nop ) I · � ! [ x 7! 1] ` x > 0 if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` x _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 1 _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 0 1 > _ ; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` true if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` seq ( s, while ( x > 0 , s )) I · � ! [ x 7! 1] ` assign ( x, x + 1)) while ( x > 0 , assign ( x, x + 1)) I � ! [ x 7! 1] ` x + 1 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` x _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 1 + _ ; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 2 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 2] ` nop while ( x > 0 , s ) I � ! [ x 7! 2] ` while ( x > 0 , s ) I · · · ·
Example: Infinite Loop and η = [ x 7! 1] . statement while ( x > 0 , assign ( x, x + 1)) execution; where s ⌘ execution, we obtion the following execution; [ x 7! 1] ` while ( x > 0 , s ) I · � ! [ x 7! 1] ` if ( x> 0 , seq ( s, while ( x> 0 , s )) , nop ) I · � ! [ x 7! 1] ` x > 0 if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` x _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 1 _ > 0; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` 0 1 > _ ; if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` true if ( _ , seq ( s, while ( x > 0 , s )) , nop ) B � ! [ x 7! 1] ` seq ( s, while ( x > 0 , s )) I · � ! [ x 7! 1] ` assign ( x, x + 1)) while ( x > 0 , assign ( x, x + 1)) I � ! [ x 7! 1] ` x + 1 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` x _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 _ + 1; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 1 1 + _ ; assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 1] ` 2 assign ( x, _ )); while ( x > 0 , s ) B � ! [ x 7! 2] ` nop while ( x > 0 , s ) I � ! [ x 7! 2] ` while ( x > 0 , s ) I · · · ·
Functions
Function Calls What needs to happen at a function call?
Function Calls What needs to happen at a function call? • Evaluate the arguments in left-to-right order
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
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
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
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
Call Stack We need to keep track of continuations and environment in stack frames Call stack: ::= · | S , h η , K i S
Call Stack We need to keep track of continuations and environment in stack frames Call stack: ::= · | S , h η , K i S Environment
Call Stack We need to keep track of continuations and environment in stack frames Continuation Call stack: ::= · | S , h η , K i S Environment
Call Stack We need to keep track of continuations and environment in stack frames Continuation Call stack: ::= · | S , h η , K i S Environment Configurations: Evaluation S ; η ` e B K ` B I Execution S ; η ` s I K
Call Stack We need to keep track of continuations and environment in stack frames Continuation Call stack: ::= · | S , h η , K i S Environment Configurations: Evaluation S ; η ` e B K ` B I Execution S ; η ` s I K Existing rules can be lifted to the new configurations by passing through the call stack
Recommend
More recommend