PROPOSAL: Method and Field Literals

David Goodenough david.goodenough at linkchoose.co.uk
Thu Mar 12 08:41:28 PDT 2009


On Thursday 12 March 2009, Neal Gafter wrote:
> On Thu, Mar 12, 2009 at 8:16 AM, David Goodenough
>
> <david.goodenough at linkchoose.co.uk> wrote:
> > You are right that getting Field or Method literals into Annotations
> > would be difficult, because the Annotation rules require compile time
> > constants as arguements (that is not what it says in the language
> > spec but it is what it means).  Because Field and Method objects are not
> > stored in the class file directly (they are reconstructed at run time
> > when they are used from a binary form) it would be extreemly difficult to
> > regard these as compile time constants, and it would require not only a
> > language syntax change, compiler changes and run time changes, but also a
> > change to the class file format.
>
> I think adding support for field and method literals to the language
> can be done as a separate step from supporting them in annotations.
> Doing the first step as a new expression form lays the groundwork for
> extending annotations as a separate step, possibly in JDK8, but to me
> the first step looks small enough for project coin.

Well the good news is that modifying the compiler to handle Field expressions
is not that hard.  From no internals knowledge of the compiler I have gotten
a compiler which parses them correctly, and when you use -printsource
prints them correctly, and I know what needs to be done to desugar them
in Lower - and I only started on this last week.  While I do not presume to 
suggest that I have done it the correct way, or that further changes and
checks might be needed, if it only takes me a week (along with all the other
things I do) it should not take an experienced compiler engineer long to
do it properly.

I did have a little help along the way, I looked at the compiler changes that
Remi Forax did for his full properties proposal, which can be found on kijaro.
This gave me a check list of things to do, and pointed out a few things I 
did not realise from the other documentation that I found.

Also I have only done field expressions, not method expressions.

So yes, I believe that in a restricted form either this or my lightweight
properties proposal should be given serious consideration as a Coin 
sized proposal.

David



More information about the coin-dev mailing list