tweak box semantics in fleeterpreter to make them have no storage
authoradam <adam@megacz.com>
Sun, 25 Feb 2007 04:38:20 +0000 (05:38 +0100)
committeradam <adam@megacz.com>
Sun, 25 Feb 2007 04:38:20 +0000 (05:38 +0100)
src/edu/berkeley/fleet/interpreter/Outbox.java

index 4c82c28..25b7f83 100644 (file)
@@ -6,7 +6,8 @@ import edu.berkeley.fleet.api.Instruction;
 public class Outbox extends InstructionBenkoBox {
 
     /** are we ready to accept another item from the ship? */
-    private boolean readyForItemFromShip = true;
+    private boolean readyForDataFromShip = false;
+    private boolean haveDataFromShip     = false;
 
     /** data which has been presented by the ship and is waiting to depart */
     private long    itemPresentedByShip;
@@ -29,14 +30,16 @@ public class Outbox extends InstructionBenkoBox {
 
         // check firing conditions
         if (instruction.tokenIn && triggersReceived <= 0) return false;
-        if (instruction.dataIn && readyForItemFromShip) return false;
+        if (instruction.dataIn) {
+            if (!haveDataFromShip) { readyForDataFromShip = true; return false; }
+        }
         
         // consume trigger
         if (instruction.tokenIn) triggersReceived--;
 
         // consume item
         if (instruction.dataIn) {
-            readyForItemFromShip = true;
+            haveDataFromShip = false;
             if (instruction.latch) 
                 register = itemPresentedByShip;
         }
@@ -57,21 +60,21 @@ public class Outbox extends InstructionBenkoBox {
         return true;
     }
 
-    public final boolean readyForItemFromShip() { return readyForItemFromShip; }
+    public final boolean readyForDataFromShip() { return readyForDataFromShip; }
     public       void addDataFromShip(long data) { addItemFromShip(data); }
-    public       boolean readyForDataFromShip() { return readyForItemFromShip(); }
     public       void addDataFromFabric(Packet packet) { triggersReceived++; }
 
     /** subclass invokes this to add an item from the ship */
     protected final void addItemFromShip(long data) {
-        if (!readyForItemFromShip)
+        if (!readyForDataFromShip)
             throw new RuntimeException("tried to add an item to an outbox which was not ready!  you have a buggy ship!");
-        readyForItemFromShip = false;
+        readyForDataFromShip = false;
+        haveDataFromShip = true;
         itemPresentedByShip = data;
     }
 
     void shutdown() {
-        if (!readyForItemFromShip)
+        if (haveDataFromShip)
             Log.println(ANSI.red(" WARNING: you left a value ("+itemPresentedByShip+") on outbox port " + this));
         if (triggersReceived > 0)
             Log.println(ANSI.red(" WARNING: you left a token on the trigger input to port " + this));