Skip to content
Snippets Groups Projects
Commit 5f451039 authored by Mick Jordan's avatar Mick Jordan
Browse files

Merge pull request #303 in G/fastr from ~MICK.JORDAN_ORACLE.COM/fastr:bugfix/embed-init to master

* commit '00136165':
  add comment
  fix regression in embedded mode polyglot init
parents fc4044fd 00136165
No related branches found
No related tags found
No related merge requests found
......@@ -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/
......
......@@ -299,17 +299,30 @@ 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());
// can't print if initializing the system in embedded mode (no builtins yet)
this.printResult = !sourceSection.getSource().getName().equals(RSource.Internal.INIT_EMBEDDED.string);
this.statements = statements;
}
......@@ -327,7 +340,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;
......
......@@ -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
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment