Skip to content
Snippets Groups Projects
Commit 500e2141 authored by Julien Lopez's avatar Julien Lopez
Browse files

Transfer interface with databases functions to TruffleRLanguage

parent 9c486b86
No related branches found
No related tags found
No related merge requests found
......@@ -23,8 +23,6 @@
package com.oracle.truffle.r.engine;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
......@@ -51,8 +49,6 @@ import com.oracle.truffle.api.profiles.ConditionProfile;
import com.oracle.truffle.api.profiles.ValueProfile;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.vm.PolyglotEngine;
import com.oracle.truffle.api.vm.PolyglotEngine.Value;
import com.oracle.truffle.r.library.graphics.RGraphics;
import com.oracle.truffle.r.nodes.RASTBuilder;
import com.oracle.truffle.r.nodes.RASTUtils;
......@@ -83,7 +79,6 @@ import com.oracle.truffle.r.runtime.RProfile;
import com.oracle.truffle.r.runtime.RRuntime;
import com.oracle.truffle.r.runtime.RSource;
import com.oracle.truffle.r.runtime.RStartParams.SA_TYPE;
import com.oracle.truffle.r.runtime.RValue;
import com.oracle.truffle.r.runtime.ReturnException;
import com.oracle.truffle.r.runtime.RootWithBody;
import com.oracle.truffle.r.runtime.SubstituteVirtualFrame;
......@@ -328,51 +323,6 @@ final class REngine implements Engine, Engine.Timings {
}
}
public static final RValue executeR(final String program) throws IOException {
RContext.setDeepEmbedded();
final Value v = PolyglotEngine.newBuilder().config("application/x-r", "REngine", null).build().eval(Source.newBuilder(program).name("RBuilder").mimeType(RRuntime.R_APP_MIME).build());
final Object res = v.get();
if (res instanceof Serializable)
return new RValue((Serializable) res);
return new RValue(v.getSourceLocation().getCode());
}
public static final RValue executeApply(final RValue fun, final RValue args[]) throws IOException {
return executeR("f = " + fun.getValue() + "\nf(" + Arrays.stream(args).map(arg -> arg.getValue().toString()).collect(Collectors.joining(", ")) + ")");
}
public static final RValue translate(final Integer i) throws IOException {
return new RValue(i);
}
public static final RValue translate(final Double d) throws IOException {
return new RValue(d);
}
public static final RValue translate(final String s) throws IOException {
return new RValue(s);
}
public static final RValue translate(final Boolean b) throws IOException {
return new RValue(b);
}
public static final Integer translateBackToInteger(final RValue v) {
return (Integer) v.getValue();
}
public static final Double translateBackToDouble(final RValue v) {
return (Double) v.getValue();
}
public static final String translateBackToString(final RValue v) {
return (String) v.getValue();
}
public static final Boolean translateBackToBoolean(final RValue v) {
return (Boolean) v.getValue();
}
private final class PolyglotEngineRootNode extends RootNode {
private final List<RSyntaxNode> statements;
......
......@@ -22,7 +22,11 @@
*/
package com.oracle.truffle.r.engine;
import java.io.IOException;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Locale;
import java.util.stream.Collectors;
import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.CompilerAsserts;
......@@ -37,7 +41,10 @@ import com.oracle.truffle.api.instrumentation.StandardTags;
import com.oracle.truffle.api.metadata.ScopeProvider;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.RootNode;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.vm.PolyglotEngine;
import com.oracle.truffle.api.vm.PolyglotEngine.Value;
import com.oracle.truffle.r.engine.interop.RForeignAccessFactoryImpl;
import com.oracle.truffle.r.nodes.RASTBuilder;
import com.oracle.truffle.r.nodes.builtin.RBuiltinPackages;
......@@ -49,6 +56,7 @@ import com.oracle.truffle.r.runtime.RAccuracyInfo;
import com.oracle.truffle.r.runtime.RDeparse;
import com.oracle.truffle.r.runtime.RError;
import com.oracle.truffle.r.runtime.RRuntime;
import com.oracle.truffle.r.runtime.RValue;
import com.oracle.truffle.r.runtime.Utils;
import com.oracle.truffle.r.runtime.context.Engine.IncompleteSourceException;
import com.oracle.truffle.r.runtime.context.Engine.ParseException;
......@@ -252,4 +260,48 @@ public final class TruffleRLanguage extends TruffleLanguage<RContext> implements
public AbstractScope findScope(RContext langContext, Node node, Frame frame) {
return RScope.createScope(node, frame);
}
public static final RValue executeR(final String program) throws IOException {
final Value v = PolyglotEngine.newBuilder().config("application/x-r", "REngine", null).build().eval(Source.newBuilder(program).name("RBuilder").mimeType(RRuntime.R_APP_MIME).build());
final Object res = v.get();
if (res instanceof Serializable)
return new RValue((Serializable) res);
return new RValue(v.getSourceLocation().getCode());
}
public static final RValue executeApply(final RValue fun, final RValue args[]) throws IOException {
return executeR("f = " + fun.getValue() + ";f(" + Arrays.stream(args).map(arg -> arg.getValue().toString()).collect(Collectors.joining(", ")) + ")");
}
public static final RValue translate(final Integer i) throws IOException {
return new RValue(i);
}
public static final RValue translate(final Double d) throws IOException {
return new RValue(d);
}
public static final RValue translate(final String s) throws IOException {
return new RValue(s);
}
public static final RValue translate(final Boolean b) throws IOException {
return new RValue(b);
}
public static final Integer translateBackToInteger(final RValue v) {
return (Integer) v.getValue();
}
public static final Double translateBackToDouble(final RValue v) {
return (Double) v.getValue();
}
public static final String translateBackToString(final RValue v) {
return (String) v.getValue();
}
public static final Boolean translateBackToBoolean(final RValue v) {
return (Boolean) v.getValue();
}
}
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