Feather-Weight Java COS 441 Princeton University Fall 2004.

Slides:



Advertisements
Similar presentations
Transposing F to C Transposing F to C Andrew Kennedy & Don Syme Microsoft Research Cambridge, U.K.
Advertisements

Substitution & Evaluation Order cos 441 David Walker.
CPSC 388 – Compiler Design and Construction
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
- Vasvi Kakkad.  Formal -  Tool for mathematical analysis of language  Method for precisely designing language  Well formed model for describing and.
Basics of Inheritance CS 5010 Program Design Paradigms "Bootcamp" Lesson 12.1 © Mitchell Wand, This work is licensed under a Creative Commons.
Current Techniques in Language-based Security David Walker COS 597B With slides stolen from: Steve Zdancewic University of Pennsylvania.
Winter Compiler Construction T7 – semantic analysis part II type-checking Mooly Sagiv and Roman Manevich School of Computer Science Tel-Aviv.
Dynamic Typing COS 441 Princeton University Fall 2004.
Featherweight Java Chapter 19 Benjamin Pierce Types and Programming Languages.
A Type System for Well-Founded Recursion Derek Dreyer Carnegie Mellon University POPL 2004 Venice, Italy.
ITEC200 – Week03 Inheritance and Class Hierarchies.
Java Generics.
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
An Untyped Calculus of Aspect- Oriented Programs Radha Jagadeesan Alan Jeffrey James Riely DEPAUL UNIVERSITY, CHICAGO.
Subtyping COS 441 Princeton University Fall 2004.
7. Fixed Points. © O. Nierstrasz PS — Fixed Points 7.2 Roadmap  Representing Numbers  Recursion and the Fixed-Point Combinator  The typed lambda calculus.
Parametric Polymorphism COS 441 Princeton University Fall 2004.
Slides prepared by Rose Williams, Binghamton University Chapter 13 Interfaces and Inner Classes.
Strict Bidirectional Type Checking Adam Chlipala, Leaf Petersen, and Robert Harper.
Syntax With Binders COS 441 Princeton University Fall 2004.
OOP #10: Correctness Fritz Henglein. Wrap-up: Types A type is a collection of objects with common behavior (operations and properties). (Abstract) types.
MinML: an idealized programming language CS 510 David Walker.
Efficient Software Model Checking of Soundness of Type Systems Michael Roberson, Melanie Harries, Paul T. Darga, Chandrasekhar Boyapati University of Michigan.
7. Fixed Points. © O. Nierstrasz PS — Fixed Points 7.2 Roadmap  Representing Numbers  Recursion and the Fixed-Point Combinator  The typed lambda calculus.
Aggregate Data Structures COS 441 Princeton University Fall 2004.
HOT Programming in Java COS 441 Princeton University Fall 2004.
Semantics for MinML COS 441 Princeton University Fall 2004.
Compilation 2007 Scopes and Environments Michael I. Schwartzbach BRICS, University of Aarhus.
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
Programming Languages 2nd edition Tucker and Noonan Chapter 6 Types I was eventually persuaded of the need to design programming notations so as to maximize.
Generic Java 21/ What is generics? To be able to assign type variables to a class These variables are not bound to any specific type until the.
CS 1110 Final Exam: Review Session 2 Part 1 : Inheriting classes 1. Inheritance Facts 2. Constructors in Subclasses BREAK : 10 sec. Part 2 : Working with.
Appendix A.2: Review of Java and Object-Oriented Programming: Part 2 “For the object-oriented project, remember that the primary unit of decomposition.
Engr 691 Special Topics in Engineering Science Software Architecture Spring Semester 2004 Lecture Notes.
Mathematical Modeling and Formal Specification Languages CIS 376 Bruce R. Maxim UM-Dearborn.
Typed Lambda Calculus Chapter 9 Benjamin Pierce Types and Programming Languages.
Self Type Constructors Atsushi Igarashi Kyoto University Joint work with Chieri Saito 1.
Chapter Twenty-ThreeModern Programming Languages1 Formal Semantics.
TCP1201 OOPDS Lecture 4 1. Learning Objectives  To understand upcasting & downcasting  To understand static polymorphism and dynamic polymorphism 
Formal Semantics Chapter Twenty-ThreeModern Programming Languages, 2nd ed.1.
Programming Languages 2nd edition Tucker and Noonan Chapter 6 Type Systems I was eventually persuaded of the need to design programming notations so as.
Featherweight Generic Ownership Alex Potanin, James Noble Victoria University of Wellington Dave Clarke CWI, Netherlands Robert Biddle Carlton University.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 9 Inheritance and.
Just Enough Type Theory or, Featherweight Java A Simple Formal Model of Objects Jonathan Aldrich
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
CMSC 330: Organization of Programming Languages Operational Semantics a.k.a. “WTF is Project 4, Part 3?”
Semantic Analysis II Type Checking EECS 483 – Lecture 12 University of Michigan Wednesday, October 18, 2006.
CS412/413 Introduction to Compilers Radu Rugina Lecture 13 : Static Semantics 18 Feb 02.
Inheritance Inheritance is the process of extending the functionality of a class by defining a new class that inherit,all the features of extending class.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
CMSC 330: Organization of Programming Languages Operational Semantics.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
CS5205Semantics1 CS5205: Foundation in Programming Languages Semantics Static Semantics Dynamic Semantics Operational Semantics Big-step Small-Step Denotational.
Further Abstraction Techniques Chapter 10. Abstract Classes There are times when you do not want someone to be able to make an object of your class. For.
COP INTERMEDIATE JAVA Inheritance, Polymorphism, Interfaces.
Subtying Kangwon National University 임현승 Programming Languages These slides were originally created by Prof. Sungwoo Park at POSTECH.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 20 – C++ Subclasses and Inheritance.
Towards a Semantic Model for Java Wildcards Sophia Drossopoulou Mariangiola Dezani-Ciancaglini Imperial College London Università di Torino Italy Nicholas.
Design issues for Object-Oriented Languages
Polymorphism in Methods
Object-oriented Programming in Java
COS 260 DAY 19 Tony Gauvin.
Chapter 9 Inheritance and Polymorphism
Lecture 19 - Inheritance (Contd).
Java Programming Language
Formal Models for Programming Languages
Inheritance in Java CS 3331 Fall 2009.
SPL – PS3 C++ Classes.
Presentation transcript:

