Re: [groovy-dev] static dispatch, was [groovy-user] Groovy Performance 20-90% of Java?
Mark C. Chu-Carroll <
markcc@...>
2004-06-01 17:56:16 GMT
On Jun 1, 2004, at 12:48 PM, John Wilson wrote:
>
> On 1 Jun 2004, at 16:09, bing ran wrote:
>
>> John, your proposal makes sense to me, and identifies a hole in my
>> current code, although we do not necessarily need to bar classes from
>> having methods of the same signature without declaring to
>> implement the GroovyObject interface.- they just get ignored. As a
>> matter of fact, I have yet to find how to define a Groovy class that
>> does NOT implement GroovyObject:)
>>
>> I'll add checks to my code so that any messages sent to GroovyObject
>> will take late binding - Groovy means dynamic anyway.
>>
>
> There is another solution to the problem of a Groovy class subclassing
> a class which does not override the default invokeMethod() method and
> then implementing invokeMethod().
> class MyGroovyClass {
> f() {
> println 'hello'
> }
> }
>
> class MyGroovySubclass extends MyGroovyClass {
> invokeMethod(String name, Object args) {
> .... do something sneaky
> }
> }
>
> The compiler could override all the methods in the superclass (there's
> a problem with final methods, though) and redirect the calls to
> invokeMethod()
>
>
> class MyGroovySubclass extends MyGroovyClass {
> invokeMethod(String name, Object args) {
> .... do something sneaky
> }
>
> f() {
> invokeMethod('f', new Object[0])
> }
> }
This is pretty much exactly what I'm working on doing for direct
binding in groovy-498. There is
one catch to this approach, which is that the code for the invokeMethod
call in the over-rides needs
to be a little more complicated. Unless I'm confused, what will happen
if you just do "f()" as above
is that calling MyGroovySubclass.f will invoke
MyGroovySubclass.invokeMethod("f", ...), which
will in turn find and call MyGroovySubclass.f...
So you need to make sure that the generated methods that defer to
invokeMethod do *not*
wind up just recursing. I'm still reading the code to figure out how to
get that right.
-Mark
> This means that you can always do direct calls and the object will
> know if they are to be made dynamic.
>
> John Wilson
> The Wilson Partnership
> http://www.wilson.co.uk
>
>
Mark Craig Chu-Carroll, IBM T.J. Watson Research Center
*** The Stellation project: Advanced SCM Research
*** http://stellation.eclipse.org
*** Work: mcc@.../Home: markcc@...