diff --git a/bjforth/src/main/java/bjforth/machine/DictionaryItem.java b/bjforth/src/main/java/bjforth/machine/DictionaryItem.java index 39197203..ca3257e0 100644 --- a/bjforth/src/main/java/bjforth/machine/DictionaryItem.java +++ b/bjforth/src/main/java/bjforth/machine/DictionaryItem.java @@ -23,6 +23,7 @@ public class DictionaryItem { private Integer address; private Boolean isImmediate; private Boolean isHidden; + private Integer length = 1; public DictionaryItem(String name, Integer address, Boolean isImmediate, Boolean isHidden) { this.name = name; @@ -70,6 +71,14 @@ public void setIsHidden(Boolean isHidden) { this.isHidden = isHidden; } + public Integer getLength() { + return length; + } + + public void setLength(Integer length) { + this.length = length; + } + @Override public String toString() { return "DictionaryItem(%s, %d, %s, %s)".formatted(name, address, isImmediate, isHidden); diff --git a/bjforth/src/main/java/bjforth/primitives/SEE.java b/bjforth/src/main/java/bjforth/primitives/SEE.java index c1b962e8..1f664807 100644 --- a/bjforth/src/main/java/bjforth/primitives/SEE.java +++ b/bjforth/src/main/java/bjforth/primitives/SEE.java @@ -46,7 +46,7 @@ public void execute(Machine machine) { var addr = target.getAddress() + 1; content = machine.getMemoryAt(addr); - while (!"DOCOL".equals(content) && addr < HEREvalue) { + while (addr < target.getLength() + target.getAddress()) { if (content == null) { System.out.print(colorize("null", FOREGROUND_COLOR, BACKGROUND_COLOR)); System.out.print(" "); diff --git a/bjforth/src/main/java/bjforth/primitives/SEMICOLON.java b/bjforth/src/main/java/bjforth/primitives/SEMICOLON.java index 410eea25..d2152e02 100644 --- a/bjforth/src/main/java/bjforth/primitives/SEMICOLON.java +++ b/bjforth/src/main/java/bjforth/primitives/SEMICOLON.java @@ -33,6 +33,10 @@ public void execute(Machine machine) { machine.setMemoryAt(Variables.get("HERE").getAddress(), HEREvalue + 1); var LATESTvalue = (Integer) machine.getMemoryAt(Variables.get("LATEST").getAddress()); machine.pushToParameterStack(LATESTvalue); + + var dictItem = machine.getDictionaryItem(LATESTvalue); + dictItem.get().setLength(HEREvalue - LATESTvalue); + HIDDEN().execute(machine); LBRAC().execute(machine); EXIT().execute(machine); diff --git a/bjforth/src/test/java/bjforth/primitives/SEMICOLONTest.java b/bjforth/src/test/java/bjforth/primitives/SEMICOLONTest.java index aa02469e..c339718a 100644 --- a/bjforth/src/test/java/bjforth/primitives/SEMICOLONTest.java +++ b/bjforth/src/test/java/bjforth/primitives/SEMICOLONTest.java @@ -23,12 +23,12 @@ import static bjforth.machine.MachineBuilder.aMachine; import static bjforth.machine.MachineStateBuilder.aMachineState; import static bjforth.machine.ReturnStackBuilder.aReturnStack; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.*; import bjforth.machine.DictionaryItem; import bjforth.variables.Variables; import org.apache.commons.lang3.RandomUtils; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -59,6 +59,8 @@ void worksOk() { // THEN assertThat(actualState).hasReturnStackEqualTo(aReturnStack().with(NIP).build()); - Assertions.assertThat(machine.getDictionaryItem("FOO").get().getIsHidden()).isFalse(); + assertThat(machine.getDictionaryItem("FOO").get().getIsHidden()).isFalse(); + assertThat(machine.getDictionaryItem("FOO").get().getLength()) + .isEqualTo(HEREvalue - LATESTvalue); } }