From 525b4e27a913ef27b4239c6a2ad9d8de1acb78c8 Mon Sep 17 00:00:00 2001
From: Mick Jordan <mick.jordan@oracle.com>
Date: Wed, 18 Jun 2014 20:56:20 -0700
Subject: [PATCH] create engine project (need to run mx eclipseinit); add
 truffle.api.ExecutionContext as RContext superclass; fix tabs

---
 .../com/oracle/truffle/r/engine}/REngine.java |  2 +-
 .../truffle/r/nodes/builtin/base/R/library.R  |  2 +-
 .../r/nodes/builtin/base/R/namespace.R        | 32 ++++++++--------
 .../truffle/r/nodes/builtin/base/R/sample.R   |  8 ++--
 .../oracle/truffle/r/runtime/RContext.java    | 38 ++++++++++++-------
 .../oracle/truffle/r/runtime/RRuntime.java    |  2 +-
 .../com/oracle/truffle/r/shell/RCommand.java  |  1 +
 .../truffle/r/test/generate/FastRSession.java |  2 +-
 mx.fastr/projects                             |  9 ++++-
 9 files changed, 58 insertions(+), 38 deletions(-)
 rename {com.oracle.truffle.r.shell/src/com/oracle/truffle/r/shell => com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine}/REngine.java (99%)

diff --git a/com.oracle.truffle.r.shell/src/com/oracle/truffle/r/shell/REngine.java b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/REngine.java
similarity index 99%
rename from com.oracle.truffle.r.shell/src/com/oracle/truffle/r/shell/REngine.java
rename to com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/REngine.java
index 4a2035c39c..060819bdc0 100644
--- a/com.oracle.truffle.r.shell/src/com/oracle/truffle/r/shell/REngine.java
+++ b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/REngine.java
@@ -20,7 +20,7 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
-package com.oracle.truffle.r.shell;
+package com.oracle.truffle.r.engine;
 
 import java.io.*;
 import java.util.*;
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/R/library.R b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/R/library.R
index 7a23c55f9b..2d43469d45 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/R/library.R
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/R/library.R
@@ -76,7 +76,7 @@ library <-
     }
     ## warn if installed under a later version of R
 # Suppress check to workaround numeric_version generic comparison
-#	if(R_version_built_under > current)
+#    if(R_version_built_under > current)
 #      warning(gettextf("package %s was built under R version %s",
 #              sQuote(pkgname), as.character(built$R)),
 #          call. = FALSE, domain = NA)
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/R/namespace.R b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/R/namespace.R
index fbd00dd655..a3baa3d20e 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/R/namespace.R
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/R/namespace.R
@@ -301,7 +301,7 @@ loadNamespace <- function (package, lib.loc = NULL,
             }
 
             symNames <- nativeRoutines$symbolNames
-			if(length(symNames) == 0L) return(NULL)
+            if(length(symNames) == 0L) return(NULL)
 
             symbols <- getNativeSymbolInfo(symNames, dll, unlist = FALSE,
                     withRegistrationInfo = TRUE)
@@ -329,12 +329,12 @@ loadNamespace <- function (package, lib.loc = NULL,
         }
 
         ## find package and check it has a namespace
-		pkgpath <- find.package(package, lib.loc, quiet = TRUE)
+        pkgpath <- find.package(package, lib.loc, quiet = TRUE)
         if (length(pkgpath) == 0L)
             stop(gettextf("there is no package called %s", sQuote(package)),
                     domain = NA)
         bindTranslations(package, pkgpath)
-		package.lib <- dirname(pkgpath)
+        package.lib <- dirname(pkgpath)
         package <- basename(pkgpath) # need the versioned name
         if (! packageHasNamespace(package, package.lib)) {
             hasNoNamespaceError <-
@@ -355,7 +355,7 @@ loadNamespace <- function (package, lib.loc = NULL,
         ## No, not during builds of standard packages
         ## stats4 depends on methods, but exports do not matter
         ## whilst it is being built
-		nsInfoFilePath <- file.path(pkgpath, "Meta", "nsInfo.rds")
+        nsInfoFilePath <- file.path(pkgpath, "Meta", "nsInfo.rds")
         nsInfo <- if(file.exists(nsInfoFilePath)) readRDS(nsInfoFilePath)
                 else parseNamespaceFile(package, package.lib, mustExist = FALSE)
 
@@ -370,7 +370,7 @@ loadNamespace <- function (package, lib.loc = NULL,
                         call. = FALSE, domain = NA)
             R_version_built_under <- as.numeric_version(built$R)
 # can't do.call generics
-#			if(R_version_built_under < "3.0.0")
+#            if(R_version_built_under < "3.0.0")
 #                stop(gettextf("package %s was built before R 3.0.0: please re-install it",
 #                                sQuote(basename(pkgpath))),
 #                        call. = FALSE, domain = NA)
@@ -416,20 +416,20 @@ loadNamespace <- function (package, lib.loc = NULL,
         "__LoadingNamespaceInfo__" <- list(libname = package.lib,
                 pkgname = package)
 
-		env <- asNamespace(ns)
+        env <- asNamespace(ns)
         ## save the package name in the environment
         assign(".packageName", package, envir = env)
 
         ## load the code
         codename <- strsplit(package, "_", fixed = TRUE)[[1L]][1L]
         codeFile <- file.path(pkgpath, "R", codename)
-		if (file.exists(codeFile)) {
+        if (file.exists(codeFile)) {
             res <- try(sys.source(codeFile, env, keep.source = keep.source))
             if(inherits(res, "try-error"))
                 stop(gettextf("unable to load R code in package %s",
                                 sQuote(package)), call. = FALSE, domain = NA)
         }
-		# a package without R code currently is required to have a namespace
+        # a package without R code currently is required to have a namespace
         # else warning(gettextf("package %s contains no R code",
         #                        sQuote(package)), call. = FALSE, domain = NA)
 
@@ -439,11 +439,11 @@ loadNamespace <- function (package, lib.loc = NULL,
 
         ## lazy-load any sysdata
         dbbase <- file.path(pkgpath, "R", "sysdata")
-		if (file.exists(paste0(dbbase, ".rdb"))) lazyLoad(dbbase, env)
+        if (file.exists(paste0(dbbase, ".rdb"))) lazyLoad(dbbase, env)
 
         ## load any lazydata into a separate environment
         dbbase <- file.path(pkgpath, "data", "Rdata")
-		if(file.exists(paste0(dbbase, ".rdb")))
+        if(file.exists(paste0(dbbase, ".rdb")))
             lazyLoad(dbbase, getNamespaceInfo(ns, "lazydata"))
 
         ## register any S3 methods
@@ -452,7 +452,7 @@ loadNamespace <- function (package, lib.loc = NULL,
         ## load any dynamic libraries
         dlls <- list()
         dynLibs <- nsInfo$dynlibs
-		for (i in seq_along(dynLibs)) {
+        for (i in seq_along(dynLibs)) {
             lib <- dynLibs[i]
             dlls[[lib]]  <- library.dynam(lib, package, package.lib)
             assignNativeRoutines(dlls[[lib]], lib, env,
@@ -468,7 +468,7 @@ loadNamespace <- function (package, lib.loc = NULL,
                 assign(names(nsInfo$dynlibs)[i], dlls[[lib]], envir = env)
             setNamespaceInfo(env, "DLLs", dlls)
         }
-		addNamespaceDynLibs(env, nsInfo$dynlibs)
+        addNamespaceDynLibs(env, nsInfo$dynlibs)
 
 
         ## used in e.g. utils::assignInNamespace
@@ -679,7 +679,7 @@ loadingNamespaceInfo <- function() {
     dynGet <- function(name,
 #            notFound = stop(gettextf("%s not found", sQuote(name)),
             notFound = gettextf("%s not found", sQuote(name),
-			domain = NA))
+            domain = NA))
     {
         n <- sys.nframe()
         while (n > 1) {
@@ -690,9 +690,9 @@ loadingNamespaceInfo <- function() {
         }
 #        notFound
         stop(notFound)
-	}
+    }
 #    dynGet("__LoadingNamespaceInfo__", stop("not loading a namespace"))
-	dynGet("__LoadingNamespaceInfo__", "not loading a namespace")
+    dynGet("__LoadingNamespaceInfo__", "not loading a namespace")
 }
 
 topenv <- function(envir = parent.frame(),
@@ -771,7 +771,7 @@ asNamespace <- function(ns, base.OK = TRUE) {
         ns <- getNamespace(ns)
     if (! isNamespace(ns)) {
         stop("not a namespace")
-	}
+    }
     else if (! base.OK && isBaseNamespace(ns))
         stop("operation not allowed on base namespace")
     else ns
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/R/sample.R b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/R/sample.R
index bda0c1c030..d9b606f4c7 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/R/sample.R
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/R/sample.R
@@ -19,11 +19,11 @@
 sample <- function(x, size, replace = FALSE, prob = NULL)
 {
     if(length(x) == 1L && is.numeric(x) && x >= 1) {
-	if(missing(size)) size <- x
-	sample.int(x, size, replace, prob)
+    if(missing(size)) size <- x
+    sample.int(x, size, replace, prob)
     } else {
-	if(missing(size)) size <- length(x)
-	x[sample.int(length(x), size, replace, prob)]
+    if(missing(size)) size <- length(x)
+    x[sample.int(length(x), size, replace, prob)]
     }
 }
 
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 cd6aaf90d7..465f822a28 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
@@ -25,7 +25,9 @@ package com.oracle.truffle.r.runtime;
 import java.util.*;
 
 import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
+import com.oracle.truffle.api.*;
 import com.oracle.truffle.api.frame.*;
+import com.oracle.truffle.api.instrument.*;
 import com.oracle.truffle.r.runtime.REnvironment.*;
 import com.oracle.truffle.r.runtime.data.*;
 
@@ -34,11 +36,11 @@ import com.oracle.truffle.r.runtime.data.*;
  * implementation of the runtime.
  *
  * The context provides two sub-interfaces {@link ConsoleHandler} and {@link Engine}that are
- * (typically) implemented elsewhere, but accessed through {@link #getConsoleHandler()} and {@loink
- * #getEngine()}, respectively.
+ * (typically) implemented elsewhere, and accessed through {@link #getConsoleHandler()} and
+ * {@link #getEngine()}, respectively.
  *
  */
-public final class RContext {
+public final class RContext extends ExecutionContext {
 
     public static final int CONSOLE_WIDTH = 80;
 
@@ -98,13 +100,13 @@ public final class RContext {
          *
          * @return elapsed time in nanosecs.
          */
-        public long elapsedTimeInNanos();
+        long elapsedTimeInNanos();
 
         /**
          * Return user and system times for any spawned child processes in nanosecs, < 0 means not
          * available (Windows).
          */
-        public long[] childTimesInNanos();
+        long[] childTimesInNanos();
 
         public static class ParseException extends Exception {
             private static final long serialVersionUID = 1L;
@@ -121,19 +123,19 @@ public final class RContext {
          * @param frame for evaluating any associated R code
          * @param envForFrame the namespace environment associated with the package.
          */
-        public void loadDefaultPackage(String name, VirtualFrame frame, REnvironment envForFrame);
+        void loadDefaultPackage(String name, VirtualFrame frame, REnvironment envForFrame);
 
         /**
          * Return the {@link RFunction} for the builtin {@code name}.
          *
          */
-        public RFunction lookupBuiltin(String name);
+        RFunction lookupBuiltin(String name);
 
         /**
          * Parse an R expression and return an {@link RExpression} object representing the Truffle
          * ASTs for the components.
          */
-        public RExpression parse(String rscript) throws ParseException;
+        RExpression parse(String rscript) throws ParseException;
 
         /**
          * Parse and evaluate {@code rscript} in {@code frame}. {@code printResult == true}, the
@@ -142,14 +144,14 @@ public final class RContext {
          * @param envForFrame the environment that {@code frame} is bound to.
          * @return the object returned by the evaluation or {@code null} if an error occurred.
          */
-        public Object parseAndEval(String rscript, VirtualFrame frame, REnvironment envForFrame, boolean printResult);
+        Object parseAndEval(String rscript, VirtualFrame frame, REnvironment envForFrame, boolean printResult);
 
         /**
          *
          * This is intended for use by the unit test environment, where a "fresh" global environment
          * is desired for each evaluation.
          */
-        public Object parseAndEvalTest(String rscript, boolean printResult);
+        Object parseAndEvalTest(String rscript, boolean printResult);
 
         /**
          * Support for the {@code eval} builtin using an {@link RExpression}.
@@ -157,7 +159,7 @@ public final class RContext {
          * @param function identifies the eval variant, e.g. {@code local}, {@code eval},
          *            {@code evalq} being invoked.
          */
-        public Object eval(RFunction function, RExpression expr, REnvironment envir, REnvironment enclos) throws PutException;
+        Object eval(RFunction function, RExpression expr, REnvironment envir, REnvironment enclos) throws PutException;
 
         /**
          * Support for the {@code eval} builtin. This is tricky because the {@link Frame} "f"
@@ -168,13 +170,13 @@ public final class RContext {
          * @param function the actual function that invoked the "eval", e.g. {@code eval},
          *            {@code evalq} , {@code local}.
          */
-        public Object eval(RFunction function, RLanguage expr, REnvironment envir, REnvironment enclos) throws PutException;
+        Object eval(RFunction function, RLanguage expr, REnvironment envir, REnvironment enclos) throws PutException;
 
         /**
          * Evaluate a promise in the given frame (for a builtin, where we can use the
          * {@link VirtualFrame}) of the caller directly).
          */
-        public Object evalPromise(RPromise expr, VirtualFrame frame) throws RError;
+        Object evalPromise(RPromise expr, VirtualFrame frame) throws RError;
 
     }
 
@@ -276,4 +278,14 @@ public final class RContext {
         }
         evalWarnings.add(s);
     }
+
+    @Override
+    public String getLanguageShortName() {
+        return "R";
+    }
+
+    @Override
+    protected void setSourceCallback(SourceCallback sourceCallback) {
+        // TODO Auto-generated method stub
+    }
 }
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RRuntime.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RRuntime.java
index bcf04a2e33..4e8b7b308e 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RRuntime.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RRuntime.java
@@ -105,7 +105,7 @@ public class RRuntime {
 
     public static final String NAMES_ATTR_KEY = new String("names");
     public static final String NAMES_ATTR_EMPTY_VALUE = "";
-    
+
     public static final String LEVELS_ATTR_KEY = new String("levels");
     public static final String LEVELS_ATTR_EMPTY_VALUE = "";
 
diff --git a/com.oracle.truffle.r.shell/src/com/oracle/truffle/r/shell/RCommand.java b/com.oracle.truffle.r.shell/src/com/oracle/truffle/r/shell/RCommand.java
index 94dc70c9e9..eb484ab105 100644
--- a/com.oracle.truffle.r.shell/src/com/oracle/truffle/r/shell/RCommand.java
+++ b/com.oracle.truffle.r.shell/src/com/oracle/truffle/r/shell/RCommand.java
@@ -28,6 +28,7 @@ import java.io.*;
 import java.util.*;
 
 import com.oracle.truffle.api.frame.*;
+import com.oracle.truffle.r.engine.*;
 import com.oracle.truffle.r.runtime.*;
 
 import jline.console.*;
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/generate/FastRSession.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/generate/FastRSession.java
index 83a89be716..d38518f577 100644
--- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/generate/FastRSession.java
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/generate/FastRSession.java
@@ -22,8 +22,8 @@
  */
 package com.oracle.truffle.r.test.generate;
 
+import com.oracle.truffle.r.engine.*;
 import com.oracle.truffle.r.runtime.*;
-import com.oracle.truffle.r.shell.*;
 
 public class FastRSession implements RSession {
 
diff --git a/mx.fastr/projects b/mx.fastr/projects
index ed5d4ecfb3..a7d524fb0b 100644
--- a/mx.fastr/projects
+++ b/mx.fastr/projects
@@ -98,9 +98,16 @@ project@com.oracle.truffle.r.test@javaCompliance=1.8
 project@com.oracle.truffle.r.test@annotationProcessors=com.oracle.truffle.r.test.ignore.processor
 project@com.oracle.truffle.r.test@workingSets=Truffle,FastR,Test
 
+# com.oracle.truffle.r.engine
+project@com.oracle.truffle.r.engine@sourceDirs=src
+project@com.oracle.truffle.r.engine@dependencies=com.oracle.truffle.r.nodes
+project@com.oracle.truffle.r.engine@checkstyle=com.oracle.truffle.r.runtime
+project@com.oracle.truffle.r.engine@javaCompliance=1.8
+project@com.oracle.truffle.r.engine@workingSets=Truffle,FastR
+
 # com.oracle.truffle.r.shell
 project@com.oracle.truffle.r.shell@sourceDirs=src
-project@com.oracle.truffle.r.shell@dependencies=com.oracle.truffle.r.nodes,JLINE
+project@com.oracle.truffle.r.shell@dependencies=com.oracle.truffle.r.engine,JLINE
 project@com.oracle.truffle.r.shell@checkstyle=com.oracle.truffle.r.runtime
 project@com.oracle.truffle.r.shell@javaCompliance=1.8
 project@com.oracle.truffle.r.shell@workingSets=Truffle,FastR
-- 
GitLab