NCC clean newCell
[fleet.git] / contrib / flow-control-example.fleet
1 #import edu.berkeley.fleet.ships
2
3 //#ship math        : ArithmeticShip
4 #ship helper      : FifoShip
5 #ship source      : FifoShip
6 #ship dest        : FifoShip
7 #ship halt        : HaltShip
8 #ship fetch       : FetchShip
9 #ship tokensource : TokenSourceShip
10
11 // NOTE: "accept" is a synonym for "move" it is less confusing in the case
12 //       of inboxes, but is otherwise identical
13
14 //"foo" -> math.din
15
16 //////////////////////////////////////////////////////////////////////////////
17 // The following three instructions simply produce one hundred "3"s
18 // and put them into fifo "a".  Ignore the switch-fabric clogging
19 // issue here; this is just setup for the rest of the code.
20
21                  3                -> helper.in
22             copy helper.out  -[10]-> source.in
23          discard helper.out       -> ()
24
25
26 //////////////////////////////////////////////////////////////////////////////
27 // set up a counting move of 10 items from source.out to dest.in, but require
28 // flow control tokens (10 items is too many to send at once)
29
30  triggered move  source.out -[10]-> dest.in
31
32
33 //////////////////////////////////////////////////////////////////////////////
34 // The next instruction tears down the "default" standing move on dest.in
35 // and uses the resulting tokens to prime source.out's pump.  Once that
36 // has been kicked off, any subsequent incoming items will generate tokens
37 // which are sent back to the source outbox
38
39           nop+ack dest.in     -[3]-> source.out
40        accept+ack dest.in     -[7]-> source.out
41        accept     dest.in     -[3]-> source.out
42           nop+ack dest.in         -> fetch.release    // then release the fetch
43            accept dest.in     -[*]-> ()               // and return the fabric to normal
44
45 { tokensource.out -> halt.in }    -> fetch.codebag    // termination codebag
46
47
48