add Rotator ship
[fleet.git] / ships / Fifo.ship
1 ship: Fifo
2
3 == Ports ===========================================================
4 data  in:   in
5
6 data  out:  out
7
8 == Constants ========================================================
9
10 == TeX ==============================================================
11
12 The {\tt Fifo} ship is a simple fifo.  Word-sized delivered to the {\tt
13 in} port are enqueued into the fifo, and values which arrive at the
14 end of the fifo are provided to the {\tt out} port.
15
16 The internal capacity of the fifo is unspecified, but guaranteed to be
17 at least 16 words.
18
19 == Fleeterpreter ====================================================
20     private Queue<Long> fifo = new LinkedList<Long>();
21     public void service() {
22         if (box_in.dataReadyForShip()) {
23             fifo.add(box_in.removeDataForShip());
24         }
25         if (box_out.readyForDataFromShip() && fifo.size() > 0) {
26             box_out.addDataFromShip(fifo.remove());
27         }
28     }
29
30 == FleetSim ==============================================================
31
32 == Test =================================================================
33 // expected output
34 #expect 9
35
36 // ships required in order to run this code
37 #ship debug        : Debug
38 #ship fifo         : Fifo
39
40 debug.in:   [*] take, deliver;
41 fifo.in:
42   literal 9;
43   deliver;
44   load repeat counter with 63;
45   take, deliver;
46   load repeat counter with 37;
47   take, deliver;
48
49 fifo.out:
50   load repeat counter with 63;
51   take, sendto fifo.in;
52   load repeat counter with 36;
53   take, sendto fifo.in;
54   take, sendto debug.in;
55
56
57
58 == Contributors =========================================================
59 Adam Megacz <megacz@cs.berkeley.edu>