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 86a08332003f12f1cfdd3aebc4f9ca78e44050b8..6dd582b8741acf34d388e9cbaa54ff9674cf232e 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 @@ -390,7 +390,7 @@ final class REngine implements Engine, Engine.Timings { break; } sb.append(input); - Source src = Source.newBuilder(sb.toString()).mimeType(RRuntime.R_APP_MIME).name(file + "#" + startLine + "-" + lineIndex).uri(uri).build(); + Source src = Source.newBuilder(sb.toString()).language(RRuntime.R_LANGUAGE_ID).name(file + "#" + startLine + "-" + lineIndex).uri(uri).build(); lineIndex++; List<RSyntaxNode> currentStmts = null; try { diff --git a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/TruffleRLanguageImpl.java b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/TruffleRLanguageImpl.java index 50633e95daf86e2f7f48ce313b85859912660432..17940abb3e8e8b3c06301b58525ef24f2a241eee 100644 --- a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/TruffleRLanguageImpl.java +++ b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/TruffleRLanguageImpl.java @@ -94,8 +94,6 @@ public final class TruffleRLanguageImpl extends TruffleRLanguage { private static boolean systemInitialized; - public static final String MIME = RRuntime.R_APP_MIME; - @Override protected boolean isObjectOfLanguage(Object object) { return object instanceof RTypedValue; diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_Context.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_Context.java index d1e3aba0258a5e33e5114be04706cb544ae85252..1f1a0ddfc0e9c8aab6fa11e7c1bd2d560a2b31a8 100644 --- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_Context.java +++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_Context.java @@ -308,7 +308,7 @@ final class TruffleNFI_Context extends RFFIContext { // new thread, initialize properly assert defaultLibrary == null && rlibDLLInfo == null; rlibDLLInfo = DLL.findLibraryContainingSymbol(context, "dot_call0"); - defaultLibrary = (TruffleObject) RContext.getInstance().getEnv().parse(Source.newBuilder("default").name("(load default)").mimeType("application/x-native").build()).call(); + defaultLibrary = (TruffleObject) RContext.getInstance().getEnv().parse(Source.newBuilder("default").name("(load default)").language("native").build()).call(); initCallbacks(context); break; case SHARE_PARENT_RO: diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_DLL.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_DLL.java index b55ff1ec00e3cc798165519cef1e6ae58b0e5c41..c9922c8ffaec3e72d14ea313a7138bf6c8187e7a 100644 --- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_DLL.java +++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_DLL.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -57,7 +57,7 @@ public class TruffleNFI_DLL implements DLLRFFI { public Object execute(String path, boolean local, boolean now) { String libName = DLL.libName(path); Env env = RContext.getInstance().getEnv(); - TruffleObject libHandle = (TruffleObject) env.parse(Source.newBuilder(prepareLibraryOpen(path, local, now)).name(path).mimeType("application/x-native").build()).call(); + TruffleObject libHandle = (TruffleObject) env.parse(Source.newBuilder(prepareLibraryOpen(path, local, now)).name(path).language("native").build()).call(); return new NFIHandle(libName, libHandle); } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Parse.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Parse.java index b35736e7e3754999eb003298b92533a89245a6ae..0fb4a4a351ae3e20d2ef3dd7a3301bea8e1f9513 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Parse.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Parse.java @@ -223,12 +223,12 @@ public abstract class Parse extends RBuiltinNode.Arg6 { assert result != null : "Source created from environment should not be null"; return result; } else { - return Source.newBuilder(coalescedLines).name("<parse>").mimeType(RRuntime.R_APP_MIME).build(); + return Source.newBuilder(coalescedLines).name("<parse>").language(RRuntime.R_LANGUAGE_ID).build(); } } else { String srcFileText = RRuntime.asString(srcFile); if (srcFileText.equals("<text>")) { - return Source.newBuilder(coalescedLines).name("<parse>").mimeType(RRuntime.R_APP_MIME).build(); + return Source.newBuilder(coalescedLines).name("<parse>").language(RRuntime.R_LANGUAGE_ID).build(); } else { return createFileSource(ConnectionSupport.removeFileURLPrefix(srcFileText), coalescedLines, false); } @@ -247,7 +247,7 @@ public abstract class Parse extends RBuiltinNode.Arg6 { return RSource.fromFileName(chars, path, internal); } catch (URISyntaxException e) { // Note: to be compatible with GnuR we construct Source even with a malformed path - Source.Builder<RuntimeException, RuntimeException, RuntimeException> builder = Source.newBuilder(chars).name(path).mimeType(RRuntime.R_APP_MIME); + Source.Builder<RuntimeException, RuntimeException, RuntimeException> builder = Source.newBuilder(chars).name(path).language(RRuntime.R_LANGUAGE_ID); if (internal) { builder.internal(); } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Rd/eval.polyglot.Rd b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Rd/eval.polyglot.Rd new file mode 100644 index 0000000000000000000000000000000000000000..4de19f8e5533f25c37a690e04ebf951ba852ab71 --- /dev/null +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Rd/eval.polyglot.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fastrInteropt.R +\name{eval.polyglot} +\alias{eval.polyglot} +\title{Evaluates expressions in the language with the given id. Either the source text or path to a text file are accepted.} +\usage{ +eval.polyglot(languageId, source, path) +} +\arguments{ +\item{languageId}{character string. Determines the language in which to evaluate the source.} + +\item{source}{character string. The text source which has to be evaluated.} + +\item{path}{character string. Path to a source file.} +} +\description{ +Evaluates expressions in the language with the given id. Either the source text or path to a text file are accepted. +} +\examples{ +eval.polyglot("R", "42") +} diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Rd/export.Rd b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Rd/export.Rd new file mode 100644 index 0000000000000000000000000000000000000000..594855dffbaeb341764ae34874c0b95265cccee8 --- /dev/null +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Rd/export.Rd @@ -0,0 +1,32 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fastrInteropt.R +\name{export} +\alias{export} +\title{Explicitly exports a polyglot symbol. Exporting a symbol with a NULL value will remove the +symbol from the polyglot object. +The exported symbol value can either be a polyglot object (e.g. a native +object from another language) to support interoperability between languages, +or a R object.} +\usage{ +export(symbolName, value) +} +\arguments{ +\item{symbolName}{character string. The name with which the symbol should be exported into the polyglot +scope.} + +\item{value}{The value to export for} +} +\description{ +Explicitly exports a polyglot symbol. Exporting a symbol with a NULL value will remove the +symbol from the polyglot object. +The exported symbol value can either be a polyglot object (e.g. a native +object from another language) to support interoperability between languages, +or a R object. +} +\examples{ +export('foo', 'foo') +export('foo', new.env()) +} +\seealso{ +\code{\link{import}} +} diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Rd/import.Rd b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Rd/import.Rd new file mode 100644 index 0000000000000000000000000000000000000000..5a69aee96ea285d7ccf9d4229b6323f5fe447867 --- /dev/null +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Rd/import.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fastrInteropt.R +\name{import} +\alias{import} +\title{Explicitly imports a polyglot symbol. Reading a symbol that does not exist will return NULL. +The returned symbol value can either be a polyglot object (e.g. a native +object from the other language) to support interoperability between languages, +or a value converted into a native R type - e.g. integer, double, logical, character, etc.} +\usage{ +import(symbolName) +} +\arguments{ +\item{symbolName}{character string. The name of the symbol to search for.} +} +\description{ +Explicitly imports a polyglot symbol. Reading a symbol that does not exist will return NULL. +The returned symbol value can either be a polyglot object (e.g. a native +object from the other language) to support interoperability between languages, +or a value converted into a native R type - e.g. integer, double, logical, character, etc. +} +\examples{ +import('foo') +} +\seealso{ +\code{\link{export}} +} diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRInterop.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRInterop.java index 1fa64d23cdc443ce7626d8e2bf09cd68d712c5cd..9d1335b53a9b2ff0232780f5ddb35de43b2ad7c6 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRInterop.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRInterop.java @@ -116,12 +116,12 @@ public class FastRInterop { isTesting = true; } - @RBuiltin(name = "eval.polyglot", visibility = CUSTOM, kind = PRIMITIVE, parameterNames = {"mimeType", "source", "path"}, behavior = COMPLEX) + @RBuiltin(name = "eval.polyglot", visibility = CUSTOM, kind = PRIMITIVE, parameterNames = {"languageId", "source", "path"}, behavior = COMPLEX) public abstract static class Eval extends RBuiltinNode.Arg3 { static { Casts casts = new Casts(Eval.class); - casts.arg("mimeType").allowMissing().mustBe(stringValue()).asStringVector().mustBe(singleElement()).findFirst(); + casts.arg("languageId").allowMissing().mustBe(stringValue()).asStringVector().mustBe(singleElement()).findFirst(); casts.arg("source").allowMissing().mustBe(stringValue()).asStringVector().mustBe(singleElement()).findFirst(); casts.arg("path").allowMissing().mustBe(stringValue()).asStringVector().mustBe(singleElement()).findFirst(); } @@ -129,16 +129,16 @@ public class FastRInterop { @Child private SetVisibilityNode setVisibilityNode = SetVisibilityNode.create(); @Child private Foreign2R foreign2rNode = Foreign2R.create(); - protected DirectCallNode createCall(String mimeType, String source) { - return Truffle.getRuntime().createDirectCallNode(parse(mimeType, source)); + protected DirectCallNode createCall(String languageId, String source) { + return Truffle.getRuntime().createDirectCallNode(parse(languageId, source)); } @SuppressWarnings("unused") - @Specialization(guards = {"cachedMimeType != null", "cachedMimeType.equals(mimeType)", "cachedSource != null", "cachedSource.equals(source)"}) - protected Object evalCached(VirtualFrame frame, String mimeType, String source, RMissing path, - @Cached("mimeType") String cachedMimeType, + @Specialization(guards = {"cachedLanguageId != null", "cachedLanguageId.equals(languageId)", "cachedSource != null", "cachedSource.equals(source)"}) + protected Object evalCached(VirtualFrame frame, String languageId, String source, RMissing path, + @Cached("languageId") String cachedLanguageId, @Cached("source") String cachedSource, - @Cached("createCall(mimeType, source)") DirectCallNode call) { + @Cached("createCall(languageId, source)") DirectCallNode call) { try { return foreign2rNode.execute(call.call(EMPTY_OBJECT_ARRAY)); } finally { @@ -147,29 +147,29 @@ public class FastRInterop { } @Specialization(replaces = "evalCached") - protected Object eval(VirtualFrame frame, String mimeType, String source, @SuppressWarnings("unused") RMissing path) { + protected Object eval(VirtualFrame frame, String languageId, String source, @SuppressWarnings("unused") RMissing path) { try { - return foreign2rNode.execute(parseAndCall(source, mimeType)); + return foreign2rNode.execute(parseAndCall(source, languageId)); } finally { setVisibilityNode.execute(frame, true); } } @TruffleBoundary - private Object parseAndCall(String source, String mimeType) { - return parse(mimeType, source).call(); + private Object parseAndCall(String source, String languageId) { + return parse(languageId, source).call(); } @Specialization() @TruffleBoundary - protected Object eval(@SuppressWarnings("unused") RMissing mimeType, @SuppressWarnings("unused") String source, @SuppressWarnings("unused") RMissing path) { - throw RError.error(this, RError.Message.INVALID_ARG, "mimeType"); + protected Object eval(@SuppressWarnings("unused") RMissing languageId, @SuppressWarnings("unused") String source, @SuppressWarnings("unused") RMissing path) { + throw RError.error(this, RError.Message.INVALID_ARG, "languageId"); } - protected CallTarget parse(String mimeType, String source) { + protected CallTarget parse(String languageId, String source) { CompilerAsserts.neverPartOfCompilation(); - Source sourceObject = RSource.fromTextInternalInvisible(source, RSource.Internal.EVAL_WRAPPER, mimeType); + Source sourceObject = RSource.fromTextInternalInvisible(source, RSource.Internal.EVAL_WRAPPER, languageId); try { return RContext.getInstance().getEnv().parse(sourceObject); } catch (Throwable t) { @@ -178,25 +178,25 @@ public class FastRInterop { } @Specialization - protected Object eval(VirtualFrame frame, String mimeType, @SuppressWarnings("unused") String source, String path) { + protected Object eval(VirtualFrame frame, String languageId, @SuppressWarnings("unused") String source, String path) { try { - return foreign2rNode.execute(parseFileAndCall(path, mimeType)); + return foreign2rNode.execute(parseFileAndCall(path, languageId)); } finally { setVisibilityNode.execute(frame, false); } } @Specialization - protected Object eval(VirtualFrame frame, String mimeType, @SuppressWarnings("unused") RMissing source, String path) { + protected Object eval(VirtualFrame frame, String languageId, @SuppressWarnings("unused") RMissing source, String path) { try { - return foreign2rNode.execute(parseFileAndCall(path, mimeType)); + return foreign2rNode.execute(parseFileAndCall(path, languageId)); } finally { setVisibilityNode.execute(frame, false); } } @Specialization - protected Object eval(VirtualFrame frame, @SuppressWarnings("unused") RMissing mimeType, @SuppressWarnings("unused") RMissing source, String path) { + protected Object eval(VirtualFrame frame, @SuppressWarnings("unused") RMissing languageId, @SuppressWarnings("unused") RMissing source, String path) { try { return foreign2rNode.execute(parseFileAndCall(path, null)); } finally { @@ -205,18 +205,18 @@ public class FastRInterop { } @TruffleBoundary - private Object parseFileAndCall(String path, String mimeType) { - return parseFile(path, mimeType).call(); + private Object parseFileAndCall(String path, String languageId) { + return parseFile(path, languageId).call(); } - protected CallTarget parseFile(String path, String mimeType) { + protected CallTarget parseFile(String path, String languageId) { CompilerAsserts.neverPartOfCompilation(); File file = new File(path); try { Builder<IOException, RuntimeException, RuntimeException> sourceBuilder = Source.newBuilder(file).name(file.getName()).internal(); - if (mimeType != null) { - sourceBuilder.mimeType(mimeType); + if (languageId != null) { + sourceBuilder.language(languageId); } Source sourceObject = sourceBuilder.build(); return RContext.getInstance().getEnv().parse(sourceObject); @@ -229,7 +229,7 @@ public class FastRInterop { @Specialization @TruffleBoundary - protected Object eval(@SuppressWarnings("unused") RMissing source, @SuppressWarnings("unused") RMissing mimeType, @SuppressWarnings("unused") RMissing path) { + protected Object eval(@SuppressWarnings("unused") RMissing source, @SuppressWarnings("unused") RMissing languageId, @SuppressWarnings("unused") RMissing path) { throw RError.error(this, RError.Message.INVALID_ARG, "'source' or 'path'"); } } diff --git a/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/test/SpecialCallTest.java b/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/test/SpecialCallTest.java index 89a959f4b3d4ee8c19bc2edf8dbb05a55b26ba89..cef464a9b4b267b333049bd20800fda1f83b95f0 100644 --- a/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/test/SpecialCallTest.java +++ b/com.oracle.truffle.r.nodes.test/src/com/oracle/truffle/r/nodes/test/SpecialCallTest.java @@ -32,6 +32,7 @@ import com.oracle.truffle.r.engine.TruffleRLanguageImpl; import com.oracle.truffle.r.runtime.ArgumentsSignature; import com.oracle.truffle.r.runtime.FastROptions; import com.oracle.truffle.r.runtime.RError; +import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.RootWithBody; import com.oracle.truffle.r.runtime.context.RContext; import com.oracle.truffle.r.runtime.data.RExpression; @@ -287,8 +288,8 @@ public class SpecialCallTest extends TestBase { if (!FastROptions.UseSpecials.getBooleanValue()) { return; } - Source setupSource = Source.newBuilder("{" + setup + "}").mimeType(TruffleRLanguageImpl.MIME).name("test").build(); - Source testSource = Source.newBuilder(test).mimeType(TruffleRLanguageImpl.MIME).name("test").build(); + Source setupSource = Source.newBuilder("{" + setup + "}").language(RRuntime.R_LANGUAGE_ID).name("test").build(); + Source testSource = Source.newBuilder(test).language(RRuntime.R_LANGUAGE_ID).name("test").build(); RExpression setupExpression = testVMContext.getThisEngine().parse(setupSource); RExpression testExpression = testVMContext.getThisEngine().parse(testSource); 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 9ce0b2aea175901d30b86102d4c45c01f3295c37..43a08e94cc1b48514865dc9c3224bcfab57e92ad 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 @@ -72,6 +72,7 @@ public class RRuntime { public static final boolean True = true; public static final boolean False = false; + public static final String R_LANGUAGE_ID = "R"; public static final String R_APP_MIME = "application/x-r"; public static final String R_TEXT_MIME = "text/x-r"; 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 4e66f50794be836f27a49ed83cc90c5b7d6a3e14..d1429ce1dee20143b7f056db5aa17d60d62831dc 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -110,7 +110,7 @@ public class RSource { public static Source fromFileName(String text, String path, boolean internal) throws URISyntaxException { File file = new File(path).getAbsoluteFile(); URI uri = new URI("file://" + file.getAbsolutePath()); - Source.Builder<RuntimeException, RuntimeException, RuntimeException> builder = Source.newBuilder(file).content(text).uri(uri).mimeType(RRuntime.R_APP_MIME); + Source.Builder<RuntimeException, RuntimeException, RuntimeException> builder = Source.newBuilder(file).content(text).uri(uri).language(RRuntime.R_LANGUAGE_ID); if (internal) { builder.internal(); } @@ -121,32 +121,32 @@ public class RSource { * Create an {@code internal} source from {@code text} and {@code description}. */ public static Source fromTextInternal(String text, Internal description) { - return fromTextInternal(text, description, RRuntime.R_APP_MIME); + return fromTextInternal(text, description, RRuntime.R_LANGUAGE_ID); } /** * Create an {@code internal} source from {@code text} and {@code description}. */ public static Source fromTextInternalInvisible(String text, Internal description) { - return fromTextInternalInvisible(text, description, RRuntime.R_APP_MIME); + return fromTextInternalInvisible(text, description, RRuntime.R_LANGUAGE_ID); } /** * Create an {@code internal} source from {@code text} and {@code description} of given - * {@code mimeType}. + * {@code languageId}. */ - public static Source fromTextInternal(String text, Internal description, String mimeType) { - return Source.newBuilder(text).name(description.string).mimeType(mimeType).internal().interactive().build(); + public static Source fromTextInternal(String text, Internal description, String languageId) { + return Source.newBuilder(text).name(description.string).language(languageId).internal().interactive().build(); } /** * Create an {@code internal} source from {@code text} and {@code description} of given - * {@code mimeType}. + * {@code languageId}. */ - public static Source fromTextInternalInvisible(String text, Internal description, String mimeType) { - return Source.newBuilder(text).name(description.string).mimeType(mimeType).internal().build(); + public static Source fromTextInternalInvisible(String text, Internal description, String languageId) { + return Source.newBuilder(text).name(description.string).language(languageId).internal().build(); } /** @@ -155,7 +155,7 @@ public class RSource { */ public static Source fromPackageTextInternal(String text, String packageName) { String name = String.format(Internal.PACKAGE.string, packageName); - return Source.newBuilder(text).name(name).mimeType(RRuntime.R_APP_MIME).build(); + return Source.newBuilder(text).name(name).language(RRuntime.R_LANGUAGE_ID).build(); } /** @@ -167,7 +167,7 @@ public class RSource { if (functionName == null) { return fromPackageTextInternal(text, packageName); } else { - return Source.newBuilder(text).name(packageName + "::" + functionName).mimeType(RRuntime.R_APP_MIME).build(); + return Source.newBuilder(text).name(packageName + "::" + functionName).language(RRuntime.R_LANGUAGE_ID).build(); } } @@ -177,7 +177,7 @@ public class RSource { public static Source fromFileName(String path, boolean internal) throws IOException { File file = new File(path); return getCachedByOrigin(file, origin -> { - Source.Builder<IOException, RuntimeException, RuntimeException> builder = Source.newBuilder(file).mimeType(RRuntime.R_APP_MIME); + Source.Builder<IOException, RuntimeException, RuntimeException> builder = Source.newBuilder(file).language(RRuntime.R_LANGUAGE_ID); if (internal) { builder.internal(); } @@ -189,21 +189,21 @@ public class RSource { * Create an (external) source from the file system path denoted by {@code file}. */ public static Source fromFile(File file) throws IOException { - return getCachedByOrigin(file, origin -> Source.newBuilder(file).name(file.getName()).mimeType(RRuntime.R_APP_MIME).build()); + return getCachedByOrigin(file, origin -> Source.newBuilder(file).name(file.getName()).language(RRuntime.R_LANGUAGE_ID).build()); } /** * Create a source from the file system path denoted by {@code file}. */ public static Source fromTempFile(File file) throws IOException { - return getCachedByOrigin(file, origin -> Source.newBuilder(file).name(file.getName()).mimeType(RRuntime.R_APP_MIME).internal().build()); + return getCachedByOrigin(file, origin -> Source.newBuilder(file).name(file.getName()).language(RRuntime.R_LANGUAGE_ID).internal().build()); } /** * Create an (external) source from {@code url}. */ public static Source fromURL(URL url, String name) throws IOException { - return getCachedByOrigin(url, origin -> Source.newBuilder(url).name(name).mimeType(RRuntime.R_APP_MIME).build()); + return getCachedByOrigin(url, origin -> Source.newBuilder(url).name(name).language(RRuntime.R_LANGUAGE_ID).build()); } /** @@ -240,7 +240,7 @@ public class RSource { * Create an unknown source with the given name. */ public static SourceSection createUnknown(String name) { - return Source.newBuilder("").name(name).mimeType(RRuntime.R_APP_MIME).build().createSection(0, 0); + return Source.newBuilder("").name(name).language(RRuntime.R_LANGUAGE_ID).build().createSection(0, 0); } /** diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test index 36ae8fe3d51db4b90073244735637d989a433793..aa4e0e0934f66f904c250138a34997c8b27d3192 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test @@ -143218,23 +143218,23 @@ NULL [1] "Hello, World!" "second line" ##com.oracle.truffle.r.test.library.fastr.TestInterop.testInteropEval# -#if (!any(R.version$engine == "FastR")) { 1 } else { eval.polyglot('application/x-r', '1') } +#if (!any(R.version$engine == "FastR")) { 1 } else { eval.polyglot('R', '1') } [1] 1 ##com.oracle.truffle.r.test.library.fastr.TestInterop.testInteropEval# -#if (!any(R.version$engine == "FastR")) { 16 } else { eval.polyglot('application/x-r', '14 + 2') } +#if (!any(R.version$engine == "FastR")) { 16 } else { eval.polyglot('R', '14 + 2') } [1] 16 ##com.oracle.truffle.r.test.library.fastr.TestInterop.testInteropEval# -#if (!any(R.version$engine == "FastR")) { 1L } else { eval.polyglot('application/x-r', '1L') } +#if (!any(R.version$engine == "FastR")) { 1L } else { eval.polyglot('R', '1L') } [1] 1 ##com.oracle.truffle.r.test.library.fastr.TestInterop.testInteropEval# -#if (!any(R.version$engine == "FastR")) { TRUE } else { eval.polyglot('application/x-r', 'TRUE') } +#if (!any(R.version$engine == "FastR")) { TRUE } else { eval.polyglot('R', 'TRUE') } [1] TRUE ##com.oracle.truffle.r.test.library.fastr.TestInterop.testInteropEval# -#if (!any(R.version$engine == "FastR")) { as.character(123) } else { eval.polyglot('application/x-r', 'as.character(123)') } +#if (!any(R.version$engine == "FastR")) { as.character(123) } else { eval.polyglot('R', 'as.character(123)') } [1] "123" ##com.oracle.truffle.r.test.library.fastr.TestInterop.testInteropEvalFile# @@ -143242,15 +143242,15 @@ NULL Error in eval.polyglot() : invalid 'source' or 'path' argument ##com.oracle.truffle.r.test.library.fastr.TestInterop.testInteropEvalFile# -#if (!any(R.version$engine == "FastR")) { cat('Error in eval.polyglot(, "abc", ) : invalid mimeType argument\n') } else { eval.polyglot(,'abc',) } -Error in eval.polyglot(, "abc", ) : invalid mimeType argument +#if (!any(R.version$engine == "FastR")) { cat('Error in eval.polyglot(, "abc", ) : invalid languageId argument\n') } else { eval.polyglot(,'abc',) } +Error in eval.polyglot(, "abc", ) : invalid languageId argument ##com.oracle.truffle.r.test.library.fastr.TestInterop.testInteropEvalFile# #if (!any(R.version$engine == "FastR")) { cat('[1] "Error reading file: /a/b.R"\n') } else { tryCatch(eval.polyglot(path="/a/b.R"), error = function(e) e$message) } [1] "Error reading file: /a/b.R" ##com.oracle.truffle.r.test.library.fastr.TestInterop.testInteropEvalFile# -#if (!any(R.version$engine == "FastR")) { x<-c(1);cat(x) } else { fileConn<-file("_testInteropEvalFile_testScript_.R");writeLines(c("x<-c(1)","cat(x)"), fileConn);close(fileConn);eval.polyglot(mimeType="application/x-r", path="_testInteropEvalFile_testScript_.R") } +#if (!any(R.version$engine == "FastR")) { x<-c(1);cat(x) } else { fileConn<-file("_testInteropEvalFile_testScript_.R");writeLines(c("x<-c(1)","cat(x)"), fileConn);close(fileConn);eval.polyglot(languageId="R", path="_testInteropEvalFile_testScript_.R") } 1 ##com.oracle.truffle.r.test.library.fastr.TestInterop.testInteropEvalFile# #if (!any(R.version$engine == "FastR")) { x<-c(1);cat(x) } else { fileConn<-file("_testInteropEvalFile_testScript_.R");writeLines(c("x<-c(1)","cat(x)"), fileConn);close(fileConn);eval.polyglot(path="_testInteropEvalFile_testScript_.R") } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/fastr/TestInterop.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/fastr/TestInterop.java index 29f1efb24bc2db60993d07b689961cd233e59d3a..d28d9bee70fc8ec7c5a6e8c9581d5255200591dc 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/fastr/TestInterop.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/fastr/TestInterop.java @@ -53,11 +53,11 @@ public class TestInterop extends TestBase { @Test public void testInteropEval() { - assertEvalFastR("eval.polyglot('application/x-r', '14 + 2')", "16"); - assertEvalFastR("eval.polyglot('application/x-r', '1')", "1"); - assertEvalFastR("eval.polyglot('application/x-r', '1L')", "1L"); - assertEvalFastR("eval.polyglot('application/x-r', 'TRUE')", "TRUE"); - assertEvalFastR("eval.polyglot('application/x-r', 'as.character(123)')", "as.character(123)"); + assertEvalFastR("eval.polyglot('R', '14 + 2')", "16"); + assertEvalFastR("eval.polyglot('R', '1')", "1"); + assertEvalFastR("eval.polyglot('R', '1L')", "1L"); + assertEvalFastR("eval.polyglot('R', 'TRUE')", "TRUE"); + assertEvalFastR("eval.polyglot('R', 'as.character(123)')", "as.character(123)"); } @Test @@ -70,7 +70,7 @@ public class TestInterop extends TestBase { @Test public void testInteropEvalFile() { - assertEvalFastR("fileConn<-file(\"" + TEST_EVAL_FILE + "\");writeLines(c(\"x<-c(1)\",\"cat(x)\"), fileConn);close(fileConn);eval.polyglot(mimeType=\"application/x-r\", path=\"" + + assertEvalFastR("fileConn<-file(\"" + TEST_EVAL_FILE + "\");writeLines(c(\"x<-c(1)\",\"cat(x)\"), fileConn);close(fileConn);eval.polyglot(languageId=\"R\", path=\"" + TEST_EVAL_FILE + "\")", "x<-c(1);cat(x)"); assertEvalFastR("fileConn<-file(\"" + TEST_EVAL_FILE + "\");writeLines(c(\"x<-c(1)\",\"cat(x)\"), fileConn);close(fileConn);eval.polyglot(path=\"" + TEST_EVAL_FILE + "\")", @@ -78,7 +78,7 @@ public class TestInterop extends TestBase { assertEvalFastR("tryCatch(eval.polyglot(path=\"/a/b.R\"), error = function(e) e$message)", "cat('[1] \"Error reading file: /a/b.R\"\\n')"); assertEvalFastR("eval.polyglot()", "cat('Error in eval.polyglot() : invalid \\'source\\' or \\'path\\' argument\\n')"); - assertEvalFastR("eval.polyglot(,'abc',)", "cat('Error in eval.polyglot(, \"abc\", ) : invalid mimeType argument\\n')"); + assertEvalFastR("eval.polyglot(,'abc',)", "cat('Error in eval.polyglot(, \"abc\", ) : invalid languageId argument\\n')"); } @Test diff --git a/documentation/tutorials/debugging/InteropDebugging/src/com/oracle/truffle/r/Main.java b/documentation/tutorials/debugging/InteropDebugging/src/com/oracle/truffle/r/Main.java index b8d073b0013f2e5c8e4c458f463ebefc1ef78a1f..e2f50e1a2837485ae85e988277f298b1d87132a0 100644 --- a/documentation/tutorials/debugging/InteropDebugging/src/com/oracle/truffle/r/Main.java +++ b/documentation/tutorials/debugging/InteropDebugging/src/com/oracle/truffle/r/Main.java @@ -34,8 +34,6 @@ import java.io.IOException; public class Main { - private static final String R_MIME_TYPE = "application/x-r"; - /** * @param args the command line arguments * @throws java.io.IOException