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

Use existing engine in QIRInterface and add test on side effects

parent dc21a185
No related branches found
No related tags found
No related merge requests found
......@@ -103,6 +103,8 @@ public class RscriptCommand {
throw RCommand.fatal("should not reach here");
}
public static Context currentContext = null;
public static int doMain(String[] args, String[] env, InputStream inStream, OutputStream outStream, OutputStream errStream) {
assert env == null : "re-enble environment variables";
......@@ -130,6 +132,7 @@ public class RscriptCommand {
ConsoleHandler consoleHandler = RCommand.createConsoleHandler(options, false, inStream, outStream);
try (Context context = Context.newBuilder().options(polyglotOptions).arguments("R", arguments).in(consoleHandler.createInputStream()).out(outStream).err(errStream).build()) {
currentContext = context;
consoleHandler.setContext(context);
return RCommand.readEvalPrint(context, consoleHandler);
}
......
......@@ -29,15 +29,13 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.oracle.truffle.api.TruffleLanguage.Env;
import com.oracle.truffle.api.frame.Frame;
import com.oracle.truffle.api.frame.FrameDescriptor;
import com.oracle.truffle.api.frame.FrameSlot;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.vm.EngineTruffleObject;
import com.oracle.truffle.api.vm.PolyglotEngine;
import com.oracle.truffle.api.vm.PolyglotEngine.Value;
import com.oracle.truffle.r.launcher.RscriptCommand;
import com.oracle.truffle.r.nodes.function.FunctionDefinitionNode;
import com.oracle.truffle.r.nodes.function.FunctionExpressionNode;
import com.oracle.truffle.r.runtime.RRuntime;
......@@ -243,14 +241,8 @@ public final class QIRInterface {
}
static final QIRNode execute(final String program) {
final Env env = RContext.getInstance().getEnv();
final PolyglotEngine vm = PolyglotEngine.newBuilder().config(RRuntime.R_APP_MIME, "REngine", null).setIn(env.in()).setOut(env.out()).build();
final Source source = Source.newBuilder(program).name("mySrc").mimeType(RRuntime.R_APP_MIME).build();
final Value v = vm.eval(source);
if (v == null)
throw new RuntimeException("No function main() defined in R source file." + source.getCharacters().toString());
return RToQIRType(v.getSourceLocation(), v.get());
// TODO: getReceiver does not exist in real Graal
return RToQIRType(null, RscriptCommand.currentContext.eval("R", program).getReceiver());
}
static final QIRTruffleNode apply(final QIRTruffleNode fun, final List<QIRNode> args) {
......
emp = new.tableRef("emp", "PostgreSQL", "postgre.config", "public")
minsalary = 2500.0
q = query.select(function (x) {
res = new.env()
res$empno = x$empno
res$ename = x$ename
print(paste("salary:", x$sal))
res$salary = (function (dol){
a = dol * 89.0 / 100.0
while (a > 1000.0) a = a * 89.0 / 100.0
a
})(x$sal)
res },
query.where(function (x) x$sal >= minsalary,
query.from(emp)))
results = query.force(q)
print(results)
[1] "salary: 2500"
[1] "salary: 5220"
[1] "salary: 3500"
[1] "salary: 4235"
[1] "salary: 5000"
ename empno salary
1 SMITH 1 984.1472
2 WARD 3 908.9094
3 JONES 4 971.3106
4 SCOTT 8 930.9439
5 ADAMS 11 978.2055
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