Package org.jruby.parser

Examples of org.jruby.parser.StaticScope


        YARVMachine ym = new YARVMachine();
       
        Ruby runtime = Ruby.newInstance(System.in, System.out, System.err);
        ThreadContext context = runtime.getCurrentContext();
       
        StaticScope scope = new LocalStaticScope(null);
        scope.setVariables(new String[] {"n", "i", "j", "cur", "k"});
        assertEquals("55", ym.exec(context, scope, getFib(runtime,10)).toString());
       
        IRubyObject fib5k = ym.exec(context, scope, getFib(runtime,5000));
        assertEquals("38789684543883256337019163083259053120821277146462451061605972148955501390440370" +
                "9701082291646221066947929345285888297381348310200895498294036143015691147893836421656" +
View Full Code Here


        compileRoot(node, context, inspector, true, true);
    }

    public void compileRoot(Node node, ScriptCompiler context, ASTInspector inspector, boolean load, boolean main) {
        RootNode rootNode = (RootNode) node;
        StaticScope staticScope = rootNode.getStaticScope();

        context.startScript(staticScope);

        // force static scope to claim restarg at 0, so it only implements the [] version of __file__
        staticScope.setRestArg(-2);

        // create method for toplevel of script
        BodyCompiler methodCompiler = context.startFileMethod(null, staticScope, inspector);

        Node nextNode = rootNode.getBodyNode();
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 = new BlockStaticScope(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

        this.runtimeCache = runtime.getRuntimeCache();
       
        // TOPLEVEL self and a few others want a top-level scope.  We create this one right
        // away and then pass it into top-level parse so it ends up being the top level.
        StaticScope topStaticScope = new LocalStaticScope(null);
        pushScope(new ManyVarsDynamicScope(topStaticScope, null));

        Frame[] stack = frameStack;
        int length = stack.length;
        for (int i = 0; i < length; i++) {
View Full Code Here

    public void preExecuteUnder(RubyModule executeUnderClass, Block block) {
        Frame frame = getCurrentFrame();
       
        pushRubyClass(executeUnderClass);
        DynamicScope scope = getCurrentScope();
        StaticScope sScope = new BlockStaticScope(scope.getStaticScope());
        sScope.setModule(executeUnderClass);
        pushScope(DynamicScope.newDynamicScope(sScope, scope));
        pushCallFrame(frame.getKlazz(), frame.getName(), frame.getSelf(), block);
        getCurrentFrame().setVisibility(getPreviousFrame().getVisibility());
    }
View Full Code Here

    static ManyVarsDynamicScope getManyVarsDynamicScope(ScriptingContainer container, int depth) {
        ManyVarsDynamicScope scope;

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

        DynamicScope currentScope = new ManyVarsDynamicScope(topStaticScope, null);
        String[] names4Injection = container.getVarMap().getLocalVarNames();
        if (names4Injection == null || names4Injection.length == 0) {
            scope =
View Full Code Here

        // which is capable of having a non-empty dynamic scope).
        if (scope == null) {
            scope = DynamicScope.newDynamicScope(staticScope);
        }
       
        StaticScope theStaticScope = scope.getStaticScope();
       
        // Each root node has a top-level scope that we need to push
        context.preScopedBody(scope);
       
        if (theStaticScope.getModule() == null) {
            theStaticScope.setModule(runtime.getObject());
        }

        try {
            return bodyNode.interpret(runtime, context, self, aBlock);
        } finally {
View Full Code Here

        Block block = proc.getBlock();
        block.getBinding().getFrame().setKlazz(this);
        block.getBinding().getFrame().setName(name);
        block.getBinding().setMethod(name);
       
        StaticScope scope = block.getBody().getStaticScope();

        // for zsupers in define_method (blech!) we tell the proc scope to act as the "argument" scope
        scope.makeArgumentScope();

        Arity arity = block.arity();
        // just using required is broken...but no more broken than before zsuper refactoring
        scope.setRequiredArgs(arity.required());

        if(!arity.isFixed()) {
            scope.setRestArg(arity.required());
        }

        return new ProcMethod(this, proc, visibility);
    }
View Full Code Here

     */
    @JRubyMethod(name = "nesting", frame = true, meta = true)
    public static RubyArray nesting(ThreadContext context, IRubyObject recv, Block block) {
        Ruby runtime = context.getRuntime();
        RubyModule object = runtime.getObject();
        StaticScope scope = context.getCurrentScope().getStaticScope();
        RubyArray result = runtime.newArray();
       
        for (StaticScope current = scope; current.getModule() != object; current = current.getPreviousCRefScope()) {
            result.append(current.getModule());
        }
View Full Code Here

        }
    }
   
    @JRubyMethod
    public IRubyObject to_proc(ThreadContext context) {
        StaticScope scope = new LocalStaticScope(null);
       
        BlockBody body = new ContextAwareBlockBody(scope, Arity.OPTIONAL, BlockBody.SINGLE_RESTARG) {
            @Override
            public IRubyObject yield(ThreadContext context, IRubyObject value, Binding binding, Type type) {
                RubyArray array = ArgsUtil.convertToRubyArray(context.getRuntime(), value, false);
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.