Package org.jruby.parser

Examples of org.jruby.parser.StaticScope


        if (value == null) return context.nil;
        return RubyString.newStringShared(context.runtime, value);
    }
   
    public static StaticScope preLoad(ThreadContext context, String[] varNames) {
        StaticScope staticScope = context.runtime.getStaticScopeFactory().newLocalScope(null, varNames);
        preLoadCommon(context, staticScope, false);

        return staticScope;
    }
View Full Code Here


        return staticScope;
    }

    public static StaticScope preLoad(ThreadContext context, String scopeString, boolean wrap) {
        StaticScope staticScope = decodeScope(context, null, scopeString);
        preLoadCommon(context, staticScope, wrap);

        return staticScope;
    }
View Full Code Here

        return decodeScope(context, context.getCurrentStaticScope(), scopeString);
    }

    public static StaticScope decodeScope(ThreadContext context, StaticScope parent, String scopeString) {
        String[][] decodedScope = decodeScopeDescriptor(scopeString);
        StaticScope scope = null;
        switch (StaticScope.Type.valueOf(decodedScope[0][0])) {
            case BLOCK:
                scope = context.runtime.getStaticScopeFactory().newBlockScope(parent, decodedScope[1]);
                break;
            case EVAL:
View Full Code Here

    private static void setAritiesFromDecodedScope(StaticScope scope, String[] scopeElements) {
        scope.setArities(Integer.parseInt(scopeElements[2]), Integer.parseInt(scopeElements[3]), Integer.parseInt(scopeElements[4]));
    }

    public static StaticScope decodeScopeAndDetermineModule(ThreadContext context, StaticScope parent, String scopeString) {
        StaticScope scope = decodeScope(context, parent, scopeString);
        scope.determineModule();

        return scope;
    }
View Full Code Here

        return script;
    }

    public IRScriptBody buildRoot(RootNode rootNode) {
        String file = rootNode.getPosition().getFile();
        StaticScope staticScope = rootNode.getStaticScope();

        // Top-level script!
        IRScriptBody script = new IRScriptBody(manager, file, staticScope);
        addInstr(script, new ReceiveSelfInstr(script.getSelf()));
        // Set %current_scope = <current-scope>
View Full Code Here

    @Override
    protected ScriptAndCode execute(final Ruby runtime, final IRScriptBody scope, JRubyClassLoader classLoader) {
        JVMVisitor visitor;
        byte[] bytecode;
        Class compiled;
        StaticScope _staticScope;
        IRubyObject _runtimeTopSelf;

        Method _compiledMethod;
        try {
            visitor = new JVMVisitor();
            bytecode = visitor.compileToBytecode(scope);
            compiled = visitor.defineFromBytecode(scope, bytecode, classLoader);
            _staticScope = scope.getStaticScope();
            _runtimeTopSelf = runtime.getTopSelf();
            _staticScope.setModule(_runtimeTopSelf.getMetaClass());

            _compiledMethod = compiled.getMethod("__script__", ThreadContext.class,
                    StaticScope.class, IRubyObject.class, IRubyObject[].class, Block.class, RubyModule.class);
        } catch (NotCompilableException nce) {
            throw nce;
        } catch (Throwable t) {
            throw new NotCompilableException("failed to compile script " + scope.getName(), t);
        }

        final Method compiledMethod = _compiledMethod;
        final StaticScope staticScope = _staticScope;
        final IRubyObject runtimeTopSelf = _runtimeTopSelf;

        Script script = new AbstractScript() {
            @Override
            public IRubyObject __file__(ThreadContext context, IRubyObject self, IRubyObject[] args, Block block) {
View Full Code Here

            .returning(IRubyObject.class)
            .appendArgs(new String[]{"context", "scope", "self", "block", "class"}, ThreadContext.class, StaticScope.class, IRubyObject.class, Block.class, RubyModule.class);

    public static final Signature signatureFor(IRScope method, boolean aritySplit) {
        if (aritySplit) {
            StaticScope argScope = method.getStaticScope();
            if (argScope.isArgumentScope() &&
                    argScope.getOptionalArgs() == 0 &&
                    argScope.getRestArg() == -1 &&
                    !method.receivesKeywordArgs()) {
                // we have only required arguments...emit a signature appropriate to that arity
                String[] args = new String[argScope.getRequiredArgs()];
                Class[] types = Helpers.arrayOf(Class.class, args.length, IRubyObject.class);
                for (int i = 0; i < args.length; i++) {
                    args[i] = "arg" + i;
                }
                return METHOD_SIGNATURE_BASE.insertArgs(3, args, types);
View Full Code Here

    public RubyRootNode parse(RubyContext context, Source source, ParserContext parserContext, MaterializedFrame parentFrame, RubyNode currentNode) {
        // Set up the JRuby parser

        final org.jruby.parser.Parser parser = new org.jruby.parser.Parser(context.getRuntime());

        final StaticScope staticScope = context.getRuntime().getStaticScopeFactory().newLocalScope(null);

        if (parentFrame != null) {
            /*
             * Note that jruby-parser will be mistaken about how deep the existing variables are,
             * but that doesn't matter as we look them up ourselves after being told they're in some
             * parent scope.
             */

            MaterializedFrame frame = parentFrame;

            while (frame != null) {
                for (FrameSlot slot : frame.getFrameDescriptor().getSlots()) {
                    if (slot.getIdentifier() instanceof String) {
                        final String name = (String) slot.getIdentifier();
                        staticScope.addVariableThisScope(name);
                    }
                }

                frame = RubyArguments.getDeclarationFrame(frame.getArguments());
            }
View Full Code Here

        return dispatch("on_args_add_block", arg1, arg2);
    }

    public IRubyObject arg_var(IRubyObject identifier) {
        String name = lexer.getIdent();
        StaticScope current = getCurrentScope();

        // Multiple _ arguments are allowed.  To not screw with tons of arity
        // issues in our runtime we will allocate unnamed bogus vars so things
        // still work. MRI does not use name as intern'd value so they don't
        // have this issue.
        if (name == "_") {
            int count = 0;
            while (current.exists(name) >= 0) {
                name = "_$" + count++;
            }
        }
       
        current.addVariableThisScope(name);
               
        return identifier;
    }
View Full Code Here

    public IRubyObject shadowing_lvar(IRubyObject identifier) {
       String name = lexer.getIdent();

        if (name == "_") return identifier;

        StaticScope current = getCurrentScope();
        if (current.isBlockScope()) {
            if (current.exists(name) >= 0) yyerror("duplicated argument name");
           
            if (lexer.isVerbose() && current.isDefined(name) >= 0) {
                lexer.warning("shadowing outer local variable - " + name);
            }
        } else if (current.exists(name) >= 0) {
            yyerror("duplicated argument name");
        }

        return identifier;
    }   
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.