Skip to content

Commit

Permalink
Several fixes for shiny 1.1.0
Browse files Browse the repository at this point in the history
(cherry picked from commit bc02f96)
  • Loading branch information
zslajchrt authored and ansalond committed Jun 29, 2018
1 parent 82e5e31 commit 7286778
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 5 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,25 @@ We encourage contributions, and invite interested developers to join in.
Prospective contributors need to sign the [Oracle Contributor Agreement (OCA)](http://www.oracle.com/technetwork/community/oca-486395.html).
The access point for contributions, issues and questions about FastR is the [GitHub repository ](https://github.com/graalvm/fastr)

## Troubleshooting

### Build fails when generating R grammar

This problem manifests by the following error message in the build output:

`Parser failed to execute command`

followed by a series of parser errors, such as:

`error(170): R.g:<LINE>:<COL>: the .. range operator isn't allowed in parser rules`

It seems to be an ANTLR issue occurring when `LANG`, `LC_ALL` and `LC_CTYPE` environment
variables are not set to the same value.

The solution is to set those variables to the same value, e.g.

```
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
export LC_CTYPE=en_US.UTF-8
```
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.oracle.truffle.r.library.fastrGrid.color.RGB;
import com.oracle.truffle.r.library.fastrGrid.grDevices.DevCairo;
import com.oracle.truffle.r.library.fastrGrid.grDevices.DevCurr;
import com.oracle.truffle.r.library.fastrGrid.grDevices.DevSet;
import com.oracle.truffle.r.library.fastrGrid.grDevices.DevHoldFlush;
import com.oracle.truffle.r.library.fastrGrid.grDevices.DevOff;
import com.oracle.truffle.r.library.fastrGrid.grDevices.DevSize;
Expand Down Expand Up @@ -63,6 +64,8 @@ public static RExternalBuiltinNode lookupDotExternal(String name) {
return new DevSize();
case "devcur":
return new DevCurr();
case "devset":
return DevSet.create();
case "devoff":
return DevOff.create();
case "svgstring":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ public final class GridContext {
private int currentDeviceIdx = 0;

private GridContext() {
devices.add(new DeviceAndState(null, null));
devices.add(new DeviceAndState(null, null, null));
}

private GridContext(GridContext parent) {
// initialized grid in spawned context. Grid R code calls initGrid(gridEnv) only once and
// then sets global variable to remember to not call it again, but we need to initialize
// grid context in newly spawned context, so we do it manually here.
gridState.init(parent.getGridState().getGridEnv());
devices.add(new DeviceAndState(null, null));
devices.add(new DeviceAndState(null, null, null));
}

public static GridContext getContext(RContext rCtx) {
Expand Down Expand Up @@ -120,10 +120,17 @@ public void setCurrentDevice(String name, GridDevice currentDevice, String filen
RGridGraphicsAdapter.addDevice(rCtx, name);
RGridGraphicsAdapter.setCurrentDevice(rCtx, name);
currentDeviceIdx = this.devices.size();
this.devices.add(new DeviceAndState(currentDevice, filenamePattern));
this.devices.add(new DeviceAndState(name, currentDevice, filenamePattern));
assert devices.size() == RGridGraphicsAdapter.getDevicesCount() : devices.size() + " vs " + RGridGraphicsAdapter.getDevicesCount();
}

public void setCurrentDevice(int deviceIdx) {
assert deviceIdx > 0 && deviceIdx < this.devices.size();
RContext rCtx = RContext.getInstance();
RGridGraphicsAdapter.setCurrentDevice(rCtx, this.devices.get(deviceIdx).name);
currentDeviceIdx = deviceIdx;
}

public void openDefaultDevice() {
String defaultDev = RGridGraphicsAdapter.getDefaultDevice();
if (defaultDev.equals("awt") || defaultDev.startsWith("X11")) {
Expand Down Expand Up @@ -190,10 +197,12 @@ private void safeOpenImageDev(String filename, String formatName) {
}

private static final class DeviceAndState {
final String name;
final GridDevice device;
final GridDeviceState state;

DeviceAndState(GridDevice device, String filenamePattern) {
DeviceAndState(String name, GridDevice device, String filenamePattern) {
this.name = name;
this.device = device;
this.state = new GridDeviceState(filenamePattern);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 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
* under the terms of the GNU General Public License version 3 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 3 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 3 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.truffle.r.library.fastrGrid.grDevices;

import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.numericValue;

import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.r.library.fastrGrid.GridContext;
import com.oracle.truffle.r.library.fastrGrid.graphics.RGridGraphicsAdapter;
import com.oracle.truffle.r.nodes.builtin.RExternalBuiltinNode;
import com.oracle.truffle.r.runtime.context.RContext;

public abstract class DevSet extends RExternalBuiltinNode.Arg1 {

static {
Casts casts = new Casts(DevSet.class);
casts.arg(0).mustBe(numericValue()).asIntegerVector().findFirst();
}

public static DevSet create() {
return DevSetNodeGen.create();
}

@Specialization
public int doInteger(int deviceIdx) {
RContext rCtx = RContext.getInstance();
RGridGraphicsAdapter.fixupDevicesVariable(rCtx);
GridContext.getContext(rCtx).setCurrentDevice(deviceIdx - 1);
return deviceIdx;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ protected Object sysCalls(VirtualFrame frame) {
@Override
public Object apply(Frame f) {
RCaller currentCall = RArguments.getCall(f);
if (!currentCall.isPromise() && currentCall.getDepth() <= depth) {
if (currentCall.isValidCaller() && !currentCall.isPromise() && currentCall.getDepth() <= depth) {
result = RDataFactory.createPairList(createCall(currentCall), result);
}
return (!currentCall.isPromise() && RArguments.getDepth(f) == 1) ? result : null;
Expand Down

0 comments on commit 7286778

Please sign in to comment.