/** * Prepend the given argument to the argument list, assigning it the * given name. * * @param name the name of the new argument * @param value the value of the new argument * @return a new SmartBinder with the prepend applied */ public SmartBinder prepend(String name, Object value) { return new SmartBinder(this, signature().prependArg(name, value.getClass()), binder.prepend(value)); }
/** * Prepend the given argument to the argument list, assigning it the * given name. * * @param name the name of the new argument * @param value the value of the new argument * @return a new SmartBinder with the prepend applied */ public SmartBinder prepend(String name, byte value) { return new SmartBinder(this, signature().prependArg(name, byte.class), binder.prepend(value)); }
/** * Prepend the given argument to the argument list, assigning it the * given name. * * @param name the name of the new argument * @param value the value of the new argument * @return a new SmartBinder with the prepend applied */ public SmartBinder prepend(String name, boolean value) { return new SmartBinder(this, signature().prependArg(name, boolean.class), binder.prepend(value)); }
/** * Prepend the given argument to the argument list, assigning it the * given name. * * @param name the name of the new argument * @param value the value of the new argument * @return a new SmartBinder with the prepend applied */ public SmartBinder prepend(String name, float value) { return new SmartBinder(this, signature().prependArg(name, float.class), binder.prepend(value)); }
/** * Prepend the given argument to the argument list, assigning it the * given name. * * @param name the name of the new argument * @param value the value of the new argument * @return a new SmartBinder with the prepend applied */ public SmartBinder prepend(String name, double value) { return new SmartBinder(this, signature().prependArg(name, double.class), binder.prepend(value)); }
/** * Prepend the given argument to the argument list, assigning it the * given name. * * @param name the name of the new argument * @param value the value of the new argument * @return a new SmartBinder with the prepend applied */ public SmartBinder prepend(String name, char value) { return new SmartBinder(this, signature().prependArg(name, char.class), binder.prepend(value)); }
/** * Prepend the given argument to the argument list, assigning it the * given name. * * @param name the name of the new argument * @param value the value of the new argument * @return a new SmartBinder with the prepend applied */ public SmartBinder prepend(String name, long value) { return new SmartBinder(this, signature().prependArg(name, long.class), binder.prepend(value)); }
/** * Prepend the given argument to the argument list, assigning it the * given name. * * @param name the name of the new argument * @param value the value of the new argument * @return a new SmartBinder with the prepend applied */ public SmartBinder prepend(String name, short value) { return new SmartBinder(this, signature().prependArg(name, short.class), binder.prepend(value)); }
/** * Prepend the given argument to the argument list, assigning it the * given name. * * @param name the name of the new argument * @param value the value of the new argument * @return a new SmartBinder with the prepend applied */ public SmartBinder prepend(String name, int value) { return new SmartBinder(this, signature().prependArg(name, int.class), binder.prepend(value)); }
/** * Prepend the given argument to the argument list, assigning it the * given name. * * @param name the name of the new argument * @param type the type to use in the new signature * @param value the value of the new argument * @return a new SmartBinder with the prepend applied */ public SmartBinder prepend(String name, Class<?> type, Object value) { return new SmartBinder(this, signature().prependArg(name, type), binder.prepend(type, value)); }
/** * Prepend the given arguments to the argument list, assigning them the * given name. * * @param names the names of the new arguments * @param types the types to use in the new signature * @param values the values of the new arguments * @return a new SmartBinder with the prepend applied */ public SmartBinder prepend(String[] names, Class<?>[] types, Object... values) { return new SmartBinder(this, signature().prependArgs(names, types), binder.prepend(types, values)); }
public static CallSite bootstrap(MethodHandles.Lookup lookup, String name, MethodType type, int unwrap) throws Throwable { YieldSite site = new YieldSite(type, unwrap == 1 ? true : false); MethodHandle handle; switch (name) { case "yield": case "yieldSpecific": handle = Binder.from(type) .prepend(YieldSite.class, site) .invokeVirtual(lookup, name); break; case "yieldValues": handle = Binder.from(type) .collect(2, IRubyObject[].class) .prepend(YieldSite.class, site) .invokeVirtual(lookup, name); break; default: throw new RuntimeException("invalid yield type: " + name); } site.setTarget(handle); return site; }
public static CallSite bootstrap(MethodHandles.Lookup lookup, String name, MethodType type, int unwrap) throws Throwable { YieldSite site = new YieldSite(type, unwrap == 1 ? true : false); MethodHandle handle; switch (name) { case "yield": case "yieldSpecific": handle = Binder.from(type) .prepend(YieldSite.class, site) .invokeVirtual(lookup, name); break; case "yieldValues": handle = Binder.from(type) .collect(2, IRubyObject[].class) .prepend(YieldSite.class, site) .invokeVirtual(lookup, name); break; default: throw new RuntimeException("invalid yield type: " + name); } site.setTarget(handle); return site; }
private static MethodHandle createAttrReaderHandle(InvokeSite site, IRubyObject self, RubyClass cls, VariableAccessor accessor) { MethodHandle nativeTarget; MethodHandle filter = cls.getClassRuntime().getNullToNilHandle(); MethodHandle getValue; if (accessor instanceof FieldVariableAccessor) { MethodHandle getter = ((FieldVariableAccessor)accessor).getGetter(); getValue = Binder.from(site.type()) .drop(0, 2) .filterReturn(filter) .cast(methodType(Object.class, self.getClass())) .invoke(getter); } else { getValue = Binder.from(site.type()) .drop(0, 2) .filterReturn(filter) .cast(methodType(Object.class, Object.class)) .prepend(accessor) .invokeVirtualQuiet(LOOKUP, "get"); } // NOTE: Must not cache the fully-bound handle in the method, since it's specific to this class return getValue; }
private static MethodHandle createAttrReaderHandle(InvokeSite site, IRubyObject self, RubyClass cls, VariableAccessor accessor) { MethodHandle nativeTarget; MethodHandle filter = cls.getClassRuntime().getNullToNilHandle(); MethodHandle getValue; if (accessor instanceof FieldVariableAccessor) { MethodHandle getter = ((FieldVariableAccessor)accessor).getGetter(); getValue = Binder.from(site.type()) .drop(0, 2) .filterReturn(filter) .cast(methodType(Object.class, self.getClass())) .invoke(getter); } else { getValue = Binder.from(site.type()) .drop(0, 2) .filterReturn(filter) .cast(methodType(Object.class, Object.class)) .prepend(accessor) .invokeVirtualQuiet(LOOKUP, "get"); } // NOTE: Must not cache the fully-bound handle in the method, since it's specific to this class return getValue; }
private static MethodHandle createAttrWriterHandle(InvokeSite site, IRubyObject self, RubyClass cls, VariableAccessor accessor) { MethodHandle nativeTarget; MethodHandle filter = Binder .from(IRubyObject.class, Object.class) .drop(0) .constant(cls.getRuntime().getNil()); MethodHandle setValue; if (accessor instanceof FieldVariableAccessor) { MethodHandle setter = ((FieldVariableAccessor)accessor).getSetter(); setValue = Binder.from(site.type()) .drop(0, 2) .filterReturn(filter) .cast(methodType(void.class, self.getClass(), Object.class)) .invoke(setter); } else { setValue = Binder.from(site.type()) .drop(0, 2) .filterReturn(filter) .cast(methodType(void.class, Object.class, Object.class)) .prepend(accessor) .invokeVirtualQuiet(LOOKUP, "set"); } return setValue; }
private static MethodHandle createAttrWriterHandle(InvokeSite site, IRubyObject self, RubyClass cls, VariableAccessor accessor) { MethodHandle nativeTarget; MethodHandle filter = Binder .from(IRubyObject.class, Object.class) .drop(0) .constant(cls.getRuntime().getNil()); MethodHandle setValue; if (accessor instanceof FieldVariableAccessor) { MethodHandle setter = ((FieldVariableAccessor)accessor).getSetter(); setValue = Binder.from(site.type()) .drop(0, 2) .filterReturn(filter) .cast(methodType(void.class, self.getClass(), Object.class)) .invoke(setter); } else { setValue = Binder.from(site.type()) .drop(0, 2) .filterReturn(filter) .cast(methodType(void.class, Object.class, Object.class)) .prepend(accessor) .invokeVirtualQuiet(LOOKUP, "set"); } return setValue; }