Skip to content
Snippets Groups Projects
Commit eb825986 authored by Stepan Sindelar's avatar Stepan Sindelar
Browse files

[GR-9678] [GR-9534] Fix par builtin and use Source#getReader.

PullRequest: fastr/1503
parents a56efd3e 6a8be88b
No related branches found
No related tags found
No related merge requests found
......@@ -376,7 +376,7 @@ final class REngine implements Engine, Engine.Timings {
String file = fullSource.getPath();
ArrayList<RSyntaxNode> statements = new ArrayList<>(128);
try {
try (BufferedReader br = new BufferedReader(new InputStreamReader(fullSource.getInputStream()))) {
try (BufferedReader br = new BufferedReader(fullSource.getReader())) {
int lineIndex = 1;
int startLine = lineIndex;
StringBuilder sb = new StringBuilder();
......
......@@ -5,7 +5,7 @@
*
* Copyright (C) 2001-3 Paul Murrell
* Copyright (c) 1998-2013, The R Core Team
* Copyright (c) 2017, Oracle and/or its affiliates
* Copyright (c) 2017, 2018, Oracle and/or its affiliates
*
* All rights reserved.
*/
......@@ -27,7 +27,7 @@ import com.oracle.truffle.r.runtime.data.RNull;
* initialization of the grid state and device specific grid state if the device has changed since
* the last time.
*/
final class LGridDirty extends RExternalBuiltinNode {
public final class LGridDirty extends RExternalBuiltinNode {
@Child private InitViewPortNode initViewPort = new InitViewPortNode();
@Child private OpenDefaultDevice openDefaultDevice = new OpenDefaultDevice();
......
......@@ -24,21 +24,31 @@ package com.oracle.truffle.r.library.fastrGrid.graphics;
import static com.oracle.truffle.r.library.fastrGrid.device.DrawingContext.INCH_TO_POINTS_FACTOR;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.r.library.fastrGrid.GPar;
import com.oracle.truffle.r.library.fastrGrid.GridContext;
import com.oracle.truffle.r.library.fastrGrid.GridState;
import com.oracle.truffle.r.library.fastrGrid.LGridDirty;
import com.oracle.truffle.r.library.fastrGrid.device.DrawingContext;
import com.oracle.truffle.r.library.fastrGrid.device.GridDevice;
import com.oracle.truffle.r.library.fastrGrid.grDevices.OpenDefaultDevice;
import com.oracle.truffle.r.nodes.access.variables.ReadVariableNode;
import com.oracle.truffle.r.nodes.builtin.RExternalBuiltinNode;
import com.oracle.truffle.r.nodes.function.call.RExplicitCallNode;
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.RError.Message;
import com.oracle.truffle.r.runtime.RRuntime;
import com.oracle.truffle.r.runtime.context.RContext;
import com.oracle.truffle.r.runtime.data.RArgsValuesAndNames;
import com.oracle.truffle.r.runtime.data.RDataFactory;
import com.oracle.truffle.r.runtime.data.RFunction;
import com.oracle.truffle.r.runtime.data.RList;
import com.oracle.truffle.r.runtime.data.RNull;
import com.oracle.truffle.r.runtime.env.REnvironment;
public final class CPar extends RExternalBuiltinNode {
static {
......@@ -46,17 +56,48 @@ public final class CPar extends RExternalBuiltinNode {
}
@Child private OpenDefaultDevice openDefaultDevice = new OpenDefaultDevice();
@Child private LGridDirty gridDirty = new LGridDirty();
@Child private ReadVariableNode readLibraryFun = ReadVariableNode.createFunctionLookup("library");
@Child private RExplicitCallNode callNode = RExplicitCallNode.create();
@Override
public Object call(RArgsValuesAndNames args) {
public Object call(VirtualFrame frame, RArgsValuesAndNames args) {
if (args.getSignature().getNonNullCount() > 0) {
throw error(Message.GENERIC, "Using par for setting device parameters is not supported in FastR grid emulation mode.");
}
initGridDevice(frame);
return call(args);
}
@Override
protected Object call(RArgsValuesAndNames args) {
openDefaultDevice.execute();
return getPar(args);
}
private void initGridDevice(VirtualFrame frame) {
RContext rCtx = RContext.getInstance();
GridState gridState = GridContext.getContext(rCtx).getGridState();
if (!gridState.isDeviceInitialized()) {
CompilerDirectives.transferToInterpreter();
gridDirty.call(getGridEnv(frame, rCtx).getFrame(), RArgsValuesAndNames.EMPTY);
}
}
private REnvironment getGridEnv(VirtualFrame frame, RContext rCtx) {
REnvironment gridEnv = REnvironment.getRegisteredNamespace(rCtx, "grid");
if (gridEnv != null) {
return gridEnv;
}
// evaluate "library(grid)"
RFunction libFun = (RFunction) readLibraryFun.execute(frame);
ArgumentsSignature libFunSig = ArgumentsSignature.get(null, "character.only");
callNode.call(frame, libFun, new RArgsValuesAndNames(new Object[]{"grid", RRuntime.LOGICAL_TRUE}, libFunSig));
gridEnv = REnvironment.getRegisteredNamespace(rCtx, "grid");
assert gridEnv != null : "grid should have been just loaded";
return gridEnv;
}
@TruffleBoundary
private static Object getPar(RArgsValuesAndNames args) {
GridDevice device = GridContext.getContext().getCurrentDevice();
......
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