diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/graphics/CPar.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/graphics/CPar.java index 4f520f1f2ab9159d8f48ae00fd8f13fd00f48263..f076d1a5e64fc162513b8369fe2d4d50108ec9d0 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/graphics/CPar.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/graphics/CPar.java @@ -31,6 +31,7 @@ import com.oracle.truffle.r.library.fastrGrid.device.DrawingContext; import com.oracle.truffle.r.library.fastrGrid.device.GridDevice; import com.oracle.truffle.r.library.fastrGrid.grDevices.OpenDefaultDevice; import com.oracle.truffle.r.nodes.builtin.RExternalBuiltinNode; +import com.oracle.truffle.r.runtime.FastROptions; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RError.Message; import com.oracle.truffle.r.runtime.RRuntime; @@ -114,7 +115,11 @@ public final class CPar extends RExternalBuiltinNode { // TODO: return RDataFactory.createLogicalVectorFromScalar(false); default: - throw RError.nyi(RError.NO_CALLER, "C_Par parameter '" + name + "'"); + if (!FastROptions.IgnoreGraphicsCalls.getBooleanValue()) { + throw RError.nyi(RError.NO_CALLER, "C_Par parameter '" + name + "'"); + } else { + return RNull.instance; + } } } diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/graphics/R/fastrGraphics.R b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/graphics/R/fastrGraphics.R index 2ffbef80c874914e8e0457462f1055a3f1d6ed33..f1d333aa7dfd2e9030bf4bc2c8136ee0b2e0992e 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/graphics/R/fastrGraphics.R +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/graphics/R/fastrGraphics.R @@ -25,24 +25,29 @@ # prints a warning message instructing the user to use grid/lattice/ggplot2 instead eval(expression({ - graphicsWarning <- function(name) { - # lookup original function and fetch signature - fun <- tryCatch(get(name, environment()), error=function(x) NULL) - if(!is.null(fun)) { - sig <- formals(fun) - } else { - sig <- NULL - } - - replacementFun <- function(...) { - warning(paste0(name, " not supported.", " Note: FastR does not support graphics package and most of its functions. Please use grid package or grid based packages like lattice instead.")) - NULL - } + if (.fastr.option('IgnoreGraphicsCalls')) { + # we force the arguments to be evaluated, but otherwise do nothing + graphicsWarning <- function(name) function(...) { list(...); invisible(NULL); } + } else { + graphicsWarning <- function(name) { + # lookup original function and fetch signature + fun <- tryCatch(get(name, environment()), error=function(x) NULL) + if(!is.null(fun)) { + sig <- formals(fun) + } else { + sig <- NULL + } + + replacementFun <- function(...) { + warning(paste0(name, " not supported.", " Note: FastR does not support graphics package and most of its functions. Please use grid package or grid based packages like lattice instead.")) + NULL + } - if(!is.null(sig)) { - formals(replacementFun) <- sig + if(!is.null(sig)) { + formals(replacementFun) <- sig + } + return(replacementFun) } - return(replacementFun) } plot.default <- function (x, y = NULL, type = "p", xlim = NULL, ylim = NULL, 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 de74bbaa12896b6f15044afdb7da4d79709bf5af..438bccd17c05f57b5621b8b478ef68ff75fe6749 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 @@ -109,6 +109,7 @@ import com.oracle.truffle.r.nodes.builtin.fastr.FastRInterop; import com.oracle.truffle.r.nodes.builtin.fastr.FastRInteropFactory; import com.oracle.truffle.r.nodes.builtin.fastr.FastRLibPaths; import com.oracle.truffle.r.nodes.builtin.fastr.FastRLibPathsNodeGen; +import com.oracle.truffle.r.nodes.builtin.fastr.FastROptionBuiltin; import com.oracle.truffle.r.nodes.builtin.fastr.FastRPkgSource; import com.oracle.truffle.r.nodes.builtin.fastr.FastRPkgSourceNodeGen; import com.oracle.truffle.r.nodes.builtin.fastr.FastRRefCountInfo; @@ -435,6 +436,7 @@ public class BasePackage extends RBuiltinPackage { add(FastRSetBreakpoint.class, FastRSetBreakpointNodeGen::create); add(FastRHelp.class, FastRHelpNodeGen::create); add(FastRIdentity.class, FastRIdentityNodeGen::create); + add(FastROptionBuiltin.class, FastROptionBuiltin::create); add(FastRTry.class, FastRTryNodeGen::create); add(FastRInspect.class, FastRInspectNodeGen::create); add(FastRInterop.Eval.class, FastRInteropFactory.EvalNodeGen::create); diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastROptionBuiltin.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastROptionBuiltin.java new file mode 100644 index 0000000000000000000000000000000000000000..a5b8a799baf880c2f5445a08ed02b72c11af395b --- /dev/null +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastROptionBuiltin.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2015, 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.fastr; + +import static com.oracle.truffle.r.runtime.RVisibility.OFF; +import static com.oracle.truffle.r.runtime.RVisibility.ON; +import static com.oracle.truffle.r.runtime.builtins.RBehavior.COMPLEX; +import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE; + +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.FastROptions; +import com.oracle.truffle.r.runtime.RRuntime; +import com.oracle.truffle.r.runtime.builtins.RBuiltin; +import com.oracle.truffle.r.runtime.data.RMissing; +import com.oracle.truffle.r.runtime.data.RNull; +import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector; + +/** + * Allows to read {@link FastROptions} from (e.g. internal) R code. + */ +@RBuiltin(name = ".fastr.option", visibility = ON, kind = PRIMITIVE, parameterNames = {"name"}, behavior = COMPLEX) +public abstract class FastROptionBuiltin extends RBuiltinNode.Arg1 { + + static { + Casts casts = new Casts(FastROptionBuiltin.class); + casts.arg("name").asStringVector().findFirst(); + } + + @Specialization + @TruffleBoundary + protected Object getOption(String name) { + FastROptions opt = null; + try { + opt = Enum.valueOf(FastROptions.class, name); + } catch (IllegalArgumentException e) { + return RNull.instance; + } + return opt.isBoolean() ? RRuntime.asLogical(opt.getBooleanValue()) : opt.getStringValue(); + } + + public static FastROptionBuiltin create() { + return FastROptionBuiltinNodeGen.create(); + } +} diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/FastROptions.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/FastROptions.java index 5a9c503079500a97603e9ffdb595104feaa5314e..e4360fc26b053139d0a36d9b630d819376b5d0e1 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/FastROptions.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/FastROptions.java @@ -74,6 +74,7 @@ public enum FastROptions { // Miscellaneous + IgnoreGraphicsCalls("Silently ignore unimplemented functions from graphics package", false), StartupTiming("Records and prints various timestamps during initialization", false); private final String help; @@ -92,6 +93,10 @@ public enum FastROptions { this.value = defaultValue; } + public boolean isBoolean() { + return isBoolean; + } + public boolean getBooleanValue() { assert isBoolean; Object v = value;