Rain: added tests for parsing channel-end casts

This commit is contained in:
Neil Brown 2007-08-24 16:56:29 +00:00
parent 121714c810
commit 0fdcdcf4a1

View File

@ -78,7 +78,7 @@ buildExprPattern (Lit e) = (stopCaringPattern m) $ mkPattern e
-- (the meaning of "b == c == d" is obscure enough to be dangerous, even if it passes the type checker)
--All arithmetic operators bind at the same level, which is a closer binding than all comparison operators.
--To clear that up, here's some BNF:
-- expression ::= comparisonExpression | subExpr | dataType ":" expression
-- expression ::= comparisonExpression | subExpr | dataType ":" expression | "?" expression | "!" expression
-- comparsionExpression ::= subExpr comparisonOp subExpr
-- subExpr ::= exprItem | monadicArithOp subExpr | subExpr dyadicArithOp subExpr | "(" expression ")"
-- exprItem ::= identifier | literal
@ -130,7 +130,24 @@ testExprs =
,passE ("a--b", 103, Dy (Var "a") A.Minus (Mon A.MonadicMinus $ Var "b") )
,passE ("a---b", 104, Dy (Var "a") A.Minus (Mon A.MonadicMinus $ Mon A.MonadicMinus $ Var "b") )
,passE ("-b+c", 105, Dy (Mon A.MonadicMinus $ Var "b") A.Plus (Var "c") )
,passE ("-(b+c)", 106, Mon A.MonadicMinus $ Dy (Var "b") A.Plus (Var "c") )
,passE ("c+-b", 106, Dy (Var "c") A.Plus (Mon A.MonadicMinus $ Var "b") )
,passE ("-(b+c)", 107, Mon A.MonadicMinus $ Dy (Var "b") A.Plus (Var "c") )
,passE ("?c", 108, Cast (A.Chan A.DirInput nonShared A.Any) $ Var "c")
,passE ("(?c)+d", 109, Dy (Cast (A.Chan A.DirInput nonShared A.Any) $ Var "c") A.Plus (Var "d"))
,passE ("?c+d", 110, Cast (A.Chan A.DirInput nonShared A.Any) $ Dy (Var "c") A.Plus (Var "d"))
,passE ("?(c+d)", 111, Cast (A.Chan A.DirInput nonShared A.Any) $ Dy (Var "c") A.Plus (Var "d"))
,passE ("??c", 112, Cast (A.Chan A.DirInput nonShared A.Any) $ Cast (A.Chan A.DirInput nonShared A.Any) $ Var "c")
,passE ("??c+d", 113, Cast (A.Chan A.DirInput nonShared A.Any) $ Cast (A.Chan A.DirInput nonShared A.Any) $ Dy (Var "c") A.Plus (Var "d"))
,passE ("!c", 113, Cast (A.Chan A.DirOutput nonShared A.Any) $ Var "c")
,passE ("(!c)+d", 115, Dy (Cast (A.Chan A.DirOutput nonShared A.Any) $ Var "c") A.Plus (Var "d"))
,passE ("!c+d", 116, Cast (A.Chan A.DirOutput nonShared A.Any) $ Dy (Var "c") A.Plus (Var "d"))
,passE ("!(c+d)", 117, Cast (A.Chan A.DirOutput nonShared A.Any) $ Dy (Var "c") A.Plus (Var "d"))
,passE ("!?c", 118, Cast (A.Chan A.DirOutput nonShared A.Any) $ Cast (A.Chan A.DirInput nonShared A.Any) $ Var "c")
,passE ("?!c+d", 119, Cast (A.Chan A.DirInput nonShared A.Any) $ Cast (A.Chan A.DirOutput nonShared A.Any) $ Dy (Var "c") A.Plus (Var "d"))
,failE ("c?d")
,failE ("c!d")
,failE ("?")
,failE ("!")
--Casting:
@ -149,7 +166,14 @@ testExprs =
,failE ("uint8 : b == uint8 : c")
,failE ("(uint8 : b) + uint8 : c")
,failE ("(uint8 : b) == uint8 : c")
,passE ("?uint8: ?c", 240, Cast (A.Chan A.DirInput nonShared A.Byte) $ Cast (A.Chan A.DirInput nonShared A.Any) $ Var "c")
--Should parse:
,passE ("?c: ?c", 241, Cast (A.Chan A.DirInput nonShared $ A.UserDataType $ typeName "c") $ Cast (A.Chan A.DirInput nonShared A.Any) $ Var "c")
,passE ("?c: ?c : b", 242, Cast (A.Chan A.DirInput nonShared $ A.UserDataType $ typeName "c") $
Cast (A.Chan A.DirInput nonShared $ A.UserDataType $ typeName "c") $ Var "b")
,failE ("?c:")
,failE (":?c")
]
where
passE :: (String,Int,ExprHelper) -> ParseTest A.Expression
@ -445,12 +469,13 @@ testComm =
pass ("c ! x;",RP.statement,assertEqual "testComm 0" $ A.Output m (variable "c") [A.OutExpression m (exprVariable "x")])
,pass ("c!x;",RP.statement,assertEqual "testComm 1" $ A.Output m (variable "c") [A.OutExpression m (exprVariable "x")])
,pass ("c!0+x;",RP.statement,assertEqual "testComm 2" $ A.Output m (variable "c") [A.OutExpression m $ A.Dyadic m A.Plus (intLiteral 0) (exprVariable "x")])
,pass ("c!!x;",RP.statement,assertEqual "testComm 3" $ A.Output m (variable "c") [A.OutExpression m $
A.Conversion m A.DefaultConversion (A.Chan A.DirOutput nonShared A.Any) (exprVariable "x")])
,fail ("c!x",RP.statement)
,fail ("c!x!y;",RP.statement)
,fail ("c!x,y;",RP.statement)
,fail ("c!;",RP.statement)
,fail ("!x;",RP.statement)
,fail ("c!!x;",RP.statement)
--Input:
,pass ("c ? x;",RP.statement, assertEqual "testComm 100" $ A.Input m (variable "c") $ A.InputSimple m [A.InVariable m (variable "x")])