示例#1
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;
 }
示例#2
0
文件: NArgs.java 项目: chumer/fastr
// TODO Figure out how to distinguish f(,,a) from f(a) - RMissing is used in both contexts
@RBuiltin(
    name = "nargs",
    kind = PRIMITIVE,
    parameterNames = {})
public abstract class NArgs extends RBuiltinNode {

  private final BranchProfile isPromiseProfile = BranchProfile.create();

  @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;
  }
}
示例#3
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());
 }
示例#4
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});
 }
示例#5
0
@RBuiltin(
    name = "dimnames",
    kind = PRIMITIVE,
    parameterNames = {"x"},
    dispatch = INTERNAL_GENERIC)
public abstract class DimNames extends RBuiltinNode {

  private final RAttributeProfiles attrProfiles = RAttributeProfiles.create();
  private final ConditionProfile nullProfile = ConditionProfile.createBinaryProfile();
  private final BranchProfile dataframeProfile = BranchProfile.create();
  private final BranchProfile factorProfile = BranchProfile.create();
  private final BranchProfile otherProfile = BranchProfile.create();

  @Specialization
  protected RNull getDimNames(@SuppressWarnings("unused") RNull operand) {
    controlVisibility();
    return RNull.instance;
  }

  @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;
  }
}
示例#6
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());
 }
示例#7
0
文件: NArgs.java 项目: chumer/fastr
 @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;
 }
示例#8
0
  @RBuiltin(
      name = ".Call.graphics",
      kind = RBuiltinKind.PRIMITIVE,
      parameterNames = {".NAME", "...", "PACKAGE"})
  public abstract static class DotCallGraphics extends LookupAdapter {

    private final BranchProfile errorProfile = BranchProfile.create();

    @Override
    public Object[] getDefaultParameterValues() {
      return new Object[] {RMissing.instance, RArgsValuesAndNames.EMPTY, RMissing.instance};
    }

    @Override
    protected RExternalBuiltinNode lookupBuiltin(RList f) {
      switch (lookupName(f)) {
        default:
          return null;
      }
    }

    @SuppressWarnings("unused")
    @Specialization(
        limit = "1",
        guards = {"cached == f", "builtin != null"})
    protected Object doExternal(
        RList f,
        RArgsValuesAndNames args,
        RMissing packageName, //
        @Cached("f") RList cached, //
        @Cached("lookupBuiltin(f)") RExternalBuiltinNode builtin) {
      controlVisibility();
      return builtin.call(args);
    }

    @Specialization
    public Object callNamedFunction(
        VirtualFrame frame,
        RList symbol,
        RArgsValuesAndNames args,
        @SuppressWarnings("unused") Object packageName) {
      return RFFIFactory.getRFFI()
          .getCallRFFI()
          .invokeCall(
              getAddressFromSymbolInfo(frame, symbol),
              getNameFromSymbolInfo(frame, symbol),
              args.getArguments());
    }

    @Specialization
    public Object callNamedFunction(
        String name, RArgsValuesAndNames args, @SuppressWarnings("unused") RMissing packageName) {
      return callNamedFunctionWithPackage(name, args, null);
    }

    @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());
    }

    @Fallback
    protected Object dotCallFallback(
        Object fobj,
        @SuppressWarnings("unused") Object args,
        @SuppressWarnings("unused") Object packageName) {
      throw fallback(fobj);
    }
  }
示例#9
0
  @RBuiltin(
      name = ".External.graphics",
      kind = RBuiltinKind.PRIMITIVE,
      parameterNames = {".NAME", "...", "PACKAGE"})
  public abstract static class DotExternalGraphics extends LookupAdapter {

    private final BranchProfile errorProfile = BranchProfile.create();

    @Override
    protected RExternalBuiltinNode lookupBuiltin(RList f) {
      if (FastROptions.UseInternalGraphics.getBooleanValue()) {
        switch (lookupName(f)) {
          case "C_mtext":
            return new GraphicsCCalls.C_mtext();
          case "C_plotXY":
            return new C_PlotXY();
        }
      }
      return null;
    }

    @SuppressWarnings("unused")
    @Specialization(
        limit = "1",
        guards = {"cached == f", "builtin != null"})
    protected Object doExternal(
        RList f,
        RArgsValuesAndNames args,
        RMissing packageName, //
        @Cached("f") RList cached, //
        @Cached("lookupBuiltin(f)") RExternalBuiltinNode builtin) {
      controlVisibility();
      return builtin.call(args);
    }

    @Specialization
    public Object callNamedFunction(
        VirtualFrame frame,
        RList symbol,
        RArgsValuesAndNames args,
        @SuppressWarnings("unused") Object packageName) {
      String name = getNameFromSymbolInfo(frame, symbol);
      Object list = encodeArgumentPairList(args, name);
      return RFFIFactory.getRFFI()
          .getCallRFFI()
          .invokeCall(getAddressFromSymbolInfo(frame, symbol), name, new Object[] {list});
    }

    @Specialization
    public Object callNamedFunction(
        String name, RArgsValuesAndNames args, @SuppressWarnings("unused") RMissing packageName) {
      return callNamedFunctionWithPackage(name, args, null);
    }

    @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);
      return RFFIFactory.getRFFI()
          .getCallRFFI()
          .invokeCall(symbolInfo.address, symbolInfo.symbol, new Object[] {list});
    }

    @Fallback
    protected Object fallback(
        Object f,
        @SuppressWarnings("unused") Object args,
        @SuppressWarnings("unused") Object packageName) {
      throw fallback(f);
    }
  }
