Skip to content
Snippets Groups Projects
Commit fc7f3b90 authored by Stepan Sindelar's avatar Stepan Sindelar
Browse files

[GR-6959] [GR-6840] Strange interop behaviour of R complex number and other...

[GR-6959] [GR-6840] Strange interop behaviour of R complex number and other fixes in FastR message resolution.

PullRequest: fastr/1250
parents d7aa001e dae8400a
No related branches found
No related tags found
No related merge requests found
Showing
with 354 additions and 126 deletions
......@@ -45,12 +45,12 @@ import com.oracle.truffle.r.nodes.access.vector.ReplaceVectorNode;
import com.oracle.truffle.r.nodes.attributes.SpecialAttributesFunctions.GetNamesAttributeNode;
import com.oracle.truffle.r.nodes.control.RLengthNode;
import com.oracle.truffle.r.runtime.data.NativeDataAccess;
import com.oracle.truffle.r.runtime.data.RDataFactory;
import com.oracle.truffle.r.runtime.data.RExpression;
import com.oracle.truffle.r.runtime.data.RFunction;
import com.oracle.truffle.r.runtime.data.RList;
import com.oracle.truffle.r.runtime.data.RLogical;
import com.oracle.truffle.r.runtime.data.RMissing;
import com.oracle.truffle.r.runtime.data.RNull;
import com.oracle.truffle.r.runtime.data.RPairList;
import com.oracle.truffle.r.runtime.data.RStringVector;
import com.oracle.truffle.r.runtime.data.RTruffleObject;
......@@ -533,6 +533,6 @@ public class ListMR {
private static Object listKeys(TruffleObject receiver, GetNamesAttributeNode getNamesNode) {
RStringVector names = getNamesNode.getNames(receiver);
return names != null ? names : RNull.instance;
return names != null ? names : RDataFactory.createEmptyStringVector();
}
}
......@@ -32,7 +32,7 @@ import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.interop.ForeignAccess;
import com.oracle.truffle.api.interop.ForeignAccess.Factory26;
import com.oracle.truffle.api.interop.ForeignAccess.StandardFactory;
import com.oracle.truffle.api.interop.KeyInfo;
import com.oracle.truffle.api.interop.Message;
import com.oracle.truffle.api.interop.TruffleObject;
......@@ -71,7 +71,7 @@ abstract class InteropRootNode extends RootNode {
}
}
public final class RAbstractVectorAccessFactory implements Factory26 {
public final class RAbstractVectorAccessFactory implements StandardFactory {
abstract static class VectorReadImplNode extends InteropRootNode {
......@@ -245,6 +245,16 @@ public final class RAbstractVectorAccessFactory implements Factory26 {
});
}
@Override
public CallTarget accessIsInstantiable() {
return Truffle.getRuntime().createCallTarget(new InteropRootNode() {
@Override
public Object execute(VirtualFrame frame) {
return false;
}
});
}
@Override
public CallTarget accessIsBoxed() {
return Truffle.getRuntime().createCallTarget(new InteropRootNode() {
......@@ -266,6 +276,16 @@ public final class RAbstractVectorAccessFactory implements Factory26 {
});
}
@Override
public CallTarget accessHasKeys() {
return Truffle.getRuntime().createCallTarget(new InteropRootNode() {
@Override
public Object execute(VirtualFrame frame) {
return false;
}
});
}
@Override
public CallTarget accessGetSize() {
return Truffle.getRuntime().createCallTarget(new InteropRootNode() {
......
/*
* 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.truffle.r.engine.interop;
import com.oracle.truffle.api.interop.CanResolve;
import com.oracle.truffle.api.interop.MessageResolution;
import com.oracle.truffle.api.interop.Resolve;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.r.runtime.data.RComplex;
@MessageResolution(receiverType = RComplex.class)
public class RComplexMR {
@Resolve(message = "IS_BOXED")
public abstract static class RComplexIsBoxedNode extends Node {
protected Object access(@SuppressWarnings("unused") RComplex receiver) {
return false;
}
}
@Resolve(message = "HAS_SIZE")
public abstract static class RComplexHasSizeNode extends Node {
protected Object access(@SuppressWarnings("unused") RComplex receiver) {
return false;
}
}
@Resolve(message = "KEY_INFO")
public abstract static class RComplexKeyInfoNode extends Node {
protected Object access(@SuppressWarnings("unused") RComplex receiver, @SuppressWarnings("unused") Object identifier) {
return 0;
}
}
@CanResolve
public abstract static class RComplexCheck extends Node {
protected static boolean test(TruffleObject receiver) {
return receiver instanceof RComplex;
}
}
}
......@@ -47,7 +47,7 @@ public class RDoubleMR {
@Resolve(message = "KEY_INFO")
public abstract static class RDoubleKeyInfoNode extends Node {
protected Object access(@SuppressWarnings("unused") TruffleObject receiver, @SuppressWarnings("unused") Object identifier) {
protected Object access(@SuppressWarnings("unused") RDouble receiver, @SuppressWarnings("unused") Object identifier) {
return 0;
}
}
......
......@@ -31,6 +31,7 @@ import com.oracle.truffle.r.runtime.conn.RConnection;
import com.oracle.truffle.r.runtime.context.RContext;
import com.oracle.truffle.r.runtime.context.RForeignAccessFactory;
import com.oracle.truffle.r.runtime.data.RArgsValuesAndNames;
import com.oracle.truffle.r.runtime.data.RComplex;
import com.oracle.truffle.r.runtime.data.RDouble;
import com.oracle.truffle.r.runtime.data.REmpty;
import com.oracle.truffle.r.runtime.data.RExpression;
......@@ -44,6 +45,7 @@ import com.oracle.truffle.r.runtime.data.RMissing;
import com.oracle.truffle.r.runtime.data.RNull;
import com.oracle.truffle.r.runtime.data.RPairList;
import com.oracle.truffle.r.runtime.data.RPromise;
import com.oracle.truffle.r.runtime.data.RRaw;
import com.oracle.truffle.r.runtime.data.RS4Object;
import com.oracle.truffle.r.runtime.data.RSymbol;
import com.oracle.truffle.r.runtime.data.RTruffleObject;
......@@ -92,6 +94,10 @@ public final class RForeignAccessFactoryImpl implements RForeignAccessFactory {
return RIntegerMRForeign.ACCESS;
} else if (obj instanceof RDouble) {
return RDoubleMRForeign.ACCESS;
} else if (obj instanceof RComplex) {
return RComplexMRForeign.ACCESS;
} else if (obj instanceof RRaw) {
return RRawMRForeign.ACCESS;
} else if (obj instanceof RConnection) {
return RConnectionMRForeign.ACCESS;
} else if (obj instanceof RContext) {
......
......@@ -40,7 +40,7 @@ public class RIntegerMR {
@Resolve(message = "KEY_INFO")
public abstract static class RIntegerKeyInfoNode extends Node {
protected Object access(@SuppressWarnings("unused") TruffleObject receiver, @SuppressWarnings("unused") Object identifier) {
protected Object access(@SuppressWarnings("unused") RInteger receiver, @SuppressWarnings("unused") Object identifier) {
return 0;
}
}
......
/*
* 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.truffle.r.engine.interop;
import com.oracle.truffle.api.interop.CanResolve;
import com.oracle.truffle.api.interop.MessageResolution;
import com.oracle.truffle.api.interop.Resolve;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.r.runtime.data.RRaw;
@MessageResolution(receiverType = RRaw.class)
public class RRawMR {
@Resolve(message = "IS_BOXED")
public abstract static class RRawIsBoxedNode extends Node {
protected Object access(@SuppressWarnings("unused") RRaw receiver) {
return true;
}
}
@Resolve(message = "UNBOX")
public abstract static class RRawUnboxNode extends Node {
protected Object access(@SuppressWarnings("unused") RRaw receiver) {
return receiver.getValue();
}
}
@Resolve(message = "HAS_SIZE")
public abstract static class RRawHasSizeNode extends Node {
protected Object access(@SuppressWarnings("unused") RRaw receiver) {
return false;
}
}
@Resolve(message = "KEY_INFO")
public abstract static class RRawKeyInfoNode extends Node {
protected Object access(@SuppressWarnings("unused") RRaw receiver, @SuppressWarnings("unused") Object identifier) {
return 0;
}
}
@CanResolve
public abstract static class RComplexCheck extends Node {
protected static boolean test(TruffleObject receiver) {
return receiver instanceof RRaw;
}
}
}
......@@ -25,11 +25,11 @@ package com.oracle.truffle.r.ffi.impl.upcalls;
import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.interop.ForeignAccess.Factory;
import com.oracle.truffle.api.interop.ForeignAccess.Factory26;
import com.oracle.truffle.api.interop.ForeignAccess.StandardFactory;
import com.oracle.truffle.api.interop.Message;
import com.oracle.truffle.api.nodes.RootNode;
public abstract class AbstractDowncallForeign implements Factory26, Factory {
public abstract class AbstractDowncallForeign implements StandardFactory, Factory {
@Override
public CallTarget accessIsNull() {
return Truffle.getRuntime().createCallTarget(RootNode.createConstantNode(false));
......
......@@ -22,7 +22,7 @@
*/
package com.oracle.truffle.r.test.engine.interop;
import static org.junit.Assert.assertEquals;
import com.oracle.truffle.api.interop.ArityException;
import static org.junit.Assert.assertTrue;
import java.util.HashSet;
......@@ -37,8 +37,14 @@ import com.oracle.truffle.api.interop.ForeignAccess;
import com.oracle.truffle.api.interop.InteropException;
import com.oracle.truffle.api.interop.Message;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.interop.UnknownIdentifierException;
import com.oracle.truffle.api.interop.UnsupportedMessageException;
import com.oracle.truffle.api.interop.UnsupportedTypeException;
import com.oracle.truffle.api.vm.PolyglotEngine;
import com.oracle.truffle.r.ffi.impl.interop.NativePointer;
import com.oracle.truffle.r.runtime.data.RNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
public abstract class AbstractMRTest {
......@@ -67,40 +73,29 @@ public abstract class AbstractMRTest {
*/
protected abstract TruffleObject createEmptyTruffleObject() throws Exception;
protected String[] getKeys() {
return null;
/**
*
* @param obj
* @return array of keys or <code>null</code> if KEYS message not supported
*/
protected String[] getKeys(TruffleObject obj) {
throw new UnsupportedOperationException("override if HAS_KEYS returns true");
}
protected boolean isNull(@SuppressWarnings("unused") TruffleObject obj) {
return false;
}
protected boolean isExecutable(@SuppressWarnings("unused") TruffleObject obj) {
return false;
}
protected boolean isPointer(@SuppressWarnings("unused") TruffleObject obj) {
return true;
}
protected boolean isBoxed(@SuppressWarnings("unused") TruffleObject obj) {
return false;
}
protected boolean hasSize(@SuppressWarnings("unused") TruffleObject obj) {
return false;
}
protected boolean testToNative(@SuppressWarnings("unused") TruffleObject obj) {
return true;
}
protected int getSize(@SuppressWarnings("unused") TruffleObject obj) {
throw new UnsupportedOperationException("override if hasSize returns true");
throw new UnsupportedOperationException("override if HAS_SIZE returns true");
}
protected Object getUnboxed(@SuppressWarnings("unused") TruffleObject obj) {
throw new UnsupportedOperationException("override if isBoxed returns true");
throw new UnsupportedOperationException("override if IS_BOXED returns true");
}
@Test
......@@ -111,16 +106,44 @@ public abstract class AbstractMRTest {
}
@Test
public void testIsExecutable() throws Exception {
public void testExecutable() throws Exception {
for (TruffleObject obj : createTruffleObjects()) {
assertEquals(isExecutable(obj), ForeignAccess.sendIsExecutable(Message.IS_EXECUTABLE.createNode(), obj));
try {
// TODO if the need appears, also provide for args for execute
ForeignAccess.sendExecute(Message.createExecute(0).createNode(), obj);
assertEquals(obj.getClass().getSimpleName() + " " + obj + " IS_EXECUTABLE", true, ForeignAccess.sendIsExecutable(Message.IS_EXECUTABLE.createNode(), obj));
} catch (UnsupportedTypeException | ArityException e) {
throw e;
} catch (UnsupportedMessageException e) {
assertEquals(obj.getClass().getSimpleName() + " " + obj + " IS_EXECUTABLE", false, ForeignAccess.sendIsExecutable(Message.IS_EXECUTABLE.createNode(), obj));
}
}
}
@Test
public void testIsPointer() throws Exception {
public void testInstantiable() throws Exception {
for (TruffleObject obj : createTruffleObjects()) {
assertEquals(obj.getClass().getSimpleName(), isPointer(obj), ForeignAccess.sendIsPointer(Message.IS_POINTER.createNode(), obj));
try {
// TODO if the need appears, also provide for args for new
ForeignAccess.sendNew(Message.createNew(0).createNode(), obj);
assertEquals(obj.getClass().getSimpleName() + " " + obj + " IS_INSTANTIABLE", true, ForeignAccess.sendIsInstantiable(Message.IS_INSTANTIABLE.createNode(), obj));
} catch (UnsupportedTypeException | ArityException e) {
throw e;
} catch (UnsupportedMessageException e) {
assertEquals(obj.getClass().getSimpleName() + " " + obj + " IS_INSTANTIABLE", false, ForeignAccess.sendIsInstantiable(Message.IS_INSTANTIABLE.createNode(), obj));
}
}
}
@Test
public void testAsNativePointer() throws Exception {
for (TruffleObject obj : createTruffleObjects()) {
try {
assertNotNull(obj.getClass().getSimpleName(), ForeignAccess.sendToNative(Message.AS_POINTER.createNode(), obj));
assertEquals(obj.getClass().getSimpleName() + " " + obj + " IS_POINTER", true, ForeignAccess.sendIsPointer(Message.IS_POINTER.createNode(), obj));
} catch (UnsupportedMessageException e) {
assertEquals(obj.getClass().getSimpleName() + " " + obj + " IS_POINTER", false, ForeignAccess.sendIsPointer(Message.IS_POINTER.createNode(), obj));
}
}
}
......@@ -131,8 +154,12 @@ public abstract class AbstractMRTest {
continue;
}
try {
assertTrue(obj.getClass().getSimpleName(), ForeignAccess.sendToNative(Message.TO_NATIVE.createNode(), obj) == obj);
} catch (UnsupportedMessageException unsupportedMessageException) {
if (obj == RNull.instance) {
assertTrue(obj.getClass().getSimpleName(), ForeignAccess.sendToNative(Message.TO_NATIVE.createNode(), obj) == NativePointer.NULL_NATIVEPOINTER);
} else {
assertTrue(obj.getClass().getSimpleName(), ForeignAccess.sendToNative(Message.TO_NATIVE.createNode(), obj) == obj);
}
} catch (UnsupportedMessageException e) {
}
}
}
......@@ -140,38 +167,62 @@ public abstract class AbstractMRTest {
@Test
public void testSize() throws Exception {
for (TruffleObject obj : createTruffleObjects()) {
boolean hasSize = ForeignAccess.sendHasSize(Message.HAS_SIZE.createNode(), obj);
assertEquals("" + obj.getClass() + " " + obj, hasSize(obj), hasSize);
if (hasSize) {
assertEquals(getSize(obj), ForeignAccess.sendGetSize(Message.GET_SIZE.createNode(), obj));
} else {
assertInteropException(() -> ForeignAccess.sendGetSize(Message.GET_SIZE.createNode(), obj), UnsupportedMessageException.class);
}
testSize(obj);
}
TruffleObject empty = createEmptyTruffleObject();
if (empty != null) {
testSize(empty);
}
}
private void testSize(TruffleObject obj) {
try {
Object size = ForeignAccess.sendGetSize(Message.GET_SIZE.createNode(), obj);
assertEquals(getSize(obj), size);
assertEquals(obj.getClass().getSimpleName() + " " + obj + " HAS_SIZE", true, ForeignAccess.sendHasSize(Message.HAS_SIZE.createNode(), obj));
} catch (UnsupportedMessageException e) {
assertEquals(obj.getClass().getSimpleName() + " " + obj + " HAS_SIZE", false, ForeignAccess.sendHasSize(Message.HAS_SIZE.createNode(), obj));
}
}
@Test
public void testBoxed() throws Exception {
for (TruffleObject obj : createTruffleObjects()) {
boolean isBoxed = ForeignAccess.sendIsBoxed(Message.IS_BOXED.createNode(), obj);
assertEquals(isBoxed(obj), isBoxed);
if (isBoxed) {
assertEquals(getUnboxed(obj), ForeignAccess.sendUnbox(Message.UNBOX.createNode(), obj));
} else {
assertInteropException(() -> ForeignAccess.sendUnbox(Message.UNBOX.createNode(), obj), UnsupportedMessageException.class);
}
testUnboxed(obj);
}
TruffleObject empty = createEmptyTruffleObject();
if (empty != null) {
testUnboxed(empty);
}
}
private void testUnboxed(TruffleObject obj) {
try {
Object unboxed = ForeignAccess.sendUnbox(Message.UNBOX.createNode(), obj);
assertEquals(getUnboxed(obj), unboxed);
assertEquals(obj.getClass().getSimpleName() + " " + obj + " IS_BOXED", true, ForeignAccess.sendIsBoxed(Message.IS_BOXED.createNode(), obj));
} catch (UnsupportedMessageException e) {
assertEquals(obj.getClass().getSimpleName() + " " + obj + " IS_BOXED", false, ForeignAccess.sendIsBoxed(Message.IS_BOXED.createNode(), obj));
}
}
@Test
public void testKeys() throws Exception {
String[] keys = getKeys();
if (keys == null) {
return;
}
for (TruffleObject obj : createTruffleObjects()) {
testKeys(obj);
}
TruffleObject empty = createEmptyTruffleObject();
if (empty != null) {
testKeys(empty);
}
}
private void testKeys(TruffleObject obj) throws UnknownIdentifierException, UnsupportedMessageException {
try {
TruffleObject keysObj = ForeignAccess.sendKeys(Message.KEYS.createNode(), obj);
int size = (int) ForeignAccess.sendGetSize(Message.GET_SIZE.createNode(), keysObj);
String[] keys = getKeys(obj);
assertEquals(keys.length, size);
Set<Object> set = new HashSet<>();
......@@ -181,31 +232,9 @@ public abstract class AbstractMRTest {
for (String key : keys) {
assertTrue(set.contains(key));
}
}
}
@Test
public void testEmpty() throws Exception {
TruffleObject obj = createEmptyTruffleObject();
if (obj != null) {
if (hasSize(obj)) {
int size = (int) ForeignAccess.sendGetSize(Message.GET_SIZE.createNode(), obj);
assertEquals(0, size);
}
TruffleObject keys = null;
try {
keys = ForeignAccess.sendKeys(Message.KEYS.createNode(), obj);
} catch (UnsupportedMessageException ex) {
}
if (keys != null) {
boolean keysHasSize = ForeignAccess.sendHasSize(Message.HAS_SIZE.createNode(), keys);
if (keysHasSize) {
int keysSize = (int) ForeignAccess.sendGetSize(Message.GET_SIZE.createNode(), keys);
assertEquals(0, keysSize);
}
}
assertEquals(obj.getClass().getSimpleName() + " " + obj + " HAS_KEYS", true, ForeignAccess.sendHasKeys(Message.HAS_KEYS.createNode(), obj));
} catch (UnsupportedMessageException e) {
assertEquals(obj.getClass().getSimpleName() + " " + obj + " HAS_KEYS", false, ForeignAccess.sendHasKeys(Message.HAS_KEYS.createNode(), obj));
}
}
......
......@@ -28,12 +28,14 @@ import com.oracle.truffle.api.vm.PolyglotEngine;
import com.oracle.truffle.r.runtime.RType;
import com.oracle.truffle.r.runtime.data.RFunction;
import com.oracle.truffle.r.runtime.env.frame.ActiveBinding;
import org.junit.Test;
public class ActiveBindingMRTest extends AbstractMRTest {
@Test
@Override
protected boolean isBoxed(TruffleObject obj) {
return true;
public void testIsNull() throws Exception {
super.testIsNull(); // force inherited tests from AbstractMRTest
}
@Override
......
......@@ -159,8 +159,11 @@ public class ListMRTest extends AbstractMRTest {
}
@Override
protected String[] getKeys() {
return new String[]{"i", "d", "b", "fn", "n", ""};
protected String[] getKeys(TruffleObject obj) {
if (((RAbstractContainer) obj).getLength() > 0) {
return new String[]{"i", "d", "b", "fn", "n", ""};
}
return new String[]{};
}
@Override
......@@ -174,11 +177,6 @@ public class ListMRTest extends AbstractMRTest {
return create("list", "");
}
@Override
protected boolean hasSize(TruffleObject arg0) {
return true;
}
@Override
protected int getSize(TruffleObject obj) {
return obj instanceof RList ? ((RList) obj).getLength() : ((RPairList) obj).getLength();
......
......@@ -140,8 +140,12 @@ public class RArgsValuesAndNamesMRTest extends AbstractMRTest {
}
@Override
protected String[] getKeys() {
return names;
protected String[] getKeys(TruffleObject obj) {
if (obj == RArgsValuesAndNames.EMPTY) {
return new String[]{};
} else {
return names;
}
}
@Override
......@@ -149,11 +153,6 @@ public class RArgsValuesAndNamesMRTest extends AbstractMRTest {
return RArgsValuesAndNames.EMPTY;
}
@Override
protected boolean hasSize(TruffleObject obj) {
return true;
}
@Override
protected int getSize(TruffleObject obj) {
return ((RArgsValuesAndNames) obj).getLength();
......
/*
* Copyright (c) 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.truffle.r.test.engine.interop;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.r.runtime.data.RComplex;
import org.junit.Test;
public class RComplexMRTest extends AbstractMRTest {
@Override
protected TruffleObject[] createTruffleObjects() throws Exception {
return new TruffleObject[]{RComplex.valueOf(1, 1)};
}
@Test
@Override
public void testIsNull() throws Exception {
super.testIsNull(); // force inherited tests from AbstractMRTest
}
@Override
protected TruffleObject createEmptyTruffleObject() throws Exception {
return null;
}
}
......@@ -24,17 +24,19 @@ package com.oracle.truffle.r.test.engine.interop;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.r.runtime.data.RDouble;
import org.junit.Test;
public class RDoubleMRTest extends AbstractMRTest {
@Test
@Override
protected TruffleObject[] createTruffleObjects() throws Exception {
return new TruffleObject[]{RDouble.valueOf(1.1)};
public void testIsNull() throws Exception {
super.testIsNull(); // force inherited tests from AbstractMRTest
}
@Override
protected boolean isBoxed(TruffleObject obj) {
return true;
protected TruffleObject[] createTruffleObjects() throws Exception {
return new TruffleObject[]{RDouble.valueOf(1.1)};
}
@Override
......
......@@ -24,9 +24,16 @@ package com.oracle.truffle.r.test.engine.interop;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.r.runtime.data.REmpty;
import org.junit.Test;
public class REmptyMRTest extends AbstractMRTest {
@Test
@Override
public void testIsNull() throws Exception {
super.testIsNull(); // force inherited tests from AbstractMRTest
}
@Override
protected TruffleObject[] createTruffleObjects() throws Exception {
return new TruffleObject[]{REmpty.instance};
......
......@@ -36,6 +36,7 @@ import com.oracle.truffle.api.interop.UnknownIdentifierException;
import com.oracle.truffle.api.interop.UnsupportedMessageException;
import com.oracle.truffle.api.interop.java.JavaInterop;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.r.runtime.data.RDataFactory;
import com.oracle.truffle.r.runtime.env.REnvironment;
public class REnvironmentMRTest extends AbstractMRTest {
......@@ -138,13 +139,16 @@ public class REnvironmentMRTest extends AbstractMRTest {
}
@Override
protected String[] getKeys() {
return new String[]{"s", "i", "d", "b", "fn", "n", "l"};
protected String[] getKeys(TruffleObject obj) {
if (((REnvironment) obj).getName().equals("R_EmptyEnv")) {
return new String[]{};
} else {
return new String[]{"s", "i", "d", "b", "fn", "n", "l"};
}
}
@Override
protected TruffleObject createEmptyTruffleObject() throws Exception {
Source src = Source.newBuilder("new.env()").mimeType("text/x-r").name("test.R").build();
return engine.eval(src).as(REnvironment.class);
return REnvironment.emptyEnv();
}
}
......@@ -78,11 +78,6 @@ public class RFunctionMRTest extends AbstractMRTest {
return result.as(RFunction.class);
}
@Override
protected boolean isExecutable(TruffleObject obj) {
return true;
}
@Override
protected TruffleObject createEmptyTruffleObject() throws Exception {
return null;
......
......@@ -24,17 +24,19 @@ package com.oracle.truffle.r.test.engine.interop;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.r.runtime.data.RInteger;
import org.junit.Test;
public class RIntegerMRTest extends AbstractMRTest {
@Test
@Override
protected TruffleObject[] createTruffleObjects() throws Exception {
return new TruffleObject[]{RInteger.valueOf(123)};
public void testIsNull() throws Exception {
super.testIsNull(); // force inherited tests from AbstractMRTest
}
@Override
protected boolean isBoxed(TruffleObject obj) {
return true;
protected TruffleObject[] createTruffleObjects() throws Exception {
return new TruffleObject[]{RInteger.valueOf(123)};
}
@Override
......
......@@ -62,16 +62,6 @@ public class RInteropScalarMRTest extends AbstractMRTest {
RInteropScalar.RInteropShort.valueOf(Short.MAX_VALUE)};
}
@Override
protected boolean isBoxed(TruffleObject arg0) {
return true;
}
@Override
protected boolean isPointer(TruffleObject obj) {
return false;
}
@Override
protected Object getUnboxed(TruffleObject obj) {
RInteropScalar is = (RInteropScalar) obj;
......
......@@ -105,11 +105,6 @@ public class RLanguageMRTest extends AbstractMRTest {
return null;
}
@Override
protected boolean hasSize(TruffleObject obj) {
return true;
}
@Override
protected int getSize(TruffleObject obj) {
return ((RLanguage) obj).getLength();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment