Skip to content
Snippets Groups Projects
Commit 8babe98e authored by Adam Welc's avatar Adam Welc
Browse files

Fixed a problem with invoking context at top level and rewritten parameter...

Fixed a problem with invoking context at top level and rewritten parameter casts for browser functions.
parent 5c7a914d
Branches
No related tags found
No related merge requests found
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
*/ */
package com.oracle.truffle.r.nodes.builtin.base; package com.oracle.truffle.r.nodes.builtin.base;
import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.*;
import static com.oracle.truffle.r.runtime.RVisibility.OFF; import static com.oracle.truffle.r.runtime.RVisibility.OFF;
import static com.oracle.truffle.r.runtime.builtins.RBehavior.COMPLEX; import static com.oracle.truffle.r.runtime.builtins.RBehavior.COMPLEX;
import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.INTERNAL; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.INTERNAL;
...@@ -50,10 +51,11 @@ public class BrowserFunctions { ...@@ -50,10 +51,11 @@ public class BrowserFunctions {
private static final class HelperState { private static final class HelperState {
private final String text; // docs state that "text" is a string but in reality it can be anything
private final Object text;
private final Object condition; private final Object condition;
private HelperState(String text, Object condition) { private HelperState(Object text, Object condition) {
this.text = text; this.text = text;
this.condition = condition; this.condition = condition;
} }
...@@ -73,19 +75,22 @@ public class BrowserFunctions { ...@@ -73,19 +75,22 @@ public class BrowserFunctions {
@Override @Override
protected void createCasts(CastBuilder casts) { protected void createCasts(CastBuilder casts) {
casts.toInteger(3); // TODO: add support for conditions conditions
casts.arg("condition").mustBe(nullValue(), RError.Message.GENERIC, "Only NULL conditions currently supported in browser");
casts.arg("expr").asLogicalVector().findFirst();
casts.arg("skipCalls").asIntegerVector().findFirst();
} }
@SuppressWarnings("unused") @SuppressWarnings("unused")
@Specialization @Specialization
protected RNull browser(VirtualFrame frame, String text, RNull condition, byte expr, int skipCalls) { protected RNull browser(VirtualFrame frame, Object text, RNull condition, byte expr, int skipCalls) {
if (RRuntime.fromLogical(expr)) { if (RRuntime.fromLogical(expr)) {
try { try {
helperState.add(new HelperState(text, condition)); helperState.add(new HelperState(text, condition));
MaterializedFrame mFrame = frame.materialize(); MaterializedFrame mFrame = frame.materialize();
RCaller caller = RArguments.getCall(mFrame); RCaller caller = RArguments.getCall(mFrame);
String callerString; String callerString;
if (caller == null) { if (caller == null || (!caller.isValidCaller() && caller.getDepth() == 0 && caller.getParent() == null)) {
callerString = "top level"; callerString = "top level";
} else { } else {
callerString = RContext.getRRuntimeASTAccess().getCallerSource(caller); callerString = RContext.getRRuntimeASTAccess().getCallerSource(caller);
...@@ -103,13 +108,15 @@ public class BrowserFunctions { ...@@ -103,13 +108,15 @@ public class BrowserFunctions {
private abstract static class RetrieveAdapter extends RBuiltinNode { private abstract static class RetrieveAdapter extends RBuiltinNode {
@Override
protected void createCasts(CastBuilder casts) {
casts.arg("n").asIntegerVector().findFirst().mustBe(gt(0), Message.POSITIVE_CONTEXTS);
}
/** /**
* GnuR objects to indices <= 0 but allows positive indices that are out of range. * GnuR objects to indices <= 0 but allows positive indices that are out of range.
*/ */
protected HelperState getHelperState(int n) { protected HelperState getHelperState(int n) {
if (n <= 0) {
throw RError.error(this, Message.POSITIVE_CONTEXTS);
}
int nn = n; int nn = n;
if (nn > helperState.size()) { if (nn > helperState.size()) {
nn = helperState.size(); nn = helperState.size();
...@@ -123,15 +130,10 @@ public class BrowserFunctions { ...@@ -123,15 +130,10 @@ public class BrowserFunctions {
@Specialization @Specialization
@TruffleBoundary @TruffleBoundary
protected String browserText(int n) { protected Object browserText(int n) {
return getHelperState(n).text; return getHelperState(n).text;
} }
@Specialization
@TruffleBoundary
protected String browserText(double n) {
return getHelperState((int) n).text;
}
} }
@RBuiltin(name = "browserCondition", kind = INTERNAL, parameterNames = {"n"}, behavior = COMPLEX) @RBuiltin(name = "browserCondition", kind = INTERNAL, parameterNames = {"n"}, behavior = COMPLEX)
...@@ -143,11 +145,6 @@ public class BrowserFunctions { ...@@ -143,11 +145,6 @@ public class BrowserFunctions {
return getHelperState(n).condition; return getHelperState(n).condition;
} }
@Specialization
@TruffleBoundary
protected Object browserCondition(double n) {
return getHelperState((int) n).condition;
}
} }
@RBuiltin(name = "browserSetDebug", visibility = OFF, kind = INTERNAL, parameterNames = {"n"}, behavior = COMPLEX) @RBuiltin(name = "browserSetDebug", visibility = OFF, kind = INTERNAL, parameterNames = {"n"}, behavior = COMPLEX)
......
...@@ -72,7 +72,8 @@ public abstract class BrowserInteractNode extends RNode { ...@@ -72,7 +72,8 @@ public abstract class BrowserInteractNode extends RNode {
String savedPrompt = ch.getPrompt(); String savedPrompt = ch.getPrompt();
ch.setPrompt(browserPrompt(RArguments.getDepth(frame))); ch.setPrompt(browserPrompt(RArguments.getDepth(frame)));
RFunction caller = RArguments.getFunction(frame); RFunction caller = RArguments.getFunction(frame);
boolean callerIsDebugged = DebugHandling.isDebugged(caller); // we may be at top level where there is not caller
boolean callerIsDebugged = caller == null ? false : DebugHandling.isDebugged(caller);
int exitMode = NEXT; int exitMode = NEXT;
try { try {
browserState.setInBrowser(true); browserState.setInBrowser(true);
...@@ -94,14 +95,16 @@ public abstract class BrowserInteractNode extends RNode { ...@@ -94,14 +95,16 @@ public abstract class BrowserInteractNode extends RNode {
break LW; break LW;
case "n": case "n":
exitMode = NEXT; exitMode = NEXT;
if (!callerIsDebugged) { // don't enable debugging if at top level
if (!callerIsDebugged && caller != null) {
DebugHandling.enableDebug(caller, "", "", true, true); DebugHandling.enableDebug(caller, "", "", true, true);
} }
browserState.setLastEmptyLineCommand("n"); browserState.setLastEmptyLineCommand("n");
break LW; break LW;
case "s": case "s":
exitMode = STEP; exitMode = STEP;
if (!callerIsDebugged) { // don't enable debugging if at top level
if (!callerIsDebugged & caller != null) {
DebugHandling.enableDebug(caller, "", "", true, true); DebugHandling.enableDebug(caller, "", "", true, true);
} }
browserState.setLastEmptyLineCommand("s"); browserState.setLastEmptyLineCommand("s");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment