Compare commits

..

No commits in common. "422344097b2aeb1a5fe9b021d74dbf9d82806b68" and "a05b2fbeeee5d2a125fb89bd259042b534f12437" have entirely different histories.

11 changed files with 39 additions and 36 deletions

View file

@ -1,8 +1,11 @@
package hatelace; package hatelace;
public interface Instruction { public abstract class Instruction {
void execute(Memory memory, ProgramCounter pc); public abstract void execute(Memory memory, ProgramCounter pc);
String opcode();
Object[] operands(); protected abstract String opcode();
String toString();
protected abstract Object[] operands();
public abstract String toString();
} }

View file

@ -1,11 +1,11 @@
package hatelace; package hatelace;
public interface Word { public abstract class Word {
<T> T getValue(); public abstract <T> T getValue();
Word add(Word other); public abstract Word add(Word other);
Word subtract(Word other); public abstract Word subtract(Word other);
Word multiply(Word other); public abstract Word multiply(Word other);
Word divide(Word other); public abstract Word divide(Word other);
String toString(); public abstract String toString();
boolean equals(Object other); public abstract boolean equals(Object other);
} }

View file

@ -2,7 +2,7 @@ package hatelace.instructions;
import hatelace.*; import hatelace.*;
public class Add implements Instruction { public class Add extends Instruction {
private Address src; private Address src;
private Word imm; private Word imm;
private Address dest; private Address dest;
@ -19,7 +19,7 @@ public class Add implements Instruction {
PC.incPC(); PC.incPC();
} }
public String opcode() { protected String opcode() {
return "ADD"; return "ADD";
} }
@ -27,7 +27,7 @@ public class Add implements Instruction {
return String.format("%s [%s] %s [%s]", this.opcode(), this.src, this.imm, this.dest); return String.format("%s [%s] %s [%s]", this.opcode(), this.src, this.imm, this.dest);
} }
public Object[] operands() { protected Object[] operands() {
return new Object[] { this.src, this.imm, this.dest }; return new Object[] { this.src, this.imm, this.dest };
} }
} }

View file

@ -2,7 +2,7 @@ package hatelace.instructions;
import hatelace.*; import hatelace.*;
public class Copy implements Instruction { public class Copy extends Instruction {
private Word imm; private Word imm;
private Address dest; private Address dest;
@ -17,11 +17,11 @@ public class Copy implements Instruction {
PC.incPC(); PC.incPC();
} }
public String opcode() { protected String opcode() {
return "CPY"; return "CPY";
} }
public Object[] operands() { protected Object[] operands() {
return new Object[] {this.imm, this.dest}; return new Object[] {this.imm, this.dest};
} }

View file

@ -2,7 +2,7 @@ package hatelace.instructions;
import hatelace.*; import hatelace.*;
public class Halt implements Instruction { public class Halt extends Instruction {
/** Halts the CPU */ /** Halts the CPU */
public Halt(){}; public Halt(){};
@ -10,11 +10,11 @@ public class Halt implements Instruction {
PC.halt(); PC.halt();
} }
public String opcode() { protected String opcode() {
return "HLT"; return "HLT";
} }
public Object[] operands() { protected Object[] operands() {
return new Object[] {}; return new Object[] {};
} }

View file

@ -2,7 +2,7 @@ package hatelace.instructions;
import hatelace.*; import hatelace.*;
public class Jump implements Instruction { public class Jump extends Instruction {
private int index; private int index;
/** Unconditional jump, non-relative */ /** Unconditional jump, non-relative */
@ -14,11 +14,11 @@ public class Jump implements Instruction {
PC.setPC(this.index); PC.setPC(this.index);
} }
public String opcode() { protected String opcode() {
return "JMP"; return "JMP";
} }
public Object[] operands() { protected Object[] operands() {
return new Object[] {this.index}; return new Object[] {this.index};
} }

View file

@ -2,7 +2,7 @@ package hatelace.instructions;
import hatelace.*; import hatelace.*;
public class JumpEq implements Instruction { public class JumpEq extends Instruction {
private int index; private int index;
private Address src; private Address src;
private Word imm; private Word imm;
@ -22,11 +22,11 @@ public class JumpEq implements Instruction {
} }
} }
public String opcode() { protected String opcode() {
return "JEQ"; return "JEQ";
} }
public Object[] operands() { protected Object[] operands() {
return new Object[] {this.index, this.src, this.imm}; return new Object[] {this.index, this.src, this.imm};
} }

View file

@ -2,7 +2,7 @@ package hatelace.instructions;
import hatelace.*; import hatelace.*;
public class Mul implements Instruction { public class Mul extends Instruction {
private Address src1; private Address src1;
private Address src2; private Address src2;
private Address dest; private Address dest;
@ -19,11 +19,11 @@ public class Mul implements Instruction {
PC.incPC(); PC.incPC();
} }
public String opcode() { protected String opcode() {
return "MUL"; return "MUL";
} }
public Object[] operands() { protected Object[] operands() {
return new Object[] { this.src1, this.src2, this.dest }; return new Object[] { this.src1, this.src2, this.dest };
} }

View file

@ -2,7 +2,7 @@ package hatelace.instructions;
import hatelace.*; import hatelace.*;
public class Print implements Instruction { public class Print extends Instruction {
private Address address; private Address address;
/** Print content of memory address */ /** Print content of memory address */
@ -15,11 +15,11 @@ public class Print implements Instruction {
PC.incPC(); PC.incPC();
} }
public String opcode() { protected String opcode() {
return "PRT"; return "PRT";
} }
public Object[] operands() { protected Object[] operands() {
return new Object[] { this.address }; return new Object[] { this.address };
} }

View file

@ -2,7 +2,7 @@ package hatelace.memtypes;
import hatelace.Word; import hatelace.Word;
public class IntWord implements Word { public class IntWord extends Word {
private Integer value; private Integer value;
public IntWord(Integer value) { public IntWord(Integer value) {

View file

@ -2,7 +2,7 @@ package hatelace.memtypes;
import hatelace.Word; import hatelace.Word;
public class LongWord implements Word { public class LongWord extends Word {
private Long value; private Long value;
public LongWord(Long value) { public LongWord(Long value) {