add Stack ship and tests
authoradam <adam@megacz.com>
Sun, 25 Feb 2007 04:39:28 +0000 (05:39 +0100)
committeradam <adam@megacz.com>
Sun, 25 Feb 2007 04:39:28 +0000 (05:39 +0100)
ships/Stack.ship [new file with mode: 0644]
src/edu/berkeley/fleet/slipway/Slipway.java
tests/stack/stack-test.fleet [new file with mode: 0644]

diff --git a/ships/Stack.ship b/ships/Stack.ship
new file mode 100644 (file)
index 0000000..58d5e12
--- /dev/null
@@ -0,0 +1,61 @@
+ship: Stack
+
+== Ports ===========================================================
+data  in:   push
+data  out:  pop
+
+== Constants ========================================================
+
+== TeX ==============================================================
+A stack ship with capacity for at least 32 elements.
+
+Push operations are executed as soon as an inbound datum is {\tt
+deliver}ed on the {\tt push} port.  Completion of a push can be
+confirmed by sending a {\tt notify} token from the {\tt push} port.
+
+Pop operations are executed no earlier than the time at which the {\tt
+pop} port attempts to {\tt take} data from the ship.
+
+When the stack becomes full, it will simply not process any new {\tt
+push} operations.  When the stack becomes empty, it will simply not
+process any new {\tt pop} operations.
+
+== Fleeterpreter ====================================================
+    private ArrayList<Long> stack = new ArrayList<Long>();
+    public void service() {
+        if (box_push.dataReadyForShip() && stack.size()<32) {
+            stack.add(box_push.removeDataForShip());
+        }
+        if (box_pop.readyForDataFromShip() && stack.size() > 0) {
+            box_pop.addDataFromShip(stack.get(stack.size()-1));
+            stack.remove(stack.size()-1);
+        }
+    }
+
+== FleetSim ==============================================================
+== FPGA ==============================================================
+
+  reg    [(`DATAWIDTH-1):0] mem [4:0];
+  reg    [5:0]              depth;
+
+  always @(posedge clk) begin
+    if (depth < 32) begin
+      `onread(push_r, push_a)
+        pop_d       = push_d;
+        mem[depth] <= push_d;
+        depth       = depth + 1;
+      end
+    end
+    if (depth > 0) begin
+      `onwrite(pop_r, pop_d)
+        depth = depth - 1;
+        if (depth > 0) begin
+          pop_d = mem[depth];
+        end
+      end
+    end
+  end
+
+
+== Contributors =========================================================
+Adam Megacz <megacz@cs.berkeley.edu>
index cb833d1..d35602f 100644 (file)
@@ -47,6 +47,7 @@ public class Slipway extends Fleet {
         createShip("Choice",    "Choice");
         createShip("Choice",    "Choice");
         createShip("Choice",    "Choice");
+        createShip("Stack",     "Stack");
         dumpFabric(true);
     }
 
diff --git a/tests/stack/stack-test.fleet b/tests/stack/stack-test.fleet
new file mode 100644 (file)
index 0000000..835ffc0
--- /dev/null
@@ -0,0 +1,21 @@
+#ship stack : Stack
+#ship debug : Debug
+
+#expect 4
+#expect 3
+#expect 2
+#expect 1
+#expect 0
+
+stack.push: [5] take, deliver; notify stack.pop;
+
+0: sendto stack.push;
+1: sendto stack.push;
+2: sendto stack.push;
+3: sendto stack.push;
+4: sendto stack.push;
+
+stack.pop: wait; [*] take, sendto debug.in;
+debug.in:  [*] take, deliver;
+
+