@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 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); } }
@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); }
@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); }
@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"); } }
@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; }
@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 } }
@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); }
@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()); }
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()); }
@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}); }
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()); } }
@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()); }
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)); }
protected void checkLength(RList restart) { if (restart.getLength() < 2) { throw RError.error(this, RError.Message.BAD_RESTART); } }
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(); }
@Specialization protected Object doInternal(@SuppressWarnings("unused") RMissing x) { errorProfile.enter(); throw RError.error(this, RError.Message.ARGUMENTS_PASSED_0_1, getRBuiltin().name()); }
@Override public int readBin(ByteBuffer buffer) throws IOException { throw RError.error(RError.SHOW_CALLER2, RError.Message.ONLY_READ_BINARY_CONNECTION); }
@Override public byte[] readBinChars() throws IOException { throw RError.error(RError.SHOW_CALLER2, RError.Message.ONLY_READ_BINARY_CONNECTION); }
@Override public void writeBin(ByteBuffer buffer) throws IOException { throw RError.error(RError.SHOW_CALLER2, RError.Message.ONLY_WRITE_BINARY_CONNECTION); }
@SuppressWarnings("unused") @Fallback protected REnvironment doList2Env(Object obj, REnvironment env) { throw RError.error(this, RError.Message.FIRST_ARGUMENT_NOT_NAMED_LIST); }
private RError invalidTimes() { throw RError.error(this, RError.Message.INVALID_ARGUMENT, "times"); }