-instance FromTree String where
- fromTree (Tree h c _) = h++(concatMap fromTree c)
-instance FromTrees String where
- fromTrees ts = concatMap (fromTree :: Tree -> String) ts
-
-type BenkoBox = Port
-data Inst =
- IKill BenkoBox Int
- | ILiteral Int BenkoBox
- | IMove { m_benkobox :: BenkoBox ,
- m_dest :: Maybe BenkoBox ,
- m_count :: Int ,
- m_recycle :: Bool ,
- m_tokenIn :: Bool ,
- m_dataIn :: Bool ,
- m_latch :: Bool ,
- m_dataOut :: Bool ,
- m_tokenOut :: Bool }
-
-showCount 0 True = "[*r] "
-showCount 0 False = "[*] "
-showCount 1 _ = ""
-showCount n True = "["++(show n)++"r] "
-showCount n False = "["++(show n)++"] "
-
-instance Show Inst where
- show (IKill bb count) = (show bb)++": "++(showCount count False)++" kill;"
- show (ILiteral lit bb) = (show lit)++": sendto "++(show bb)++";"
- show m@(_) = (show $ m_benkobox m) ++
- ": "++
- (showCount (m_count m) $ m_recycle m) ++
- (join ", " $ showrest m)++
- ";"
- where
- showrest m = wait++takelatch++out++ack
- where
- wait = if m_tokenIn m then ["wait"] else []
- takelatch = if m_dataIn m then (if m_latch m then ["take"] else ["drop"]) else []
- out = if m_dataOut m then (case m_dest m of { Nothing -> ["deliver"]; (Just j) -> ["sendto "++(show j)] }) else []
- ack = if m_tokenOut m then (case m_dest m of (Just j) -> ["ack "++(show j)]) else []
-