コード例 #1
0
ファイル: ArrayLiteralNode.java プロジェクト: byteit101/jruby
 @ExplodeLoop
 @Override
 public void executeVoid(VirtualFrame frame) {
   for (RubyNode value : values) {
     value.executeVoid(frame);
   }
 }
コード例 #2
0
  @Override
  public Object execute(VirtualFrame frame) {
    if (optimizedProfile.profile(RubyArguments.isKwOptimized(frame.getArguments()))) {
      Object kwarg =
          argumentValueProfile.profile(
              RubyArguments.getOptimizedKeywordArgument(frame.getArguments(), kwIndex));

      if (defaultProfile.profile(
          kwarg instanceof OptionalKeywordArgMissingNode.OptionalKeywordArgMissing)) {
        return defaultValue.execute(frame);
      } else {
        return kwarg;
      }
    } else {
      final RubyHash hash = RubyArguments.getUserKeywordsHash(frame.getArguments(), minimum);

      if (defaultProfile.profile(hash == null)) {
        return defaultValue.execute(frame);
      }

      Object value = lookupKeywordInHash(hash);

      if (defaultProfile.profile(value == null)) {
        return defaultValue.execute(frame);
      }

      return value;
    }
  }
コード例 #3
0
ファイル: EnsureNode.java プロジェクト: trejkaz/jruby
 @Override
 public void executeVoid(VirtualFrame frame) {
   try {
     tryPart.executeVoid(frame);
   } finally {
     ensurePart.executeVoid(frame);
   }
 }
コード例 #4
0
ファイル: EnsureNode.java プロジェクト: trejkaz/jruby
 @Override
 public Object execute(VirtualFrame frame) {
   try {
     return tryPart.execute(frame);
   } finally {
     ensurePart.executeVoid(frame);
   }
 }
コード例 #5
0
ファイル: ModuleFields.java プロジェクト: raeoks/jruby
  // TODO CS 20-Aug-15 this needs to go
  public static boolean verySlowIsFrozen(RubyContext context, Object object) {
    final RubyNode node =
        IsFrozenNodeGen.create(context, null, new LiteralNode(context, null, object));
    new Node() {
      @Child RubyNode child = node;
    }.adoptChildren();

    return (boolean) node.execute(null);
  }
コード例 #6
0
ファイル: ArrayLiteralNode.java プロジェクト: byteit101/jruby
  @ExplodeLoop
  @Override
  public Object isDefined(VirtualFrame frame) {
    for (RubyNode value : values) {
      if (value.isDefined(frame) == getContext().getCoreLibrary().getNilObject()) {
        return getContext().getCoreLibrary().getNilObject();
      }
    }

    return super.isDefined(frame);
  }
コード例 #7
0
ファイル: MethodTranslator.java プロジェクト: danshep/jruby
  private RubyNode composeBody(RubyNode prelude, RubyNode body) {
    final SourceSection sourceSection =
        SequenceNode.enclosing(prelude.getSourceSection(), body.getSourceSection());

    body = SequenceNode.sequence(context, sourceSection, prelude, body);

    if (environment.getFlipFlopStates().size() > 0) {
      body = SequenceNode.sequence(context, sourceSection, initFlipFlopStates(sourceSection), body);
    }

    return body;
  }
