Start line:  
End line:  

Snippet Preview

Snippet HTML Code

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

MethodBodyCompiler is the base compiler for all method bodies.
 
 public class MethodBodyCompiler extends RootScopedBodyCompiler {
     protected boolean specificArity;
 
     public MethodBodyCompiler(StandardASMCompiler scriptCompilerString rubyNameString javaNameASTInspector inspectorStaticScope scope) {
         super(scriptCompilerjavaNamerubyNameinspectorscope);
     }
 
     public boolean isSpecificArity() {
         return ;
     }
 
     @Override
     public String getSignature() {
         if (shouldUseBoxedArgs()) {
              = false;
             return StandardASMCompiler.getStaticMethodSignature(.getClassname(), 4);
         } else {
              = true;
             return StandardASMCompiler.getStaticMethodSignature(.getClassname(), .getRequiredArgs());
         }
     }
 
     @Override
     protected void createVariableCompiler() {
         if ( == null) {
         } else if (.hasClosure() || .hasScopeAwareMethods()) {
         } else {
         }
     }
 
     @Override
     public void beginMethod(CompilerCallback argsStaticScope scope) {
         .start();
 
         .beginMethod(argsscope);
 
         // visit a label to start scoping for local vars in this method
         .label();
     }
 
     @Override
     public void endBody() {
         // return last value from execution
         .areturn();
 
         // end of variable scope
         .label();
 
         // method is done, declare all variables
         
         // Define the annotation for the method
         AnnotationVisitor annotation = .visitAnnotation(ci(JRubyMethod.class), true);
         annotation.visit("name");
         annotation.visit("frame"true);
         annotation.visit("required".getRequiredArgs());
         annotation.visit("optional".getOptionalArgs());
         annotation.visit("rest".getRestArg());
         // TODO: reads/writes from frame
         // TODO: information on scoping
         // TODO: visibility?
 
         .end();
         if () {
             
              = new SkinnyMethodAdapter(
                     .getClassVisitor(),
                     ACC_PUBLIC | ACC_STATIC | ACC_SYNTHETIC,
                     ,
                     StandardASMCompiler.getStaticMethodSignature(.getClassname(), 4),
                     null,
                     null);
             .start();
 
             // check arity in the variable-arity version
             .aload(1);
             .aload(3);
             .pushInt(.getRequiredArgs());
             invokeUtilityMethod("checkArgumentCount"sig(void.classThreadContext.classIRubyObject[].classint.class));
            loadThis();
            loadThreadContext();
            loadSelf();
            for (int i = 0; i < .getRequiredArgs(); i++) {
                .aload(.);
                .ldc(i);
                .arrayload();
            }
            .aload(. + 1);
            // load block from [] version of method
            .areturn();
            .end();
        }
    }
    @Override
    public void performReturn() {
        // normal return for method body. return jump for within a begin/rescue/ensure
        if () {
            loadThreadContext();
            invokeUtilityMethod("throwReturnJump"sig(IRubyObject.classIRubyObject.classThreadContext.class));
        } else {
            .areturn();
        }
    }
    @Override
    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));
        }
    }
    @Override
    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));
        }
    }
    @Override
    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));
        }
    }
    public boolean isSimpleRoot() {
        return !;
    }
New to GrepCode? Check out our FAQ X