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

returns results from fastr.context.eval

parent bbcfe0db
Branches
No related tags found
No related merge requests found
......@@ -26,6 +26,7 @@ import java.io.*;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.*;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.source.*;
import com.oracle.truffle.api.vm.*;
import com.oracle.truffle.r.nodes.builtin.*;
......@@ -119,7 +120,8 @@ public class FastRContext {
public abstract static class Eval extends RExternalBuiltinNode.Arg3 {
@Specialization
@TruffleBoundary
protected RNull eval(RAbstractIntVector contexts, RAbstractStringVector exprs, byte par) {
protected Object eval(RAbstractIntVector contexts, RAbstractStringVector exprs, byte par) {
Object[] results = new Object[contexts.getLength()];
if (RRuntime.fromLogical(par)) {
RContext.EvalThread[] threads = new RContext.EvalThread[contexts.getLength()];
for (int i = 0; i < threads.length; i++) {
......@@ -132,6 +134,7 @@ public class FastRContext {
try {
for (int i = 0; i < threads.length; i++) {
threads[i].join();
results[i] = threads[i].getReturnValue();
}
} catch (InterruptedException ex) {
throw RError.error(this, RError.Message.GENERIC, "error finishing eval thread");
......@@ -141,8 +144,15 @@ public class FastRContext {
ContextInfo info = checkContext(contexts.getDataAt(i), this);
PolyglotEngine vm = info.apply(PolyglotEngine.newBuilder()).build();
try {
Source source = Source.fromText(exprs.getDataAt(i), "<eval>").withMimeType(RRuntime.R_APP_MIME);
vm.eval(source);
Source source = Source.fromText(exprs.getDataAt(i % exprs.getLength()), "<eval>").withMimeType(RRuntime.R_APP_MIME);
PolyglotEngine.Value resultValue = vm.eval(source);
Object result = resultValue.get();
if (result instanceof TruffleObject) {
Object returnValue = resultValue.as(Object.class);
results[i] = returnValue;
} else {
results[i] = result;
}
} catch (IOException e) {
throw RInternalError.shouldNotReachHere(e);
} finally {
......@@ -150,7 +160,11 @@ public class FastRContext {
}
}
}
return RNull.instance;
if (results.length == 1) {
return results[0];
} else {
return RDataFactory.createList(results);
}
}
}
......
......@@ -104,8 +104,8 @@ fastr.context.join <- function(contexts) {
}
fastr.context.eval <- function(contexts, exprs, par=FALSE) {
.FastR(.NAME="context.eval", contexts, exprs, par)
invisible(NULL)
result = .FastR(.NAME="context.eval", contexts, exprs, par)
invisible(result)
}
fastr.context.pareval <- function(contexts, exprs) {
......
......@@ -164,6 +164,7 @@ public final class RContext extends ExecutionContext implements TruffleObject {
public static class EvalThread extends ContextThread {
private final Source source;
private final ContextInfo info;
private Object returnValue;
public static final Map<Integer, Thread> threads = new ConcurrentHashMap<>();
......@@ -184,7 +185,13 @@ public final class RContext extends ExecutionContext implements TruffleObject {
}
try {
try {
vm.eval(source);
PolyglotEngine.Value resultValue = vm.eval(source);
Object result = resultValue.get();
if (result instanceof TruffleObject) {
returnValue = resultValue.as(Object.class);
} else {
returnValue = result;
}
} catch (ParseException e) {
e.report(context.getConsoleHandler());
} catch (IOException e) {
......@@ -200,6 +207,10 @@ public final class RContext extends ExecutionContext implements TruffleObject {
threads.remove(info.getId());
}
}
public Object getReturnValue() {
return returnValue;
}
}
private final ContextInfo info;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment