Esempio n. 1
0
 @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));
 }
Esempio n. 2
0
  @Override
  public IRubyObject interpret(
      Ruby runtime, ThreadContext context, IRubyObject self, Block aBlock) {
    IRubyObject result = firstNode.interpret(runtime, context, self, aBlock);

    if (!result.isTrue()) {
      result = secondNode.interpret(runtime, context, self, aBlock);
    }

    return result;
  }
Esempio n. 3
0
  @Override
  public IRubyObject interpret(
      Ruby runtime, ThreadContext context, IRubyObject self, Block aBlock) {
    IRubyObject receiver = getReceiverNode().interpret(runtime, context, self, aBlock);

    return callAdapter.callIter(
        context,
        self,
        receiver,
        arg1.interpret(runtime, context, self, aBlock),
        arg2.interpret(runtime, context, self, aBlock),
        Helpers.getBlock(context, self, iterNode));
  }
Esempio n. 4
0
  @Override
  public IRubyObject interpret(
      Ruby runtime, ThreadContext context, IRubyObject self, Block aBlock) {
    Block block =
        SharedScopeBlock.newInterpretedSharedScopeClosure(
            context, this, context.getCurrentScope(), self);

    try {
      while (true) {
        try {
          String savedFile = context.getFile();
          int savedLine = context.getLine();

          IRubyObject recv = null;
          try {
            recv = iterNode.interpret(runtime, context, self, aBlock);
          } finally {
            context.setFileAndLine(savedFile, savedLine);
          }

          return callAdapter.call(context, self, recv, block);
        } catch (JumpException.RetryJump rj) {
          // do nothing, allow loop to retry
        }
      }
    } catch (JumpException.BreakJump bj) {
      return (IRubyObject) bj.getValue();
    }
  }
Esempio n. 5
0
  @Override
  public IRubyObject interpret(
      Ruby runtime, ThreadContext context, IRubyObject self, Block aBlock) {
    // Serialization killed our dynamic scope.  We can just create an empty one
    // since serialization cannot serialize an eval (which is the only thing
    // which is capable of having a non-empty dynamic scope).
    if (scope == null) {
      scope = DynamicScope.newDynamicScope(staticScope);
    }

    StaticScope theStaticScope = scope.getStaticScope();

    // Each root node has a top-level scope that we need to push
    context.preScopedBody(scope);

    if (theStaticScope.getModule() == null) {
      theStaticScope.setModule(runtime.getObject());
    }

    try {
      return bodyNode.interpret(runtime, context, self, aBlock);
    } finally {
      context.postScopedBody();
    }
  }
Esempio n. 6
0
 public static IRubyObject INTERPRET_METHOD(
     Ruby runtime,
     ThreadContext context,
     String file,
     int line,
     RubyModule implClass,
     Node node,
     String name,
     IRubyObject self,
     Block block,
     boolean isTraceable) {
   try {
     ThreadContext.pushBacktrace(context, name, file, line);
     if (isTraceable) methodPreTrace(runtime, context, name, implClass);
     return node.interpret(runtime, context, self, block);
   } finally {
     if (isTraceable) {
       try {
         methodPostTrace(runtime, context, name, implClass);
       } finally {
         ThreadContext.popBacktrace(context);
       }
     } else {
       ThreadContext.popBacktrace(context);
     }
   }
 }
Esempio n. 7
0
 public static IRubyObject INTERPRET_EVAL(
     Ruby runtime, ThreadContext context, Node node, String name, IRubyObject self, Block block) {
   try {
     ThreadContext.pushBacktrace(context, name, node.getPosition());
     return node.interpret(runtime, context, self, block);
   } finally {
     ThreadContext.popBacktrace(context);
   }
 }
Esempio n. 8
0
  private static Block getBlockPassBlock(
      Node blockNode, Ruby runtime, ThreadContext context, IRubyObject self, Block currentBlock) {
    Node bodyNode = ((BlockPassNode) blockNode).getBodyNode();
    IRubyObject proc;
    if (bodyNode == null) {
      proc = runtime.getNil();
    } else {
      proc = bodyNode.interpret(runtime, context, self, currentBlock);
    }

    return Helpers.getBlockFromBlockPassBody(proc, currentBlock);
  }
Esempio n. 9
0
 public static IRubyObject INTERPRET_BLOCK(
     Ruby runtime,
     ThreadContext context,
     String file,
     int line,
     Node node,
     String name,
     IRubyObject self,
     Block block) {
   try {
     ThreadContext.pushBacktrace(context, name, file, line);
     blockPreTrace(runtime, context, name, self.getType());
     return node.interpret(runtime, context, self, block);
   } finally {
     blockPostTrace(runtime, context, name, self.getType());
     ThreadContext.popBacktrace(context);
   }
 }
Esempio n. 10
0
  public static IRubyObject[] setupArgs(
      Ruby runtime, ThreadContext context, Node node, IRubyObject self, Block aBlock) {
    if (node == null) return IRubyObject.NULL_ARRAY;

    if (node instanceof ArrayNode) {
      ArrayNode argsArrayNode = (ArrayNode) node;
      String savedFile = context.getFile();
      int savedLine = context.getLine();
      int size = argsArrayNode.size();
      IRubyObject[] argsArray = new IRubyObject[size];

      for (int i = 0; i < size; i++) {
        argsArray[i] = argsArrayNode.get(i).interpret(runtime, context, self, aBlock);
      }

      context.setFileAndLine(savedFile, savedLine);

      return argsArray;
    }

    return ArgsUtil.convertToJavaArray(node.interpret(runtime, context, self, aBlock));
  }
Esempio n. 11
0
 @Override
 public IRubyObject interpret(
     Ruby runtime, ThreadContext context, IRubyObject self, Block aBlock) {
   return RuntimeHelpers.splatValue(node.interpret(runtime, context, self, aBlock));
 }