This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Parameterizing on incomplete types


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


Attachment: bridge.patch
Description: Binary data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]