コード例 #8
0
ファイル: MethodTranslator.java プロジェクト: danshep/jruby
  public RubyNode doCompileMethodBody(
      SourceSection sourceSection,
      String methodName,
      org.jruby.ast.Node bodyNode,
      SharedMethodInfo sharedMethodInfo) {
    declareArguments(sourceSection, methodName, sharedMethodInfo);
    final Arity arity = getArity(argsNode);

    final LoadArgumentsTranslator loadArgumentsTranslator =
        new LoadArgumentsTranslator(currentNode, context, source, false, this);
    final RubyNode loadArguments = argsNode.accept(loadArgumentsTranslator);

    RubyNode body;

    parentSourceSection.push(sourceSection);
    try {
      body = translateNodeOrNil(sourceSection, bodyNode);
    } finally {
      parentSourceSection.pop();
    }

    final RubyNode prelude;

    if (usesRubiniusPrimitive) {
      // Use Rubinius.primitive seems to turn off arity checking. See Time.from_array for example.
      prelude = loadArguments;
    } else {
      prelude =
          SequenceNode.sequence(
              context,
              sourceSection,
              CheckArityNode.create(context, sourceSection, arity),
              loadArguments);
    }

    body = SequenceNode.sequence(context, body.getSourceSection(), prelude, body);

    if (environment.getFlipFlopStates().size() > 0) {
      body =
          SequenceNode.sequence(
              context, body.getSourceSection(), initFlipFlopStates(sourceSection), body);
    }

    body =
        new CatchForMethodNode(context, body.getSourceSection(), body, environment.getReturnID());

    // TODO(CS, 10-Jan-15) why do we only translate exceptions in methods and not blocks?
    body = new ExceptionTranslatingNode(context, body.getSourceSection(), body);
    return body;
  }
コード例 #9
0
ファイル: WriteConstantNode.java プロジェクト: jvshahid/jruby
  @Override
  public Object execute(VirtualFrame frame) {
    // TODO(cs): can module ever not evaluate to a RubyModule?

    final RubyModule moduleObject = (RubyModule) module.execute(frame);

    final Object rhsValue = rhs.execute(frame);

    assert rhsValue != null;
    assert !(rhsValue instanceof String);

    moduleObject.setModuleConstant(name, rhsValue);

    return rhsValue;
  }
コード例 #10
0
ファイル: TryNode.java プロジェクト: godfat/jruby
  @Override
  public Object execute(VirtualFrame frame) {
    while (true) {
      getContext().getSafepointManager().poll();

      Object result;

      try {
        result = tryPart.execute(frame);
      } catch (ControlFlowException exception) {
        controlFlowProfile.enter();
        throw exception;
      } catch (RaiseException exception) {
        raiseExceptionProfile.enter();

        try {
          return handleException(frame, exception);
        } catch (RetryException e) {
          continue;
        }
      } finally {
        clearExceptionVariableNode.execute(frame);
      }

      elseProfile.enter();
      elsePart.executeVoid(frame);
      return result;
    }
  }
コード例 #11
0
ファイル: RubyFiber.java プロジェクト: jhominal/jruby
  /**
   * Send the Java thread that represents this fiber to sleep until it recieves a resume or exit
   * message. On entry, assumes that the GIL is not held. On exit, holding the GIL.
   */
  public Object waitForResume() {
    RubyNode.notDesignedForCompilation();

    FiberMessage message = null;

    do {
      try {
        // TODO(cs) what is a suitable timeout?
        message = messageQueue.poll(1, TimeUnit.SECONDS);
      } catch (InterruptedException e) {
        // Poll again
      }
    } while (message == null);

    if (message instanceof FiberExitMessage) {
      throw new FiberExitException();
    }

    final FiberResumeMessage resumeMessage = (FiberResumeMessage) message;

    threadManager.enterGlobalLock(resumeMessage.getThread());

    fiberManager.setCurrentFiber(this);

    lastResumedByFiber = resumeMessage.getSendingFiber();
    return resumeMessage.getArg();
  }
コード例 #12
0
ファイル: RubyFiber.java プロジェクト: jhominal/jruby
  public void initialize(RubyProc block) {
    RubyNode.notDesignedForCompilation();

    final RubyFiber finalFiber = this;
    final RubyProc finalBlock = block;

    new Thread(
            new Runnable() {

              @Override
              public void run() {
                fiberManager.registerFiber(finalFiber);

                try {
                  try {
                    final Object arg = finalFiber.waitForResume();
                    final Object result = finalBlock.rootCall(arg);
                    finalFiber.lastResumedByFiber.resume(finalFiber, result);
                  } catch (FiberExitException e) {
                    // Naturally exit the thread on catching this
                  }
                } finally {
                  fiberManager.unregisterFiber(finalFiber);
                }
              }
            })
        .start();
  }
