Docsity

Featherweight Java - Assignment - Advanced Topics in Computer Graphics | CMPS 290, Assignments of Computer Graphics

Toggle sidebar
bg1
Featherweight Java
CMPS 290G: Spring 2005
Presenter: Kenneth Knowles
April 29, 2005
1 An Opening Example
Featherweight Java is a core subset of java an allows us to reason about an ob ject-oriented language using a
higher level model than our previous model based on the λ-calculus. In Featherweight Java objects are the
basic building blocks with deal with as opposed to objects being an abstraction of lower-level components.
The discussion started with the following brief example:
class A extends Object { A() { super(); } }
class B extends Object { B() { super(); } }
class Pair extends Object {
Object fst;
Object snd;
Pair(Object fst, Object snd) { super; this.fst = fst; this.snd = snd; }
Pair setfst(Object newfst) { return new Pair(newfst, this.snd); }
}
The example appears very close to Java code with a few notable differences. In the course of discussion
the following differences were noted:
•The classes A,Band Pair all explicitly state that they extend Object.
•The setfst method returns a new object instead of doing an assignment.
•The explicit constructors that just called super.
•There is strict parity between the constructor arguments and the class member variables.
With these items in mind, we then outlined the syntax for featherweight Java as follows:
CL ::= class C extends C {¯
C¯
f; K ¯
M}class decl.
K ::= C (¯
C¯
f) super (¯
f); this.¯
f=¯
f; constructor
M ::= C m(¯
C ¯x) return t; method decl.
t ::= x variable
t.f field access
t.m(¯
t) method invocation
new C(¯
t) object creation
(C) t cast
v ::= new C(¯v) object creation
One link to our previous work is that the value in the λ-calculus was λx.t and here our value is the object
creation.
1
pf3
pf4

Partial preview of the text

Download Featherweight Java - Assignment - Advanced Topics in Computer Graphics | CMPS 290 and more Assignments Computer Graphics in PDF only on Docsity!

Featherweight Java

CMPS 290G: Spring 2005

Presenter: Kenneth Knowles

April 29, 2005

1 An Opening Example

Featherweight Java is a core subset of java an allows us to reason about an object-oriented language using a

higher level model than our previous model based on the λ-calculus. In Featherweight Java objects are the

basic building blocks with deal with as opposed to objects being an abstraction of lower-level components.

The discussion started with the following brief example:

class A extends Object { A() { super(); } }

class B extends Object { B() { super(); } }

class Pair extends Object {

Object fst;

Object snd;

Pair(Object fst, Object snd) { super; this.fst = fst; this.snd = snd; }

Pair setfst(Object newfst) { return new Pair(newfst, this.snd); }

The example appears very close to Java code with a few notable differences. In the course of discussion

the following differences were noted:

  • The classes A, B and Pair all explicitly state that they extend Object.
  • The setfst method returns a new object instead of doing an assignment.
  • The explicit constructors that just called super.
  • There is strict parity between the constructor arguments and the class member variables.

With these items in mind, we then outlined the syntax for featherweight Java as follows:

CL ::= class C extends C {

C

f; K

M} class decl.

K ::= C (

C

f) super (

f); this.

f=

f; constructor

M ::= C m(

C ¯x) return t; method decl.

t ::= x variable

t.f field access

t.m(¯t) method invocation

new C(¯t) object creation

(C) t cast

v ::= new C(¯v) object creation

One link to our previous work is that the value in the λ-calculus was λx.t and here our value is the object

creation.

2 Evaluation and Sub-typing Rules

In the following evaluation rules we explicitly pass the program text, P , to each rule.

P ` t → t

′

P ` t.f → t

′

.f

P ` t → t

′

P ` t.m(¯t) → t

′

.m(¯t)

P ` t → t

′

P ` (C)t → (C)t

′

P ` (C)v → (C)v

P ` t i

→ t

′

i

P ` v.m(¯v,... , t i ,... , t n ) → v.m(¯v,... , t

′

i

,... , , t n

P ` t i → t

′

i

P ` new C(¯v ,... , t i

,... , t n

) → new C(¯v ,... , t

′

i

,... , , t n

P ` D m(

E ¯x){return t; } ∈ methods(P, C)

P ` new C(¯v).m(¯u) → [¯x 7 → u, this¯ 7 → new C(¯v)]t

P ` f ields(P, C) = D 1 e 1

,... , D

n e n f = e i

P ` new C(v 1

,... , v n

).f → v i

P ` D <: C

P ` (C)new D.(¯v) → new D(¯v)

P ` A <: B B <: C

P ` A <: C

P ` A <: A

class A extends B... ∈ P

A <: B

P ` B <: C class A extends B... ∈ P

A <: B

D ∈ ClassNames(P ) ∀f i

f.f i

∈ fields(P, D)

fields(P, D) is OK

D¯g = fields(P, D)P ` m is OK in C K = C(

Dg,¯

C

f ){super(¯g; this.

f = f }

P ` class C extends D

E

f; K m¯ is OK

∀CL ∈ P, P ` CL is OK ClassesOnce(P )

P is OK

if Em(

E ¯z){.. .} ∈ methods(P, D) then E = D and

C =

E

class C extendsC

′

{.. .} ∈ P Override OK(C

′

, D m,

C, P ) this : C, ¯x : ¯c P ` t : D

P ` D m(

C

f){returnt; } is OK in C