From 3d64d14231c571c77349785c84bdba13a1863855 Mon Sep 17 00:00:00 2001 From: Mick Jordan <mick.jordan@oracle.com> Date: Fri, 16 Jan 2015 16:28:18 -0800 Subject: [PATCH] Inital groundwork for aligning startup with GnuR - create AutoLoad env in system profile - check for invoking .OptRequireMethods/.First/.First.sys/.Last - remove handler-based setting of R options and align initial settings with GnuR - create dummy .so files for utils and methods - add -R:Rdebug option to allow debugging system profile functions --- .hgignore | 2 +- .../com/oracle/truffle/r/engine/REngine.java | 52 ++++++-- com.oracle.truffle.r.native/library/Makefile | 22 +++- com.oracle.truffle.r.native/library/lib.mk | 65 +++++++++ .../library/methods/Makefile | 24 ++++ .../library/methods/src/methods.c | 1 + .../library/tools/Makefile | 45 +------ .../library/utils/Makefile | 24 ++++ .../library/utils/src/utils.c | 1 + .../r/nodes/builtin/base/BaseOptions.java | 124 ------------------ .../r/nodes/builtin/base/BaseVariables.java | 13 +- .../nodes/builtin/base/PrettyPrinterNode.java | 2 +- .../truffle/r/nodes/builtin/base/Quit.java | 6 +- .../r/nodes/instrument/RInstrument.java | 26 +++- .../truffle/r/options/FastROptions.java | 2 + .../com/oracle/truffle/r/runtime/R/Rprofile.R | 61 +++++---- .../oracle/truffle/r/runtime/RArguments.java | 9 +- .../oracle/truffle/r/runtime/RContext.java | 6 + .../oracle/truffle/r/runtime/ROptions.java | 69 +++++----- .../truffle/r/runtime/env/REnvironment.java | 38 +++--- mx.fastr/copyrights/overrides | 3 + 21 files changed, 313 insertions(+), 282 deletions(-) create mode 100644 com.oracle.truffle.r.native/library/lib.mk create mode 100644 com.oracle.truffle.r.native/library/methods/Makefile create mode 100644 com.oracle.truffle.r.native/library/methods/src/methods.c create mode 100644 com.oracle.truffle.r.native/library/utils/Makefile create mode 100644 com.oracle.truffle.r.native/library/utils/src/utils.c delete mode 100644 com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BaseOptions.java diff --git a/.hgignore b/.hgignore index f97ba0c92f..4063df2c04 100644 --- a/.hgignore +++ b/.hgignore @@ -90,4 +90,4 @@ R.tokens findbugs.html com.oracle.truffle.r.native/builtinlibs/lib/*/librfficall.* com.oracle.truffle.r.native/builtinlibs/lib/*/libR.dylib -com.oracle.truffle.r.native/library/tools/lib/*/*.* +com.oracle.truffle.r.native/library/*/lib/*/*.* diff --git a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/REngine.java b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/REngine.java index 77562e257c..1931286aaf 100644 --- a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/REngine.java +++ b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/REngine.java @@ -106,6 +106,7 @@ public final class REngine implements RContext.Engine { RPerfAnalysis.initialize(); Locale.setDefault(Locale.ROOT); RAccuracyInfo.initialize(); + ROptions.initialize(); singleton.crashOnFatalError = crashOnFatalErrorArg; singleton.builtinLookup = RBuiltinPackages.getInstance(); singleton.context = RContext.setRuntimeState(singleton, commandArgs, consoleHandler, new RASTHelperImpl(), headless); @@ -115,30 +116,59 @@ public final class REngine implements RContext.Engine { RVersionInfo.initialize(); RRNG.initialize(); TempDirPath.initialize(); - ROptions.initialize(); RProfile.initialize(); /* - * eval the system profile. Experimentally GnuR does not report warnings during this - * evaluation, but does for the site/user profiles + * eval the system/site/user profiles. Experimentally GnuR does not report warnings + * during system profile evaluation, but does for the site/user profiles. */ - singleton.parseAndEval(RProfile.systemProfile(), baseFrame.materialize(), REnvironment.baseEnv(), false, false); + MaterializedFrame baseFrameMaterialized = baseFrame.materialize(); + MaterializedFrame globalFrameMaterialized = globalFrame.materialize(); + singleton.parseAndEval(RProfile.systemProfile(), baseFrameMaterialized, REnvironment.baseEnv(), false, false); + checkAndRunStartupFunction(".OptRequireMethods"); + reportWarnings = true; - REnvironment.packagesInitialize(RPackages.initialize()); - RPackageVariables.initialize(); // TODO replace with R code Source siteProfile = RProfile.siteProfile(); if (siteProfile != null) { - singleton.parseAndEval(siteProfile, baseFrame.materialize(), REnvironment.baseEnv(), false, false); + singleton.parseAndEval(siteProfile, baseFrameMaterialized, REnvironment.baseEnv(), false, false); } + Source userProfile = RProfile.userProfile(); + if (userProfile != null) { + singleton.parseAndEval(userProfile, globalFrameMaterialized, REnvironment.globalEnv(), false, false); + } + /* + * TODO This is where we would load any saved user data + */ + checkAndRunStartupFunction(".First"); + checkAndRunStartupFunction(".First.sys"); + /* + * TODO The following calls will eventually go away as this will be done in the system + * profile + */ + REnvironment.packagesInitialize(RPackages.initialize()); + RPackageVariables.initialize(); // TODO replace with R code initialized = true; } - Source userProfile = RProfile.userProfile(); - if (userProfile != null) { - singleton.parseAndEval(userProfile, globalFrame.materialize(), REnvironment.globalEnv(), false, false); - } registerBaseGraphicsSystem(); return globalFrame; } + public static void checkAndRunStartupFunction(String name) { + Object func = REnvironment.globalEnv().findVar(name); + if (func != null && func instanceof RFunction) { + /* + * We could just invoke runCall, but that way causes problems for debugging, so we parse + * and eval a "fake" call. + */ + RInstrument.checkDebugRequested(name, (RFunction) func); + String call = name + "()"; + singleton.parseAndEval(Source.asPseudoFile(call, "<startup>"), REnvironment.globalEnv().getFrame(), REnvironment.globalEnv(), true, false); + } + } + + public void checkAndRunLast(String name) { + checkAndRunStartupFunction(name); + } + private static void registerBaseGraphicsSystem() { try { getGraphicsEngine().registerGraphicsSystem(new BaseGraphicsSystem()); diff --git a/com.oracle.truffle.r.native/library/Makefile b/com.oracle.truffle.r.native/library/Makefile index cb84c604e0..c912b7658c 100644 --- a/com.oracle.truffle.r.native/library/Makefile +++ b/com.oracle.truffle.r.native/library/Makefile @@ -1,5 +1,5 @@ # -# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2014, 2015, 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 @@ -21,13 +21,23 @@ # questions. # -.PHONY: all clean libdir +.PHONY: all clean libdir make_subdirs clean_subdirs -all: libdir - $(MAKE) -C tools +SUBDIRS = tools utils methods -clean: - $(MAKE) -C tools clean +all: libdir make_subdirs + +make_subdirs: + for dir in $(SUBDIRS); do \ + $(MAKE) PACKAGE=$$dir -C $$dir; \ + done + +clean: clean_subdirs + +clean_subdirs: + for dir in $(SUBDIRS); do \ + $(MAKE) PACKAGE=$$dir -C $$dir clean ; \ + done libdir: mkdir -p $(TOPDIR)/../library diff --git a/com.oracle.truffle.r.native/library/lib.mk b/com.oracle.truffle.r.native/library/lib.mk new file mode 100644 index 0000000000..7858973726 --- /dev/null +++ b/com.oracle.truffle.r.native/library/lib.mk @@ -0,0 +1,65 @@ +# +# Copyright (c) 2014, 2015, 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. +# + +include ../../platform.mk + +.PHONY: all clean cleanlib cleanobj force libr + +PKG = $(PACKAGE) + +SRC = src +OBJ = lib/$(OS_DIR) + +C_SOURCES := $(wildcard $(SRC)/*.c) + +C_OBJECTS := $(subst $(SRC),$(OBJ),$(C_SOURCES:.c=.o)) + +LIBDIR := $(OBJ) + +# packages seem to use .so even on Mac OS X and no "lib" +LIB_PKG := $(OBJ)/$(PKG).so + + +all: $(LIB_PKG) + +$(OBJ): + mkdir -p $(OBJ) + +$(LIB_PKG): $(OBJ) $(OBJ)/$(PACKAGE).o + mkdir -p $(LIBDIR) + $(CC) $(LDFLAGS) -o $(LIB_PKG) $(OBJ)/$(PACKAGE).o + +$(OBJ)/%.o: $(SRC)/%.c + $(CC) $(CFLAGS) -c $< -o $@ + +$(OBJ)/%.o: $(SRC)/%.f + $(FC) $(CFLAGS) -c $< -o $@ + +clean: cleanobj cleanlib + +cleanlib: + rm -f $(LIB_PKG) + +cleanobj: + rm -f $(LIBDIR)/*.o + diff --git a/com.oracle.truffle.r.native/library/methods/Makefile b/com.oracle.truffle.r.native/library/methods/Makefile new file mode 100644 index 0000000000..f128fcf8a4 --- /dev/null +++ b/com.oracle.truffle.r.native/library/methods/Makefile @@ -0,0 +1,24 @@ +# +# Copyright (c) 2014, 2015, 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. +# + +include ../lib.mk diff --git a/com.oracle.truffle.r.native/library/methods/src/methods.c b/com.oracle.truffle.r.native/library/methods/src/methods.c new file mode 100644 index 0000000000..fab17ac780 --- /dev/null +++ b/com.oracle.truffle.r.native/library/methods/src/methods.c @@ -0,0 +1 @@ +// Empty file diff --git a/com.oracle.truffle.r.native/library/tools/Makefile b/com.oracle.truffle.r.native/library/tools/Makefile index 46ca3d2c24..f128fcf8a4 100644 --- a/com.oracle.truffle.r.native/library/tools/Makefile +++ b/com.oracle.truffle.r.native/library/tools/Makefile @@ -1,5 +1,5 @@ # -# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2014, 2015, 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 @@ -21,45 +21,4 @@ # questions. # -include ../../platform.mk - -.PHONY: all clean cleanlib cleanobj force libr - -PKG = tools - -SRC = src -OBJ = lib/$(OS_DIR) - -C_SOURCES := $(wildcard $(SRC)/*.c) - -C_OBJECTS := $(subst $(SRC),$(OBJ),$(C_SOURCES:.c=.o)) - -LIBDIR := $(OBJ) - -# packages seem to use .so even on Mac OS X and no "lib" -LIB_PKG := $(OBJ)/$(PKG).so - - -all: $(LIB_PKG) - -$(OBJ): - mkdir -p $(OBJ) - -$(LIB_PKG): $(OBJ) $(OBJ)/tools.o - mkdir -p $(LIBDIR) - $(CC) $(LDFLAGS) -o $(LIB_PKG) $(OBJ)/tools.o - -$(OBJ)/%.o: $(SRC)/%.c - $(CC) $(CFLAGS) -c $< -o $@ - -$(OBJ)/%.o: $(SRC)/%.f - $(FC) $(CFLAGS) -c $< -o $@ - -clean: cleanobj cleanlib - -cleanlib: - rm -f $(LIB_PKG) - -cleanobj: - rm -f $(LIBDIR)/*.o - +include ../lib.mk diff --git a/com.oracle.truffle.r.native/library/utils/Makefile b/com.oracle.truffle.r.native/library/utils/Makefile new file mode 100644 index 0000000000..f128fcf8a4 --- /dev/null +++ b/com.oracle.truffle.r.native/library/utils/Makefile @@ -0,0 +1,24 @@ +# +# Copyright (c) 2014, 2015, 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. +# + +include ../lib.mk diff --git a/com.oracle.truffle.r.native/library/utils/src/utils.c b/com.oracle.truffle.r.native/library/utils/src/utils.c new file mode 100644 index 0000000000..fab17ac780 --- /dev/null +++ b/com.oracle.truffle.r.native/library/utils/src/utils.c @@ -0,0 +1 @@ +// Empty file diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BaseOptions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BaseOptions.java deleted file mode 100644 index e9084f119c..0000000000 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BaseOptions.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2014, 2014, 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 com.oracle.truffle.r.runtime.*; -import com.oracle.truffle.r.runtime.data.*; - -public class BaseOptions implements ROptions.Handler { - public enum Name { - AddSmooth("add.smooth"), - BrowserNLdisabled("browserNLdisabled"), - CheckPackageLicense("checkPackageLicense"), - CheckBounds("check.bounds"), - CBoundsCheck("CBoundsCheck"), - Continue("continue"), - DefaultPackages("defaultPackages"), - DeparseCutoff("deparse.cutoff"), - DeparseMaxLines("deparse.max.lines"), - Digits("digits"), - DigitsSecs("digits.secs"), - DownloadFileExtra("download.file.extra"), - DownloadFileMethod("download.file.method"), - Echo("echo"), - Encoding("encoding"), - Error("error"), - Expressions("expressions"), - KeepSource("keep.source"), - KeepSourcePkgs("keep.source.pkgs"), - MaxPrint("max.print"), - OutDec("OutDec"), - Pager("pager"), - Papersize("papersize"), - Pdfviewer("pdfviewer"), - Printcmd("printcmd"), - Prompt("prompt"), - Rl_word_breaks("rl_word_breaks"), - SaveDefaults("save.defaults"), - SaveImageDefaults("save.image.defaults"), - Scipen("scipen"), - ShowWarnCalls("showWarnCalls"), - ShowErrorCalls("showErrorCalls"), - ShowNCalls("showNCalls"), - ShowErrorLocations("show.error.locations"), - ShowErrorMessages("show.error.messages"), - StringsAsFactors("stringsAsFactors"), - Texi2dvi("texi2dvi"), - Timeout("timeout"), - TopLevelEnvironment("topLevelEnvironment"), - UseFancyQuotes("useFancyQuotes"), - Verbose("verbose"), - Warn("warn"), - WarnPartialMatchArgs("warnPartialMatchArgs"), - WarnPartialMatchAttr("warnPartialMatchAttr"), - WarnPartialMatchDollar("warnPartialMatchDollar"), - WarningExpression("warning.expression"), - WarningLength("warning.length"), - Nwarnings("nwarnings"), - Width("width"); - - private final String rName; - - private Name(String name) { - this.rName = name; - } - - public String getName() { - return rName; - } - } - - public BaseOptions() { - ROptions.registerHandler(this); - } - - public void initialize() { - // The "factory fresh" settings - ROptions.setValue(Name.AddSmooth.rName, RDataFactory.createLogicalVectorFromScalar(true)); - ROptions.setValue(Name.CheckBounds.rName, RDataFactory.createLogicalVectorFromScalar(false)); - ROptions.setValue(Name.Continue.rName, RDataFactory.createStringVector("+ ")); - ROptions.setValue(Name.Digits.rName, RDataFactory.createIntVectorFromScalar(7)); - ROptions.setValue(Name.Echo.rName, RDataFactory.createLogicalVectorFromScalar(true)); - ROptions.setValue(Name.Encoding.rName, RDataFactory.createStringVector("native.enc")); - ROptions.setValue(Name.Error.rName, RNull.instance); - ROptions.setValue(Name.Expressions.rName, RDataFactory.createIntVectorFromScalar(5000)); - ROptions.setValue(Name.KeepSourcePkgs.rName, RDataFactory.createLogicalVectorFromScalar(false)); - ROptions.setValue(Name.KeepSource.rName, RDataFactory.createLogicalVectorFromScalar(!RContext.isHeadless())); - ROptions.setValue(Name.MaxPrint.rName, RDataFactory.createIntVectorFromScalar(99999)); - ROptions.setValue(Name.OutDec.rName, RDataFactory.createStringVector(".")); - ROptions.setValue(Name.Prompt.rName, RDataFactory.createStringVector("> ")); - ROptions.setValue(Name.Scipen.rName, RDataFactory.createIntVector(0)); - ROptions.setValue(Name.ShowErrorMessages.rName, RDataFactory.createLogicalVectorFromScalar(true)); - ROptions.setValue(Name.Timeout.rName, RDataFactory.createIntVectorFromScalar(60)); - ROptions.setValue(Name.Verbose.rName, RDataFactory.createLogicalVectorFromScalar(false)); - ROptions.setValue(Name.Warn.rName, RDataFactory.createIntVectorFromScalar(0)); - ROptions.setValue(Name.WarningLength.rName, RDataFactory.createIntVectorFromScalar(1000)); - ROptions.setValue(Name.Width.rName, RDataFactory.createIntVectorFromScalar(80)); - - // others - ROptions.setValue(Name.BrowserNLdisabled.rName, RDataFactory.createLogicalVectorFromScalar(false)); - } - - public void addOptions() { - } -} diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BaseVariables.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BaseVariables.java index ddc368a925..99a1a8d541 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BaseVariables.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/BaseVariables.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2015, 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 @@ -30,9 +30,9 @@ import com.oracle.truffle.r.runtime.data.*; import com.oracle.truffle.r.runtime.env.*; /** - * The (global) variables defined in the {@code base} package, e.g. {@code .Platform}. As per - * {@link BaseOptions} the definition and initialization is two-step process handled through the - * {@link RPackageVariables} class. + * The (global) variables defined in the {@code base} package, e.g. {@code .Platform}. The + * definition and initialization is two-step process handled through the {@link RPackageVariables} + * class. * * N.B. Some variables are assigned explicitly in the R source files associated with the base * package. @@ -40,7 +40,7 @@ import com.oracle.truffle.r.runtime.env.*; public class BaseVariables implements RPackageVariables.Handler { // @formatter:off @CompilationFinal private static final String[] VARS = new String[]{ - ".AutoloadEnv", ".BaseNamespaceEnv", ".GlobalEnv", ".Machine", ".Platform" + ".BaseNamespaceEnv", ".GlobalEnv", ".Machine", ".Platform" }; // @formatter:on @@ -87,9 +87,6 @@ private int initialized = -1; case ".GlobalEnv": value = REnvironment.globalEnv(); break; - case ".AutoloadEnv": - value = REnvironment.autoloadEnv(); - break; case ".Machine": value = createMachine(); break; diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/PrettyPrinterNode.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/PrettyPrinterNode.java index 482ef07d89..5b14dff717 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/PrettyPrinterNode.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/PrettyPrinterNode.java @@ -400,7 +400,7 @@ public abstract class PrettyPrinterNode extends RNode { private static int getMaxPrintLength() { int maxPrint = -1; // infinity - Object maxPrintObj = ROptions.getValue(BaseOptions.Name.MaxPrint.getName()); + Object maxPrintObj = ROptions.getValue("max.print"); if (maxPrintObj != null) { if (maxPrintObj instanceof Integer) { diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Quit.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Quit.java index 105f6ce941..161d49fc10 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Quit.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Quit.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2015, 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 @@ -91,7 +91,9 @@ public abstract class Quit extends RInvisibleBuiltinNode { consoleHandler.println("Image saving is not implemented"); } if (runLast != 0) { - consoleHandler.println(".Last execution not implemented"); + RContext.getEngine().checkAndRunLast(".Last"); + // TODO errors should return to prompt if interactive + RContext.getEngine().checkAndRunLast(".Last.sys"); } Utils.exit(status); return null; diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/instrument/RInstrument.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/instrument/RInstrument.java index 847a5e0100..11eada1660 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/instrument/RInstrument.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/instrument/RInstrument.java @@ -30,6 +30,7 @@ import com.oracle.truffle.api.instrument.SyntaxTag; import com.oracle.truffle.api.nodes.*; import com.oracle.truffle.api.source.Source; import com.oracle.truffle.r.nodes.function.*; +import com.oracle.truffle.r.nodes.instrument.debug.*; import com.oracle.truffle.r.nodes.instrument.trace.*; import com.oracle.truffle.r.options.FastROptions; import com.oracle.truffle.r.runtime.data.*; @@ -92,6 +93,12 @@ public class RInstrument { */ private static boolean instrumentingEnabled; + /** + * The function names that were requested to be used in implicit {@code debug(f)} calls, when + * those functions are defined. + */ + private static String[] debugFunctionNames; + private static void putProbe(FunctionUID uid, Probe probe) { ArrayList<Probe> list = probeMap.get(uid); if (list == null) { @@ -110,17 +117,34 @@ public class RInstrument { * features that need it are also enabled. */ public static void initialize() { - instrumentingEnabled = FastROptions.Instrument.getValue() || REntryCounters.Function.enabled() || RNodeTimer.Statement.enabled(); + // @formatter:off + instrumentingEnabled = FastROptions.Instrument.getValue() || FastROptions.TraceCalls.getValue() || FastROptions.Rdebug.getValue() != null || + REntryCounters.Function.enabled() || RNodeTimer.Statement.enabled(); + // @formatter:on if (instrumentingEnabled) { Probe.registerASTProber(RASTProber.getRASTProber()); Probe.addProbeListener(new RProbeListener()); } + String rdebugValue = FastROptions.Rdebug.getValue(); + if (rdebugValue != null) { + debugFunctionNames = rdebugValue.split(","); + } } public static boolean instrumentingEnabled() { return instrumentingEnabled; } + public static void checkDebugRequested(String name, RFunction func) { + if (debugFunctionNames != null) { + for (String debugFunctionName : debugFunctionNames) { + if (debugFunctionName.equals(name)) { + DebugHandling.enableDebug(func, "", RNull.instance, false); + } + } + } + } + /** * Returns the {@link Probe} with the given tag for the given function, or {@code null} if not * found. diff --git a/com.oracle.truffle.r.options/src/com/oracle/truffle/r/options/FastROptions.java b/com.oracle.truffle.r.options/src/com/oracle/truffle/r/options/FastROptions.java index 82cd6427f3..08521a3936 100644 --- a/com.oracle.truffle.r.options/src/com/oracle/truffle/r/options/FastROptions.java +++ b/com.oracle.truffle.r.options/src/com/oracle/truffle/r/options/FastROptions.java @@ -57,6 +57,8 @@ public class FastROptions { public static final OptionValue<Boolean> TraceCalls = new OptionValue<>(false); @Option(help = "Collect Performance Data") public static final OptionValue<String> PerfStats = new OptionValue<>(null); + @Option(help = "Rdebug=f1,f2.,,,; list of R function to call debug on (implies +Instrument)") + public static final OptionValue<String> Rdebug = new OptionValue<>(null); // Promises optimizations @Option(help = "If enabled, overrides all other EagerEval switches (see EagerEvalHelper)") diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/R/Rprofile.R b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/R/Rprofile.R index 90f93a09f7..6232ac26cb 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/R/Rprofile.R +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/R/Rprofile.R @@ -21,9 +21,9 @@ ### Mostly commented out as FastR currently does a lot of this in Java, which may change. #.GlobalEnv <- globalenv() -#attach(NULL, name = "Autoloads") -#.AutoloadEnv <- as.environment(2) -#assign(".Autoloaded", NULL, envir = .AutoloadEnv) +attach(NULL, name = "Autoloads") +.AutoloadEnv <- as.environment(2) +assign(".Autoloaded", NULL, envir = .AutoloadEnv) T <- TRUE F <- FALSE R.version <- structure(R.Version(), class = "simple.list") @@ -35,32 +35,33 @@ R.version.string <- R.version$version.string ### NOTA BENE: options() for non-base package functionality are in places like ### --------- ../utils/R/zzz.R # -#options(keep.source = interactive()) -#options(warn = 0) -## options(repos = c(CRAN="@CRAN@")) -## options(BIOC = "http://www.bioconductor.org") -# -#options(timeout = 60) -#options(encoding = "native.enc") -#options(show.error.messages = TRUE) -### keep in sync with PrintDefaults() in ../../main/print.c : -#options(scipen = 0) -#options(max.print = 99999)# max. #{entries} in internal printMatrix() -#options(add.smooth = TRUE)# currently only used in 'plot.lm' -#options(stringsAsFactors = TRUE) -#if(!interactive() && is.null(getOption("showErrorCalls"))) -# options(showErrorCalls = TRUE) -# -#local({dp <- Sys.getenv("R_DEFAULT_PACKAGES") -# if(identical(dp, "")) # marginally faster to do methods last -# dp <- c("datasets", "utils", "grDevices", "graphics", -# "stats", "methods") -# else if(identical(dp, "NULL")) dp <- character(0) -# else dp <- strsplit(dp, ",")[[1]] +options(keep.source = interactive()) +options(warn = 0) +# options(repos = c(CRAN="@CRAN@")) +# options(BIOC = "http://www.bioconductor.org") + +options(timeout = 60) +options(encoding = "native.enc") +options(show.error.messages = TRUE) +## keep in sync with PrintDefaults() in ../../main/print.c : +options(scipen = 0) +options(max.print = 99999)# max. #{entries} in internal printMatrix() +options(add.smooth = TRUE)# currently only used in 'plot.lm' +options(stringsAsFactors = TRUE) +if(!interactive() && is.null(getOption("showErrorCalls"))) + options(showErrorCalls = TRUE) + +local({dp <- Sys.getenv("R_DEFAULT_PACKAGES") + if(identical(dp, "")) # marginally faster to do methods last + dp <- c("datasets", "utils", "grDevices", "graphics", + "stats", "methods") + else if(identical(dp, "NULL")) dp <- character(0) + else dp <- strsplit(dp, ",")[[1]] + # There is a problem with the \\1 # dp <- sub("[[:blank:]]*([[:alnum:]]+)", "\\1", dp) # strip whitespace -# options(defaultPackages = dp) -# }) -# + options(defaultPackages = dp) + }) + ## Expand R_LIBS_* environment variables. Sys.setenv(R_LIBS_SITE = .expand_R_libs_env_var(Sys.getenv("R_LIBS_SITE"))) @@ -70,6 +71,8 @@ Sys.setenv(R_LIBS_USER = #.First.sys <- function() #{ # for(pkg in getOption("defaultPackages")) { +# # for the moment we only handle "utils" this way +# if (pkg != "utils") next # res <- require(pkg, quietly = TRUE, warn.conflicts = FALSE, # character.only = TRUE) # if(!res) @@ -87,7 +90,7 @@ Sys.setenv(R_LIBS_USER = # warning('package "methods" in options("defaultPackages") was not found', call.=FALSE) # } #} -# + #if(nzchar(Sys.getenv("R_BATCH"))) { # .Last.sys <- function() # { diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RArguments.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RArguments.java index 1d99d02ea1..f28743aeb3 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RArguments.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RArguments.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2015, 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 @@ -321,7 +321,12 @@ public final class RArguments { if (ss != null) { return ss.getCode(); } else { - return getFunction(frame).getTarget().toString(); + RFunction function = getFunction(frame); + if (function != null) { + return function.getTarget().toString(); + } else { + return "<unknown call>"; + } } } diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RContext.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RContext.java index bbb15d834e..a56f2d87ae 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RContext.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RContext.java @@ -250,6 +250,12 @@ public final class RContext extends ExecutionContext { */ Object evalPromise(RPromise expr, SourceSection callSrc); + /** + * Checks for the existence of {@code .Last/.Last.sys} and if present and bound to a + * function, invokes the (parameterless) function. + */ + void checkAndRunLast(String name); + /** * Wraps the Truffle AST in {@code body} in an anonymous function and returns a * {@link RootCallTarget} for it. diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ROptions.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ROptions.java index 016dc35c45..57ef75ff02 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ROptions.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ROptions.java @@ -1,24 +1,13 @@ /* - * Copyright (c) 2014, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * This material is distributed under the GNU General Public License + * Version 2. You may review the terms of this license at + * http://www.gnu.org/licenses/gpl-2.0.html * - * 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. + * Copyright (c) 1995-2012, The R Core Team + * Copyright (c) 2003, The R Foundation + * Copyright (c) 2015, Oracle and/or its affiliates * - * 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. + * All rights reserved. */ package com.oracle.truffle.r.runtime; @@ -28,10 +17,7 @@ import com.oracle.truffle.r.runtime.data.*; /** * Central location for all R options, that is for the {@code options(...)} and {@code getOption} - * builtins. When a package is loaded, it must call {@link #registerHandler}, which will immediately - * callback the {@code addOptions} method that should register the options for that package. The - * {@code initialize} method will be called (later) which can set values based on the current - * execution environment. + * builtins. * * An unset option does not appear in the map but is represented as the value {@link RNull#instance} * . Setting with {@link RNull#instance} removes the option from the map and, therefore, from being @@ -40,24 +26,37 @@ import com.oracle.truffle.r.runtime.data.*; */ public class ROptions { - public interface Handler { - void initialize(); - - void addOptions(); - } - private static final HashMap<String, Object> map = new HashMap<>(); - private static final ArrayList<Handler> handlers = new ArrayList<>(); + + // Transcribed from src/main.options.c public static void initialize() { - for (Handler handler : handlers) { - handler.initialize(); - } + ROptions.setValue("add.smooth", RDataFactory.createLogicalVectorFromScalar(true)); + ROptions.setValue("check.bounds", RDataFactory.createLogicalVectorFromScalar(false)); + ROptions.setValue("continue", RDataFactory.createStringVector("+ ")); + ROptions.setValue("deparse.cutoff", RDataFactory.createIntVectorFromScalar(60)); + ROptions.setValue("digits", RDataFactory.createIntVectorFromScalar(7)); + ROptions.setValue("echo", RDataFactory.createLogicalVectorFromScalar(true)); + ROptions.setValue("echo", RDataFactory.createStringVector("native.enc")); + ROptions.setValue("expressions", RDataFactory.createIntVectorFromScalar(5000)); + boolean keepPkgSource = optionFromEnvVar("R_KEEP_PKG_SOURCE"); + ROptions.setValue("keep.source", RDataFactory.createLogicalVectorFromScalar(keepPkgSource)); + ROptions.setValue("keep.source.pkgs", RDataFactory.createLogicalVectorFromScalar(keepPkgSource)); + ROptions.setValue("OutDec", RDataFactory.createStringVector(".")); + ROptions.setValue("prompt", RDataFactory.createStringVector("> ")); + ROptions.setValue("verbose", RDataFactory.createLogicalVectorFromScalar(false)); + ROptions.setValue("nwarnings", RDataFactory.createIntVectorFromScalar(50)); + ROptions.setValue("warning.length", RDataFactory.createIntVectorFromScalar(1000)); + ROptions.setValue("width", RDataFactory.createIntVectorFromScalar(80)); + ROptions.setValue("browserNLdisabled", RDataFactory.createLogicalVectorFromScalar(false)); + boolean cBoundsCheck = optionFromEnvVar("R_C_BOUNDS_CHECK"); + ROptions.setValue("CBoundsCheck", RDataFactory.createLogicalVectorFromScalar(cBoundsCheck)); } - public static void registerHandler(Handler handler) { - handlers.add(handler); - handler.addOptions(); + private static boolean optionFromEnvVar(String envVar) { + String envValue = REnvVars.get(envVar); + return envValue != null && envValue.equals("yes"); + } public static Set<Map.Entry<String, Object>> getValues() { diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/env/REnvironment.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/env/REnvironment.java index e34536a907..c6ae40c144 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/env/REnvironment.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/env/REnvironment.java @@ -116,7 +116,6 @@ public abstract class REnvironment extends RAttributeStorage implements RAttribu private static Global globalEnv; private static REnvironment initialGlobalEnvParent; private static Base baseEnv; - private static REnvironment autoloadEnv; private static REnvironment namespaceRegistry; /** @@ -198,14 +197,6 @@ public abstract class REnvironment extends RAttributeStorage implements RAttribu return baseEnv.getNamespace(); } - /** - * Value set in the {@code .AutoloadEnv} variable. - */ - public static REnvironment autoloadEnv() { - assert autoloadEnv != null; - return autoloadEnv; - } - /** * Invoked on startup to setup the global values and package search path. Owing to the * restrictions on storing {@link VirtualFrame} instances, this method creates the @@ -224,9 +215,7 @@ public abstract class REnvironment extends RAttributeStorage implements RAttribu namespaceRegistry = RDataFactory.createNewEnv(UNNAMED); baseEnv = new Base(baseFrame); - // autoload always next - autoloadEnv = NewEnv.createAutoload(); - globalEnv = new Global(autoloadEnv, globalFrame); + globalEnv = new Global(baseEnv, globalFrame); initSearchList(); // load base package first @@ -235,7 +224,7 @@ public abstract class REnvironment extends RAttributeStorage implements RAttribu public static void packagesInitialize(ArrayList<RPackage> rPackages) { // now load rPackages, we need a new VirtualFrame for each - REnvironment pkgParent = autoloadEnv; + REnvironment pkgParent = globalEnv.parent; for (RPackage rPackage : rPackages) { VirtualFrame pkgFrame = RRuntime.createNonFunctionFrame(); Package pkgEnv = new Package(pkgParent, rPackage.name, pkgFrame, rPackage.path); @@ -700,6 +689,23 @@ public abstract class REnvironment extends RAttributeStorage implements RAttribu frameAccess.rm(key); } + /** + * Explicit search for a variable {@code name}; used in startup sequence. + * + * @return the value of the variable or {@code null} if not found. + */ + public Object findVar(String varName) { + REnvironment env = this; + while (env != emptyEnv) { + Object value = env.get(varName); + if (value != null) { + return value; + } + env = env.parent; + } + return null; + } + public RStringVector ls(boolean allNames, Pattern pattern) { return frameAccess.ls(allNames, pattern); } @@ -907,12 +913,6 @@ public abstract class REnvironment extends RAttributeStorage implements RAttribu } } - private static REnvironment createAutoload() { - REnvironment autoload = RDataFactory.createNewEnv(baseEnv, 0); - autoload.setAttr(NAME_ATTR_KEY, "Autoloads"); - return autoload; - } - public REnvMapFrameAccess getFrameAccess() { return (REnvMapFrameAccess) frameAccess; } diff --git a/mx.fastr/copyrights/overrides b/mx.fastr/copyrights/overrides index 8d533d1b1b..e602e30b64 100644 --- a/mx.fastr/copyrights/overrides +++ b/mx.fastr/copyrights/overrides @@ -17,6 +17,8 @@ com.oracle.truffle.r.native/include/jni/Rconfig.h,no.copyright com.oracle.truffle.r.native/include/jni/Rdefines.h,no.copyright com.oracle.truffle.r.native/include/jni/Rinternals.h,gnu_r.copyright com.oracle.truffle.r.native/library/tools/src/tools.c,no.copyright +com.oracle.truffle.r.native/library/utils/src/utils.c,no.copyright +com.oracle.truffle.r.native/library/methods/src/methods.c,no.copyright com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/BinaryOpsGroupDispatchNode.java,purdue.copyright com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/DispatchNode.java,purdue.copyright com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/DispatchedCallNode.java,purdue.copyright @@ -143,6 +145,7 @@ com.oracle.truffle.r.parser/src/com/oracle/truffle/r/parser/tools/TreeViewer.jav com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RSerialize.java,gnu_r.copyright com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RDeparse.java,gnu_r.copyright com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RError.java,gnu_r.copyright +com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ROptions.java,gnu_r.copyright com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/rng/RRNG.java,gnu_r.copyright com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/rng/RNGInitAdapter.java,gnu_r.copyright com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/rng/mt/MersenneTwister.java,hiroshima.copyright -- GitLab