Package org.jruby.parser

Examples of org.jruby.parser.StaticScope


       
        DynamicMethod.NativeCall nativeCall = method.getNativeCall();
       
        try {
            Object scriptObject;
            StaticScope scope = null;
            if (method instanceof CompiledMethod) {
                scriptObject = ((CompiledMethod)method).getScriptObject();
                scope = ((CompiledMethod)method).getStaticScope();
            } else if (method instanceof JittedMethod) {
                scriptObject = ((JittedMethod)method).getScriptObject();
View Full Code Here


    ////////////////////////////////////////////////////////////////////////////

    public static IRubyObject constantFallback(RubyConstantCallSite site,
            AbstractScript script, ThreadContext context, int scopeIndex) {
        SwitchPoint switchPoint = (SwitchPoint)context.runtime.getConstantInvalidator().getData();
        StaticScope scope = script.getScope(scopeIndex);
        IRubyObject value = scope.getConstant(site.name());
       
        if (value != null) {
            if (RubyInstanceConfig.LOG_INDY_CONSTANTS) LOG.info("constant " + site.name() + " bound directly");
           
            MethodHandle valueHandle = constant(IRubyObject.class, value);
            valueHandle = dropArguments(valueHandle, 0, AbstractScript.class, ThreadContext.class);

            MethodHandle fallback = insertArguments(
                    findStatic(InvokeDynamicSupport.class, "constantFallback",
                    methodType(IRubyObject.class, RubyConstantCallSite.class, AbstractScript.class, ThreadContext.class, int.class)),
                    0,
                    site);
            fallback = insertArguments(fallback, 2, scopeIndex);

            MethodHandle gwt = switchPoint.guardWithTest(valueHandle, fallback);
            site.setTarget(gwt);
        } else {
            value = scope.getModule()
                    .callMethod(context, "const_missing", context.runtime.newSymbol(site.name()));
        }
       
        return value;
    }
View Full Code Here

    }

    public static boolean constantBooleanFallback(RubyConstantCallSite site,
            AbstractScript script, ThreadContext context, int scopeIndex) {
        SwitchPoint switchPoint = (SwitchPoint)context.runtime.getConstantInvalidator().getData();
        StaticScope scope = script.getScope(scopeIndex);
        IRubyObject value = scope.getConstant(site.name());
       
        if (value != null) {
            if (RubyInstanceConfig.LOG_INDY_CONSTANTS) LOG.info("constant " + site.name() + " bound directly");
           
            MethodHandle valueHandle = constant(boolean.class, value.isTrue());
            valueHandle = dropArguments(valueHandle, 0, AbstractScript.class, ThreadContext.class);

            MethodHandle fallback = insertArguments(
                    findStatic(InvokeDynamicSupport.class, "constantBooleanFallback",
                    methodType(boolean.class, RubyConstantCallSite.class, AbstractScript.class, ThreadContext.class, int.class)),
                    0,
                    site);
            fallback = insertArguments(fallback, 2, scopeIndex);

            MethodHandle gwt = switchPoint.guardWithTest(valueHandle, fallback);
            site.setTarget(gwt);
        } else {
            value = scope.getModule()
                    .callMethod(context, "const_missing", context.runtime.newSymbol(site.name()));
        }
       
        boolean booleanValue = value.isTrue();
       
View Full Code Here

        site.setTarget(dropArguments(constant(RubyFloat.class, rubyFloat), 0, ThreadContext.class));
        return rubyFloat;
    }
   
    public static StaticScope initStaticScope(MutableCallSite site, AbstractScript script, ThreadContext context, StaticScope parent, String staticScope, int index) {
        StaticScope scope = script.getScope(context, parent, staticScope, index);
        site.setTarget(dropArguments(constant(StaticScope.class, scope), 0, AbstractScript.class, ThreadContext.class, StaticScope.class));
        return scope;
    }
View Full Code Here

        site.setTarget(dropArguments(constant(StaticScope.class, scope), 0, AbstractScript.class, ThreadContext.class, StaticScope.class));
        return scope;
    }
   
    public static StaticScope loadStaticScope(MutableCallSite site, AbstractScript script, int index) {
        StaticScope scope = script.getScope(index);
        site.setTarget(dropArguments(constant(StaticScope.class, scope), 0, AbstractScript.class));
        return scope;
    }
View Full Code Here

        }
        ManyVarsDynamicScope scope;
        StaticScopeFactory scopeFactory = container.getProvider().getRuntime().getStaticScopeFactory();

        // root our parsing scope with a dummy scope
        StaticScope topStaticScope = scopeFactory.newLocalScope(null);
        topStaticScope.setModule(container.getProvider().getRuntime().getObject());

        DynamicScope currentScope = new ManyVarsDynamicScope(topStaticScope, null);
        String[] names4Injection = container.getVarMap().getLocalVarNames();
        StaticScope evalScope = names4Injection == null || names4Injection.length == 0 ?
                scopeFactory.newEvalScope(currentScope.getStaticScope()) :
                scopeFactory.newEvalScope(currentScope.getStaticScope(), names4Injection);
        scope = new ManyVarsDynamicScope(evalScope, currentScope);

        // JRUBY-5501: ensure we've set up a cref for the scope too
View Full Code Here

       
        block = procBlock.cloneBlock();

        if (isThread()) {
            // modify the block with a new backref/lastline-grabbing scope
            StaticScope oldScope = block.getBody().getStaticScope();
            StaticScope newScope = getRuntime().getStaticScopeFactory().newBlockScope(oldScope.getEnclosingScope(), oldScope.getVariables());
            newScope.setBackrefLastlineScope(true);
            newScope.setPreviousCRefScope(oldScope.getPreviousCRefScope());
            newScope.setModule(oldScope.getModule());
            block.getBody().setStaticScope(newScope);
        }

        // force file/line info into the new block's binding
        block.getBinding().setFile(block.getBody().getFile());
View Full Code Here

    public List<String[]> getParameterList() {
        return (method instanceof IRMethod) ? ((IRMethod)method).getArgDesc() : new ArrayList<String[]>();
    }

    private Arity calculateArity() {
        StaticScope s = method.getStaticScope();
        if (s.getOptionalArgs() > 0 || s.getRestArg() >= 0) return Arity.required(s.getRequiredArgs());

        return Arity.createArity(s.getRequiredArgs());
    }
View Full Code Here

    public RuntimeCache() {
    }

    public final StaticScope getScope(ThreadContext context, StaticScope parent, String varNamesDescriptor, int index) {
        StaticScope scope = scopes[index];
        if (scope == null) {
            scopes[index] = scope = RuntimeHelpers.decodeScopeAndDetermineModule(context, parent, varNamesDescriptor);
        }
        return scope;
    }
View Full Code Here

        setHandle(method);
    }

    private Arity calculateArity() {
        StaticScope s = scope;
        if (s.getOptionalArgs() > 0 || s.getRestArg() >= 0) return Arity.required(s.getRequiredArgs());

        return Arity.createArity(s.getRequiredArgs());
    }
View Full Code Here

TOP

Related Classes of org.jruby.parser.StaticScope

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.