コード例 #13
0
ファイル: AddMethodNode.java プロジェクト: jhominal/jruby
  @Override
  public RubySymbol execute(VirtualFrame frame) {
    notDesignedForCompilation();

    final Object receiverObject = receiver.execute(frame);

    final RubyMethod methodObject = (RubyMethod) method.execute(frame);

    RubyModule module;

    if (receiverObject instanceof RubyModule) {
      module = (RubyModule) receiverObject;
    } else {
      module = ((RubyBasicObject) receiverObject).getSingletonClass(this);
    }

    final RubyMethod methodWithDeclaringModule = methodObject.withDeclaringModule(module);

    if (moduleFunctionFlag(frame)) {
      module.addMethod(this, methodWithDeclaringModule.withVisibility(Visibility.PRIVATE));
      module
          .getSingletonClass(this)
          .addMethod(this, methodWithDeclaringModule.withVisibility(Visibility.PUBLIC));
    } else {
      module.addMethod(this, methodWithDeclaringModule);
    }

    return getContext().newSymbol(method.getName());
  }
コード例 #14
0
ファイル: AddMethodNode.java プロジェクト: rthbound/jruby
  @Override
  public DynamicObject execute(VirtualFrame frame) {
    CompilerDirectives.transferToInterpreter();

    final Object receiverObject = receiver.execute(frame);

    final InternalMethod methodObject = (InternalMethod) methodNode.execute(frame);

    final DynamicObject module = (DynamicObject) receiverObject;
    assert RubyGuards.isRubyModule(module);

    final Visibility visibility = getVisibility(frame, methodObject.getName());
    final InternalMethod method =
        methodObject.withDeclaringModule(module).withVisibility(visibility);

    if (method.getVisibility() == Visibility.MODULE_FUNCTION) {
      Layouts.MODULE.getFields(module).addMethod(this, method.withVisibility(Visibility.PRIVATE));
      Layouts.MODULE
          .getFields(singletonClassNode.executeSingletonClass(module))
          .addMethod(this, method.withVisibility(Visibility.PUBLIC));
    } else {
      Layouts.MODULE.getFields(module).addMethod(this, method);
    }

    return getSymbol(method.getName());
  }
コード例 #15
0
ファイル: IfNode.java プロジェクト: byteit101/jruby
 @Override
 public Object execute(VirtualFrame frame) {
   if (CompilerDirectives.injectBranchProbability(
       getBranchProbability(), condition.executeBoolean(frame))) {
     if (CompilerDirectives.inInterpreter()) {
       thenCount++;
     }
     thenProfile.enter();
     return thenBody.execute(frame);
   } else {
     if (CompilerDirectives.inInterpreter()) {
       elseCount++;
     }
     elseProfile.enter();
     return elseBody.execute(frame);
   }
 }
コード例 #16
0
  @ExplodeLoop
  @Override
  public final Object execute(VirtualFrame frame) {
    final Object self = RubyArguments.getSelf(frame.getArguments());

    // Execute the arguments

    final Object[] argumentsObjects = new Object[arguments.length];

    CompilerAsserts.compilationConstant(arguments.length);
    for (int i = 0; i < arguments.length; i++) {
      argumentsObjects[i] = arguments[i].execute(frame);
    }

    // Execute the block

    RubyProc blockObject;

    if (block != null) {
      final Object blockTempObject = block.execute(frame);

      if (blockTempObject instanceof RubyNilClass) {
        blockObject = null;
      } else {
        blockObject = (RubyProc) blockTempObject;
      }
    } else {
      blockObject = null;
    }

    // Check we have a method and the module is unmodified

    if (!guard(frame, self)) {
      CompilerDirectives.transferToInterpreterAndInvalidate();
      lookup(frame);
    }

    // Call the method

    if (isSplatted) {
      // TODO(CS): need something better to splat the arguments array
      notDesignedForCompilation();
      final RubyArray argumentsArray = (RubyArray) argumentsObjects[0];
      return callNode.call(
          frame,
          RubyArguments.pack(
              superMethod,
              superMethod.getDeclarationFrame(),
              self,
              blockObject,
              argumentsArray.slowToArray()));
    } else {
      return callNode.call(
          frame,
          RubyArguments.pack(
              superMethod, superMethod.getDeclarationFrame(), self, blockObject, argumentsObjects));
    }
  }
