Hi All,

I am interested in implementing multiple dispatch using invoke dynamic
to Java using a modified compiler and I am looking for some advice. I
currently use a dispatcher object:

http://pec.dev.java.net/nonav/compile/javadoc/pec/compile/multipledispatch/package-summary.html#package_description

but think invoke dynamic might be better. Consider an illustrative
problem, suppose you have a multiple dispatch method with the
signature:

interface MyNumeric { @MultipleDispatch MyNumeric add( MyNumeric ); }

and, in various classes, specific implementations defined as static
methods

MyInteger add( MyInteger, MyInteger ), MyDouble add( MyInteger,
MyDouble ), MyDouble add(MyDouble, MyInteger ), and MyDouble add
( MyDouble, MyDouble )

Where MyInteger and MyDouble implemented MyNumeric and the call to add
( MyNumeric ) is handled by invoke dynamic so that runtime types can
be used.

The problem is to bind i1.add( d2 ) in the following code:

class Main {
 public static void main( String... notUsed ) {
   MyNumeric i1 = new MyInteger( 1 );
   MyNumeric d2 = new MyDouble( 2 );
   out.println( i1.add( d2 ) );
  }
}

to MyDouble add( MyInteger, MyDouble ). I could in my compiler rewrite
MyNumeric and Main as something like:

interface MyNumeric { /* @MultipleDispatch add( MyNumeric ); */ } //
Method add removed

class MyNumerics {
  public static Object bootstrapMethod( CallSite site, Object...
args ) { ... } // Resolve MyNumeric calls
}

class Main {

 public static void main( String... notUsed ) {
   Dynamic i1 = new MyInteger( 1 );
   Dynamic d2 = new MyDouble( 2 );
   out.println( i1.add( d2 ) );
  }

  static { Linkage.registerBootstrapMethod( "bootstrapMethod" ); }

  private static Object bootstrapMethod( CallSite site, Object...
args ) {
    return MyNumerics.bootStrapMethod( site, args );
  }

}

The disadvantage of this approach is that every class that uses
MyNumeric needs to be modified. Is there a better way?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "JVM 
Languages" group.
To post to this group, send email to jvm-languages@googlegroups.com
To unsubscribe from this group, send email to 
jvm-languages+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jvm-languages?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to