


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



CMPS 290G: Spring 2005
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:
With these items in mind, we then outlined the syntax for featherweight Java as follows:
CL ::= class C extends C {
f; K
M} class decl.
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.
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
n e n f = e i
P ` new C(v 1
,... , v n
).f → v i
P ` (C)new D.(¯v) → new D(¯v)
class A extends B... ∈ P
P ` B <: C class A extends B... ∈ P
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,¯
f ){super(¯g; this.
f = f }
P ` class C extends D
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
class C extendsC
′
{.. .} ∈ P Override OK(C
′
, D m,
C, P ) this : C, ¯x : ¯c P ` t : D
P ` D m(
f){returnt; } is OK in C