checkpoint
[fleet.git] / src / edu / berkeley / fleet / f0 / Fleet.lhs
1 \begin{code}
2 module Fleet where
3 import Util
4 import Types
5
6 itake  box = IMove { m_count=1, m_recycle=False, m_tokenIn=False, m_dataIn=True,
7                      m_latch=True, m_dataOut=False, m_tokenOut=False, m_dest=Nothing,
8                      m_benkobox=box }
9 move   box = (itake box){ m_dataOut=True }
10 send   box = (move box){ m_dataIn=False, m_latch=False }
11 notify box dest = IMove { m_count=1, m_recycle=False, m_tokenIn=False, m_dataIn=False,
12                           m_latch=False, m_dataOut=False, m_tokenOut=True, m_dest=(Just dest),
13                           m_benkobox=box }
14 wait box = IMove { m_count=1, m_recycle=False, m_tokenIn=True, m_dataIn=False,
15                    m_latch=False, m_dataOut=False, m_tokenOut=False, m_dest=Nothing,
16                    m_benkobox=box }
17 accept box = move box
18
19 type BenkoBox = Port
20 data Inst =
21     IKill     BenkoBox Int
22   | ILiteral  Int           BenkoBox
23   | IMove   { m_benkobox :: BenkoBox ,
24               m_dest     :: Maybe BenkoBox ,
25               m_count    :: Int ,
26               m_recycle  :: Bool ,
27               m_tokenIn  :: Bool ,
28               m_dataIn   :: Bool ,
29               m_latch    :: Bool ,
30               m_dataOut  :: Bool ,
31               m_tokenOut :: Bool }
32
33 showCount 0 True  = "[*r] "
34 showCount 0 False = "[*] "
35 showCount 1 _     = ""
36 showCount n True  = "["++(show n)++"r] "
37 showCount n False = "["++(show n)++"] "
38
39 instance Show Inst where
40  show (IKill bb count)  = (show bb)++": "++(showCount count False)++" kill;"
41  show (ILiteral lit bb) = (show lit)++": sendto "++(show bb)++";"
42  show m@(_)             = (show $ m_benkobox m) ++
43                          ": "++
44                          (showCount (m_count m) $ m_recycle m) ++
45                          (join ", " $ showrest m)++
46                          ";"
47                            where
48                              showrest m = wait++takelatch++out++ack
49                               where
50                                wait      = if m_tokenIn m then ["wait"] else []
51                                takelatch = if m_dataIn m then (if m_latch m then ["take"] else ["drop"]) else []
52                                out       = if m_dataOut m then (case m_dest m of { Nothing -> ["deliver"]; (Just j) -> ["sendto "++(show j)] }) else []
53                                ack       = if m_tokenOut m then (case m_dest m of (Just j) -> ["notify "++(show j)]) else []
54 \end{code}