diff --git a/.gitignore b/.gitignore index d39a0a4a07f33856d938f8873ce7daafa0d520c1..4e690d74e099bcaadeb02937d049ac0b1151dad2 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ /com.oracle.truffle.r.test.native/packages/*/lib/* /com.oracle.truffle.r.test/rpackages/testrlibs_user /com.oracle.truffle.r.test.native/urand/lib/liburand.so +/com.oracle.truffle.r.release/lib/ +/com.oracle.truffle.r.release/library/ /DEPARSE_ERROR /Rpkgsource/* /install.cran.logs/ 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 03697c9230d1f732c49bc450e890a0164a75b0a3..38fb76d40693a287fed4cf21da1f45e83fb4c0b7 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 @@ -299,17 +299,29 @@ final class REngine implements Engine, Engine.Timings { @Override public CallTarget parseToCallTarget(Source source) throws ParseException { List<RSyntaxNode> statements = parseImpl(null, source); - return Truffle.getRuntime().createCallTarget(new PolyglotEngineRootNode(statements)); + return Truffle.getRuntime().createCallTarget(new PolyglotEngineRootNode(statements, createSourceSection(statements))); + } + + private static SourceSection createSourceSection(List<RSyntaxNode> statements) { + // All statements come from the same "Source" + if (statements.size() == 1) { + return statements.get(0).getSourceSection(); + } else { + Source source = statements.get(0).getSourceSection().getSource(); + return source.createSection(0, statements.get(statements.size() - 1).getSourceSection().getCharEndIndex()); + } } private final class PolyglotEngineRootNode extends RootNode { private final List<RSyntaxNode> statements; + private final boolean printResult; @Child private Node findContext = TruffleRLanguage.INSTANCE.actuallyCreateFindContextNode(); - PolyglotEngineRootNode(List<RSyntaxNode> statements) { - super(TruffleRLanguage.class, SourceSection.createUnavailable("repl", RSource.Internal.REPL_WRAPPER.string), new FrameDescriptor()); + PolyglotEngineRootNode(List<RSyntaxNode> statements, SourceSection sourceSection) { + super(TruffleRLanguage.class, sourceSection, new FrameDescriptor()); + this.printResult = !sourceSection.getSource().getName().equals(RSource.Internal.INIT_EMBEDDED.string); this.statements = statements; } @@ -327,7 +339,7 @@ final class REngine implements Engine, Engine.Timings { Object lastValue = RNull.instance; for (int i = 0; i < statements.size(); i++) { RSyntaxNode node = statements.get(i); - RootCallTarget callTarget = doMakeCallTarget(node.asRNode(), RSource.Internal.REPL_WRAPPER.string, true, true); + RootCallTarget callTarget = doMakeCallTarget(node.asRNode(), RSource.Internal.REPL_WRAPPER.string, printResult, true); lastValue = callTarget.call(newContext.stateREnvironment.getGlobalFrame()); } return lastValue; diff --git a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/shell/REmbedded.java b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/shell/REmbedded.java index 87bb3136b5a4622e005dd1dac3b237a468f268cc..0e9fa5f656cbaadb937bb5ca2a67629e38c2fd98 100644 --- a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/shell/REmbedded.java +++ b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/shell/REmbedded.java @@ -27,6 +27,7 @@ import com.oracle.truffle.api.vm.PolyglotEngine; import com.oracle.truffle.r.runtime.RCmdOptions; import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.RSource; +import com.oracle.truffle.r.runtime.RSource.Internal; import com.oracle.truffle.r.runtime.RStartParams; import com.oracle.truffle.r.runtime.Utils; import com.oracle.truffle.r.runtime.context.ContextInfo; @@ -73,7 +74,12 @@ public class REmbedded { return vm; } - private static final Source INIT = RSource.fromTextInternal("invisible(1)", RSource.Internal.GET_ECHO); + /** + * N.B. This expression cannot contain any R functions, e.g. "invisible", because at the time it + * is evaluated the R builtins have not been installed, see {@link #initializeR}. The + * suppression of printing is handled a a special case based on {@link Internal#INIT_EMBEDDED}. + */ + private static final Source INIT = RSource.fromTextInternal("1", RSource.Internal.INIT_EMBEDDED); /** * GnuR distinguishes {@code setup_Rmainloop} and {@code run_Rmainloop}. Currently we don't have diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RSource.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RSource.java index d02be78943a02cc152563c7394bd78b1fd7fb80f..6d8b059ca5a9dc13a51111012b40169ac3ffeb1d 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RSource.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RSource.java @@ -74,7 +74,8 @@ public class RSource { DEPARSE_ERROR("<package_deparse_error>"), LAPPLY("<lapply>"), R_PARSEVECTOR("<R_ParseVector>"), - PAIRLIST_DEPARSE("<pairlist deparse>"); + PAIRLIST_DEPARSE("<pairlist deparse>"), + INIT_EMBEDDED("<init embedded>"); public final String string;