diff --git a/bjforth/src/main/java/bjforth/machine/Machine.java b/bjforth/src/main/java/bjforth/machine/Machine.java
index e12ef010..744d3e60 100644
--- a/bjforth/src/main/java/bjforth/machine/Machine.java
+++ b/bjforth/src/main/java/bjforth/machine/Machine.java
@@ -102,20 +102,49 @@ public void jumpTo(Integer address) {
state.setInstructionPointer(address);
}
- /**
- * Executes exactly ONE memory cell and stops.
- *
- *
To be used for debugging/testing purposes.
- */
+ public void DOCOL(Boolean calledByPrimitive) {
+ pushToReturnStack(getNextInstructionPointer());
+ if (!calledByPrimitive) {
+ setNextInstructionPointer(getInstrcutionPointer() + 1);
+ }
+ }
+
+ private Integer threadedCodeDepth = 0;
+
+ public void enterThreadedCode() {
+ threadedCodeDepth += 1;
+ }
+
+ public void exitThreadedCode() {
+ if (threadedCodeDepth == 0) {
+ throw new MachineException("Invalid threadedCode depth.");
+ } else {
+ threadedCodeDepth -= 1;
+ }
+ }
+
+ private void applyThreadedCode(Integer IP) {
+ if (threadedCodeDepth > 0) {
+ setNextInstructionPointer(IP + 1);
+ }
+ }
+
+ /** Executes exactly ONE memory cell and stops. */
public void step() {
var IP = state.getInstructionPointer();
var content = getMemoryAt(IP);
if (content instanceof NativeSubroutine nativeSubroutine) {
nativeSubroutine.call(this);
} else if (content instanceof Integer address) {
- state.setInstructionPointer(address);
+ jumpTo(address);
+ applyThreadedCode(IP);
+ } else if (content instanceof String s && "DOCOL".equals(s)) {
+ enterThreadedCode();
+ DOCOL(false);
+ jumpTo(getInstrcutionPointer() + 1);
} else {
- throw new MachineException("don't know how to execute *(%d)".formatted(IP));
+ // throw new MachineException("don't know how to execute *(%d)".formatted(IP));
+ jumpTo(getInstrcutionPointer() + 1);
}
}
@@ -136,4 +165,16 @@ public void loop() {
step();
}
}
+
+ public static void main(String[] args) {
+ System.out.println("bjForth ");
+ System.out.println("⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯");
+
+ var state = new MachineState(0, 0, new Memory(), new Dictionary(), new Stack(), new Stack());
+ var machine = new Machine(state); // Bootstraps the components like memory and dictionary
+ var QUITaddr = machine.getDictionaryItem("QUIT").get().getAddress();
+ machine.setNextInstructionPointer(machine.getDictionaryItem("INTERPRET").get().getAddress());
+ machine.jumpTo(QUITaddr);
+ machine.loop();
+ }
}
diff --git a/bjforth/src/main/java/bjforth/machine/Stack.java b/bjforth/src/main/java/bjforth/machine/Stack.java
index d2617e4d..c930fcd1 100644
--- a/bjforth/src/main/java/bjforth/machine/Stack.java
+++ b/bjforth/src/main/java/bjforth/machine/Stack.java
@@ -35,11 +35,11 @@ class Stack {
}
public Object pop() {
- return data.removeLast();
+ return data.removeFirst();
}
public void push(Object item) {
- data.addLast(item);
+ data.addFirst(item);
}
public Object peek() {
diff --git a/bjforth/src/main/java/bjforth/primitives/COLON.java b/bjforth/src/main/java/bjforth/primitives/COLON.java
index 902cbb95..d3ddc504 100644
--- a/bjforth/src/main/java/bjforth/primitives/COLON.java
+++ b/bjforth/src/main/java/bjforth/primitives/COLON.java
@@ -26,12 +26,12 @@
public class COLON implements Primitive {
@Override
public void execute(Machine machine) {
+ machine.DOCOL(true);
WORD().execute(machine);
CREATE().execute(machine);
var LATESTvalue = (Integer) machine.getMemoryAt(Variables.get("LATEST").getAddress());
- var DOCOLaddr = machine.getDictionaryItem("DOCOL").get().getAddress();
- machine.setMemoryAt(LATESTvalue, DOCOLaddr);
+ machine.setMemoryAt(LATESTvalue, "DOCOL");
machine.setMemoryAt(Variables.get("HERE").getAddress(), LATESTvalue + 1);
machine.pushToParameterStack(LATESTvalue);
HIDDEN().execute(machine);
diff --git a/bjforth/src/main/java/bjforth/primitives/EXIT.java b/bjforth/src/main/java/bjforth/primitives/EXIT.java
index 494b27fd..b186b1fe 100644
--- a/bjforth/src/main/java/bjforth/primitives/EXIT.java
+++ b/bjforth/src/main/java/bjforth/primitives/EXIT.java
@@ -28,6 +28,7 @@ public void execute(Machine machine) {
try {
var value = (Integer) machine.popFromReturnStack();
machine.setNextInstructionPointer(value);
+ machine.exitThreadedCode();
} catch (NoSuchElementException _ex) {
throw new MachineException("Return stack empty.");
}
diff --git a/bjforth/src/main/java/bjforth/primitives/INTERPRET.java b/bjforth/src/main/java/bjforth/primitives/INTERPRET.java
index eb8cee90..c81b6526 100644
--- a/bjforth/src/main/java/bjforth/primitives/INTERPRET.java
+++ b/bjforth/src/main/java/bjforth/primitives/INTERPRET.java
@@ -18,6 +18,9 @@
*/
package bjforth.primitives;
+import static bjforth.primitives.PrimitiveFactory.FIND;
+import static bjforth.primitives.PrimitiveFactory.WORD;
+
import bjforth.machine.Machine;
import bjforth.machine.MachineException;
import bjforth.variables.Variables;
@@ -29,13 +32,13 @@ public void execute(Machine machine) {
var HEREaddr = Variables.get("HERE").getAddress();
var HEREvalue = (Integer) machine.getMemoryAt(HEREaddr);
- PrimitiveFactory.WORD().execute(machine);
+ WORD().execute(machine);
var obj = machine.peekIntoParameterStack();
try {
- PrimitiveFactory.FIND().execute(machine);
+ FIND().execute(machine);
var dictItem = machine.getDictionaryItem((Integer) machine.popFromParameterStack()).get();
if (STATE == 0 || dictItem.getIsImmediate()) {
- machine.setNextInstructionPointer(dictItem.getAddress());
+ machine.jumpTo(dictItem.getAddress());
} else {
machine.setMemoryAt(HEREvalue, dictItem.getAddress());
machine.setMemoryAt(HEREaddr, (Integer) machine.getMemoryAt(HEREaddr) + 1);
@@ -62,4 +65,9 @@ public void execute(Machine machine) {
}
}
}
+
+ @Override
+ public Boolean isBypassNextInstructionPointer() {
+ return true;
+ }
}
diff --git a/bjforth/src/main/java/bjforth/primitives/Primitive.java b/bjforth/src/main/java/bjforth/primitives/Primitive.java
index f00f1e3c..0e9b43ea 100644
--- a/bjforth/src/main/java/bjforth/primitives/Primitive.java
+++ b/bjforth/src/main/java/bjforth/primitives/Primitive.java
@@ -27,9 +27,8 @@ public interface Primitive extends NativeSubroutine {
default void call(Machine machine) {
execute(machine);
if (!isBypassNextInstructionPointer()) {
- var nextWordAddr = machine.getNextInstructionPointer();
- machine.setNextInstructionPointer(nextWordAddr + 1);
- machine.jumpTo(nextWordAddr);
+ var NIP = machine.getNextInstructionPointer();
+ machine.jumpTo(NIP);
}
}
diff --git a/bjforth/src/main/java/bjforth/primitives/PrimitiveFactory.java b/bjforth/src/main/java/bjforth/primitives/PrimitiveFactory.java
index ddc2e7f1..92d680cb 100644
--- a/bjforth/src/main/java/bjforth/primitives/PrimitiveFactory.java
+++ b/bjforth/src/main/java/bjforth/primitives/PrimitiveFactory.java
@@ -107,12 +107,6 @@ static Primitive DIV() {
return containerDIV.get();
}
- private static PrimitiveContainer containerDOCOL = new PrimitiveContainer(DOCOL::new);
-
- static Primitive DOCOL() {
- return containerDOCOL.get();
- }
-
private static PrimitiveContainer containerDROP = new PrimitiveContainer(DROP::new);
static Primitive DROP() {
@@ -395,6 +389,12 @@ static Primitive TOR() {
return containerTOR.get();
}
+ private static PrimitiveContainer containerTOSTRING = new PrimitiveContainer(TOSTRING::new);
+
+ static Primitive TOSTRING() {
+ return containerTOSTRING.get();
+ }
+
private static PrimitiveContainer containerTWODROP = new PrimitiveContainer(TWODROP::new);
static Primitive TWODROP() {
@@ -477,7 +477,6 @@ static Primitive ZNEQU() {
containerDECR4,
containerDFA,
containerDIV,
- containerDOCOL,
containerDROP,
containerDSPFETCH,
containerDSPSTORE,
@@ -525,6 +524,7 @@ static Primitive ZNEQU() {
containerSWAP,
containerTELL,
containerTOR,
+ containerTOSTRING,
containerTWODROP,
containerTWODUP,
containerTWOSWAP,
diff --git a/bjforth/src/main/java/bjforth/primitives/QUIT.java b/bjforth/src/main/java/bjforth/primitives/QUIT.java
index 9e9e0776..b0866ba7 100644
--- a/bjforth/src/main/java/bjforth/primitives/QUIT.java
+++ b/bjforth/src/main/java/bjforth/primitives/QUIT.java
@@ -25,15 +25,14 @@ public class QUIT implements Primitive {
@Override
public void execute(Machine machine) {
+ machine.DOCOL(true);
try {
while (true) {
machine.popFromReturnStack();
}
} catch (NoSuchElementException _ex) { // Return stack is empty
}
- var nip = machine.getNextInstructionPointer();
- PrimitiveFactory.INTERPRET().execute(machine);
- machine.setNextInstructionPointer(nip);
+ machine.setNextInstructionPointer(machine.getDictionaryItem("QUIT").get().getAddress());
machine.jumpTo(machine.getDictionaryItem("INTERPRET").get().getAddress());
}
diff --git a/bjforth/src/main/java/bjforth/primitives/SEMICOLON.java b/bjforth/src/main/java/bjforth/primitives/SEMICOLON.java
index b389efa0..410eea25 100644
--- a/bjforth/src/main/java/bjforth/primitives/SEMICOLON.java
+++ b/bjforth/src/main/java/bjforth/primitives/SEMICOLON.java
@@ -26,8 +26,11 @@
public class SEMICOLON implements Primitive {
@Override
public void execute(Machine machine) {
+ machine.DOCOL(true);
+ machine.enterThreadedCode(); // TODO TO be removed.
var HEREvalue = (Integer) machine.getMemoryAt(Variables.get("HERE").getAddress());
machine.setMemoryAt(HEREvalue, machine.getDictionaryItem("EXIT").get().getAddress());
+ machine.setMemoryAt(Variables.get("HERE").getAddress(), HEREvalue + 1);
var LATESTvalue = (Integer) machine.getMemoryAt(Variables.get("LATEST").getAddress());
machine.pushToParameterStack(LATESTvalue);
HIDDEN().execute(machine);
@@ -44,9 +47,4 @@ public Boolean isImmediate() {
public String getName() {
return ";";
}
-
- @Override
- public Boolean isBypassNextInstructionPointer() {
- return true;
- }
}
diff --git a/bjforth/src/main/java/bjforth/primitives/DOCOL.java b/bjforth/src/main/java/bjforth/primitives/TOSTRING.java
similarity index 78%
rename from bjforth/src/main/java/bjforth/primitives/DOCOL.java
rename to bjforth/src/main/java/bjforth/primitives/TOSTRING.java
index 45344ce0..bf9cadc2 100644
--- a/bjforth/src/main/java/bjforth/primitives/DOCOL.java
+++ b/bjforth/src/main/java/bjforth/primitives/TOSTRING.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2022 Bahman Movaqar
+ * Copyright 2024 Bahman Movaqar
*
* This file is part of bjForth.
*
@@ -20,11 +20,10 @@
import bjforth.machine.Machine;
-class DOCOL implements Primitive {
-
+public class TOSTRING implements Primitive {
@Override
public void execute(Machine machine) {
- machine.pushToReturnStack(machine.getNextInstructionPointer());
- machine.setNextInstructionPointer(machine.getInstrcutionPointer() + 1);
+ var obj = machine.peekIntoParameterStack();
+ System.out.println(obj.toString());
}
}
diff --git a/bjforth/src/test/java/bjforth/primitives/ADDSTORETest.java b/bjforth/src/test/java/bjforth/primitives/ADDSTORETest.java
index 7080e246..6c75faff 100644
--- a/bjforth/src/test/java/bjforth/primitives/ADDSTORETest.java
+++ b/bjforth/src/test/java/bjforth/primitives/ADDSTORETest.java
@@ -19,12 +19,10 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
import static bjforth.machine.MemoryBuilder.aMemory;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.assertj.core.api.Assertions.*;
@@ -59,17 +57,12 @@ void worksOk() {
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
.hasMemoryEqualTo(
aMemory()
.with(referenceState)
.with(parameterAddress, parameterValue + increment)
.build())
- .hasParameterStackEqualTo(aParameterStack().build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().build());
}
@DisplayName("should throw if parameter stack top is not a number.")
diff --git a/bjforth/src/test/java/bjforth/primitives/ADDTest.java b/bjforth/src/test/java/bjforth/primitives/ADDTest.java
index fc9b0fd0..6e51f311 100644
--- a/bjforth/src/test/java/bjforth/primitives/ADDTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/ADDTest.java
@@ -19,12 +19,10 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
import static bjforth.machine.MemoryBuilder.aMemory;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.assertj.core.api.Assertions.*;
@@ -75,13 +73,7 @@ void worksOkWithNumbers(
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build());
}
@DisplayName("should throw if any of parameter stack top is not a number.")
diff --git a/bjforth/src/test/java/bjforth/primitives/BASETest.java b/bjforth/src/test/java/bjforth/primitives/BASETest.java
index 2814063e..d7deeec6 100644
--- a/bjforth/src/test/java/bjforth/primitives/BASETest.java
+++ b/bjforth/src/test/java/bjforth/primitives/BASETest.java
@@ -19,12 +19,10 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.assertThat;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
import static bjforth.machine.MemoryBuilder.aMemory;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import bjforth.variables.Variables;
@@ -33,7 +31,7 @@
class BASETest {
@Test
- @DisplayName("Push the value of HERE to parameter stack.")
+ @DisplayName("Push the value of BASE to parameter stack.")
public void worksOk() {
// GIVEN
var BASEaddr = getPrimitiveAddress("BASE");
@@ -52,13 +50,6 @@ public void worksOk() {
machine.step();
// THEN
- assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(10).build())
- .hasReturnStackEqualTo(referenceState);
+ assertThat(actualState).hasParameterStackEqualTo(aParameterStack().with(10).build());
}
}
diff --git a/bjforth/src/test/java/bjforth/primitives/BRANCHTest.java b/bjforth/src/test/java/bjforth/primitives/BRANCHTest.java
index 020a7947..74591bd4 100644
--- a/bjforth/src/test/java/bjforth/primitives/BRANCHTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/BRANCHTest.java
@@ -57,7 +57,7 @@ public void worksOk() {
assertThat(actualState)
.hasInstructionPointerEqualTo(anInstructionPointer().with(nip).plus(offset).build())
.hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(offset).plus(1).build())
+ aNextInstructionPointer().with(referenceState).plus(offset).build())
.hasMemoryEqualTo(referenceState)
.hasParameterStackEqualTo(aParameterStack().build())
.hasReturnStackEqualTo(referenceState);
diff --git a/bjforth/src/test/java/bjforth/primitives/CFATest.java b/bjforth/src/test/java/bjforth/primitives/CFATest.java
index 1486e676..2aa871f5 100644
--- a/bjforth/src/test/java/bjforth/primitives/CFATest.java
+++ b/bjforth/src/test/java/bjforth/primitives/CFATest.java
@@ -19,12 +19,10 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.assertThat;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
import static bjforth.machine.MemoryBuilder.aMemory;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.apache.commons.lang3.RandomUtils.nextInt;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -55,13 +53,7 @@ public void worksOk() {
machine.step();
// THEN
- assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().build())
- .hasReturnStackEqualTo(referenceState);
+ assertThat(actualState).hasParameterStackEqualTo(aParameterStack().build());
}
@Test
diff --git a/bjforth/src/test/java/bjforth/primitives/CHARTest.java b/bjforth/src/test/java/bjforth/primitives/CHARTest.java
index ca820d66..58d9e2d4 100644
--- a/bjforth/src/test/java/bjforth/primitives/CHARTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/CHARTest.java
@@ -19,11 +19,9 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.assertThat;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import java.io.ByteArrayInputStream;
@@ -71,11 +69,6 @@ void worksOk() {
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(wordStr, wordStr.charAt(0)).build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().with(wordStr, wordStr.charAt(0)).build());
}
}
diff --git a/bjforth/src/test/java/bjforth/primitives/COLONTest.java b/bjforth/src/test/java/bjforth/primitives/COLONTest.java
index e556a713..1e869eac 100644
--- a/bjforth/src/test/java/bjforth/primitives/COLONTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/COLONTest.java
@@ -77,7 +77,7 @@ void worksOk() {
.hasMemoryEqualTo(
aMemory()
.with(referenceState)
- .with(referenceLATESTvalue + 1, getPrimitiveAddress("DOCOL"))
+ .with(referenceLATESTvalue + 1, "DOCOL")
.with(Variables.get("HERE").getAddress(), referenceHEREvalue + 1)
.with(Variables.get("STATE").getAddress(), 1)
.with(Variables.get("LATEST").getAddress(), referenceLATESTvalue + 1)
diff --git a/bjforth/src/test/java/bjforth/primitives/COMMATest.java b/bjforth/src/test/java/bjforth/primitives/COMMATest.java
index d2be5004..6cc16f5e 100644
--- a/bjforth/src/test/java/bjforth/primitives/COMMATest.java
+++ b/bjforth/src/test/java/bjforth/primitives/COMMATest.java
@@ -19,12 +19,10 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.assertThat;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
import static bjforth.machine.MemoryBuilder.aMemory;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.apache.commons.lang3.RandomUtils.nextInt;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -59,17 +57,13 @@ public void worksOk() {
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
.hasMemoryEqualTo(
aMemory()
.with(referenceState)
.with(HEREvalue, parameter)
.with(HEREaddr, HEREvalue + 1)
.build())
- .hasParameterStackEqualTo(aParameterStack().build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().build());
}
@Test
diff --git a/bjforth/src/test/java/bjforth/primitives/COPYTest.java b/bjforth/src/test/java/bjforth/primitives/COPYTest.java
index f1a89ca3..4ff247f7 100644
--- a/bjforth/src/test/java/bjforth/primitives/COPYTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/COPYTest.java
@@ -19,12 +19,10 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
import static bjforth.machine.MemoryBuilder.aMemory;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static bjforth.utils.RandomUtils.nextInt;
import static org.assertj.core.api.Assertions.*;
@@ -60,13 +58,8 @@ void worksOk() {
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
.hasMemoryEqualTo(aMemory().with(referenceState).with(toAddr, objectToCopy).build())
- .hasParameterStackEqualTo(aParameterStack().build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().build());
}
@DisplayName("should throw if the top of the stack is not a number.")
diff --git a/bjforth/src/test/java/bjforth/primitives/CREATETest.java b/bjforth/src/test/java/bjforth/primitives/CREATETest.java
index 21f0614b..058afdf9 100644
--- a/bjforth/src/test/java/bjforth/primitives/CREATETest.java
+++ b/bjforth/src/test/java/bjforth/primitives/CREATETest.java
@@ -71,8 +71,7 @@ public void worksOk() {
.with(HEREaddr, HEREvalue)
.with(Variables.get("LATEST").getAddress(), HEREvalue)
.build())
- .hasParameterStackEqualTo(aParameterStack().build())
- .hasReturnStackEqualTo(actualState);
+ .hasParameterStackEqualTo(aParameterStack().build());
}
@Test
diff --git a/bjforth/src/test/java/bjforth/primitives/DECR4Test.java b/bjforth/src/test/java/bjforth/primitives/DECR4Test.java
index 960b6ac6..de6b445a 100644
--- a/bjforth/src/test/java/bjforth/primitives/DECR4Test.java
+++ b/bjforth/src/test/java/bjforth/primitives/DECR4Test.java
@@ -18,12 +18,10 @@
*/
package bjforth.primitives;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
import static bjforth.machine.MemoryBuilder.aMemory;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.assertj.core.api.Assertions.*;
@@ -66,13 +64,7 @@ void worksOkWithNumber(Object parameter, Object expectedResult, String parameter
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build());
}
@DisplayName("should throw if top of parameter stack is not a number.")
diff --git a/bjforth/src/test/java/bjforth/primitives/DECRTest.java b/bjforth/src/test/java/bjforth/primitives/DECRTest.java
index 3feb50e0..76be2492 100644
--- a/bjforth/src/test/java/bjforth/primitives/DECRTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/DECRTest.java
@@ -18,12 +18,10 @@
*/
package bjforth.primitives;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
import static bjforth.machine.MemoryBuilder.aMemory;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.assertj.core.api.Assertions.*;
@@ -66,13 +64,7 @@ void worksOkWithNumber(Object parameter, Object expectedResult, String parameter
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build());
}
@DisplayName("should throw if top of parameter stack is not a number.")
diff --git a/bjforth/src/test/java/bjforth/primitives/DFATest.java b/bjforth/src/test/java/bjforth/primitives/DFATest.java
index cb304c04..82951927 100644
--- a/bjforth/src/test/java/bjforth/primitives/DFATest.java
+++ b/bjforth/src/test/java/bjforth/primitives/DFATest.java
@@ -19,12 +19,10 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.assertThat;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
import static bjforth.machine.MemoryBuilder.aMemory;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.apache.commons.lang3.RandomUtils.nextInt;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -55,13 +53,7 @@ public void worksOk() {
machine.step();
// THEN
- assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(parameter + 1).build())
- .hasReturnStackEqualTo(referenceState);
+ assertThat(actualState).hasParameterStackEqualTo(aParameterStack().with(parameter + 1).build());
}
@Test
diff --git a/bjforth/src/test/java/bjforth/primitives/DIVTest.java b/bjforth/src/test/java/bjforth/primitives/DIVTest.java
index fbac1058..277b715a 100644
--- a/bjforth/src/test/java/bjforth/primitives/DIVTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/DIVTest.java
@@ -19,12 +19,10 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
import static bjforth.machine.MemoryBuilder.aMemory;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.assertj.core.api.Assertions.*;
@@ -65,7 +63,6 @@ void worksOkWithNumbers(
var actualState =
aMachineState()
.withInstrcutionPointer(DIVaddr)
- .withNextInstructionPointer(DIVaddr + 1)
.withMemory(aMemory().build())
.withParameterStack(aParameterStack().with(parameter2, parameter1).build())
.build();
@@ -77,13 +74,7 @@ void worksOkWithNumbers(
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build());
}
@DisplayName(
@@ -97,7 +88,6 @@ void shouldThrowIfDivisorZero(Object parameter1, Object parameter2, String param
var actualState =
aMachineState()
.withInstrcutionPointer(DIVaddr)
- .withNextInstructionPointer(DIVaddr + 1)
.withMemory(aMemory().build())
.withParameterStack(aParameterStack().with(parameter2, parameter1).build())
.build();
@@ -126,7 +116,6 @@ void shouldReturnInfinityIfDivisorZero(
var actualState =
aMachineState()
.withInstrcutionPointer(DIVaddr)
- .withNextInstructionPointer(DIVaddr + 1)
.withMemory(aMemory().build())
.withParameterStack(aParameterStack().with(parameter2, parameter1).build())
.build();
@@ -138,13 +127,7 @@ void shouldReturnInfinityIfDivisorZero(
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build());
}
@DisplayName("should throw if any of parameter stack top is not a number.")
@@ -160,7 +143,6 @@ void throwsIfNonNumber(
var actualState =
aMachineState()
.withInstrcutionPointer(DIVaddr)
- .withNextInstructionPointer(DIVaddr + 1)
.withMemory(aMemory().build())
.withParameterStack(aParameterStack().with(parameter2, parameter1).build())
.build();
@@ -185,7 +167,6 @@ void throwIfEmpty() {
var actualState =
aMachineState()
.withInstrcutionPointer(DIVaddr)
- .withNextInstructionPointer(DIVaddr)
.withMemory(aMemory().build())
.withParameterStack(aParameterStack().build())
.build();
diff --git a/bjforth/src/test/java/bjforth/primitives/DOCOLTest.java b/bjforth/src/test/java/bjforth/primitives/DOCOLTest.java
deleted file mode 100644
index b793a513..00000000
--- a/bjforth/src/test/java/bjforth/primitives/DOCOLTest.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright 2022 Bahman Movaqar
- *
- * This file is part of bjForth.
- *
- * bjForth is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * bjForth is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with bjForth. If not, see .
- */
-package bjforth.primitives;
-
-import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
-import static bjforth.machine.MachineAssertions.assertThat;
-import static bjforth.machine.MachineBuilder.aMachine;
-import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.MachineStateInspectionUtils.*;
-import static bjforth.machine.MemoryBuilder.aMemory;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
-import static bjforth.machine.ReturnStackBuilder.aReturnStack;
-import static org.assertj.core.api.Assertions.assertThat;
-
-import org.junit.jupiter.api.DisplayName;
-import org.junit.jupiter.api.Test;
-
-class DOCOLTest {
-
- @Test
- @DisplayName("it pushes IP onto return stack and sets NIP")
- public void worksOk() {
- // GIVEN
- var DOCOLaddr = getPrimitiveAddress("DOCOL");
- var actualState =
- aMachineState().withMemory(aMemory().build()).withInstrcutionPointer(DOCOLaddr).build();
- var machine = aMachine().withState(actualState).build();
- var referenceState = aMachineState().copyFrom(actualState).build();
-
- // WHEN
- machine.step();
-
- // THEN
- assertThat(actualState)
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(referenceState)
- .hasReturnStackEqualTo(
- aReturnStack()
- .with(referenceState)
- .with(nextInstructionPointer(referenceState))
- .build())
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().withInstructionPointer(referenceState).plus(2).build());
- }
-}
diff --git a/bjforth/src/test/java/bjforth/primitives/DROPTest.java b/bjforth/src/test/java/bjforth/primitives/DROPTest.java
index e8cf3341..27814b83 100644
--- a/bjforth/src/test/java/bjforth/primitives/DROPTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/DROPTest.java
@@ -19,12 +19,10 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
import static bjforth.machine.MemoryBuilder.aMemory;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.assertj.core.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -54,14 +52,7 @@ public void workOk() {
machine.step();
// THEN
- assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().build())
- .hasReturnStackEqualTo(referenceState);
+ assertThat(actualState).hasParameterStackEqualTo(aParameterStack().build());
}
@Test
diff --git a/bjforth/src/test/java/bjforth/primitives/DSPFETCHTest.java b/bjforth/src/test/java/bjforth/primitives/DSPFETCHTest.java
index fb130791..da10f77f 100644
--- a/bjforth/src/test/java/bjforth/primitives/DSPFETCHTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/DSPFETCHTest.java
@@ -19,17 +19,15 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
import static bjforth.machine.MemoryBuilder.aMemory;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.assertj.core.api.Assertions.*;
import bjforth.machine.MachineException;
-import java.util.stream.IntStream;
+import java.util.List;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
@@ -40,13 +38,11 @@ class DSPFETCHTest {
void worksOk() {
// GIVEN
var DSPFETCHaddr = getPrimitiveAddress("DSP@");
- var pointer = org.apache.commons.lang3.RandomUtils.nextInt(0, 5);
- var parameterStackElements =
- IntStream.range(0, pointer + 1).mapToObj(i -> new Object()).toList();
+ var pointer = 0;
+ var parameterStackElements = List.of(new Object());
var actualState =
aMachineState()
.withInstrcutionPointer(DSPFETCHaddr)
- .withNextInstructionPointer(DSPFETCHaddr + 1)
.withMemory(aMemory().build())
.withParameterStack(aParameterStack().with(parameterStackElements).build())
.build();
@@ -58,11 +54,6 @@ void worksOk() {
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(aMemory().with(referenceState).build())
.hasParameterStackEqualTo(aParameterStack().with(referenceState).with(pointer).build());
}
@@ -72,11 +63,7 @@ void throwsIfEmpty() {
// GIVEN
var DSPFETCHaddr = getPrimitiveAddress("DSP@");
var actualState =
- aMachineState()
- .withInstrcutionPointer(DSPFETCHaddr)
- .withNextInstructionPointer(DSPFETCHaddr + 1)
- .withMemory(aMemory().build())
- .build();
+ aMachineState().withInstrcutionPointer(DSPFETCHaddr).withMemory(aMemory().build()).build();
var machine = aMachine().withState(actualState).build();
var referenceState = aMachineState().copyFrom(actualState).build();
diff --git a/bjforth/src/test/java/bjforth/primitives/DSPSTORETest.java b/bjforth/src/test/java/bjforth/primitives/DSPSTORETest.java
index d3774939..82cdf5ce 100644
--- a/bjforth/src/test/java/bjforth/primitives/DSPSTORETest.java
+++ b/bjforth/src/test/java/bjforth/primitives/DSPSTORETest.java
@@ -19,12 +19,10 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.assertThat;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
import static bjforth.machine.MemoryBuilder.aMemory;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static bjforth.utils.RandomUtils.nextInt;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -50,7 +48,6 @@ void worksOk() {
var actualState =
aMachineState()
.withInstrcutionPointer(DSPSTOREaddr)
- .withNextInstructionPointer(DSPSTOREaddr + 1)
.withMemory(aMemory().build())
.withParameterStack(
aParameterStack()
@@ -66,15 +63,14 @@ void worksOk() {
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(aMemory().with(referenceState).build())
.hasParameterStackPointerEqualTo(pointerToStore)
.hasParameterStackEqualTo(
aParameterStack()
- .with(actualStateParameterStackElements.subList(0, pointerToStore + 1))
+ .with(
+ actualStateParameterStackElements
+ .reversed()
+ .subList(0, pointerToStore + 1)
+ .reversed())
.build());
}
diff --git a/bjforth/src/test/java/bjforth/primitives/DUPTest.java b/bjforth/src/test/java/bjforth/primitives/DUPTest.java
index a5144cb4..77cf740c 100644
--- a/bjforth/src/test/java/bjforth/primitives/DUPTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/DUPTest.java
@@ -19,12 +19,10 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
import static bjforth.machine.MemoryBuilder.aMemory;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.apache.commons.lang3.RandomUtils.nextInt;
import static org.assertj.core.api.Assertions.*;
@@ -57,13 +55,7 @@ public void worksOk() {
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(parameter, parameter).build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().with(parameter, parameter).build());
}
@Test
diff --git a/bjforth/src/test/java/bjforth/primitives/EMITTest.java b/bjforth/src/test/java/bjforth/primitives/EMITTest.java
index aee46b85..d3904280 100644
--- a/bjforth/src/test/java/bjforth/primitives/EMITTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/EMITTest.java
@@ -19,12 +19,10 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.assertThat;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
import static bjforth.machine.MemoryBuilder.aMemory;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -46,7 +44,7 @@ class EMITTest {
private PrintStream systemOut = null;
@AfterEach
- private void restoreSystemIn() {
+ public void restoreSystemIn() {
System.setOut(originalSystemOut);
systemOut.close();
systemOut = null;
@@ -60,7 +58,7 @@ private void restoreSystemIn() {
}
@BeforeEach
- private void setupSystemOut() {
+ public void setupSystemOut() {
outputStream = new ByteArrayOutputStream();
systemOut = new PrintStream(outputStream);
System.setOut(systemOut);
@@ -88,13 +86,7 @@ void worksOk() {
machine.step();
// THEN
- assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().build())
- .hasReturnStackEqualTo(referenceState);
+ assertThat(actualState).hasParameterStackEqualTo(aParameterStack().build());
assertThat(outputStream.toByteArray()).containsExactly(str.getBytes());
}
diff --git a/bjforth/src/test/java/bjforth/primitives/EQUTest.java b/bjforth/src/test/java/bjforth/primitives/EQUTest.java
index 0cce6d96..cd9ede11 100644
--- a/bjforth/src/test/java/bjforth/primitives/EQUTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/EQUTest.java
@@ -19,12 +19,10 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
import static bjforth.machine.MemoryBuilder.aMemory;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.assertj.core.api.Assertions.*;
@@ -79,13 +77,7 @@ void worksOkWithNumbers(
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build());
}
@DisplayName("should throw if ParameterStack is already empty.")
diff --git a/bjforth/src/test/java/bjforth/primitives/EXECUTETest.java b/bjforth/src/test/java/bjforth/primitives/EXECUTETest.java
index ff5e90f3..ab4010a1 100644
--- a/bjforth/src/test/java/bjforth/primitives/EXECUTETest.java
+++ b/bjforth/src/test/java/bjforth/primitives/EXECUTETest.java
@@ -23,7 +23,6 @@
import static bjforth.machine.MachineAssertions.assertThat;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.*;
@@ -55,10 +54,7 @@ void worksOk() {
// THEN
assertThat(actualState)
.hasInstructionPointerEqualTo(anInstructionPointer().with(ADDaddr).build())
- .hasNextInstructionPointerEqualTo(aNextInstructionPointer().with(referenceState).build())
- .hasParameterStackEqualTo(aParameterStack().build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().build());
}
@DisplayName("Should throw if ParameterStack is already empty.")
diff --git a/bjforth/src/test/java/bjforth/primitives/EXITTest.java b/bjforth/src/test/java/bjforth/primitives/EXITTest.java
index a42f7547..feb596c5 100644
--- a/bjforth/src/test/java/bjforth/primitives/EXITTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/EXITTest.java
@@ -49,13 +49,14 @@ void worksOk() {
var referenceState = aMachineState().copyFrom(actualState).build();
// WHEN
+ machine.enterThreadedCode();
machine.step();
// THEN
assertThat(actualState)
.hasMemoryEqualTo(referenceState)
.hasReturnStackEqualTo(aReturnStack().build())
- .hasNextInstructionPointerEqualTo(NIPnew + 1);
+ .hasNextInstructionPointerEqualTo(NIPnew);
}
@Test
diff --git a/bjforth/src/test/java/bjforth/primitives/FETCHTest.java b/bjforth/src/test/java/bjforth/primitives/FETCHTest.java
index d1fdfa9b..312fc212 100644
--- a/bjforth/src/test/java/bjforth/primitives/FETCHTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/FETCHTest.java
@@ -18,12 +18,10 @@
*/
package bjforth.primitives;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
import static bjforth.machine.MemoryBuilder.aMemory;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.assertj.core.api.Assertions.*;
@@ -46,7 +44,6 @@ void worksOk() {
var actualState =
aMachineState()
.withInstrcutionPointer(FETCHaddr)
- .withNextInstructionPointer(FETCHaddr + 1)
.withMemory(aMemory().with(addrToFetch, objectToFetch).build())
.withParameterStack(aParameterStack().with(addrToFetch).build())
.build();
@@ -57,14 +54,7 @@ void worksOk() {
machine.step();
// THEN
- assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(aMemory().with(referenceState).build())
- .hasParameterStackEqualTo(aParameterStack().with(objectToFetch).build())
- .hasReturnStackEqualTo(referenceState);
+ assertThat(actualState).hasParameterStackEqualTo(aParameterStack().with(objectToFetch).build());
}
@DisplayName("should throw if parameter stack top is not a number.")
diff --git a/bjforth/src/test/java/bjforth/primitives/FINDTest.java b/bjforth/src/test/java/bjforth/primitives/FINDTest.java
index c5305ffb..8152b8c1 100644
--- a/bjforth/src/test/java/bjforth/primitives/FINDTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/FINDTest.java
@@ -20,12 +20,10 @@
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
import static bjforth.machine.DictionaryBuilder.aDictionary;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
import static bjforth.machine.MemoryBuilder.aMemory;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.assertj.core.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -48,7 +46,6 @@ public void worksOk() {
var actualState =
aMachineState()
.withInstrcutionPointer(FINDaddr)
- .withNextInstructionPointer(FINDaddr + 1)
.withMemory(aMemory().build())
.withParameterStack(aParameterStack().with(wordToFind).build())
.build();
@@ -60,13 +57,7 @@ public void worksOk() {
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(wordToFindAddr).build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().with(wordToFindAddr).build());
}
@Test
@@ -80,7 +71,6 @@ public void ignoreHidden() {
var actualState =
aMachineState()
.withInstrcutionPointer(FINDaddr)
- .withNextInstructionPointer(FINDaddr + 1)
.withMemory(aMemory().with(wordToFindAddr, new Object()).build())
.withParameterStack(aParameterStack().with(wordToFind).build())
.withDictionary(
@@ -98,11 +88,6 @@ public void ignoreHidden() {
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
.hasParameterStackEqualTo(aParameterStack().build())
.hasReturnStackEqualTo(referenceState);
}
diff --git a/bjforth/src/test/java/bjforth/primitives/FROMRTest.java b/bjforth/src/test/java/bjforth/primitives/FROMRTest.java
index d4bf7046..76164d66 100644
--- a/bjforth/src/test/java/bjforth/primitives/FROMRTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/FROMRTest.java
@@ -19,12 +19,10 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
import static bjforth.machine.MemoryBuilder.aMemory;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static bjforth.machine.ReturnStackBuilder.aReturnStack;
import static bjforth.utils.RandomUtils.nextInt;
@@ -45,7 +43,6 @@ void worksOk() {
var actualState =
aMachineState()
.withInstrcutionPointer(FROMRaddr)
- .withNextInstructionPointer(FROMRaddr + 1)
.withMemory(aMemory().build())
.withReturnStack(aReturnStack().with(object).build())
.build();
@@ -57,11 +54,6 @@ void worksOk() {
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(aMemory().with(referenceState).build())
.hasParameterStackEqualTo(aParameterStack().with(object).build())
.hasReturnStackEqualTo(aReturnStack().build());
}
diff --git a/bjforth/src/test/java/bjforth/primitives/GETest.java b/bjforth/src/test/java/bjforth/primitives/GETest.java
index a60dafc5..d2f7d33f 100644
--- a/bjforth/src/test/java/bjforth/primitives/GETest.java
+++ b/bjforth/src/test/java/bjforth/primitives/GETest.java
@@ -19,12 +19,10 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
import static bjforth.machine.MemoryBuilder.aMemory;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static bjforth.utils.RandomUtils.nextInt;
import static org.assertj.core.api.Assertions.*;
@@ -66,7 +64,6 @@ void worksOkWithNumbers(
var actualState =
aMachineState()
.withInstrcutionPointer(GEaddr)
- .withNextInstructionPointer(GEaddr + 1)
.withMemory(aMemory().build())
.withParameterStack(aParameterStack().with(parameter2, parameter1).build())
.build();
@@ -78,13 +75,7 @@ void worksOkWithNumbers(
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build());
}
@DisplayName("should throw if either of ParameterStack top 2 is not a number.")
diff --git a/bjforth/src/test/java/bjforth/primitives/GTTest.java b/bjforth/src/test/java/bjforth/primitives/GTTest.java
index 452ac300..d2f77433 100644
--- a/bjforth/src/test/java/bjforth/primitives/GTTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/GTTest.java
@@ -19,11 +19,9 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static bjforth.utils.RandomUtils.nextInt;
import static org.assertj.core.api.Assertions.*;
@@ -65,7 +63,6 @@ void worksOkWithNumbers(
var actualState =
aMachineState()
.withInstrcutionPointer(GTaddr)
- .withNextInstructionPointer(GTaddr + 1)
.withParameterStack(aParameterStack().with(parameter2, parameter1).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -76,13 +73,7 @@ void worksOkWithNumbers(
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build());
}
@DisplayName("should throw if either of ParameterStack top 2 is not a number.")
diff --git a/bjforth/src/test/java/bjforth/primitives/HERETest.java b/bjforth/src/test/java/bjforth/primitives/HERETest.java
index cc8270a1..07b08ef3 100644
--- a/bjforth/src/test/java/bjforth/primitives/HERETest.java
+++ b/bjforth/src/test/java/bjforth/primitives/HERETest.java
@@ -19,11 +19,9 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.assertThat;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.junit.jupiter.api.Assertions.*;
@@ -40,7 +38,6 @@ public void worksOk() {
var actualState =
aMachineState()
.withInstrcutionPointer(HEREaddr)
- .withNextInstructionPointer(HEREaddr + 1)
.withParameterStack(aParameterStack().build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -51,11 +48,6 @@ public void worksOk() {
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
.hasParameterStackEqualTo(
aParameterStack()
.with(
@@ -63,7 +55,6 @@ public void worksOk() {
+ PrimitiveFactory.getPrimitiveContainers()
.size()) /* TODO This assertion is likely to fail as soon as
bootstrapping extends to non-primitive words. */
- .build())
- .hasReturnStackEqualTo(referenceState);
+ .build());
}
}
diff --git a/bjforth/src/test/java/bjforth/primitives/HIDDENTest.java b/bjforth/src/test/java/bjforth/primitives/HIDDENTest.java
index 6ec71617..7a85874a 100644
--- a/bjforth/src/test/java/bjforth/primitives/HIDDENTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/HIDDENTest.java
@@ -21,12 +21,10 @@
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
import static bjforth.machine.DictionaryBuilder.aDictionary;
import static bjforth.machine.DictionaryItemBuilder.aDictionaryItem;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.assertThat;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
import static bjforth.machine.MemoryBuilder.aMemory;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.apache.commons.lang3.RandomUtils.nextBoolean;
import static org.apache.commons.lang3.RandomUtils.nextInt;
@@ -53,7 +51,6 @@ public void worksOk() {
var actualState =
aMachineState()
.withInstrcutionPointer(HIDDENaddr)
- .withNextInstructionPointer(HIDDENaddr + 1)
.withDictionary(aDictionary().with(wordName, dictItem).build())
.withMemory(aMemory().with(latestValue, wordAddr).build())
.withParameterStack(aParameterStack().with(wordAddr).build())
@@ -65,17 +62,11 @@ public void worksOk() {
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
.hasDictionaryEqualTo(
aDictionary()
.with(referenceState)
.with(wordName, aDictionaryItem().with(dictItem).isHidden(!isHidden).build())
- .build())
- .hasMemoryEqualTo(aMemory().with(referenceState).build())
- .hasParameterStackEqualTo(aParameterStack().build())
- .hasReturnStackEqualTo(referenceState);
+ .build());
}
@Test
diff --git a/bjforth/src/test/java/bjforth/primitives/IMMEDIATETest.java b/bjforth/src/test/java/bjforth/primitives/IMMEDIATETest.java
index 112ba293..9efd7a49 100644
--- a/bjforth/src/test/java/bjforth/primitives/IMMEDIATETest.java
+++ b/bjforth/src/test/java/bjforth/primitives/IMMEDIATETest.java
@@ -21,12 +21,10 @@
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
import static bjforth.machine.DictionaryBuilder.aDictionary;
import static bjforth.machine.DictionaryItemBuilder.aDictionaryItem;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.assertThat;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
import static bjforth.machine.MemoryBuilder.aMemory;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.apache.commons.lang3.RandomUtils.nextBoolean;
import static org.apache.commons.lang3.RandomUtils.nextInt;
@@ -55,7 +53,6 @@ public void worksOk() {
var actualState =
aMachineState()
.withInstrcutionPointer(IMMEDIATEaddr)
- .withNextInstructionPointer(IMMEDIATEaddr + 1)
.withMemory(aMemory().with(latestValue, wordAddr).build())
.withDictionary(aDictionary().with(wordName, dictItem).build())
.withParameterStack(aParameterStack().build())
@@ -69,9 +66,6 @@ public void worksOk() {
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
.hasDictionaryEqualTo(
aDictionary()
.with(referenceState)
@@ -81,9 +75,7 @@ public void worksOk() {
aMemory()
.with(referenceState)
.with(Variables.get("LATEST").getAddress(), latestValue)
- .build())
- .hasParameterStackEqualTo(aParameterStack().build())
- .hasReturnStackEqualTo(referenceState);
+ .build());
}
@Test
diff --git a/bjforth/src/test/java/bjforth/primitives/INCR4Test.java b/bjforth/src/test/java/bjforth/primitives/INCR4Test.java
index 1b6aff50..97d7193f 100644
--- a/bjforth/src/test/java/bjforth/primitives/INCR4Test.java
+++ b/bjforth/src/test/java/bjforth/primitives/INCR4Test.java
@@ -19,11 +19,9 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.assertj.core.api.Assertions.*;
@@ -53,7 +51,6 @@ void worksOkWithNumber(Object parameter, Object expectedResult, String parameter
var actualState =
aMachineState()
.withInstrcutionPointer(INCR4addr)
- .withNextInstructionPointer(INCR4addr + 1)
.withParameterStack(aParameterStack().with(parameter).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -64,13 +61,7 @@ void worksOkWithNumber(Object parameter, Object expectedResult, String parameter
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build());
}
@DisplayName("should throw if top of parameter stack is not a number.")
diff --git a/bjforth/src/test/java/bjforth/primitives/INCRTest.java b/bjforth/src/test/java/bjforth/primitives/INCRTest.java
index ed9ad37c..6ffda4e3 100644
--- a/bjforth/src/test/java/bjforth/primitives/INCRTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/INCRTest.java
@@ -19,11 +19,9 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.assertj.core.api.Assertions.*;
@@ -53,7 +51,6 @@ void worksOkWithNumber(Object parameter, Object expectedResult, String parameter
var actualState =
aMachineState()
.withInstrcutionPointer(INCRaddr)
- .withNextInstructionPointer(INCRaddr + 1)
.withParameterStack(aParameterStack().with(parameter).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -64,13 +61,7 @@ void worksOkWithNumber(Object parameter, Object expectedResult, String parameter
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build());
}
@DisplayName("should throw if top of parameter stack is not a number.")
diff --git a/bjforth/src/test/java/bjforth/primitives/INTERPRETTest.java b/bjforth/src/test/java/bjforth/primitives/INTERPRETTest.java
index 6260a10e..867c618f 100644
--- a/bjforth/src/test/java/bjforth/primitives/INTERPRETTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/INTERPRETTest.java
@@ -24,7 +24,6 @@
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
import static bjforth.machine.MemoryBuilder.aMemory;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.assertj.core.api.Assertions.*;
@@ -63,11 +62,7 @@ void immediateExecuteWord() {
System.setIn(inputStream);
var INTERPRETaddr = getPrimitiveAddress("INTERPRET");
- var actualState =
- aMachineState()
- .withInstrcutionPointer(INTERPRETaddr)
- .withNextInstructionPointer(INTERPRETaddr + 1)
- .build();
+ var actualState = aMachineState().withInstrcutionPointer(INTERPRETaddr).build();
var machine = aMachine().withState(actualState).build();
machine.setMemoryAt(Variables.get("STATE").getAddress(), 0);
var referenceState = aMachineState().copyFrom(actualState).build();
@@ -78,14 +73,7 @@ void immediateExecuteWord() {
// THEN
assertThat(actualState)
.hasInstructionPointerEqualTo(
- anInstructionPointer().with(machine.getDictionaryItem("+").get().getAddress()).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer()
- .with(machine.getDictionaryItem("+").get().getAddress())
- .plus(1)
- .build())
- .hasDictionaryEqualTo(referenceState)
- .hasReturnStackEqualTo(referenceState);
+ anInstructionPointer().with(machine.getDictionaryItem("+").get().getAddress()).build());
}
@DisplayName("Compiling mode: replaces the word with its CFA at HERE.")
@@ -99,11 +87,7 @@ void compilingReplaceWordWithAddress() {
System.setIn(inputStream);
var INTERPRETaddr = getPrimitiveAddress("INTERPRET");
- var actualState =
- aMachineState()
- .withInstrcutionPointer(INTERPRETaddr)
- .withNextInstructionPointer(INTERPRETaddr + 1)
- .build();
+ var actualState = aMachineState().withInstrcutionPointer(INTERPRETaddr).build();
var machine = aMachine().withState(actualState).build();
machine.setMemoryAt(Variables.get("STATE").getAddress(), 1);
var referenceState = aMachineState().copyFrom(actualState).build();
@@ -114,9 +98,6 @@ void compilingReplaceWordWithAddress() {
// THEN
var HEREdereferenced = (Integer) machine.getMemoryAt(Variables.get("HERE").getAddress());
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
.hasVariableEqualTo(Variables.get("HERE"), HEREdereferenced)
.hasMemoryEqualTo(
aMemory()
@@ -139,11 +120,7 @@ void compilingReplaceNumberWithLITAndNumber() {
System.setIn(inputStream);
var INTERPRETaddr = getPrimitiveAddress("INTERPRET");
- var actualState =
- aMachineState()
- .withInstrcutionPointer(INTERPRETaddr)
- .withNextInstructionPointer(INTERPRETaddr + 1)
- .build();
+ var actualState = aMachineState().withInstrcutionPointer(INTERPRETaddr).build();
var machine = aMachine().withState(actualState).build();
machine.setMemoryAt(Variables.get("STATE").getAddress(), 1);
var referenceState = aMachineState().copyFrom(actualState).build();
@@ -154,9 +131,6 @@ void compilingReplaceNumberWithLITAndNumber() {
// THEN
var HEREdereferenced = (Integer) machine.getMemoryAt(Variables.get("HERE").getAddress());
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
.hasVariableEqualTo(Variables.get("HERE"), HEREdereferenced)
.hasMemoryEqualTo(
aMemory()
@@ -179,11 +153,7 @@ void immediatePushNumberToStack() {
System.setIn(inputStream);
var INTERPRETaddr = getPrimitiveAddress("INTERPRET");
- var actualState =
- aMachineState()
- .withInstrcutionPointer(INTERPRETaddr)
- .withNextInstructionPointer(INTERPRETaddr + 1)
- .build();
+ var actualState = aMachineState().withInstrcutionPointer(INTERPRETaddr).build();
var machine = aMachine().withState(actualState).build();
machine.setMemoryAt(Variables.get("STATE").getAddress(), 0);
var referenceState = aMachineState().copyFrom(actualState).build();
@@ -194,14 +164,8 @@ void immediatePushNumberToStack() {
// THEN
var HEREdereferenced = (Integer) machine.getMemoryAt(Variables.get("HERE").getAddress());
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
.hasVariableEqualTo(Variables.get("HERE"), HEREdereferenced)
- .hasParameterStackEqualTo(aParameterStack().with(number).build())
- .hasMemoryEqualTo(aMemory().with(referenceState).build())
- .hasDictionaryEqualTo(referenceState)
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().with(number).build());
}
@DisplayName("Invalid input - not a word, not a number")
@@ -213,11 +177,7 @@ void invalidInput() {
System.setIn(inputStream);
var INTERPRETaddr = getPrimitiveAddress("INTERPRET");
- var actualState =
- aMachineState()
- .withInstrcutionPointer(INTERPRETaddr)
- .withNextInstructionPointer(INTERPRETaddr + 1)
- .build();
+ var actualState = aMachineState().withInstrcutionPointer(INTERPRETaddr).build();
var machine = aMachine().withState(actualState).build();
machine.setMemoryAt(Variables.get("STATE").getAddress(), 0);
var referenceState = aMachineState().copyFrom(actualState).build();
diff --git a/bjforth/src/test/java/bjforth/primitives/KEYTest.java b/bjforth/src/test/java/bjforth/primitives/KEYTest.java
index 450e63ef..df267187 100644
--- a/bjforth/src/test/java/bjforth/primitives/KEYTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/KEYTest.java
@@ -19,11 +19,9 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.assertThat;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -60,11 +58,7 @@ void worksOk() {
System.setIn(inputStream);
var KEYaddr = getPrimitiveAddress("KEY");
- var actualState =
- aMachineState()
- .withInstrcutionPointer(KEYaddr)
- .withNextInstructionPointer(KEYaddr + 1)
- .build();
+ var actualState = aMachineState().withInstrcutionPointer(KEYaddr).build();
var machine = aMachine().withState(actualState).build();
var referenceState = aMachineState().copyFrom(actualState).build();
@@ -73,12 +67,7 @@ void worksOk() {
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(str.codePointAt(0)).build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().with(str.codePointAt(0)).build());
}
@DisplayName("throws if reaches end of input stream.")
@@ -90,11 +79,7 @@ void throwsIfEndOfStream() {
System.setIn(inputStream);
var KEYaddr = getPrimitiveAddress("KEY");
- var actualState =
- aMachineState()
- .withInstrcutionPointer(KEYaddr)
- .withNextInstructionPointer(KEYaddr + 1)
- .build();
+ var actualState = aMachineState().withInstrcutionPointer(KEYaddr).build();
var machine = aMachine().withState(actualState).build();
var referenceState = aMachineState().copyFrom(actualState).build();
diff --git a/bjforth/src/test/java/bjforth/primitives/LATESTTest.java b/bjforth/src/test/java/bjforth/primitives/LATESTTest.java
index c69424ea..b5f2f0b4 100644
--- a/bjforth/src/test/java/bjforth/primitives/LATESTTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/LATESTTest.java
@@ -19,11 +19,9 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.assertThat;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.apache.commons.lang3.RandomUtils.nextInt;
@@ -42,7 +40,6 @@ public void worksOk() {
var actualState =
aMachineState()
.withInstrcutionPointer(LATESTaddr)
- .withNextInstructionPointer(LATESTaddr + 1)
.withParameterStack(aParameterStack().build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -53,13 +50,6 @@ public void worksOk() {
machine.step();
// THEN
- assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(latestValue).build())
- .hasReturnStackEqualTo(referenceState);
+ assertThat(actualState).hasParameterStackEqualTo(aParameterStack().with(latestValue).build());
}
}
diff --git a/bjforth/src/test/java/bjforth/primitives/LBRACTest.java b/bjforth/src/test/java/bjforth/primitives/LBRACTest.java
index e7888179..7e427dd3 100644
--- a/bjforth/src/test/java/bjforth/primitives/LBRACTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/LBRACTest.java
@@ -19,13 +19,10 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.assertThat;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
import static bjforth.machine.MemoryBuilder.aMemory;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
-import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import bjforth.variables.Variables;
import org.junit.jupiter.api.DisplayName;
@@ -38,11 +35,7 @@ class LBRACTest {
public void worksOk() {
// GIVEN
var LBRACaddr = getPrimitiveAddress("[");
- var actualState =
- aMachineState()
- .withInstrcutionPointer(LBRACaddr)
- .withNextInstructionPointer(LBRACaddr + 1)
- .build();
+ var actualState = aMachineState().withInstrcutionPointer(LBRACaddr).build();
var machine = aMachine().withState(actualState).build();
machine.setMemoryAt(Variables.get("STATE").getAddress(), 1);
var referenceState = aMachineState().copyFrom(actualState).build();
@@ -52,12 +45,7 @@ public void worksOk() {
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
.hasMemoryEqualTo(
- aMemory().with(referenceState).with(Variables.get("STATE").getAddress(), 0).build())
- .hasParameterStackEqualTo(aParameterStack().build())
- .hasReturnStackEqualTo(actualState);
+ aMemory().with(referenceState).with(Variables.get("STATE").getAddress(), 0).build());
}
}
diff --git a/bjforth/src/test/java/bjforth/primitives/LITSTRINGTest.java b/bjforth/src/test/java/bjforth/primitives/LITSTRINGTest.java
index d3103a20..5209b5c3 100644
--- a/bjforth/src/test/java/bjforth/primitives/LITSTRINGTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/LITSTRINGTest.java
@@ -63,13 +63,7 @@ void worksOk() {
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(memoryAddress).plus(2).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(memoryAddress).plus(3).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(memoryAddress + 1).build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().with(memoryAddress + 1).build());
}
@DisplayName("throws an exception in case NIP doesn't point to a string.")
@@ -102,9 +96,6 @@ void throwIfNoString() {
assertThat(actualState)
.hasInstructionPointerEqualTo(anInstructionPointer().with(LITSTRINGaddr).build())
.hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(memoryAddress).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasReturnStackEqualTo(referenceState);
+ aNextInstructionPointer().with(memoryAddress).plus(1).build());
}
}
diff --git a/bjforth/src/test/java/bjforth/primitives/LITTest.java b/bjforth/src/test/java/bjforth/primitives/LITTest.java
index 4d3e2040..7144f23d 100644
--- a/bjforth/src/test/java/bjforth/primitives/LITTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/LITTest.java
@@ -67,11 +67,8 @@ void worksOk(Object literal, String literalClassName) {
assertThat(actualState)
.hasInstructionPointerEqualTo(anInstructionPointer().with(memoryAddress).plus(2).build())
.hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(memoryAddress).plus(3).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(literal).build())
- .hasReturnStackEqualTo(referenceState);
+ aNextInstructionPointer().with(memoryAddress).plus(2).build())
+ .hasParameterStackEqualTo(aParameterStack().with(literal).build());
}
//////////////////////////////////////////////////////////////////////////////
diff --git a/bjforth/src/test/java/bjforth/primitives/LTETest.java b/bjforth/src/test/java/bjforth/primitives/LTETest.java
index 56a67b5b..e8b0c799 100644
--- a/bjforth/src/test/java/bjforth/primitives/LTETest.java
+++ b/bjforth/src/test/java/bjforth/primitives/LTETest.java
@@ -18,11 +18,9 @@
*/
package bjforth.primitives;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static bjforth.utils.RandomUtils.nextInt;
import static org.assertj.core.api.Assertions.*;
@@ -65,7 +63,6 @@ void worksOkWithNumbers(
var actualState =
aMachineState()
.withInstrcutionPointer(LEaddr)
- .withNextInstructionPointer(LEaddr + 1)
.withParameterStack(aParameterStack().with(parameter2, parameter1).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -76,13 +73,7 @@ void worksOkWithNumbers(
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build());
}
@DisplayName("should throw if either of ParameterStack top 2 is not a number.")
@@ -99,7 +90,6 @@ void throwIfNonNumber(
var actualState =
aMachineState()
.withInstrcutionPointer(LEaddr)
- .withNextInstructionPointer(LEaddr + 1)
.withParameterStack(aParameterStack().with(new Object(), new Object()).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -123,7 +113,6 @@ void throwIfEmpty() {
var actualState =
aMachineState()
.withInstrcutionPointer(LEaddr)
- .withNextInstructionPointer(LEaddr + 1)
.withParameterStack(aParameterStack().build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -142,7 +131,6 @@ void throwIfOnlyOneElement() {
var actualState =
aMachineState()
.withInstrcutionPointer(LEaddr)
- .withNextInstructionPointer(LEaddr + 1)
.withParameterStack(aParameterStack().with(RandomUtils.nextBigDecimal()).build())
.build();
var machine = aMachine().withState(actualState).build();
diff --git a/bjforth/src/test/java/bjforth/primitives/LTTest.java b/bjforth/src/test/java/bjforth/primitives/LTTest.java
index 737e7feb..cc55d81c 100644
--- a/bjforth/src/test/java/bjforth/primitives/LTTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/LTTest.java
@@ -18,11 +18,9 @@
*/
package bjforth.primitives;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static bjforth.utils.RandomUtils.nextInt;
import static org.assertj.core.api.Assertions.*;
@@ -65,7 +63,6 @@ void worksOkWithNumbers(
var actualState =
aMachineState()
.withInstrcutionPointer(LTaddr)
- .withNextInstructionPointer(LTaddr + 1)
.withParameterStack(aParameterStack().with(parameter2, parameter1).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -76,13 +73,7 @@ void worksOkWithNumbers(
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build());
}
@DisplayName("should throw if either of ParameterStack top 2 is not a number.")
@@ -99,7 +90,6 @@ void throwIfNonNumber(
var actualState =
aMachineState()
.withInstrcutionPointer(LTaddr)
- .withNextInstructionPointer(LTaddr + 1)
.withParameterStack(aParameterStack().with(new Object(), new Object()).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -123,7 +113,6 @@ void throwIfEmpty() {
var actualState =
aMachineState()
.withInstrcutionPointer(LTaddr)
- .withNextInstructionPointer(LTaddr)
.withParameterStack(aParameterStack().build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -142,7 +131,6 @@ void throwIfOnlyOneElement() {
var actualState =
aMachineState()
.withInstrcutionPointer(LTaddr)
- .withNextInstructionPointer(LTaddr + 1)
.withParameterStack(aParameterStack().with(RandomUtils.nextBigDecimal()).build())
.build();
var machine = aMachine().withState(actualState).build();
diff --git a/bjforth/src/test/java/bjforth/primitives/MODTest.java b/bjforth/src/test/java/bjforth/primitives/MODTest.java
index e19b7ef5..0731b189 100644
--- a/bjforth/src/test/java/bjforth/primitives/MODTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/MODTest.java
@@ -19,11 +19,9 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.assertj.core.api.Assertions.*;
@@ -65,7 +63,6 @@ void worksOkWithNumbers(
var actualState =
aMachineState()
.withInstrcutionPointer(MODaddr)
- .withNextInstructionPointer(MODaddr + 1)
.withParameterStack(aParameterStack().with(parameter2, parameter1).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -76,13 +73,7 @@ void worksOkWithNumbers(
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build());
}
@DisplayName(
@@ -96,7 +87,6 @@ void shouldThrowIfDivisorZero(Object parameter1, Object parameter2, String param
var actualState =
aMachineState()
.withInstrcutionPointer(MODaddr)
- .withNextInstructionPointer(MODaddr + 1)
.withParameterStack(aParameterStack().with(parameter2, parameter1).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -124,7 +114,6 @@ void shouldReturnInfinityIfDivisorZero(
var actualState =
aMachineState()
.withInstrcutionPointer(MODaddr)
- .withNextInstructionPointer(MODaddr + 1)
.withParameterStack(aParameterStack().with(parameter2, parameter1).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -135,13 +124,7 @@ void shouldReturnInfinityIfDivisorZero(
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build());
}
@DisplayName("should throw if any of parameter stack top is not a number.")
@@ -157,7 +140,6 @@ void throwsIfNonNumber(
var actualState =
aMachineState()
.withInstrcutionPointer(MODaddr)
- .withNextInstructionPointer(MODaddr + 1)
.withParameterStack(aParameterStack().with(parameter2, parameter1).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -181,7 +163,6 @@ void throwIfEmpty() {
var actualState =
aMachineState()
.withInstrcutionPointer(MODaddr)
- .withNextInstructionPointer(MODaddr + 1)
.withParameterStack(aParameterStack().build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -200,7 +181,6 @@ void throwIfOnlyOneElement() {
var actualState =
aMachineState()
.withInstrcutionPointer(MODaddr)
- .withNextInstructionPointer(MODaddr + 1)
.withParameterStack(aParameterStack().with(RandomUtils.nextBigDecimal()).build())
.build();
var machine = aMachine().withState(actualState).build();
diff --git a/bjforth/src/test/java/bjforth/primitives/MOVETest.java b/bjforth/src/test/java/bjforth/primitives/MOVETest.java
index e4f5360e..9689886b 100644
--- a/bjforth/src/test/java/bjforth/primitives/MOVETest.java
+++ b/bjforth/src/test/java/bjforth/primitives/MOVETest.java
@@ -18,12 +18,10 @@
*/
package bjforth.primitives;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
import static bjforth.machine.MemoryBuilder.aMemory;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static bjforth.utils.RandomUtils.nextInt;
import static org.assertj.core.api.Assertions.*;
@@ -55,7 +53,6 @@ void worksOk() {
var actualState =
aMachineState()
.withInstrcutionPointer(MOVEaddr)
- .withNextInstructionPointer(MOVEaddr + 1)
.withMemory(aMemory().with(cellsToMove).build())
.withParameterStack(aParameterStack().with(toAddr, fromAddr, nObjectsToMove).build())
.build();
@@ -71,13 +68,8 @@ void worksOk() {
.map(e -> Map.entry(toAddr + (e.getKey() - fromAddr), e.getValue()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
.hasMemoryEqualTo(aMemory().with(referenceState).with(movedCells).build())
- .hasParameterStackEqualTo(aParameterStack().build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().build());
}
@DisplayName("should throw if the top of the stack is not a number.")
@@ -88,7 +80,6 @@ void throwsIfTopNonNumber() {
var actualState =
aMachineState()
.withInstrcutionPointer(MOVEaddr)
- .withNextInstructionPointer(MOVEaddr + 1)
.withParameterStack(aParameterStack().with(nextInt(), nextInt(), new Object()).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -112,7 +103,6 @@ void throwsIf2ndTopNonNumber() {
var actualState =
aMachineState()
.withInstrcutionPointer(MOVEaddr)
- .withNextInstructionPointer(MOVEaddr + 1)
.withParameterStack(aParameterStack().with(nextInt(), new Object(), nextInt()).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -136,7 +126,6 @@ void throwsIf3rdTopNonNumber() {
var actualState =
aMachineState()
.withInstrcutionPointer(MOVEaddr)
- .withNextInstructionPointer(MOVEaddr + 1)
.withParameterStack(aParameterStack().with(new Object(), nextInt(), nextInt()).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -160,7 +149,6 @@ void throwIfEmpty() {
var actualState =
aMachineState()
.withInstrcutionPointer(MOVEaddr)
- .withNextInstructionPointer(MOVEaddr + 1)
.withParameterStack(aParameterStack().build())
.build();
var machine = aMachine().withState(actualState).build();
diff --git a/bjforth/src/test/java/bjforth/primitives/MULTest.java b/bjforth/src/test/java/bjforth/primitives/MULTest.java
index 0eb73bf2..2cf5391d 100644
--- a/bjforth/src/test/java/bjforth/primitives/MULTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/MULTest.java
@@ -19,11 +19,9 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.assertj.core.api.Assertions.*;
@@ -62,7 +60,6 @@ void worksOkWithNumbers(
var actualState =
aMachineState()
.withInstrcutionPointer(MULaddr)
- .withNextInstructionPointer(MULaddr + 1)
.withParameterStack(aParameterStack().with(parameter2, parameter1).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -73,13 +70,7 @@ void worksOkWithNumbers(
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build());
}
@DisplayName("should throw if any of parameter stack top is not a number.")
@@ -95,7 +86,6 @@ void throwsIfNonNumber(
var actualState =
aMachineState()
.withInstrcutionPointer(MULaddr)
- .withNextInstructionPointer(MULaddr + 1)
.withParameterStack(aParameterStack().with(parameter2, parameter1).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -119,7 +109,6 @@ void throwIfEmpty() {
var actualState =
aMachineState()
.withInstrcutionPointer(MULaddr)
- .withNextInstructionPointer(MULaddr + 1)
.withParameterStack(aParameterStack().build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -138,7 +127,6 @@ void throwIfOnlyOneElement() {
var actualState =
aMachineState()
.withInstrcutionPointer(MULaddr)
- .withNextInstructionPointer(MULaddr + 1)
.withParameterStack(aParameterStack().with(RandomUtils.nextBigDecimal()).build())
.build();
var machine = aMachine().withState(actualState).build();
diff --git a/bjforth/src/test/java/bjforth/primitives/NEQUTest.java b/bjforth/src/test/java/bjforth/primitives/NEQUTest.java
index 7ec1da37..4d20b705 100644
--- a/bjforth/src/test/java/bjforth/primitives/NEQUTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/NEQUTest.java
@@ -19,11 +19,9 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.assertj.core.api.Assertions.*;
@@ -66,7 +64,6 @@ void worksOkWithNumbers(
var actualState =
aMachineState()
.withInstrcutionPointer(NEQUaddr)
- .withNextInstructionPointer(NEQUaddr + 1)
.withParameterStack(aParameterStack().with(parameter2, parameter1).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -77,13 +74,7 @@ void worksOkWithNumbers(
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build());
}
@DisplayName("should throw if ParameterStack is already empty.")
@@ -94,7 +85,6 @@ void throwIfEmpty() {
var actualState =
aMachineState()
.withInstrcutionPointer(NEQUaddr)
- .withNextInstructionPointer(NEQUaddr + 1)
.withParameterStack(aParameterStack().build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -113,7 +103,6 @@ void throwIfOnlyOneElement() {
var actualState =
aMachineState()
.withInstrcutionPointer(NEQUaddr)
- .withNextInstructionPointer(NEQUaddr)
.withParameterStack(aParameterStack().with(RandomUtils.nextBigDecimal()).build())
.build();
var machine = aMachine().withState(actualState).build();
diff --git a/bjforth/src/test/java/bjforth/primitives/NROTTest.java b/bjforth/src/test/java/bjforth/primitives/NROTTest.java
index 1be61614..512a8174 100644
--- a/bjforth/src/test/java/bjforth/primitives/NROTTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/NROTTest.java
@@ -19,11 +19,9 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.apache.commons.lang3.RandomUtils.nextInt;
import static org.assertj.core.api.Assertions.*;
@@ -46,7 +44,6 @@ void worksOk() {
var actualState =
aMachineState()
.withInstrcutionPointer(NROTaddr)
- .withNextInstructionPointer(NROTaddr + 1)
.withParameterStack(aParameterStack().with(parameter3, parameter2, parameter1).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -57,14 +54,8 @@ void worksOk() {
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
.hasParameterStackEqualTo(
- aParameterStack().with(parameter1, parameter3, parameter2).build())
- .hasReturnStackEqualTo(referenceState);
+ aParameterStack().with(parameter1, parameter3, parameter2).build());
}
@Test
@@ -75,7 +66,6 @@ void throwIfEmpty() {
var actualState =
aMachineState()
.withInstrcutionPointer(NROTaddr)
- .withNextInstructionPointer(NROTaddr + 1)
.withParameterStack(aParameterStack().build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -95,7 +85,6 @@ void throwIfParameterStackOneElement() {
var actualState =
aMachineState()
.withInstrcutionPointer(NROTaddr)
- .withNextInstructionPointer(NROTaddr + 1)
.withParameterStack(aParameterStack().with(parameter).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -121,7 +110,6 @@ void throwIfParameterStackTwoElements() {
var actualState =
aMachineState()
.withInstrcutionPointer(NROTaddr)
- .withNextInstructionPointer(NROTaddr + 1)
.withParameterStack(aParameterStack().with(parameter2, parameter1).build())
.build();
var machine = aMachine().withState(actualState).build();
diff --git a/bjforth/src/test/java/bjforth/primitives/NUMBERTest.java b/bjforth/src/test/java/bjforth/primitives/NUMBERTest.java
index 83e7959f..f20136ad 100644
--- a/bjforth/src/test/java/bjforth/primitives/NUMBERTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/NUMBERTest.java
@@ -19,11 +19,9 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.apache.commons.lang3.RandomUtils.nextInt;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -44,7 +42,6 @@ public void worksOk() {
var actualState =
aMachineState()
.withInstrcutionPointer(NUMBERaddr)
- .withNextInstructionPointer(NUMBERaddr + 1)
.withParameterStack(aParameterStack().with(Integer.toString(parameter)).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -55,13 +52,7 @@ public void worksOk() {
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(parameter).with(0).build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().with(parameter).with(0).build());
}
@Test
@@ -73,7 +64,6 @@ public void invalidParameter() {
var actualState =
aMachineState()
.withInstrcutionPointer(NUMBERaddr)
- .withNextInstructionPointer(NUMBERaddr + 1)
.withParameterStack(aParameterStack().with(parameter).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -84,13 +74,7 @@ public void invalidParameter() {
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with((Object) null).with(-1).build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().with((Object) null).with(-1).build());
}
@Test
@@ -101,7 +85,6 @@ public void throwIfEmpty() {
var actualState =
aMachineState()
.withInstrcutionPointer(NUMBERaddr)
- .withNextInstructionPointer(NUMBERaddr + 1)
.withParameterStack(aParameterStack().build())
.build();
var machine = aMachine().withState(actualState).build();
diff --git a/bjforth/src/test/java/bjforth/primitives/OVERTest.java b/bjforth/src/test/java/bjforth/primitives/OVERTest.java
index 7a0acca8..402803c2 100644
--- a/bjforth/src/test/java/bjforth/primitives/OVERTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/OVERTest.java
@@ -19,11 +19,9 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.apache.commons.lang3.RandomUtils.nextInt;
import static org.assertj.core.api.Assertions.*;
@@ -45,7 +43,6 @@ void worksOk() {
var actualState =
aMachineState()
.withInstrcutionPointer(OVERaddr)
- .withNextInstructionPointer(OVERaddr + 1)
.withParameterStack(aParameterStack().with(parameter2, parameter1).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -56,14 +53,8 @@ void worksOk() {
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
.hasParameterStackEqualTo(
- aParameterStack().with(parameter2, parameter1, parameter2).build())
- .hasReturnStackEqualTo(referenceState);
+ aParameterStack().with(parameter2, parameter1, parameter2).build());
}
@Test
@@ -74,7 +65,6 @@ void throwIfEmpty() {
var actualState =
aMachineState()
.withInstrcutionPointer(OVERaddr)
- .withNextInstructionPointer(OVERaddr + 1)
.withParameterStack(aParameterStack().build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -94,7 +84,6 @@ void throwIfParameterStackOneElement() {
var actualState =
aMachineState()
.withInstrcutionPointer(OVERaddr)
- .withNextInstructionPointer(OVERaddr + 1)
.withParameterStack(aParameterStack().with(parameter).build())
.build();
var machine = aMachine().withState(actualState).build();
diff --git a/bjforth/src/test/java/bjforth/primitives/QDUPTest.java b/bjforth/src/test/java/bjforth/primitives/QDUPTest.java
index 7e13129a..5971041c 100644
--- a/bjforth/src/test/java/bjforth/primitives/QDUPTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/QDUPTest.java
@@ -19,11 +19,9 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.assertj.core.api.Assertions.*;
@@ -53,7 +51,6 @@ void worksOkWithNonZero(Object parameter, String parameterClassName) {
var actualState =
aMachineState()
.withInstrcutionPointer(QDUPaddr)
- .withNextInstructionPointer(QDUPaddr + 1)
.withParameterStack(aParameterStack().with(parameter).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -64,13 +61,7 @@ void worksOkWithNonZero(Object parameter, String parameterClassName) {
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(parameter, parameter).build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().with(parameter, parameter).build());
}
@DisplayName("does not modify stack if top element is a zero number, ie a -> a.")
@@ -82,7 +73,6 @@ void worksOkWithZero(Object parameter, String parameterClassName) {
var actualState =
aMachineState()
.withInstrcutionPointer(QDUPaddr)
- .withNextInstructionPointer(QDUPaddr + 1)
.withParameterStack(aParameterStack().with(parameter).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -93,11 +83,6 @@ void worksOkWithZero(Object parameter, String parameterClassName) {
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
.hasParameterStackEqualTo(aParameterStack().with(parameter).build())
.hasReturnStackEqualTo(referenceState);
}
@@ -111,7 +96,6 @@ void throwsIfNonNumber(E parameter, String parameterClassName
var actualState =
aMachineState()
.withInstrcutionPointer(QDUPaddr)
- .withNextInstructionPointer(QDUPaddr + 1)
.withParameterStack(aParameterStack().with(parameter).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -127,7 +111,7 @@ void throwsIfNonNumber(E parameter, String parameterClassName
.build());
}
- @DisplayName("should trhow if ParameterStack is already empty.")
+ @DisplayName("should throw if ParameterStack is already empty.")
@Test
void throwIfEmpty() {
// GIVEN
diff --git a/bjforth/src/test/java/bjforth/primitives/QUITTest.java b/bjforth/src/test/java/bjforth/primitives/QUITTest.java
index 7c663cfe..1fb7f6e5 100644
--- a/bjforth/src/test/java/bjforth/primitives/QUITTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/QUITTest.java
@@ -80,7 +80,7 @@ public void workOk() {
// THEN
assertThat(actualState)
.hasInstructionPointerEqualTo(anInstructionPointer().with(INTERPRETaddr).build())
- .hasNextInstructionPointerEqualTo(aNextInstructionPointer().with(nip).build())
+ .hasNextInstructionPointerEqualTo(aNextInstructionPointer().with(QUITaddr).build())
.hasDictionaryEqualTo(referenceState)
.hasMemoryEqualTo(referenceState)
.hasReturnStackEqualTo(aReturnStack().build());
diff --git a/bjforth/src/test/java/bjforth/primitives/RBRACTest.java b/bjforth/src/test/java/bjforth/primitives/RBRACTest.java
index 37c8463e..e8cebad3 100644
--- a/bjforth/src/test/java/bjforth/primitives/RBRACTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/RBRACTest.java
@@ -18,13 +18,10 @@
*/
package bjforth.primitives;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.assertThat;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
import static bjforth.machine.MemoryBuilder.aMemory;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
-import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import bjforth.machine.BootstrapUtils;
import bjforth.variables.Variables;
@@ -38,11 +35,7 @@ class RBRACTest {
public void worksOk() {
// GIVEN
var RBRACaddr = BootstrapUtils.getPrimitiveAddress("]");
- var actualState =
- aMachineState()
- .withInstrcutionPointer(RBRACaddr)
- .withNextInstructionPointer(RBRACaddr + 1)
- .build();
+ var actualState = aMachineState().withInstrcutionPointer(RBRACaddr).build();
var machine = aMachine().withState(actualState).build();
machine.setMemoryAt(Variables.get("STATE").getAddress(), 0);
var referenceState = aMachineState().copyFrom(actualState).build();
@@ -52,12 +45,7 @@ public void worksOk() {
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
.hasMemoryEqualTo(
- aMemory().with(referenceState).with(Variables.get("STATE").getAddress(), 1).build())
- .hasParameterStackEqualTo(aParameterStack().build())
- .hasReturnStackEqualTo(referenceState);
+ aMemory().with(referenceState).with(Variables.get("STATE").getAddress(), 1).build());
}
}
diff --git a/bjforth/src/test/java/bjforth/primitives/RDROPTest.java b/bjforth/src/test/java/bjforth/primitives/RDROPTest.java
index 5adf27d3..ac871436 100644
--- a/bjforth/src/test/java/bjforth/primitives/RDROPTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/RDROPTest.java
@@ -19,11 +19,9 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.assertThat;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ReturnStackBuilder.aReturnStack;
import static org.apache.commons.lang3.RandomUtils.nextInt;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -42,7 +40,6 @@ public void workOk() {
var actualState =
aMachineState()
.withInstrcutionPointer(RDROPaddr)
- .withNextInstructionPointer(RDROPaddr + 1)
.withReturnStack(aReturnStack().with(nextInt()).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -52,13 +49,7 @@ public void workOk() {
machine.step();
// THEN
- assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasReturnStackEqualTo(aReturnStack().build());
+ assertThat(actualState).hasReturnStackEqualTo(aReturnStack().build());
}
@Test
@@ -69,7 +60,6 @@ public void throwIfEmpty() {
var actualState =
aMachineState()
.withInstrcutionPointer(RDROPaddr)
- .withNextInstructionPointer(RDROPaddr + 1)
.withReturnStack(aReturnStack().build())
.build();
var machine = aMachine().withState(actualState).build();
diff --git a/bjforth/src/test/java/bjforth/primitives/ROTTest.java b/bjforth/src/test/java/bjforth/primitives/ROTTest.java
index 01d43591..ec09da84 100644
--- a/bjforth/src/test/java/bjforth/primitives/ROTTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/ROTTest.java
@@ -18,11 +18,9 @@
*/
package bjforth.primitives;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.apache.commons.lang3.RandomUtils.nextInt;
import static org.assertj.core.api.Assertions.*;
@@ -46,7 +44,6 @@ void worksOk() {
var actualState =
aMachineState()
.withInstrcutionPointer(ROTaddr)
- .withNextInstructionPointer(ROTaddr + 1)
.withParameterStack(aParameterStack().with(parameter3, parameter2, parameter1).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -57,14 +54,8 @@ void worksOk() {
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
.hasParameterStackEqualTo(
- aParameterStack().with(parameter2, parameter1, parameter3).build())
- .hasReturnStackEqualTo(referenceState);
+ aParameterStack().with(parameter2, parameter1, parameter3).build());
}
@Test
@@ -75,7 +66,6 @@ void throwIfEmpty() {
var actualState =
aMachineState()
.withInstrcutionPointer(ROTaddr)
- .withNextInstructionPointer(ROTaddr + 1)
.withParameterStack(aParameterStack().build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -95,7 +85,6 @@ void throwIfParameterStackOneElement() {
var actualState =
aMachineState()
.withInstrcutionPointer(ROTaddr)
- .withNextInstructionPointer(ROTaddr + 1)
.withParameterStack(aParameterStack().with(parameter).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -121,7 +110,6 @@ void throwIfParameterStackTwoElements() {
var actualState =
aMachineState()
.withInstrcutionPointer(ROTaddr)
- .withNextInstructionPointer(ROTaddr + 1)
.withParameterStack(aParameterStack().with(parameter2, parameter1).build())
.build();
var machine = aMachine().withState(actualState).build();
diff --git a/bjforth/src/test/java/bjforth/primitives/RSPFETCHTest.java b/bjforth/src/test/java/bjforth/primitives/RSPFETCHTest.java
index 924ca04e..01df2f9b 100644
--- a/bjforth/src/test/java/bjforth/primitives/RSPFETCHTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/RSPFETCHTest.java
@@ -19,13 +19,10 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineAssertions.assertThat;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.MemoryBuilder.aMemory;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static bjforth.machine.ReturnStackBuilder.aReturnStack;
import static org.assertj.core.api.Assertions.*;
@@ -47,7 +44,6 @@ void worksOk() {
var actualState =
aMachineState()
.withInstrcutionPointer(RSPFETCHaddr)
- .withNextInstructionPointer(RSPFETCHaddr + 1)
.withReturnStack(
aReturnStack()
.with(IntStream.range(0, pointer + 1).mapToObj(i -> new Object()).toList())
@@ -60,14 +56,7 @@ void worksOk() {
machine.step();
// THEN
- assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(aMemory().with(referenceState).build())
- .hasParameterStackEqualTo(aParameterStack().with(pointer).build())
- .hasReturnStackEqualTo(referenceState);
+ assertThat(actualState).hasParameterStackEqualTo(aParameterStack().with(pointer).build());
}
@DisplayName("should throw if return stack is empty.")
@@ -75,11 +64,7 @@ void worksOk() {
void throwsIfEmpty() {
// GIVEN
var RSPFETCHaddr = getPrimitiveAddress("RSP@");
- var actualState =
- aMachineState()
- .withInstrcutionPointer(RSPFETCHaddr)
- .withNextInstructionPointer(RSPFETCHaddr)
- .build();
+ var actualState = aMachineState().withInstrcutionPointer(RSPFETCHaddr).build();
var machine = aMachine().withState(actualState).build();
var referenceState = aMachineState().copyFrom(actualState).build();
diff --git a/bjforth/src/test/java/bjforth/primitives/RSPSTORETest.java b/bjforth/src/test/java/bjforth/primitives/RSPSTORETest.java
index a118f606..419c63fb 100644
--- a/bjforth/src/test/java/bjforth/primitives/RSPSTORETest.java
+++ b/bjforth/src/test/java/bjforth/primitives/RSPSTORETest.java
@@ -18,12 +18,9 @@
*/
package bjforth.primitives;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.assertThat;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.MemoryBuilder.aMemory;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static bjforth.machine.ReturnStackBuilder.aReturnStack;
import static bjforth.utils.RandomUtils.nextInt;
@@ -48,7 +45,6 @@ void worksOk() {
var actualState =
aMachineState()
.withInstrcutionPointer(RSPSTOREaddr)
- .withNextInstructionPointer(RSPSTOREaddr + 1)
.withParameterStack(aParameterStack().with(pointerToStore).build())
.withReturnStack(
aReturnStack()
@@ -63,14 +59,7 @@ void worksOk() {
machine.step();
// THEN
- assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(aMemory().with(referenceState).build())
- .hasParameterStackEqualTo(aParameterStack().build())
- .hasReturnStackPointerEqualTo(pointerToStore);
+ assertThat(actualState).hasReturnStackPointerEqualTo(pointerToStore);
}
@DisplayName("should throw if parameter stack is empty.")
@@ -81,7 +70,6 @@ void throwsIfParameterStackEmpty() {
var actualState =
aMachineState()
.withInstrcutionPointer(RSPSTOREaddr)
- .withNextInstructionPointer(RSPSTOREaddr + 1)
.withReturnStack(aReturnStack().with(nextInt()).build())
.withParameterStack(aParameterStack().build())
.build();
@@ -101,7 +89,6 @@ void throwsIfParameterStackNonNumber() {
var actualState =
aMachineState()
.withInstrcutionPointer(RSPSTOREaddr)
- .withNextInstructionPointer(RSPSTOREaddr + 1)
.withParameterStack(aParameterStack().with(new Object()).build())
.withReturnStack(aReturnStack().with(nextInt()).build())
.build();
@@ -126,7 +113,6 @@ void throwsIfReturnStackEmpty() {
var actualState =
aMachineState()
.withInstrcutionPointer(RSPSTOREaddr)
- .withNextInstructionPointer(RSPSTOREaddr + 1)
.withParameterStack(aParameterStack().with(nextInt()).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -151,7 +137,6 @@ void throwsIfPointerTooLarge() {
var actualState =
aMachineState()
.withInstrcutionPointer(RSPSTOREaddr)
- .withNextInstructionPointer(RSPSTOREaddr + 1)
.withParameterStack(aParameterStack().with(pointer).build())
.withReturnStack(aReturnStack().with(nextInt(), nextInt()).build())
.build();
diff --git a/bjforth/src/test/java/bjforth/primitives/SEMICOLONTest.java b/bjforth/src/test/java/bjforth/primitives/SEMICOLONTest.java
index adccf669..aa02469e 100644
--- a/bjforth/src/test/java/bjforth/primitives/SEMICOLONTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/SEMICOLONTest.java
@@ -46,7 +46,6 @@ void worksOk() {
var actualState =
aMachineState()
.withInstrcutionPointer(SEMICOLONaddr)
- .withNextInstructionPointer(SEMICOLONaddr + 1)
.withReturnStack(aReturnStack().with(NIP).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -59,9 +58,7 @@ void worksOk() {
machine.step();
// THEN
- assertThat(actualState)
- .hasReturnStackEqualTo(aReturnStack().build())
- .hasNextInstructionPointerEqualTo(NIP);
+ assertThat(actualState).hasReturnStackEqualTo(aReturnStack().with(NIP).build());
Assertions.assertThat(machine.getDictionaryItem("FOO").get().getIsHidden()).isFalse();
}
}
diff --git a/bjforth/src/test/java/bjforth/primitives/STORETest.java b/bjforth/src/test/java/bjforth/primitives/STORETest.java
index ac256f0c..8ed45c33 100644
--- a/bjforth/src/test/java/bjforth/primitives/STORETest.java
+++ b/bjforth/src/test/java/bjforth/primitives/STORETest.java
@@ -19,12 +19,10 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
import static bjforth.machine.MemoryBuilder.aMemory;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static bjforth.utils.RandomUtils.nextInt;
import static org.assertj.core.api.Assertions.*;
@@ -46,7 +44,6 @@ void worksOk() {
var actualState =
aMachineState()
.withInstrcutionPointer(STOREaddr)
- .withNextInstructionPointer(STOREaddr + 1)
.withParameterStack(aParameterStack().with(objectToStore, addrToStore).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -57,13 +54,8 @@ void worksOk() {
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
.hasMemoryEqualTo(aMemory().with(referenceState).with(addrToStore, objectToStore).build())
- .hasParameterStackEqualTo(aParameterStack().build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().build());
}
@DisplayName("should throw if parameter stack top is not a number.")
@@ -74,7 +66,6 @@ void throwsIfNonNumber() {
var actualState =
aMachineState()
.withInstrcutionPointer(STOREaddr)
- .withNextInstructionPointer(STOREaddr + 1)
.withParameterStack(aParameterStack().with(new Object(), new Object()).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -98,7 +89,6 @@ void throwIfEmpty() {
var actualState =
aMachineState()
.withInstrcutionPointer(STOREaddr)
- .withNextInstructionPointer(STOREaddr + 1)
.withParameterStack(aParameterStack().build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -117,7 +107,6 @@ void throwIfOnlyOneElement() {
var actualState =
aMachineState()
.withInstrcutionPointer(STOREaddr)
- .withNextInstructionPointer(STOREaddr + 1)
.withParameterStack(aParameterStack().with(nextInt()).build())
.build();
var machine = aMachine().withState(actualState).build();
diff --git a/bjforth/src/test/java/bjforth/primitives/SUBSTORETest.java b/bjforth/src/test/java/bjforth/primitives/SUBSTORETest.java
index 1e0f1e7c..b49b4687 100644
--- a/bjforth/src/test/java/bjforth/primitives/SUBSTORETest.java
+++ b/bjforth/src/test/java/bjforth/primitives/SUBSTORETest.java
@@ -19,12 +19,10 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
import static bjforth.machine.MemoryBuilder.aMemory;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static bjforth.utils.RandomUtils.nextInt;
import static org.assertj.core.api.Assertions.*;
@@ -47,7 +45,6 @@ void worksOk() {
var actualState =
aMachineState()
.withInstrcutionPointer(SUBSTOREaddr)
- .withNextInstructionPointer(SUBSTOREaddr + 1)
.withMemory(aMemory().with(addrToSubstore, initialValue).build())
.withParameterStack(aParameterStack().with(decrement, addrToSubstore).build())
.build();
@@ -59,14 +56,9 @@ void worksOk() {
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
.hasMemoryEqualTo(
aMemory().with(referenceState).with(addrToSubstore, initialValue - decrement).build())
- .hasParameterStackEqualTo(aParameterStack().build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().build());
}
@DisplayName("should throw if parameter stack top is not a number.")
@@ -77,7 +69,6 @@ void throwsIfNonNumber() {
var actualState =
aMachineState()
.withInstrcutionPointer(SUBSTOREaddr)
- .withNextInstructionPointer(SUBSTOREaddr + 1)
.withParameterStack(aParameterStack().with(new Object()).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -101,7 +92,6 @@ void throwIfEmpty() {
var actualState =
aMachineState()
.withInstrcutionPointer(SUBSTOREaddr)
- .withNextInstructionPointer(SUBSTOREaddr + 1)
.withParameterStack(aParameterStack().build())
.build();
var machine = aMachine().withState(actualState).build();
diff --git a/bjforth/src/test/java/bjforth/primitives/SUBTest.java b/bjforth/src/test/java/bjforth/primitives/SUBTest.java
index 3966d32e..8d2981bf 100644
--- a/bjforth/src/test/java/bjforth/primitives/SUBTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/SUBTest.java
@@ -19,11 +19,9 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.assertj.core.api.Assertions.*;
@@ -62,7 +60,6 @@ void worksOkWithNumbers(
var actualState =
aMachineState()
.withInstrcutionPointer(SUBaddr)
- .withNextInstructionPointer(SUBaddr + 1)
.withParameterStack(aParameterStack().with(parameter2, parameter1).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -73,13 +70,7 @@ void worksOkWithNumbers(
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build());
}
@DisplayName("should throw if any of parameter stack top is not a number.")
@@ -95,7 +86,6 @@ void throwsIfNonNumber(
var actualState =
aMachineState()
.withInstrcutionPointer(SUBaddr)
- .withNextInstructionPointer(SUBaddr + 1)
.withParameterStack(aParameterStack().with(parameter2, parameter1).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -119,7 +109,6 @@ void throwIfEmpty() {
var actualState =
aMachineState()
.withInstrcutionPointer(SUBaddr)
- .withNextInstructionPointer(SUBaddr + 1)
.withParameterStack(aParameterStack().build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -138,7 +127,6 @@ void throwIfOnlyOneElement() {
var actualState =
aMachineState()
.withInstrcutionPointer(SUBaddr)
- .withNextInstructionPointer(SUBaddr + 1)
.withParameterStack(aParameterStack().with(RandomUtils.nextBigDecimal()).build())
.build();
var machine = aMachine().withState(actualState).build();
diff --git a/bjforth/src/test/java/bjforth/primitives/SWAPTest.java b/bjforth/src/test/java/bjforth/primitives/SWAPTest.java
index 2d1aa459..373d885d 100644
--- a/bjforth/src/test/java/bjforth/primitives/SWAPTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/SWAPTest.java
@@ -19,11 +19,9 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.apache.commons.lang3.RandomUtils.nextInt;
import static org.assertj.core.api.Assertions.*;
@@ -45,7 +43,6 @@ public void worksOk() {
var actualState =
aMachineState()
.withInstrcutionPointer(SWAPaddr)
- .withNextInstructionPointer(SWAPaddr + 1)
.withParameterStack(aParameterStack().with(parameter1, parameter2).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -56,13 +53,7 @@ public void worksOk() {
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(parameter2, parameter1).build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().with(parameter2, parameter1).build());
}
@Test
@@ -73,7 +64,6 @@ public void throwIfEmpty() {
var actualState =
aMachineState()
.withInstrcutionPointer(SWAPaddr)
- .withNextInstructionPointer(SWAPaddr + 1)
.withParameterStack(aParameterStack().build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -92,7 +82,6 @@ public void throwIfOneElement() {
var actualState =
aMachineState()
.withInstrcutionPointer(SWAPaddr)
- .withNextInstructionPointer(SWAPaddr + 1)
.withParameterStack(aParameterStack().with(nextInt()).build())
.build();
var machine = aMachine().withState(actualState).build();
diff --git a/bjforth/src/test/java/bjforth/primitives/TELLTest.java b/bjforth/src/test/java/bjforth/primitives/TELLTest.java
index a6fb3701..6c44a7e4 100644
--- a/bjforth/src/test/java/bjforth/primitives/TELLTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/TELLTest.java
@@ -19,12 +19,10 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.assertThat;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
import static bjforth.machine.MemoryBuilder.aMemory;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.apache.commons.lang3.RandomUtils.nextInt;
import static org.assertj.core.api.Assertions.assertThat;
@@ -50,7 +48,6 @@ public void worksOk() {
var actualState =
aMachineState()
.withInstrcutionPointer(TELLaddr)
- .withNextInstructionPointer(TELLaddr + 1)
.withMemory(aMemory().with(stringAddr, string).build())
.withParameterStack(aParameterStack().with(length, stringAddr, stream).build())
.build();
@@ -61,14 +58,7 @@ public void worksOk() {
machine.step();
// THEN
- assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().build())
- .hasReturnStackEqualTo(referenceState);
+ assertThat(actualState).hasParameterStackEqualTo(aParameterStack().build());
assertThat(stream.toByteArray()).isEqualTo(string.getBytes());
}
@@ -80,7 +70,6 @@ public void throwIfEmpty() {
var actualState =
aMachineState()
.withInstrcutionPointer(TELLaddr)
- .withNextInstructionPointer(TELLaddr + 1)
.withParameterStack(aParameterStack().build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -99,7 +88,6 @@ public void throwIfOneElement() {
var actualState =
aMachineState()
.withInstrcutionPointer(TELLaddr)
- .withNextInstructionPointer(TELLaddr + 1)
.withParameterStack(aParameterStack().with(nextInt()).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -123,7 +111,6 @@ public void throwIfTwoElements() {
var actualState =
aMachineState()
.withInstrcutionPointer(TELLaddr)
- .withNextInstructionPointer(TELLaddr + 1)
.withParameterStack(aParameterStack().with(nextInt(), nextInt()).build())
.build();
var machine = aMachine().withState(actualState).build();
diff --git a/bjforth/src/test/java/bjforth/primitives/TORTest.java b/bjforth/src/test/java/bjforth/primitives/TORTest.java
index 453f7e3b..31e20e22 100644
--- a/bjforth/src/test/java/bjforth/primitives/TORTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/TORTest.java
@@ -19,12 +19,9 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.MemoryBuilder.aMemory;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static bjforth.machine.ReturnStackBuilder.aReturnStack;
import static bjforth.utils.RandomUtils.nextInt;
@@ -45,7 +42,6 @@ void worksOk() {
var actualState =
aMachineState()
.withInstrcutionPointer(TORaddr)
- .withNextInstructionPointer(TORaddr + 1)
.withParameterStack(aParameterStack().with(object).build())
.withReturnStack(aReturnStack().build())
.build();
@@ -57,11 +53,6 @@ void worksOk() {
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(aMemory().with(referenceState).build())
.hasParameterStackEqualTo(aParameterStack().build())
.hasReturnStackEqualTo(aReturnStack().with(object).build());
}
@@ -74,7 +65,6 @@ void throwIfEmpty() {
var actualState =
aMachineState()
.withInstrcutionPointer(TORaddr)
- .withNextInstructionPointer(TORaddr + 1)
.withParameterStack(aParameterStack().build())
.withReturnStack(aReturnStack().build())
.build();
diff --git a/bjforth/src/test/java/bjforth/primitives/TWODROPTest.java b/bjforth/src/test/java/bjforth/primitives/TWODROPTest.java
index a92c8702..565056cd 100644
--- a/bjforth/src/test/java/bjforth/primitives/TWODROPTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/TWODROPTest.java
@@ -19,11 +19,9 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.apache.commons.lang3.RandomUtils.nextInt;
import static org.assertj.core.api.Assertions.*;
@@ -46,7 +44,6 @@ void worksOk() {
var actualState =
aMachineState()
.withInstrcutionPointer(TWODROPaddr)
- .withNextInstructionPointer(TWODROPaddr + 1)
.withParameterStack(aParameterStack().with(parameter3, parameter2, parameter1).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -56,14 +53,7 @@ void worksOk() {
machine.step();
// THEN
- assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(parameter3).build())
- .hasReturnStackEqualTo(referenceState);
+ assertThat(actualState).hasParameterStackEqualTo(aParameterStack().with(parameter3).build());
}
@Test
@@ -74,7 +64,6 @@ void throwIfEmpty() {
var actualState =
aMachineState()
.withInstrcutionPointer(TWODROPaddr)
- .withNextInstructionPointer(TWODROPaddr + 1)
.withParameterStack(aParameterStack().build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -94,7 +83,6 @@ void throwIfParameterStackOneElement() {
var actualState =
aMachineState()
.withInstrcutionPointer(TWODROPaddr)
- .withNextInstructionPointer(TWODROPaddr + 1)
.withParameterStack(aParameterStack().with(parameter).build())
.build();
var machine = aMachine().withState(actualState).build();
diff --git a/bjforth/src/test/java/bjforth/primitives/TWODUPTest.java b/bjforth/src/test/java/bjforth/primitives/TWODUPTest.java
index 8bf3f3e4..66f3791d 100644
--- a/bjforth/src/test/java/bjforth/primitives/TWODUPTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/TWODUPTest.java
@@ -19,11 +19,9 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.apache.commons.lang3.RandomUtils.nextInt;
import static org.assertj.core.api.Assertions.*;
@@ -46,7 +44,6 @@ void worksOk() {
var actualState =
aMachineState()
.withInstrcutionPointer(TWODUPaddr)
- .withNextInstructionPointer(TWODUPaddr + 1)
.withParameterStack(aParameterStack().with(parameter3, parameter2, parameter1).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -57,16 +54,10 @@ void worksOk() {
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
.hasParameterStackEqualTo(
aParameterStack()
.with(parameter3, parameter2, parameter1, parameter2, parameter1)
- .build())
- .hasReturnStackEqualTo(referenceState);
+ .build());
}
@Test
@@ -77,7 +68,6 @@ void throwIfEmpty() {
var actualState =
aMachineState()
.withInstrcutionPointer(TWODUPaddr)
- .withNextInstructionPointer(TWODUPaddr + 1)
.withParameterStack(aParameterStack().build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -97,7 +87,6 @@ void throwIfParameterStackOneElement() {
var actualState =
aMachineState()
.withInstrcutionPointer(TWODUPaddr)
- .withNextInstructionPointer(TWODUPaddr + 1)
.withParameterStack(aParameterStack().with(parameter).build())
.build();
var machine = aMachine().withState(actualState).build();
diff --git a/bjforth/src/test/java/bjforth/primitives/TWOSWAPTest.java b/bjforth/src/test/java/bjforth/primitives/TWOSWAPTest.java
index ed51700d..e88d43ea 100644
--- a/bjforth/src/test/java/bjforth/primitives/TWOSWAPTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/TWOSWAPTest.java
@@ -19,11 +19,9 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.apache.commons.lang3.RandomUtils.nextInt;
import static org.assertj.core.api.Assertions.*;
@@ -47,7 +45,6 @@ void worksOk() {
var actualState =
aMachineState()
.withInstrcutionPointer(TWOSWAPaddr)
- .withNextInstructionPointer(TWOSWAPaddr + 1)
.withParameterStack(
aParameterStack().with(parameter4, parameter3, parameter2, parameter1).build())
.build();
@@ -59,14 +56,8 @@ void worksOk() {
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
.hasParameterStackEqualTo(
- aParameterStack().with(parameter2, parameter1, parameter4, parameter3).build())
- .hasReturnStackEqualTo(referenceState);
+ aParameterStack().with(parameter2, parameter1, parameter4, parameter3).build());
}
@Test
@@ -77,7 +68,6 @@ void throwIfEmpty() {
var actualState =
aMachineState()
.withInstrcutionPointer(TWOSWAPaddr)
- .withNextInstructionPointer(TWOSWAPaddr + 1)
.withParameterStack(aParameterStack().build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -97,7 +87,6 @@ void throwIfParameterStackOneElement() {
var actualState =
aMachineState()
.withInstrcutionPointer(TWOSWAPaddr)
- .withNextInstructionPointer(TWOSWAPaddr + 1)
.withParameterStack(aParameterStack().with(parameter).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -123,7 +112,6 @@ void throwIfParameterStackTwoElements() {
var actualState =
aMachineState()
.withInstrcutionPointer(TWOSWAPaddr)
- .withNextInstructionPointer(TWOSWAPaddr + 1)
.withParameterStack(aParameterStack().with(parameter1, parameter2).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -150,7 +138,6 @@ void throwIfParameterStackThreeElements() {
var actualState =
aMachineState()
.withInstrcutionPointer(TWOSWAPaddr)
- .withNextInstructionPointer(TWOSWAPaddr + 1)
.withParameterStack(aParameterStack().with(parameter1, parameter2, parameter3).build())
.build();
var machine = aMachine().withState(actualState).build();
diff --git a/bjforth/src/test/java/bjforth/primitives/WORDTest.java b/bjforth/src/test/java/bjforth/primitives/WORDTest.java
index eec3337b..2094bdb2 100644
--- a/bjforth/src/test/java/bjforth/primitives/WORDTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/WORDTest.java
@@ -19,11 +19,9 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.assertThat;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import java.io.ByteArrayInputStream;
@@ -58,11 +56,7 @@ void worksOk() {
System.setIn(inputStream);
var WORDaddr = getPrimitiveAddress("WORD");
- var actualState =
- aMachineState()
- .withInstrcutionPointer(WORDaddr)
- .withNextInstructionPointer(WORDaddr + 1)
- .build();
+ var actualState = aMachineState().withInstrcutionPointer(WORDaddr).build();
var machine = aMachine().withState(actualState).build();
var referenceState = aMachineState().copyFrom(actualState).build();
@@ -70,13 +64,7 @@ void worksOk() {
machine.step();
// THEN
- assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(wordStr).build())
- .hasReturnStackEqualTo(referenceState);
+ assertThat(actualState).hasParameterStackEqualTo(aParameterStack().with(wordStr).build());
}
@DisplayName("skips leading space")
@@ -89,11 +77,7 @@ void skipsLeadingSpace() {
System.setIn(inputStream);
var WORDaddr = getPrimitiveAddress("WORD");
- var actualState =
- aMachineState()
- .withInstrcutionPointer(WORDaddr)
- .withNextInstructionPointer(WORDaddr + 1)
- .build();
+ var actualState = aMachineState().withInstrcutionPointer(WORDaddr).build();
var machine = aMachine().withState(actualState).build();
var referenceState = aMachineState().copyFrom(actualState).build();
@@ -101,13 +85,7 @@ void skipsLeadingSpace() {
machine.step();
// THEN
- assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(wordStr).build())
- .hasReturnStackEqualTo(referenceState);
+ assertThat(actualState).hasParameterStackEqualTo(aParameterStack().with(wordStr).build());
}
@DisplayName("skips comment lines")
@@ -127,11 +105,7 @@ void skipsComments() {
System.setIn(inputStream);
var WORDaddr = getPrimitiveAddress("WORD");
- var actualState =
- aMachineState()
- .withInstrcutionPointer(WORDaddr)
- .withNextInstructionPointer(WORDaddr + 1)
- .build();
+ var actualState = aMachineState().withInstrcutionPointer(WORDaddr).build();
var machine = aMachine().withState(actualState).build();
var referenceState = aMachineState().copyFrom(actualState).build();
@@ -139,12 +113,6 @@ void skipsComments() {
machine.step();
// THEN
- assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(wordStr).build())
- .hasReturnStackEqualTo(referenceState);
+ assertThat(actualState).hasParameterStackEqualTo(aParameterStack().with(wordStr).build());
}
}
diff --git a/bjforth/src/test/java/bjforth/primitives/ZBRANCHTest.java b/bjforth/src/test/java/bjforth/primitives/ZBRANCHTest.java
index 2b29033f..3846b5d4 100644
--- a/bjforth/src/test/java/bjforth/primitives/ZBRANCHTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/ZBRANCHTest.java
@@ -61,10 +61,7 @@ public void worksOkIfZero() {
.hasInstructionPointerEqualTo(
anInstructionPointer().with(referenceState).plus(offset).plus(1).build())
.hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(offset).plus(1).build())
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().build())
- .hasReturnStackEqualTo(referenceState);
+ aNextInstructionPointer().with(referenceState).plus(offset).build());
}
@Test
@@ -92,10 +89,7 @@ public void worksOkIfNotZero() {
assertThat(actualState)
.hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(2).build())
.hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(2).build())
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().build())
- .hasReturnStackEqualTo(referenceState);
+ aNextInstructionPointer().with(referenceState).plus(1).build());
}
@Test
@@ -105,7 +99,6 @@ public void throwIfEmpty() {
var actualState =
aMachineState()
.withInstrcutionPointer(ZBRANCHaddr)
- .withNextInstructionPointer(ZBRANCHaddr + 1)
.withParameterStack(aParameterStack().build())
.build();
var machine = aMachine().withState(actualState).build();
diff --git a/bjforth/src/test/java/bjforth/primitives/ZEQUTest.java b/bjforth/src/test/java/bjforth/primitives/ZEQUTest.java
index d0b56e94..39b58c59 100644
--- a/bjforth/src/test/java/bjforth/primitives/ZEQUTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/ZEQUTest.java
@@ -19,11 +19,9 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.assertj.core.api.Assertions.*;
@@ -52,7 +50,6 @@ void worksOkWithNumbers(Object parameter, Object expectedResult, String paramete
var actualState =
aMachineState()
.withInstrcutionPointer(ZEQUaddr)
- .withNextInstructionPointer(ZEQUaddr + 1)
.withParameterStack(aParameterStack().with(parameter).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -63,13 +60,7 @@ void worksOkWithNumbers(Object parameter, Object expectedResult, String paramete
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build());
}
@DisplayName("should throw if top of ParameterStack is not a number.")
@@ -80,7 +71,6 @@ void throwIfNonNumber() {
var actualState =
aMachineState()
.withInstrcutionPointer(ZEQUaddr)
- .withNextInstructionPointer(ZEQUaddr + 1)
.withParameterStack(aParameterStack().with(new Object()).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -104,7 +94,6 @@ void throwIfEmpty() {
var actualState =
aMachineState()
.withInstrcutionPointer(ZEQUaddr)
- .withNextInstructionPointer(ZEQUaddr + 1)
.withParameterStack(aParameterStack().build())
.build();
var machine = aMachine().withState(actualState).build();
diff --git a/bjforth/src/test/java/bjforth/primitives/ZGETest.java b/bjforth/src/test/java/bjforth/primitives/ZGETest.java
index 8e890e4e..4ef14a16 100644
--- a/bjforth/src/test/java/bjforth/primitives/ZGETest.java
+++ b/bjforth/src/test/java/bjforth/primitives/ZGETest.java
@@ -19,11 +19,9 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static java.lang.Math.abs;
import static org.assertj.core.api.Assertions.*;
@@ -53,7 +51,6 @@ void worksOkWithNumbers(Object parameter, Object expectedResult, String paramete
var actualState =
aMachineState()
.withInstrcutionPointer(ZGEaddr)
- .withNextInstructionPointer(ZGEaddr + 1)
.withParameterStack(aParameterStack().with(parameter).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -64,13 +61,7 @@ void worksOkWithNumbers(Object parameter, Object expectedResult, String paramete
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build());
}
@DisplayName("should throw if top of ParameterStack is not a number.")
@@ -81,7 +72,6 @@ void throwIfNonNumber() {
var actualState =
aMachineState()
.withInstrcutionPointer(ZGEaddr)
- .withNextInstructionPointer(ZGEaddr + 1)
.withParameterStack(aParameterStack().with(new Object()).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -105,7 +95,6 @@ void throwIfEmpty() {
var actualState =
aMachineState()
.withInstrcutionPointer(ZGEaddr)
- .withNextInstructionPointer(ZGEaddr + 1)
.withParameterStack(aParameterStack().build())
.build();
var machine = aMachine().withState(actualState).build();
diff --git a/bjforth/src/test/java/bjforth/primitives/ZGTTest.java b/bjforth/src/test/java/bjforth/primitives/ZGTTest.java
index 0d48fd9d..f5378490 100644
--- a/bjforth/src/test/java/bjforth/primitives/ZGTTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/ZGTTest.java
@@ -19,11 +19,9 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static java.lang.Math.abs;
import static org.assertj.core.api.Assertions.*;
@@ -53,7 +51,6 @@ void worksOkWithNumbers(Object parameter, Object expectedResult, String paramete
var actualState =
aMachineState()
.withInstrcutionPointer(ZGTaddr)
- .withNextInstructionPointer(ZGTaddr + 1)
.withParameterStack(aParameterStack().with(parameter).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -64,13 +61,7 @@ void worksOkWithNumbers(Object parameter, Object expectedResult, String paramete
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build());
}
@DisplayName("should throw if top of ParameterStack is not a number.")
@@ -81,7 +72,6 @@ void throwIfNonNumber() {
var actualState =
aMachineState()
.withInstrcutionPointer(ZGTaddr)
- .withNextInstructionPointer(ZGTaddr + 1)
.withParameterStack(aParameterStack().with(new Object()).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -105,7 +95,6 @@ void throwIfEmpty() {
var actualState =
aMachineState()
.withInstrcutionPointer(ZGTaddr)
- .withNextInstructionPointer(ZGTaddr + 1)
.withParameterStack(aParameterStack().build())
.build();
var machine = aMachine().withState(actualState).build();
diff --git a/bjforth/src/test/java/bjforth/primitives/ZLETest.java b/bjforth/src/test/java/bjforth/primitives/ZLETest.java
index 34e84a71..df8f5a38 100644
--- a/bjforth/src/test/java/bjforth/primitives/ZLETest.java
+++ b/bjforth/src/test/java/bjforth/primitives/ZLETest.java
@@ -19,11 +19,9 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static java.lang.Math.abs;
import static org.assertj.core.api.Assertions.*;
@@ -53,7 +51,6 @@ void worksOkWithNumbers(Object parameter, Object expectedResult, String paramete
var actualState =
aMachineState()
.withInstrcutionPointer(ZLEaddr)
- .withNextInstructionPointer(ZLEaddr + 1)
.withParameterStack(aParameterStack().with(parameter).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -64,13 +61,7 @@ void worksOkWithNumbers(Object parameter, Object expectedResult, String paramete
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build());
}
@DisplayName("should throw if top of ParameterStack is not a number.")
@@ -81,7 +72,6 @@ void throwIfNonNumber() {
var actualState =
aMachineState()
.withInstrcutionPointer(ZLEaddr)
- .withNextInstructionPointer(ZLEaddr + 1)
.withParameterStack(aParameterStack().with(new Object()).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -105,7 +95,6 @@ void throwIfEmpty() {
var actualState =
aMachineState()
.withInstrcutionPointer(ZLEaddr)
- .withNextInstructionPointer(ZLEaddr + 1)
.withParameterStack(aParameterStack().build())
.build();
var machine = aMachine().withState(actualState).build();
diff --git a/bjforth/src/test/java/bjforth/primitives/ZLTTest.java b/bjforth/src/test/java/bjforth/primitives/ZLTTest.java
index e06350f5..e4dfc083 100644
--- a/bjforth/src/test/java/bjforth/primitives/ZLTTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/ZLTTest.java
@@ -19,11 +19,9 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static java.lang.Math.abs;
import static org.assertj.core.api.Assertions.*;
@@ -53,7 +51,6 @@ void worksOkWithNumbers(Object parameter, Object expectedResult, String paramete
var actualState =
aMachineState()
.withInstrcutionPointer(ZLTaddr)
- .withNextInstructionPointer(ZLTaddr + 1)
.withParameterStack(aParameterStack().with(parameter).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -64,13 +61,7 @@ void worksOkWithNumbers(Object parameter, Object expectedResult, String paramete
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build());
}
@DisplayName("should throw if top of ParameterStack is not a number.")
@@ -81,7 +72,6 @@ void throwIfNonNumber() {
var actualState =
aMachineState()
.withInstrcutionPointer(ZLTaddr)
- .withNextInstructionPointer(ZLTaddr + 1)
.withParameterStack(aParameterStack().with(new Object()).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -105,7 +95,6 @@ void throwIfEmpty() {
var actualState =
aMachineState()
.withInstrcutionPointer(ZLTaddr)
- .withNextInstructionPointer(ZLTaddr + 1)
.withParameterStack(aParameterStack().build())
.build();
var machine = aMachine().withState(actualState).build();
diff --git a/bjforth/src/test/java/bjforth/primitives/ZNEQUTest.java b/bjforth/src/test/java/bjforth/primitives/ZNEQUTest.java
index 290c9793..1c2ff813 100644
--- a/bjforth/src/test/java/bjforth/primitives/ZNEQUTest.java
+++ b/bjforth/src/test/java/bjforth/primitives/ZNEQUTest.java
@@ -19,11 +19,9 @@
package bjforth.primitives;
import static bjforth.machine.BootstrapUtils.getPrimitiveAddress;
-import static bjforth.machine.InstructionPointerBuilder.anInstructionPointer;
import static bjforth.machine.MachineAssertions.*;
import static bjforth.machine.MachineBuilder.aMachine;
import static bjforth.machine.MachineStateBuilder.aMachineState;
-import static bjforth.machine.NextInstructionPointerBuilder.aNextInstructionPointer;
import static bjforth.machine.ParameterStackBuilder.aParameterStack;
import static org.assertj.core.api.Assertions.*;
@@ -52,7 +50,6 @@ void worksOkWithNumbers(Object parameter, Object expectedResult, String paramete
var actualState =
aMachineState()
.withInstrcutionPointer(ZNEQUaddr)
- .withNextInstructionPointer(ZNEQUaddr + 1)
.withParameterStack(aParameterStack().with(parameter).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -63,13 +60,7 @@ void worksOkWithNumbers(Object parameter, Object expectedResult, String paramete
// THEN
assertThat(actualState)
- .hasInstructionPointerEqualTo(anInstructionPointer().with(referenceState).plus(1).build())
- .hasNextInstructionPointerEqualTo(
- aNextInstructionPointer().with(referenceState).plus(1).build())
- .hasDictionaryEqualTo(referenceState)
- .hasMemoryEqualTo(referenceState)
- .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build())
- .hasReturnStackEqualTo(referenceState);
+ .hasParameterStackEqualTo(aParameterStack().with(expectedResult).build());
}
@DisplayName("should throw if top of ParameterStack is not a number.")
@@ -80,7 +71,6 @@ void throwIfNonNumber() {
var actualState =
aMachineState()
.withInstrcutionPointer(ZNEQUaddr)
- .withNextInstructionPointer(ZNEQUaddr + 1)
.withParameterStack(aParameterStack().with(new Object()).build())
.build();
var machine = aMachine().withState(actualState).build();
@@ -104,7 +94,6 @@ void throwIfEmpty() {
var actualState =
aMachineState()
.withInstrcutionPointer(ZNEQUaddr)
- .withNextInstructionPointer(ZNEQUaddr + 1)
.withParameterStack(aParameterStack().build())
.build();
var machine = aMachine().withState(actualState).build();