Example #1
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);
  }
Example #2
0
 private RError dimensionsError() {
   if (replace) {
     if (mode.isSubset()) {
       if (getDimensions() == 2) {
         return RError.error(this, RError.Message.INCORRECT_SUBSCRIPTS_MATRIX);
       } else {
         return RError.error(this, RError.Message.INCORRECT_SUBSCRIPTS);
       }
     } else {
       return RError.error(this, RError.Message.IMPROPER_SUBSCRIPT);
     }
   } else {
     return RError.error(this, RError.Message.INCORRECT_DIMENSIONS);
   }
 }
Example #3
0
 @Override
 protected void createDelegateConnection() throws IOException {
   DelegateRConnection delegate = null;
   switch (getOpenMode().abstractOpenMode) {
     case Read:
       delegate = new FileReadTextRConnection(this);
       break;
     case Write:
       delegate = new FileWriteTextRConnection(this, false);
       break;
     case Append:
       delegate = new FileWriteTextRConnection(this, true);
       break;
     case ReadBinary:
       delegate = new FileReadBinaryRConnection(this);
       break;
     case WriteBinary:
       delegate = new FileWriteBinaryConnection(this, false);
       break;
     case ReadWriteTrunc:
     case ReadWriteTruncBinary:
       delegate = new FileReadWriteConnection(this);
       break;
     default:
       throw RError.nyi(RError.SHOW_CALLER2, "open mode: " + getOpenMode());
   }
   setDelegate(delegate);
 }
Example #4
0
 @SuppressWarnings("unused")
 @Specialization
 protected Object updateLengthError(Object vector, Object lengthVector) {
   controlVisibility();
   CompilerDirectives.transferToInterpreter();
   throw RError.error(this, RError.Message.INVALID_UNNAMED_VALUE);
 }
 @Override
 public void execute(VirtualFrame frame, Object value, MaterializedFrame enclosingFrame) {
   CompilerDirectives.transferToInterpreterAndInvalidate();
   if (name.isEmpty()) {
     throw RError.error(RError.NO_CALLER, RError.Message.ZERO_LENGTH_VARIABLE);
   }
   final WriteSuperFrameVariableNode writeNode;
   if (REnvironment.isGlobalEnvFrame(enclosingFrame)) {
     /*
      * we've reached the global scope, do unconditional write. if this is the first node
      * in the chain, needs the rhs and enclosingFrame nodes
      */
     AccessEnclosingFrameNode enclosingFrameNode =
         RArguments.getEnclosingFrame(frame) == enclosingFrame
             ? new AccessEnclosingFrameNode()
             : null;
     writeNode =
         ResolvedWriteSuperFrameVariableNodeGen.create(
             mode,
             rhs,
             enclosingFrameNode,
             FrameSlotNode.create(
                 findOrAddFrameSlot(
                     enclosingFrame.getFrameDescriptor(), name, FrameSlotKind.Illegal)),
             name);
   } else {
     ResolvedWriteSuperFrameVariableNode actualWriteNode =
         ResolvedWriteSuperFrameVariableNodeGen.create(
             mode, null, null, FrameSlotNode.create(name), name);
     writeNode =
         new WriteSuperFrameVariableConditionalNode(
             actualWriteNode, new UnresolvedWriteSuperFrameVariableNode(name, null, mode), rhs);
   }
   replace(writeNode).execute(frame, value, enclosingFrame);
 }
Example #6
0
 @Override
 public long seek(long offset, SeekMode seekMode, SeekRWMode seekRWMode) throws IOException {
   long result = raf.getFilePointer();
   switch (seekMode) {
     case ENQUIRE:
       return result;
     case START:
       break;
     default:
       throw RError.nyi(RError.SHOW_CALLER, "seek mode");
   }
   switch (seekRWMode) {
     case LAST:
       if (lastMode == SeekRWMode.READ) {
         readOffset = offset;
       } else {
         writeOffset = offset;
       }
       break;
     case READ:
       readOffset = offset;
       break;
     case WRITE:
       writeOffset = offset;
       break;
   }
   return result;
 }
 public RFactorToStringVectorClosure(
     RFactor factor, RAbstractStringVector levels, boolean withNames) {
   super(factor.getVector());
   this.levels = levels;
   this.withNames = withNames;
   if (this.levels == null) {
     RError.warning(RError.NO_NODE, RError.Message.IS_NA_TO_NON_VECTOR, "NULL");
   }
 }
