Package org.jruby.runtime

Examples of org.jruby.runtime.DynamicScope


     *
     */
    public void remove() {
        ThreadContext context = receiver.getRuntime().getCurrentContext();
        try {
            DynamicScope currentScope = context.getCurrentScope();
            ManyVarsDynamicScope scope = (ManyVarsDynamicScope) context.getCurrentScope();
            scope = new ManyVarsDynamicScope(context.runtime.getStaticScopeFactory().newEvalScope(currentScope.getStaticScope()), currentScope);
        } catch (ArrayIndexOutOfBoundsException e) {
            //no context is left.
            //no operation is needed.
        }
    }
View Full Code Here


        // 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
        scope.getStaticScope().determineModule();
       
View Full Code Here

                }*/
                assert frames.size() == scopes.size() : "Frames don't match scopes :S";
                for (int i = 0; i < frames.size(); i++) {
                    Frame frame = frames.get(i);
                    IRubyObject s = selfs.get(i);
                    DynamicScope scope = scopes.get(i);
                    RubyStackTraceElement stackElement = trace[i];
                    StaticScope sScope = scope.getStaticScope();
                    Map<String, Object> var = new HashMap<>();
                    String[] names = sScope.getVariables();
                    IRubyObject[] values = scope.getValues();
                    assert names.length == values.length : "Scope name and value length mismatch";
                    for (int j = 0; j < names.length; j++)
                        var.put(names[j], values[j]);
                    DebugFrame created = info.pushFrame(stackElement.getClassName() + "." + stackElement.getMethodName(),
                            stackElement.getFileName(), stackElement.getLineNumber(), s, var);
View Full Code Here

        // 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
        scope.getStaticScope().determineModule();
        return new EmbedEvalUnitImpl(container, root, scope);
View Full Code Here

    public IRubyObject match_m19(ThreadContext context, IRubyObject str, IRubyObject pos, Block block) {
        return match19Common(context, str, RubyNumeric.num2int(pos), block);
    }

    private IRubyObject match19Common(ThreadContext context, IRubyObject arg, int pos, Block block) {
        DynamicScope scope = context.getCurrentScope();
        if (arg.isNil()) {
            scope.setBackRef(arg);
            return arg;
        }
        Ruby runtime = context.runtime;
        RubyString str = operandCheck(runtime, arg);

        if (matchPos(context, str, pos) < 0) {
            scope.setBackRef(runtime.getNil());
            return runtime.getNil();
        }

        IRubyObject backref = scope.getBackRef(runtime);
        ((RubyMatchData)backref).use();
        if (block.isGiven()) return block.yield(context, backref);
        return backref;
    }
View Full Code Here

    /** rb_reg_search
     */
    public final int search(ThreadContext context, RubyString str, int pos, boolean reverse) {
        check();
        DynamicScope scope = context.getCurrentScope();
        ByteList value = str.getByteList();

        if (pos <= value.getRealSize() && pos >= 0) {
            int realSize = value.getRealSize();
            int begin = value.getBegin();
            Matcher matcher = pattern.matcher(value.getUnsafeBytes(), begin, begin + realSize);

            int result = matcher.search(begin + pos, begin + (reverse ? 0 : realSize), Option.NONE);
            if (result >= 0) {
                updateBackRef(context, str, scope, matcher);
                return result;
            }
        }

        scope.setBackRef(context.runtime.getNil());
        return -1;
    }
View Full Code Here

        return match;
    }

    public final int search19(ThreadContext context, RubyString str, int pos, boolean reverse) {
        check();
        DynamicScope scope = context.getCurrentScope();
        ByteList value = str.getByteList();

        if (pos <= value.getRealSize() && pos >= 0) {
            int realSize = value.getRealSize();
            int begin = value.getBegin();
            Matcher matcher = preparePattern(str).matcher(value.getUnsafeBytes(), begin, begin + realSize);

            int result = matcher.search(begin + pos, begin + (reverse ? 0 : realSize), Option.NONE);
            if (result >= 0) {
                updateBackRef(context, str, scope, matcher).charOffsetUpdated = false;;
                return result;
            }
        }

        scope.setBackRef(context.runtime.getNil());
        return -1;
    }
View Full Code Here

    }

    @Override
    public IRubyObject interpret(Ruby runtime, ThreadContext context, IRubyObject self, Block aBlock) {
        IRubyObject result = super.interpret(runtime, context, self, aBlock);
        DynamicScope scope = context.getCurrentScope();

        RuntimeHelpers.updateScopeWithCaptures(context, scope, scopeOffsets, result);

        return result;
    }
View Full Code Here

            prepare(context, runtime, self, new IRubyObject[] {arg0}, block);
        }
        if (getBlock() != null) processBlockArg(scope, runtime, block);
    }
    public void prepare(ThreadContext context, Ruby runtime, IRubyObject self, IRubyObject arg0, IRubyObject arg1, Block block) {
        DynamicScope scope = context.getCurrentScope();

        if (isSimple) {
            scope.setArgValues(arg0, arg1);
        } else {
            prepare(context, runtime, self, new IRubyObject[] {arg0, arg1}, block);
        }
        if (getBlock() != null) processBlockArg(scope, runtime, block);
    }
View Full Code Here

            prepare(context, runtime, self, new IRubyObject[] {arg0, arg1}, block);
        }
        if (getBlock() != null) processBlockArg(scope, runtime, block);
    }
    public void prepare(ThreadContext context, Ruby runtime, IRubyObject self, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
        DynamicScope scope = context.getCurrentScope();

        if (isSimple) {
            scope.setArgValues(arg0, arg1, arg2);
        } else {
            prepare(context, runtime, self, new IRubyObject[] {arg0, arg1, arg2}, block);
        }
        if (getBlock() != null) processBlockArg(scope, runtime, block);
    }
View Full Code Here

TOP

Related Classes of org.jruby.runtime.DynamicScope

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.