Skip to content

Commit fb52182

Browse files
author
Adam Hrbac
committed
Remove magic numbers
1 parent 56360a0 commit fb52182

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/PFrame.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ public final class PFrame extends PythonBuiltinObject {
7676

7777
// -3 for jumps not allowed, -2 for no jump, otherwise the line to jump to - only should be set
7878
// in a trace function.
79-
private int jumpDestLine = -3;
79+
public static final int DISALLOW_JUMPS = -3;
80+
public static final int NO_JUMP = -2;
81+
private int jumpDestLine = DISALLOW_JUMPS;
8082
private Object localTraceFun = null;
8183

8284
private boolean traceLine = true;
@@ -100,7 +102,7 @@ public void setTraceLine(boolean traceLine) {
100102
}
101103

102104
public boolean isTraceArgument() {
103-
return jumpDestLine != -3;
105+
return jumpDestLine != DISALLOW_JUMPS;
104106
}
105107

106108
public int getJumpDestLine() {
@@ -244,7 +246,7 @@ public void lineUnlock() {
244246
}
245247

246248
public boolean didJump() {
247-
return jumpDestLine > -2;
249+
return jumpDestLine > NO_JUMP;
248250
}
249251

250252
@TruffleBoundary

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2929,15 +2929,17 @@ private int traceLine(VirtualFrame virtualFrame, MutableLoopData mutableData, by
29292929
return bci;
29302930
}
29312931
if (pyFrame.getTraceLine()) {
2932-
pyFrame.setJumpDestLine(-2);
2932+
pyFrame.setJumpDestLine(PFrame.NO_JUMP); // jumps from live event allowed
29332933
invokeTraceFunction(virtualFrame, null, mutableData.getThreadState(this), mutableData, PythonContext.TraceEvent.LINE,
29342934
mutableData.getPastLine(), true);
29352935
if (pyFrame.didJump()) {
29362936
int newBci = lineToBci(pyFrame.getJumpDestLine());
29372937
mutableData.setPastBci(bci);
29382938
if (newBci == -1) {
2939+
// line before the code block
29392940
throw PRaiseNode.getUncached().raise(ValueError, ErrorMessages.LINE_D_COMES_AFTER_THE_CURRENT_CODE_BLOCK, pyFrame.getLine());
29402941
} else if (newBci == -2) {
2942+
// line after the code block
29412943
throw PRaiseNode.getUncached().raise(ValueError, ErrorMessages.LINE_D_COMES_BEFORE_THE_CURRENT_CODE_BLOCK, pyFrame.getJumpDestLine());
29422944
} else {
29432945
var stacks = co.computeStackElems();
@@ -2950,7 +2952,7 @@ private int traceLine(VirtualFrame virtualFrame, MutableLoopData mutableData, by
29502952
}
29512953
}
29522954
}
2953-
pyFrame.setJumpDestLine(-3);
2955+
pyFrame.setJumpDestLine(PFrame.DISALLOW_JUMPS);
29542956
}
29552957
mutableData.setPastBci(bci);
29562958
return ret;

0 commit comments

Comments
 (0)