Skip to content

Commit

Permalink
fix: added numberOfStackRows() method to avoid repetition + ras (#1431)
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierBBB authored Oct 17, 2024
1 parent e1ef888 commit f01738f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

public class StackOnlySection extends TraceSection {
public StackOnlySection(Hub hub) {
super(hub, (short) (hub.opCode().getData().stackSettings().twoLineInstruction() ? 2 : 1));
super(hub, (short) (hub.opCode().getData().numberOfStackRows()));

this.addStack(hub);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private List<TraceFragment> makeStackFragments(final Hub hub, CallFrame f) {
final List<TraceFragment> r = new ArrayList<>(2);
Stack snapshot = f.stack().snapshot();
if (f.pending().lines().isEmpty()) {
for (int i = 0; i < (f.opCodeData().stackSettings().twoLineInstruction() ? 2 : 1); i++) {
for (int i = 0; i < (f.opCodeData().numberOfStackRows()); i++) {
r.add(
StackFragment.prepare(
hub,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public boolean isAnyOf(OpCode... opCodes) {
}

public short numberOfStackRows() {
return (short) (this.getData().stackSettings().twoLineInstruction() ? 2 : 1);
return (short) (this.getData().numberOfStackRows());
}

public boolean mayTriggerStackUnderflow() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,8 @@ public boolean isInvalid() {
public boolean isMxp() {
return this.billing().type() != MxpType.NONE;
}

public int numberOfStackRows() {
return stackSettings.twoLineInstruction() ? 2 : 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -375,13 +375,13 @@ public void processInstruction(final Hub hub, MessageFrame frame, int stackStamp
currentOpcodeData = hub.opCodeData();
callFrame.pending(new StackContext(currentOpcodeData.mnemonic()));

final int alpha = currentOpcodeData.stackSettings().alpha();
final int delta = currentOpcodeData.stackSettings().delta();
final short delta = (short) currentOpcodeData.stackSettings().delta();
final short alpha = (short) currentOpcodeData.stackSettings().alpha();

Preconditions.checkArgument(heightNew == frame.stackSize());
height = (short) frame.stackSize();
heightNew += currentOpcodeData.stackSettings().nbAdded();
heightNew -= currentOpcodeData.stackSettings().nbRemoved();
heightNew -= delta;
heightNew += alpha;

if (frame.stackSize() < delta) { // Testing for underflow
status = Status.UNDERFLOW;
Expand Down Expand Up @@ -411,12 +411,8 @@ public void processInstruction(final Hub hub, MessageFrame frame, int stackStamp

if (status.isFailure()) {
heightNew = 0;

if (currentOpcodeData.stackSettings().twoLineInstruction()) {
stamp += callFrame.pending().addEmptyLines(2);
} else {
stamp += callFrame.pending().addEmptyLines(1);
}
final int numberOfStackRows = currentOpcodeData.numberOfStackRows();
callFrame.pending().addEmptyLines(numberOfStackRows);

return;
}
Expand Down

0 comments on commit f01738f

Please sign in to comment.