|
| 1 | +package org.jruby.ir.targets; |
| 2 | + |
| 3 | +import com.headius.invokebinder.Binder; |
| 4 | +import org.jruby.ir.runtime.IRRuntimeHelpers; |
| 5 | +import org.jruby.runtime.Block; |
| 6 | +import org.jruby.runtime.CompiledIRBlockBody; |
| 7 | +import org.jruby.runtime.ThreadContext; |
| 8 | +import org.jruby.runtime.builtin.IRubyObject; |
| 9 | +import org.objectweb.asm.Handle; |
| 10 | +import org.objectweb.asm.Opcodes; |
| 11 | + |
| 12 | +import java.lang.invoke.CallSite; |
| 13 | +import java.lang.invoke.MethodHandle; |
| 14 | +import java.lang.invoke.MethodHandles; |
| 15 | +import java.lang.invoke.MethodType; |
| 16 | +import java.lang.invoke.MutableCallSite; |
| 17 | + |
| 18 | +import static org.jruby.util.CodegenUtils.p; |
| 19 | +import static org.jruby.util.CodegenUtils.sig; |
| 20 | + |
| 21 | +public class BlockArgsSite extends MutableCallSite { |
| 22 | + |
| 23 | + public static final MethodHandles.Lookup LOOKUP = MethodHandles.publicLookup(); |
| 24 | + |
| 25 | + public BlockArgsSite(MethodType type) { |
| 26 | + super(type); |
| 27 | + } |
| 28 | +// |
| 29 | +// public static final Handle BOOTSTRAP = new Handle( |
| 30 | +// Opcodes.H_INVOKESTATIC, p(BlockArgsSite.class), |
| 31 | +// "bootstrap", |
| 32 | +// sig(CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class), |
| 33 | +// false); |
| 34 | +// |
| 35 | +// public static CallSite bootstrap(MethodHandles.Lookup lookup, String name, MethodType type) throws Throwable { |
| 36 | +// BlockArgsSite site = new BlockArgsSite(type); |
| 37 | +// |
| 38 | +// MethodHandle handle; |
| 39 | +// switch (name) { |
| 40 | +// case "prepareNoBlockArgs": |
| 41 | +// handle = Binder.from(type) |
| 42 | +// .prepend(BlockArgsSite.class, site) |
| 43 | +// .invokeVirtual(lookup, name); |
| 44 | +// break; |
| 45 | +// default: |
| 46 | +// throw new RuntimeException("invalid block args type: " + name); |
| 47 | +// } |
| 48 | +// |
| 49 | +// site.setTarget(handle); |
| 50 | +// |
| 51 | +// return site; |
| 52 | +// } |
| 53 | +// |
| 54 | +// public IRubyObject[] prepareNoBlockArgs(ThreadContext context, Block block, IRubyObject[] args) { |
| 55 | +// Binder prepBinder = Binder.from(type()); |
| 56 | +//// .filter(2, nullToArgs); |
| 57 | +// |
| 58 | +// if (block.isLambda()) { |
| 59 | +// prepBinder = prepBinder.foldVoid( |
| 60 | +// b -> b |
| 61 | +// .dropFirst(2) |
| 62 | +// .prepend(block.getSignature(), context.runtime) |
| 63 | +// .invokeVirtualQuiet(LOOKUP, "checkArity")); |
| 64 | +// } |
| 65 | +// |
| 66 | +// setTarget(prepBinder.dropFirst(2).identity()); |
| 67 | +// |
| 68 | +// return IRRuntimeHelpers.prepareNoBlockArgs(context, block, args); |
| 69 | +// } |
| 70 | +// |
| 71 | +// private static final MethodHandle nullToArgs = Binder |
| 72 | +// .from(IRubyObject[].class, IRubyObject[].class) |
| 73 | +// .invokeStaticQuiet(LOOKUP, BlockArgsSite.class, "nullToArgs"); |
| 74 | +// |
| 75 | +// public static IRubyObject[] nullToArgs(IRubyObject[] args) { |
| 76 | +// return args == null ? IRubyObject.NULL_ARRAY : args; |
| 77 | +// } |
| 78 | +} |
0 commit comments