コード例 #17
0
ファイル: RubyNilClass.java プロジェクト: erippetoe/jruby
  /** Given a reference, produce either {@code nil} or the object. . */
  public static Object instanceOrNil(Object object) {
    RubyNode.notDesignedForCompilation();

    if (object == null) {
      return NilPlaceholder.INSTANCE;
    } else {
      return object;
    }
  }
コード例 #18
0
 @Override
 public Object execute(VirtualFrame frame) {
   if (RubyArguments.getUserArgumentsCount(frame.getArguments()) < minimum) {
     defaultValueProfile.enter();
     return defaultValue.execute(frame);
   } else {
     return RubyArguments.getUserArgument(frame.getArguments(), index);
   }
 }
コード例 #19
0
ファイル: MethodTranslator.java プロジェクト: danshep/jruby
  public MethodDefinitionNode compileMethodNode(
      SourceSection sourceSection,
      String methodName,
      org.jruby.ast.Node bodyNode,
      SharedMethodInfo sharedMethodInfo) {
    final RubyNode body = compileMethodBody(sourceSection, methodName, bodyNode, sharedMethodInfo);
    final RubyRootNode rootNode =
        new RubyRootNode(
            context,
            considerExtendingMethodToCoverEnd(body.getSourceSection()),
            environment.getFrameDescriptor(),
            environment.getSharedMethodInfo(),
            body,
            environment.needsDeclarationFrame());

    final CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
    return new MethodDefinitionNode(
        context, sourceSection, methodName, environment.getSharedMethodInfo(), callTarget);
  }
コード例 #20
0
ファイル: TryNode.java プロジェクト: jwinter/jruby
  @Override
  public Object execute(VirtualFrame frame) {
    while (true) {
      try {
        final Object result = tryPart.execute(frame);
        elsePart.executeVoid(frame);
        return result;
      } catch (ControlFlowException exception) {
        controlFlowProfile.enter();

        throw exception;
      } catch (RuntimeException exception) {
        CompilerDirectives.transferToInterpreter();

        try {
          return handleException(frame, exception);
        } catch (RetryException e) {
          continue;
        }
      }
    }
  }
コード例 #21
0
ファイル: CatchBreakNode.java プロジェクト: vaseems/jruby
  @Override
  public Object execute(VirtualFrame frame) {
    try {
      return body.execute(frame);
    } catch (BreakException e) {
      breakProfile.enter();

      if (matchingBreakProfile.profile(e.getBreakID() == breakID)) {
        return e.getResult();
      } else {
        throw e;
      }
    }
  }
コード例 #22
0
ファイル: BoxingNode.java プロジェクト: jvshahid/jruby
  @Override
  public RubyBasicObject executeRubyBasicObject(VirtualFrame frame) {
    final Object object = child.execute(frame);

    RubyBasicObject boxedObject;

    if (object instanceof RubyBasicObject) {
      boxedObject = (RubyBasicObject) object;
    } else {
      boxBranch.enter();
      boxedObject = getContext().getCoreLibrary().box(object);
    }

    return boxedObject;
  }
