예제 #1
0
파일: Internal.java 프로젝트: graalvm/fastr
  @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);
  }
예제 #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);
   }
 }
예제 #3
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);
 }
예제 #5
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;
 }
예제 #6
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
   }
 }
예제 #7
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());
 }
예제 #8
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);
 }
예제 #9
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());
 }
예제 #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});
 }
예제 #11
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());
 }
예제 #12
0
파일: Repeat.java 프로젝트: graalvm/fastr
 private RError invalidTimes() {
   throw RError.error(this, RError.Message.INVALID_ARGUMENT, "times");
 }
예제 #13
0
파일: Internal.java 프로젝트: graalvm/fastr
 @Specialization
 protected Object doInternal(@SuppressWarnings("unused") RMissing x) {
   errorProfile.enter();
   throw RError.error(this, RError.Message.ARGUMENTS_PASSED_0_1, getRBuiltin().name());
 }
예제 #14
0
 @Override
 public int readBin(ByteBuffer buffer) throws IOException {
   throw RError.error(RError.SHOW_CALLER2, RError.Message.ONLY_READ_BINARY_CONNECTION);
 }
예제 #15
0
 protected void checkLength(RList restart) {
   if (restart.getLength() < 2) {
     throw RError.error(this, RError.Message.BAD_RESTART);
   }
 }
예제 #16
0
파일: RCommand.java 프로젝트: graalvm/fastr
  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();
  }
예제 #17
0
 @Override
 public byte[] readBinChars() throws IOException {
   throw RError.error(RError.SHOW_CALLER2, RError.Message.ONLY_READ_BINARY_CONNECTION);
 }
예제 #18
0
 @Override
 public void writeBin(ByteBuffer buffer) throws IOException {
   throw RError.error(RError.SHOW_CALLER2, RError.Message.ONLY_WRITE_BINARY_CONNECTION);
 }
예제 #19
0
 @SuppressWarnings("unused")
 @Fallback
 protected REnvironment doList2Env(Object obj, REnvironment env) {
   throw RError.error(this, RError.Message.FIRST_ARGUMENT_NOT_NAMED_LIST);
 }