Checkpoint 2
This commit is contained in:
parent
7d7509e852
commit
e0845968a1
4 changed files with 17 additions and 27 deletions
|
@ -7,31 +7,23 @@ public class IntWord extends Word {
|
|||
this.value = value;
|
||||
}
|
||||
|
||||
// public <T> T getValue() {
|
||||
// return value;
|
||||
// }
|
||||
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public IntWord multiply(Word value) {
|
||||
public Word add(Word other) {
|
||||
return new IntWord(value + (Integer) other.getValue());
|
||||
}
|
||||
|
||||
public Word subtract(Word other) {
|
||||
return new IntWord(value - (Integer) other.getValue());
|
||||
}
|
||||
|
||||
public Word multiply(Word value) {
|
||||
return new IntWord(this.value * (Integer) value.getValue());
|
||||
}
|
||||
|
||||
public <T> T add(Word other) {
|
||||
return (T) new IntWord(value + (Integer) other.getValue());
|
||||
}
|
||||
|
||||
public <T> T subtract(Word other) {
|
||||
return (T) new IntWord(value - (Integer) other.getValue());
|
||||
}
|
||||
|
||||
// public <T> T multiply(Word other) {
|
||||
// return (T) new IntWord(value * (Integer) other.getValue());
|
||||
// }
|
||||
|
||||
public <T> T divide(Word other) {
|
||||
return (T) new IntWord(value / (Integer) other.getValue());
|
||||
public Word divide(Word other) {
|
||||
return new IntWord(value / (Integer) other.getValue());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@ package hatelace;
|
|||
|
||||
public abstract class Word {
|
||||
public abstract <T> T getValue();
|
||||
public abstract <T> T add(Word other);
|
||||
public abstract <T> T subtract(Word other);
|
||||
public abstract <T> T multiply(Word other);
|
||||
public abstract <T> T divide(Word other);
|
||||
public abstract Word add(Word other);
|
||||
public abstract Word subtract(Word other);
|
||||
public abstract Word multiply(Word other);
|
||||
public abstract Word divide(Word other);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package hatelace.instructions;
|
|||
import hatelace.Instruction;
|
||||
import hatelace.Memory;
|
||||
import hatelace.ProgramCounter;
|
||||
import hatelace.IntWord;
|
||||
import hatelace.Word;
|
||||
import hatelace.Address;
|
||||
|
||||
|
@ -19,7 +18,7 @@ public class Add extends Instruction {
|
|||
}
|
||||
|
||||
public void execute(Memory memory, ProgramCounter PC) {
|
||||
memory.write(this.dest, new IntWord(op1.add(op2)));
|
||||
memory.write(this.dest, op1.add(op2));
|
||||
PC.incPC();
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ import hatelace.Word;
|
|||
import hatelace.Instruction;
|
||||
import hatelace.Memory;
|
||||
import hatelace.ProgramCounter;
|
||||
import hatelace.IntWord;
|
||||
|
||||
public class Mul extends Instruction {
|
||||
private Word op1;
|
||||
|
@ -19,7 +18,7 @@ public class Mul extends Instruction {
|
|||
}
|
||||
|
||||
public void execute(Memory memory, ProgramCounter PC) {
|
||||
memory.write(this.dest, new IntWord(op1.multiply(op2)));
|
||||
memory.write(this.dest, op1.multiply(op2));
|
||||
PC.incPC();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue