diff --git a/GenerateC.hs b/GenerateC.hs index 1fdbd09..ab3cdd1 100644 --- a/GenerateC.hs +++ b/GenerateC.hs @@ -265,7 +265,7 @@ cgenTopLevel ops p tell ["void tock_main (Process *me, Channel *in, Channel *out, Channel *err) {\n"] genName name tell [" (me"] - sequence_ [tell [", "] >> call genTLPChannel ops c | c <- chans] + sequence_ [tell [", "] >> call genTLPChannel ops c | (_,c) <- chans] tell [");\n"] tell ["}\n"] --}}} diff --git a/GenerateCPPCSP.hs b/GenerateCPPCSP.hs index 60d6066..403c367 100644 --- a/GenerateCPPCSP.hs +++ b/GenerateCPPCSP.hs @@ -143,8 +143,16 @@ cppgenTopLevel ops p tell [" csp::Run( csp::InParallel (new StreamWriter(std::cout,out.reader())) (new StreamWriter(std::cerr,err.reader())) (csp::InSequenceOneThread ( new proc_"] genName name tell ["("] - infixComma [tell ["&"] >> call genTLPChannel ops c | c <- chans] + infixComma $ map (tlpChannel ops) chans tell [")) (new csp::common::ChannelPoisoner< csp::Chanout/**/> (out.writer())) (new csp::common::ChannelPoisoner< csp::Chanout/**/> (err.writer())) ) ); csp::End_CPPCSP(); return 0;}"] + where + tlpChannel :: GenOps -> (A.Direction,TLPChannel) -> CGen() + tlpChannel ops (dir,c) = case dir of + A.DirUnknown -> tell ["&"] >> chanName + A.DirInput -> chanName >> tell [" .reader() "] + A.DirOutput -> chanName >> tell [" .writer() "] + where + chanName = call genTLPChannel ops c --}}} diff --git a/TLP.hs b/TLP.hs index 284c978..3552752 100644 --- a/TLP.hs +++ b/TLP.hs @@ -36,7 +36,7 @@ data TLPChannel = TLPIn | TLPOut | TLPError -- | Get the name of the TLP and the channels it uses. -- Fail if the process isn't using a valid interface. -tlpInterface :: (CSM m, Die m) => m (A.Name, [TLPChannel]) +tlpInterface :: (CSM m, Die m) => m ( A.Name, [(A.Direction, TLPChannel)] ) tlpInterface = do ps <- get when (null $ csMainLocals ps) (die "No main process found") @@ -46,17 +46,17 @@ tlpInterface A.Proc _ _ fs _ -> return fs _ -> die "Last definition is not a PROC" chans <- mapM tlpChannel formals - when ((nub chans) /= chans) $ die "Channels used more than once in TLP" + when ((nub (map snd chans)) /= (map snd chans)) $ die "Channels used more than once in TLP" return (mainName, chans) where - tlpChannel :: (CSM m, Die m) => A.Formal -> m TLPChannel + tlpChannel :: (CSM m, Die m) => A.Formal -> m (A.Direction, TLPChannel) tlpChannel (A.Formal _ (A.Chan dir _ A.Byte) n) = do def <- lookupName n let origN = A.ndOrigName def case lookup origN tlpChanNames of Just c -> if (dir == A.DirUnknown || dir == (tlpDir c)) - then return c + then return (dir,c) else die $ "TLP formal " ++ show n ++ " has wrong direction for its name" _ -> die $ "TLP formal " ++ show n ++ " has unrecognised name" tlpChannel (A.Formal _ _ n)