/** * Create a new SmartHandle that converts arguments from the given signature to * the current signature's type with the new argument names. This conversion * is equivalent to MethodHandle#asType. * * @param incoming the target MethodType from which arguments will be converted * @return a new SmartHandle that accepts the given argument types */ public SmartHandle convert(Signature incoming) { return new SmartHandle(incoming, handle.asType(incoming.type())); }
/** * Cast the incoming arguments to the types in the given signature. The * argument count must match, but the names in the target signature are * ignored. * * @param target the Signature to which arguments should be cast * @return a new SmartBinder with the cast applied */ public SmartBinder cast(Signature target) { return new SmartBinder(target, binder.cast(target.type())); }
/** * Create a new SmartHandle that casts arguments from the given signature to * the current signature's type with the new argument names. This casting * is equivalent to MethodHandle#asType. * * @param incoming the target MethodType from which arguments will be converted * @return a new SmartHandle that accepts the given argument types */ public SmartHandle cast(Signature incoming) { return new SmartHandle(incoming, MethodHandles.explicitCastArguments(handle, incoming.type())); }
/** * Create a new SmartBinder from the given Signature. * * @param inbound the Signature to start from * @return a new SmartBinder */ public static SmartBinder from(Signature inbound) { return new SmartBinder(inbound, Binder.from(inbound.type())); }
/** * Create a new SmartBinder from the given Signature, using the given * Lookup for any handle lookups. * * @param lookup the Lookup to use for handle lookups * @param inbound the Signature to start from * @return a new SmartBinder */ public static SmartBinder from(Lookup lookup, Signature inbound) { return new SmartBinder(inbound, Binder.from(lookup, inbound.type())); }
/** * Set the argument name at the given index. * * @param index the index at which to set the argument name * @param name the name to set * @return a new signature with the given name at the given index */ public Signature argName(int index, String name) { String[] argNames = Arrays.copyOf(argNames(), argNames().length); argNames[index] = name; return new Signature(type(), argNames); }
/** * Set the argument type at the given index. * * @param index the index at which to set the argument type * @param type the type to set * @return a new signature with the given type at the given index */ public Signature argType(int index, Class<?> type) { return new Signature(type().changeParameterType(index, type), argNames()); }
protected Handle emitClosure(IRClosure closure, boolean print) { /* Compile the closure like a method */ String name = JavaNameMangler.encodeScopeForBacktrace(closure) + '$' + methodIndex++; emitScope(closure, name, CLOSURE_SIGNATURE, false, print); return new Handle( Opcodes.H_INVOKESTATIC, jvm.clsData().clsName, name, sig(CLOSURE_SIGNATURE.type().returnType(), CLOSURE_SIGNATURE.type().parameterArray()), false); }
protected Handle emitClosure(IRClosure closure, boolean print) { /* Compile the closure like a method */ String name = JavaNameMangler.encodeScopeForBacktrace(closure) + '$' + methodIndex++; emitScope(closure, name, CLOSURE_SIGNATURE, false, print); return new Handle( Opcodes.H_INVOKESTATIC, jvm.clsData().clsName, name, sig(CLOSURE_SIGNATURE.type().returnType(), CLOSURE_SIGNATURE.type().parameterArray()), false); }
protected Handle emitModuleBody(IRModuleBody method) { String name = JavaNameMangler.encodeScopeForBacktrace(method) + '$' + methodIndex++; Signature signature = signatureFor(method, false); emitScope(method, name, signature, false, true); return new Handle( Opcodes.H_INVOKESTATIC, jvm.clsData().clsName, name, sig(signature.type().returnType(), signature.type().parameterArray()), false); }
protected Handle emitModuleBody(IRModuleBody method) { String name = JavaNameMangler.encodeScopeForBacktrace(method) + '$' + methodIndex++; Signature signature = signatureFor(method, false); emitScope(method, name, signature, false, true); return new Handle( Opcodes.H_INVOKESTATIC, jvm.clsData().clsName, name, sig(signature.type().returnType(), signature.type().parameterArray()), false); }
/** * Apply an argument into the handle at the end, returning a new * SmartHandle. The new handle will use the given value for the last * argument, accepting one fewer argument as a result. In other words, * fix that argument (partial application) into the given handle. * * @param arg the argument value * @return a new SmartHandle that already has applied the given argument */ public SmartHandle applyLast(Object arg) { return new SmartHandle(signature.dropLast(), MethodHandles.insertArguments(handle, signature.type().parameterCount(), arg)); }
/** * Cast the named argument to the given type. * * @param name the name of the argument to cast * @param type the type to which that argument will be cast * @return a new SmartBinder with the cast applied */ public SmartBinder castArg(String name, Class<?> type) { Signature newSig = signature().replaceArg(name, name, type); return new SmartBinder(this, newSig, binder.cast(newSig.type())); }
/** * Use the given filter function to transform the return value at this * point in the binder. The filter will be inserted into the handle, and * return values will pass through it before continuing. * * The filter's argument must match the expected return value downstream * from this point in the binder, and the return value must match the * return value at this point in the binder. * * @param filter the function to use to transform the return value at this point * @return a new SmartBinder with the filter applied */ public SmartBinder filterReturn(SmartHandle filter) { return new SmartBinder(this, signature().changeReturn(filter.signature().type().returnType()), binder.filterReturn(filter.handle())); }
protected Handle emitModuleBodyJIT(IRModuleBody method) { String name = JavaNameMangler.encodeScopeForBacktrace(method) + '$' + methodIndex++; String clsName = jvm.scriptToClass(method.getFile()); jvm.pushscript(clsName, method.getFile()); Signature signature = signatureFor(method, false); emitScope(method, name, signature, false, true); Handle handle = new Handle( Opcodes.H_INVOKESTATIC, jvm.clsData().clsName, name, sig(signature.type().returnType(), signature.type().parameterArray()), false); jvm.cls().visitEnd(); jvm.popclass(); return handle; }
public void pushmethod(String name, IRScope scope, Signature signature, boolean specificArity) { Method m = new Method(name, Type.getType(signature.type().returnType()), IRRuntimeHelpers.typesFromSignature(signature)); SkinnyMethodAdapter adapter = new SkinnyMethodAdapter(cls, Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, m.getName(), m.getDescriptor(), null, null); methodStack.push( new MethodData( new IRBytecodeAdapter6(adapter, signature, this), scope, signature, specificArity ? scope.getStaticScope().getSignature().required() : -1) ); } }
public void pushmethod(String name, IRScope scope, Signature signature, boolean specificArity) { Method m = new Method(name, Type.getType(signature.type().returnType()), IRRuntimeHelpers.typesFromSignature(signature)); SkinnyMethodAdapter adapter = new SkinnyMethodAdapter(cls, Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, m.getName(), m.getDescriptor(), null, null); methodStack.push( new MethodData( new IRBytecodeAdapter7(adapter, signature, this), scope, signature, specificArity ? scope.getStaticScope().getSignature().required() : -1) ); }
public void pushmethod(String name, IRScope scope, Signature signature, boolean specificArity) { Method m = new Method(name, Type.getType(signature.type().returnType()), IRRuntimeHelpers.typesFromSignature(signature)); SkinnyMethodAdapter adapter = new SkinnyMethodAdapter(cls, Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, m.getName(), m.getDescriptor(), null, null); methodStack.push( new MethodData( new IRBytecodeAdapter6(adapter, signature, this), scope, signature, specificArity ? scope.getStaticScope().getSignature().required() : -1) ); } }
public void pushmethod(String name, IRScope scope, Signature signature, boolean specificArity) { Method m = new Method(name, Type.getType(signature.type().returnType()), IRRuntimeHelpers.typesFromSignature(signature)); SkinnyMethodAdapter adapter = new SkinnyMethodAdapter(cls, Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, m.getName(), m.getDescriptor(), null, null); methodStack.push( new MethodData( new IRBytecodeAdapter7(adapter, signature, this), scope, signature, specificArity ? scope.getStaticScope().getSignature().required() : -1) ); }
@Override public MethodHandle generate(JRubyCallSite site, RubyClass cls, DynamicMethod method, String realName) { MethodHandle handle = ((HandleMethod)method).getHandle(site.arity()); if (handle == null) { throw new IndirectBindingException("MH dynamic method does not have needed arity"); } if (RubyInstanceConfig.LOG_INDY_BINDINGS) LOG.info(site.name() + "\tbound from MHDynMethod " + logMethod(method) + ":" + handle); Signature fullSig = site.fullSignature(); MethodHandle nativeTarget = Binder .from(fullSig.type()) .permute(fullSig.to("context", "self", "arg*", "block")) .invoke(handle); nativeTarget = addOrRemoveBlock(site, nativeTarget); return nativeTarget; } }