Skip to content

Commit 503058c

Browse files
committed
Make assignments with yields properly resumable
1 parent b988581 commit 503058c

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/parser/sst/FactorySSTVisitor.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public ExpressionNode asExpression(PNode node) {
251251
}
252252
}
253253

254-
protected StatementNode createAssignmentBlock(@SuppressWarnings("unused") AssignmentSSTNode node, StatementNode... statements) {
254+
protected StatementNode createResumableBlock(@SuppressWarnings("unused") boolean canYield, StatementNode... statements) {
255255
return BlockNode.create(statements);
256256
}
257257

@@ -303,6 +303,7 @@ public PNode visit(AssertSSTNode node) {
303303
@Override
304304
public PNode visit(AssignmentSSTNode node) {
305305
ExpressionNode[] lhs = new ExpressionNode[node.lhs.length];
306+
int numYields = getCurrentNumberOfYields();
306307
for (int i = 0; i < node.lhs.length; i++) {
307308
SSTNode sstLhs = node.lhs[i];
308309
checkCannotAssignTo(sstLhs);
@@ -311,7 +312,7 @@ public PNode visit(AssignmentSSTNode node) {
311312
ExpressionNode rhs = (ExpressionNode) node.rhs.accept(this);
312313

313314
StatementNode result;
314-
if (lhs.length == 1) {
315+
if (lhs.length == 1 && !hadYieldSince(numYields)) {
315316
result = createAssignment(lhs[0], rhs);
316317
} else {
317318
int len = lhs.length;
@@ -322,7 +323,7 @@ public PNode visit(AssignmentSSTNode node) {
322323
for (int i = 0; i < len; i++) {
323324
assignments[i + 1] = createAssignment(lhs[i], (ExpressionNode) tmp);
324325
}
325-
result = createAssignmentBlock(node, assignments);
326+
result = createResumableBlock(hadYieldSince(numYields), assignments);
326327
}
327328
result.assignSourceSection(createSourceSection(node.startOffset, node.endOffset));
328329
return result;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/parser/sst/GeneratorFactorySSTVisitor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ public GeneratorInfo.Mutable getMutableGeneratorInfo() {
114114
}
115115

116116
@Override
117-
protected StatementNode createAssignmentBlock(AssignmentSSTNode node, StatementNode... statements) {
118-
if (node.rhs instanceof YieldExpressionSSTNode) {
117+
protected StatementNode createResumableBlock(boolean canYield, StatementNode... statements) {
118+
if (canYield) {
119119
return GeneratorBlockNode.create(statements, generatorInfo);
120120
} else {
121121
return BlockNode.create(statements);

0 commit comments

Comments
 (0)