diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RDeparse.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RDeparse.java index c2591fed09b1daa0da4629576ead236f5121561a..ee419a0aec3a10299b47b8f8ea5c373be5f88ed6 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RDeparse.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RDeparse.java @@ -578,24 +578,22 @@ public class RDeparse { case BINARY: case BINARY2: RSyntaxElement[] subArgs = ((RSyntaxCall) arg).getSyntaxArguments(); - if (subArgs.length > 2) { - needsParens = false; - break; - } if (subArgs.length == 1) { - if (!isLeft) { + if (!isLeft && (arginfo.prec != RDeparse.PREC_NOT || mainOp.prec != RDeparse.PREC_NOT)) { needsParens = false; break; } if (arginfo.prec == RDeparse.PREC_SUM) { arginfo = arginfo.changePrec(RDeparse.PREC_SIGN); } - } - if (subArgs.length == 2) { + } else if (subArgs.length == 2) { if (mainOp.prec == PREC_COMPARE && arginfo.prec == PREC_COMPARE) { needsParens = true; break; } + } else if (subArgs.length > 2) { + needsParens = false; + break; } needsParens = mainOp.prec > arginfo.prec || (mainOp.prec == arginfo.prec && isLeft == mainOp.rightassoc); break; diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RRuntime.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RRuntime.java index a9b666dd66f0f2c7479aae715fbf41b18eaa5fa0..ad2573744bb9317fe95888c01c962febc5494de3 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RRuntime.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RRuntime.java @@ -865,11 +865,6 @@ public class RRuntime { return RDataFactory.createLogicalVectorFromScalar((Byte) obj); } else if (obj instanceof String) { return RDataFactory.createStringVectorFromScalar((String) obj); - } else if (obj instanceof RComplex) { - RComplex complex = (RComplex) obj; - return RDataFactory.createComplexVector(new double[]{complex.getRealPart(), complex.getImaginaryPart()}, RDataFactory.COMPLETE_VECTOR); - } else if (obj instanceof RRaw) { - return RDataFactory.createRawVector(new byte[]{((RRaw) obj).getValue()}); } else { return obj; } diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RSerialize.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RSerialize.java index 0c171118ede834f66f139028513543cb516212a5..a28f47de137f5aa79972bdf9af6aef0b4dae09eb 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RSerialize.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RSerialize.java @@ -41,16 +41,13 @@ import com.oracle.truffle.r.runtime.data.RArgsValuesAndNames; import com.oracle.truffle.r.runtime.data.RAttributable; import com.oracle.truffle.r.runtime.data.RAttributesLayout; import com.oracle.truffle.r.runtime.data.RComplex; -import com.oracle.truffle.r.runtime.data.RComplexVector; import com.oracle.truffle.r.runtime.data.RDataFactory; import com.oracle.truffle.r.runtime.data.REmpty; import com.oracle.truffle.r.runtime.data.RExpression; import com.oracle.truffle.r.runtime.data.RExternalPtr; import com.oracle.truffle.r.runtime.data.RFunction; -import com.oracle.truffle.r.runtime.data.RIntVector; import com.oracle.truffle.r.runtime.data.RLanguage; import com.oracle.truffle.r.runtime.data.RList; -import com.oracle.truffle.r.runtime.data.RLogicalVector; import com.oracle.truffle.r.runtime.data.RMissing; import com.oracle.truffle.r.runtime.data.RNull; import com.oracle.truffle.r.runtime.data.RPairList; @@ -839,10 +836,7 @@ public class RSerialize { /** * GnuR uses a pairlist to represent attributes, whereas FastR uses the abstract RAttributes - * class. FastR also uses different types to represent data/frame and factor which is - * handled in the setClassAttr. N.B. In theory connections can be unserialized but they are - * unusable, so we don't go to the trouble of converting the {@link RIntVector} - * representation into an {@link RConnection}. + * class. */ @TruffleBoundary private static Object setAttributes(final Object object, Object attr) { @@ -1461,46 +1455,56 @@ public class RSerialize { stream.writeInt(1); writeCHARSXP((String) obj); } else { - outStringVec((RStringVector) obj, true); + outStringVec((RAbstractStringVector) obj, true); } break; } case INTSXP: { - RAbstractIntVector vec = (RAbstractIntVector) obj; - stream.writeInt(vec.getLength()); - for (int i = 0; i < vec.getLength(); i++) { - stream.writeInt(vec.getDataAt(i)); + if (obj instanceof Integer) { + stream.writeInt(1); + stream.writeInt((int) obj); + } else { + RAbstractIntVector vec = (RAbstractIntVector) obj; + stream.writeInt(vec.getLength()); + for (int i = 0; i < vec.getLength(); i++) { + stream.writeInt(vec.getDataAt(i)); + } } break; } case REALSXP: { - RAbstractDoubleVector vec = (RAbstractDoubleVector) obj; - stream.writeInt(vec.getLength()); - for (int i = 0; i < vec.getLength(); i++) { - stream.writeDouble(vec.getDataAt(i)); + if (obj instanceof Double) { + stream.writeInt(1); + stream.writeDouble((double) obj); + } else { + RAbstractDoubleVector vec = (RAbstractDoubleVector) obj; + stream.writeInt(vec.getLength()); + for (int i = 0; i < vec.getLength(); i++) { + stream.writeDouble(vec.getDataAt(i)); + } } break; } case LGLSXP: { // Output as ints - RLogicalVector vec = (RLogicalVector) obj; - stream.writeInt(vec.getLength()); - for (int i = 0; i < vec.getLength(); i++) { - byte val = vec.getDataAt(i); - if (RRuntime.isNA(val)) { - stream.writeInt(RRuntime.INT_NA); - } else { - stream.writeInt(vec.getDataAt(i)); + if (obj instanceof Byte) { + stream.writeInt(1); + stream.writeInt(RRuntime.logical2int((byte) obj)); + } else { + RAbstractLogicalVector vec = (RAbstractLogicalVector) obj; + stream.writeInt(vec.getLength()); + for (int i = 0; i < vec.getLength(); i++) { + stream.writeInt(RRuntime.logical2int(vec.getDataAt(i))); } } break; } case CPLXSXP: { - RComplexVector vec = (RComplexVector) obj; + RAbstractComplexVector vec = (RAbstractComplexVector) obj; stream.writeInt(vec.getLength()); for (int i = 0; i < vec.getLength(); i++) { RComplex val = vec.getDataAt(i); @@ -1551,55 +1555,6 @@ public class RSerialize { break; } - /* - * FastR scalar, (length 1) "vectors" - */ - - case FASTR_INT: { - Integer value = (Integer) obj; - stream.writeInt(1); - stream.writeInt(value); - break; - } - - case FASTR_DOUBLE: { - Double value = (Double) obj; - stream.writeInt(1); - stream.writeDouble(value); - break; - } - - case FASTR_BYTE: { - Byte value = (Byte) obj; - stream.writeInt(1); - if (RRuntime.isNA(value)) { - stream.writeInt(RRuntime.INT_NA); - } else { - stream.writeInt(value); - } - break; - } - - case FASTR_COMPLEX: { - RComplex value = (RComplex) obj; - stream.writeInt(1); - if (RRuntime.isNA(value)) { - stream.writeDouble(RRuntime.DOUBLE_NA); - stream.writeDouble(RRuntime.DOUBLE_NA); - } else { - stream.writeDouble(value.getRealPart()); - stream.writeDouble(value.getImaginaryPart()); - } - break; - } - - case FASTR_CONNECTION: { - RConnection con = (RConnection) obj; - stream.writeInt(1); - stream.writeInt(con.getDescriptor()); - break; - } - /* * The objects that GnuR represents as a pairlist. To avoid stack overflow, * these utilize manual tail recursion on the cdr of the pairlist. @@ -1725,7 +1680,7 @@ public class RSerialize { return result; } - private void outStringVec(RStringVector vec, boolean strsxp) throws IOException { + private void outStringVec(RAbstractStringVector vec, boolean strsxp) throws IOException { if (!strsxp) { stream.writeInt(0); } diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/gnur/SEXPTYPE.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/gnur/SEXPTYPE.java index 4740bd9bc7c7364e73f758441c9621f7c8a45a30..9aa6e79d3426372eac3b29810ce4fb1e4b684449 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/gnur/SEXPTYPE.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/gnur/SEXPTYPE.java @@ -14,9 +14,7 @@ package com.oracle.truffle.r.runtime.gnur; import java.util.HashMap; import java.util.Map; -import com.oracle.truffle.api.source.SourceSection; import com.oracle.truffle.r.runtime.RInternalError; -import com.oracle.truffle.r.runtime.conn.RConnection; import com.oracle.truffle.r.runtime.data.RArgsValuesAndNames; import com.oracle.truffle.r.runtime.data.RComplex; import com.oracle.truffle.r.runtime.data.RComplexVector; @@ -48,18 +46,6 @@ import com.oracle.truffle.r.runtime.env.REnvironment; public enum SEXPTYPE { - /* - * FastR scalar variants of GnuR vector types (other than String) These could be removed in a - * similar way to String, but there is no pressing need. - */ - FASTR_DOUBLE(300, Double.class), - FASTR_INT(301, Integer.class), - FASTR_BYTE(302, Byte.class), - FASTR_COMPLEX(303, RComplex.class), - // very special case - FASTR_SOURCESECTION(306, SourceSection.class), - FASTR_CONNECTION(307, RConnection.class), - NILSXP(0, RNull.class), /* nil ()NULL */ SYMSXP(1, RSymbol.class), /* symbols */ LISTSXP(2, RPairList.class), /* lists of dotted pairs */ @@ -70,10 +56,10 @@ public enum SEXPTYPE { SPECIALSXP(7), /* special forms */ BUILTINSXP(8), /* builtin non-special forms */ CHARSXP(9), /* "scalar" string type (GnuR internal only) */ - LGLSXP(10, RLogicalVector.class), /* logical vectors */ - INTSXP(13, RIntVector.class, RIntSequence.class), /* integer vectors */ - REALSXP(14, RDoubleVector.class, RDoubleSequence.class), /* real variables */ - CPLXSXP(15, RComplexVector.class), /* complex variables */ + LGLSXP(10, RLogicalVector.class, Byte.class), /* logical vectors */ + INTSXP(13, RIntVector.class, RIntSequence.class, Integer.class), /* integer vectors */ + REALSXP(14, RDoubleVector.class, RDoubleSequence.class, Double.class), /* real variables */ + CPLXSXP(15, RComplexVector.class, RComplex.class), /* complex variables */ STRSXP(16, RStringVector.class, String.class), /* string vectors */ DOTSXP(17, RArgsValuesAndNames.class), /* dot-dot-dot object */ ANYSXP(18), /* make "any" args work */ @@ -142,11 +128,9 @@ public enum SEXPTYPE { } } } - // (only) promises, environments and connections have subtypes + // (only) promises and environments have subtypes if (REnvironment.class.isAssignableFrom(fastRClass)) { return ENVSXP; - } else if (RConnection.class.isAssignableFrom(fastRClass)) { - return FASTR_CONNECTION; } else if (RPromise.class.isAssignableFrom(fastRClass)) { return PROMSXP; } @@ -174,52 +158,22 @@ public enum SEXPTYPE { */ public static SEXPTYPE gnuRType(SEXPTYPE type, Object obj) { switch (type) { - case FUNSXP: { + case FUNSXP: RFunction func = (RFunction) obj; if (func.isBuiltin()) { return SEXPTYPE.BUILTINSXP; } else { return SEXPTYPE.CLOSXP; } - } - - case LISTSXP: { + case LISTSXP: RPairList pl = (RPairList) obj; if (pl.getType() != null && pl.getType() == SEXPTYPE.LANGSXP) { return SEXPTYPE.LANGSXP; } else { return type; } - } - - case FASTR_INT: - return SEXPTYPE.INTSXP; - case FASTR_DOUBLE: - return SEXPTYPE.REALSXP; - case FASTR_BYTE: - return SEXPTYPE.LGLSXP; - case FASTR_COMPLEX: - return SEXPTYPE.CPLXSXP; - case FASTR_CONNECTION: - return SEXPTYPE.INTSXP; default: return type; } } - - public static SEXPTYPE convertFastRScalarType(SEXPTYPE type) { - switch (type) { - case FASTR_DOUBLE: - return SEXPTYPE.REALSXP; - case FASTR_INT: - return SEXPTYPE.INTSXP; - case FASTR_BYTE: - return SEXPTYPE.LGLSXP; - case FASTR_COMPLEX: - return SEXPTYPE.CPLXSXP; - default: - assert false; - return null; - } - } } 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 0f04b19455769e560600531552a02a10c009e14f..5d5d443d281f0e6ef3085d33111e737711d7ecaa 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 @@ -61694,6 +61694,90 @@ Error in seq.int(NaN) : 'from' cannot be NA, NaN or infinite #argv <- list(from = 0, to = 0.793110173512391, length.out = FALSE);do.call('seq.int', argv); integer(0) +##com.oracle.truffle.r.test.builtins.TestBuiltin_serialize.testserialize# +#options(keep.source=FALSE); serialize('asdf', connection=NULL) + [1] 58 0a 00 00 00 02 00 03 03 02 00 02 03 00 00 00 00 10 00 00 00 01 00 04 00 +[26] 09 00 00 00 04 61 73 64 66 + +##com.oracle.truffle.r.test.builtins.TestBuiltin_serialize.testserialize# +#options(keep.source=FALSE); serialize(111+8i, connection=NULL) + [1] 58 0a 00 00 00 02 00 03 03 02 00 02 03 00 00 00 00 0f 00 00 00 01 40 5b c0 +[26] 00 00 00 00 00 40 20 00 00 00 00 00 00 + +##com.oracle.truffle.r.test.builtins.TestBuiltin_serialize.testserialize# +#options(keep.source=FALSE); serialize(111, connection=NULL) + [1] 58 0a 00 00 00 02 00 03 03 02 00 02 03 00 00 00 00 0e 00 00 00 01 40 5b c0 +[26] 00 00 00 00 00 + +##com.oracle.truffle.r.test.builtins.TestBuiltin_serialize.testserialize# +#options(keep.source=FALSE); serialize(111L, connection=NULL) + [1] 58 0a 00 00 00 02 00 03 03 02 00 02 03 00 00 00 00 0d 00 00 00 01 00 00 00 +[26] 6f + +##com.oracle.truffle.r.test.builtins.TestBuiltin_serialize.testserialize# +#options(keep.source=FALSE); serialize(FALSE, connection=NULL) + [1] 58 0a 00 00 00 02 00 03 03 02 00 02 03 00 00 00 00 0a 00 00 00 01 00 00 00 +[26] 00 + +##com.oracle.truffle.r.test.builtins.TestBuiltin_serialize.testserialize# +#options(keep.source=FALSE); serialize(NA_character_, connection=NULL) + [1] 58 0a 00 00 00 02 00 03 03 02 00 02 03 00 00 00 00 10 00 00 00 01 00 00 00 +[26] 09 ff ff ff ff + +##com.oracle.truffle.r.test.builtins.TestBuiltin_serialize.testserialize# +#options(keep.source=FALSE); serialize(NA_complex_, connection=NULL) + [1] 58 0a 00 00 00 02 00 03 03 02 00 02 03 00 00 00 00 0f 00 00 00 01 7f f0 00 +[26] 00 00 00 07 a2 7f f0 00 00 00 00 07 a2 + +##com.oracle.truffle.r.test.builtins.TestBuiltin_serialize.testserialize# +#options(keep.source=FALSE); serialize(NA_integer_, connection=NULL) + [1] 58 0a 00 00 00 02 00 03 03 02 00 02 03 00 00 00 00 0d 00 00 00 01 80 00 00 +[26] 00 + +##com.oracle.truffle.r.test.builtins.TestBuiltin_serialize.testserialize# +#options(keep.source=FALSE); serialize(NA_real_, connection=NULL) + [1] 58 0a 00 00 00 02 00 03 03 02 00 02 03 00 00 00 00 0e 00 00 00 01 7f f0 00 +[26] 00 00 00 07 a2 + +##com.oracle.truffle.r.test.builtins.TestBuiltin_serialize.testserialize# +#options(keep.source=FALSE); serialize(TRUE, connection=NULL) + [1] 58 0a 00 00 00 02 00 03 03 02 00 02 03 00 00 00 00 0a 00 00 00 01 00 00 00 +[26] 01 + +##com.oracle.truffle.r.test.builtins.TestBuiltin_serialize.testserialize# +#options(keep.source=FALSE); serialize(as.raw(10), connection=NULL) + [1] 58 0a 00 00 00 02 00 03 03 02 00 02 03 00 00 00 00 18 00 00 00 01 0a + +##com.oracle.truffle.r.test.builtins.TestBuiltin_serialize.testserialize# +#options(keep.source=FALSE); serialize(as.raw(210), connection=NULL) + [1] 58 0a 00 00 00 02 00 03 03 02 00 02 03 00 00 00 00 18 00 00 00 01 d2 + +##com.oracle.truffle.r.test.builtins.TestBuiltin_serialize.testserialize# +#options(keep.source=FALSE); serialize(as.raw(c(1, 55, 210)), connection=NULL) + [1] 58 0a 00 00 00 02 00 03 03 02 00 02 03 00 00 00 00 18 00 00 00 03 01 37 d2 + +##com.oracle.truffle.r.test.builtins.TestBuiltin_serialize.testserialize# +#options(keep.source=FALSE); serialize(c(111+8i, 55+9i, NA), connection=NULL) + [1] 58 0a 00 00 00 02 00 03 03 02 00 02 03 00 00 00 00 0f 00 00 00 03 40 5b c0 +[26] 00 00 00 00 00 40 20 00 00 00 00 00 00 40 4b 80 00 00 00 00 00 40 22 00 00 +[51] 00 00 00 00 7f f0 00 00 00 00 07 a2 7f f0 00 00 00 00 07 a2 + +##com.oracle.truffle.r.test.builtins.TestBuiltin_serialize.testserialize# +#options(keep.source=FALSE); serialize(c(111, 99, NA, 44), connection=NULL) + [1] 58 0a 00 00 00 02 00 03 03 02 00 02 03 00 00 00 00 0e 00 00 00 04 40 5b c0 +[26] 00 00 00 00 00 40 58 c0 00 00 00 00 00 7f f0 00 00 00 00 07 a2 40 46 00 00 +[51] 00 00 00 00 + +##com.oracle.truffle.r.test.builtins.TestBuiltin_serialize.testserialize# +#options(keep.source=FALSE); serialize(c(111L, 11L, 990000L, NA_integer_), connection=NULL) + [1] 58 0a 00 00 00 02 00 03 03 02 00 02 03 00 00 00 00 0d 00 00 00 04 00 00 00 +[26] 6f 00 00 00 0b 00 0f 1b 30 80 00 00 00 + +##com.oracle.truffle.r.test.builtins.TestBuiltin_serialize.testserialize# +#options(keep.source=FALSE); serialize(c(TRUE, FALSE, TRUE, NA, TRUE), connection=NULL) + [1] 58 0a 00 00 00 02 00 03 03 02 00 02 03 00 00 00 00 0a 00 00 00 05 00 00 00 +[26] 01 00 00 00 00 00 00 00 01 80 00 00 00 00 00 00 01 + ##com.oracle.truffle.r.test.builtins.TestBuiltin_serialize.testserialize# #options(keep.source=FALSE); serialize(quote("bar"), connection=NULL) [1] 58 0a 00 00 00 02 00 03 03 02 00 02 03 00 00 00 00 10 00 00 00 01 00 04 00 @@ -71268,6 +71352,14 @@ numeric(0) #unserialize(serialize("Hello world", NULL)) [1] "Hello world" +##com.oracle.truffle.r.test.builtins.TestBuiltin_unserialize.tests# +#unserialize(serialize((1:15)+0.1, NULL)) + [1] 1.1 2.1 3.1 4.1 5.1 6.1 7.1 8.1 9.1 10.1 11.1 12.1 13.1 14.1 15.1 + +##com.oracle.truffle.r.test.builtins.TestBuiltin_unserialize.tests# +#unserialize(serialize(1:15, NULL)) + [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 + ##com.oracle.truffle.r.test.builtins.TestBuiltin_unserialize.tests# #unserialize(serialize(3+2i, NULL)) [1] 3+2i @@ -71292,6 +71384,18 @@ NULL #unserialize(serialize(c(1,2,3,4), NULL)) [1] 1 2 3 4 +##com.oracle.truffle.r.test.builtins.TestBuiltin_unserialize.tests# +#unserialize(serialize(c(1L,2L,99L,NA), NULL)) +[1] 1 2 99 NA + +##com.oracle.truffle.r.test.builtins.TestBuiltin_unserialize.tests# +#unserialize(serialize(c(3+2i, 5+944i, NA), NULL)) +[1] 3+ 2i 5+944i NA + +##com.oracle.truffle.r.test.builtins.TestBuiltin_unserialize.tests# +#unserialize(serialize(c(TRUE, FALSE, NA, FALSE, TRUE), NULL)) +[1] TRUE FALSE NA FALSE TRUE + ##com.oracle.truffle.r.test.builtins.TestBuiltin_unserialize.tests# #unserialize(serialize(data.frame(col1=c(9,8,7), col2=1:3), NULL)) col1 col2 @@ -71455,7 +71559,7 @@ function(x, y = 1, ...) { NA } -##com.oracle.truffle.r.test.builtins.TestBuiltin_unserialize.testunserialize#Ignored.OutputFormatting# +##com.oracle.truffle.r.test.builtins.TestBuiltin_unserialize.testunserialize# #options(keep.source=FALSE); unserialize(serialize(quote(function(x={1 + a},y,...) { !!NA }), connection=NULL)) function(x = { 1 + a @@ -76903,7 +77007,7 @@ Error in cat(x, file = file, sep = c(rep.int(sep, ncolumns - 1), "\n"), : [51] 00 00 00 00 00 00 40 00 00 00 00 00 00 00 40 08 00 00 00 00 00 00 00 00 00 [76] fe -##com.oracle.truffle.r.test.library.base.TestConnections.testRawWriteBinary#Ignored.ImplementationError# +##com.oracle.truffle.r.test.library.base.TestConnections.testRawWriteBinary# #conn <- rawConnection(raw(0), "wb"); value <- list(a=c(1,2,3), b='foo'); save(value, file=conn); rawConnectionValue(conn) [1] 52 44 58 32 0a 58 0a 00 00 00 02 00 03 03 02 00 02 03 00 00 00 04 02 00 00 [26] 00 01 00 04 00 09 00 00 00 05 76 61 6c 75 65 00 00 02 13 00 00 00 02 00 00 diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_serialize.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_serialize.java index 31dbe41a622dbb7f5080345f7bdaf9f4e8baada6..0679742b3e203e2e39342a53b5ff4a00193b7722 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_serialize.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_serialize.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -44,6 +44,24 @@ public class TestBuiltin_serialize extends TestBase { assertEval("options(keep.source=FALSE); serialize(quote(111+11), connection=NULL)"); assertEval("options(keep.source=FALSE); serialize(quote(a+b), connection=NULL)"); + assertEval("options(keep.source=FALSE); serialize(TRUE, connection=NULL)"); + assertEval("options(keep.source=FALSE); serialize(FALSE, connection=NULL)"); + assertEval("options(keep.source=FALSE); serialize(c(TRUE, FALSE, TRUE, NA, TRUE), connection=NULL)"); + assertEval("options(keep.source=FALSE); serialize('asdf', connection=NULL)"); + assertEval("options(keep.source=FALSE); serialize(NA_character_, connection=NULL)"); + assertEval("options(keep.source=FALSE); serialize(NA_complex_, connection=NULL)"); + assertEval("options(keep.source=FALSE); serialize(NA_integer_, connection=NULL)"); + assertEval("options(keep.source=FALSE); serialize(NA_real_, connection=NULL)"); + assertEval("options(keep.source=FALSE); serialize(111L, connection=NULL)"); + assertEval("options(keep.source=FALSE); serialize(c(111L, 11L, 990000L, NA_integer_), connection=NULL)"); + assertEval("options(keep.source=FALSE); serialize(111+8i, connection=NULL)"); + assertEval("options(keep.source=FALSE); serialize(c(111+8i, 55+9i, NA), connection=NULL)"); + assertEval("options(keep.source=FALSE); serialize(111, connection=NULL)"); + assertEval("options(keep.source=FALSE); serialize(c(111, 99, NA, 44), connection=NULL)"); + assertEval("options(keep.source=FALSE); serialize(as.raw(10), connection=NULL)"); + assertEval("options(keep.source=FALSE); serialize(as.raw(210), connection=NULL)"); + assertEval("options(keep.source=FALSE); serialize(as.raw(c(1, 55, 210)), connection=NULL)"); + assertEval("options(keep.source=FALSE); serialize(quote((a+b)), connection=NULL)"); assertEval("options(keep.source=FALSE); serialize(quote((a %asdf% b)), connection=NULL)"); diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_unserialize.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_unserialize.java index 786a26fcd95d42e49bde626fbff43eb454c63004..db3283245f27635d8ca949d6a756141a740bee62 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_unserialize.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_unserialize.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -29,8 +29,8 @@ import com.oracle.truffle.r.test.TestBase; public class TestBuiltin_unserialize extends TestBase { private static final String[] BASIC_TYPE_VALUES = new String[]{ - "c(1,2,3,4)", "3L", "42", "\"Hello world\"", "3+2i", "TRUE", "head(mtcars)", - "data.frame(col1=c(9,8,7), col2=1:3)", "expression(x+1)", "list(1,2)", "NULL" + "c(1,2,3,4)", "3L", "c(1L,2L,99L,NA)", "1:15", "(1:15)+0.1", "42", "\"Hello world\"", "3+2i", "c(3+2i, 5+944i, NA)", "TRUE", "c(TRUE, FALSE, NA, FALSE, TRUE)", + "head(mtcars)", "data.frame(col1=c(9,8,7), col2=1:3)", "expression(x+1)", "list(1,2)", "NULL" }; @Test @@ -88,7 +88,7 @@ public class TestBuiltin_unserialize extends TestBase { assertEval(Output.IgnoreWhitespace, "options(keep.source=FALSE); unserialize(serialize(quote(function(x,y,...) { 1 }), connection=NULL))"); assertEval(Output.IgnoreWhitespace, "options(keep.source=FALSE); unserialize(serialize(quote(function(x,y=1,...) { NA }), connection=NULL))"); assertEval("options(keep.source=FALSE); unserialize(serialize(quote(function(x={1 + a},y,...) { NA }), connection=NULL))"); - assertEval(Ignored.OutputFormatting, "options(keep.source=FALSE); unserialize(serialize(quote(function(x={1 + a},y,...) { !!NA }), connection=NULL))"); + assertEval("options(keep.source=FALSE); unserialize(serialize(quote(function(x={1 + a},y,...) { !!NA }), connection=NULL))"); assertEval("options(keep.source=FALSE); unserialize(serialize(quote(function(x={1 + a},y,...) { !1+5i }), connection=NULL))"); assertEval("options(keep.source=FALSE); unserialize(serialize(quote(function(x={1 + a},y=c(1,2,3),z=\"foo\",...) { !1+5i }), connection=NULL))"); diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/base/TestConnections.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/base/TestConnections.java index a727d532ef283f4fb83c8334c6fbe353a2b4af2d..d96b63d0c3d4512a72b9487321fc5919ab1b4976 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/base/TestConnections.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/base/TestConnections.java @@ -244,7 +244,7 @@ public class TestConnections extends TestRBase { assertEval(Ignored.ImplementationError, "{ s <- \"äöüß\"; rc <- rawConnection(raw(0), \"wb\"); write(charToRaw(s), rc); res <- rawConnectionValue(rc); close(rc); res }"); assertEval("{ zz <- rawConnection(raw(0), \"wb\"); x <- c(\"a\", \"this will be truncated\", \"abc\"); nc <- c(3, 10, 3); writeChar(x, zz, nc, eos = NULL); writeChar(x, zz, eos = \"\\r\\n\"); res <- rawConnectionValue(zz); close(zz); res }"); - assertEval(Ignored.ImplementationError, "conn <- rawConnection(raw(0), \"wb\"); value <- list(a=c(1,2,3), b='foo'); save(value, file=conn); rawConnectionValue(conn)"); + assertEval("conn <- rawConnection(raw(0), \"wb\"); value <- list(a=c(1,2,3), b='foo'); save(value, file=conn); rawConnectionValue(conn)"); // ignored because save refuses to write to a rawConnection that is not configured to binary assertEval(Ignored.ImplementationError, "conn <- rawConnection(raw(0), \"w\"); value <- c(1,2,3); save(value, file=conn); rawConnectionValue(conn)"); }