Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

numberOfStackRows() method to avoid repetition + minor clean up #1431

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading