Package org.jruby.runtime

Examples of org.jruby.runtime.DynamicScope


    }
   
    public static void preLoad(ThreadContext context, String[] varNames) {
        StaticScope staticScope = new LocalStaticScope(null, varNames);
        staticScope.setModule(context.getRuntime().getObject());
        DynamicScope scope = DynamicScope.newDynamicScope(staticScope);
       
        // Each root node has a top-level scope that we need to push
        context.preScopedBody(scope);
    }
View Full Code Here


            context.preBsfApply(names);
           
            // FIXME: This is broken.  We are assigning BSF globals as local vars in the top-level
            // scope.  This may be ok, but we are overwriting $~ and $_.  Leaving for now.
            DynamicScope scope = context.getCurrentScope();

            // set global variables
            for (int i = 0, size = args.size(); i < size; i++) {
                scope.setValue(i, JavaEmbedUtils.javaToRuby(runtime, args.get(i)), 0);
            }

          // See eval todo about why this is commented out
            //runtime.setPosition(file, line);
View Full Code Here

                throw runtime.newTypeError("wrong argument type " + scope.getMetaClass() + " (expected Proc/Binding)");
            }
        }

        Binding binding = ((RubyBinding)scope).getBinding();
        DynamicScope evalScope = binding.getDynamicScope().getEvalScope();

        // If no explicit file passed in we will use the bindings location
        if (file == null) file = binding.getFrame().getFile();
        if (lineNumber == -1) lineNumber = binding.getFrame().getLine();
       
        // FIXME:  This determine module is in a strange location and should somehow be in block
        evalScope.getStaticScope().determineModule();

        Frame lastFrame = context.preEvalWithBinding(binding);
        try {
            // Binding provided for scope, use it
            IRubyObject newSelf = binding.getSelf();
View Full Code Here

        int savedLine = context.getLine();

        // no binding, just eval in "current" frame (caller's frame)
        RubyString source = src.convertToString();
       
        DynamicScope evalScope = context.getCurrentScope().getEvalScope();
        evalScope.getStaticScope().determineModule();
       
        try {
            Node node = runtime.parseEval(source.getByteList(), file, evalScope, lineNumber);
           
            return node.interpret(runtime, context, self, Block.NULL_BLOCK);
View Full Code Here

     * @param script The scriptlet to run
     * @returns The result of the eval
     */
    public IRubyObject evalScriptlet(String script) {
        ThreadContext context = getCurrentContext();
        DynamicScope currentScope = context.getCurrentScope();
        ManyVarsDynamicScope newScope = new ManyVarsDynamicScope(new EvalStaticScope(currentScope.getStaticScope()), currentScope);
        Node node = parseEval(script, "<script>", newScope, 0);
       
        try {
            context.preEvalScriptlet(newScope);
            return node.interpret(this, context, context.getFrameSelf(), Block.NULL_BLOCK);
View Full Code Here

        return Node.createList(beginNode, endNode);
    }
   
    @Override
    public IRubyObject interpret(Ruby runtime, ThreadContext context, IRubyObject self, Block aBlock) {
        DynamicScope scope = context.getCurrentScope();
        IRubyObject nil = runtime.getNil();
        int index = getIndex();

        // Make sure the appropriate scope has proper size. See JRUBY-2046.
        DynamicScope flipScope = scope.getFlipScope();
        flipScope.growIfNeeded();
       
        IRubyObject result = flipScope.getValueDepthZeroOrNil(index, nil);
  
        if (exclusive) {
            if (result == null || !result.isTrue()) {
                result = trueIfTrue(runtime, beginNode.interpret(runtime, context, self, aBlock));
                flipScope.setValueDepthZero(result, index);
                return result;
            } else {
                if (endNode.interpret(runtime, context, self, aBlock).isTrue()) {
                    flipScope.setValueDepthZero(runtime.getFalse(), index);
                }
               
                return runtime.getTrue();
            }
        } else {
            if (result == null || !result.isTrue()) {
                if (beginNode.interpret(runtime, context, self, aBlock).isTrue()) {
                    flipScope.setValueDepthZero(falseIfTrue(runtime, endNode.interpret(runtime, context, self, aBlock)), index);
                    return runtime.getTrue();
                }

                return runtime.getFalse();
            } else {
                if (endNode.interpret(runtime, context, self, aBlock).isTrue()) {
                    flipScope.setValueDepthZero(runtime.getFalse(), index);
                }
                return runtime.getTrue();
            }
        }
    }
View Full Code Here

        return iVisitor.visitPreExeNode(this);
    }
   
    @Override
    public IRubyObject interpret(Ruby runtime, ThreadContext context, IRubyObject self, Block aBlock) {
        DynamicScope scope = DynamicScope.newDynamicScope(getScope());
        // Each root node has a top-level scope that we need to push
        context.preScopedBody(scope);

        // FIXME: I use a for block to implement END node because we need a proc which captures
        // its enclosing scope.   ForBlock now represents these node and should be renamed.
View Full Code Here

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

    /**
    *  Description of the RubyMethod
    */
    public void initTopLocalVariables() {
        DynamicScope scope = configuration.getScope();
        currentScope = scope.getStaticScope();
       
        result.setScope(scope);
    }
View Full Code Here

            prepareArguments(context, runtime, args);
            getArity().checkArity(runtime, args);

            if (runtime.hasEventHooks()) traceCall(context, runtime, name);

            DynamicScope scope = context.getCurrentScope();
           
            // Why not setArgValues
            scope.setArgValues(args, args.length);

            return YARVMachine.INSTANCE.exec(context, self, iseq.body);
        } catch (JumpException.ReturnJump rj) {
          if (rj.getTarget() == this) return (IRubyObject) rj.getValue();
           
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.