checkpoint
authoradam <adam@megacz.com>
Thu, 1 Mar 2007 12:29:11 +0000 (13:29 +0100)
committeradam <adam@megacz.com>
Thu, 1 Mar 2007 12:29:11 +0000 (13:29 +0100)
contrib/demo.f0
src/edu/berkeley/fleet/f0/Compile.lhs
src/edu/berkeley/fleet/f0/Types.lhs

index 2c4785c..a7946f5 100644 (file)
@@ -6,11 +6,11 @@ main(x -> out) =
   fifo2 :: Fifo
   { 0, 1, 2 } --> fifo1.in
   { 0, 3, 4 } --> fifo2.in
-  fifo1.out --> alu.inOp, alu.in1, alu.in2
-  alu.out   --> debug.in
+  fifo1.out   --> alu.inOp, alu.in1, alu.in2
+  alu.out     --> debug.in
   ;;
-  fifo2.out --> alu.inOp, alu.in1, alu.in2
-  alu.out   --> debug.in
+  fifo2.out   --> alu.inOp, alu.in1, alu.in2
+  alu.out     --> debug.in
 
 /*
 double(a -> out) =
index a505eec..ec26258 100644 (file)
@@ -12,14 +12,14 @@ import Fleet
 
 getInboxes :: Expr -> [Port]
 getInboxes (Move 1 s d)   = [d]
-getInboxes (Exprs d e)    = getInboxes e
+getInboxes (Decl d e)    = getInboxes e
 getInboxes (Par e)        = concatMap getInboxes e
 getInboxes (Seq [a,b])    = getInboxes a
 getInboxes _              = []
 
 getOutboxes :: Expr -> [Port]
 getOutboxes (Move 1 s d)   = [s]
-getOutboxes (Exprs d e)    = getOutboxes e
+getOutboxes (Decl d e)    = getOutboxes e
 getOutboxes (Par e)        = concatMap getOutboxes e
 getOutboxes (Seq [a,b])    = getOutboxes b
 getOutboxes _              = []
@@ -28,7 +28,7 @@ compile :: Expr -> [Inst]
 compile (Literal 0 lit d) =  [ ILiteral lit d, (accept d) {m_count=0} ]
 compile (Literal 1 lit d) =  [ ILiteral lit d, (accept d)             ]
 compile (Literal n lit d) =  [ ILiteral lit d, (accept d) {m_count=n} ]
-compile (Exprs d e)       = compile e
+compile (Decl d e)       = compile e
 compile (Seq [a,b])       = (compile a)++(bridge (getInboxes a) (uniq (getOutboxes b)))++(compile b)
 compile (Par e)           = concatMap compile e
 compile (Move 1 s d)      = [ (move s) { m_dest=(Just d) }, (accept d) ]
@@ -43,7 +43,7 @@ bridge obs (ib:ibs) = notifyFromOutboxes ++ waitForOutboxNotifications ++ notify
   notifyInboxes              = map (notify ib) ibs
   waitForInboxNotifications  = map wait ibs
 
-getdecls (Exprs d e) = map (\(Decl n t) -> ("#ship " ++ n ++ " : " ++ t)) d
+getdecls (Decl d e) = map (\(n,t) -> ("#ship " ++ n ++ " : " ++ t)) d
 getdecls (Seq es)   = concatMap getdecls es
 getdecls (Par es)   = concatMap getdecls es
 getdecls _          = []
index f82c411..d9290b8 100644 (file)
@@ -16,6 +16,7 @@ instance FromTree Def where
      Def (fromTree name) (fromTree inp) (fromTree outp) (fromTree es)
   fromTree (Tree "Def" q _) = error $ show q
 
+
 -- Port ------------------------------------------------------------------------------
 data Port = ShipPort String String
           | IdPort   String
@@ -32,13 +33,11 @@ instance FromTree Port where
 
 
 -- Expr ------------------------------------------------------------------------------
-data Decl  = Decl String String
-  deriving (Show,Eq)
 data Expr  = Seq     [Expr] 
            | Par     [Expr]
-           | Exprs   [Decl] Expr
-           | Move     Int Port    Port
-           | Literal  Int Int     Port
+           | Decl    [(String,String)] Expr
+           | Move     Int Port Port
+           | Literal  Int Int  Port
            | Nop
   deriving (Show,Eq)
 {-
@@ -55,12 +54,11 @@ instance Show Expr where
  show (Literal count i dest)   = (show i) ++ " -["++(show count)++"]-> " ++ (show dest)
 -}
 
-instance FromTree Decl where
- fromTree (Tree "::" [shipName,shipType] _) = Decl    (fromTree shipName) (fromTree shipType)
-
 instance FromTree Expr where
-  fromTree (Tree "Exprs" [decls, sequents] _) = Exprs (fromTree decls) (seq $ map par $ fromTree sequents)
-   where seq []  = Nop
+  fromTree (Tree "Exprs" [(Tree _ decls _), sequents] _) = Decl declist (seq $ map par $ fromTree sequents)
+   where
+         declist = map (\(Tree "::" [shipName,shipType] _) -> ((fromTree shipName), (fromTree shipType))) decls
+         seq []  = Nop
          seq [x] = x
          seq x   = Seq x
          par []  = Nop