Exemple #1
0
  @Override
  public Object execute(VirtualFrame frame) {
    while (true) {
      Object result;

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

        try {
          return handleException(frame, exception);
        } catch (RetryException e) {
          getContext().getSafepointManager().poll(this);
          continue;
        }
      } catch (ControlFlowException exception) {
        controlFlowProfile.enter();
        throw exception;
      }

      elseProfile.enter();

      if (elsePart != null) {
        result = elsePart.execute(frame);
      }

      return result;
    }
  }
Exemple #2
0
  @Specialization
  protected Object doInternal(VirtualFrame frame, RPromise x) {
    if (builtinCallNode == null) {
      RNode call = (RNode) x.getRep();
      RNode operand = (RNode) RASTUtils.unwrap(call);

      if (!(operand instanceof RCallNode)) {
        errorProfile.enter();
        throw RError.error(this, RError.Message.INVALID_INTERNAL);
      }

      RCallNode callNode = (RCallNode) operand;
      RNode func = callNode.getFunctionNode();
      String name = ((ReadVariableNode) func).getIdentifier();
      RFunction function = RContext.lookupBuiltin(name);
      if (function == null
          || function.isBuiltin() && function.getRBuiltin().getKind() != RBuiltinKind.INTERNAL) {
        errorProfile.enter();
        if (function == null && notImplemented(name)) {
          throw RInternalError.unimplemented(".Internal " + name);
        }
        throw RError.error(this, RError.Message.NO_SUCH_INTERNAL, name);
      }

      // .Internal function is validated
      CompilerDirectives.transferToInterpreterAndInvalidate();
      builtinCallNode = insert(RCallNode.createInternalCall(callNode, function));
    }
    return builtinCallNode.execute(frame);
  }
 private void verifyDimensions(int[] vectorDimensions) {
   if (vectorDimensions == null) {
     if (isMultiDimension()) {
       errorBranch.enter();
       throw dimensionsError();
     }
   } else {
     if (getDimensions() > vectorDimensions.length || getDimensions() < vectorDimensions.length) {
       errorBranch.enter();
       throw dimensionsError();
     }
   }
 }
 @ExplodeLoop
 public boolean isSupported(Object[] positions) {
   if (positionsCheck.length != positions.length) {
     unsupportedProfile.enter();
     return false;
   }
   for (int i = 0; i < positionsCheck.length; i++) {
     if (!positionsCheck[i].isSupported(positions[i])) {
       unsupportedProfile.enter();
       return false;
     }
   }
   return true;
 }
Exemple #5
0
 @Specialization
 protected Object getDimNames(RAbstractContainer container) {
   controlVisibility();
   RList names;
   if (container instanceof RDataFrame) {
     dataframeProfile.enter();
     names = ((RDataFrame) container).getVector().getDimNames();
   } else if (container instanceof RFactor) {
     factorProfile.enter();
     names = ((RFactor) container).getVector().getDimNames();
   } else {
     otherProfile.enter();
     names = container.getDimNames(attrProfiles);
   }
   return nullProfile.profile(names == null) ? RNull.instance : names;
 }
Exemple #6
0
 @Specialization(guards = {"each > 1", "hasNames(x)"})
 protected RAbstractVector repEachNames(
     RAbstractVector x,
     RAbstractIntVector times,
     int lengthOut,
     int each,
     @Cached("create()") InitAttributesNode initAttributes,
     @Cached("createNames()") SetFixedAttributeNode putNames) {
   if (times.getLength() > 1) {
     errorBranch.enter();
     throw invalidTimes();
   }
   RAbstractVector input = handleEach(x, each);
   RStringVector names = (RStringVector) handleEach(getNames.getNames(x), each);
   RVector<?> r;
   if (lengthOutOrTimes.profile(!RRuntime.isNA(lengthOut))) {
     names = (RStringVector) handleLengthOut(names, lengthOut, false);
     r = handleLengthOut(input, lengthOut, false);
   } else {
     names = (RStringVector) handleTimes(names, times, false);
     r = handleTimes(input, times, false);
   }
   putNames.execute(initAttributes.execute(r), names);
   return r;
 }
Exemple #7
0
 /** Replicate the vector a given number of times. */
 private RVector<?> handleTimes(
     RAbstractVector x, RAbstractIntVector times, boolean copyIfSameSize) {
   if (oneTimeGiven.profile(times.getLength() == 1)) {
     // only one times value is given
     final int howManyTimes = times.getDataAt(0);
     if (howManyTimes < 0) {
       errorBranch.enter();
       throw invalidTimes();
     }
     if (replicateOnce.profile(howManyTimes == 1)) {
       return (RVector<?>) (copyIfSameSize ? x.copy() : x);
     } else {
       return x.copyResized(x.getLength() * howManyTimes, false);
     }
   } else {
     // times is a vector with several elements
     if (x.getLength() != times.getLength()) {
       errorBranch.enter();
       invalidTimes();
     }
     // iterate once over the times vector to determine result vector size
     int resultLength = 0;
     for (int i = 0; i < times.getLength(); i++) {
       int t = times.getDataAt(i);
       if (t < 0) {
         errorBranch.enter();
         throw invalidTimes();
       }
       resultLength += t;
     }
     // create and populate result vector
     RVector<?> r = x.createEmptySameType(resultLength, x.isComplete());
     int wp = 0; // write pointer
     for (int i = 0; i < x.getLength(); i++) {
       for (int j = 0; j < times.getDataAt(i); ++j, ++wp) {
         r.transferElementSameType(wp, x, i);
       }
     }
     return r;
   }
 }