示例#10
0
  @RBuiltin(
      name = ".External2",
      kind = RBuiltinKind.PRIMITIVE,
      parameterNames = {".NAME", "...", "PACKAGE"})
  public abstract static class DotExternal2 extends LookupAdapter {
    private static final Object CALL = "call";
    private static final Object OP = "op";
    private static final Object RHO = "rho";

    private final BranchProfile errorProfile = BranchProfile.create();

    @Override
    protected RExternalBuiltinNode lookupBuiltin(RList f) {
      if (FastROptions.UseInternalGraphics.getBooleanValue()) {
        switch (lookupName(f)) {
          case "C_par":
            return new C_Par();
        }
      }
      String name = lookupName(f);
      switch (name) {
          // tools
        case "writetable":
          return new WriteTable();
        case "typeconvert":
          return TypeConvertNodeGen.create();
        case "C_parseRd":
          return C_ParseRdNodeGen.create();
        default:
          return null;
      }
    }

    @SuppressWarnings("unused")
    @Specialization(
        limit = "1",
        guards = {"cached == f", "builtin != null"})
    protected Object doExternal(
        RList f,
        RArgsValuesAndNames args,
        RMissing packageName, //
        @Cached("f") RList cached, //
        @Cached("lookupBuiltin(f)") RExternalBuiltinNode builtin) {
      controlVisibility();
      return builtin.call(args);
    }

    @Specialization
    public Object callNamedFunction(
        VirtualFrame frame,
        RList symbol,
        RArgsValuesAndNames args,
        @SuppressWarnings("unused") Object packageName) {
      String name = getNameFromSymbolInfo(frame, symbol);
      Object list = encodeArgumentPairList(args, name);
      // TODO: provide proper values for the CALL, OP and RHO parameters
      return RFFIFactory.getRFFI()
          .getCallRFFI()
          .invokeCall(
              getAddressFromSymbolInfo(frame, symbol), name, new Object[] {CALL, OP, list, RHO});
    }

    @Specialization
    public Object callNamedFunction(
        String name, RArgsValuesAndNames args, @SuppressWarnings("unused") RMissing packageName) {
      return callNamedFunctionWithPackage(name, args, null);
    }

    @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});
    }

    @Fallback
    protected Object fallback(
        Object f,
        @SuppressWarnings("unused") Object args,
        @SuppressWarnings("unused") Object packageName) {
      throw fallback(f);
    }
  }
