From 806a25e81f6d2f9904674d162f800dcabacac5a6 Mon Sep 17 00:00:00 2001 From: Florian Angerer <florian.angerer@oracle.com> Date: Mon, 29 Jan 2018 18:19:28 +0100 Subject: [PATCH] Introduce class VersionFunctions. --- .../r/nodes/builtin/base/BasePackage.java | 5 +- .../nodes/builtin/base/DynLoadFunctions.java | 48 ---------- .../r/nodes/builtin/base/RVersion.java | 43 --------- .../nodes/builtin/base/VersionFunctions.java | 96 +++++++++++++++++++ 4 files changed, 99 insertions(+), 93 deletions(-) delete mode 100644 com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/RVersion.java create mode 100644 com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/VersionFunctions.java diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BasePackage.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BasePackage.java index a3930beaac..a2bd261a01 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BasePackage.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BasePackage.java @@ -40,6 +40,7 @@ import com.oracle.truffle.r.nodes.builtin.base.ConnectionFunctions.SockSelect; import com.oracle.truffle.r.nodes.builtin.base.ConnectionFunctionsFactory.SockSelectNodeGen; import com.oracle.truffle.r.nodes.builtin.base.DebugFunctions.FastRSetBreakpoint; import com.oracle.truffle.r.nodes.builtin.base.DebugFunctionsFactory.FastRSetBreakpointNodeGen; +import com.oracle.truffle.r.nodes.builtin.base.VersionFunctions.RVersion; import com.oracle.truffle.r.nodes.builtin.base.fastpaths.AssignFastPathNodeGen; import com.oracle.truffle.r.nodes.builtin.base.fastpaths.ExistsFastPathNodeGen; import com.oracle.truffle.r.nodes.builtin.base.fastpaths.GetFastPathNodeGen; @@ -395,7 +396,7 @@ public class BasePackage extends RBuiltinPackage { add(DynLoadFunctions.GetLoadedDLLs.class, DynLoadFunctionsFactory.GetLoadedDLLsNodeGen::create); add(DynLoadFunctions.GetSymbolInfo.class, DynLoadFunctionsFactory.GetSymbolInfoNodeGen::create); add(DynLoadFunctions.IsLoaded.class, DynLoadFunctionsFactory.IsLoadedNodeGen::create); - add(DynLoadFunctions.ExtSoftVersion.class, DynLoadFunctionsFactory.ExtSoftVersionNodeGen::create); + add(VersionFunctions.ExtSoftVersion.class, VersionFunctionsFactory.ExtSoftVersionNodeGen::create); add(EncodeString.class, EncodeStringNodeGen::create); add(EncodingFunctions.Encoding.class, EncodingFunctionsFactory.EncodingNodeGen::create); add(EncodingFunctions.SetEncoding.class, EncodingFunctionsFactory.SetEncodingNodeGen::create); @@ -669,7 +670,7 @@ public class BasePackage extends RBuiltinPackage { add(RNGFunctions.RNGkind.class, RNGFunctionsFactory.RNGkindNodeGen::create); add(RNGFunctions.SetSeed.class, RNGFunctionsFactory.SetSeedNodeGen::create); add(RNGFunctions.FastRSetSeed.class, RNGFunctionsFactory.FastRSetSeedNodeGen::create); - add(RVersion.class, RVersionNodeGen::create); + add(RVersion.class, VersionFunctionsFactory.RVersionNodeGen::create); add(RawFunctions.CharToRaw.class, RawFunctionsFactory.CharToRawNodeGen::create); add(RawFunctions.RawToChar.class, RawFunctionsFactory.RawToCharNodeGen::create); add(RawFunctions.RawShift.class, RawFunctionsFactory.RawShiftNodeGen::create); diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/DynLoadFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/DynLoadFunctions.java index 12eb630eff..05c9f4f3e4 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/DynLoadFunctions.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/DynLoadFunctions.java @@ -33,18 +33,13 @@ import static com.oracle.truffle.r.runtime.builtins.RBehavior.COMPLEX; import static com.oracle.truffle.r.runtime.builtins.RBehavior.READS_STATE; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.INTERNAL; -import java.io.IOException; import java.util.ArrayList; -import java.util.List; -import java.util.Map; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.r.ffi.impl.common.LibPaths; import com.oracle.truffle.r.nodes.attributes.SpecialAttributesFunctions.SetClassAttributeNode; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; -import com.oracle.truffle.r.runtime.RCompression; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.builtins.RBuiltin; @@ -52,10 +47,7 @@ import com.oracle.truffle.r.runtime.data.RDataFactory; import com.oracle.truffle.r.runtime.data.RExternalPtr; import com.oracle.truffle.r.runtime.data.RList; import com.oracle.truffle.r.runtime.data.RNull; -import com.oracle.truffle.r.runtime.data.RStringVector; import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector; -import com.oracle.truffle.r.runtime.ffi.BaseRFFI; -import com.oracle.truffle.r.runtime.ffi.BaseRFFI.ESoftVersionNode; import com.oracle.truffle.r.runtime.ffi.DLL; import com.oracle.truffle.r.runtime.ffi.DLL.DLLException; import com.oracle.truffle.r.runtime.ffi.DLL.DLLInfo; @@ -225,44 +217,4 @@ public class DynLoadFunctions { return DLL.isDLLInfo(externalPtr); } } - - @RBuiltin(name = "eSoftVersion", kind = INTERNAL, parameterNames = {}, behavior = READS_STATE) - public abstract static class ExtSoftVersion extends RBuiltinNode.Arg0 { - @Child private ESoftVersionNode eSoftVersionNode = BaseRFFI.ESoftVersionNode.create(); - - static { - Casts.noCasts(ExtSoftVersion.class); - } - - @Specialization - @TruffleBoundary - protected RStringVector getSymbolInfo() { - - Map<String, String> eSoftVersion = eSoftVersionNode.eSoftVersion(); - - List<String> libNames = new ArrayList<>(); - List<String> versions = new ArrayList<>(); - - for (Map.Entry<String, String> versionEntry : eSoftVersion.entrySet()) { - libNames.add(versionEntry.getKey()); - versions.add(versionEntry.getValue()); - } - - // BZIP2 - try { - versions.add(RCompression.getBz2Version()); - libNames.add("bzip2"); - } catch (IOException e) { - // ignore - } - - // BLAS - libNames.add("BLAS"); - versions.add(LibPaths.getBuiltinLibPath("Rblas")); - - RStringVector names = RDataFactory.createStringVector(libNames.toArray(new String[0]), true); - return RDataFactory.createStringVector(versions.toArray(new String[0]), true, names); - - } - } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/RVersion.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/RVersion.java deleted file mode 100644 index 5deeb4662e..0000000000 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/RVersion.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2014, 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.nodes.builtin.base; - -import static com.oracle.truffle.r.runtime.builtins.RBehavior.READS_STATE; -import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.INTERNAL; - -import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; -import com.oracle.truffle.r.runtime.RVersionInfo; -import com.oracle.truffle.r.runtime.builtins.RBuiltin; -import com.oracle.truffle.r.runtime.data.RDataFactory; - -@RBuiltin(name = "Version", kind = INTERNAL, parameterNames = {}, behavior = READS_STATE) -public abstract class RVersion extends RBuiltinNode.Arg0 { - - @Specialization - @TruffleBoundary - protected Object doRVersion() { - return RDataFactory.createList(RVersionInfo.listValues(), RDataFactory.createStringVector(RVersionInfo.listNames(), RDataFactory.COMPLETE_VECTOR)); - } -} diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/VersionFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/VersionFunctions.java new file mode 100644 index 0000000000..a012fdfa93 --- /dev/null +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/VersionFunctions.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) 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 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.nodes.builtin.base; + +import static com.oracle.truffle.r.runtime.builtins.RBehavior.READS_STATE; +import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.INTERNAL; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; +import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.r.ffi.impl.common.LibPaths; +import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; +import com.oracle.truffle.r.runtime.RCompression; +import com.oracle.truffle.r.runtime.RVersionInfo; +import com.oracle.truffle.r.runtime.builtins.RBuiltin; +import com.oracle.truffle.r.runtime.data.RDataFactory; +import com.oracle.truffle.r.runtime.data.RStringVector; +import com.oracle.truffle.r.runtime.ffi.BaseRFFI; +import com.oracle.truffle.r.runtime.ffi.BaseRFFI.ESoftVersionNode; + +public abstract class VersionFunctions { + + @RBuiltin(name = "Version", kind = INTERNAL, parameterNames = {}, behavior = READS_STATE) + public abstract static class RVersion extends RBuiltinNode.Arg0 { + + @Specialization + @TruffleBoundary + protected Object doRVersion() { + return RDataFactory.createList(RVersionInfo.listValues(), RDataFactory.createStringVector(RVersionInfo.listNames(), RDataFactory.COMPLETE_VECTOR)); + } + } + + @RBuiltin(name = "eSoftVersion", kind = INTERNAL, parameterNames = {}, behavior = READS_STATE) + public abstract static class ExtSoftVersion extends RBuiltinNode.Arg0 { + @Child private ESoftVersionNode eSoftVersionNode = BaseRFFI.ESoftVersionNode.create(); + + static { + Casts.noCasts(ExtSoftVersion.class); + } + + @Specialization + @TruffleBoundary + protected RStringVector getSymbolInfo() { + + Map<String, String> eSoftVersion = eSoftVersionNode.eSoftVersion(); + + List<String> libNames = new ArrayList<>(); + List<String> versions = new ArrayList<>(); + + for (Map.Entry<String, String> versionEntry : eSoftVersion.entrySet()) { + libNames.add(versionEntry.getKey()); + versions.add(versionEntry.getValue()); + } + + // BZIP2 + try { + versions.add(RCompression.getBz2Version()); + libNames.add("bzip2"); + } catch (IOException e) { + // ignore + } + + // BLAS + libNames.add("BLAS"); + versions.add(LibPaths.getBuiltinLibPath("Rblas")); + + RStringVector names = RDataFactory.createStringVector(libNames.toArray(new String[0]), true); + return RDataFactory.createStringVector(versions.toArray(new String[0]), true, names); + + } + } +} -- GitLab