add initial support for virtual destinations
authoradam <adam@megacz.com>
Sat, 17 Feb 2007 08:40:21 +0000 (09:40 +0100)
committeradam <adam@megacz.com>
Sat, 17 Feb 2007 08:40:21 +0000 (09:40 +0100)
src/edu/berkeley/fleet/api/BenkoBox.java
src/edu/berkeley/fleet/api/Destination.java [new file with mode: 0644]
src/edu/berkeley/fleet/api/Instruction.java
src/edu/berkeley/fleet/ies44/InstructionEncoder.java
src/edu/berkeley/fleet/interpreter/Interpreter.java
tests/alu2/simple-alu2-test.fleet

index 1e93825..5a3d9dd 100644 (file)
@@ -1,6 +1,7 @@
 package edu.berkeley.fleet.api;
+import java.util.*;
 
-public abstract class BenkoBox {
+public abstract class BenkoBox extends Destination {
 
     /** you should extend subclasses, not this class directly */
     //FIXME
@@ -24,4 +25,10 @@ public abstract class BenkoBox {
         public Outbox() { }
     }
 
+    /** get all destinations associated with this BenkoBox */
+    public Iterable<Destination> getDestinations() {
+        HashSet<Destination> self = new HashSet<Destination>();
+        self.add(this);
+        return self;
+    }
 }            
diff --git a/src/edu/berkeley/fleet/api/Destination.java b/src/edu/berkeley/fleet/api/Destination.java
new file mode 100644 (file)
index 0000000..8bf7270
--- /dev/null
@@ -0,0 +1,10 @@
+package edu.berkeley.fleet.api;
+
+public abstract class Destination {
+
+    Destination() { }
+
+    /** return the Ship to which this BenkoBox belongs */
+    public abstract Ship   getShip();
+
+}            
index 5e3c106..5b89965 100644 (file)
@@ -18,9 +18,9 @@ public abstract class Instruction {
 
     public static class Executable extends Instruction {
 
-        public final BenkoBox benkoBox;
-        public final BenkoBox dest;
-        public final int      count;
+        public final BenkoBox    benkoBox;
+        public final Destination dest;
+        public final int         count;
 
         public final boolean  tokenIn;
         public final boolean  dataIn;
@@ -30,15 +30,15 @@ public abstract class Instruction {
         public final boolean  recycle;
 
         /** count=0 denotes a standing move */
-        public Executable(BenkoBox benkoBox,
-                          BenkoBox dest,
-                          int      count,
-                          boolean  tokenIn,
-                          boolean  dataIn,
-                          boolean  latch,
-                          boolean  dataOut,
-                          boolean  tokenOut,
-                          boolean  recycle) {
+        public Executable(BenkoBox    benkoBox,
+                          Destination dest,
+                          int         count,
+                          boolean     tokenIn,
+                          boolean     dataIn,
+                          boolean     latch,
+                          boolean     dataOut,
+                          boolean     tokenOut,
+                          boolean     recycle) {
             this.benkoBox = benkoBox;
             this.dest = dest;
             this.count = count;
@@ -94,12 +94,12 @@ public abstract class Instruction {
     }
 
     public static class Literal extends Instruction {
-        public final BenkoBox dest;
-        protected Literal(BenkoBox dest) { this.dest = dest; }
+        public final Destination dest;
+        protected Literal(Destination 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 Absolute(Destination dest, long value) { super(dest); this.value = value; }
             public String toString() {
                 return value + ": sendto " + dest;
             }
@@ -108,7 +108,7 @@ public abstract class Instruction {
         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; }
+            public Relative(Destination dest, long offset) { super(dest); this.offset = offset; }
             public String toString() {
                 String off = ""+offset;
                 if (offset > 0) off = "+"+off;
@@ -120,7 +120,7 @@ public abstract class Instruction {
             /** 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) {
+            public CodeBagDescriptor(Destination dest, long offset, long size) {
                 super(dest); this.offset = offset; this.size = size; }
             public String toString() {
                 String off = ""+offset;
index e8f38a3..0e9174d 100644 (file)
@@ -6,7 +6,7 @@ import java.io.*;
 public abstract class InstructionEncoder {
 
     /** get the bits describing this box's location on the DESTINATION HORN */
-    public abstract long getBoxAddr(BenkoBox box);
+    public abstract long getBoxAddr(Destination box);
 
     /** get the bits describing this box's location on the INSTRUCTION HORN */
     public abstract long getBoxInstAddr(BenkoBox box);
@@ -91,7 +91,7 @@ public abstract class InstructionEncoder {
 
         if (d instanceof Instruction.Executable) {
             Instruction.Executable inst = (Instruction.Executable)d;
-            BenkoBox dest = inst.dest;
+            Destination dest = inst.dest;
             instr = dest==null ? 0 : (getBoxAddr(dest) << 1);
             if (inst.count >= (1<<8))
                 throw new RuntimeException("count field must be less than 128");
index 16f36b8..d78be10 100644 (file)
@@ -206,7 +206,7 @@ public class Interpreter extends Fleet {
     public void writeInstruction(DataOutputStream os, Instruction d) throws IOException { iie.writeInstruction(os, d); }
 
     private class InterpreterInstructionEncoder extends InstructionEncoder {
-        public long getBoxAddr(BenkoBox box) { return ((InterpreterBenkoBox)box).addr; }
+        public long getBoxAddr(Destination box) { return ((InterpreterBenkoBox)box).addr; }
         public long getBoxInstAddr(BenkoBox box) { return ((InterpreterBenkoBox)box).instr_addr; }
         public BenkoBox getBoxByAddr(long dest) {
             for(Ship ship : Interpreter.this)
index 965d80a..9ca5d4d 100644 (file)
@@ -22,8 +22,7 @@ Alu2.SUB:   sendto alu.inOp;
 Alu2.MIN:   sendto alu.inOp;
 Alu2.MAX:   sendto alu.inOp;
 
-alu.in1:   [*] take, deliver;
-alu.in2:   [*] take, deliver;
-alu.inOp:  [*] take, deliver;
-alu.out:
-  [*] take, sendto debug.in;
+alu.in1:    [*] take, deliver;
+alu.in2:    [*] take, deliver;
+alu.inOp:   [*] take, deliver;
+alu.out:    [*] take, sendto debug.in;