Formal Models for Programming Languages - PowerPoint PPT Presentation

1 / 46
About This Presentation
Title:

Formal Models for Programming Languages

Description:

E. Zucca. 9/5/09. 24. Separate compilation: motivation. Why do we want these properties? ... Languages' by D. Anacona, S. Drossopoulou, F. Damiani, E. Zucca ... – PowerPoint PPT presentation

Number of Views:48
Avg rating:3.0/5.0
Slides: 47
Provided by: type
Category:

less

Transcript and Presenter's Notes

Title: Formal Models for Programming Languages


1
Formal Models for Programming Languages
  • FJ and FGJ

Alexandra Stefan
2
Topics of Discussion
  • Programming Languages (PLs) and
  • Formal Models
  • Case study
  • Java - Featherweight Java (FJ)
  • Extension
  • Generic Java (1.5 beta)
  • Featherweight Generic Java (FGJ)
  • Some properties compositionality ...
  • Related work

3
PLs formal models
  • First was the computer
  • and then the programs
  • and then the programs to write programs
  • Numerous programming languages
  • imperative Ada, Pascal, Perl, Java, all of the
    Cs
  • functional Scheme, SML, Prolog, Haskel, OCaml
  • How to choose one? What makes one better than the
    other?
  • expressive power?
  • No.
  • friendliness? (readability/ modifiability/
    debugging)
  • Yes.

4
PLs formal models
  • Then questions and needs were raised about
    languages
  • How safe is it?
  • It passed compilation what next?
  • Can I trust it to run well?
  • Will it stab me on the back?
  • Can it be extended?
  • Improved efficiency generic classes
  • Increased expressivity XML syntax
  • How would I design a new language?

5
PLs formal models
  • Here we come, the PL people!
  • check their properties (e.g. type preservation,
    progress, )
  • try to capture the invariants with a type system
  • How do we do this?
  • using a formal model

6
Formal model
  • Design choice completeness or compactness?
  • more complex is more unwieldy
  • too parsimonious is useless
  • trade-off

7
Formal model
  • Examples
  • Lambda calculus
  • Java FJ, FGJ, Javas (Javase), Javalight,
    ClassicJava,
  • C C?

8
Topics of Discussion
  • Programming Languages (PLs) and
  • Formal Models
  • Case study
  • Java - Featherweight Java (FJ)
  • Extension
  • Generic Java (1.5 beta)
  • Featherweight Generic Java (FGJ)
  • Some properties compositionality ...
  • Related work

9
Topics of Discussion
  • Programming Languages (PLs) and
  • Formal Models
  • Case study
  • Java - Featherweight Java (FJ)

10
Case study Featherweight Java (FJ)
  • Proposed by Igarashi, Pierce, and Wadler in 1999.
  • Models Javas type system.
  • Minimal core calculus
  • Favors compactness over completeness almost
    obsessively
  • (It hardly resembles Java!)
  • no assignment -gt functional
  • captures the core features of Java typing.
  • How close is it to Java?
  • FJ purely functional core of Java.
  • (every FJ program is literally an executable
    Java program)

11
FJ What can be done with it?
  • It allows easy proofs for type safety for FJ
  • FJs main application is to model extensions
  • of Java
  • FGJ
  • Featherweight Open Java
  • Inner classes

12
FJ
13
FJ
  • How does an FJ program look like?
  • Pair (class table, expression)
  • The class table - fixed
  • Sanity conditions for classes
  • Object - not part of the class table
  • All necessary classes are defined
  • No cycles in the subtyping relation
  • induced by the class table

14
FJ class declaration examples
15
FJ expression examples
16
FJ syntax subtyping rules
17
FJ auxiliary functions
18
FJ expression typing
19
FJ expression typing
20
FJ evaluation rules
21
FJ results
22
Topics of Discussion
  • Programming Languages (PLs) and
  • Formal Models
  • Case study
  • Java - Featherweight Java (FJ)
  • Extension
  • Generic Java (1.5 beta)
  • Featherweight Generic Java (FGJ)
  • Some properties compositionality ...
  • Related work

