change benkobox=>pump
[fleet.git] / src / edu / berkeley / fleet / api / Instruction.java
index 789aff3..a32b8d0 100644 (file)
@@ -4,88 +4,107 @@ public abstract class Instruction {
 
     public static class Kill extends Instruction {
 
-        public final BenkoBox benkoBox;
+        public final Pump pump;
         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 final boolean  killOnlyStandingInstructions;
+        public Kill(Pump pump, int count, boolean killOnlyStandingInstructions) {
+            this.pump=pump;
+            this.count=count;
+            this.killOnlyStandingInstructions = killOnlyStandingInstructions;
+            if (killOnlyStandingInstructions && count !=1)
+                throw new RuntimeException("currently, kill* must have count=1");
+        }
+        public String toString() { return (count>1 ? "["+count+"] " : "") + "kill" + (killOnlyStandingInstructions ? "*" : ""); }
 
     }
 
     public static class Executable extends Instruction {
 
-        public final BenkoBox benkoBox;
-        public final BenkoBox dest;
-        public final int      count;
+        public final Pump    pump;
+        public final Destination dest;
+        public final int         count;
 
         public final boolean  tokenIn;
         public final boolean  dataIn;
         public final boolean  latch;
+        public final boolean  dataOutDest;
         public final boolean  dataOut;
         public final boolean  tokenOut;
-        public final boolean  recycle;
+        public final boolean  requeue;
 
         /** 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) {
-            this.benkoBox = benkoBox;
+        public Executable(Pump    pump,
+                          Destination dest,
+                          int         count,
+                          boolean     tokenIn,
+                          boolean     dataIn,
+                          boolean     latch,
+                          boolean     dataOutDest,
+                          boolean     dataOut,
+                          boolean     tokenOut,
+                          boolean     requeue) {
+            this.pump = pump;
             this.dest = dest;
             this.count = count;
             this.tokenIn = tokenIn;
             this.dataIn = dataIn;
             this.latch = latch;
+            this.dataOutDest = dataOutDest;
             this.dataOut = dataOut;
             this.tokenOut = tokenOut;
-            this.recycle = recycle;
+            this.requeue = requeue;
             if (count < 0)
                 throw new RuntimeException("count field of an instruction must be >=0");
         }
 
+        public boolean isStanding() {
+            return count==0;
+        }
+
         public Instruction.Executable decrementCount() {
             if (count==1) return null;
-            return new Executable(benkoBox, dest, count==0 ? 0 : count-1,
-                                  tokenIn, dataIn, latch, dataOut, tokenOut, recycle);
+            return new Executable(pump, dest, count==0 ? 0 : count-1,
+                                  tokenIn, dataIn, latch, dataOutDest, dataOut, tokenOut, requeue);
         }
 
         public String toString() {
-            String ret = benkoBox.toString() + ": ";
-            if (count==0 || count>1 || recycle) {
-                ret += "[";
+            String ret = pump.toString() + ": ";
+            if (count==0 || count>1 || requeue) {
+                ret += requeue ? "(" : "[";
                 if (count>1) ret += count;
                 if (count==0) ret += "*";
-                if (recycle) ret += "r";
-                ret += "] ";
+                ret += requeue ? ")" : "] ";
             }
             boolean needcomma = false;
             if (tokenIn)           { ret += (needcomma ? ", " : "") + "wait";    needcomma = true; }
-            if (dataIn && latch)   { ret += (needcomma ? ", " : "") + "take";    needcomma = true; }
-            if (dataIn && !latch)  { ret += (needcomma ? ", " : "") + "discard"; needcomma = true; }
+            if (dataIn && latch)  {
+                if (pump.isInbox())
+                    ret += (needcomma ? ", " : "") + "receive";
+                else
+                    ret += (needcomma ? ", " : "") + "take";
+                needcomma = true;
+            }
+            if (dataIn && !latch)  { ret += (needcomma ? ", " : "") + "dismiss"; needcomma = true; }
             if (dataOut)  {
-                if (benkoBox instanceof BenkoBox.Inbox || dest==null)
+                if (pump.isInbox() || dest==null)
                     ret += (needcomma ? ", " : "") + "deliver";
                 else
                     ret += (needcomma ? ", " : "") + "sendto "+dest;
                 needcomma = true;
             }
-            if (tokenOut) { ret += (needcomma ? ", " : "") + "ack "+dest; needcomma = true; }
+            if (tokenOut) { ret += (needcomma ? ", " : "") + "notify "+dest; needcomma = true; }
             return ret;
         }
 
     }
 
     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;
             }
@@ -94,7 +113,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;
@@ -106,12 +125,12 @@ 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;
                 if (offset > 0) off = "+"+off;
-                return "(@"+off+":"+size+"): sendto " + dest;
+                return "(CBD @"+off+"+"+size+"): sendto " + dest;
             }
         }
     }