Feather-Weight Java COS 441 Princeton University Fall 2004

Feather-Weight Java Core calculus defining “essence” of Java –Target language to explain generics Featherweight Java: A Minimal Core Calculus for Java and GJ by Atsushi Igarashi, Benjamin Pierce, and Philip Wadler. Harper’s Notes contains many small and big bugs! Exercise for today is bug hunting as well as understanding FJ

Abstract Syntax

Example: Point

Example: Color Points

Class Tables and Programs A class table T is a finite function assigning classes to class names. The classes declared in the class table are bound within the table so that all classes may refer to one another via the class table. A program is a pair ( T, e ) consisting of a class table T and an expression e. We generally suppress explicit mention of the class table, and consider programs to be expressions.

Static Semantics All judgments for dynamic and static semantics are implicitly parameterized by a single global class table

Subtyping

Fields of a Class

Signature of a Method

should be d i should be m i should be d

Expression Typing

Typing for Casts typo-in Harper Should be c’

Typing for Casts Treatment of cast in original FJ Paper ` (c) e  c` (c) e  c  ` e   c ’ c ’ <: c up-cast ` (c) e  c` (c) e  c  ` e   c ’ c <: c ’ c ’  c down-cast ` (c) e  c` (c) e  c  ` e   c ’ c <: c ’ c ’ <: c stupid-cast

Well-Formed Method

Doesn’t handle the case of extending a class with a new method only when overriding a class Doesn’t allow subtyping for returned type

Well-Formed Method c 0 m(c x) { return e 0 ; } ok in c T  c  = class c extends c’ { …; …} x:c, this :c ` e 0 : c’ 0 c’ 0 <: c 0 if type(m,c’) = c arg ! c ret then c = c arg and c 0 = c ret Buggy Fixed Rule

Well-Formed Class

should be d

Class-Table and Programs

Dynamic Semantics Small-step semantics Implicitly index/parameterized by a global class table T –Left unspecified in the rules to avoid clutter Values define as

Field Lookup

Method Dispatch/Lookup

should be m i should be body

Class Cast Runtime Check wrt particular class table

Search Rules

Search Rules (cont.) Left to right evaluation

Safety Theorem If ( T, e ) ok and e  * e ’ then either 1. e ’ value, or 2. there exists e ’’ such that e ’  e ’’, or 3. e ’ contains a bad cast of the form ( c ) new ( c ’)( e 0 ) where c ’ <: c “Well formed programs only get stuck in well-defined ways!”

Proof of Type Safety

should be c ’

Factorial in FJ Define a new abstract class Nat class Nat extends Object { Nat(){ super(); } Nat add(Nat n) { /* loop */ return this.add(n); } Nat mul(Nat m) { /* loop */ return this.mul(m); } Nat fact() { /* loop */ return this.fact(); } }

The Zero Subclass Define Zero which is a subclass of Nat class Zero extends Nat { Zero() { super(); } Nat add(Nat n){ return n; } Nat mul(Nat m){return new Zero(); } Nat fact() { return new Succ(new Zero()); } }

The Succ Subclass class Succ extends Nat { Nat n; Succ(Nat n){super(); this.n = n;} Nat add(Nat n) { return new Succ(this.n.add(n)); } Nat mul(Nat m) { return m.add(m.mul(this.n)); } Nat fact() { return this.mul(this.n.fact()); } }

Summary We can apply operational techniques to describe the core of Java Does it scale to full language? Semantics provide description of high- level “reference interpter” less ambigious than english text –More inscrutable to non-experts –Should not be too inscrutable to a COS441 student

Summary of Corrections to Notes

Page 203 should be d Rule 25.9 should be c’ Rule 25.5

Page 203 c 0 m(c x) { return e 0 ; } ok in c T  c  = class c extends c’ { …; …} x:c, this :c ` e 0 : c’ 0 c’ 0 <: c 0 if type(m,c’) = c arg ! c ret then c = c arg and c 0 = c ret Buggy Rule Fixed Rule 25.10

Page 204 should be d i should be m i should be d Rule Rule 25.16

Page 206 should be m i should be body Rule Rule 25.28

Page 207 should be c ’