diff --git a/.gitignore b/.gitignore index a007f0d..77b3a40 100644 --- a/.gitignore +++ b/.gitignore @@ -36,8 +36,6 @@ gradle-app.setting *.tar.gz *.rar -*.minisig - # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* replay_pid* diff --git a/app/src/main/java/hatelace/Address.java b/app/src/main/java/hatelace/Address.java index f914865..fb4d249 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 implements Operand { +public class Address { int address; public Address(int address) { @@ -14,8 +14,4 @@ public class Address implements Operand { 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 deleted file mode 100644 index bcdc6be..0000000 --- a/app/src/main/java/hatelace/Operand.java +++ /dev/null @@ -1,5 +0,0 @@ -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 b0bbb17..db74dbc 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 implements Operand { +public abstract class Word { public abstract T getValue(); public abstract Word add(Word other); public abstract Word subtract(Word other); diff --git a/app/src/main/java/hatelace/instructions/Add.java b/app/src/main/java/hatelace/instructions/Add.java index 1b88504..fc5c2ab 100644 --- a/app/src/main/java/hatelace/instructions/Add.java +++ b/app/src/main/java/hatelace/instructions/Add.java @@ -3,18 +3,19 @@ package hatelace.instructions; import hatelace.*; public class Add extends Instruction { + private Address src; + private Word imm; private Address dest; - private Operand o1, o2; /** Add immediate value to memory address. */ - public Add(Operand o1, Operand o2, Address dest) { - this.o1 = o1; - this.o2 = o2; + public Add(Address src, Word imm, Address dest) { + this.src = src; + this.imm = imm; this.dest = dest; } public void execute(Memory memory, ProgramCounter PC) { - memory.write(this.dest, this.o1.getWord(memory).add(this.o2.getWord(memory))); + memory.write(this.dest, memory.read(this.src).add(this.imm)); PC.incPC(); } @@ -23,10 +24,10 @@ public class Add extends Instruction { } public String toString() { - return String.format("%s [%s] %s [%s]", this.opcode(), this.o1, this.o2, this.dest); + return String.format("%s [%s] %s [%s]", this.opcode(), this.src, this.imm, this.dest); } protected Object[] operands() { - return new Object[] { this.o1, this.o2, this.dest }; + return new Object[] { this.src, this.imm, this.dest }; } } diff --git a/app/src/main/java/hatelace/instructions/Copy.java b/app/src/main/java/hatelace/instructions/Copy.java index a88c27e..985ce1a 100644 --- a/app/src/main/java/hatelace/instructions/Copy.java +++ b/app/src/main/java/hatelace/instructions/Copy.java @@ -3,17 +3,17 @@ package hatelace.instructions; import hatelace.*; public class Copy extends Instruction { - private Operand src; + private Word imm; private Address dest; /** Copy immediate value to memory address. */ - public Copy(Operand src, Address dest) { - this.src = src; + public Copy(Word imm, Address dest) { + this.imm = imm; this.dest = dest; } public void execute(Memory memory, ProgramCounter PC) { - memory.write(this.dest, this.src.getWord(memory)); + memory.write(this.dest, this.imm); PC.incPC(); } @@ -22,10 +22,10 @@ public class Copy extends Instruction { } protected Object[] operands() { - return new Object[] {this.src, this.dest}; + return new Object[] {this.imm, this.dest}; } public String toString() { - return String.format("%s %s [%s]", this.opcode(), this.src, this.dest); + return String.format("%s %s [%s]", this.opcode(), this.imm, this.dest); } } diff --git a/app/src/main/java/hatelace/instructions/JumpEq.java b/app/src/main/java/hatelace/instructions/JumpEq.java index a0b27ba..f2538be 100644 --- a/app/src/main/java/hatelace/instructions/JumpEq.java +++ b/app/src/main/java/hatelace/instructions/JumpEq.java @@ -4,18 +4,18 @@ import hatelace.*; public class JumpEq extends Instruction { private int index; - private Operand o1; - private Operand o2; + private Address src; + private Word imm; /** Conditional jump */ - public JumpEq(int index, Operand o1, Operand o2) { + public JumpEq(int index, Address src, Word imm) { this.index = index; - this.o1 = o1; - this.o2 = o2; + this.src = src; + this.imm = imm; } public void execute(Memory memory, ProgramCounter PC) { - if (this.o1.getWord(memory).equals(this.o2.getWord(memory))) { + if (this.imm.equals(memory.read(this.src))) { PC.setPC(this.index); } else { PC.incPC(); @@ -27,10 +27,10 @@ public class JumpEq extends Instruction { } protected Object[] operands() { - return new Object[] {this.index, this.o1, this.o2}; + return new Object[] {this.index, this.src, this.imm}; } public String toString() { - return String.format("%s %s [%s] %s", this.opcode(), this.index, this.o1, this.o2); + return String.format("%s %s [%s] %s", this.opcode(), this.index, this.src, this.imm); } } diff --git a/app/src/main/java/hatelace/instructions/Mul.java b/app/src/main/java/hatelace/instructions/Mul.java index 4536682..cd61d81 100644 --- a/app/src/main/java/hatelace/instructions/Mul.java +++ b/app/src/main/java/hatelace/instructions/Mul.java @@ -3,19 +3,19 @@ package hatelace.instructions; import hatelace.*; public class Mul extends Instruction { - private Operand o1; - private Operand o2; + private Address src1; + private Address src2; private Address dest; /** Multiply contents of two addresses and store the result in a third memory address. */ - public Mul(Operand o1, Operand o2, Address dest) { - this.o1 = o1; - this.o2 = o2; + public Mul(Address src1, Address src2, Address dest) { + this.src1 = src1; + this.src2 = src2; this.dest = dest; } public void execute(Memory memory, ProgramCounter PC) { - memory.write(this.dest, this.o1.getWord(memory).multiply(this.o2.getWord(memory))); + memory.write(this.dest, memory.read(this.src1).multiply(memory.read(this.src2))); PC.incPC(); } @@ -24,10 +24,10 @@ public class Mul extends Instruction { } protected Object[] operands() { - return new Object[] { this.o1, this.o2, this.dest }; + return new Object[] { this.src1, this.src2, this.dest }; } public String toString() { - return String.format("%s [%s] [%s] [%s]", this.opcode(), this.o1, this.o2, this.dest); + return String.format("%s [%s] [%s] [%s]", this.opcode(), this.src1, this.src2, this.dest); } } diff --git a/app/src/main/java/hatelace/memtypes/IntWord.java b/app/src/main/java/hatelace/memtypes/IntWord.java index ba8402d..75c00a8 100644 --- a/app/src/main/java/hatelace/memtypes/IntWord.java +++ b/app/src/main/java/hatelace/memtypes/IntWord.java @@ -1,6 +1,5 @@ package hatelace.memtypes; -import hatelace.Memory; import hatelace.Word; public class IntWord extends Word { @@ -16,11 +15,6 @@ 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 272ffd5..f01ace2 100644 --- a/app/src/main/java/hatelace/memtypes/LongWord.java +++ b/app/src/main/java/hatelace/memtypes/LongWord.java @@ -1,6 +1,5 @@ package hatelace.memtypes; -import hatelace.Memory; import hatelace.Word; public class LongWord extends Word { @@ -16,11 +15,6 @@ 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()); }