示例#11
0
  @RBuiltin(
      name = ".External",
      kind = RBuiltinKind.PRIMITIVE,
      parameterNames = {".NAME", "...", "PACKAGE"})
  public abstract static class DotExternal extends LookupAdapter {

    private final BranchProfile errorProfile = BranchProfile.create();

    @Override
    protected RExternalBuiltinNode lookupBuiltin(RList f) {
      String name = lookupName(f);
      if (FastROptions.UseInternalGraphics.getBooleanValue()) {
        switch (name) {
          case "PDF":
            return new DevicesCCalls.C_PDF();
          case "devoff":
            return new DevicesCCalls.C_DevOff();
          case "devcur":
            return new DevicesCCalls.C_DevCur();
        }
      }
      switch (name) {
        case "compcases":
          return new CompleteCases();
          // utils
        case "countfields":
          return new CountFields();
        case "readtablehead":
          return new ReadTableHead();
        case "rnorm":
          return RnormNodeGen.create();
        case "runif":
          return RunifNodeGen.create();
        case "qgamma":
          return QgammaNodeGen.create();
        case "download":
          return new Download();
        case "unzip":
        case "Rprof":
        case "Rprofmem":
        case "addhistory":
        case "loadhistory":
        case "savehistory":
        case "dataentry":
        case "dataviewer":
        case "edit":
        case "fileedit":
        case "selectlist":
          return new UnimplementedExternal(name);
        default:
          return null;
      }
    }

    @SuppressWarnings("unused")
    @Specialization(
        limit = "1",
        guards = {"cached == f", "builtin != null"})
    protected Object doExternal(
        RList f,
        RArgsValuesAndNames args,
        RMissing packageName, //
        @Cached("f") RList cached, //
        @Cached("lookupBuiltin(f)") RExternalBuiltinNode builtin) {
      controlVisibility();
      return builtin.call(args);
    }

    @Specialization
    public Object callNamedFunction(
        VirtualFrame frame,
        RList symbol,
        RArgsValuesAndNames args,
        @SuppressWarnings("unused") Object packageName) {
      String name = getNameFromSymbolInfo(frame, symbol);
      Object list = encodeArgumentPairList(args, name);
      return RFFIFactory.getRFFI()
          .getCallRFFI()
          .invokeCall(getAddressFromSymbolInfo(frame, symbol), name, new Object[] {list});
    }

    @Specialization
    public Object callNamedFunction(
        String name, RArgsValuesAndNames args, @SuppressWarnings("unused") RMissing packageName) {
      return callNamedFunctionWithPackage(name, args, null);
    }

    @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);
      return RFFIFactory.getRFFI()
          .getCallRFFI()
          .invokeCall(symbolInfo.address, symbolInfo.symbol, new Object[] {list});
    }

    @Fallback
    protected Object fallback(
        Object f,
        @SuppressWarnings("unused") Object args,
        @SuppressWarnings("unused") Object packageName) {
      throw fallback(f);
    }
  }
