Skip to content
Snippets Groups Projects
Commit 8f1704df authored by Tomas Stupka's avatar Tomas Stupka
Browse files

created RStringMR and RLogicalMR

parent 796f4cad
Branches
No related tags found
No related merge requests found
......@@ -465,13 +465,7 @@ public final class RAbstractVectorAccessFactory implements StandardFactory {
@Override
public Object execute(VirtualFrame frame) {
final Object receiver = ForeignAccess.getReceiver(frame);
// TODO: RLogical has no ForeignAccess, issue: GR-9536, use RAbstractVectorAccessFactory
// for compatibility.
final boolean logical = receiver.getClass() == RLogical.class;
// TODO: RString has no ForeignAccess, issue: GR-9536, use RAbstractVectorAccessFactory
// for compatibility.
final boolean string = receiver.getClass() == RString.class;
return receiver instanceof RAbstractAtomicVector && (!(receiver instanceof RScalar) || logical || string);
return receiver instanceof RAbstractAtomicVector && !(receiver instanceof RScalar);
}
}
}
......@@ -40,11 +40,13 @@ import com.oracle.truffle.r.runtime.data.RInteger;
import com.oracle.truffle.r.runtime.data.RInteropScalar;
import com.oracle.truffle.r.runtime.data.RPairList;
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.RPromise;
import com.oracle.truffle.r.runtime.data.RRaw;
import com.oracle.truffle.r.runtime.data.RS4Object;
import com.oracle.truffle.r.runtime.data.RString;
import com.oracle.truffle.r.runtime.data.RSymbol;
import com.oracle.truffle.r.runtime.data.RTruffleObject;
import com.oracle.truffle.r.runtime.data.RUnboundValue;
......@@ -88,6 +90,8 @@ public final class RForeignAccessFactoryImpl implements RForeignAccessFactory {
return RExternalPtrMRForeign.ACCESS;
} else if (obj instanceof RUnboundValue) {
return RUnboundValueMRForeign.ACCESS;
} else if (obj instanceof RLogical) {
return RLogicalMRForeign.ACCESS;
} else if (obj instanceof RInteger) {
return RIntegerMRForeign.ACCESS;
} else if (obj instanceof RDouble) {
......@@ -96,6 +100,8 @@ public final class RForeignAccessFactoryImpl implements RForeignAccessFactory {
return RComplexMRForeign.ACCESS;
} else if (obj instanceof RRaw) {
return RRawMRForeign.ACCESS;
} else if (obj instanceof RString) {
return RStringMRForeign.ACCESS;
} else if (obj instanceof RConnection) {
return RConnectionMRForeign.ACCESS;
} else if (obj instanceof RS4Object) {
......
/*
* Copyright (c) 2016, 2018, 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 3 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 3 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
* 3 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.RLogical;
@MessageResolution(receiverType = RLogical.class)
public class RLogicalMR {
@Resolve(message = "IS_BOXED")
public abstract static class RLogicalIsBoxedNode extends Node {
protected Object access(@SuppressWarnings("unused") RLogical receiver) {
return true;
}
}
@Resolve(message = "KEY_INFO")
public abstract static class RLogicalKeyInfoNode extends Node {
protected Object access(@SuppressWarnings("unused") RLogical receiver, @SuppressWarnings("unused") Object identifier) {
return 0;
}
}
@Resolve(message = "UNBOX")
public abstract static class RLogicalUnboxNode extends Node {
protected byte access(RLogical receiver) {
return receiver.getValue();
}
}
@CanResolve
public abstract static class RLogicalCheck extends Node {
protected static boolean test(TruffleObject receiver) {
return receiver instanceof RLogical;
}
}
}
/*
* Copyright (c) 2016, 2018, 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 3 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 3 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
* 3 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.RString;
@MessageResolution(receiverType = RString.class)
public class RStringMR {
@Resolve(message = "IS_BOXED")
public abstract static class RStringIsBoxedNode extends Node {
protected Object access(@SuppressWarnings("unused") RString receiver) {
return true;
}
}
@Resolve(message = "KEY_INFO")
public abstract static class RStringKeyInfoNode extends Node {
protected Object access(@SuppressWarnings("unused") RString receiver, @SuppressWarnings("unused") Object identifier) {
return 0;
}
}
@Resolve(message = "UNBOX")
public abstract static class RStringUnboxNode extends Node {
protected String access(RString receiver) {
return receiver.getValue();
}
}
@CanResolve
public abstract static class RStringCheck extends Node {
protected static boolean test(TruffleObject receiver) {
return receiver instanceof RString;
}
}
}
/*
* Copyright (c) 2017, 2018, 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 3 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 3 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
* 3 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.RLogical;
import org.junit.Test;
public class RLogicalMRTest 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[]{RLogical.valueOf(true), RLogical.valueOf(false)};
}
@Override
protected Object getUnboxed(TruffleObject obj) {
return ((RLogical) obj).getValue();
}
@Override
protected TruffleObject createEmptyTruffleObject() throws Exception {
return null;
}
}
/*
* Copyright (c) 2017, 2018, 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 3 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 3 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
* 3 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.RString;
import org.junit.Test;
public class RStringMRTest 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[]{RString.valueOf("abc")};
}
@Override
protected Object getUnboxed(TruffleObject obj) {
return ((RString) obj).getValue();
}
@Override
protected TruffleObject createEmptyTruffleObject() throws Exception {
return null;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment