From 66afdf9085c069861c8d51dc82467666c179d513 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sat, 11 May 2024 19:27:59 +0200 Subject: [PATCH] Operand implemented, not used in instructions --- app/src/main/java/hatelace/Address.java | 6 +++++- app/src/main/java/hatelace/Operand.java | 5 +++++ app/src/main/java/hatelace/Word.java | 2 +- app/src/main/java/hatelace/memtypes/IntWord.java | 6 ++++++ app/src/main/java/hatelace/memtypes/LongWord.java | 6 ++++++ 5 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/hatelace/Operand.java diff --git a/app/src/main/java/hatelace/Address.java b/app/src/main/java/hatelace/Address.java index fb4d249..f914865 100644 --- a/app/src/main/java/hatelace/Address.java +++ b/app/src/main/java/hatelace/Address.java @@ -1,6 +1,6 @@ package hatelace; -public class Address { +public class Address implements Operand { int address; public Address(int address) { @@ -14,4 +14,8 @@ public class Address { public String toString() { return Integer.toString(address); } + + public Word getWord(Memory memory) { + return memory.read(this); + } } diff --git a/app/src/main/java/hatelace/Operand.java b/app/src/main/java/hatelace/Operand.java new file mode 100644 index 0000000..bcdc6be --- /dev/null +++ b/app/src/main/java/hatelace/Operand.java @@ -0,0 +1,5 @@ +package hatelace; + +public interface Operand { + Word getWord(Memory memory); +} diff --git a/app/src/main/java/hatelace/Word.java b/app/src/main/java/hatelace/Word.java index db74dbc..b0bbb17 100644 --- a/app/src/main/java/hatelace/Word.java +++ b/app/src/main/java/hatelace/Word.java @@ -1,6 +1,6 @@ package hatelace; -public abstract class Word { +public abstract class Word implements Operand { public abstract T getValue(); public abstract Word add(Word other); public abstract Word subtract(Word other); diff --git a/app/src/main/java/hatelace/memtypes/IntWord.java b/app/src/main/java/hatelace/memtypes/IntWord.java index 75c00a8..ba8402d 100644 --- a/app/src/main/java/hatelace/memtypes/IntWord.java +++ b/app/src/main/java/hatelace/memtypes/IntWord.java @@ -1,5 +1,6 @@ package hatelace.memtypes; +import hatelace.Memory; import hatelace.Word; public class IntWord extends Word { @@ -15,6 +16,11 @@ public class IntWord extends Word { return value; } + @Override + public Word getWord(Memory memory) { + return this; + } + public Word add(Word other) { return new IntWord(value + (Integer) other.getValue()); } diff --git a/app/src/main/java/hatelace/memtypes/LongWord.java b/app/src/main/java/hatelace/memtypes/LongWord.java index f01ace2..272ffd5 100644 --- a/app/src/main/java/hatelace/memtypes/LongWord.java +++ b/app/src/main/java/hatelace/memtypes/LongWord.java @@ -1,5 +1,6 @@ package hatelace.memtypes; +import hatelace.Memory; import hatelace.Word; public class LongWord extends Word { @@ -15,6 +16,11 @@ public class LongWord extends Word { return value; } + @Override + public Word getWord(Memory memory) { + return this; + } + public Word add(Word other) { return new LongWord(value + (Long) other.getValue()); }