fixes and more debugging output
authoradam <adam@megacz.com>
Fri, 10 Nov 2006 14:13:05 +0000 (15:13 +0100)
committeradam <adam@megacz.com>
Fri, 10 Nov 2006 14:13:05 +0000 (15:13 +0100)
15 files changed:
fleet.g
flow-control-example.fleet
problem0.fleet [deleted file]
src/edu/berkeley/fleet/Fleet.java
src/edu/berkeley/fleet/FleetParser.java
src/edu/berkeley/fleet/InboxPort.java
src/edu/berkeley/fleet/InstructionPort.java
src/edu/berkeley/fleet/Literal.java
src/edu/berkeley/fleet/OutboxPort.java
src/edu/berkeley/fleet/Port.java
src/edu/berkeley/fleet/Ship.java
src/edu/berkeley/fleet/TokenInPort.java
src/edu/berkeley/fleet/TokenOutPort.java
src/edu/berkeley/fleet/ships/HaltShip.java
src/edu/berkeley/fleet/ships/TokenSourceShip.java

diff --git a/fleet.g b/fleet.g
index 145ea0a..7a5b16c 100644 (file)
--- a/fleet.g
+++ b/fleet.g
@@ -5,9 +5,9 @@
 // the grammar.  An equivalent lex+yacc grammar and support code would
 // be several times as long.
 
-w               = " " | "\n" | "\r"
-ws              =  w**
-                |  w** "//" (~[\n])*! "\n" ws!
+Comment        = "//" ~[\n]* "\n"
+               | "/*" ~[\n]* "*/"
+ws             = ([\r\n ] | Comment)* -> ~[\r\n ]
 
 s               = ws! Program ws!
 Program         = Program::
@@ -36,7 +36,7 @@ Source         = Port
 Port           = Port::     shipname "." portname
                |           ^"()"
 
-CodeBagBody    = Statement +/ (ws (";" ws)?!)
+CodeBagBody    = Statement */ (ws (";" ws)?!)
 CodeBag        = CodeBagRef:: CodeBagName
                | AnonymousCodeBag:: "{" CodeBagBody "}" /ws
 
index 28af17d..7999e07 100644 (file)
@@ -17,7 +17,7 @@
 // issue here; this is just setup for the rest of the code.
 
                  3                -> helper.in
-            copy helper.out -[10]-> source.in
+            copy helper.out  -[10]-> source.in
          discard helper.out       -> ()
 
 
@@ -35,7 +35,8 @@
 // which are sent back to the source outbox
 
           nop+ack dest.in     -[3]-> source.out
-       accept+ack dest.in   -[10]-> source.out
+       accept+ack dest.in     -[7]-> source.out
+       accept     dest.in     -[3]-> source.out
           nop+ack dest.in         -> fetch.release    // then release the fetch
            accept dest.in     -[*]-> ()               // and return the fabric to normal
 
