diff --git a/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/JLineConsoleCompleter.java b/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/JLineConsoleCompleter.java index dc79ee71d212978d766ecfdf60de89138cac0f99..99777055f92d9dd36c21adc023f195104977af56 100644 --- a/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/JLineConsoleCompleter.java +++ b/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/JLineConsoleCompleter.java @@ -73,7 +73,7 @@ public class JLineConsoleCompleter implements Completer { setFunction.execute(completionEnv, "start", start); setFunction.execute(completionEnv, "end", cursor); setFunction.execute(completionEnv, "linebuffer", buffer); - setFunction.execute(completionEnv, "token", buffer.substring(start, cursor)); + setFunction.execute(completionEnv, "token", start > -1 && start < buffer.length() && cursor > -1 && cursor <= buffer.length() ? buffer.substring(start, cursor).trim() : ""); completionFunction.execute(); @@ -98,13 +98,33 @@ public class JLineConsoleCompleter implements Completer { private static int getStart(String buffer, Value env, int cursor) { int start = 0; + + // are we in quotes? + int lastQuoteIdx = isInQuotes(buffer, cursor); + if (lastQuoteIdx != -1) { + return lastQuoteIdx; + } + Value opt = env.getMember("options"); if (opt.hasMembers()) { start = lastIdxOf(buffer, opt, "funarg.suffix", start, cursor); start = lastIdxOf(buffer, opt, "function.suffix", start, cursor); } - start = lastIdxOf(buffer, "\"", start, cursor); - start = lastIdxOf(buffer, "'", start, cursor); + + // are we just after a ',' or ' ' + if (cursor > 0 && cursor <= buffer.length() && (buffer.charAt(cursor - 1) == ',' || buffer.charAt(cursor - 1) == ' ')) { + return cursor; + } + + // is there any next closest ',' or ' '? + int idx = cursor >= buffer.length() ? buffer.length() - 1 : cursor; + while (idx >= start && (buffer.charAt(idx) != ',' && buffer.charAt(idx) != ' ')) { + --idx; + } + if (idx > -1) { + return ++idx; + } + return start; } @@ -120,6 +140,19 @@ public class JLineConsoleCompleter implements Completer { return start; } + private static int isInQuotes(String buffer, int cursor) { + int idx = -1; + int qidx = -1; + int c = 0; + while (++idx <= cursor && idx < buffer.length()) { + if (buffer.charAt(idx) == '\'' || buffer.charAt(idx) == '\"') { + qidx = idx; + c++; + } + } + return c % 2 == 0 ? -1 : qidx; + } + private static int lastIdxOf(String buffer, String subs, int start, int cursor) { if (!subs.isEmpty()) { int idx = buffer.lastIndexOf(subs, cursor); diff --git a/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/RscriptCommand.java b/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/RscriptCommand.java index 1fecdef2659b15cf69373baa44e05bb88007925f..c274a249764463831cf8aac1f8e8c8b3235a7e0e 100644 --- a/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/RscriptCommand.java +++ b/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/RscriptCommand.java @@ -27,6 +27,7 @@ import java.io.OutputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; import org.graalvm.options.OptionCategory; @@ -45,7 +46,7 @@ public class RscriptCommand { // CheckStyle: stop system..print check - private static void preprocessRScriptOptions(RLauncher launcher, RCmdOptions options) { + private static String[] preprocessRScriptOptions(RLauncher launcher, RCmdOptions options) { String[] arguments = options.getArguments(); int resultArgsLength = arguments.length; int firstNonOptionArgIndex = options.getFirstNonOptionArgIndex(); @@ -65,9 +66,6 @@ public class RscriptCommand { System.exit(1); } } else { - if (arguments[firstNonOptionArgIndex].startsWith("-")) { - throw RCommand.fatal("file name is missing"); - } options.setValue(RCmdOption.FILE, arguments[firstNonOptionArgIndex]); } } @@ -97,7 +95,7 @@ public class RscriptCommand { adjArgs.add(arguments[rx++]); } } - options.setArguments(adjArgs.toArray(new String[adjArgs.size()])); + return adjArgs.toArray(new String[adjArgs.size()]); } public static void main(String[] args) { @@ -117,20 +115,21 @@ public class RscriptCommand { } }; Map<String, String> polyglotOptions = new HashMap<>(); - for (int i = 1; i < argsList.size(); i++) { - String arg = argsList.get(i); + Iterator<String> iter = argsList.iterator(); + while (iter.hasNext()) { + String arg = iter.next(); if (launcher.parsePolyglotOption("R", polyglotOptions, arg)) { - argsList.remove(i); + iter.remove(); } } if (launcher.runPolyglotAction()) { return 0; } RCmdOptions options = RCmdOptions.parseArguments(Client.RSCRIPT, argsList.toArray(new String[argsList.size()]), false); - preprocessRScriptOptions(launcher, options); + String[] arguments = preprocessRScriptOptions(launcher, options); ConsoleHandler consoleHandler = RCommand.createConsoleHandler(options, false, inStream, outStream); - try (Context context = Context.newBuilder().options(polyglotOptions).arguments("R", options.getArguments()).in(consoleHandler.createInputStream()).out(outStream).err(errStream).build()) { + try (Context context = Context.newBuilder().options(polyglotOptions).arguments("R", arguments).in(consoleHandler.createInputStream()).out(outStream).err(errStream).build()) { consoleHandler.setContext(context); return RCommand.readEvalPrint(context, consoleHandler); } diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/DisplayList.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/DisplayList.java index 89834ac50af2d878927acccc056c2165cae43537..14cd2fda773ebceec382ffdd337cd510e2503e86 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/DisplayList.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/DisplayList.java @@ -49,7 +49,7 @@ public class DisplayList { static void initDisplayList(GridState gridState) { RList list = createInitialDisplayList(); - list.setDataAt(list.getInternalStore(), 0, gridState.getViewPort()); + list.setDataAt(0, gridState.getViewPort()); gridState.setDisplayList(list); gridState.setDisplayListIndex(1); } diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/DoSetViewPort.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/DoSetViewPort.java index f2d1290c6e10fd3c4f50de1f5d7aa8f74d3e51c4..87ac3095c6689f05bc93ba6516e6732797683790 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/DoSetViewPort.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/DoSetViewPort.java @@ -36,6 +36,7 @@ import com.oracle.truffle.r.runtime.data.RDoubleVector; import com.oracle.truffle.r.runtime.data.RList; import com.oracle.truffle.r.runtime.data.RNull; import com.oracle.truffle.r.runtime.data.model.RAbstractContainer; +import com.oracle.truffle.r.runtime.data.model.RAbstractDoubleVector; import com.oracle.truffle.r.runtime.data.model.RAbstractIntVector; import com.oracle.truffle.r.runtime.env.REnvironment; @@ -54,12 +55,11 @@ final class DoSetViewPort { @TruffleBoundary public static RList doSetViewPort(RList pushedViewPort, boolean hasParent, boolean pushing) { GridState gridState = GridContext.getContext().getGridState(); - Object[] pushedVPData = pushedViewPort.getDataWithoutCopying(); if (hasParent && pushing) { RList parent = gridState.getViewPort(); - pushedVPData[ViewPort.PVP_PARENT] = parent; + pushedViewPort.setDataAt(ViewPort.PVP_PARENT, parent); REnvironment children = GridUtils.asEnvironment(parent.getDataAt(ViewPort.PVP_CHILDREN)); - children.safePut(RRuntime.asString(pushedVPData[ViewPort.VP_NAME]), pushedViewPort); + children.safePut(RRuntime.asString(pushedViewPort.getDataAt(ViewPort.VP_NAME)), pushedViewPort); } GridDevice currentDevice = GridContext.getContext().getCurrentDevice(); @@ -70,9 +70,9 @@ final class DoSetViewPort { calcViewportTransform(pushedViewPort, parent, doNotRecalculateParent, currentDevice, gpar); // TODO: clipping - pushedVPData[ViewPort.PVP_CLIPRECT] = RDataFactory.createDoubleVector(new double[]{0, 0, 0, 0}, RDataFactory.COMPLETE_VECTOR); - pushedVPData[ViewPort.PVP_DEVWIDTHCM] = scalar(Unit.inchesToCm(currentDevice.getWidth())); - pushedVPData[ViewPort.PVP_DEVHEIGHTCM] = scalar(Unit.inchesToCm(currentDevice.getHeight())); + pushedViewPort.setDataAt(ViewPort.PVP_CLIPRECT, RDataFactory.createDoubleVector(new double[]{0, 0, 0, 0}, RDataFactory.COMPLETE_VECTOR)); + pushedViewPort.setDataAt(ViewPort.PVP_DEVWIDTHCM, scalar(Unit.inchesToCm(currentDevice.getWidth()))); + pushedViewPort.setDataAt(ViewPort.PVP_DEVHEIGHTCM, scalar(Unit.inchesToCm(currentDevice.getHeight()))); assert pushedViewPort.verify(); return pushedViewPort; @@ -108,17 +108,17 @@ final class DoSetViewPort { } else { assert parent instanceof RList : "inconsistent data: parent of a viewport must be a list"; RList parentVPList = (RList) parent; - Object[] parentData = parentVPList.getDataWithoutCopying(); if (!incremental) { - calcViewportTransform(parentVPList, parentData[ViewPort.PVP_PARENT], false, device, deviceTopLevelGpar); + calcViewportTransform(parentVPList, parentVPList.getDataAt(ViewPort.PVP_PARENT), false, device, deviceTopLevelGpar); } - parentSize = new Size(Unit.cmToInches(GridUtils.asDouble(parentData[ViewPort.PVP_WIDTHCM])), Unit.cmToInches(GridUtils.asDouble(parentData[ViewPort.PVP_HEIGHTCM]))); - parentTransform = fromFlat(GridUtils.asDoubleVector(parentData[ViewPort.PVP_TRANS]).materialize().getDataWithoutCopying()); + parentSize = new Size(Unit.cmToInches(GridUtils.asDouble(parentVPList.getDataAt(ViewPort.PVP_WIDTHCM))), + Unit.cmToInches(GridUtils.asDouble(parentVPList.getDataAt(ViewPort.PVP_HEIGHTCM)))); + parentTransform = fromFlat(GridUtils.asDoubleVector(parentVPList.getDataAt(ViewPort.PVP_TRANS))); parentContext = ViewPortContext.fromViewPort(parentVPList); - parentAngle = asDouble(parentData[ViewPort.PVP_ROTATION]); + parentAngle = asDouble(parentVPList.getDataAt(ViewPort.PVP_ROTATION)); drawingContext = GPar.create(asList(viewPort.getDataAt(ViewPort.PVP_PARENTGPAR))); - boolean noLayout = (isNull(viewPort.getDataAt(ViewPort.VP_VALIDLPOSROW)) && isNull(viewPort.getDataAt(ViewPort.VP_VALIDLPOSCOL))) || isNull(parentData[ViewPort.VP_LAYOUT]); + boolean noLayout = (isNull(viewPort.getDataAt(ViewPort.VP_VALIDLPOSROW)) && isNull(viewPort.getDataAt(ViewPort.VP_VALIDLPOSCOL))) || isNull(parentVPList.getDataAt(ViewPort.VP_LAYOUT)); if (noLayout) { vpl = ViewPortLocation.fromViewPort(viewPort); } else { @@ -160,11 +160,10 @@ final class DoSetViewPort { calcViewPortLayout(viewPort, new Size(width, height), vpCtx, device, GPar.create(asList(viewPort.getDataAt(ViewPort.PVP_GPAR)))); } - Object[] viewPortData = viewPort.getDataWithoutCopying(); - viewPortData[ViewPort.PVP_WIDTHCM] = scalar(Unit.inchesToCm(width)); - viewPortData[ViewPort.PVP_HEIGHTCM] = scalar(Unit.inchesToCm(height)); - viewPortData[ViewPort.PVP_ROTATION] = scalar(rotationAngle); - viewPortData[ViewPort.PVP_TRANS] = RDataFactory.createDoubleVector(flatten(transform), RDataFactory.COMPLETE_VECTOR, new int[]{3, 3}); + viewPort.setDataAt(ViewPort.PVP_WIDTHCM, scalar(Unit.inchesToCm(width))); + viewPort.setDataAt(ViewPort.PVP_HEIGHTCM, scalar(Unit.inchesToCm(height))); + viewPort.setDataAt(ViewPort.PVP_ROTATION, scalar(rotationAngle)); + viewPort.setDataAt(ViewPort.PVP_TRANS, RDataFactory.createDoubleVector(flatten(transform), RDataFactory.COMPLETE_VECTOR, new int[]{3, 3})); } private static void calcViewPortLayout(RList viewPort, Size size, ViewPortContext parentVPCtx, GridDevice device, GPar gpar) { @@ -178,12 +177,12 @@ final class DoSetViewPort { // For both dimensions we find out which units are other than "null" for those we can // immediately calculate the physical size in npcWidth/npcHeights. The reducedWidth/Height // gives us how much of width/height is left after we take up the space by physical units - Object[] layoutData = asList(viewPort.getDataAt(ViewPort.VP_LAYOUT)).getDataWithoutCopying(); - RAbstractContainer layoutWidths = asAbstractContainer(layoutData[ViewPort.LAYOUT_WIDTHS]); + RList layoutList = asList(viewPort.getDataAt(ViewPort.VP_LAYOUT)); + RAbstractContainer layoutWidths = asAbstractContainer(layoutList.getDataAt(ViewPort.LAYOUT_WIDTHS)); assert Unit.getLength(layoutWidths) == layoutSize.ncol : "inconsistent layout size with layout widths"; double reducedWidth = getReducedDimension(layoutWidths, npcWidths, relativeWidths, size.getWidth(), conversionCtx, true); - RAbstractContainer layoutHeights = asAbstractContainer(layoutData[ViewPort.LAYOUT_HEIGHTS]); + RAbstractContainer layoutHeights = asAbstractContainer(layoutList.getDataAt(ViewPort.LAYOUT_HEIGHTS)); assert Unit.getLength(layoutHeights) == layoutSize.nrow : "inconsistent layout size with layout height"; double reducedHeight = getReducedDimension(layoutHeights, npcHeights, relativeHeights, size.getHeight(), conversionCtx, false); @@ -192,7 +191,7 @@ final class DoSetViewPort { // Firstly allocate the respected widths/heights and calculate how much space remains RList layoutAsList = asList(viewPort.getDataAt(ViewPort.VP_LAYOUT)); int respect = RRuntime.asInteger(layoutAsList.getDataAt(ViewPort.LAYOUT_VRESPECT)); - int[] layoutRespectMat = ((RAbstractIntVector) layoutAsList.getDataAt(ViewPort.LAYOUT_MRESPECT)).materialize().getDataWithoutCopying(); + RAbstractIntVector layoutRespectMat = ((RAbstractIntVector) layoutAsList.getDataAt(ViewPort.LAYOUT_MRESPECT)); if ((reducedHeight > 0 || reducedWidth > 0) && respect > 0) { double sumRelWidth = sumRelativeDimension(layoutWidths, relativeWidths, parentVPCtx, device, gpar, true); double sumRelHeight = sumRelativeDimension(layoutHeights, relativeHeights, parentVPCtx, device, gpar, false); @@ -253,12 +252,12 @@ final class DoSetViewPort { allocateRelativeDim(layoutSize, layoutHeights, npcHeights, relativeHeights, reducedHeight, respect, layoutRespectMat, device, gpar, parentVPCtx, false); // Create the result - Object[] vpData = viewPort.getDataWithoutCopying(); - vpData[ViewPort.PVP_WIDTHS] = RDataFactory.createDoubleVector(npcWidths, RDataFactory.COMPLETE_VECTOR); - vpData[ViewPort.PVP_HEIGHTS] = RDataFactory.createDoubleVector(npcHeights, RDataFactory.COMPLETE_VECTOR); + viewPort.setDataAt(ViewPort.PVP_WIDTHS, RDataFactory.createDoubleVector(npcWidths, RDataFactory.COMPLETE_VECTOR)); + viewPort.setDataAt(ViewPort.PVP_HEIGHTS, RDataFactory.createDoubleVector(npcHeights, RDataFactory.COMPLETE_VECTOR)); } - private static void allocateRelativeDim(LayoutSize layoutSize, RAbstractContainer layoutItems, double[] npcItems, boolean[] relativeItems, double reducedDim, int respect, int[] layoutRespectMat, + private static void allocateRelativeDim(LayoutSize layoutSize, RAbstractContainer layoutItems, double[] npcItems, boolean[] relativeItems, double reducedDim, int respect, + RAbstractIntVector layoutRespectMat, GridDevice device, GPar gpar, ViewPortContext parentVPCtx, boolean isWidth) { assert relativeItems.length == npcItems.length; UnitConversionContext layoutModeCtx = new UnitConversionContext(new Size(0, 0), parentVPCtx, device, gpar, 1, 0); @@ -282,28 +281,28 @@ final class DoSetViewPort { } } - private static boolean rowColRespected(int respected, int rowOrCol, int[] layoutRespectMat, LayoutSize layoutSize, boolean isColumn) { + private static boolean rowColRespected(int respected, int rowOrCol, RAbstractIntVector layoutRespectMat, LayoutSize layoutSize, boolean isColumn) { return isColumn ? colRespected(respected, rowOrCol, layoutRespectMat, layoutSize) : rowRespected(respected, rowOrCol, layoutRespectMat, layoutSize); } - private static boolean rowRespected(int respected, int row, int[] layoutRespectMat, LayoutSize layoutSize) { + private static boolean rowRespected(int respected, int row, RAbstractIntVector layoutRespectMat, LayoutSize layoutSize) { if (respected == 1) { return true; } for (int i = 0; i < layoutSize.ncol; i++) { - if (layoutRespectMat[i * layoutSize.nrow + row] != 0) { + if (layoutRespectMat.getDataAt(i * layoutSize.nrow + row) != 0) { return true; } } return false; } - private static boolean colRespected(int respected, int col, int[] layoutRespectMat, LayoutSize layoutSize) { + private static boolean colRespected(int respected, int col, RAbstractIntVector layoutRespectMat, LayoutSize layoutSize) { if (respected == 1) { return true; } for (int i = 0; i < layoutSize.nrow; i++) { - if (layoutRespectMat[col * layoutSize.nrow + i] != 0) { + if (layoutRespectMat.getDataAt(col * layoutSize.nrow + i) != 0) { return true; } } @@ -344,8 +343,8 @@ final class DoSetViewPort { // positions replaced with nrow/ncol already. private static ViewPortLocation calcViewportLocationFromLayout(LayoutPos pos, RList parentVP, Size parentSize) { // unlike in GnuR, we maintain parent viewport widths/heights in inches like anything else - double[] widths = GridUtils.asDoubleVector(parentVP.getDataAt(ViewPort.PVP_WIDTHS)).materialize().getDataWithoutCopying(); - double[] heights = GridUtils.asDoubleVector(parentVP.getDataAt(ViewPort.PVP_HEIGHTS)).materialize().getDataWithoutCopying(); + RAbstractDoubleVector widths = GridUtils.asDoubleVector(parentVP.getDataAt(ViewPort.PVP_WIDTHS)); + RAbstractDoubleVector heights = GridUtils.asDoubleVector(parentVP.getDataAt(ViewPort.PVP_HEIGHTS)); double totalWidth = sum(widths, 0, pos.layoutSize.ncol); double totalHeight = sum(heights, 0, pos.layoutSize.nrow); double width = sum(widths, pos.colMin, pos.colMax - pos.colMin + 1); diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GPar.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GPar.java index adba03004cfa945ccba56231ed7b4f4140995caa..cbffadad5796a831a4f1843024f6780bf1f4837a 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GPar.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GPar.java @@ -168,37 +168,37 @@ public final class GPar { } private static final class GParDrawingContext implements DrawingContext { - private final Object[] data; + private final RList data; private final int index; private GParDrawingContext(RList list, int index) { - data = list.getDataWithoutCopying(); + data = list; this.index = index; } @Override public byte[] getLineType() { - return convertNamedValue(data[GP_LTY], LINE_STYLES.length - 1, "line type", GParDrawingContext::lineTypeFromName, num -> LINE_STYLES[num]); + return convertNamedValue(data.getDataAt(GP_LTY), LINE_STYLES.length - 1, "line type", GParDrawingContext::lineTypeFromName, num -> LINE_STYLES[num]); } @Override public double getLineWidth() { - return asDouble(data[GP_LWD], index) * asDouble(data[GP_LEX], index); + return asDouble(data.getDataAt(GP_LWD), index) * asDouble(data.getDataAt(GP_LEX), index); } @Override public GridLineJoin getLineJoin() { - return convertNamedValue(data[GP_LINEJOIN], GridLineJoin.LAST_VALUE, "line join", GParDrawingContext::lineJoinFromName, GridLineJoin::fromInt); + return convertNamedValue(data.getDataAt(GP_LINEJOIN), GridLineJoin.LAST_VALUE, "line join", GParDrawingContext::lineJoinFromName, GridLineJoin::fromInt); } @Override public GridLineEnd getLineEnd() { - return convertNamedValue(data[GP_LINEEND], GridLineEnd.LAST_VALUE, "line end", GParDrawingContext::lineEndFromName, GridLineEnd::fromInt); + return convertNamedValue(data.getDataAt(GP_LINEEND), GridLineEnd.LAST_VALUE, "line end", GParDrawingContext::lineEndFromName, GridLineEnd::fromInt); } @Override public double getLineMitre() { - double value = asDouble(data[GP_LINEMITRE], index); + double value = asDouble(data.getDataAt(GP_LINEMITRE), index); if (value < 1.) { throw RError.error(RError.NO_CALLER, Message.GENERIC, "Invalid line mitre."); } @@ -212,22 +212,22 @@ public final class GPar { @Override public double getFontSize() { - return asDouble(data[GP_FONTSIZE], index) * asDouble(data[GP_CEX], index); + return asDouble(data.getDataAt(GP_FONTSIZE), index) * asDouble(data.getDataAt(GP_CEX), index); } @Override public GridFontStyle getFontStyle() { - return GridFontStyle.fromInt(GridUtils.asInt(data[GP_FONT], index)); + return GridFontStyle.fromInt(GridUtils.asInt(data.getDataAt(GP_FONT), index)); } @Override public String getFontFamily() { - return GridUtils.asString(data[GP_FONTFAMILY], index); + return GridUtils.asString(data.getDataAt(GP_FONTFAMILY), index); } @Override public double getLineHeight() { - return asDouble(data[GP_LINEHEIGHT], index); + return asDouble(data.getDataAt(GP_LINEHEIGHT), index); } @Override @@ -264,9 +264,9 @@ public final class GPar { } private GridColor getGridColor(int listIndex) { - Object value = data[listIndex]; + Object value = data.getDataAt(listIndex); GridColor color = GridColorUtils.getColor(value, index); - double alpha = asDouble(data[GP_ALPHA], index); + double alpha = asDouble(data.getDataAt(GP_ALPHA), index); if (alpha != 1.) { int newAlpha = Math.min(255, (int) (alpha * ((color.getAlpha() / 255.0) * 255))); return new GridColor(color.getRed(), color.getGreen(), color.getBlue(), newAlpha); diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridState.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridState.java index 5579a9051982fdcfa38d77d60f9ddb4a1c316fd8..3150a167f08fb8c0c35a75239d94af3ad8744ece 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridState.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridState.java @@ -70,8 +70,7 @@ public final class GridState { } public void setDisplayListElement(Object element) { - Object[] data = devState.displayList.getDataWithoutCopying(); - data[devState.displayListIndex] = element; + devState.displayList.setDataAt(devState.displayListIndex, element); } public boolean isDisplayListOn() { diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridUtils.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridUtils.java index e88b9cf5a61311e6d7e7e7d1a013a1a2ff686476..494d46df7e6f70fcbbdf23bb8a27ff6a162dc6b9 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridUtils.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridUtils.java @@ -228,13 +228,17 @@ final class GridUtils { } static double sum(double[] values) { - return sum(values, 0, values.length); + double result = 0; + for (int i = 0; i < values.length; i++) { + result += values[i]; + } + return result; } - static double sum(double[] values, int from, int length) { + static double sum(RAbstractDoubleVector values, int from, int length) { double result = 0; for (int i = 0; i < length; i++) { - result += values[from + i]; + result += values.getDataAt(from + i); } return result; } diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LPretty.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LPretty.java index 2d447deb2c14deb1ba1fcc1194328383ee72480f..08726045729118459ef08538939f458358c6b2d0 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LPretty.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LPretty.java @@ -50,7 +50,7 @@ public abstract class LPretty extends RExternalBuiltinNode.Arg1 { double[] ns = new double[]{min}; double[] nu = new double[]{max}; int[] ndiv = new int[]{5}; - double unit = PrettyIntevals.pretty(getErrorContext(), ns, nu, new int[]{5}, 1, 0.25, new double[]{.8, 1.7}, 2, false); + double unit = PrettyIntevals.pretty(getErrorContext(), ns, nu, new int[]{5}, 1, 0.25, .8, 1.7, 2, false); if (nu[0] >= ns[0] + 1) { if (ns[0] * unit < min - 1e-7 * unit) { diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LRaster.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LRaster.java index 2b9c075642ab3c89aefe158d5deeea4e92fa5d4c..4773b94e0cf2ff93d2a6c4356f6cc1a7193b3db7 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LRaster.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LRaster.java @@ -25,6 +25,7 @@ import com.oracle.truffle.r.nodes.builtin.RExternalBuiltinNode; import com.oracle.truffle.r.runtime.RError.Message; import com.oracle.truffle.r.runtime.RInternalError; import com.oracle.truffle.r.runtime.RRuntime; +import com.oracle.truffle.r.runtime.data.RIntVector; import com.oracle.truffle.r.runtime.data.RList; import com.oracle.truffle.r.runtime.data.RNull; import com.oracle.truffle.r.runtime.data.RStringVector; @@ -75,7 +76,8 @@ public abstract class LRaster extends RExternalBuiltinNode.Arg8 { int[] pixels; if (raster instanceof RAbstractIntVector && isNativeRaster(raster)) { - pixels = ((RAbstractIntVector) raster).materialize().getDataWithoutCopying(); + RIntVector rasterVec = ((RAbstractIntVector) raster).materialize(); + pixels = rasterVec.getDataTemp(); } else { int rasterLen = raster.getLength(); pixels = new int[rasterLen]; diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LUnsetViewPort.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LUnsetViewPort.java index 5ff2d5c8a54518cfc4ed3b061bb01c86bd4f6c34..25124315ba09c9331b4c42845b9cb6b95e97463e 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LUnsetViewPort.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LUnsetViewPort.java @@ -74,7 +74,7 @@ public abstract class LUnsetViewPort extends RExternalBuiltinNode.Arg1 { gridState.setViewPort(newVp); // remove the parent link from the old viewport - gvp.setDataAt(gvp.getInternalStore(), ViewPort.PVP_PARENT, RNull.instance); + gvp.setDataAt(ViewPort.PVP_PARENT, RNull.instance); return RNull.instance; } diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/TransformMatrix.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/TransformMatrix.java index 28ed32b803c8510197c5f581ff4144f0a8b7e6d3..ae64fd26f0d13217bc1f8904b8e3e03a04226581 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/TransformMatrix.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/TransformMatrix.java @@ -15,6 +15,7 @@ import static com.oracle.truffle.r.runtime.nmath.MathConstants.M_PI; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RError.Message; +import com.oracle.truffle.r.runtime.data.model.RAbstractDoubleVector; // transcribed from matrix.c @@ -111,11 +112,11 @@ final class TransformMatrix { /** * Reverse operation to {@link #flatten(double[][])}. */ - static double[][] fromFlat(double[] flat) { + static double[][] fromFlat(RAbstractDoubleVector flat) { double[][] res = new double[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - res[i][j] = flat[i + j * 3]; + res[i][j] = flat.getDataAt(i + j * 3); } } return res; diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/ViewPort.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/ViewPort.java index 6bd2592e1610cafb8fd09614d33457f6387881da..813782bb255540cbfc5dfae24fc3046158886027 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/ViewPort.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/ViewPort.java @@ -89,12 +89,12 @@ final class ViewPort { double devWidthCm = inchesToCm(device.getWidth()); boolean result = false; if (Math.abs(devWidthCm - asDouble(viewPort.getDataAt(PVP_DEVWIDTHCM))) >= 1e-6) { - viewPort.setDataAt(viewPort.getInternalStore(), PVP_DEVWIDTHCM, devWidthCm); + viewPort.setDataAt(PVP_DEVWIDTHCM, devWidthCm); result = true; } double devHeightCm = inchesToCm(device.getHeight()); if (Math.abs(devHeightCm - asDouble(viewPort.getDataAt(PVP_DEVHEIGHTCM))) >= 1e-6) { - viewPort.setDataAt(viewPort.getInternalStore(), PVP_DEVHEIGHTCM, devHeightCm); + viewPort.setDataAt(PVP_DEVHEIGHTCM, devHeightCm); } return result; } diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/ViewPortTransform.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/ViewPortTransform.java index 179ec60d185947d6dbffb883dca04063d8b9b92f..db897108d618cc89389027f7102dd4f8a08bc9d5 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/ViewPortTransform.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/ViewPortTransform.java @@ -42,7 +42,7 @@ public final class ViewPortTransform { double height = Unit.cmToInches(GridUtils.asDouble(viewPort.getDataAt(ViewPort.PVP_HEIGHTCM))); double rotationAngle = GridUtils.asDouble(viewPort.getDataAt(ViewPort.VP_ANGLE)); RAbstractDoubleVector trans = GridUtils.asDoubleVector(viewPort.getDataAt(ViewPort.PVP_TRANS)); - double[][] transform = TransformMatrix.fromFlat(trans.materialize().getDataWithoutCopying()); + double[][] transform = TransformMatrix.fromFlat(trans); return new ViewPortTransform(width, height, rotationAngle, transform); } } diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/GridDevice.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/GridDevice.java index 87ed10b88a6d2d714f9d08448f05f3b08b49c558..d8ba61ad93f7e9c6605257abb8eb0cc96b26ec3d 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/GridDevice.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/GridDevice.java @@ -97,7 +97,8 @@ public interface GridDevice { /** * Draws a raster image at specified position. The pixels array shall be treated as by row * matrix, the values are values compatible with the internal {@link GridColor} representation, - * e.g. what {@link GridColor#getRawValue()} would return. + * e.g. what {@link GridColor#getRawValue()} would return. The method is not required to make a + * defensive copy. */ void drawRaster(double leftX, double bottomY, double width, double height, int[] pixels, int pixelsColumnsCount, ImageInterpolation interpolation); diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/graphics/CPar.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/graphics/CPar.java index 524eeb912a1a86689b13e6dc427156186d67d920..2f19eafd4df206506301bb1ea24fca902eaaa1b1 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/graphics/CPar.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/graphics/CPar.java @@ -47,19 +47,19 @@ public final class CPar extends RExternalBuiltinNode { } GridDevice device = GridContext.getContext().getCurrentDevice(); - Object[] names = args.getArguments(); + RList names = RDataFactory.createList(args.getArguments()); // unwrap list if it is the first argument - if (names.length == 1) { + if (names.getLength() == 1) { Object first = args.getArgument(0); if (first instanceof RList) { - names = ((RList) first).getDataWithoutCopying(); + names = (RList) first; } } - Object[] result = new Object[names.length]; - String[] resultNames = new String[names.length]; - for (int i = 0; i < names.length; i++) { - resultNames[i] = RRuntime.asString(names[i]); + Object[] result = new Object[names.getLength()]; + String[] resultNames = new String[names.getLength()]; + for (int i = 0; i < names.getLength(); i++) { + resultNames[i] = RRuntime.asString(names.getDataAt(i)); result[i] = getParam(resultNames[i], device); } return RDataFactory.createList(result, RDataFactory.createStringVector(resultNames, RDataFactory.COMPLETE_VECTOR)); diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/GrepFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/GrepFunctions.java index 177902b34d228318732f5c7a32d605c22e6d8115..2df8eb603794c158a712ea6ca84146946623c2cd 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/GrepFunctions.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/GrepFunctions.java @@ -793,7 +793,7 @@ public class GrepFunctions { throw RInternalError.unimplemented("multi-element patterns in regexpr not implemented yet"); } String pattern = patternArg.getDataAt(0); - if (!perl) { + if (!perl && !fixed) { pattern = RegExp.checkPreDefinedClasses(pattern); } // TODO: useBytes normally depends on the value of the parameter and (if false) on @@ -1090,7 +1090,7 @@ public class GrepFunctions { throw RInternalError.unimplemented("multi-element patterns in gregexpr not implemented yet"); } String pattern = patternArg.getDataAt(0); - if (!perl) { + if (!perl && !fixed) { pattern = RegExp.checkPreDefinedClasses(pattern); } // TODO: useBytes normally depends on the value of the parameter and (if false) on @@ -1105,7 +1105,7 @@ public class GrepFunctions { String txt = vector.getDataAt(i); res = RDataFactory.createIntVector(txt.length()); for (int j = 0; j < txt.length(); j++) { - res.setDataAt(res.getDataWithoutCopying(), j, j + 1); + res.setDataAt(res.getInternalStore(), j, j + 1); } setMatchLengthAttrNode.execute(res, RDataFactory.createIntVector(txt.length())); if (useBytes) { diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Order.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Order.java index 3bfa03b8884869ecd48d80de293e189608fc12eb..36df142643555effe37636671ff6dd420550ed41 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Order.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Order.java @@ -85,9 +85,8 @@ public abstract class Order extends RPrecedenceBuiltinNode { int n = v.getLength(); reportWork(n); - RIntVector indxVec = RDataFactory.createIntVector(createIndexes(v, n, naLast), RDataFactory.COMPLETE_VECTOR); - initOrderVector1(needsStringCollation).execute(indxVec, v, naLast, dec, null); - int[] indx = indxVec.getDataWithoutCopying(); + int[] indx = createIndexes(v, n, naLast); + initOrderVector1(needsStringCollation).execute(indx, v, naLast, dec, null); for (int i = 0; i < indx.length; i++) { indx[i] = indx[i] + 1; } @@ -321,14 +320,13 @@ public abstract class Order extends RPrecedenceBuiltinNode { this.needsStringCollation = needsStringCollation; } - public abstract Object execute(Object v, Object dv, byte naLast, boolean dec, Object rho); + public abstract Object execute(int[] v, Object dv, byte naLast, boolean dec, Object rho); @Specialization - protected Object orderVector1(RIntVector indxVec, RAbstractIntVector dv, byte naLast, boolean decreasing, Object rho) { - if (indxVec.getLength() < 2) { - return indxVec; + protected Object orderVector1(int[] indx, RAbstractIntVector dv, byte naLast, boolean decreasing, Object rho) { + if (indx.length < 2) { + return indx; } - int[] indx = indxVec.getDataWithoutCopying(); int lo = 0; int hi = indx.length - 1; if (rho == null) { @@ -359,15 +357,14 @@ public abstract class Order extends RPrecedenceBuiltinNode { } sort(indx, dv, lo, hi, decreasing); - return indxVec; + return indx; } @Specialization - protected Object orderVector1(RIntVector indxVec, RAbstractDoubleVector dv, byte naLast, boolean decreasing, Object rho) { - if (indxVec.getLength() < 2) { - return indxVec; + protected Object orderVector1(int[] indx, RAbstractDoubleVector dv, byte naLast, boolean decreasing, Object rho) { + if (indx.length < 2) { + return indx; } - int[] indx = indxVec.getDataWithoutCopying(); int lo = 0; int hi = indx.length - 1; if (rho == null && !RRuntime.isNA(naLast)) { @@ -396,15 +393,14 @@ public abstract class Order extends RPrecedenceBuiltinNode { } sort(indx, dv, lo, hi, decreasing); - return indxVec; + return indx; } @Specialization - protected Object orderVector1(RIntVector indxVec, RAbstractStringVector dv, byte naLast, boolean decreasing, Object rho) { - if (indxVec.getLength() < 2) { - return indxVec; + protected Object orderVector1(int[] indx, RAbstractStringVector dv, byte naLast, boolean decreasing, Object rho) { + if (indx.length < 2) { + return indx; } - int[] indx = indxVec.getDataWithoutCopying(); int lo = 0; int hi = indx.length - 1; if (rho == null) { @@ -435,15 +431,14 @@ public abstract class Order extends RPrecedenceBuiltinNode { } sort(indx, dv, lo, hi, decreasing); - return indxVec; + return indx; } @Specialization - protected Object orderVector1(RIntVector indxVec, RAbstractComplexVector dv, byte naLast, boolean decreasing, Object rho) { - if (indxVec.getLength() < 2) { - return indxVec; + protected Object orderVector1(int[] indx, RAbstractComplexVector dv, byte naLast, boolean decreasing, Object rho) { + if (indx.length < 2) { + return indx; } - int[] indx = indxVec.getDataWithoutCopying(); int lo = 0; int hi = indx.length - 1; if (rho == null) { @@ -474,14 +469,14 @@ public abstract class Order extends RPrecedenceBuiltinNode { } sort(indx, dv, lo, hi, decreasing); - return indxVec; + return indx; } @SuppressWarnings("unused") @Specialization - protected Object orderVector1(RIntVector indxVec, RList dv, byte naLast, boolean decreasing, Object rho) { + protected Object orderVector1(int[] indx, RList dv, byte naLast, boolean decreasing, Object rho) { /* Only needed to satisfy .Internal(rank) in unit test */ - return indxVec; + return indx; } private void sort(int[] indx, RAbstractDoubleVector dv, int lo, int hi, boolean dec) { diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Parse.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Parse.java index 5d38f5473f74d870b7c4c5d4ca30384b1758c9b2..30de7c5d7daaeceadfe21a932c989064b9d4a3d2 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Parse.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Parse.java @@ -123,18 +123,17 @@ public abstract class Parse extends RBuiltinNode.Arg6 { } catch (IOException ex) { throw error(RError.Message.PARSE_ERROR); } - return doParse(connection, n, lines, prompt, srcFile, encoding); + return doParse(connection, n, coalesce(lines), prompt, srcFile, encoding); } @TruffleBoundary @Specialization protected RExpression parse(int conn, int n, RAbstractStringVector text, String prompt, Object srcFile, String encoding) { RConnection connection = RConnection.fromIndex(conn); - return doParse(connection, n, text.materialize().getDataWithoutCopying(), prompt, srcFile, encoding); + return doParse(connection, n, coalesce(text), prompt, srcFile, encoding); } - private RExpression doParse(RConnection conn, int n, String[] lines, @SuppressWarnings("unused") String prompt, Object srcFile, @SuppressWarnings("unused") String encoding) { - String coalescedLines = coalesce(lines); + private RExpression doParse(RConnection conn, int n, String coalescedLines, @SuppressWarnings("unused") String prompt, Object srcFile, @SuppressWarnings("unused") String encoding) { if (coalescedLines.length() == 0 || n == 0) { return RDataFactory.createExpression(new Object[0]); } @@ -158,6 +157,15 @@ public abstract class Parse extends RBuiltinNode.Arg6 { } } + private static String coalesce(RAbstractStringVector lines) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < lines.getLength(); i++) { + sb.append(lines.getDataAt(i)); + sb.append('\n'); + } + return sb.toString(); + } + private static String coalesce(String[] lines) { StringBuilder sb = new StringBuilder(); for (String line : lines) { diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Pretty.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Pretty.java index f44ff63f51a6af10e960ba1fefe0eef72d278c69..64f2c9f74462cb4d0ccf2b423d08846d513f9d00 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Pretty.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Pretty.java @@ -63,7 +63,7 @@ public abstract class Pretty extends RBuiltinNode.Arg7 { double[] lo = new double[]{l}; double[] up = new double[]{u}; int[] ndiv = new int[]{n}; - PrettyIntevals.pretty(getErrorContext(), lo, up, ndiv, minN, shrinkSml, hi.materialize().getDataWithoutCopying(), epsCorrect, true); + PrettyIntevals.pretty(getErrorContext(), lo, up, ndiv, minN, shrinkSml, hi.getDataAt(0), hi.getDataAt(1), epsCorrect, true); Object[] data = new Object[3]; data[0] = lo[0]; data[1] = up[0]; diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Rank.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Rank.java index c15016ffb9bde4c2dc0f275de2ff1e4e00574c51..d9c48f7c886237a56d7b9b13298cbf3e4f14aa9a 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Rank.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Rank.java @@ -42,7 +42,6 @@ import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.RType; import com.oracle.truffle.r.runtime.builtins.RBuiltin; import com.oracle.truffle.r.runtime.data.RDataFactory; -import com.oracle.truffle.r.runtime.data.RIntVector; import com.oracle.truffle.r.runtime.data.model.RAbstractLogicalVector; import com.oracle.truffle.r.runtime.data.model.RAbstractVector; @@ -112,9 +111,8 @@ public abstract class Rank extends RBuiltinNode.Arg3 { for (int i = 0; i < n; i++) { indx[i] = i; } - RIntVector indxVec = RDataFactory.createIntVector(indx, RDataFactory.COMPLETE_VECTOR); RAbstractVector x = xa instanceof RAbstractLogicalVector ? xa.castSafe(RType.Integer, isNAProfile) : xa; - initOrderVector1().execute(indxVec, x, RRuntime.LOGICAL_TRUE, false, rho); + initOrderVector1().execute(indx, x, RRuntime.LOGICAL_TRUE, false, rho); initOrderCmp(); int j; for (int i = 0; i < n; i = j + 1) { diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/printer/ValuePrinterNode.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/printer/ValuePrinterNode.java index ca3ba2e74e589591a357d2425a26f2377b40e656..bea08a0ce86a96e7a6b346089e5ff581d582c9e4 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/printer/ValuePrinterNode.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/printer/ValuePrinterNode.java @@ -289,7 +289,7 @@ public final class ValuePrinterNode extends RBaseNode { RAbstractStringVector abstractNames = new RStringWrapper(size, keys); RStringVector names = RDataFactory.createStringVector(size); for (int i = 0; i < size; i++) { - names.getDataWithoutCopying()[i] = abstractNames.getDataAt(i); + names.setDataAt(names.getInternalStore(), i, abstractNames.getDataAt(i)); } class RListWrapper extends TruffleObjectWrapper implements RAbstractListVector { diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/PrettyIntevals.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/PrettyIntevals.java index 9ff10b704e4d1081c3428ab59cd5977bd756e0f7..f7fa13723450f65b89e1801f4b38fcbf5988970b 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/PrettyIntevals.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/PrettyIntevals.java @@ -25,7 +25,7 @@ public final class PrettyIntevals { // transcribed from pretty.c public static double pretty(RBaseNode errorCtx, double[] lo, double[] up, int[] ndiv, int minN, - double shrinkSml, double[] highUFact, + double shrinkSml, double highUFact0, double highUFact1, int epsCorrection, boolean returnBounds) { /* * From version 0.65 on, we had rounding_eps := 1e-5, before, r..eps = 0 1e-7 is consistent @@ -33,8 +33,8 @@ public final class PrettyIntevals { */ double roundingEps = 1e-7; - double h = highUFact[0]; - double h5 = highUFact[1]; + double h = highUFact0; + double h5 = highUFact1; double dx; double cell; diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RListBase.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RListBase.java index abd4bf2d470f48fa9cc444720952e6ec17ef19c6..4a796edb8499890e7203816ac3d434c52f90d2f7 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RListBase.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RListBase.java @@ -77,6 +77,10 @@ public abstract class RListBase extends RVector<Object[]> implements RAbstractLi return ((Object[]) store)[index]; } + public void setDataAt(int index, Object value) { + setDataAt(data, index, value); + } + @Override public void setDataAt(Object store, int index, Object valueArg) { assert valueArg != null : "lists must not contain nulls"; diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test index 35e626cff237e38f505e8f81d7783ab4d59a2614..6ece459577d039a5b1fc206a9d530e9c0e187206 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test @@ -25389,6 +25389,61 @@ attr(,"useBytes") [1] TRUE +##com.oracle.truffle.r.test.builtins.TestBuiltin_gregexpr.testRegExpr#Output.IgnoreErrorMessage# +#gregexpr('(', 'abc()', fixed = FALSE) +Error in gregexpr("(", "abc()", fixed = FALSE) : + invalid regular expression '(', reason 'Missing ')'' + +##com.oracle.truffle.r.test.builtins.TestBuiltin_gregexpr.testRegExpr# +#gregexpr('(', 'abc()', fixed = TRUE) +[[1]] +[1] 4 +attr(,"match.length") +[1] 1 +attr(,"useBytes") +[1] TRUE + + +##com.oracle.truffle.r.test.builtins.TestBuiltin_gregexpr.testRegExpr# +#gregexpr(')', 'abc()', fixed = FALSE) +[[1]] +[1] 5 +attr(,"match.length") +[1] 1 +attr(,"useBytes") +[1] TRUE + + +##com.oracle.truffle.r.test.builtins.TestBuiltin_gregexpr.testRegExpr# +#gregexpr(')', 'abc()', fixed = TRUE) +[[1]] +[1] 5 +attr(,"match.length") +[1] 1 +attr(,"useBytes") +[1] TRUE + + +##com.oracle.truffle.r.test.builtins.TestBuiltin_gregexpr.testRegExpr# +#gregexpr('\\(', 'abc()', fixed = FALSE) +[[1]] +[1] 4 +attr(,"match.length") +[1] 1 +attr(,"useBytes") +[1] TRUE + + +##com.oracle.truffle.r.test.builtins.TestBuiltin_gregexpr.testRegExpr# +#gregexpr('\\)', 'abc()', fixed = FALSE) +[[1]] +[1] 5 +attr(,"match.length") +[1] 1 +attr(,"useBytes") +[1] TRUE + + ##com.oracle.truffle.r.test.builtins.TestBuiltin_gregexpr.testRegExpr# #{ .Internal(gregexpr("7", 42, F, F, F, F)) } Error: invalid 'text' argument @@ -47602,6 +47657,51 @@ attr(,"match.length") attr(,"useBytes") [1] TRUE +##com.oracle.truffle.r.test.builtins.TestBuiltin_regexpr.testRegExpr#Output.IgnoreErrorMessage# +#regexpr('(', 'abc()', fixed = FALSE) +Error in regexpr("(", "abc()", fixed = FALSE) : + invalid regular expression '(', reason 'Missing ')'' + +##com.oracle.truffle.r.test.builtins.TestBuiltin_regexpr.testRegExpr# +#regexpr('(', 'abc()', fixed = TRUE) +[1] 4 +attr(,"match.length") +[1] 1 +attr(,"useBytes") +[1] TRUE + +##com.oracle.truffle.r.test.builtins.TestBuiltin_regexpr.testRegExpr# +#regexpr(')', 'abc()', fixed = FALSE) +[1] 5 +attr(,"match.length") +[1] 1 +attr(,"useBytes") +[1] TRUE + +##com.oracle.truffle.r.test.builtins.TestBuiltin_regexpr.testRegExpr# +#regexpr(')', 'abc()', fixed = TRUE) +[1] 5 +attr(,"match.length") +[1] 1 +attr(,"useBytes") +[1] TRUE + +##com.oracle.truffle.r.test.builtins.TestBuiltin_regexpr.testRegExpr# +#regexpr('\\(', 'abc()', fixed = FALSE) +[1] 4 +attr(,"match.length") +[1] 1 +attr(,"useBytes") +[1] TRUE + +##com.oracle.truffle.r.test.builtins.TestBuiltin_regexpr.testRegExpr# +#regexpr('\\)', 'abc()', fixed = FALSE) +[1] 5 +attr(,"match.length") +[1] 1 +attr(,"useBytes") +[1] TRUE + ##com.oracle.truffle.r.test.builtins.TestBuiltin_regexpr.testRegExpr# #{ .Internal(regexpr("7", 42, F, F, F, F)) } Error: invalid 'text' argument diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_gregexpr.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_gregexpr.java index 1d55ebbc8d048b622032a4ea4790025fdfebdb9e..08a34adfe09cbfd428691e2662983018c2d2eede 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_gregexpr.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_gregexpr.java @@ -120,5 +120,12 @@ public class TestBuiltin_gregexpr extends TestBase { assertEval("{ x<-c(\"Aaa bbb Aaa Bbb\", \"Aaa bbb Aaa bbb\", \"Aaa bbb Aaa Bbb\"); p<-\"(?<first>[[:upper:]][[:lower:]]+) (?<last>[[:upper:]][[:lower:]]+)\"; gregexpr(p, x, perl=TRUE) }"); assertEval("{ x<-c(\"Aaa bbb Aaa bbb\", \"Aaa Bbb Aaa Bbb\", \"Aaa bbb Aaa bbb\"); p<-\"(?<first>[[:upper:]][[:lower:]]+) (?<last>[[:upper:]][[:lower:]]+)\"; gregexpr(p, x, perl=TRUE) }"); + assertEval("gregexpr(')', 'abc()', fixed = TRUE)"); + assertEval("gregexpr('(', 'abc()', fixed = TRUE)"); + assertEval("gregexpr(')', 'abc()', fixed = FALSE)"); + assertEval("gregexpr('\\\\)', 'abc()', fixed = FALSE)"); + assertEval(Output.IgnoreErrorMessage, "gregexpr('(', 'abc()', fixed = FALSE)"); + assertEval("gregexpr('\\\\(', 'abc()', fixed = FALSE)"); + } } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_regexpr.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_regexpr.java index a4ed9501b845b8a1d136c6dc81d157fb66f2d481..a9e76b8ee72c34108539805352efdaffc24c6933 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_regexpr.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_regexpr.java @@ -118,5 +118,11 @@ public class TestBuiltin_regexpr extends TestBase { assertEval("{ x<-c(\"Aaa bbb Aaa bbb\", \"Aaa Bbb Aaa Bbb\"); p<-\"(?<first>[[:upper:]][[:lower:]]+) (?<last>[[:upper:]][[:lower:]]+)\"; regexpr(p, x, perl=TRUE) }"); assertEval("{ x<-c(\"Aaa bbb Aaa bbb\", \"Aaa Bbb Aaa Bbb\", \"Aaa bbb Aaa bbb\"); p<-\"(?<first>[[:upper:]][[:lower:]]+) (?<last>[[:upper:]][[:lower:]]+)\"; regexpr(p, x, perl=TRUE) }"); + assertEval("regexpr(')', 'abc()', fixed = TRUE)"); + assertEval("regexpr('(', 'abc()', fixed = TRUE)"); + assertEval("regexpr(')', 'abc()', fixed = FALSE)"); + assertEval("regexpr('\\\\)', 'abc()', fixed = FALSE)"); + assertEval(Output.IgnoreErrorMessage, "regexpr('(', 'abc()', fixed = FALSE)"); + assertEval("regexpr('\\\\(', 'abc()', fixed = FALSE)"); } } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/engine/shell/TestJLineConsoleCompleter.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/engine/shell/TestJLineConsoleCompleter.java index eaabb32efebf6e106e3d3b75a0b94911d2edf486..d42b412385fbd6c7b1d67a625bd7bc4dea428eca 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/engine/shell/TestJLineConsoleCompleter.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/engine/shell/TestJLineConsoleCompleter.java @@ -32,10 +32,10 @@ import org.graalvm.polyglot.Context; import org.junit.After; import org.junit.Assert; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import com.oracle.truffle.r.launcher.JLineConsoleCompleter; +import org.junit.Ignore; public class TestJLineConsoleCompleter { @@ -70,10 +70,27 @@ public class TestJLineConsoleCompleter { assertCompl("$", 1); assertCompl("strt", 4, "strtoi", "strtrim"); + assertCompl("strt", 5); + assertCompl("strt", 6); + assertCompl("strto", 5, "strtoi"); assertCompl("strtoi", 5, "strtoi"); assertCompl("strtoi", 4, "strtoi", "strtrim"); assertCompl("strto ", 6); + assertCompl("strto,", 6); + assertCompl("blabla,strt", 11, "strtoi", "strtrim"); + assertCompl("blabla strt", 11, "strtoi", "strtrim"); + assertCompl("blabla,,strt", 12, "strtoi", "strtrim"); + assertCompl("blabla strt", 12, "strtoi", "strtrim"); + assertCompl("blabla, strt", 12, "strtoi", "strtrim"); + // Checkstyle: stop + assertCompl("blabla ,strt", 12, "strtoi", "strtrim"); + // Checkstyle: resume + + assertCompl("source('a')", 10); + assertCompl("source('a')", 11); + assertCompl("source('a') ", 12); + assertCompl("source('a') ", 13); assertCompl("base::strt", 10, "base::strtoi", "base::strtrim"); assertCompl("base:::strt", 11, "base:::strtoi", "base:::strtrim"); @@ -88,6 +105,30 @@ public class TestJLineConsoleCompleter { assertCompl("f(strt(strto", 11, "strtoi", "strtrim"); assertCompl("f(strt(strto", 12, "strtoi"); + assertCompl("grep(", 5, "fixed=", "ignore.case=", "invert=", "pattern=", "perl=", "useBytes=", "value=", "x="); + assertCompl("grep(pattern=\"a\",", 17, "fixed=", "ignore.case=", "invert=", "pattern=", "perl=", "useBytes=", "value=", "x="); + assertCompl("grep(pattern=\"a\"", 16); + assertCompl("grep(pattern=\"a\", fixe", 22, "fixed="); + + assertCompl("grep (patt", 10, "pattern="); + assertCompl("grep,(patt", 10, "pattern="); + assertCompl("grep (patt", 11, "pattern="); + assertCompl("grep,,(patt", 11, "pattern="); + // Checkstyle: stop + assertCompl("grep ,(patt", 11, "pattern="); + // Checkstyle: resume + assertCompl("grep, (patt", 11, "pattern="); + + assertCompl("grep(patt ", 10, "fixed=", "ignore.case=", "invert=", "pattern=", "perl=", "useBytes=", "value=", "x="); + assertCompl("grep (patt ", 11, "fixed=", "ignore.case=", "invert=", "pattern=", "perl=", "useBytes=", "value=", "x="); + assertCompl("grep (patt ", 12, "fixed=", "ignore.case=", "invert=", "pattern=", "perl=", "useBytes=", "value=", "x="); + + // show only arguments for 'cor', and not also those for 'cor.test', 'cor.test.name' etc. + assertCompl("cor(", 3, "cor", "cor.test"); + assertCompl("cor(", 4, "method=", "use=", "x=", "y="); + assertCompl("cor(", 5, "method=", "use=", "x=", "y="); + assertCompl("cor( ", 5, "method=", "use=", "x=", "y="); + String noName = "_f_f_f_"; assertCompl(noName + ".", 7); assertCompl(noName + ".", 8);