Package com.headius.invokebinder

Examples of com.headius.invokebinder.SmartHandle


                curry = true;
            }

            site.addType(selfClass.id);
           
            SmartHandle test;
            SmartBinder selfTest = SmartBinder
                                          .from(site.signature().asFold(boolean.class))
                                          .permute("self");
           
            if (self instanceof RubySymbol ||
View Full Code Here


                    }
                }
            }

            if (rewriteStackTrace) {
                SmartHandle rewriteHandle = SmartBinder.from(lookup(), site.signature().insertArg(0, "throwable", Throwable.class))
                        .permute("throwable")
                        .append("runtime", method.getImplementationClass().getRuntime())
                        .invokeStaticQuiet(lookup(), Helpers.class, "rewriteStackTraceAndThrow");

                nativeTarget = catchException(nativeTarget, Throwable.class, rewriteHandle.handle());
            }
        }
       
        return nativeTarget;
    }
View Full Code Here

                clearTypes();
            }

            addType(testClass.id);

            SmartHandle test;
            SmartBinder selfTest = SmartBinder
                    .from(signature.asFold(boolean.class))
                    .permute("self");

            if (self instanceof RubySymbol ||
                    self instanceof RubyFixnum ||
                    self instanceof RubyFloat ||
                    self instanceof RubyNil ||
                    self instanceof RubyBoolean.True ||
                    self instanceof RubyBoolean.False) {

                test = selfTest
                        .insert(1, "selfJavaType", self.getClass())
                        .cast(boolean.class, Object.class, Class.class)
                        .invoke(TEST_CLASS);

            } else {

                test = SmartBinder
                        .from(signature.changeReturn(boolean.class))
                        .permute("self")
                        .insert(0, "selfClass", RubyClass.class, testClass)
                        .invokeStaticQuiet(Bootstrap.LOOKUP, Bootstrap.class, "testType");
            }

            gwt = MethodHandles.guardWithTest(test.handle(), target, fallback);

            // wrap in switchpoint for mutation invalidation
            gwt = switchPoint.guardWithTest(gwt, fallback);

            setTarget(gwt);
View Full Code Here

            MethodNodes methodNodes) {
        Class scriptClass = scriptObject.getClass();

        try {
            MethodHandle[] targets = new MethodHandle[5];
            SmartHandle directCall;
            int specificArity = -1;

            // acquire handle to the actual method body
            if (scope.getRestArg() >= 0 || scope.getOptionalArgs() > 0 || scope.getRequiredArgs() > 3) {
                // variable arity method (has optional, rest, or more args than we can splat)
                directCall = SmartBinder
                        .from(VARIABLE_ARITY_SIGNATURE.prependArg("script", scriptClass))
                        .invokeStaticQuiet(LOOKUP, scriptClass, javaName)
                        .bindTo(scriptObject);
            } else {
                // specific arity method (less than 4 required args only)
                specificArity = scope.getRequiredArgs();

                directCall = SmartBinder
                        .from(SPECIFIC_ARITY_SIGNATURES[specificArity].prependArg("script", scriptClass))
                        .invokeStaticQuiet(LOOKUP, scriptClass, javaName)
                        .bindTo(scriptObject);
            }

            // wrap with framing logic if needed
            if (!callConfig.isNoop()) {
                directCall = SmartHandle
                        .from(directCall.signature(), InvocationLinker.wrapWithFraming(directCall.signature(), callConfig, implementationClass, rubyName, directCall.handle(), scope));
            }

            // provide a variable-arity path for specific-arity target
            SmartHandle variableCall;
            if (specificArity >= 0) {
                SmartHandle arityCheck = SmartBinder
                        .from(ARITY_CHECK_FOLD)
                        .append(new String[]{"min", "max"}, new Class[]{int.class, int.class}, specificArity, specificArity)
                        .cast(ARITY_CHECK_SIGNATURE)
                        .invokeStaticQuiet(LOOKUP, Arity.class, "checkArgumentCount");
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);
           
            // convert all specific-arity handles into varargs handles
            MethodHandle[] varargsTargets = new MethodHandle[4];
            for (int i = 0; i < 4; i++) {
                // TODO arity error
                if (targets[i] == null) continue;
                if (i == 0) {
                    varargsTargets[i] = MethodHandles.dropArguments(targets[i], 2, IRubyObject[].class);
                } else {
                    varargsTargets[i] = SmartBinder
                            .from(VARIABLE_ARITY_SIGNATURE)
                            .permute("context", "self", "block", "args")
                            .spread("arg", i)
                            .permute("context", "self", "arg*", "block")
                            .invoke(targets[i]).handle();
                }
            }
           
            SmartHandle HANDLE_GETTER = SmartBinder
                    .from(Signature.returning(MethodHandle.class).appendArg("targets", MethodHandle[].class).appendArg("arity", int.class))
                    .arrayGet();
           
            SmartHandle handleLookup = SmartBinder
                    .from(Signature.returning(MethodHandle.class).appendArg("args", IRubyObject[].class))
                    .filterReturn(HANDLE_GETTER.bindTo(varargsTargets))
                    .cast(int.class, Object.class)
                    .invokeStaticQuiet(LOOKUP, Array.class, "getLength");
           
            SmartHandle variableCall = SmartBinder
                    .from(VARIABLE_ARITY_SIGNATURE)
                    .fold("handle", handleLookup)
                    .invoker();
           
            targets[4] = variableCall.handle();
        }
       
       
        // TODO: tracing
       
View Full Code Here

TOP

Related Classes of com.headius.invokebinder.SmartHandle

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.