make api.Destination a class rather than an interface
authoradam <adam@megacz.com>
Thu, 1 Mar 2007 13:15:15 +0000 (14:15 +0100)
committeradam <adam@megacz.com>
Thu, 1 Mar 2007 13:15:15 +0000 (14:15 +0100)
contrib/demo.f0
src/edu/berkeley/fleet/api/Destination.java
src/edu/berkeley/fleet/interpreter/Inbox.java
src/edu/berkeley/fleet/interpreter/InterpreterBenkoBox.java
src/edu/berkeley/fleet/interpreter/InterpreterDestination.java
src/edu/berkeley/fleet/interpreter/Outbox.java
src/edu/berkeley/fleet/slipway/Slipway.java
src/edu/berkeley/fleet/slipway/SlipwayBenkoBox.java

index a7946f5..824f9e6 100644 (file)
@@ -11,6 +11,9 @@ main(x -> out) =
   ;;
   fifo2.out   --> alu.inOp, alu.in1, alu.in2
   alu.out     --> debug.in
+  while alu.out > 3 {
+    3 --> debug.in
+  }
 
 /*
 double(a -> out) =
index c89ae92..3127836 100644 (file)
@@ -1,14 +1,14 @@
 package edu.berkeley.fleet.api;
 
-public interface Destination {
+public abstract class Destination {
 
     /** return the Ship to which this BenkoBox belongs */
-    public Ship   getShip();
+    public abstract Ship   getShip();
 
     /**
      *  this returns the third component of the name; that is in
      *  "ship.port.foo", it returns "foo", and in "ship.port" it
      *  returns ""
      */
-    public String getDestinationName();
+    public abstract String getDestinationName();
 }            
index a1e4769..f7e5522 100644 (file)
@@ -72,12 +72,12 @@ public class Inbox extends InstructionBenkoBox {
 
             // and make note of the fact that we need to send an ack (if requested)
             if (instruction.tokenOut)
-                bufferedAck = new Packet(getInterpreter(), this, 0, (InterpreterBenkoBox)instruction.dest);
+                bufferedAck = new Packet(getInterpreter(), this, 0, (InterpreterDestination)instruction.dest);
 
         } else if (instruction.tokenOut) {
 
             // if dataOut is not set, we can send the data immediately
-            new Packet(getInterpreter(), this, 0, (InterpreterBenkoBox)instruction.dest).send();
+            new Packet(getInterpreter(), this, 0, (InterpreterDestination)instruction.dest).send();
         }
         return true;
     }
index f8525c8..88a8815 100644 (file)
@@ -4,7 +4,7 @@ import edu.berkeley.fleet.api.BenkoBox;
 import java.util.*;
 
 /** anything that has a destination address on the switch fabric */
-public abstract class InterpreterBenkoBox extends BenkoBox implements InterpreterDestination {
+public abstract class InterpreterBenkoBox extends BenkoBox {
         
     private final String name;
     private final InterpreterShip ship;
@@ -17,9 +17,7 @@ public abstract class InterpreterBenkoBox extends BenkoBox implements Interprete
         this.ports = new Destination[ports.length];
         for(int i=0; i<ports.length; i++)
             this.ports[i] =
-                ports[i].equals("")
-                ? this
-                : new InterpreterBenkoBoxDestination(ports[i]);
+                new InterpreterBenkoBoxDestination(ports[i]);
     }
 
     public Iterable<Destination> getDestinations() {
@@ -47,7 +45,7 @@ public abstract class InterpreterBenkoBox extends BenkoBox implements Interprete
 
     private static int max_addr;
 
-    private class InterpreterBenkoBoxDestination implements InterpreterDestination {
+    private class InterpreterBenkoBoxDestination extends InterpreterDestination {
         public String name;
         public long addr = max_addr++;
         public InterpreterBenkoBoxDestination(String name)          { this.name = name; }
index bde33bc..87748bd 100644 (file)
@@ -2,8 +2,8 @@ package edu.berkeley.fleet.interpreter;
 import edu.berkeley.fleet.api.*;
 import java.util.*;
 
-interface InterpreterDestination extends Destination {
-    public long getDestAddr();
-    public void addDataFromFabric(Packet packet);
-    public String getDestinationName();
+abstract class InterpreterDestination extends Destination {
+    public abstract long getDestAddr();
+    public abstract void addDataFromFabric(Packet packet);
+    public abstract String getDestinationName();
 }
\ No newline at end of file
index 25b7f83..b6f76eb 100644 (file)
@@ -54,7 +54,7 @@ public class Outbox extends InstructionBenkoBox {
         } else if (instruction.tokenOut) {
 
             // if no item was sent, we might still send an ack
-            new Packet(getInterpreter(), this, 0, (InterpreterBenkoBox)instruction.dest).send();
+            new Packet(getInterpreter(), this, 0, (InterpreterDestination)instruction.dest).send();
         }
 
         return true;
index bd7d781..a27e165 100644 (file)
@@ -423,14 +423,7 @@ public class Slipway extends Fleet {
     public void writeInstruction(DataOutputStream os, Instruction d) throws IOException { iie.writeInstruction(os, d); }
 
     private class SlipwayInstructionEncoder extends InstructionEncoder {
-        public long getDestAddr(Destination box) {
-            long ret;
-            if (box instanceof SlipwayBenkoBox)
-                ret = ((SlipwayBenkoBox)box).addr;
-            else
-                ret = ((SlipwayBenkoBox.VirtualPort)box).addr;
-            return ret;
-        }
+        public long getDestAddr(Destination box) { return ((SlipwayBenkoBox.VirtualPort)box).addr; }
         public long getBoxInstAddr(BenkoBox box) { return ((SlipwayBenkoBox)box).instr_addr; }
         public Destination getDestByAddr(long dest) {
             for(Ship ship : Slipway.this)
index fb6082d..a43a659 100644 (file)
@@ -59,7 +59,7 @@ public class SlipwayBenkoBox extends BenkoBox {
         ports = newports;
     }
 
-    public class VirtualPort implements Destination {
+    public class VirtualPort extends Destination {
         public String name;
         public VirtualPort(String name) { this.name = name; }
         public String getDestinationName() { return name; }