Operand implemented, not used in instructions

This commit is contained in:
Imbus 2024-05-11 19:27:59 +02:00
parent a00f27aa25
commit 66afdf9085
5 changed files with 23 additions and 2 deletions

View file

@ -1,6 +1,6 @@
package hatelace; package hatelace;
public class Address { public class Address implements Operand {
int address; int address;
public Address(int address) { public Address(int address) {
@ -14,4 +14,8 @@ public class Address {
public String toString() { public String toString() {
return Integer.toString(address); return Integer.toString(address);
} }
public Word getWord(Memory memory) {
return memory.read(this);
}
} }

View file

@ -0,0 +1,5 @@
package hatelace;
public interface Operand {
Word getWord(Memory memory);
}

View file

@ -1,6 +1,6 @@
package hatelace; package hatelace;
public abstract class Word { public abstract class Word implements Operand {
public abstract <T> T getValue(); public abstract <T> T getValue();
public abstract Word add(Word other); public abstract Word add(Word other);
public abstract Word subtract(Word other); public abstract Word subtract(Word other);

View file

@ -1,5 +1,6 @@
package hatelace.memtypes; package hatelace.memtypes;
import hatelace.Memory;
import hatelace.Word; import hatelace.Word;
public class IntWord extends Word { public class IntWord extends Word {
@ -15,6 +16,11 @@ public class IntWord extends Word {
return value; return value;
} }
@Override
public Word getWord(Memory memory) {
return this;
}
public Word add(Word other) { public Word add(Word other) {
return new IntWord(value + (Integer) other.getValue()); return new IntWord(value + (Integer) other.getValue());
} }

View file

@ -1,5 +1,6 @@
package hatelace.memtypes; package hatelace.memtypes;
import hatelace.Memory;
import hatelace.Word; import hatelace.Word;
public class LongWord extends Word { public class LongWord extends Word {
@ -15,6 +16,11 @@ public class LongWord extends Word {
return value; return value;
} }
@Override
public Word getWord(Memory memory) {
return this;
}
public Word add(Word other) { public Word add(Word other) {
return new LongWord(value + (Long) other.getValue()); return new LongWord(value + (Long) other.getValue());
} }