Skip to content

Commit 4c49b79

Browse files
committed
use executeVoid whereever possible (in preparation of splitting statements/expressions)
1 parent 8b6009f commit 4c49b79

File tree

15 files changed

+67
-51
lines changed

15 files changed

+67
-51
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/NodeFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public LoopNode createWhile(CastToBooleanNode condition, PNode body) {
176176
}
177177

178178
public StatementNode createIf(CastToBooleanNode condition, PNode thenPart, PNode elsePart) {
179-
return IfNode.create(condition, thenPart, elsePart);
179+
return new IfNode(condition, thenPart, elsePart);
180180
}
181181

182182
public GetIteratorNode createGetIterator(PNode collection) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/control/ElseNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public PNode getOrelse() {
4949

5050
@Override
5151
public Object execute(VirtualFrame frame) {
52-
then.execute(frame);
52+
then.executeVoid(frame);
5353
return orelse.execute(frame);
5454
}
5555
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/control/IfNode.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,18 @@
3030
import com.oracle.graal.python.nodes.statement.StatementNode;
3131
import com.oracle.truffle.api.frame.VirtualFrame;
3232

33-
public class IfNode extends StatementNode {
34-
@Child protected CastToBooleanNode condition;
35-
@Child protected PNode then;
36-
@Child protected PNode orelse;
33+
public final class IfNode extends StatementNode {
34+
35+
@Child private CastToBooleanNode condition;
36+
@Child private PNode then;
37+
@Child private PNode orelse;
3738

3839
public IfNode(CastToBooleanNode condition, PNode then, PNode orelse) {
3940
this.condition = condition;
4041
this.then = then;
4142
this.orelse = orelse;
4243
}
4344

44-
public static IfNode create(CastToBooleanNode condition, PNode then, PNode orelse) {
45-
return new IfNode(condition, then, orelse);
46-
}
47-
4845
public CastToBooleanNode getCondition() {
4946
return condition;
5047
}
@@ -65,4 +62,13 @@ public Object execute(VirtualFrame frame) {
6562
return orelse.execute(frame);
6663
}
6764
}
65+
66+
@Override
67+
public void executeVoid(VirtualFrame frame) {
68+
if (condition.executeBoolean(frame)) {
69+
then.executeVoid(frame);
70+
} else {
71+
orelse.executeVoid(frame);
72+
}
73+
}
6874
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/control/ReturnNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public PNode getRight() {
5151

5252
@Override
5353
public Object execute(VirtualFrame frame) {
54-
right.execute(frame);
54+
right.executeVoid(frame);
5555
throw ReturnException.INSTANCE;
5656
}
5757

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/control/ReturnTargetNode.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@
3030
import com.oracle.graal.python.nodes.statement.StatementNode;
3131
import com.oracle.graal.python.runtime.exception.ReturnException;
3232
import com.oracle.truffle.api.frame.VirtualFrame;
33+
import com.oracle.truffle.api.profiles.BranchProfile;
3334

34-
public class ReturnTargetNode extends StatementNode {
35+
public final class ReturnTargetNode extends StatementNode {
3536

36-
@Child protected PNode body;
37-
@Child protected PNode returnValue;
37+
@Child private PNode body;
38+
@Child private PNode returnValue;
39+
40+
private final BranchProfile returnProfile = BranchProfile.create();
41+
private final BranchProfile fallthroughProfile = BranchProfile.create();
3842

3943
public ReturnTargetNode(PNode body, PNode returnValue) {
4044
this.body = body;
4145
this.returnValue = returnValue;
4246
}
4347

44-
protected ReturnTargetNode(ReturnTargetNode prev) {
45-
this(prev.body, prev.returnValue);
46-
}
47-
4848
public PNode getBody() {
4949
return body;
5050
}
@@ -56,10 +56,12 @@ public PNode getReturn() {
5656
@Override
5757
public Object execute(VirtualFrame frame) {
5858
try {
59-
body.execute(frame);
59+
body.executeVoid(frame);
60+
fallthroughProfile.enter();
61+
return PNone.NONE;
6062
} catch (ReturnException ire) {
63+
returnProfile.enter();
6164
return returnValue.execute(frame);
6265
}
63-
return PNone.NONE;
6466
}
6567
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/control/WhileNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public boolean executeRepeating(VirtualFrame frame) {
4949
if (!condition.executeBoolean(frame)) {
5050
return false;
5151
}
52-
body.execute(frame);
52+
body.executeVoid(frame);
5353
return true;
5454
}
5555
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/generator/GeneratorIfNode.java

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,19 @@
2828
import com.oracle.graal.python.builtins.objects.PNone;
2929
import com.oracle.graal.python.nodes.EmptyNode;
3030
import com.oracle.graal.python.nodes.PNode;
31-
import com.oracle.graal.python.nodes.control.IfNode;
3231
import com.oracle.graal.python.nodes.expression.CastToBooleanNode;
32+
import com.oracle.graal.python.nodes.statement.StatementNode;
3333
import com.oracle.graal.python.runtime.exception.YieldException;
3434
import com.oracle.truffle.api.frame.VirtualFrame;
3535
import com.oracle.truffle.api.profiles.BranchProfile;
3636
import com.oracle.truffle.api.profiles.ConditionProfile;
3737

38-
public class GeneratorIfNode extends IfNode implements GeneratorControlNode {
38+
public class GeneratorIfNode extends StatementNode implements GeneratorControlNode {
3939

4040
@Child protected GeneratorAccessNode gen = GeneratorAccessNode.create();
41+
@Child protected CastToBooleanNode condition;
42+
@Child protected PNode then;
43+
@Child protected PNode orelse;
4144

4245
protected final int thenFlagSlot;
4346
protected final int elseFlagSlot;
@@ -48,7 +51,9 @@ public class GeneratorIfNode extends IfNode implements GeneratorControlNode {
4851
protected final BranchProfile seenYield = BranchProfile.create();
4952

5053
public GeneratorIfNode(CastToBooleanNode condition, PNode then, PNode orelse, int thenFlagSlot, int elseFlagSlot) {
51-
super(condition, then, orelse);
54+
this.condition = condition;
55+
this.then = then;
56+
this.orelse = orelse;
5257
this.thenFlagSlot = thenFlagSlot;
5358
this.elseFlagSlot = elseFlagSlot;
5459
}
@@ -61,14 +66,6 @@ public static GeneratorIfNode create(CastToBooleanNode condition, PNode then, PN
6166
}
6267
}
6368

64-
public int getThenFlagSlot() {
65-
return thenFlagSlot;
66-
}
67-
68-
public int getElseFlagSlot() {
69-
return elseFlagSlot;
70-
}
71-
7269
@Override
7370
public Object execute(VirtualFrame frame) {
7471
boolean startThenFlag = gen.isActive(frame, thenFlagSlot);
@@ -82,9 +79,9 @@ public Object execute(VirtualFrame frame) {
8279
thenFlag = condition.executeBoolean(frame);
8380
}
8481
if (thenFlag) {
85-
then.execute(frame);
82+
then.executeVoid(frame);
8683
} else {
87-
orelse.execute(frame);
84+
orelse.executeVoid(frame);
8885
}
8986
return PNone.NONE;
9087
} catch (YieldException e) {
@@ -122,7 +119,7 @@ public Object execute(VirtualFrame frame) {
122119
thenFlag = condition.executeBoolean(frame);
123120
}
124121
if (thenFlag) {
125-
then.execute(frame);
122+
then.executeVoid(frame);
126123
}
127124
return PNone.NONE;
128125
} catch (YieldException e) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/generator/GeneratorReturnTargetNode.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,28 @@
2828
import static com.oracle.graal.python.runtime.exception.PythonErrorType.StopIteration;
2929

3030
import com.oracle.graal.python.nodes.PNode;
31-
import com.oracle.graal.python.nodes.control.ReturnTargetNode;
31+
import com.oracle.graal.python.nodes.statement.StatementNode;
3232
import com.oracle.graal.python.runtime.exception.ReturnException;
3333
import com.oracle.graal.python.runtime.exception.YieldException;
3434
import com.oracle.truffle.api.frame.VirtualFrame;
35+
import com.oracle.truffle.api.profiles.BranchProfile;
3536

36-
public final class GeneratorReturnTargetNode extends ReturnTargetNode implements GeneratorControlNode {
37+
public final class GeneratorReturnTargetNode extends StatementNode implements GeneratorControlNode {
3738

39+
@Child private PNode body;
40+
@Child private PNode returnValue;
3841
@Child private PNode parameters;
3942
@Child private GeneratorAccessNode gen = GeneratorAccessNode.create();
4043

44+
private final BranchProfile returnProfile = BranchProfile.create();
45+
private final BranchProfile fallthroughProfile = BranchProfile.create();
46+
private final BranchProfile yieldProfile = BranchProfile.create();
47+
4148
private final int flagSlot;
4249

4350
public GeneratorReturnTargetNode(PNode parameters, PNode body, PNode returnValue, int activeFlagIndex) {
44-
super(body, returnValue);
51+
this.body = body;
52+
this.returnValue = returnValue;
4553
this.parameters = parameters;
4654
this.flagSlot = activeFlagIndex;
4755
}
@@ -58,11 +66,14 @@ public Object execute(VirtualFrame frame) {
5866
}
5967

6068
try {
61-
body.execute(frame);
69+
body.executeVoid(frame);
70+
fallthroughProfile.enter();
6271
} catch (YieldException eye) {
72+
yieldProfile.enter();
6373
return returnValue.execute(frame);
6474
} catch (ReturnException ire) {
6575
// return statement in generators throws StopIteration.
76+
returnProfile.enter();
6677
}
6778

6879
throw raise(StopIteration);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/generator/GeneratorTryExceptNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public Object execute(VirtualFrame frame) {
8282
}
8383

8484
try {
85-
getBody().execute(frame);
85+
getBody().executeVoid(frame);
8686
} catch (PException ex) {
8787
gen.setActive(frame, exceptFlag, true);
8888
gen.setActiveException(frame, ex);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/generator/GeneratorTryFinallyNode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ public Object execute(VirtualFrame frame) {
6262
PException exceptionState = getContext().getCurrentException();
6363
PException exception = null;
6464
if (gen.isActive(frame, finallyFlag)) {
65-
getFinalbody().execute(frame);
65+
getFinalbody().executeVoid(frame);
6666
} else {
6767
try {
68-
getBody().execute(frame);
68+
getBody().executeVoid(frame);
6969
} catch (PException e) {
7070
exception = e;
7171
}
7272
gen.setActive(frame, finallyFlag, true);
73-
getFinalbody().execute(frame);
73+
getFinalbody().executeVoid(frame);
7474
}
7575
reset(frame);
7676
if (exception != null) {

0 commit comments

Comments
 (0)