diff --git a/problem0.fleet b/problem0.fleet
deleted file mode 100644 (file)
index 69586d6..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-#import edu.berkeley.fleet.ships
-
-#memory { 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5,
-          1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5,
-          1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5,
-          1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5,
-          1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5,
-          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
-          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
-          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
-          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
-          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
- }
-
-#ship fifo        : FifoShip
-
-#ship halt        : HaltShip
-#ship fetch       : FetchShip
-#ship tokensource : TokenSourceShip
-
-
-
-{ tokensource.out -> halt.in } -> fetch.codebag
-tokensource.out                -> fetch.release
-
index 26ba3a1..b1e2ac9 100644 (file)
@@ -22,7 +22,20 @@ public class Fleet {
     public void go() {
         while(!halt)
             for(Ship ship : ships.values())
-                ship._service();
+                for(int j=0; j<10; j++)
+                    ship._service();
+
+        // run the ships a bit longer for good measure
+        for(int i=0; i<100; i++)
+            for(Ship ship : ships.values())
+                for(int j=0; j<10; j++)
+                    ship._service();
+
+        // check the state of the ships
+        for(Ship ship : ships.values())
+            ship.shutdown();
+
+        Log.println(Log.yellow("    DONE: ====== FLEET is halted.  Have a nice day.  ======"));
     }
 
     public void dumpMem() {
index 761e3c3..7130f7e 100644 (file)
@@ -116,7 +116,7 @@ public class FleetParser {
             PortReference d = portReference(t.child(3));
             if (t.child(1).head() == null) {
                 int literal = Integer.parseInt(string(t.child(1)));
-                cb.add(new Literal.LiteralDatum(literal, d, false));
+                cb.add(new Literal.LiteralDatum(literal, d, false, count));
 
             } else if ("AnonymousCodeBag".equals(t.child(1).head())) {
                 CodeBag cb3 = new CodeBag(cb, null);
index 34f18e1..bae09b2 100644 (file)
@@ -5,18 +5,14 @@ import java.util.*;
 
 public class InboxPort extends InstructionPort {
 
+    public static final Instruction defaultInstruction =
+        new Instruction(null, null, Integer.MAX_VALUE, TAKE, false, false, true);
+
     public InboxPort(Ship ship, String name) {
         super(ship, name);
 
         // default standing move
-        addInstruction(new Instruction(null,
-                                       null,
-                                       Integer.MAX_VALUE,
-                                       TAKE,
-                                       false,
-                                       false,
-                                       true
-                                       ));
+        addInstruction(defaultInstruction);
     }
 
     // data in from the switch fabric
@@ -37,6 +33,7 @@ public class InboxPort extends InstructionPort {
         if (tokenDestination != null) {
             Log.token(this, tokenDestination);
             tokenDestination.addToken();
+            tokenDestination = null;
         }
         return dataOut;
     }
@@ -63,6 +60,7 @@ public class InboxPort extends InstructionPort {
             case TAKE:
                 dataOut = dataIn.remove();
                 break;
+
         }
 
         if (instruction.dataOut) {
@@ -77,4 +75,16 @@ public class InboxPort extends InstructionPort {
         }
         return true;
     }
+
+    public void shutdown() {
+        if (!empty)
+            Log.println(Log.red(" WARNING: a datum ("+dataOut+") was left in inbox " + this + " -- the ship has not consumed it"));
+                        
+        if (dataIn.size() > 0) {
+            Log.println(Log.red(" WARNING: you left data on the input to inbox " + this + ":"));
+            for(int i : dataIn)
+                Log.println("  " + i);
+        }
+        super.shutdown(true);
+    }
 }
index 84b7b66..415ad1c 100644 (file)
@@ -26,9 +26,38 @@ public abstract class InstructionPort extends Port {
     // inherited from Port
     public abstract void addData(int data);
 
-    private Instruction currentlyExecuting = null;
-    private Queue<Instruction> instructions = new LinkedList<Instruction>();
-    private int currentlyExecutingCount;
+    Instruction currentlyExecuting = null;
+    Queue<Instruction> instructions = new LinkedList<Instruction>();
+    int currentlyExecutingCount;
+
+
+    protected void shutdown(boolean leaveAsInbox) {
+        if (leaveAsInbox) {
+            if (currentlyExecuting == null) {
+                Log.println(Log.red(" WARNING: you did not leave a standing move on inbox-port " + this));
+                return;
+            } else {
+                if (currentlyExecuting.count != Integer.MAX_VALUE
+                    || currentlyExecuting.dataIn != Instruction.IgnoreCopyTake.TAKE
+                    || currentlyExecuting.ack
+                    || currentlyExecuting.trigger
+                    || !currentlyExecuting.dataOut) {
+                    Log.println(Log.red(" WARNING: you did not leave the correct standing move on inbox-port " + this)+
+                                "\n            found:    " + currentlyExecuting
+                                );
+                    return;
+                }
+            }
+            currentlyExecuting = null;
+        }
+        if (currentlyExecuting != null || instructions.size() > 0) {
+            Log.println(Log.red(" WARNING: you left instructions on the instruction queue of port " + this + "; they are:"));
+            if (currentlyExecuting != null)
+                Log.println("   " + currentlyExecuting);
+            for(Instruction i : instructions)
+                Log.println("   " + i);
+        }
+    }
 
     // interface to subclass ///////////////////////////////////////////////////////////////////////
 
index 20d3b78..e9e9a9c 100644 (file)
@@ -6,19 +6,24 @@ public class Literal {
         private int data;
         private PortReference destination;
         private boolean isCodeBag;
-        public LiteralDatum(int data, PortReference destination, boolean isCodeBag) {
+        private int count;
+        public LiteralDatum(int data, PortReference destination, boolean isCodeBag) { this(data, destination, isCodeBag, 1); }
+        public LiteralDatum(int data, PortReference destination, boolean isCodeBag, int count) {
             this.data = data;
             this.destination = destination;
             this.isCodeBag = isCodeBag;
+            this.count = count;
         }
         protected int getData() { return data; }
         public void dispatch(Fleet fleet) {
-            Port port = destination.resolve(fleet);
-            Log.data((isCodeBag?(CodeBag.getCodeBagByDescriptor(getData())+""):(getData()+"")), null, port);
-            port.addData(getData());
+            for(int i=0; i<count; i++) {
+                Port port = destination.resolve(fleet);
+                Log.data((isCodeBag?(CodeBag.getCodeBagByDescriptor(getData())+""):(getData()+"")), null, port);
+                port.addData(getData());
+            }
         }
         public String toString() {
-            return (isCodeBag?(CodeBag.getCodeBagByDescriptor(getData())+""):(getData()+""))+" -> "+destination;
+            return (isCodeBag?(CodeBag.getCodeBagByDescriptor(getData())+""):(getData()+""))+" -"+(count==1?"":("["+count+"]-"))+"> "+destination;
         }
     }
 
@@ -31,6 +36,8 @@ public class Literal {
             this.name = name;
         }
         protected int getData() {
+            if (parent.getCodeBag(name)==null)
+                throw new RuntimeException("[invalid codebag, name="+name+"]");
             return parent.getCodeBag(name).getDescriptor();
         }
     }
index ff6decd..b79a74f 100644 (file)
@@ -50,10 +50,23 @@ public class OutboxPort extends InstructionPort {
             Port port = instruction.destination.resolve(getShip().getFleet());
             Log.data(data+"", this, port);
             port.addData(data);
+            if (instruction.ack)
+                throw new RuntimeException("outboxes may not send acks!");
+
+        } else if (instruction.ack) {
+            Port p = instruction.destination.resolve(getShip().getFleet());
+            Log.token(this, p);
+            p.addToken();
         }
-        if (instruction.ack)
-            throw new RuntimeException("outboxes may not send acks!");
 
         return true;
     }
+
+    public void shutdown() {
+        if (!empty)
+            Log.println(Log.red(" WARNING: you left a value ("+dataIn+") on outbox port " + this));
+        if (trigger > 0)
+            Log.println(Log.red(" WARNING: you left a token on the trigger input to port " + this));
+        super.shutdown(false);
+    }
 }
index 6c208c4..ca049b0 100644 (file)
@@ -26,4 +26,5 @@ public abstract class Port {
 
     public String toString() { return ship+"."+name; }
 
+    public abstract void shutdown();
 }
index 453441f..8eb93b4 100644 (file)
@@ -47,4 +47,9 @@ public abstract class Ship {
     public void addPort(String name, Port port) {
         ports.put(name, port);
     }
+
+    public void shutdown() {
+        for(Port p : ports.values())
+            p.shutdown();
+    }
 }
index fc04e65..990ba89 100644 (file)
@@ -24,4 +24,8 @@ public class TokenInPort extends Port {
         tokens--;
     }
 
+    public void shutdown() {
+        if (tokens > 0)
+            Log.println(Log.red(" WARNING: tokens were left on the input to " + this));
+    }
 }
index d6238f6..42ea958 100644 (file)
@@ -30,8 +30,10 @@ public class TokenOutPort extends InstructionPort {
 
         switch(instruction.dataIn) {
             case COPY:
+                if (empty) return false;
                 break;
             case TAKE:
+                if (empty) return false;
                 empty = true;
                 break;
         }
@@ -45,4 +47,10 @@ public class TokenOutPort extends InstructionPort {
     public void addData(int data) {
         throw new RuntimeException("invalid!");
     }
+
+    public void shutdown() {
+        if (!empty)
+            Log.println(Log.red(" WARNING: you left a token on token-output port " + this));
+        super.shutdown(false);
+    }
 }
index 73bbff3..3cd7746 100644 (file)
@@ -16,7 +16,7 @@ public class HaltShip extends Ship {
         if (in.empty()) return;
         in.remove();
         getFleet().halt = true;
-        Log.println(Log.red("    HALT: ====== halt ship got a token; halting the fleet ======"));
+        Log.println(Log.yellow("    HALT: ====== halt ship got a token; halting the fleet ======"));
     }
 
 }
index 3db56d3..bd59010 100644 (file)
@@ -17,4 +17,7 @@ public class TokenSourceShip extends Ship {
             out.addToken();
     }
 
+    public void shutdown() {
+    }
+
 }