Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions bjforth/src/main/java/bjforth/machine/DictionaryItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion bjforth/src/main/java/bjforth/primitives/SEE.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(" ");
Expand Down
4 changes: 4 additions & 0 deletions bjforth/src/main/java/bjforth/primitives/SEMICOLON.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions bjforth/src/test/java/bjforth/primitives/SEMICOLONTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}