further separation on f0 code
[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 accept box = move box
12
13 type BenkoBox = Port
14 data Inst =
15     IKill     BenkoBox Int
16   | ILiteral  Int                 BenkoBox
17   | IMove   { m_benkobox   :: BenkoBox ,
18               m_dest     :: Maybe BenkoBox ,
19               m_count    :: Int ,
20               m_recycle  :: Bool ,
21               m_tokenIn  :: Bool ,
22               m_dataIn   :: Bool ,
23               m_latch    :: Bool ,
24               m_dataOut  :: Bool ,
25               m_tokenOut :: Bool }
26
27 showCount 0 True  = "[*r] "
28 showCount 0 False = "[*] "
29 showCount 1 _     = ""
30 showCount n True  = "["++(show n)++"r] "
31 showCount n False = "["++(show n)++"] "
32
33 instance Show Inst where
34  show (IKill bb count)  = (show bb)++": "++(showCount count False)++" kill;"
35  show (ILiteral lit bb) = (show lit)++": sendto "++(show bb)++";"
36  show m@(_)             = (show $ m_benkobox m) ++
37                          ": "++
38                          (showCount (m_count m) $ m_recycle m) ++
39                          (join ", " $ showrest m)++
40                          ";"
41                            where
42                              showrest m = wait++takelatch++out++ack
43                               where
44                                wait = if m_tokenIn m then ["wait"] else []
45                                takelatch = if m_dataIn m then (if m_latch m then ["take"] else ["drop"]) else []
46                                out = if m_dataOut m then (case m_dest m of { Nothing -> ["deliver"]; (Just j) -> ["sendto "++(show j)] }) else []
47                                ack = if m_tokenOut m then (case m_dest m of (Just j) -> ["ack "++(show j)]) else []
48 \end{code}