/** * Terminate this binder by invoking the given target handle. * * @param target the handle to invoke * @return a new SmartHandle with this binder's starting signature, bound * through to the given handle */ public SmartHandle invoke(MethodHandle target) { return new SmartHandle(start, binder.invoke(target)); }
/** * Produce a MethodHandle that invokes its leading MethodHandle argument * with the remaining arguments, returning the result. * * @return a new handle that invokes its leading MethodHandle argument */ public MethodHandle invoker() { return invoke(MethodHandles.invoker(start)); }
public static MethodHandle nullReplacingFilter(Class<?> target) throws NoSuchMethodException, IllegalAccessException { Lookup lookup = MethodHandles.lookup(); MethodHandle returnNull = lookup.findStatic(DynJSCoercionMatrix.class, "returnNull", methodType(Object.class, Object.class)); return Binder.from(methodType(target, Object.class)) //.drop(0) //.insert(0, new Class[]{Object.class}, new Object[]{null}) .invoke(returnNull); }
protected final MethodHandle newIdTest() { return Binder.from(boolean.class, ThreadContext.class, IRubyObject.class) .insert(2, id) .invoke(testModuleMatch); }
/** * Terminate this binder by invoking the given target handle. The signature * of this binder is not compared to the signature of the given * SmartHandle. * * @param target the handle to invoke * @return a new SmartHandle with this binder's starting signature, bound * through to the given handle */ public SmartHandle invoke(SmartHandle target) { return new SmartHandle(start, binder.invoke(target.handle())); }
public MethodHandle getNormalYieldSpecificHandle() { MethodHandle normalYieldSpecificHandle = this.normalYieldSpecificHandle; if (normalYieldSpecificHandle != null) return normalYieldSpecificHandle; return this.normalYieldSpecificHandle = Binder.from(IRubyObject.class, ThreadContext.class, Block.class) .append(new Class[] {StaticScope.class, IRubyObject.class, IRubyObject[].class, Block.class}, getStaticScope(), null, null, Block.NULL_BLOCK) .invoke(handle); }
public MethodHandle getTestBlockBody() { final MethodHandle testBlockBody = this.testBlockBody; if (testBlockBody != null) return testBlockBody; return this.testBlockBody = Binder.from(boolean.class, ThreadContext.class, Block.class).drop(0).append(this).invoke(TEST_BLOCK_BODY); }
public MethodHandle getNormalYieldSpecificHandle() { MethodHandle normalYieldSpecificHandle = this.normalYieldSpecificHandle; if (normalYieldSpecificHandle != null) return normalYieldSpecificHandle; return this.normalYieldSpecificHandle = Binder.from(IRubyObject.class, ThreadContext.class, Block.class) .append(new Class[] {StaticScope.class, IRubyObject.class, IRubyObject[].class, Block.class}, getStaticScope(), null, null, Block.NULL_BLOCK) .invoke(handle); }
/** * Apply the tranforms, binding them to a constant value that will * propagate back through the chain. The chain's expected return type * at that point must be compatible with the given value's type. * * @param value the constant value to put at the end of the chain * @return a handle that has all transforms applied in sequence up to the constant */ public MethodHandle constant(Object value) { return invoke(MethodHandles.constant(type().returnType(), value)); }
/** * Apply the chain of transforms and bind them to an array element get. The signature * at the endpoint must return the array element type and receive the array type and * int index. * * @return the full handle chain, bound to an array element get. */ public MethodHandle arrayGet() { return invoke(MethodHandles.arrayElementGetter(type().parameterType(0))); }
public MethodHandle getTestBlockBody() { final MethodHandle testBlockBody = this.testBlockBody; if (testBlockBody != null) return testBlockBody; return this.testBlockBody = Binder.from(boolean.class, ThreadContext.class, Block.class).drop(0).append(this).invoke(TEST_BLOCK_BODY); }
/** * Apply the tranforms, binding them to a handle that will simply return its sole * argument as its return value. The endpoint signature must have a single argument * of the same type as its return type. * * @return a handle that has all transforms applied in sequence */ public MethodHandle identity() { return invoke(MethodHandles.identity(type().parameterType(0))); }
@Override public MethodHandle guardMethodHandle(MethodType inputType) throws NoSuchMethodException, IllegalAccessException { Binder binder = Binder.from(inputType); MethodHandle target = super.guardMethodHandle(methodType(boolean.class, this.argType)); return binder.permute(this.argPos) .convert(target.type()) .invoke(target); }
public MethodHandle getNormalYieldHandle() { MethodHandle normalYieldHandle = this.normalYieldHandle; if (normalYieldHandle != null) return normalYieldHandle; return this.normalYieldHandle = Binder.from(IRubyObject.class, ThreadContext.class, Block.class, IRubyObject.class) .filter(2, WRAP_VALUE) .insert(2, new Class[]{StaticScope.class, IRubyObject.class}, getStaticScope(), null) .append(Block.class, Block.NULL_BLOCK) .invoke(handle); }
public MethodHandle getNormalYieldHandle() { MethodHandle normalYieldHandle = this.normalYieldHandle; if (normalYieldHandle != null) return normalYieldHandle; return this.normalYieldHandle = Binder.from(IRubyObject.class, ThreadContext.class, Block.class, IRubyObject.class) .filter(2, WRAP_VALUE) .insert(2, new Class[]{StaticScope.class, IRubyObject.class}, getStaticScope(), null) .append(Block.class, Block.NULL_BLOCK) .invoke(handle); }
public MethodHandle up(MethodHandle target) { if (onlyTail()) { // fast path for tail args return target.asCollector(arrayType, count); } else { Permutes permutes = buildPermutes(source, target.type()); Binder binder = preparePermuteBinder(permutes); return binder.invoke(target); } }
public MethodHandle getNormalYieldUnwrapHandle() { MethodHandle normalYieldUnwrapHandle = this.normalYieldUnwrapHandle; if (normalYieldUnwrapHandle != null) return normalYieldUnwrapHandle; return this.normalYieldUnwrapHandle = Binder.from(IRubyObject.class, ThreadContext.class, Block.class, IRubyObject.class) .filter(2, VALUE_TO_ARRAY) .insert(2, new Class[] {StaticScope.class, IRubyObject.class}, getStaticScope(), null) .append(Block.class, Block.NULL_BLOCK) .invoke(handle); } //
public MethodHandle getNormalYieldUnwrapHandle() { MethodHandle normalYieldUnwrapHandle = this.normalYieldUnwrapHandle; if (normalYieldUnwrapHandle != null) return normalYieldUnwrapHandle; return this.normalYieldUnwrapHandle = Binder.from(IRubyObject.class, ThreadContext.class, Block.class, IRubyObject.class) .filter(2, VALUE_TO_ARRAY) .insert(2, new Class[] {StaticScope.class, IRubyObject.class}, getStaticScope(), null) .append(Block.class, Block.NULL_BLOCK) .invoke(handle); } //
/** * Throw the current signature's sole Throwable argument. Return type * does not matter, since it will never return. * * @return a handle that has all transforms applied and which will eventually throw an exception */ public MethodHandle throwException() { if (type().parameterCount() != 1 || !Throwable.class.isAssignableFrom(type().parameterType(0))) { throw new InvalidTransformException("incoming signature must have one Throwable type as its sole argument: " + type()); } return invoke(MethodHandles.throwException(type().returnType(), type().parameterType(0).asSubclass(Throwable.class))); }
@Override public LinkBuilder guardWith(Guard guard) throws Exception { MethodHandle methodHandle = binder().guardBinder().invoke(guard.guardMethodHandle(binder().guardBinder().type())); methodHandle = MethodHandles.guardWithTest(this.guard, methodHandle, Guards.FALSE.guardMethodHandle(binder().guardInputType())); return new ChildLinkBuilder(new MultiBinder(binder()), methodHandle); }