示例#12
0
  /**
   * Handles the generic case, but also many special case functions that are called from the default
   * packages.
   */
  @RBuiltin(
      name = ".Call",
      kind = RBuiltinKind.PRIMITIVE,
      parameterNames = {".NAME", "...", "PACKAGE"})
  public abstract static class DotCall extends LookupAdapter {

    private final BranchProfile errorProfile = BranchProfile.create();

    @Override
    public Object[] getDefaultParameterValues() {
      return new Object[] {RMissing.instance, RArgsValuesAndNames.EMPTY, RMissing.instance};
    }

    @Override
    protected RExternalBuiltinNode lookupBuiltin(RList f) {
      String name = lookupName(f);
      switch (name) {
          // methods
        case "R_initMethodDispatch":
          return R_initMethodDispatchNodeGen.create();
        case "R_methodsPackageMetaName":
          return R_methodsPackageMetaNameNodeGen.create();
        case "R_set_method_dispatch":
          return R_set_method_dispatchNodeGen.create();
        case "R_M_setPrimitiveMethods":
          return R_M_setPrimitiveMethodsNodeGen.create();
        case "R_getClassFromCache":
          return R_getClassFromCacheNodeGen.create();
        case "R_clear_method_selection":
        case "R_dummy_extern_place":
        case "R_el_named":
          return new UnimplementedExternal(name);
        case "R_externalptr_prototype_object":
          return R_externalPtrPrototypeObjectNodeGen.create();
        case "R_getGeneric":
          return R_getGenericNodeGen.create();
        case "R_get_slot":
          return R_getSlotNodeGen.create();
        case "R_hasSlot":
          return new UnimplementedExternal(name);
        case "R_identC":
          return R_identCNodeGen.create();
        case "R_methods_test_MAKE_CLASS":
        case "R_methods_test_NEW":
        case "R_missingArg":
        case "R_nextMethodCall":
          return R_nextMethodCallNodeGen.create();
        case "R_quick_method_check":
        case "R_selectMethod":
        case "R_set_el_named":
          return new UnimplementedExternal(name);
        case "R_set_slot":
          return R_setSlotNodeGen.create();
        case "R_standardGeneric":
          return new UnimplementedExternal(name);
        case "do_substitute_direct":
          return SubstituteDirectNodeGen.create();
        case "Rf_allocS4Object":
        case "R_get_primname":
          return new UnimplementedExternal(name);
        case "new_object":
          return NewObjectNodeGen.create();

          // stats

        case "fft":
          return new Fft();
        case "cov":
          return new Covcor(false);
        case "cor":
          return new Covcor(true);
        case "SplineCoef":
          return SplineCoefNodeGen.create();
        case "SplineEval":
          return SplineEvalNodeGen.create();
        case "cutree":
        case "isoreg":
        case "monoFC_m":
        case "numeric_deriv":
        case "nls_iter":
        case "setup_starma":
        case "free_starma":
        case "set_trans":
        case "arma0fa":
        case "get_s2":
        case "get_resid":
        case "Dotrans":
        case "arma0_kfore":
        case "Starma_method":
        case "Invtrans":
        case "Gradtrans":
        case "ARMAtoMA":
        case "KalmanLike":
        case "KalmanFore":
        case "KalmanSmooth":
        case "ARIMA_undoPars":
        case "ARIMA_transPars":
        case "ARIMA_Invtrans":
        case "ARIMA_Gradtrans":
        case "ARIMA_Like":
        case "ARIMA_CSS":
        case "TSconv":
        case "getQ0":
        case "getQ0bis":
        case "port_ivset":
        case "port_nlminb":
        case "port_nlsb":
        case "logit_link":
        case "logit_linkinv":
        case "logit_mu_eta":
        case "binomial_dev_resids":
        case "rWishart":
        case "Cdqrls":
        case "Cdist":
        case "updateform":
        case "mvfft":
        case "nextn":
        case "r2dtable":
        case "cfilter":
        case "rfilter":
        case "lowess":
        case "DoubleCentre":
        case "BinDist":
        case "Rsm":
        case "tukeyline":
        case "runmed":
        case "influence":
        case "pSmirnov2x":
        case "pKolmogorov2x":
        case "pKS2":
        case "ksmooth":
        case "Approx":
        case "ApproxTest":
        case "LogLin":
        case "pAnsari":
        case "qAnsari":
        case "pKendall":
        case "pRho":
        case "SWilk":
        case "bw_den":
        case "bw_ucv":
        case "bw_bcv":
        case "bw_phi4":
        case "bw_phi6":
        case "acf":
        case "pacf1":
        case "ar2ma":
        case "Burg":
        case "intgrt_vec":
        case "pp_sum":
        case "Fexact":
        case "Fisher_sim":
        case "chisq_sim":
        case "d2x2xk":
          return new UnimplementedExternal(name);

          // tools
        case "doTabExpand":
          return DoTabExpandNodeGen.create();
        case "codeFilesAppend":
          return CodeFilesAppendNodeGen.create();
        case "Rmd5":
          return Rmd5NodeGen.create();
        case "dirchmod":
          return DirChmodNodeGen.create();
        case "delim_match":
        case "C_getfmts":
        case "check_nonASCII":
        case "check_nonASCII2":
        case "ps_kill":
        case "ps_sigs":
        case "ps_priority":
        case "startHTTPD":
        case "stopHTTPD":
        case "C_deparseRd":
          return new UnimplementedExternal(name);

          // utils
        case "crc64":
          return Crc64NodeGen.create();
        case "flushconsole":
          return new Flushconsole();
        case "menu":
          return MenuNodeGen.create();
        case "nsl":
        case "objectSize":
        case "processevents":
        case "octsize":
        case "sockconnect":
        case "sockread":
        case "sockclose":
        case "sockopen":
        case "socklisten":
        case "sockwrite":
          return new UnimplementedExternal(name);

          // grDevices
        case "cairoProps":
          return CairoPropsNodeGen.create();
        case "makeQuartzDefault":
          return new MakeQuartzDefault();

          // grid
        case "L_initGrid":
          return InitGridNodeGen.create();
        default:
          return null;
      }
    }

    @SuppressWarnings("unused")
    @Specialization(
        limit = "1",
        guards = {"cached == f", "builtin != null"})
    protected Object doExternal(
        RList f,
        RArgsValuesAndNames args,
        RMissing packageName, //
        @Cached("f") RList cached, //
        @Cached("lookupBuiltin(f)") RExternalBuiltinNode builtin) {
      controlVisibility();
      return builtin.call(args);
    }

    @Specialization
    public Object callNamedFunction(
        VirtualFrame frame,
        RList symbol,
        RArgsValuesAndNames args,
        @SuppressWarnings("unused") Object packageName) {
      controlVisibility();
      return RFFIFactory.getRFFI()
          .getCallRFFI()
          .invokeCall(
              getAddressFromSymbolInfo(frame, symbol),
              getNameFromSymbolInfo(frame, symbol),
              args.getArguments());
    }

    @Specialization
    public Object callNamedFunction(
        String name, RArgsValuesAndNames args, @SuppressWarnings("unused") RMissing packageName) {
      return callNamedFunctionWithPackage(name, args, null);
    }

    @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());
    }

    @Fallback
    protected Object dotCallFallback(
        Object fobj,
        @SuppressWarnings("unused") Object args,
        @SuppressWarnings("unused") Object packageName) {
      throw fallback(fobj);
    }
  }