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 5b82001fe056f196fd7bb86d9e733580ea4003ee..04db0897276c01b27b72bd1e0e85422e4b90892b 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 @@ -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); } } diff --git a/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/ConsoleHandler.java b/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/ConsoleHandler.java index 9d326212d263e8b5eb47d2de60302778dd80f463..895f1ededed1bb1714461ffc3d1dc1b136657fe2 100644 --- a/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/ConsoleHandler.java +++ b/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/ConsoleHandler.java @@ -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 } diff --git a/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/JLineConsoleCompleter.java b/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/JLineConsoleCompleter.java index cefa1ace252c35cb2d02e23aeeb936393b37e590..b1c670fe8adcf88b98cd7d12d75f60dadda3c8e0 100644 --- a/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/JLineConsoleCompleter.java +++ b/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/JLineConsoleCompleter.java @@ -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; } diff --git a/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/JLineConsoleHandler.java b/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/JLineConsoleHandler.java index 0a8350df2667b57946531e5a8c9208202e8c5bc8..1f0ad295e3d6b27e00f45d6c7f478540ea00d217 100644 --- a/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/JLineConsoleHandler.java +++ b/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/JLineConsoleHandler.java @@ -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) { diff --git a/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/RCommand.java b/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/RCommand.java index 7fa7abfe28a5f2d96d07cfd00837dbe8520cec33..ef547b6a2b1d87a0fe0c05df2d2f2511daefb993 100644 --- a/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/RCommand.java +++ b/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/RCommand.java @@ -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"); } } } diff --git a/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/RscriptCommand.java b/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/RscriptCommand.java index f8373da95848535ccaff51c0dfd611ba48c5cac2..a6d4faa44eb3e114571de92d16859c32a2e0b14f 100644 --- a/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/RscriptCommand.java +++ b/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/RscriptCommand.java @@ -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); } } diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/ContextInfo.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/ContextInfo.java index 8e140b8338a4419b264686ef865a38898bbcf823..57d153738cf5a888930a555c3b17e7592f2c8953 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/ContextInfo.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/ContextInfo.java @@ -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()) { diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/engine/shell/TestJLineConsoleCompleter.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/engine/shell/TestJLineConsoleCompleter.java index 3f3c94aad6186d5b67f260652079fc51ce2fe12d..17dd5fdd79e9591053246ff48a71d1f24342945d 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/engine/shell/TestJLineConsoleCompleter.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/engine/shell/TestJLineConsoleCompleter.java @@ -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); } diff --git a/mx.fastr/suite.py b/mx.fastr/suite.py index f4a2ad667a7fe96b148f986725a6896d3fd9e788..5ba7bb64939a551747124f257ea390143164d8dd 100644 --- a/mx.fastr/suite.py +++ b/mx.fastr/suite.py @@ -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"},