Example #8
0
 @Specialization
 protected REnvironment doList2Env(RList list, REnvironment env) {
   RStringVector names = list.getNames();
   if (names == null) {
     throw RError.error(this, RError.Message.LIST_NAMES_SAME_LENGTH);
   }
   for (int i = list.getLength() - 1; i >= 0; i--) {
     String name = names.getDataAt(i);
     if (name.length() == 0) {
       throw RError.error(this, RError.Message.ZERO_LENGTH_VARIABLE);
     }
     // in case of duplicates, last element in list wins
     if (env.get(name) == null) {
       env.safePut(name, list.getDataAt(i));
     }
   }
   return env;
 }
Example #9
0
 @Specialization
 @TruffleBoundary
 protected RNull invokeRestart(RList restart, Object args) {
   checkLength(restart);
   if (RErrorHandling.invokeRestart(restart, args) == null) {
     throw RError.error(this, RError.Message.RESTART_NOT_ON_STACK);
   } else {
     return RNull.instance; // not reached
   }
 }
Example #10
0
 @Specialization
 @TruffleBoundary
 protected Object addCondHands(
     RAbstractStringVector classes,
     RList handlers,
     REnvironment parentEnv,
     Object target,
     byte calling) {
   if (classes.getLength() != handlers.getLength()) {
     throw RError.error(this, RError.Message.BAD_HANDLER_DATA);
   }
   return RErrorHandling.createHandlers(classes, handlers, parentEnv, target, calling);
 }
Example #11
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());
 }
Example #12
0
 protected String getName(Object nameObj) {
   assert nameObj instanceof RPromise;
   Object rep = ((RPromise) nameObj).getRep();
   if (rep instanceof WrapArgumentNode) {
     rep = ((WrapArgumentNode) rep).getOperand();
   }
   if (rep instanceof ConstantNode) {
     Object val = ((ConstantNode) rep).getValue();
     if (val instanceof String) {
       return (String) val;
     }
     if (val instanceof RSymbol) {
       return ((RSymbol) val).getName();
     }
   } else if (rep instanceof ReadVariableNode) {
     return ((ReadVariableNode) rep).getIdentifier();
   } else if (rep instanceof RCallNode) {
     throw RError.error(this, RError.Message.SLOT_INVALID_TYPE, "language");
   }
   // TODO: this is not quite correct, but I wonder if we even reach here (can also be
   // augmented on demand)
   throw RError.error(this, RError.Message.SLOT_INVALID_TYPE, nameObj.getClass().toString());
 }
Example #13
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});
 }
Example #14
0
 FileReadTextRConnection(BasePathRConnection base) throws IOException {
   super(base);
   // can be compressed - check for it
   RCompression.Type cType = RCompression.getCompressionType(base.path);
   switch (cType) {
     case NONE:
       inputStream = new BufferedInputStream(new FileInputStream(base.path));
       break;
     case GZIP:
       inputStream =
           new GZIPInputStream(new FileInputStream(base.path), GZIPConnections.GZIP_BUFFER_SIZE);
       break;
     default:
       throw RError.nyi(RError.SHOW_CALLER2, "compression type: " + cType.name());
   }
 }
Example #15
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());
 }
Example #16
0
 protected RuntimeException fallback(Object fobj) {
   String name = null;
   if (fobj instanceof RList) {
     name = lookupName((RList) fobj);
     name = name == UNKNOWN_EXTERNAL_BUILTIN ? null : name;
     if (name != null && lookupBuiltin((RList) fobj) != null) {
       /*
        * if we reach this point, then the cache saw a different value for f. the lists
        * that contain the information about native calls are never expected to change.
        */
       throw RInternalError.shouldNotReachHere(
           "fallback reached for " + getRBuiltin().name() + " " + name);
     }
   }
   throw RError.nyi(
       this,
       getRBuiltin().name() + " specialization failure: " + (name == null ? "<unknown>" : name));
 }
Example #17
0
 protected void checkLength(RList restart) {
   if (restart.getLength() < 2) {
     throw RError.error(this, RError.Message.BAD_RESTART);
   }
 }
Example #18
0
  static PolyglotEngine createPolyglotEngineFromCommandLine(
      RCmdOptions options,
      boolean embedded,
      boolean initial,
      InputStream inStream,
      OutputStream outStream,
      String[] env) {
    RStartParams rsp = new RStartParams(options, embedded);

    String fileArg = options.getString(FILE);
    if (fileArg != null) {
      if (options.getStringList(EXPR) != null) {
        Utils.rSuicide("cannot use -e with -f or --file");
      }
      if (!rsp.getSlave()) {
        rsp.setSaveAction(SA_TYPE.NOSAVE);
      }
      if (fileArg.equals("-")) {
        // means stdin, but still implies NO_SAVE
        fileArg = null;
      } else {
        fileArg = unescapeSpace(fileArg);
      }
      // cf GNU R
      rsp.setInteractive(false);
    }

    /*
     * Outputting the welcome message here has the virtue that the VM initialization delay
     * occurs later. However, it does not work in embedded mode as console redirects have not
     * been installed at this point. So we do it later in REmbedded.
     */
    if (!rsp.getQuiet() && !embedded) {
      System.out.println(RRuntime.WELCOME_MESSAGE);
    }
    /*
     * Whether the input is from stdin, a file (-f), or an expression on the command line (-e)
     * it goes through the console. N.B. -f and -e can't be used together and this is already
     * checked.
     */
    ConsoleHandler consoleHandler;
    if (fileArg != null) {
      List<String> lines;
      String filePath;
      try {
        /*
         * If initial==false, ~ expansion will not have been done and the open will fail.
         * It's harmless to always do it.
         */
        File file = new File(Utils.tildeExpand(fileArg));
        lines = Files.readAllLines(file.toPath());
        filePath = file.getCanonicalPath();
      } catch (IOException e) {
        if (initial) {
          throw Utils.rSuicide(String.format(RError.Message.NO_SUCH_FILE.message, fileArg));
        } else {
          throw RError.error(RError.NO_CALLER, RError.Message.NO_SUCH_FILE, fileArg);
        }
      }
      consoleHandler = new StringConsoleHandler(lines, outStream, filePath);
    } else if (options.getStringList(EXPR) != null) {
      List<String> exprs = options.getStringList(EXPR);
      for (int i = 0; i < exprs.size(); i++) {
        exprs.set(i, unescapeSpace(exprs.get(i)));
      }
      if (!rsp.getSlave()) {
        rsp.setSaveAction(SA_TYPE.NOSAVE);
      }
      // cf GNU R
      rsp.setInteractive(false);
      consoleHandler =
          new StringConsoleHandler(exprs, outStream, RSource.Internal.EXPRESSION_INPUT.string);
    } else {
      /*
       * GnuR behavior differs from the manual entry for {@code interactive} in that {@code
       * --interactive} never applies to {@code -e/-f}, only to console input that has been
       * redirected from a pipe/file etc.
       *
       * If we are in embedded mode, the creation of ConsoleReader and the ConsoleHandler
       * should be lazy, as these may not be necessary and can cause hangs if stdin has been
       * redirected.
       */
      Console sysConsole = System.console(); // TODO fix for context sessions
      boolean isInteractive = options.getBoolean(INTERACTIVE) || sysConsole != null;
      if (!isInteractive
          && rsp.getSaveAction() != SA_TYPE.SAVE
          && rsp.getSaveAction() != SA_TYPE.NOSAVE) {
        String msg = "you must specify '--save', '--no-save' or '--vanilla'";
        if (initial) {
          throw Utils.rSuicide(msg);
        } else {
          throw RError.error(RError.NO_CALLER, RError.Message.GENERIC, msg);
        }
      }
      if (embedded) {
        consoleHandler = new EmbeddedConsoleHandler(rsp);
      } else {
        boolean useReadLine = !rsp.getNoReadline();
        if (useReadLine) {
          consoleHandler = new JLineConsoleHandler(rsp, inStream, outStream);
        } else {
          consoleHandler = new DefaultConsoleHandler(inStream, outStream);
        }
      }
    }
    return ContextInfo.create(
            rsp,
            env,
            ContextKind.SHARE_NOTHING,
            initial ? null : RContext.getInstance(),
            consoleHandler)
        .createVM();
  }
Example #19
0
 @Specialization
 protected Object doInternal(@SuppressWarnings("unused") RMissing x) {
   errorProfile.enter();
   throw RError.error(this, RError.Message.ARGUMENTS_PASSED_0_1, getRBuiltin().name());
 }
Example #20
0
 @Override
 public int readBin(ByteBuffer buffer) throws IOException {
   throw RError.error(RError.SHOW_CALLER2, RError.Message.ONLY_READ_BINARY_CONNECTION);
 }
Example #21
0
 @Override
 public byte[] readBinChars() throws IOException {
   throw RError.error(RError.SHOW_CALLER2, RError.Message.ONLY_READ_BINARY_CONNECTION);
 }
Example #22
0
 @Override
 public void writeBin(ByteBuffer buffer) throws IOException {
   throw RError.error(RError.SHOW_CALLER2, RError.Message.ONLY_WRITE_BINARY_CONNECTION);
 }
Example #23
0
 @SuppressWarnings("unused")
 @Fallback
 protected REnvironment doList2Env(Object obj, REnvironment env) {
   throw RError.error(this, RError.Message.FIRST_ARGUMENT_NOT_NAMED_LIST);
 }
Example #24
0
 private RError invalidTimes() {
   throw RError.error(this, RError.Message.INVALID_ARGUMENT, "times");
 }