further separation on f0 code
[fleet.git] / src / edu / berkeley / fleet / f0 / Types.lhs
index 9b478b1..eb955e8 100644 (file)
@@ -3,13 +3,7 @@ module Types where
 import SBP
 import Util
 
-class FromTree a where
- fromTree  :: Tree   -> a
-class FromTrees a where
- fromTrees :: [Tree] -> a
-instance FromTree a => FromTree [a] where
- fromTree (Tree _ c _) = map fromTree c
-
+-- Def ------------------------------------------------------------------------------
 data Def = Def String [String] [String] Expr
   deriving Eq
 instance Show Def where
@@ -17,23 +11,27 @@ instance Show Def where
      name ++ "(" ++ (commify inp) ++ " -> " ++ (commify outp) ++ ") =\n   " ++ (indent (show exprs))
   where
    commify x = join "," x
-
 instance FromTree Def where
   fromTree (Tree "Def" [name,inp,outp,es] _) =
      Def (fromTree name) (fromTree inp) (fromTree outp) (Par (fromTree es))
   fromTree (Tree "Def" q _) = error $ show q
 
+-- Port ------------------------------------------------------------------------------
 data Port = ShipPort String String
           | IdPort   String
  deriving Eq
+
 instance Show Port where
  show (ShipPort a b) = a++"."++b
  show (IdPort a)     = a
+
 instance FromTree Port where
  fromTree (Tree "Port" [s] _)   = IdPort (fromTree s)
  fromTree (Tree "Port" [a,b] _) = ShipPort (fromTree a) (fromTree b)
  fromTree t = error (show t)
 
+
+-- Expr ------------------------------------------------------------------------------
 data Expr = Decl     String  String
           | Seq      [Expr] 
           | Par      [Expr]
@@ -65,45 +63,4 @@ instance FromTree Expr where
   fromTree t@(Tree ";;"   [a,b] _)                              = Seq    [(fromTree a), (fromTree b)]
   fromTree other = error  (show other)
 
-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 []
-
 \end{code}
\ No newline at end of file