Exemple #8
0
 @Specialization
 public Object callNamedFunctionWithPackage(
     String name, RArgsValuesAndNames args, String packageName) {
   controlVisibility();
   SymbolInfo symbolInfo = DLL.findSymbolInfo(name, packageName);
   if (symbolInfo == null) {
     errorProfile.enter();
     throw RError.error(this, Message.C_SYMBOL_NOT_IN_TABLE, name);
   }
   return RFFIFactory.getRFFI()
       .getCallRFFI()
       .invokeCall(symbolInfo.address, symbolInfo.symbol, args.getArguments());
 }
Exemple #9
0
 @Specialization(guards = {"each > 1", "!hasNames(x)"})
 protected RAbstractVector repEachNoNames(
     RAbstractVector x, RAbstractIntVector times, int lengthOut, int each) {
   if (times.getLength() > 1) {
     errorBranch.enter();
     throw invalidTimes();
   }
   RAbstractVector input = handleEach(x, each);
   if (lengthOutOrTimes.profile(!RRuntime.isNA(lengthOut))) {
     return handleLengthOut(input, lengthOut, false);
   } else {
     return handleTimes(input, times, false);
   }
 }
Exemple #10
0
 @Specialization
 public Object callNamedFunctionWithPackage(
     String name, RArgsValuesAndNames args, String packageName) {
   controlVisibility();
   SymbolInfo symbolInfo = DLL.findSymbolInfo(name, packageName);
   if (symbolInfo == null) {
     errorProfile.enter();
     throw RError.error(this, Message.C_SYMBOL_NOT_IN_TABLE, name);
   }
   Object list = encodeArgumentPairList(args, symbolInfo.symbol);
   // TODO: provide proper values for the CALL, OP and RHO parameters
   return RFFIFactory.getRFFI()
       .getCallRFFI()
       .invokeCall(symbolInfo.address, symbolInfo.symbol, new Object[] {CALL, OP, list, RHO});
 }
Exemple #11
0
 @Specialization(
     guards = {"x.getLength() == 1", "times.getLength() == 1", "each <= 1", "!hasNames(x)"})
 protected RAbstractVector repNoEachNoNamesSimple(
     RAbstractDoubleVector x,
     RAbstractIntVector times,
     int lengthOut,
     @SuppressWarnings("unused") int each) {
   int t = times.getDataAt(0);
   if (t < 0) {
     errorBranch.enter();
     throw invalidTimes();
   }
   int length = lengthOutOrTimes.profile(!RRuntime.isNA(lengthOut)) ? lengthOut : t;
   double[] data = new double[length];
   Arrays.fill(data, x.getDataAt(0));
   return RDataFactory.createDoubleVector(data, !RRuntime.isNA(x.getDataAt(0)));
 }
Exemple #12
0
 @Specialization
 protected RList c(
     String f,
     RArgsValuesAndNames args,
     byte naok,
     byte dup,
     @SuppressWarnings("unused") RMissing rPackage,
     @SuppressWarnings("unused") RMissing encoding, //
     @Cached("create()") BranchProfile errorProfile) {
   controlVisibility();
   SymbolInfo symbolInfo = DLL.findRegisteredSymbolinInDLL(f, null, "");
   if (symbolInfo == null) {
     errorProfile.enter();
     throw RError.error(this, RError.Message.C_SYMBOL_NOT_IN_TABLE, f);
   }
   return DotC.dispatch(
       this, symbolInfo.address, symbolInfo.symbol, naok, dup, args.getArguments());
 }
Exemple #13
0
 @Specialization
 protected int doNArgs(VirtualFrame frame) {
   int result = 0;
   if (RArguments.getFunction(frame) == null) {
     return RRuntime.INT_NA;
   }
   int l = RArguments.getArgumentsLength(frame);
   for (int i = 0; i < l; i++) {
     Object arg = RArguments.getArgument(frame, i);
     if (arg instanceof RPromise) {
       isPromiseProfile.enter();
       RPromise promise = (RPromise) arg;
       if (!promise.isDefault()) {
         result++;
       }
     } else if (arg instanceof RArgsValuesAndNames) {
       result += ((RArgsValuesAndNames) arg).getLength();
     } else if (!(arg instanceof RMissing)) {
       result++;
     }
   }
   return result;
 }
  @Specialization(guards = "isRubyModule(lexicalParentModule)")
  public Object defineModule(VirtualFrame frame, DynamicObject lexicalParentModule) {
    final RubyConstant constant = lookupForExistingModule(frame, name, lexicalParentModule);

    final DynamicObject definingModule;

    if (needToDefineProfile.profile(constant == null)) {
      definingModule =
          ModuleNodes.createModule(
              getContext(), coreLibrary().getModuleClass(), lexicalParentModule, name, this);
    } else {
      final Object constantValue = constant.getValue();

      if (!RubyGuards.isRubyModule(constantValue) || RubyGuards.isRubyClass(constantValue)) {
        errorProfile.enter();
        throw new RaiseException(coreExceptions().typeErrorIsNotA(name, "module", this));
      }

      definingModule = (DynamicObject) constantValue;
    }

    return definingModule;
  }
Exemple #15
0
 @Specialization
 protected Object doInternal(@SuppressWarnings("unused") RMissing x) {
   errorProfile.enter();
   throw RError.error(this, RError.Message.ARGUMENTS_PASSED_0_1, getRBuiltin().name());
 }