--- /dev/null
+package edu.berkeley.fleet.api;
+
+public abstract class BenkoBox {
+
+ /** you should extend subclasses, not this class directly */
+ BenkoBox() { }
+
+ /** the descriptive name of this benkobox (relative to its ship) */
+ public abstract String getName();
+
+ /** the maximum number of instructions we can put in the BenkoBox instruction fifo,
+ * or Integer.MAX_VALUE if unbounded */
+ public abstract int getInstructionFifoLength();
+
+ public static abstract class Inbox extends BenkoBox {
+ public Inbox() { }
+ }
+
+ public static abstract class Outbox extends BenkoBox {
+ public Outbox() { }
+ }
+
+}
--- /dev/null
+package edu.berkeley.fleet.api;
+import java.io.*;
+import java.util.*;
+
+public abstract class Fleet implements Iterable<Ship> {
+
+ /** read a machine-formatted instruction from a file (into a Java object) */
+ public abstract Instruction readInstruction(DataInputStream is) throws IOException;
+
+ /** write a machine-formatted instruction to a file (from a Java object) */
+ public abstract void writeInstruction(DataOutputStream os, Instruction instr) throws IOException;
+
+ /** ships must be returned in the same order every time -- ordering may be significant */
+ public abstract Iterator<Ship> iterator();
+
+}
\ No newline at end of file
--- /dev/null
+package edu.berkeley.fleet.api;
+
+public abstract class Instruction {
+
+ public static class Kill extends Instruction {
+
+ public final BenkoBox benkoBox;
+ public final int count;
+ public Kill(BenkoBox benkoBox, int count) { this.benkoBox=benkoBox; this.count=count; }
+ public String toString() { return (count>1 ? "["+count+"] " : "") + "kill"; }
+
+ }
+
+ public static class Normal extends Instruction {
+
+ public final BenkoBox benkoBox;
+ public final BenkoBox dest;
+ public final int count;
+
+ public final boolean wait;
+ public final boolean dataIn;
+ public final boolean latch;
+ public final boolean dataOut;
+ public final boolean ack;
+ public final boolean recycle;
+
+ public Normal(BenkoBox benkoBox,
+ BenkoBox dest,
+ int count,
+ boolean dataIn,
+ boolean latch,
+ boolean ack,
+ boolean wait,
+ boolean dataOut,
+ boolean recycle) {
+ this.benkoBox = benkoBox;
+ this.dest = dest;
+ this.count = count;
+ this.dataIn = dataIn;
+ this.latch = latch;
+ this.ack = ack;
+ this.wait = wait;
+ this.dataOut = dataOut;
+ this.recycle = recycle;
+ if (count <= 0)
+ throw new RuntimeException("count field of an instruction must be >0");
+ }
+
+ }
+
+ public static class Literal extends Instruction {
+ public final BenkoBox dest;
+ protected Literal(BenkoBox dest) { this.dest = dest; }
+
+ public static class Absolute extends Literal {
+ public final long value;
+ public Absolute(BenkoBox dest, long value) { super(dest); this.value = value; }
+ public String toString() { return value + ": sendto " + dest; }
+ }
+
+ public static class Relative extends Literal {
+ /** value transmitted will be offset plus the address from which this instruction was loaded */
+ public final long offset;
+ public Relative(BenkoBox dest, long offset) { super(dest); this.offset = offset; }
+ // FIXME: not final form!
+ public String toString() { return "(relative "+offset+"): sendto " + dest; }
+ }
+
+ public static class CodeBagDescriptor extends Literal {
+ /** address of CBD, relative to address that this instruction was loaded from */
+ public final long offset;
+ public final long size;
+ public CodeBagDescriptor(BenkoBox dest, long offset, long size) {
+ super(dest); this.offset = offset; this.size = size; }
+ // FIXME: not final form!
+ public String toString() { return "(CBD "+offset+":"+size+"): sendto " + dest; }
+ }
+ }
+}