Skip to content

Commit a97d544

Browse files
committed
Store the correct BytecodeNode for generator frames in DSL
1 parent d0eda62 commit a97d544

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/GeneratorBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,10 @@ static Object getFrame(PGenerator self) {
189189
return PNone.NONE;
190190
} else {
191191
if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) {
192-
BytecodeLocation location = self.getCurrentRootNode().getLocation();
193192
MaterializedFrame generatorFrame = self.getGeneratorFrame();
194193
BytecodeDSLFrameInfo info = (BytecodeDSLFrameInfo) generatorFrame.getFrameDescriptor().getInfo();
195-
PFrame frame = MaterializeFrameNode.materializeGeneratorFrame(location != null ? location.getBytecodeNode() : null, generatorFrame, PFrame.Reference.EMPTY);
194+
PFrame frame = MaterializeFrameNode.materializeGeneratorFrame(self.getBytecodeNode(), generatorFrame, PFrame.Reference.EMPTY);
195+
BytecodeLocation location = self.getCurrentLocation();
196196
if (location != null) {
197197
int bci = location.getBytecodeIndex();
198198
frame.setBci(bci);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/PGenerator.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
4848
import com.oracle.truffle.api.RootCallTarget;
4949
import com.oracle.truffle.api.TruffleStackTraceElement;
50+
import com.oracle.truffle.api.bytecode.BytecodeLocation;
51+
import com.oracle.truffle.api.bytecode.BytecodeNode;
5052
import com.oracle.truffle.api.bytecode.ContinuationResult;
5153
import com.oracle.truffle.api.bytecode.ContinuationRootNode;
5254
import com.oracle.truffle.api.frame.Frame;
@@ -116,17 +118,20 @@ public Object handleResult(PythonLanguage language, GeneratorYieldResult result)
116118
private static class BytecodeDSLState {
117119
private final PBytecodeDSLRootNode rootNode;
118120
private final Object[] arguments;
121+
private BytecodeNode bytecodeNode;
119122
private ContinuationRootNode continuationRootNode;
120123
private boolean isStarted;
121124

122125
public BytecodeDSLState(PBytecodeDSLRootNode rootNode, Object[] arguments, ContinuationRootNode continuationRootNode) {
123126
this.rootNode = rootNode;
124127
this.arguments = arguments;
125128
this.continuationRootNode = continuationRootNode;
129+
this.bytecodeNode = rootNode.getBytecodeNode();
126130
}
127131

128132
public Object handleResult(ContinuationResult result) {
129133
isStarted = true;
134+
bytecodeNode = continuationRootNode.getLocation().getBytecodeNode();
130135
continuationRootNode = result.getContinuationRootNode();
131136
return result.getResult();
132137
}
@@ -312,9 +317,17 @@ public RootCallTarget getCurrentCallTarget() {
312317
}
313318
}
314319

315-
public ContinuationRootNode getCurrentRootNode() {
320+
/**
321+
* Return the BytecodeNode that should be used for accessing the frame
322+
*/
323+
public BytecodeNode getBytecodeNode() {
324+
assert PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER;
325+
return getBytecodeDSLState().bytecodeNode;
326+
}
327+
328+
public BytecodeLocation getCurrentLocation() {
316329
assert PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER;
317-
return getBytecodeDSLState().continuationRootNode;
330+
return getBytecodeDSLState().continuationRootNode.getLocation();
318331
}
319332

320333
public Object getYieldFrom() {
@@ -327,7 +340,7 @@ public Object getYieldFrom() {
327340
if (rootNode.yieldFromGeneratorIndex == -1 || !getBytecodeDSLState().isStarted) {
328341
return null;
329342
}
330-
return rootNode.getBytecodeNode().getLocalValue(0, getGeneratorFrame(), rootNode.yieldFromGeneratorIndex);
343+
return getBytecodeNode().getLocalValue(0, getGeneratorFrame(), rootNode.yieldFromGeneratorIndex);
331344
} else {
332345
return frameInfo.getYieldFrom(frame, getBci(), getBytecodeState().getCurrentRootNode().getResumeStackTop());
333346
}

0 commit comments

Comments
 (0)