コード例 #1
0
ファイル: SuperInstr.java プロジェクト: ryfow/jruby
  protected Object interpretSuper(
      ThreadContext context, IRubyObject self, IRubyObject[] args, Block block) {
    // SSS FIXME: We should check in the current module (for instance methods) or the current
    // module's meta class (for class methods)
    //
    // RubyModule currM = context.getCurrentScope().getStaticScope().getModule();
    // RubyModule klazz = (isInstanceMethodSuper) ? currM : currM.getMetaClass();
    //
    // The question is how do we know what this 'super' ought to do?
    // For 'super' that occurs in a method scope, this is easy to figure out.
    // But, what about 'super' that occurs in block scope?  How do we figure that out?
    RubyModule klazz = context.getFrameKlazz();

    // SSS FIXME: Even though we may know the method name in some instances,
    // we are not making use of it here.
    String methodName = context.getCurrentFrame().getName(); // methAddr.getName();

    checkSuperDisabledOrOutOfMethod(context, klazz, methodName);
    RubyClass superClass =
        RuntimeHelpers.findImplementerIfNecessary(self.getMetaClass(), klazz).getSuperClass();
    DynamicMethod method =
        superClass != null ? superClass.searchMethod(methodName) : UndefinedMethod.INSTANCE;

    Object rVal =
        method.isUndefined()
            ? RuntimeHelpers.callMethodMissing(
                context, self, method.getVisibility(), methodName, CallType.SUPER, args, block)
            : method.call(context, self, superClass, methodName, args, block);

    return hasUnusedResult() ? null : rVal;
  }
コード例 #2
0
ファイル: SuperInstr.java プロジェクト: yokolet/jruby
  @Override
  public Object interpret(
      ThreadContext context,
      DynamicScope currDynScope,
      IRubyObject self,
      Object[] temp,
      Block aBlock) {
    // FIXME: Receiver is not being used...should we be retrieving it?
    IRubyObject receiver = (IRubyObject) getReceiver().retrieve(context, self, currDynScope, temp);
    IRubyObject[] args = prepareArguments(context, self, getCallArgs(), currDynScope, temp);
    Block block = prepareBlock(context, self, currDynScope, temp);
    RubyModule klazz = context.getFrameKlazz();
    // SSS FIXME: Even though we may know the method name in some instances,
    // we are not making use of it here.  It is cleaner in the sense of not
    // relying on implicit information whose data flow doesn't show up in the IR.
    String methodName = context.getCurrentFrame().getName(); // methAddr.getName();

    checkSuperDisabledOrOutOfMethod(context, klazz, methodName);
    RubyClass superClass =
        RuntimeHelpers.findImplementerIfNecessary(self.getMetaClass(), klazz).getSuperClass();
    DynamicMethod method =
        superClass != null ? superClass.searchMethod(methodName) : UndefinedMethod.INSTANCE;

    Object rVal =
        method.isUndefined()
            ? RuntimeHelpers.callMethodMissing(
                context, self, method.getVisibility(), methodName, CallType.SUPER, args, block)
            : method.call(context, self, superClass, methodName, args, block);

    return hasUnusedResult() ? null : rVal;
  }
コード例 #3
0
ファイル: RubyZlib.java プロジェクト: headius/jruby-cdc
 @JRubyMethod(name = "gets", optional = 1, writes = FrameField.LASTLINE)
 public IRubyObject gets(ThreadContext context, IRubyObject[] args) throws IOException {
   IRubyObject result = internalGets(args);
   if (!result.isNil()) {
     context.getCurrentFrame().setLastLine(result);
   }
   return result;
 }
コード例 #4
0
ファイル: YieldTwoNode.java プロジェクト: RB-DPR/RB-DPR
 @Override
 public IRubyObject interpret(
     Ruby runtime, ThreadContext context, IRubyObject self, Block aBlock) {
   return context
       .getCurrentFrame()
       .getBlock()
       .yieldSpecific(
           context,
           argument1.interpret(runtime, context, self, aBlock),
           argument2.interpret(runtime, context, self, aBlock));
 }
コード例 #5
0
ファイル: RubyProc.java プロジェクト: graalvm/jrubytruffle
  /**
   * Create a new instance of a Proc object. We override this method (from RubyClass) since we need
   * to deal with special case of Proc.new with no arguments or block arg. In this case, we need to
   * check previous frame for a block to consume.
   */
  @JRubyMethod(name = "new", rest = true, meta = true)
  public static IRubyObject newInstance(
      ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
    // No passed in block, lets check next outer frame for one ('Proc.new')
    if (!block.isGiven()) block = context.getCurrentFrame().getBlock();

    // This metaclass == recv check seems gross, but MRI seems to do the same:
    // if (!proc && ruby_block->block_obj && CLASS_OF(ruby_block->block_obj) == klass) {
    if (block.isGiven()
        && block.getProcObject() != null
        && block.getProcObject().getMetaClass() == recv) {
      return block.getProcObject();
    }

    RubyProc obj = new RubyProc(context.runtime, (RubyClass) recv, Block.Type.PROC);
    obj.setup(block);

    obj.callMethod(context, "initialize", args, block);
    return obj;
  }