What is the Meaning of These Constant Interruptions? Graham Hutton and Joel Wright University of Nottingham.

Slides:



Advertisements
Similar presentations
Chapter 8 Technicalities: Functions, etc. Bjarne Stroustrup
Advertisements

Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
- Vasvi Kakkad.  Formal -  Tool for mathematical analysis of language  Method for precisely designing language  Well formed model for describing and.
Introducing Formal Methods, Module 1, Version 1.1, Oct., Formal Specification and Analytical Verification L 5.
Compilation 2011 Static Analysis Johnni Winther Michael I. Schwartzbach Aarhus University.
The lambda calculus David Walker CS 441. the lambda calculus Originally, the lambda calculus was developed as a logic by Alonzo Church in 1932 –Church.
CALCULATING AN EXCEPTIONAL MACHINE Graham Hutton and Joel Wright University of Nottingham.
Recap 1.Programmer enters expression 2.ML checks if expression is “well-typed” Using a precise set of rules, ML tries to find a unique type for the expression.
THE WORKER / WRAPPER TRANSFORMATION Graham Hutton and Andy Gill.
Introduction to Programming Lesson 1. Objectives Skills/ConceptsMTA Exam Objectives Understanding Computer Programming Understand computer storage and.
Optimization Compiler Baojian Hua
ISBN Chapter 3 Describing Syntax and Semantics.
1 Semantic Description of Programming languages. 2 Static versus Dynamic Semantics n Static Semantics represents legal forms of programs that cannot be.
Comp 205: Comparative Programming Languages Semantics of Imperative Programming Languages denotational semantics operational semantics logical semantics.
Denotational vs Operational Approaches COS 441 Princeton University Fall 2004.
Python Programming Chapter 1: The way of the program Saad Bani Mohammad Department of Computer Science Al al-Bayt University 1 st 2011/2012.
Misc. Announcements Assignment available end of the day today –Due back in 11/03 (after break) Will also update slides on website –Today Midterm next week.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Operational Semantics.
1 Joint work with Claudio Antares Mezzina (INRIA), Jean-Bernard Stefani (INRIA) and Alan Schmitt (INRIA) Controlling Reversibility in Rhopi Ivan Lanese.
Dec Formal Semantics1 Programming Language Theory Formal Semantics Leif Grönqvist The national Graduate School of Language Technology (GSLT) MSI.
Developing Dependable Systems CIS 376 Bruce R. Maxim UM-Dearborn.
Semantics for MinML COS 441 Princeton University Fall 2004.
Describing Syntax and Semantics
12.1 Exceptions The limitations of traditional methods of exception handling Error conditions are a certainty in programming Programmers make.
Configuration Management
1 I.Introduction to Algorithm and Programming Algoritma dan Pemrograman – Teknik Informatika UK Petra 2009.
Principles of Programming Chapter 1: Introduction  In this chapter you will learn about:  Overview of Computer Component  Overview of Programming 
And other languages…. must remember to check return value OR, must pass label/exception handler to every function Caller Function return status Caller.
Slides Credit Umair Javed LUMS Web Application Development.
1 Abstract Syntax Tree--motivation The parse tree –contains too much detail e.g. unnecessary terminals such as parentheses –depends heavily on the structure.
CIS 199 Test 01 Review. Computer Hardware  Central Processing Unit (CPU)  Brains  Operations performed here  Main Memory (RAM)  Scratchpad  Work.
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
COMPILING EXCEPTIONS CORRECTLY Graham Hutton and Joel Wright University of Nottingham.
Input, Output, and Processing
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
What does a computer program look like: a general overview.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Introduction to Problem Solving. Steps in Programming A Very Simplified Picture –Problem Definition & Analysis – High Level Strategy for a solution –Arriving.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Semantics. Semantics is a precise definition of the meaning of a syntactically and type-wise correct program. Ideas of meaning: –Operational Semantics.
Writing Systems Software in a Functional Language An Experience Report Iavor Diatchki, Thomas Hallgren, Mark Jones, Rebekah Leslie, Andrew Tolmach.
QuickCheck: A Lightweight Tool for Random Testing of Haskell Programs By Koen Claessen, Juhn Hughes ME: Mike Izbicki.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Ivan Lanese Computer Science Department University of Bologna/INRIA Italy Decidability Results for Dynamic Installation of Compensation Handlers Joint.
THE COUNTDOWN PROBLEM Graham Hutton University of Nottingham.
Principles of programming languages 6: Types Isao Sasano Department of Information Science and Engineering.
Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming.
How to Program? -- Part 1 Part 1: Problem Solving –Analyze a problem –Decide what steps need to be taken to solve it. –Take into consideration any special.
CSE 332: C++ Statements C++ Statements In C++ statements are basic units of execution –Each ends with ; (can use expressions to compute values) –Statements.
Lexical Analysis – Part II EECS 483 – Lecture 3 University of Michigan Wednesday, September 13, 2006.
Fall 2008Programming Development Techniques 1 Topic 17 Assignment, Local State, and the Environment Model of Evaluation Section 3.1 & 3.2.
Types and Programming Languages
CMSC 330: Organization of Programming Languages Operational Semantics.
How to answer the American West exam paper Edexcel.
Course: Software Engineering – Design I IntroductionSlide Number 1 What is a specification Description of a (computer) system, which:  is precise;  defines.
Operational Semantics Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
CS5205Semantics1 CS5205: Foundation in Programming Languages Semantics Static Semantics Dynamic Semantics Operational Semantics Big-step Small-Step Denotational.
CSE Winter 2008 Introduction to Program Verification February 5 calculating with simplify.
1 ENERGY 211 / CME 211 Lecture 4 September 29, 2008.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
Introduction to Programming Lesson 1. Algorithms Algorithm refers to a method for solving problems. Common techniques for representing an algorithms:
Software Engineering Algorithms, Compilers, & Lifecycle.
CSE 332: C++ Exceptions Motivation for C++ Exceptions Void Number:: operator/= (const double denom) { if (denom == 0.0) { // what to do here? } m_value.
Language-Based Security: Overview of Types Deepak Garg Foundations of Security and Privacy October 27, 2009.
Secure Coding Rules for C++ Copyright © 2016 Curt Hill
Principles of programming languages 8: Types
Secure Coding Rules for C++ Copyright © Curt Hill
Background In his classic 1972 paper on definitional interpreters, John Reynolds introduced two key techniques: Continuation-passing style - Makes.
Verifying a compiler for a simple language with exceptions (MPC 04).
Introduction to Programming
Presentation transcript:

What is the Meaning of These Constant Interruptions? Graham Hutton and Joel Wright University of Nottingham

1 What Is An Exception? zDivision by zero zNull pointer Examples: An event within a computation that causes termination in a non-standard way

2 What Is An Interrupt? An exception that arises from the external environement, e.g. another computation zTerminate zAny exception Examples:

3 This Talk zHaskell is unique in providing both full support for interrupts and a semantics for this. zBut the semantics is subtle, and relies on quite considerable technical machinery. zWe give a simple, formally justified, semantics for interrupts in a small language.

4 An Exceptional Language data Expr = Val Int | Throw | Add Expr Expr | Seq Expr Expr | Catch Expr Expr Syntax: Semantics: e  v e can evaluate to v

5 Sequencing: Seq x y  v x  Val ny  v Seq x y  Throw x  Throw Catch x y  Val n x  Val n Catch x y  v x  Throwy  v Catch:

6 Finally, An Example Problem: how can we ensure that evaluation of x is always succeeded by evaluation of y? finally x y =

7 Finally, An Example Problem: how can we ensure that evaluation of x is always succeeded by evaluation of y? finally x y = Seq x y

8 Finally, An Example Problem: how can we ensure that evaluation of x is always succeeded by evaluation of y? finally x y = Seq x y If x produces an exception, y is not evaluated

9 Seq (Catch x y) y Finally, An Example Problem: how can we ensure that evaluation of x is always succeeded by evaluation of y? finally x y =

10 Seq (Catch x y) y Finally, An Example Problem: how can we ensure that evaluation of x is always succeeded by evaluation of y? finally x y = If x produces an exception, y may be evaluated twice

11 Seq (Catch x (Seq y Throw)) y Finally, An Example Problem: how can we ensure that evaluation of x is always succeeded by evaluation of y? finally x y =

12 Seq (Catch x (Seq y Throw)) y Finally, An Example Problem: how can we ensure that evaluation of x is always succeeded by evaluation of y? finally x y = Now has the correct behaviour

13 Adding Interrupts To avoid the need for concurrency, we adopt the following worst-case rule for interrupts: x  Throw Evaluation can be interrupted at any time by replacing the current expression by throw

14 Seq (Catch x (Seq y Throw)) y Note: zEvaluation is now non-deterministic. zFinally no longer behaves as expected. could be interrupted as y is about to be evaluated

15 Controlling Interrupts data Expr = | Block Expr | Unblock Expr Syntax: Semantics: e  i v e can evaluate to v in interrupt status i

16 Key rules: Block x  i v x  B v Unblock x  i v x  U v x  U Throw The other rules are simply modified to propogate the current interrupt status to their arguments.

17 Finally Revisited finally x y = Seq (Catch x (Seq y Throw)) y

18 Block (Seq (Catch (Unblock x) (Seq y Throw)) y) Finally Revisited finally x y =

19 Block (Seq (Catch (Unblock x) (Seq y Throw)) y) Finally Revisited finally x y = Modulo syntax, finally in Haskell is defined in precisely the same way

20 Is Our Semantics Correct? zHow does our high-level semantics reflect our low-level intuition about interrupts? zTo address this issue, we first define a virtual machine, its semantics, and a compiler. zWe explain the basic ideas informally using an example - the paper gives full details.

21 Catch (Unblock (2+3)) 4 Example Code

22 Catch (Unblock (2+3)) 4 Example Code

23 Catch (Unblock (2+3)) 4 Example MARK [ ] UNMARK Code

24 Catch (Unblock (2+3)) 4 Example MARK [ ] UNMARK Code

25 Catch (Unblock (2+3)) 4 Example MARK [PUSH 4] UNMARK Code

26 Catch (Unblock (2+3)) 4 Example MARK [PUSH 4] UNMARK Code

27 Catch (Unblock (2+3)) 4 Example MARK [PUSH 4] SET U RESET UNMARK Code

28 Catch (Unblock (2+3)) 4 Example MARK [PUSH 4] SET U RESET UNMARK Code

29 Catch (Unblock (2+3)) 4 Example MARK [PUSH 4] SET U PUSH 2 PUSH 3 ADD RESET UNMARK Code

30 Catch (Unblock (2+3)) 4 Example MARK [PUSH 4] SET U PUSH 2 PUSH 3 ADD RESET UNMARK CodeStackStatus

31 Catch (Unblock (2+3)) 4 Example MARK [PUSH 4] SET U PUSH 2 PUSH 3 ADD RESET UNMARK CodeStackStatus B

32 Catch (Unblock (2+3)) 4 Example SET U PUSH 2 PUSH 3 ADD RESET UNMARK CodeStack HAN [PUSH 4] Status B

33 Catch (Unblock (2+3)) 4 Example PUSH 2 PUSH 3 ADD RESET UNMARK CodeStack INT B HAN [PUSH 4] Status U

34 Catch (Unblock (2+3)) 4 Example PUSH 3 ADD RESET UNMARK CodeStack VAL 2 INT B HAN [PUSH 4] Status U

35 Catch (Unblock (2+3)) 4 Example ADD RESET UNMARK CodeStack VAL 3 VAL 2 INT B HAN [PUSH 4] Status U

36 Catch (Unblock (2+3)) 4 Example ADD RESET UNMARK CodeStack VAL 3 VAL 2 INT B HAN [PUSH 4] Status U interrupt!

37 Catch (Unblock (2+3)) 4 Example THROW RESET UNMARK CodeStack VAL 3 VAL 2 INT B HAN [PUSH 4] Status U interrupt!

38 Catch (Unblock (2+3)) 4 Example THROW RESET UNMARK CodeStack VAL 2 INT B HAN [PUSH 4] Status U

39 Catch (Unblock (2+3)) 4 Example THROW RESET UNMARK CodeStack INT B HAN [PUSH 4] Status U

40 Catch (Unblock (2+3)) 4 Example THROW RESET UNMARK CodeStack HAN [PUSH 4] Status B

41 Catch (Unblock (2+3)) 4 Example PUSH 4 CodeStackStatus B

42 Catch (Unblock (2+3)) 4 Example CodeStack VAL 4 Status B

43 Catch (Unblock (2+3)) 4 Example CodeStack VAL 4 Status B Final result

44 Compiler Correctness We will exploit two basic notions of reachability for configurations of our virtual machine. x can reach everything in Y x will reach something in Y x * Y x Y

45 Theorem { | e  i Val n } { | e  i Throw } * U Proof: approximately 10 pages of calculation, much of which requires considerable care. comp e c i s c i VAL n : s i s

46 Summary zSimple semantics for interrupts, formally justified by a compiler correctness theorem. zDiscovery of an error in the semantics for Haskell, concerning the delivery of interrupts. zVerification of finally, a useful high-level operator for programming with exceptions/interrupts.

47 Further Work zMechanical verification zBisimulation theorem zGeneralising the language zReasoning about programs zCalculating the compiler