1 / 40

Feather-Weight Java

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.

bian
Télécharger la présentation

Feather-Weight Java

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Feather-Weight Java COS 441 Princeton University Fall 2004

  2. 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

  3. Abstract Syntax

  4. Example: Point

  5. Example: Color Points

  6. 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.

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

  8. Subtyping

  9. Fields of a Class

  10. Signature of a Method

  11. Signature of a Method should be d should be di should be mi should be d

  12. Expression Typing

  13. Typing for Casts typo-in Harper Should be c’

  14. up-cast down-cast stupid-cast `e0 :c’ c’ <: c `e0 :c’ c <: c’ c’ c `e0 :c’ c <: c’ c’ <: c `(c)e0:c `(c)e0:c `(c)e0:c Typing for Casts Treatment of cast in original FJ Paper

  15. Well-Formed Method

  16. 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

  17. Well-Formed Method Buggy Fixed Rule T(c) = classcextendsc’ { …; …} x:c, this:c`e0 : c’0c’0 <: c0 if type(m,c’) = carg! cret then c = carg and c0 = cret c0m(cx) { returne0; } ok in c

  18. Well-Formed Class

  19. Well-Formed Class should be d

  20. Class-Table and Programs

  21. 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

  22. Field Lookup

  23. Method Dispatch/Lookup

  24. Method Dispatch/Lookup should be mi should be body

  25. Class Cast Runtime Check wrt particular class table

  26. Search Rules

  27. Search Rules (cont.) Left to right evaluation

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

  29. Proof of Type Safety

  30. Proof of Type Safety should be c’

  31. 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(); } }

  32. 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()); } }

  33. 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()); } }

  34. 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

  35. Summary of Corrections to Notes

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

  37. Page 203 Buggy Rule 25.10 Fixed Rule 25.10 T(c) = classcextendsc’ { …; …} x:c, this:c`e0 : c’0c’0 <: c0 if type(m,c’) = carg! cret then c = carg and c0 = cret c0m(cx) { returne0; } ok in c

  38. Page 204 Rule 25.15 should be d should be di should be mi Rule 25.16 should be d

  39. Page 206 Rule 25.27 should be mi Rule 25.28 should be body

  40. Page 207 should be c’

More Related