Created
May 8, 2011 02:41
-
-
Save headius/961054 to your computer and use it in GitHub Desktop.
invokedynamic example in BiteScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.invoke.MethodHandle | |
import java.lang.invoke.MethodType | |
import java.lang.invoke.CallSite | |
import java.lang.invoke.ConstantCallSite | |
import java.lang.invoke.MethodHandles::Lookup | |
JClass = java.lang.Class | |
# Our main method, which does one invokedynamic | |
main do | |
# handle for our bootstrap, which binds invokedynamic to a CallSite | |
bootstrap = mh_invokestatic this, 'bootstrap', CallSite, Lookup, string, MethodType | |
ldc 'Hello, invokedynamic!' | |
invokedynamic 'print', [void, string], bootstrap | |
returnvoid | |
end | |
# The method we want to invoke, prints given string | |
public_static_method :print, [], void, string do | |
aload 0 | |
aprintln | |
returnvoid | |
end | |
# The bootstrap method, which binds our dynamic call | |
public_static_method :bootstrap, [], CallSite, Lookup, string, MethodType do | |
# Constant since we bind just once directly | |
new ConstantCallSite | |
dup | |
# Locate the method indicated by name + type on current class | |
aload 0 # Lookup | |
ldc this # this class | |
aload 1 # String | |
aload 2 # MethodType | |
invokevirtual Lookup, 'findStatic', [MethodHandle, JClass, string, MethodType] | |
# finish constructing call site and return | |
invokespecial ConstantCallSite, '<init>', [void, MethodHandle] | |
areturn | |
end |
Author
headius
commented
May 8, 2011
via email
Latter.
…On Sun, May 8, 2011 at 2:53 AM, olabini ***@***.*** wrote:
Nice.
Does the mh_invokestatic look up a real method handle, or an ASM method handle shim? If possible, it would be good to have the latter instead of the former.
##
Reply to this email directly or view it on GitHub:
https://gist.github.com/961054
Latter. The changes are pushed to BiteScript master now, so you can have a look.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment