Skip to content
Snippets Groups Projects
Commit ccaf4e42 authored by Lukas Stadler's avatar Lukas Stadler
Browse files

use Context instead of PolyglotContext

parent bd6972c7
No related branches found
No related tags found
No related merge requests found
Showing
with 36 additions and 49 deletions
......@@ -22,9 +22,9 @@
*/
package com.oracle.truffle.r.engine.shell;
import org.graalvm.polyglot.Context.Builder;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Engine;
import org.graalvm.polyglot.PolyglotContext;
import org.graalvm.polyglot.PolyglotContext.Builder;
import com.oracle.truffle.api.vm.PolyglotEngine;
import com.oracle.truffle.r.launcher.ConsoleHandler;
......@@ -65,9 +65,8 @@ import com.oracle.truffle.r.runtime.context.RContext.ContextKind;
public class REmbedded {
private static ConsoleHandler consoleHandler;
private static ContextInfo info;
private static Engine engine;
private static PolyglotContext context;
private static Context context;
/**
* Creates the {@link Engine} and initializes it. Called from native code when FastR is
......@@ -77,20 +76,15 @@ public class REmbedded {
*/
private static void initializeR(String[] args) {
assert engine == null;
assert info == null;
RContext.setEmbedded();
RCmdOptions options = RCmdOptions.parseArguments(RCmdOptions.Client.R, args, false);
RStartParams rsp = new RStartParams(options, true);
info = ContextInfo.create(rsp, null, ContextKind.SHARE_NOTHING, null, System.in, System.out, System.err);
engine = info.createEngine();
context = engine.createPolyglotContext();
engine = Engine.create();
consoleHandler = RCommand.createConsoleHandler(options, true, System.in, System.out);
Builder builder = engine.newPolyglotContextBuilder();
try (PolyglotContext cntx = builder.setArguments("R", options.getArguments()).setIn(consoleHandler.createInputStream()).setOut(System.out).setErr(System.err).build()) {
Builder builder = Context.newBuilder().engine(engine);
try (Context cntx = builder.arguments("R", options.getArguments()).in(consoleHandler.createInputStream()).out(System.out).err(System.err).build()) {
context = cntx;
consoleHandler.setPolyglotContext(context);
consoleHandler.setContext(context);
context.eval("R", INIT);
}
}
......
......@@ -26,7 +26,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import org.graalvm.polyglot.PolyglotContext;
import org.graalvm.polyglot.Context;
/**
* The interface to a source of input/output for the context, which may have different
......@@ -44,7 +44,7 @@ public abstract class ConsoleHandler {
*/
public abstract void setPrompt(String prompt);
public void setPolyglotContext(@SuppressWarnings("unused") PolyglotContext context) {
public void setContext(@SuppressWarnings("unused") Context context) {
// ignore by default
}
......
......@@ -26,7 +26,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.graalvm.polyglot.PolyglotContext;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Value;
import jline.console.completer.Completer;
......@@ -34,13 +34,13 @@ import jline.console.completer.Completer;
public class JLineConsoleCompleter implements Completer {
private static boolean isTesting = false;
private final PolyglotContext context;
private final Context context;
public static void testingMode() {
isTesting = true;
}
public JLineConsoleCompleter(PolyglotContext context) {
public JLineConsoleCompleter(Context context) {
this.context = context;
}
......
......@@ -26,7 +26,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.graalvm.polyglot.PolyglotContext;
import org.graalvm.polyglot.Context;
import jline.console.ConsoleReader;
import jline.console.UserInterruptException;
......@@ -53,7 +53,7 @@ public class JLineConsoleHandler extends ConsoleHandler {
}
@Override
public void setPolyglotContext(PolyglotContext context) {
public void setContext(Context context) {
console.addCompleter(new JLineConsoleCompleter(context));
CompletionHandler completionHandler = console.getCompletionHandler();
if (completionHandler instanceof CandidateListCompletionHandler) {
......
......@@ -30,9 +30,9 @@ import java.io.OutputStream;
import java.nio.file.Files;
import java.util.List;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Context.Builder;
import org.graalvm.polyglot.Engine;
import org.graalvm.polyglot.PolyglotContext;
import org.graalvm.polyglot.PolyglotContext.Builder;
import org.graalvm.polyglot.PolyglotException;
import org.graalvm.polyglot.Source;
......@@ -97,9 +97,9 @@ public class RCommand {
try (Engine engine = Engine.create()) {
assert env == null : "re-enable setting environments";
ConsoleHandler consoleHandler = createConsoleHandler(options, false, inStream, outStream);
Builder builder = engine.newPolyglotContextBuilder();
try (PolyglotContext context = builder.setArguments("R", options.getArguments()).setIn(consoleHandler.createInputStream()).setOut(outStream).setErr(errStream).build()) {
consoleHandler.setPolyglotContext(context);
Builder builder = Context.newBuilder().engine(engine);
try (Context context = builder.arguments("R", options.getArguments()).in(consoleHandler.createInputStream()).out(outStream).err(errStream).build()) {
consoleHandler.setContext(context);
StartupTiming.timestamp("VM Created");
StartupTiming.printSummary();
return readEvalPrint(context, consoleHandler);
......@@ -180,7 +180,7 @@ public class RCommand {
* In case 2, we must implicitly execute a {@code quit("default, 0L, TRUE} command before
* exiting. So,in either case, we never return.
*/
public static int readEvalPrint(PolyglotContext context, ConsoleHandler consoleHandler) {
public static int readEvalPrint(Context context, ConsoleHandler consoleHandler) {
int lastStatus = 0;
try {
while (true) { // processing inputs
......@@ -202,7 +202,7 @@ public class RCommand {
while (true) { // processing subsequent lines while input is incomplete
lastStatus = 0;
try {
context.eval("R", Source.newBuilder(sb.toString()).interactive().build());
context.eval(Source.newBuilder("R", sb.toString(), "<REPL>").interactive(true).buildLiteral());
} catch (PolyglotException e) {
if (continuePrompt == null) {
continuePrompt = doEcho ? getContinuePrompt(context) : "";
......@@ -222,11 +222,10 @@ public class RCommand {
// usually from quit
throw new ExitException(e.getExitStatus());
} else if (e.isHostException()) {
// We continue the repl even though the system may be broken
// we continue the repl even though the system may be broken
lastStatus = 1;
} else if (e.isGuestException()) {
// drop through to continue REPL and remember last eval was an
// error
// drop through to continue REPL and remember last eval was an error
lastStatus = 1;
}
}
......@@ -260,7 +259,7 @@ public class RCommand {
}
}
private static boolean doEcho(PolyglotContext context) {
private static boolean doEcho(Context context) {
try {
return context.eval("R", GET_ECHO).asBoolean();
} catch (PolyglotException e) {
......@@ -271,25 +270,25 @@ public class RCommand {
}
}
private static String getPrompt(PolyglotContext context) {
private static String getPrompt(Context context) {
try {
return context.eval("R", GET_PROMPT).asString();
} catch (PolyglotException e) {
if (e.isExit()) {
throw new ExitException(e.getExitStatus());
}
throw fatal(e, "error while retrieving echo");
throw fatal(e, "error while retrieving prompt");
}
}
private static String getContinuePrompt(PolyglotContext context) {
private static String getContinuePrompt(Context context) {
try {
return context.eval("R", GET_CONTINUE_PROMPT).asString();
} catch (PolyglotException e) {
if (e.isExit()) {
throw new ExitException(e.getExitStatus());
}
throw fatal(e, "error while retrieving echo");
throw fatal(e, "error while retrieving continue prompt");
}
}
}
......@@ -26,8 +26,8 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Engine;
import org.graalvm.polyglot.PolyglotContext;
import com.oracle.truffle.r.launcher.RCmdOptions.RCmdOption;
......@@ -111,9 +111,9 @@ public class RscriptCommand {
try (Engine engine = Engine.create()) {
ConsoleHandler consoleHandler = RCommand.createConsoleHandler(options, false, inStream, outStream);
try (PolyglotContext context = engine.newPolyglotContextBuilder().setArguments("R",
options.getArguments()).setIn(consoleHandler.createInputStream()).setOut(outStream).setErr(errStream).build()) {
consoleHandler.setPolyglotContext(context);
try (Context context = Context.newBuilder().engine(engine).arguments("R",
options.getArguments()).in(consoleHandler.createInputStream()).out(outStream).err(errStream).build()) {
consoleHandler.setContext(context);
return RCommand.readEvalPrint(context, consoleHandler);
}
}
......
......@@ -109,10 +109,6 @@ public final class ContextInfo {
multiSlotInds.set(0); // to account for primordial context
}
public org.graalvm.polyglot.Engine createEngine() {
return org.graalvm.polyglot.Engine.newBuilder().setIn(stdin).setOut(stdout).setErr(stderr).build();
}
public PolyglotEngine createVM() {
Builder builder = PolyglotEngine.newBuilder();
if (startParams.isInteractive()) {
......
......@@ -28,9 +28,8 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
import java.util.LinkedList;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Engine;
import org.graalvm.polyglot.PolyglotContext;
import org.graalvm.polyglot.PolyglotContext.Builder;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
......@@ -41,15 +40,14 @@ import com.oracle.truffle.r.launcher.JLineConsoleCompleter;
public class TestJLineConsoleCompleter {
private Engine engine;
private PolyglotContext context;
private Context context;
private JLineConsoleCompleter consoleCompleter;
@Before
public void before() {
JLineConsoleCompleter.testingMode();
engine = Engine.create();
Builder builder = engine.newPolyglotContextBuilder();
context = builder.build();
context = Context.newBuilder().engine(engine).build();
consoleCompleter = new JLineConsoleCompleter(context);
}
......
......@@ -29,7 +29,7 @@ suite = {
{
"name" : "truffle",
"subdir" : True,
"version" : "8a073fbc3a52b6b023023c5b33773ce8ef3ad939",
"version" : "90f29df947c052acb20be84e4278c8e522d0fa63",
"urls" : [
{"url" : "https://github.com/graalvm/graal", "kind" : "git"},
{"url" : "https://curio.ssw.jku.at/nexus/content/repositories/snapshots", "kind" : "binary"},
......
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