Package org.jruby.parser

Examples of org.jruby.parser.StaticScope


    }

    @Override
    public void DefineModuleInstr(DefineModuleInstr definemoduleinstr) {
        IRModuleBody newIRModuleBody = definemoduleinstr.getNewIRModuleBody();
        StaticScope scope = newIRModuleBody.getStaticScope();
        if (scope.getRequiredArgs() > 3 || scope.getRestArg() >= 0 || scope.getOptionalArgs() != 0) {
            throw new RuntimeException("can't compile variable method: " + this);
        }

        String scopeString = RuntimeHelpers.encodeScope(scope);
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 = runtime.getStaticScopeFactory().newLocalScope(null);
        pushScope(new ManyVarsDynamicScope(topStaticScope, null));

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

        popFrame();
    }
   
    public void preBsfApply(String[] names) {
        // FIXME: I think we need these pushed somewhere?
        StaticScope staticScope = runtime.getStaticScopeFactory().newLocalScope(null);
        staticScope.setVariables(names);
        pushFrame();
    }
View Full Code Here

    public void preExecuteUnder(RubyModule executeUnderClass, Block block) {
        Frame frame = getCurrentFrame();
       
        pushRubyClass(executeUnderClass);
        DynamicScope scope = getCurrentScope();
        StaticScope sScope = runtime.getStaticScopeFactory().newBlockScope(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

        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

        return context.runtime.getEncodingService().getEncoding(symbolBytes.getEncoding());
    }
   
    @JRubyMethod
    public IRubyObject to_proc(ThreadContext context) {
        StaticScope scope = context.runtime.getStaticScopeFactory().getDummyScope();
        final CallSite site = new FunctionalCachingCallSite(symbol);
        BlockBody body = new ContextAwareBlockBody(scope, Arity.OPTIONAL, BlockBody.SINGLE_RESTARG) {
            private IRubyObject yieldInner(ThreadContext context, RubyArray array) {
                if (array.isEmpty()) {
                    throw context.runtime.newArgumentError("no receiver given");
View Full Code Here

    private Script tryCompile(Node node, String cachedClassName, JRubyClassLoader classLoader, boolean dump) {
        if (config.getCompileMode() == CompileMode.FORCEIR) {
            final IRScope scope = IRBuilder.createIRBuilder(getIRManager(), is1_9()).buildRoot((RootNode) node);
            final Class compiled = JVMVisitor.compile(this, scope, classLoader);
            final StaticScope staticScope = scope.getStaticScope();
            staticScope.setModule(getTopSelf().getMetaClass());
            return new AbstractScript() {
                public IRubyObject __file__(ThreadContext context, IRubyObject self, IRubyObject[] args, Block block) {
                    try {
                        return (IRubyObject)compiled.getMethod("__script__0", ThreadContext.class, StaticScope.class, IRubyObject.class, Block.class).invoke(null, getCurrentContext(), scope.getStaticScope(), getTopSelf(), block);
                    } catch (InvocationTargetException ite) {
View Full Code Here

            }
            script = (Script)asmCompiler.loadClass(classLoader).newInstance();

            // __file__ method expects its scope at 0, so prepare that here
            // this is only needed for the "gets loop" which skips calling load
            StaticScope rootScope = ((RootNode)node).getStaticScope();
            if (rootScope.getModule() == null) rootScope.setModule(objectClass);
            script.setRootScope(rootScope);

            if (config.isJitLogging()) {
                LOG.info("compiled: " + node.getPosition().getFile());
            }
View Full Code Here

    public static IRubyObject interpretCommonEval(Ruby runtime, String file, int lineNumber, String backtraceName, RootNode rootNode, IRubyObject self, Block block) {
        // SSS FIXME: Is this required here since the IR version cannot change from eval-to-eval? This is much more of a global setting.
        boolean is_1_9 = runtime.is1_9();
        if (is_1_9) IRBuilder.setRubyVersion("1.9");

        StaticScope ss = rootNode.getStaticScope();
        IRScope containingIRScope = getEvalContainerScope(runtime, ss);
        IREvalScript evalScript = IRBuilder.createIRBuilder(runtime.getIRManager(), is_1_9).buildEvalRoot(ss, containingIRScope, file, lineNumber, rootNode);
        evalScript.prepareForInterpretation(false);
//        evalScript.runCompilerPass(new CallSplitter());
        ThreadContext context = runtime.getCurrentContext();
View Full Code Here

                self,
                body);
    }
   
    public static IRubyObject runBeginBlock(ThreadContext context, IRubyObject self, String scopeString, CompiledBlockCallback callback) {
        StaticScope staticScope = decodeScope(context, context.getCurrentStaticScope(), scopeString);
       
        context.preScopedBody(DynamicScope.newDynamicScope(staticScope, context.getCurrentScope()));
       
        Block block = CompiledBlock.newCompiledClosure(context, self, Arity.createArity(0), staticScope, callback, false, BlockBody.ZERO_ARGS);
       
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.