From 2d5f8d3547b46b920353b34a84a201b869fd01d0 Mon Sep 17 00:00:00 2001 From: Mick Jordan <mick.jordan@oracle.com> Date: Tue, 18 Apr 2017 16:24:10 -0700 Subject: [PATCH] make RConnection a TruffleObject for C_ParseRd in NFI/LLVM --- .../r/engine/interop/RConnectionMR.java | 42 +++++++++++++++++++ .../interop/RForeignAccessFactoryImpl.java | 3 ++ .../truffle/r/runtime/conn/RConnection.java | 3 +- 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/RConnectionMR.java diff --git a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/RConnectionMR.java b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/RConnectionMR.java new file mode 100644 index 0000000000..45df6f9f19 --- /dev/null +++ b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/RConnectionMR.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2017, 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.TruffleObject; +import com.oracle.truffle.api.nodes.Node; +import com.oracle.truffle.r.engine.TruffleRLanguage; +import com.oracle.truffle.r.runtime.conn.RConnection; + +@MessageResolution(receiverType = RConnection.class, language = TruffleRLanguage.class) +public class RConnectionMR { + @CanResolve + public abstract static class RConnection extends Node { + + protected static boolean test(TruffleObject receiver) { + return receiver instanceof RConnection; + } + } + +} diff --git a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/RForeignAccessFactoryImpl.java b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/RForeignAccessFactoryImpl.java index 0c91b000ba..428399f41f 100644 --- a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/RForeignAccessFactoryImpl.java +++ b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/interop/RForeignAccessFactoryImpl.java @@ -28,6 +28,7 @@ import com.oracle.truffle.api.interop.ForeignAccess; import com.oracle.truffle.api.interop.MessageResolution; import com.oracle.truffle.r.engine.TruffleRLanguage; import com.oracle.truffle.r.runtime.RInternalError; +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.RDouble; @@ -92,6 +93,8 @@ public final class RForeignAccessFactoryImpl implements RForeignAccessFactory { return RDoubleMRForeign.ACCESS; } else if (obj instanceof CharSXPWrapper) { return CharSXPWrapperMRForeign.ACCESS; + } else if (obj instanceof RConnection) { + return RConnectionMRForeign.ACCESS; } else { if (obj instanceof RAbstractVector) { return ForeignAccess.create(RAbstractVector.class, new RAbstractVectorAccessFactory()); diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/RConnection.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/RConnection.java index 1314faf885..df7d420c8b 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/RConnection.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/RConnection.java @@ -31,12 +31,13 @@ import java.nio.channels.ByteChannel; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.r.runtime.conn.ConnectionSupport.BaseRConnection; import com.oracle.truffle.r.runtime.context.RContext; +import com.oracle.truffle.r.runtime.data.RTruffleObject; import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector; /** * Denotes an R {@code connection} instance used in the {@code base} I/O library. */ -public interface RConnection extends AutoCloseable { +public interface RConnection extends AutoCloseable, RTruffleObject { static BaseRConnection fromIndex(int con) { return RContext.getInstance().stateRConnection.getConnection(con, true); -- GitLab