Package com.headius.invokebinder

Examples of com.headius.invokebinder.Signature


    }

    private void emitWithSignatures(IRMethod method, String name) {
        method.setJittedName(name);

        Signature signature = signatureFor(method, false);
        emitScope(method, name, signature, false);
        method.addNativeSignature(-1, signature.type());

        Signature specificSig = signatureFor(method, true);
        if (specificSig != null) {
            emitScope(method, name, specificSig, true);
            method.addNativeSignature(method.getStaticScope().getRequiredArgs(), specificSig.type());
        }
    }
View Full Code Here


            name = baseName + "_" + methodIndex++;
        }
        String clsName = jvm.scriptToClass(method.getFileName());
        jvm.pushscript(clsName, method.getFileName());

        Signature signature = signatureFor(method, false);
        emitScope(method, "__script__", signature, false);

        Handle handle = new Handle(Opcodes.H_INVOKESTATIC, jvm.clsData().clsName, name, sig(signature.type().returnType(), signature.type().parameterArray()));

        jvm.cls().visitEnd();
        jvm.popclass();

        return handle;
View Full Code Here

            name = "METACLASS_" + methodIndex++;
        } else {
            name = baseName + "_" + methodIndex++;
        }

        Signature signature = signatureFor(method, false);
        emitScope(method, name, signature, false);

        return new Handle(Opcodes.H_INVOKESTATIC, jvm.clsData().clsName, name, sig(signature.type().returnType(), signature.type().parameterArray()));
    }
