@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); }
@Override public Object getRelementImpl(int index) { if (index == 0) { String name = getBuiltin().getName(); assert name == name.intern(); return RDataFactory.createSymbol(name); } else { throw RInternalError.unimplemented(); } }
private static boolean doEcho(PolyglotEngine vm) { PolyglotEngine.Value echoValue = vm.eval(GET_ECHO); Object echo = echoValue.get(); if (echo instanceof TruffleObject) { RLogicalVector echoVec = echoValue.as(RLogicalVector.class); return RRuntime.fromLogical(echoVec.getDataAt(0)); } else if (echo instanceof Byte) { return RRuntime.fromLogical((Byte) echo); } else { throw RInternalError.shouldNotReachHere(); } }
FileReadWriteConnection(FileRConnection base) throws IOException { super(base); OpenMode openMode = base.getOpenMode(); String rafMode = null; switch (openMode.abstractOpenMode) { case ReadWriteTrunc: case ReadWriteTruncBinary: rafMode = "rw"; break; default: throw RInternalError.shouldNotReachHere(); } raf = new RandomAccessFile(base.path, rafMode); inputStream = new RAFInputStream(); }
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)); }
@Override public long seek(long offset, SeekMode seekMode, SeekRWMode seekRWMode) throws IOException { long position = inputStream.getChannel().position(); switch (seekMode) { case ENQUIRE: break; case CURRENT: if (offset != 0) { inputStream.getChannel().position(position + offset); } break; case START: inputStream.getChannel().position(offset); break; case END: throw RInternalError.unimplemented(); } return position; }
@SuppressWarnings("unused") @Specialization protected RNull resetCondHands(Object stack) { // TODO throw RInternalError.unimplemented(); }
public static void main(String[] args) { doMain(args, null, true, System.in, System.out); // never returns throw RInternalError.shouldNotReachHere(); }
/** * The read-eval-print loop, which can take input from a console, command line expression or a * file. There are two ways the repl can terminate: * * <ol> * <li>A {@code quit} command is executed successfully, which case the system exits from the * {@link Quit} {@code .Internal} . * <li>EOF on the input. * </ol> * * In case 2, we must implicitly execute a {@code quit("default, 0L, TRUE} command before exiting. * So,in either case, we never return. */ static int readEvalPrint(PolyglotEngine vm) { int lastStatus = 0; ContextInfo contextInfo = ContextInfo.getContextInfo(vm); ConsoleHandler consoleHandler = contextInfo.getConsoleHandler(); try { // console.println("initialize time: " + (System.currentTimeMillis() - start)); REPL: for (; ; ) { boolean doEcho = doEcho(vm); consoleHandler.setPrompt(doEcho ? "> " : null); try { String input = consoleHandler.readLine(); if (input == null) { throw new EOFException(); } String trInput = input.trim(); if (trInput.equals("") || trInput.charAt(0) == '#') { // nothing to parse continue; } String continuePrompt = getContinuePrompt(); StringBuffer sb = new StringBuffer(input); Source source = RSource.fromTextInternal(sb.toString(), RSource.Internal.SHELL_INPUT); while (true) { lastStatus = 0; try { try { vm.eval(source); // checked exceptions are wrapped in RuntimeExceptions } catch (RuntimeException e) { if (e.getCause() instanceof com.oracle.truffle.api.vm.IncompleteSourceException) { throw e.getCause().getCause(); } throw e; } } catch (IncompleteSourceException e) { // read another line of input consoleHandler.setPrompt(doEcho ? continuePrompt : null); String additionalInput = consoleHandler.readLine(); if (additionalInput == null) { throw new EOFException(); } sb.append(additionalInput); source = RSource.fromTextInternal(sb.toString(), RSource.Internal.SHELL_INPUT); // The only continuation in the while loop continue; } catch (ParseException e) { e.report(consoleHandler); lastStatus = 1; } catch (RError e) { // drop through to continue REPL and remember last eval was an error lastStatus = 1; } catch (JumpToTopLevelException e) { // drop through to continue REPL } catch (DebugExitException e) { throw (RuntimeException) e.getCause(); } catch (ExitException e) { // usually from quit int status = e.getStatus(); if (contextInfo.getParent() == null) { vm.dispose(); Utils.systemExit(status); } else { return status; } } catch (Throwable e) { RInternalError.reportErrorAndConsoleLog(e, consoleHandler, 0); // We continue the repl even though the system may be broken lastStatus = 1; } continue REPL; } } catch (UserInterruptException e) { // interrupted by ctrl-c } } } catch (JumpToTopLevelException | EOFException ex) { // JumpToTopLevelException can happen if user profile invokes browser (unlikely but // possible) try { vm.eval(QUIT_EOF); } catch (JumpToTopLevelException e) { Utils.systemExit(0); } catch (ExitException e) { // normal quit, but with exit code based on lastStatus if (contextInfo.getParent() == null) { Utils.systemExit(lastStatus); } else { return lastStatus; } } catch (Throwable e) { throw RInternalError.shouldNotReachHere(e); } } finally { vm.dispose(); } return 0; }
@Override public final Object call(RArgsValuesAndNames args) { throw RInternalError.unimplemented("unimplemented external builtin: " + name); }
@Override public byte[] readBinChars() throws IOException { throw RInternalError.unimplemented(); }
@Override public int readBin(ByteBuffer buffer) throws IOException { throw RInternalError.unimplemented(); }
@Override public String readChar(int nchars, boolean useBytes) throws IOException { throw RInternalError.unimplemented(); }
@Override public void writeChar(String s, int pad, String eos, boolean useBytes) throws IOException { throw RInternalError.unimplemented(); }
@Override public void writeString(String s, boolean nl) throws IOException { throw RInternalError.unimplemented(); }
@Override public OutputStream getOutputStream() throws IOException { throw RInternalError.unimplemented(); }