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,
9 move box = (itake box){ m_dataOut=True }
10 copy box = (move box){ m_dataIn=False }
11 send box = (move box){ m_dataIn=False, m_latch=False }
12 notify box dest = IMove { m_count=1, m_recycle=False, m_tokenIn=False, m_dataIn=False,
13 m_latch=False, m_dataOut=False, m_tokenOut=True, m_dest=(Just dest),
15 wait box = IMove { m_count=1, m_recycle=False, m_tokenIn=True, m_dataIn=False,
16 m_latch=False, m_dataOut=False, m_tokenOut=False, m_dest=Nothing,
18 dismiss box = IMove { m_count=1, m_recycle=False, m_tokenIn=False, m_dataIn=True,
19 m_latch=False, m_dataOut=False, m_tokenOut=False, m_dest=Nothing,
23 -- Port ------------------------------------------------------------------------------
24 data Port = ShipPort String String
28 instance Show Port where
29 show (ShipPort a b) = a++"."++b
32 instance FromTree Port where
33 fromTree (Tree "Port" [s] _) = IdPort (fromTree s)
34 fromTree (Tree "Port" [a,b] _) = ShipPort (fromTree a) (fromTree b)
35 fromTree t = error (show t)
40 | ILiteral Int PortBox
41 | ILiteralBag String PortBox
42 | IBagDef String [Inst]
43 | IMove { m_pump :: PortBox ,
44 m_dest :: Maybe PortBox ,
53 showCount 0 True = "[*r] "
54 showCount 0 False = "[*] "
56 showCount n True = "["++(show n)++"r] "
57 showCount n False = "["++(show n)++"] "
59 instance Show Inst where
60 show (IKill bb count) = (show bb)++": "++(showCount count False)++" kill;"
61 show (ILiteral lit bb) = (show lit)++": sendto "++(show bb)++";"
62 show (ILiteralBag bagname bb) = bagname++": sendto "++(show bb)++";"
63 show (IBagDef bagname is) = bagname++": {\n "++(join "" $ map (\i -> (show i)++"\n ") is)++"}\n"
64 show m@(_) = (show $ m_pump m) ++
66 (showCount (m_count m) $ m_recycle m) ++
67 (join ", " $ showrest m)++
70 showrest m = wait++takelatch++out++ack
72 wait = if m_tokenIn m then ["wait"] else []
73 takelatch = if m_dataIn m then (if m_latch m then ["take"] else ["dismiss"]) else []
74 out = if m_dataOut m then (case m_dest m of { Nothing -> ["deliver"]; (Just j) -> ["sendto "++(show j)] }) else []
75 ack = if m_tokenOut m then (case m_dest m of (Just j) -> ["notify "++(show j)]) else []