Skip to content
Snippets Groups Projects
Commit fc4bcc14 authored by Florian Angerer's avatar Florian Angerer
Browse files

Fix: Now using right frame for the scope and the right node.

Also added a debug test.
parent d0ae301e
Branches
No related tags found
No related merge requests found
......@@ -24,8 +24,6 @@ package com.oracle.truffle.r.runtime.env;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.frame.Frame;
import com.oracle.truffle.api.frame.FrameInstance;
import com.oracle.truffle.api.frame.MaterializedFrame;
import com.oracle.truffle.api.interop.ForeignAccess;
import com.oracle.truffle.api.interop.Message;
import com.oracle.truffle.api.interop.MessageResolution;
......@@ -38,8 +36,6 @@ import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.r.runtime.ArgumentsSignature;
import com.oracle.truffle.r.runtime.RArguments;
import com.oracle.truffle.r.runtime.RInternalError;
import com.oracle.truffle.r.runtime.Utils;
import com.oracle.truffle.r.runtime.VirtualEvalFrame;
import com.oracle.truffle.r.runtime.data.RFunction;
import com.oracle.truffle.r.runtime.data.RStringVector;
import com.oracle.truffle.r.runtime.env.REnvironment.PutException;
......@@ -68,7 +64,7 @@ public final class RScope extends AbstractScope {
@Override
protected String getName() {
// TODO
// TODO promises (= closure)
return "function";
}
......@@ -82,29 +78,9 @@ public final class RScope extends AbstractScope {
return new VariablesMapObject(env, false);
}
private static MaterializedFrame getCallerFrame(Frame frame) {
MaterializedFrame funFrame = RArguments.getCallerFrame(frame);
if (funFrame == null) {
Frame callerFrame = Utils.getCallerFrame(frame, FrameInstance.FrameAccess.MATERIALIZE);
if (callerFrame != null) {
return callerFrame.materialize();
} else {
// S3 method can be dispatched from top-level where there is no caller frame
return frame.materialize();
}
}
return funFrame;
}
private static REnvironment getEnv(Frame frame) {
// TODO deopt frame
// PromiseDeoptimizeFrameNode deoptFrameNode = new PromiseDeoptimizeFrameNode();
MaterializedFrame matFrame = getCallerFrame(frame);
matFrame = matFrame instanceof VirtualEvalFrame ? ((VirtualEvalFrame) matFrame).getOriginalFrame() : matFrame;
// deoptFrameNode.deoptimizeFrame(matFrame);
return REnvironment.frameToEnvironment(matFrame);
assert RArguments.isRFrame(frame);
return REnvironment.frameToEnvironment(frame.materialize());
}
@Override
......
......@@ -38,6 +38,7 @@ import org.junit.Before;
import org.junit.Test;
import com.oracle.truffle.api.debug.Breakpoint;
import com.oracle.truffle.api.debug.DebugScope;
import com.oracle.truffle.api.debug.DebugStackFrame;
import com.oracle.truffle.api.debug.DebugValue;
import com.oracle.truffle.api.debug.Debugger;
......@@ -230,6 +231,42 @@ public class FastRDebugTest {
assertExecutedOK();
}
@Test
public void testScope() throws Throwable {
final Source srcFunMain = RSource.fromTextInternal("function () {\n" +
" i = 3L\n" +
" n = 15\n" +
" str = \"hello\"\n" +
" i <- i + 1L\n" +
" ab <<- i\n" +
" i\n" +
"}", RSource.Internal.DEBUGTEST_DEBUG);
final Source source = RSource.fromTextInternal("x <- 10L\n" +
"makeActiveBinding('ab', function(v) { if(missing(v)) x else x <<- v }, .GlobalEnv)\n" +
"main <- " + srcFunMain.getCode() + "\n",
RSource.Internal.DEBUGTEST_DEBUG);
engine.eval(source);
// @formatter:on
run.addLast(() -> {
assertNull(suspendedEvent);
assertNotNull(debuggerSession);
debuggerSession.suspendNextExecution();
});
assertLocation(1, "main()", "x", 10, "ab", 10, "main", srcFunMain.getCode());
stepInto(1);
assertLocation(4, "i = 3L");
stepOut();
assertLocation(1, "main()", "x", 4, "ab", 4, "main", srcFunMain.getCode());
performWork();
final Source evalSource = RSource.fromTextInternal("main()\n", RSource.Internal.DEBUGTEST_EVAL);
engine.eval(evalSource);
assertExecutedOK();
}
private void performWork() {
try {
if (ex == null && !run.isEmpty()) {
......@@ -279,17 +316,20 @@ public class FastRDebugTest {
});
assertEquals(line + ": " + code, expectedFrame.length / 2, numFrameVars.get());
DebugScope scope = frame.getScope();
for (int i = 0; i < expectedFrame.length; i = i + 2) {
String expectedIdentifier = (String) expectedFrame[i];
Object expectedValue = expectedFrame[i + 1];
String expectedValueStr = (expectedValue != null) ? expectedValue.toString() : null;
DebugValue value = frame.getValue(expectedIdentifier);
DebugValue value = scope.getDeclaredValue(expectedIdentifier);
assertNotNull(value);
String valueStr = value.as(String.class);
assertEquals(expectedValueStr, valueStr);
}
run.removeFirst().run();
if (!run.isEmpty()) {
run.removeFirst().run();
}
} catch (RuntimeException | Error e) {
final DebugStackFrame frame = suspendedEvent.getTopStackFrame();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment