Package com.headius.invokebinder

Examples of com.headius.invokebinder.Binder


        // we can handle this; do remaining transforms and return
        if (returnFilter != null) {
            Class[] newNativeParams = nativeTarget.type().parameterArray();
            Class newNativeReturn = nativeTarget.type().returnType();

            Binder exBinder = Binder
                    .from(newNativeReturn, Throwable.class, newNativeParams)
                    .drop(1, newNativeParams.length)
                    .insert(0, runtime);
            if (nativeReturn != void.class) {
                exBinder = exBinder
                        .filterReturn(Binder
                                .from(newNativeReturn)
                                .constant(nullValue(newNativeReturn)));
            }
View Full Code Here


        MethodHandle mh = null;
        if (method.getNativeCall() != null) {
            DynamicMethod.NativeCall nc = method.getNativeCall();
            if (method.getArity().isFixed()) {
                if (method.getArity().getValue() <= 3) {
                    Binder b = Binder.from(site.type());
                    if (!nc.hasContext()) {
                        b.drop(0);
                    }

                    if (nc.hasBlock() && !block) {
                        b.insert(site.type().parameterCount() - 1, Block.NULL_BLOCK);
                    } else if (!nc.hasBlock() && block) {
                        b.drop(site.type().parameterCount() - 2, 1);
                    }


                    if (nc.isStatic()) {
                        if (b.type().parameterCount() == nc.getNativeSignature().length) {
                            mh = b
                                    .cast(nc.getNativeReturn(), nc.getNativeSignature())
                                    .invokeStaticQuiet(MethodHandles.lookup(), nc.getNativeTarget(), nc.getNativeName());
//                            System.out.println(mh);
                        }
                    } else {
//                        System.out.println(b.type());
//                        System.out.println(Arrays.toString(nc.getNativeSignature()));
                        if (b.type().parameterCount() == nc.getNativeSignature().length + 1) {
                            // only threadcontext-receivers right now
                            mh = b
                                    .permute(PERMUTES[arity])
                                    .cast(MethodType.methodType(nc.getNativeReturn(), nc.getNativeTarget(), nc.getNativeSignature()))
                                    .invokeVirtualQuiet(MethodHandles.lookup(), nc.getNativeName());
//                            System.out.println(mh);
                        }
View Full Code Here

        // we can handle this; do remaining transforms and return
        if (returnFilter != null) {
            Class[] newNativeParams = nativeTarget.type().parameterArray();
            Class newNativeReturn = nativeTarget.type().returnType();

            Binder exBinder = Binder
                    .from(newNativeReturn, Throwable.class, newNativeParams)
                    .drop(1, newNativeParams.length)
                    .insert(0, runtime);
            if (nativeReturn != void.class) {
                exBinder = exBinder
                        .filterReturn(Binder
                                .from(newNativeReturn)
                                .constant(nullValue(newNativeReturn)));
            }
View Full Code Here

                .insert(1, cls.getRuntime().getNil())
                .cast(IRubyObject.class, IRubyObject.class, IRubyObject.class)
                .invokeStaticQuiet(lookup(), InvocationLinker.class, "valueOrNil");
       
        if (accessor instanceof FieldVariableAccessor) {
            Binder b = Binder
                    .from(site.type())
                    .permute(2)
                    .filterReturn(filter);
           
            int offset = ((FieldVariableAccessor)accessor).getOffset();
            Class objCls = InvokeDynamicSupport.REIFIED_OBJECT_CLASSES[offset];
            nativeTarget = b
                    .cast(Object.class, objCls)
                    .getFieldQuiet(lookup(), "var" + offset);
        } else {
            nativeTarget = Binder
                    .from(site.type())
View Full Code Here

                .from(IRubyObject.class, Object.class)
                .drop(0)
                .constant(cls.getRuntime().getNil());
       
        if (accessor instanceof FieldVariableAccessor) {
            Binder b = Binder
                    .from(site.type())
                    .permute(2, 3)
                    .filterReturn(filter);
           
            int offset = ((FieldVariableAccessor)accessor).getOffset();
            Class objCls = InvokeDynamicSupport.REIFIED_OBJECT_CLASSES[offset];
            nativeTarget = b
                    .cast(void.class, objCls, Object.class)
                    .invokeStaticQuiet(lookup(), objCls, "setVariableChecked");
        } else {
            nativeTarget = Binder
                    .from(site.type())
View Full Code Here

        if (entry == null) entry = EncodingDB.getAliases().get(encodingName.getBytes());
        if (entry == null) throw new RuntimeException("could not find encoding: " + encodingName);
        encoding = entry.getEncoding();
        ByteList byteList = new ByteList(value.getBytes(RubyEncoding.ISO), encoding);
        MutableCallSite site = new MutableCallSite(type);
        Binder binder = Binder
                .from(RubyString.class, ThreadContext.class)
                .insert(0, arrayOf(MutableCallSite.class, ByteList.class), site, byteList);
        if (name.equals("frozen")) {
            site.setTarget(binder.invokeStaticQuiet(lookup, Bootstrap.class, "frozenString"));
        } else {
            site.setTarget(binder.invokeStaticQuiet(lookup, Bootstrap.class, "string"));
        }

        return site;
    }
View Full Code Here

      Lookup lookup = MethodHandles.lookup();

      MethodHandle originalHandle = lookup.findVirtual(type, method.getName(), description);

      Binder binder = createBinder(method, parameterTypes.length).cast(originalHandle.type());

      return binder.invokeVirtual(lookup, method.getName());
    } catch (Exception e) {
      throw new RuntimeException(e);
    }

  }
View Full Code Here

TOP

Related Classes of com.headius.invokebinder.Binder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.