diff options
author | Iulian Dragos <jaguarul@gmail.com> | 2009-03-30 08:45:39 +0000 |
---|---|---|
committer | Iulian Dragos <jaguarul@gmail.com> | 2009-03-30 08:45:39 +0000 |
commit | 532147c333a8dab79fc77c20162a4d752c6f6780 (patch) | |
tree | d18c5275381e34655b0dad967f6304ba63c4416e /src/library | |
parent | 1c72ffaee5e0faeeb6d046216e5e76c86a6a41ff (diff) | |
download | scala-532147c333a8dab79fc77c20162a4d752c6f6780.tar.gz scala-532147c333a8dab79fc77c20162a4d752c6f6780.tar.bz2 scala-532147c333a8dab79fc77c20162a4d752c6f6780.zip |
Code to support invoke-dynamic for structural t...
Code to support invoke-dynamic for structural types. Not yet complete,
built around the JSR 292 spec of December 2008.
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/runtime/DynamicDispatch.java | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/library/scala/runtime/DynamicDispatch.java b/src/library/scala/runtime/DynamicDispatch.java new file mode 100644 index 0000000000..2868298211 --- /dev/null +++ b/src/library/scala/runtime/DynamicDispatch.java @@ -0,0 +1,42 @@ +package scala.runtime; + +import java.dyn.CallSite; +import java.dyn.MethodHandle; + +/** + * This class resolves calls through refinement types. The + * bootstrap method is called when an invokedynamic is found + * by the Java VM. + * + * Note: Requires Java 7 with invoke dynamic support (see JSR 292) + * + * @author Iulian Dragos + * @see JSR292 + */ +public class DynamicDispatch { + + /** + * Resolve an invoke dynamic in Scala code. invokedynamic calls appear + * when a method defined by a refinement type is called. It is resolved + * by looking up a method with the same name and types in the receiver + * object. It is guaranteed by the type checker that such a method + * exists. + * + * The current implementation is not correct, a call site being + * always bootstrapped to a method handle. A bound call site should be + * guarded by a test on the receiver type. Such code should either + * be generated by the compiler, or by this bootstrap method using + * one of the code combinators provided in java.dyn.*. + * + * ATM, they are not yet available in the JVM. + */ + public static bootstrapInvokeDynamic(CallSite cs, Object... args) { + println(cs); + + MethodHandle mh = MethodHandles.findVirtual(cs.callerClass(), + cs.name(), + cs.type()); + cs.setTarget(mh); + return mh(args) + } +} |