Added tests for the genOutput and genOutputCase functions, corrected the C++ code, and added some helper functions to the C++ support header
This commit is contained in:
parent
97ee0c4a4e
commit
3b20d18937
|
@ -1574,13 +1574,13 @@ cgenOutputCase :: GenOps -> A.Variable -> A.Name -> [A.OutputItem] -> CGen ()
|
|||
cgenOutputCase ops c tag ois
|
||||
= do t <- typeOfVariable c
|
||||
let proto = case t of A.Chan _ _ (A.UserProtocol n) -> n
|
||||
tell ["ChanOutInt ("]
|
||||
tell ["ChanOutInt("]
|
||||
call genVariable ops c
|
||||
tell [", "]
|
||||
tell [","]
|
||||
genName tag
|
||||
tell ["_"]
|
||||
genName proto
|
||||
tell [");\n"]
|
||||
tell [");"]
|
||||
call genOutput ops c ois
|
||||
--}}}
|
||||
--{{{ stop
|
||||
|
|
|
@ -110,7 +110,6 @@ cppgenOps = cgenOps {
|
|||
genInput = cppgenInput,
|
||||
genInputCase = cppgenInputCase,
|
||||
genInputItem = cppgenInputItem,
|
||||
genOutput = cppgenOutput,
|
||||
genOutputCase = cppgenOutputCase,
|
||||
genOutputItem = cppgenOutputItem,
|
||||
genPar = cppgenPar,
|
||||
|
@ -180,7 +179,7 @@ genCPPCSPChannelInput ops var
|
|||
case t of
|
||||
(A.Chan A.DirInput _ _) -> call genVariable ops var
|
||||
(A.Chan A.DirUnknown _ _) -> do call genVariable ops var
|
||||
tell [" ->reader() "]
|
||||
tell ["->reader()"]
|
||||
_ -> call genMissing ops $ "genCPPCSPChannelInput used on something which does not support input: " ++ show var
|
||||
|
||||
-- | Generates code from a channel 'A.Variable' that will be of type Chanout\<\>
|
||||
|
@ -190,7 +189,7 @@ genCPPCSPChannelOutput ops var
|
|||
case t of
|
||||
(A.Chan A.DirOutput _ _) -> call genVariable ops var
|
||||
(A.Chan A.DirUnknown _ _) -> do call genVariable ops var
|
||||
tell [" ->writer() "]
|
||||
tell ["->writer()"]
|
||||
_ -> call genMissing ops $ "genCPPCSPChannelOutput used on something which does not support output: " ++ show var
|
||||
--}}}
|
||||
|
||||
|
@ -445,20 +444,6 @@ cppgenOutputItem ops chan item
|
|||
genJustOutputItem ops item
|
||||
tell [" ; "]
|
||||
|
||||
cppgenOutput :: GenOps -> A.Variable -> [A.OutputItem] -> CGen ()
|
||||
cppgenOutput ops c ois
|
||||
= do t <- typeOfVariable c
|
||||
case t of
|
||||
--If it's a protocol, we have to build the appropriate tuple to send down the channel:
|
||||
A.Chan _ _ (A.UserProtocol innerType) ->
|
||||
do genCPPCSPChannelOutput ops c
|
||||
tell [" << "]
|
||||
genProtocolName innerType
|
||||
tell [" ( "]
|
||||
infixComma $ map (genJustOutputItem ops) ois
|
||||
tell [" ); "]
|
||||
_ -> sequence_ $ map (call genOutputItem ops c) ois
|
||||
|
||||
-- FIXME Should be a generic helper somewhere (along with the others from GenerateC)
|
||||
-- | Helper function to place a comma between items, but not before or after
|
||||
infixComma :: [CGen ()] -> CGen ()
|
||||
|
@ -526,12 +511,14 @@ cppgenOutputCase :: GenOps -> A.Variable -> A.Name -> [A.OutputItem] -> CGen ()
|
|||
cppgenOutputCase ops c tag ois
|
||||
= do t <- typeOfVariable c
|
||||
let proto = case t of A.Chan _ _ (A.UserProtocol n) -> n
|
||||
genCPPCSPChannelInput ops c
|
||||
tell [" << "]
|
||||
genSubTypes proto tag (middle proto)
|
||||
tell [" ; "]
|
||||
where
|
||||
middle proto = tupleExpression True (genTupleProtocolTagName proto tag) (((genProtocolTagName proto tag) >> tell ["()"]) : map (genJustOutputItem ops) ois)
|
||||
tell ["tockSendInt("]
|
||||
genCPPCSPChannelOutput ops c
|
||||
tell [","]
|
||||
genName tag
|
||||
tell ["_"]
|
||||
genName proto
|
||||
tell [");"]
|
||||
call genOutput ops c ois
|
||||
|
||||
|
||||
-- | We use the process wrappers here, in order to execute the functions in parallel.
|
||||
|
|
|
@ -685,6 +685,24 @@ testWhile = testBothSame "testWhile 0" "while($){@}" ((tcall2 genWhile undefined
|
|||
where
|
||||
over ops = ops {genExpression = override1 dollar, genProcess = override1 at}
|
||||
|
||||
testOutput :: Test
|
||||
testOutput = TestList
|
||||
[
|
||||
testBothSame "testOutput 0" "" ((tcall2 genOutput undefined []) . overOutputItem)
|
||||
,testBothSame "testOutput 1" "^" ((tcall2 genOutput undefined [undefined]) . overOutputItem)
|
||||
,testBothSame "testOutput 2" "^^^" ((tcall2 genOutput undefined [undefined,undefined,undefined]) . overOutputItem)
|
||||
|
||||
,testBothS "testOutput 100" "ChanOutInt(@,bar_foo);^" "tockSendInt(@->writer(),bar_foo);^" ((tcall3 genOutputCase (A.Variable emptyMeta chan) bar []) . overOutput) state
|
||||
,testBothS "testOutput 101" "ChanOutInt(@,bar_foo);^" "tockSendInt(@,bar_foo);^" ((tcall3 genOutputCase (A.Variable emptyMeta chanOut) bar []) . overOutput) state
|
||||
]
|
||||
where
|
||||
chan = simpleName "c"
|
||||
chanOut = simpleName "cOut"
|
||||
state = do defineName chan $ simpleDefDecl "c" (A.Chan A.DirUnknown (A.ChanAttributes False False) $ A.UserProtocol foo)
|
||||
defineName chanOut $ simpleDefDecl "cOut" (A.Chan A.DirOutput (A.ChanAttributes False False) $ A.UserProtocol foo)
|
||||
overOutput ops = ops {genVariable = override1 at, genOutput = override2 caret}
|
||||
overOutputItem ops = ops {genOutputItem = override2 caret}
|
||||
|
||||
---Returns the list of tests:
|
||||
tests :: Test
|
||||
tests = TestList
|
||||
|
@ -700,6 +718,7 @@ tests = TestList
|
|||
,testGenVariable
|
||||
,testGetTime
|
||||
,testIf
|
||||
,testOutput
|
||||
,testOverArray
|
||||
,testReplicator
|
||||
,testSpec
|
||||
|
|
|
@ -394,3 +394,14 @@ public:
|
|||
memcpy(dp,sp,n);
|
||||
}
|
||||
};
|
||||
|
||||
void tockSendInt(const csp::Chanout<tockSendableArrayOfBytes>& c, unsigned int n)
|
||||
{
|
||||
c << tockSendableArrayOfBytes(&n);
|
||||
}
|
||||
|
||||
void tockRecvInt(const csp::Chanin<tockSendableArrayOfBytes>& c, unsigned int* p)
|
||||
{
|
||||
tockSendableArrayOfBytes d(sizeof(unsigned int),p);
|
||||
c >> d;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user