View Full Code Here

    public static IRubyObject handleRedo(JumpException.RedoJump rj, ThreadContext context) {
        throw context.runtime.newLocalJumpError(RubyLocalJumpError.Reason.REDO, context.runtime.getNil(), "unexpected redo");
    }

    public static MethodHandle getFramePre(Signature signature, CallConfiguration callConfig, RubyModule implClass, String name, StaticScope scope) {
        Signature inbound = signature.asFold(void.class);
        SmartBinder binder = SmartBinder
                           .from(inbound);

        switch (callConfig) {
            case FrameFullScopeFull:
View Full Code Here

       
        return null;
    }

    public static MethodHandle getFramePost(Signature signature, CallConfiguration callConfig) {
        Signature inbound = signature.asFold(void.class);
        SmartBinder binder = SmartBinder
                               .from(inbound)
                               .permute("context");
       
        switch (callConfig) {
View Full Code Here

        // if native method returns void, return nil instead
        if (nativeCall.getNativeReturn() == void.class) {
            nativeTarget = filterReturnValue(nativeTarget, constant(IRubyObject.class, runtime.getNil()));
        }

        Signature fullSig = site.fullSignature();
        Signature target;

        if (nativeSig.length > 0 && nativeSig[0] == ThreadContext.class) {
            if (nativeSig[nativeSig.length - 1] == Block.class) {
                target = isStatic ?
                        fullSig.permute("context", "self", "arg*", "block") :
                        fullSig.permute("self", "context", "arg*", "block");
            } else {
                target = isStatic ?
                        fullSig.permute("context", "self", "arg*") :
                        fullSig.permute("self", "context", "arg*");
            }
        } else {
            if (nativeSig.length > 0 && nativeSig[nativeSig.length - 1] == Block.class) {
                target = fullSig.permute("self", "arg*", "block");
            } else {
                target = fullSig.permute("self", "arg*");
            }
        }

        nativeTarget = explicitCastArguments(nativeTarget, target.type());
        nativeTarget = permuteArguments(nativeTarget, fullSig.type(), fullSig.to(target));

        nativeTarget = wrapWithFraming(fullSig, method.getCallConfig(), method.getImplementationClass(), name, nativeTarget, null);

        method.setHandle(nativeTarget);
View Full Code Here

                throw new IndirectBindingException("MH dynamic method does not have needed arity");
            }
           
            if (Options.INVOKEDYNAMIC_LOG_BINDING.load()) 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;           
        }
View Full Code Here

    public InvokeSite(MethodType type, String name, CallType callType) {
        super(type);
        this.methodName = name;
        this.callType = callType;

        Signature startSig;

        if (callType == CallType.SUPER) {
            // super calls receive current class argument, so offsets and signature are different
            startSig = JRubyCallSite.STANDARD_SUPER_SIG;
            argOffset = 4;
        } else {
            startSig = JRubyCallSite.STANDARD_SITE_SIG;
            argOffset = 3;
        }

        int arity;
        if (type.parameterType(type.parameterCount() - 1) == Block.class) {
            arity = type.parameterCount() - (argOffset + 1);

            if (arity == 1 && type.parameterType(argOffset) == IRubyObject[].class) {
                arity = -1;
                startSig = startSig.appendArg("args", IRubyObject[].class);
            } else {
                for (int i = 0; i < arity; i++) {
                    startSig = startSig.appendArg("arg" + i, IRubyObject.class);
                }
            }
            startSig = startSig.appendArg("block", Block.class);
            fullSignature = signature = startSig;
        } else {
            arity = type.parameterCount() - argOffset;

            if (arity == 1 && type.parameterType(argOffset) == IRubyObject[].class) {
                arity = -1;
                startSig = startSig.appendArg("args", IRubyObject[].class);
            } else {
                for (int i = 0; i < arity; i++) {
                    startSig = startSig.appendArg("arg" + i, IRubyObject.class);
                }
            }
            signature = startSig;
            fullSignature = startSig.appendArg("block", Block.class);
        }

        this.arity = arity;

        this.fallback = prepareBinder().invokeVirtualQuiet(Bootstrap.LOOKUP, "invoke");
View Full Code Here

        super(type);

        this.name = name;
        this.callType = callType;

        Signature startSig;
        int argOffset;

        if (callType == CallType.SUPER) {
            // super calls receive current class argument, so offsets and signature are different
            startSig = JRubyCallSite.STANDARD_SUPER_SIG;
            argOffset = 4;
        } else {
            startSig = JRubyCallSite.STANDARD_SITE_SIG;
            argOffset = 3;
        }

        int arity;
        if (type.parameterType(type.parameterCount() - 1) == Block.class) {
            arity = type.parameterCount() - (argOffset + 1);

            if (arity == 1 && type.parameterType(argOffset) == IRubyObject[].class) {
                arity = -1;
                startSig = startSig.appendArg("args", IRubyObject[].class);
            } else {
                for (int i = 0; i < arity; i++) {
                    startSig = startSig.appendArg("arg" + i, IRubyObject.class);
                }
            }
            startSig = startSig.appendArg("block", Block.class);
            fullSignature = signature = startSig;
        } else {
            arity = type.parameterCount() - argOffset;

            if (arity == 1 && type.parameterType(argOffset) == IRubyObject[].class) {
                arity = -1;
                startSig = startSig.appendArg("args", IRubyObject[].class);
            } else {
                for (int i = 0; i < arity; i++) {
                    startSig = startSig.appendArg("arg" + i, IRubyObject.class);
                }
            }
            signature = startSig;
            fullSignature = startSig.appendArg("block", Block.class);
        }

        this.arity = arity;

        this.lookup = lookup;
View Full Code Here

//            checkArity(desc.anno, method, specificArity);

            SmartBinder targetBinder;
            SmartHandle target;
            Signature baseSignature;
            if (specificArity >= 0) {
                baseSignature = SPECIFIC_ARITY_SIGNATURES[specificArity];
            } else {
                baseSignature = VARIABLE_ARITY_SIGNATURE;
            }
           
            targetBinder = SmartBinder.from(baseSignature);
           
            MethodHandle returnFilter = null;
            boolean castReturn = false;
            if (desc.returnClass != IRubyObject.class) {
                if (desc.returnClass == void.class) {
                    returnFilter = MethodHandles.constant(IRubyObject.class, runtime.getNil());
                } else {
                    castReturn = true;
                }
            }
           
            if (desc.isStatic) {
                if (desc.hasContext) {
                    if (desc.hasBlock) {
                        // straight through with no permutation necessary
                    } else {
                        targetBinder = targetBinder.exclude("block");
                    }
                } else {
                    if (desc.hasBlock) {
                        targetBinder = targetBinder.exclude("context");
                    } else {
                        targetBinder = targetBinder.exclude("context", "block");
                    }
                }
               
                if (returnFilter != null) {
                    targetBinder = targetBinder
                            .filterReturn(returnFilter);
                } else if (castReturn) {
                    targetBinder = targetBinder
                            .castReturn(desc.returnClass);
                }
            } else {
                if (desc.hasContext) {
                    if (desc.hasBlock) {
                        targetBinder = targetBinder.permute("self", "context", "arg*", "block");
                    } else {
                        targetBinder = targetBinder.permute("self", "context", "arg*");
                    }
                } else {
                    if (desc.hasBlock) {
                        targetBinder = targetBinder.permute("self", "arg*", "block");
                    } else {
                        targetBinder = targetBinder.permute("self", "arg*");
                    }
                }
               
                if (returnFilter != null) {
                    targetBinder = targetBinder
                            .filterReturn(returnFilter);
                } else if (castReturn) {
                    targetBinder = targetBinder
                            .castReturn(desc.returnClass);
                }
                targetBinder = targetBinder
                        .castArg("self", desc.getDeclaringClass());
            }
           
            if (desc.isStatic) {
                target = targetBinder
                        .invokeStaticQuiet(LOOKUP, desc.getDeclaringClass(), javaMethodName);
            } else {
                target = targetBinder
                        .invokeVirtualQuiet(LOOKUP, javaMethodName);
            }

            CallConfiguration callConfig = CallConfiguration.getCallConfigByAnno(desc.anno);
            if (!callConfig.isNoop()) {
                target = SmartHandle
                        .from(target.signature(), InvocationLinker.wrapWithFraming(baseSignature, callConfig, implementationClass, rubyName, target.handle(), null));
            }
           
            if (specificArity >= 0) {
                targets[specificArity] = target.handle();
            } else {
                targets[4] = target.handle();
            }
        }
       
        if (targets[4] == null) {
            // provide a variable-arity path for specific-arity target
            Signature VARIABLE_ARITY_SIGNATURE = Signature
                    .returning(IRubyObject.class)
                    .appendArg("context", ThreadContext.class)
                    .appendArg("self", IRubyObject.class)
                    .appendArg("args", IRubyObject[].class)
                    .appendArg("block", Block.class);
View Full Code Here

TOP

Related Classes of com.headius.invokebinder.Signature

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.