Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.jruby.compiler.impl;
  
  import org.jruby.Ruby;
 import static org.jruby.util.CodegenUtils.*;
 import static org.objectweb.asm.Opcodes.*;

Behaviors common to all "root-scoped" bodies are encapsulated in this class. "Root-scoped" refers to any method body which does not inherit a containing variable scope. This includes method bodies and class bodies.
 
 public abstract class RootScopedBodyCompiler extends BaseBodyCompiler {
     private boolean specificArity;
 
     protected RootScopedBodyCompiler(StandardASMCompiler scriptCompilerString friendlyNameString rubyNameASTInspector inspectorStaticScope scopeint scopeIndex) {
         super(scriptCompilerfriendlyNamerubyNameinspectorscopescopeIndex);
     }
 
     public String getSignature() {
         if (shouldUseBoxedArgs()) {
              = false;
             return StandardASMCompiler.getStaticMethodSignature(.getClassname(), 4);
         } else {
              = true;
             return StandardASMCompiler.getStaticMethodSignature(.getClassname(), .getRequiredArgs());
         }
     }
 
     protected void createVariableCompiler() {
         if ( == null) {
         } else if (.hasClosure() || .hasScopeAwareMethods()) {
         } else {
         }
     }
 
     public void beginMethod(CompilerCallback argsStaticScope scope) {
         .start();
 
         .beginMethod(argsscope);
 
         // visit a label to start scoping for local vars in this method
         .label();
     }
 
     public ChainedRootBodyCompiler outline(String methodName) {
         // chain to the next segment of this giant method
 
         // load all arguments straight through
         for (int i = 1; i <= getClosureIndex(); i++) {
             .aload(i);
         }
         // we append an index to ensure two identical method names will not conflict
         methodName = "chained_" + .getAndIncrementMethodIndex() + "_" + methodName;
         .invokestatic(.getClassname(), methodNamegetSignature());
 
         ChainedRootBodyCompiler methodCompiler = new ChainedRootBodyCompiler(methodNamethis);
 
         methodCompiler.beginChainedMethod();
 
         return methodCompiler;
     }
 
     public void endBody() {
         // return last value from execution
         .areturn();
 
         // end of variable scope
         .label();
 
         // method is done, declare all variables
 
         .end();
         if () {
              = new SkinnyMethodAdapter(.getClassVisitor(), ACC_PUBLIC | ACC_STATIC, , StandardASMCompiler.getStaticMethodSignature(.getClassname(), 4), nullnull);
             .start();
 
             // check arity in the variable-arity version
             .aload(1);
             .invokevirtual(p(ThreadContext.class), "getRuntime"sig(Ruby.class));
             .aload(3);
             .pushInt(.getRequiredArgs());
             .pushInt(.getRequiredArgs());
             .invokestatic(p(Arity.class), "checkArgumentCount"sig(int.classRuby.classIRubyObject[].classint.classint.class));
             .pop();
 
             loadThis();
             loadThreadContext();
             loadSelf();
            // FIXME: missing arity check
            for (int i = 0; i < .getRequiredArgs(); i++) {
                .aload(.);
                .ldc(i);
                .arrayload();
            }
            .aload(. + 1);
            // load block from [] version of method
            .areturn();
            .end();
        }
    }
    public void performReturn() {
        if () {
            // returning from rescue, clear $!
            clearErrorInfo();
        }
        
        // normal return for method body. return jump for within a begin/rescue/ensure
        if () {
            loadThreadContext();
            invokeUtilityMethod("throwReturnJump"sig(IRubyObject.classIRubyObject.classThreadContext.class));
        } else {
            .areturn();
        }
    }
    public void issueBreakEvent(CompilerCallback value) {
        if ( != null) {
            value.call(this);
            issueLoopBreak();
        } else if () {
            loadThreadContext();
            value.call(this);
            invokeUtilityMethod("breakJump"sig(IRubyObject.classThreadContext.classIRubyObject.class));
        } else {
            // in method body with no containing loop, issue jump error
            // load runtime and value, issue jump error
            loadRuntime();
            value.call(this);
            invokeUtilityMethod("breakLocalJumpError"sig(IRubyObject.classRuby.classIRubyObject.class));
        }
    }
    public void issueNextEvent(CompilerCallback value) {
        if ( != null) {
            value.call(this);
            issueLoopNext();
        } else if () {
            value.call(this);
            invokeUtilityMethod("nextJump"sig(IRubyObject.classIRubyObject.class));
        } else {
            // in method body with no containing loop, issue jump error
            // load runtime and value, issue jump error
            loadRuntime();
            value.call(this);
            invokeUtilityMethod("nextLocalJumpError"sig(IRubyObject.classRuby.classIRubyObject.class));
        }
    }
    public void issueRedoEvent() {
        if ( != null) {
            issueLoopRedo();
        } else if () {
            invokeUtilityMethod("redoJump"sig(IRubyObject.class));
        } else {
            // in method body with no containing loop, issue jump error
            // load runtime and value, issue jump error
            loadRuntime();
            invokeUtilityMethod("redoLocalJumpError"sig(IRubyObject.classRuby.class));
        }
    }
New to GrepCode? Check out our FAQ X