Parameterizing on incomplete types

Jamison Hope jrh@theptrgroup.com
Sat Dec 3 20:38:00 GMT 2011


On Dec 3, 2011, at 2:14 AM, Per Bothner wrote:

> (2) mostly just a matter of code: generating the needed
> bridge methods.  How the <init> methods are generated is probably
> a helpful illustration.  The other (more interesting?) part is
> figuring out *when* we need a bridge method, and the necessary
> signature.

OK, here's what I've got so far. It appears to handle our Comparable  
test case

(define-simple-class Foo (java.lang.Comparable[Foo])
   (x ::int)
   ((compare-to (o ::Foo)) ::int
    (- x o:x)))

generating a bridge method equivalent to

public int compareTo(java.lang.Object o)
{
   return this.compareTo((Foo) o);
}

.

The patch consists of two parts: the new  
Compilation#generateBridgeMethod(),
and a few lines added to ClassExp#compileMembers.

generateBridgeMethod takes an existing method and desired arg/return  
types,
creates a new method with the desired signature and emits bytecode to  
checkcast
its args and then call the existing method. In my limited testing so  
far, this
is the same bytecode generated by javac for similar cases.

The addition to ClassExp sits after the call to getImplMethods() where  
the current
"missing implementation" error is. Before triggering that error, we  
look to see
if the problem was 0 implementations found (as opposed to multiple,  
which is a
different problem), and if so, we look to see if there's a method with  
the right
name and number of args but wrong signature. If there is such a  
method, then
we check its arg types and return type to see if they're compatible  
with the
required signature, and if so we generate the bridge method. If not,  
then we still
do the error message.


I'm not handling covariant returns yet, because I'm not sure where/how  
to check
for those. We could use the same generateBridgeMethod there, but in  
that case the
checkcast instructions aren't needed. I suppose I should put the  
emitCheckcast
inside of something like "if  
(bridge_arg_types[i].compare(src_arg_types[i]) != 0)".
Maybe later.


-Jamie

--
Jamison Hope
The PTR Group
www.theptrgroup.com


-------------- next part --------------
A non-text attachment was scrubbed...
Name: bridge.patch
Type: application/octet-stream
Size: 2850 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/kawa/attachments/20111203/359d2156/attachment.obj>


More information about the Kawa mailing list