23
Compositional compilation
  • Polymorphic Bytecode Compositional Compilation
    for Java-like Languages
  • D. Anacona
  • S. Drossopoulou
  • F. Damiani
  • E. Zucca

24
Separate compilation motivation
  • Why do we want these properties?
  • modularity
  • safety

25
Separate compilation
Used fragments
fragment
compile
link
Used fragments
fragment
compile
fragment
compile
fragment
26
Java-like languages clash of philosophy
  • Separate compilation -gt byte-code reflects
    compilation environment
  • Dynamic linking -gt byte-code does not reflect
    compilation environment
  • no (compilation execution) environment
  • no (final globally) compiled application
  • type-safety through runtime verification
  • Example
  • E m(B x) return x.f1.f2
  • CEnv1 B C f1 C E f2
  • -gt mdB1 E m(B x) return xB.f1 CC.f2 E
  • CEnv2 B D f1 D F f2 -gt
  • -gt mdB2 E m(B x) return xB.f1 DD.f2 F

27
Compositionality
  • Compositional analysis
  • analyze source code fragments separately
  • put them together
  • finish analysis of the whole without reanalyzing
    the fragments
  • Compositional compilation
  • typecheck source code fragments separately
  • -gt generate corresponding binaries
  • link together fragments whose mutual constraints
    are satisfied, without reinspecting the code

28
Compositional compilation IDEA
  • Compile fragments separately
  • Generate
  • bytecode with type variables
  • constraints gt relate the type variables
  • Put the constraints together (particular order)
  • Solve the constraints gt substitution
  • Put the bytecode together
  • Apply the substitution
  • Done!

29
Compositional compilation
  • How good is it?
  • We are not sure yet, but it looks promising.
  • My work
  • Try to apply it for FGJ.

30
Topics of Discussion
  • Programming Languages (PLs) and
  • Formal Models
  • Case study
  • Java - Featherweight Java (FJ)
  • Extension
  • Generic Java (1.5 beta)
  • Featherweight Generic Java (FGJ)
  • Some properties compositionality ...
  • Related work

31
Generic Java
  • Version 1.5 beta
  • Parametric polymorphism
  • Uses the standard JVM
  • Backward Forward compatibility with old code.

32
FGJ class declaration examples
33
FGJ term examples
34
Homogeneous vs Heterogeneous polymorphism
35
Generic Java (GJ)
  • No explicit type arguments to a generic method
  • parsing problem
  • e.mltA,Bgt(e) ? e.mltA, Bgt(e)
  • Performs parameter inference has a least type

36
Featherweight Generic Java (FGJ)
  • FJ extended with generic classes
  • Not a subset of GJ requires type arguments to
    generic methods
  • Not concerned with parameter inference

37
FGJ syntax subtyping rules
38
FGJ auxiliary functions
39
FGJ
40
FGJ
41
FGJ expression typing
42
FGJ expression typing
43
FGJ evaluation rules
44
FGJ results
45
Topics of Discussion
  • Programming Languages (PLs) and
  • Formal Models
  • Case study
  • Java - Featherweight Java (FJ)
  • Extension
  • Generic Java (1.5 beta)
  • Featherweight Generic Java (FGJ)
  • Some properties compositionality ...
  • Related work

46
Related work
  • Types and Programming Languages by B.C.Pierce
  • Featherweight Java A Minimal Core Calculus for
    Java and GJ by Atsushi Igarashi, Benjamin C.
    Pierce, Philip Wadler
  • GJ Specification by Gilad Bracha, Martin
    Odersky, David Stoutamire, Philid Wadler
  • Bringing Genericity to Java by David W. Dunham
  • Polymorphic Bytecode Compositional Compilation
    for Java-like Languages by D. Anacona, S.
    Drossopoulou, F. Damiani, E. Zucca
Write a Comment
User Comments (0)
About PowerShow.com