diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/UnaryNotNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/UnaryNotNode.java index f62c4c154217387146f55c2badeb8ead10290a0c..262744ccbc8d1c49b2ff8e24764da72133cc4a8a 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/UnaryNotNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/UnaryNotNode.java @@ -32,6 +32,7 @@ import com.oracle.truffle.r.runtime.RDispatch; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.data.RAttributeProfiles; +import com.oracle.truffle.r.runtime.data.RComplex; import com.oracle.truffle.r.runtime.data.RDataFactory; import com.oracle.truffle.r.runtime.data.RList; import com.oracle.truffle.r.runtime.data.RLogicalVector; @@ -64,6 +65,10 @@ public abstract class UnaryNotNode extends RBuiltinNode { return RRuntime.asLogical(operand == 0); } + private static byte not(RComplex operand) { + return RRuntime.asLogical(operand.getRealPart() == 0 && operand.getImaginaryPart() == 0); + } + private static byte notRaw(RRaw operand) { return (byte) (255 - operand.getValue()); } @@ -145,6 +150,25 @@ public abstract class UnaryNotNode extends RBuiltinNode { return resultVector; } + @Specialization + protected RLogicalVector doComplexVector(RAbstractComplexVector vector) { + int length = vector.getLength(); + byte[] result; + if (zeroLengthProfile.profile(length == 0)) { + result = new byte[0]; + } else { + na.enable(vector); + result = new byte[length]; + for (int i = 0; i < length; i++) { + RComplex value = vector.getDataAt(i); + result[i] = na.check(value) ? RRuntime.LOGICAL_NA : not(value); + } + } + RLogicalVector resultVector = RDataFactory.createLogicalVector(result, na.neverSeenNA()); + resultVector.copyNamesDimsDimNamesFrom(attrProfiles, vector, this); + return resultVector; + } + @Specialization protected RRawVector doRawVector(RRawVector vector) { int length = vector.getLength(); @@ -167,11 +191,6 @@ public abstract class UnaryNotNode extends RBuiltinNode { return RDataFactory.createEmptyLogicalVector(); } - @Specialization(guards = {"vector.getLength() == 0"}) - protected RLogicalVector doComplexVector(@SuppressWarnings("unused") RAbstractComplexVector vector) { - return RDataFactory.createEmptyLogicalVector(); - } - @Specialization(guards = {"list.getLength() == 0"}) protected RLogicalVector doList(@SuppressWarnings("unused") RList list) { return RDataFactory.createEmptyLogicalVector(); 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 99635c1c275c375792042d4e7b39b0ac771f65ea..e56dcc464d1341cddb360151da793f69638f8734 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 @@ -61674,6 +61674,10 @@ Error in if (x) 1 else 2 : argument is of length zero #{ f <- function(x) { if (x) 1 else 2 } ; f(NA) } Error in if (x) 1 else 2 : missing value where TRUE/FALSE needed +##com.oracle.truffle.r.test.library.base.TestSimpleIfEvaluator.testIf +#{ if (!(7+42i)) TRUE else FALSE } +[1] FALSE + ##com.oracle.truffle.r.test.library.base.TestSimpleIfEvaluator.testIf #{ if (FALSE==1) TRUE else FALSE } [1] FALSE diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/base/TestSimpleIfEvaluator.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/base/TestSimpleIfEvaluator.java index a5ac77267d6ec78356debd95a9cdbaadb97cedd4..29916d0e1ff7336ebd230a55f0682d04e89376b4 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/base/TestSimpleIfEvaluator.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/base/TestSimpleIfEvaluator.java @@ -68,6 +68,7 @@ public class TestSimpleIfEvaluator extends TestBase { assertEval("{ if (FALSE==1) TRUE else FALSE }"); assertEval("{ f <- function(v) { if (FALSE==v) TRUE else FALSE } ; f(TRUE) ; f(1) }"); assertEval(Output.ContainsError, Output.ContainsWarning, "{ x<-list(1,2); if (x) 7 else 42 }"); + assertEval("{ if (!(7+42i)) TRUE else FALSE }"); } @Test