Changed tlpInterface to also return the direction of each channel, so that the (C++CSP) backend knows whether to pass it a whole channel, or just an end

This commit is contained in:
Neil Brown 2007-08-22 22:07:42 +00:00
parent 7c61208c93
commit 63d18373b8
3 changed files with 14 additions and 6 deletions

View File

@ -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"]
--}}}

View File

@ -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<uint8_t>/**/> (out.writer())) (new csp::common::ChannelPoisoner< csp::Chanout<uint8_t>/**/> (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
--}}}

8
TLP.hs
View File

@ -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)