added ArithmeticShip skeleton
authoradam <adam@megacz.com>
Thu, 23 Nov 2006 11:54:14 +0000 (12:54 +0100)
committeradam <adam@megacz.com>
Thu, 23 Nov 2006 11:54:14 +0000 (12:54 +0100)
src/edu/berkeley/fleet/TokenOutbox.java
src/edu/berkeley/fleet/ships/ArithmeticShip.java [new file with mode: 0644]
src/edu/berkeley/fleet/ships/FetchShip.java
src/edu/berkeley/fleet/ships/HomeworkCounter.java
src/edu/berkeley/fleet/ships/MemoryReadShip.java
src/edu/berkeley/fleet/ships/TokenFifo.java
src/edu/berkeley/fleet/ships/TokenSourceShip.java

index d690c23..0e2c0e0 100644 (file)
@@ -11,7 +11,7 @@ public class TokenOutbox extends Outbox {
         getFleet().sendToken(this, port);
     }
 
-    public boolean readyForDataFromShip() {
+    public boolean readyForTokenFromShip() {
         return super.readyForItemFromShip();
     }
 
@@ -19,7 +19,4 @@ public class TokenOutbox extends Outbox {
         addItemFromShip(0);
     }
 
-    public boolean readyForToken() {
-        return readyForDataFromShip();
-    }
 }
diff --git a/src/edu/berkeley/fleet/ships/ArithmeticShip.java b/src/edu/berkeley/fleet/ships/ArithmeticShip.java
new file mode 100644 (file)
index 0000000..c2492d0
--- /dev/null
@@ -0,0 +1,48 @@
+package edu.berkeley.fleet.ships;
+import edu.berkeley.fleet.*;
+
+import java.util.*;
+import java.io.*;
+
+public class ArithmeticShip extends Ship {
+
+    TokenOutbox tout    = new TokenOutbox(this, "tout");
+    TokenInbox  tin     = new TokenInbox(this, "tin");
+    DataOutbox dout     = new DataOutbox(this, "dout");
+    DataInbox  din      = new DataInbox(this, "din");
+
+    public ArithmeticShip(Fleet fleet, String name) {
+        super(fleet, name);
+    }
+
+    public void service() {
+
+        // dominic, pretend this method is inside an infinite loop;
+        // every time it is invoked you should:
+
+        // 1. check your input ports to see if they have stuff
+
+        // 2. make sure your output ports don't still have stuff stuck
+        //    in them (if they do, just return and wait until later)
+
+        // 3. do your thing
+
+        // here's some sample code snippets that should cover all the
+        //    cases you need
+
+        if (!tin.tokenReadyForShip())
+            return;
+        tin.removeTokenForShip();
+
+        if (!din.dataReadyForShip())
+            return;
+        int mydat = din.removeDataForShip();
+
+        if (tout.readyForTokenFromShip())
+            tout.addTokenFromShip();
+        if (dout.readyForDataFromShip())
+            dout.addDataFromShip(123);
+
+    }
+
+}
index 080f1a7..33ce950 100644 (file)
@@ -18,7 +18,7 @@ public class FetchShip extends Ship {
     public void service() {
         if (!codebag.dataReadyForShip()) return;
         if (!release.tokenReadyForShip() && !revoke.tokenReadyForShip()) return;
-        if (!done.readyForToken()) return;
+        if (!done.readyForTokenFromShip()) return;
         int cbd = codebag.removeDataForShip();
 
         CodeBag cb = CodeBag.getCodeBagByDescriptor(cbd);
index ee265ec..c8e9fb5 100644 (file)
@@ -18,8 +18,8 @@ public class HomeworkCounter extends Ship {
     }
 
     public void service() {
-        if (!zero.readyForToken()) return;
-        if (!positive.readyForToken()) return;
+        if (!zero.readyForTokenFromShip()) return;
+        if (!positive.readyForTokenFromShip()) return;
         if (load.dataReadyForShip()) {
             count = load.removeDataForShip();
             return;
index 515351a..632d88d 100644 (file)
@@ -24,7 +24,7 @@ public class MemoryReadShip extends Ship {
     public void service() {
         if (_count > 0) {
             if (!data.readyForDataFromShip()) return;
-            data.addDataFromShip(_addr>=fleet.mem.length ? 0 : fleet.mem[_addr]);
+            data.addDataFromShip(_addr>=getFleet().mem.length ? 0 : getFleet().mem[_addr]);
             _count--;
             _addr += _stride;
             if (_count==0)
@@ -33,7 +33,7 @@ public class MemoryReadShip extends Ship {
             if (count.dataReadyForShip() &&
                 addr.dataReadyForShip() &&
                 stride.dataReadyForShip() &&
-                done.readyForToken() &&
+                done.readyForTokenFromShip() &&
                 data.readyForDataFromShip()) {
 
                 _count  = count.removeDataForShip();
index 6ab4a86..e2fad3f 100644 (file)
@@ -21,7 +21,7 @@ public class TokenFifo extends Ship {
             in.removeTokenForShip();
             return;
         }
-        if (count > 0 && out.readyForToken()) {
+        if (count > 0 && out.readyForTokenFromShip()) {
             count--;
             out.addTokenFromShip();
         }
index 8de78b2..c65d0ff 100644 (file)
@@ -13,7 +13,7 @@ public class TokenSourceShip extends Ship {
     }
 
     public void service() {
-        if (out.readyForToken())
+        if (out.readyForTokenFromShip())
             out.addTokenFromShip();
     }