コード例 #23
0
ファイル: RubyFiber.java プロジェクト: jhominal/jruby
  /**
   * Send a message to a fiber by posting into a message queue. Doesn't explicitly notify the Java
   * thread (although the queue implementation may) and doesn't wait for the message to be received.
   * On entry, assumes the the GIL is held. On exit, not holding the GIL.
   */
  public void resume(RubyFiber sendingFiber, Object... args) {
    RubyNode.notDesignedForCompilation();

    Object arg;

    if (args.length == 0) {
      arg = getContext().getCoreLibrary().getNilObject();
    } else if (args.length == 1) {
      arg = args[0];
    } else {
      arg = RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(), args);
    }

    final RubyThread runningThread = threadManager.leaveGlobalLock();

    messageQueue.add(new FiberResumeMessage(runningThread, sendingFiber, arg));
  }
コード例 #24
0
ファイル: OpenModuleNode.java プロジェクト: vaseems/jruby
  @Override
  public Object execute(VirtualFrame frame) {
    CompilerDirectives.transferToInterpreter();

    // TODO(CS): cast
    final DynamicObject module = (DynamicObject) definingModule.execute(frame);

    lexicalScope.setLiveModule(module);
    Layouts.MODULE.getFields(lexicalScope.getParent().getLiveModule()).addLexicalDependent(module);

    final InternalMethod definition =
        definitionMethod.executeMethod(frame).withDeclaringModule(module);
    return callModuleDefinitionNode.call(
        frame,
        definition.getCallTarget(),
        RubyArguments.pack(
            definition, null, null, module, null, DeclarationContext.MODULE, new Object[] {}));
  }
コード例 #25
0
  @Override
  public Object execute(VirtualFrame frame) {
    try {
      assert assertArgumentsShouldBeVisible(frame);

      final Object result = child.execute(frame);

      assert shouldObjectBeVisible(result)
          : "result@" + getEncapsulatingSourceSection().getShortDescription();

      return result;
    } catch (StackOverflowError error) {
      // TODO: we might want to do sth smarter here to avoid consuming frames when we are almost out
      // of it.
      CompilerDirectives.transferToInterpreter();
      throw new RaiseException(translate(error));
    } catch (TruffleFatalException | ThreadExitException exception) {
      throw exception;
    } catch (ControlFlowException exception) {
      controlProfile.enter();
      throw exception;
    } catch (RaiseException exception) {
      rethrowProfile.enter();
      throw exception;
    } catch (MainExitException exception) {
      CompilerDirectives.transferToInterpreter();
      throw exception;
    } catch (ArithmeticException exception) {
      CompilerDirectives.transferToInterpreter();
      throw new RaiseException(translate(exception));
    } catch (UnsupportedSpecializationException exception) {
      CompilerDirectives.transferToInterpreter();
      throw new RaiseException(translate(exception));
    } catch (org.jruby.exceptions.RaiseException e) {
      CompilerDirectives.transferToInterpreter();
      throw new RaiseException(getContext().toTruffle(e.getException(), this));
    } catch (Throwable exception) {
      CompilerDirectives.transferToInterpreter();
      throw new RaiseException(translate(exception));
    }
  }
コード例 #26
0
 @Override
 public void executeVoid(VirtualFrame frame) {
   for (RubyNode child : keyValues) {
     child.executeVoid(frame);
   }
 }
コード例 #27
0
  public static boolean assignableTo(RubyClass thisClass, RubyModule otherClass) {
    RubyNode.notDesignedForCompilation();

    return includesModule(thisClass, otherClass);
  }
コード例 #28
0
ファイル: RubyNilClass.java プロジェクト: erippetoe/jruby
  @Override
  public boolean equals(Object other) {
    RubyNode.notDesignedForCompilation();

    return other instanceof RubyNilClass || other instanceof NilPlaceholder;
  }
コード例 #29
0
ファイル: RubyFiber.java プロジェクト: jhominal/jruby
  public void shutdown() {
    RubyNode.notDesignedForCompilation();

    messageQueue.add(new FiberExitMessage());
  }
コード例 #30
0
ファイル: RubyNilClass.java プロジェクト: erippetoe/jruby
  public static boolean isNil(Object block) {
    RubyNode.notDesignedForCompilation();

    return block == NilPlaceholder.INSTANCE || block instanceof RubyNilClass;
  }