Got all the tests compiling again after recent changes

For some reason, the usage check tests are now very slow to run (perhaps because of all the operator definitions added to each one?), which needs further investigation.
This commit is contained in:
Neil Brown 2009-04-10 19:29:40 +00:00
parent 2690ec1d1b
commit ddbec737f2
13 changed files with 119 additions and 101 deletions

View File

@ -74,7 +74,8 @@ testTransformWaitFor1 = TestCase $ testPass "testTransformWaitFor1" exp transfor
mSeveralP mSeveralP
[ [
mOnlyP $ mGetTime var mOnlyP $ mGetTime var
,mOnlyP $ tag3 A.Assign DontCare [var] $ tag2 A.ExpressionList DontCare [tag4 A.Dyadic DontCare A.Plus evar (exprVariablePattern "t")] ,mOnlyP $ mAssign [var] $ mExpressionList
[mFunctionCall (occamDefaultOperator "PLUS" [A.Int, A.Int]) [evar, exprVariablePattern "t"]]
,mOnlyP $ tag3 A.Alt DontCare True $ mOnlyA $ mWaitUntil evar (A.Skip m) ,mOnlyP $ tag3 A.Alt DontCare True $ mOnlyA $ mWaitUntil evar (A.Skip m)
] ]
varName = (tag2 A.Name DontCare $ Named "nowt" DontCare) varName = (tag2 A.Name DontCare $ Named "nowt" DontCare)
@ -92,9 +93,11 @@ testTransformWaitFor2 = TestCase $ testPass "testTransformWaitFor2" exp transfor
mSeveralP mSeveralP
[ [
mOnlyP $ mGetTime var0 mOnlyP $ mGetTime var0
,mOnlyP $ tag3 A.Assign DontCare [var0] $ tag2 A.ExpressionList DontCare [tag4 A.Dyadic DontCare A.Plus evar0 (exprVariablePattern "t0")] ,mOnlyP $ mAssign [var0] $ mExpressionList [mFunctionCall (occamDefaultOperator
"PLUS" [A.Int, A.Int]) [evar0, exprVariablePattern "t0"]]
,mOnlyP $ mGetTime var1 ,mOnlyP $ mGetTime var1
,mOnlyP $ tag3 A.Assign DontCare [var1] $ tag2 A.ExpressionList DontCare [tag4 A.Dyadic DontCare A.Plus evar1 (exprVariablePattern "t1")] ,mOnlyP $ mAssign [var1] $ mExpressionList [mFunctionCall (occamDefaultOperator
"PLUS" [A.Int, A.Int]) [evar1, exprVariablePattern "t1"]]
,mOnlyP $ tag3 A.Alt DontCare True $ mSeveralA ,mOnlyP $ tag3 A.Alt DontCare True $ mSeveralA
[mOnlyA $ mWaitUntil evar0 (A.Skip m) [mOnlyA $ mWaitUntil evar0 (A.Skip m)
,mOnlyA $ mWaitUntil evar1 (A.Skip m)] ,mOnlyA $ mWaitUntil evar1 (A.Skip m)]
@ -110,13 +113,17 @@ testTransformWaitFor2 = TestCase $ testPass "testTransformWaitFor2" exp transfor
testTransformWaitFor3 :: Test testTransformWaitFor3 :: Test
testTransformWaitFor3 = TestCase $ testPass "testTransformWaitFor3" exp transformWaitFor orig (return ()) testTransformWaitFor3 = TestCase $ testPass "testTransformWaitFor3" exp transformWaitFor orig (return ())
where where
orig = A.Alt m True $ A.Only m $ waitFor (A.Dyadic m A.Plus (exprVariable "t0") (exprVariable "t1")) (A.Skip m) orig = A.Alt m True $ A.Only m $ waitFor (A.FunctionCall m (A.Name emptyMeta
$ occamDefaultOperator "PLUS" [A.Int, A.Int]) [exprVariable "t0", exprVariable "t1"]) (A.Skip m)
exp = tag2 A.Seq DontCare $ mSpecP (tag3 A.Specification DontCare varName $ A.Declaration m A.Time) $ exp = tag2 A.Seq DontCare $ mSpecP (tag3 A.Specification DontCare varName $ A.Declaration m A.Time) $
mSeveralP mSeveralP
[ [
mOnlyP $ mGetTime var mOnlyP $ mGetTime var
,mOnlyP $ tag3 A.Assign DontCare [var] $ tag2 A.ExpressionList DontCare [tag4 A.Dyadic DontCare A.Plus evar ,mOnlyP $ tag3 A.Assign DontCare [var] $ tag2 A.ExpressionList DontCare
(A.Dyadic m A.Plus (exprVariable "t0") (exprVariable "t1"))] [mFunctionCall (occamDefaultOperator "PLUS" [A.Int, A.Int])
[evar
,mFunctionCall (occamDefaultOperator "PLUS" [A.Int, A.Int])
[exprVariable "t0", exprVariable "t1"]]]
,mOnlyP $ tag3 A.Alt DontCare True $ mOnlyA $ mWaitUntil evar (A.Skip m) ,mOnlyP $ tag3 A.Alt DontCare True $ mOnlyA $ mWaitUntil evar (A.Skip m)
] ]
varName = (tag2 A.Name DontCare $ Named "nowt" DontCare) varName = (tag2 A.Name DontCare $ Named "nowt" DontCare)
@ -132,7 +139,8 @@ testTransformWaitFor4 = TestCase $ testPass "testTransformWaitFor4" exp transfor
mSeveralP mSeveralP
[ [
mOnlyP $ mGetTime var mOnlyP $ mGetTime var
,mOnlyP $ tag3 A.Assign DontCare [var] $ tag2 A.ExpressionList DontCare [tag4 A.Dyadic DontCare A.Plus evar (exprVariablePattern "t")] ,mOnlyP $ tag3 A.Assign DontCare [var] $ tag2 A.ExpressionList DontCare
[mFunctionCall (occamDefaultOperator "PLUS" [A.Int, A.Int]) [evar, exprVariablePattern "t"]]
,mOnlyP $ tag3 A.Alt DontCare True $ mSeveralA ,mOnlyP $ tag3 A.Alt DontCare True $ mSeveralA
[mOnlyA $ mWaitUntil evar (A.Skip m)] [mOnlyA $ mWaitUntil evar (A.Skip m)]
] ]
@ -151,9 +159,11 @@ testTransformWaitFor5 = TestCase $ testPass "testTransformWaitFor5" exp transfor
mSeveralP mSeveralP
[ [
mOnlyP $ mGetTime var0 mOnlyP $ mGetTime var0
,mOnlyP $ tag3 A.Assign DontCare [var0] $ tag2 A.ExpressionList DontCare [tag4 A.Dyadic DontCare A.Plus evar0 (exprVariablePattern "t")] ,mOnlyP $ tag3 A.Assign DontCare [var0] $ tag2 A.ExpressionList DontCare
[mFunctionCall (occamDefaultOperator "PLUS" [A.Int, A.Int]) [evar0, exprVariablePattern "t"]]
,mOnlyP $ mGetTime var1 ,mOnlyP $ mGetTime var1
,mOnlyP $ tag3 A.Assign DontCare [var1] $ tag2 A.ExpressionList DontCare [tag4 A.Dyadic DontCare A.Plus evar1 (exprVariablePattern "t")] ,mOnlyP $ tag3 A.Assign DontCare [var1] $ tag2 A.ExpressionList DontCare
[mFunctionCall (occamDefaultOperator "PLUS" [A.Int, A.Int]) [evar1, exprVariablePattern "t"]]
,mOnlyP $ tag3 A.Alt DontCare True $ mSeveralA ,mOnlyP $ tag3 A.Alt DontCare True $ mSeveralA
[mOnlyA $ mWaitUntil evar0 (A.Skip m) [mOnlyA $ mWaitUntil evar0 (A.Skip m)
,mOnlyA $ mWaitUntil evar1 (A.Skip m)] ,mOnlyA $ mWaitUntil evar1 (A.Skip m)]

View File

@ -19,6 +19,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
module ArrayUsageCheckTest (vioqcTests) where module ArrayUsageCheckTest (vioqcTests) where
import Control.Monad.Identity import Control.Monad.Identity
import Control.Monad.Reader
import Control.Monad.State import Control.Monad.State
import Control.Monad.Writer (tell) import Control.Monad.Writer (tell)
import Data.Array.IArray import Data.Array.IArray
@ -49,6 +50,11 @@ import Utils
instance Show FlattenedExp where instance Show FlattenedExp where
show fexp = runIdentity $ showFlattenedExp (return . showOccam) fexp show fexp = runIdentity $ showFlattenedExp (return . showOccam) fexp
testCompState :: CompState
testCompState = emptyState
rr :: ReaderT CompState m a -> m a
rr = flip runReaderT testCompState
testArrayCheck :: Test testArrayCheck :: Test
testArrayCheck = TestList testArrayCheck = TestList
[ [
@ -270,10 +276,10 @@ testMakeEquations = TestLabel "testMakeEquations" $ TestList
[exprVariable "i",exprVariable "j"],intLiteral 8) [exprVariable "i",exprVariable "j"],intLiteral 8)
,test (3,[(ij_mapping,[i ++ con 3 === j],leq [con 0,i ++ con 3,con 7] &&& leq [con 0,j,con 7])], ,test (3,[(ij_mapping,[i ++ con 3 === j],leq [con 0,i ++ con 3,con 7] &&& leq [con 0,j,con 7])],
[buildExpr $ Dy (Var "i") A.Add (Lit $ intLiteral 3),exprVariable "j"],intLiteral 8) [buildExpr $ Dy (Var "i") "+" (Lit $ intLiteral 3),exprVariable "j"],intLiteral 8)
,test (4,[(ij_mapping,[2 ** i === j],leq [con 0,2 ** i,con 7] &&& leq [con 0,j,con 7])], ,test (4,[(ij_mapping,[2 ** i === j],leq [con 0,2 ** i,con 7] &&& leq [con 0,j,con 7])],
[buildExpr $ Dy (Var "i") A.Mul (Lit $ intLiteral 2),exprVariable "j"],intLiteral 8) [buildExpr $ Dy (Var "i") "*" (Lit $ intLiteral 2),exprVariable "j"],intLiteral 8)
,test' (5, [(((0,[]),(1,[])), ijk_mapping, [j === k], leq [con 0, j, i ++ con (-1)] &&& leq [con 0, k, i ++ con (-1)])], ,test' (5, [(((0,[]),(1,[])), ijk_mapping, [j === k], leq [con 0, j, i ++ con (-1)] &&& leq [con 0, k, i ++ con (-1)])],
[exprVariable "j", exprVariable "k"], exprVariable "i") [exprVariable "j", exprVariable "k"], exprVariable "i")
@ -286,7 +292,7 @@ testMakeEquations = TestLabel "testMakeEquations" $ TestList
[i ++ 3 ** j === con 4], leq [con 0,con 4,con 7] &&& leq [con 0,i ++ 3 ** j,con 7] &&& [i >== con 1] &&& [j <== con 0] &&& leq [con 0, i ++ 3 ** j, con 2]) [i ++ 3 ** j === con 4], leq [con 0,con 4,con 7] &&& leq [con 0,i ++ 3 ** j,con 7] &&& [i >== con 1] &&& [j <== con 0] &&& leq [con 0, i ++ 3 ** j, con 2])
,(( (0,[XNeg]), (1,[]) ), i_mod_mapping 3, ,(( (0,[XNeg]), (1,[]) ), i_mod_mapping 3,
[i ++ 3 ** j === con 4], leq [con 0,con 4,con 7] &&& leq [con 0,i ++ 3 ** j,con 7] &&& [i <== con (-1)] &&& [j >== con 0] &&& leq [con (-2), i ++ 3 ** j, con 0]) [i ++ 3 ** j === con 4], leq [con 0,con 4,con 7] &&& leq [con 0,i ++ 3 ** j,con 7] &&& [i <== con (-1)] &&& [j >== con 0] &&& leq [con (-2), i ++ 3 ** j, con 0])
],[buildExpr $ Dy (Var "i") A.Rem (Lit $ intLiteral 3),intLiteral 4],intLiteral 8) ],[buildExpr $ Dy (Var "i") "\\" (Lit $ intLiteral 3),intLiteral 4],intLiteral 8)
-- Testing ((3*i - 2*j REM 11) - 5) vs (i + j) -- Testing ((3*i - 2*j REM 11) - 5) vs (i + j)
-- Expressed as ((2 * (i - j)) + i) REM 11 - 5, and i + j -- Expressed as ((2 * (i - j)) + i) REM 11 - 5, and i + j
@ -303,14 +309,14 @@ testMakeEquations = TestLabel "testMakeEquations" $ TestList
&&& [3**i ++ (-2)**j <== con (-1)] &&& [k >== con 0] &&& leq [con (-10), 3**i ++ (-2)**j ++ 11 ** k, con 0]) &&& [3**i ++ (-2)**j <== con (-1)] &&& [k >== con 0] &&& leq [con (-10), 3**i ++ (-2)**j ++ 11 ** k, con 0])
],[buildExpr $ ],[buildExpr $
Dy (Dy (Dy (Dy (Lit $ intLiteral 2) Dy (Dy (Dy (Dy (Lit $ intLiteral 2)
A.Mul (Dy (Var "i") A.Subtr (Var "j")) "*" (Dy (Var "i") "-" (Var "j"))
) )
A.Add (Var "i") "+" (Var "i")
) )
A.Rem (Lit $ intLiteral 11) "\\" (Lit $ intLiteral 11)
) )
A.Subtr (Lit $ intLiteral 5) "-" (Lit $ intLiteral 5)
,buildExpr $ Dy (Var "i") A.Add (Var "j")],intLiteral 8) ,buildExpr $ Dy (Var "i") "+" (Var "j")],intLiteral 8)
-- Testing i REM 2 vs (i + 1) REM 4 -- Testing i REM 2 vs (i + 1) REM 4
,test' (12,combine (0,1) (i_ip1_mod_mapping 2 4) ,test' (12,combine (0,1) (i_ip1_mod_mapping 2 4)
@ -323,8 +329,8 @@ testMakeEquations = TestLabel "testMakeEquations" $ TestList
,([XNeg],[XZero],[([i ++ 2**j === con 0],[]),rr_i_neg,rr_ip1_zero]) ,([XNeg],[XZero],[([i ++ 2**j === con 0],[]),rr_i_neg,rr_ip1_zero])
,([XNeg],[XPos],[([i ++ 2**j === i ++ con 1 ++ 4**k],[]),rr_i_neg,rr_ip1_pos]) ,([XNeg],[XPos],[([i ++ 2**j === i ++ con 1 ++ 4**k],[]),rr_i_neg,rr_ip1_pos])
,([XNeg],[XNeg],[([i ++ 2**j === i ++ con 1 ++ 4**k],[]),rr_i_neg,rr_ip1_neg]) ,([XNeg],[XNeg],[([i ++ 2**j === i ++ con 1 ++ 4**k],[]),rr_i_neg,rr_ip1_neg])
], [buildExpr $ Dy (Var "i") A.Rem (Lit $ intLiteral 2) ], [buildExpr $ Dy (Var "i") "\\" (Lit $ intLiteral 2)
,buildExpr $ Dy (Dy (Var "i") A.Add (Lit $ intLiteral 1)) A.Rem (Lit $ intLiteral 4) ,buildExpr $ Dy (Dy (Var "i") "+" (Lit $ intLiteral 1)) "\\" (Lit $ intLiteral 4)
], intLiteral 8) ], intLiteral 8)
-- Testing i REM j vs 3 -- Testing i REM j vs 3
@ -361,7 +367,7 @@ testMakeEquations = TestLabel "testMakeEquations" $ TestList
,(((0,[XNegYNegANonZero]),(1,[])),i_mod_j_mapping, ,(((0,[XNegYNegANonZero]),(1,[])),i_mod_j_mapping,
[i ++ k === con 3], [i <== con (-1), k >== (-1)**j] &&& [i ++ k === con 3], [i <== con (-1), k >== (-1)**j] &&&
leq [j ++ con 1, i ++ k, con 0] &&& leq [con 0, i ++ k, con 7] &&& leq [con 0, con 3, con 7]) leq [j ++ con 1, i ++ k, con 0] &&& leq [con 0, i ++ k, con 7] &&& leq [con 0, con 3, con 7])
], [buildExpr $ Dy (Var "i") A.Rem (Var "j"), intLiteral 3], intLiteral 8) ], [buildExpr $ Dy (Var "i") "\\" (Var "j"), intLiteral 3], intLiteral 8)
-- i vs. i' -- i vs. i'
@ -393,7 +399,7 @@ testMakeEquations = TestLabel "testMakeEquations" $ TestList
,(((1,[]),(1,[])),rep_i_mapping,[i === j],common &&& leq [con 0, i ++ con 1, con 7] &&& leq [con 0, j ++ con 1, con 7])] ,(((1,[]),(1,[])),rep_i_mapping,[i === j],common &&& leq [con 0, i ++ con 1, con 7] &&& leq [con 0, j ++ con 1, con 7])]
++ [(((0,[]),(1,[])),rep_i_mapping, [i === i ++ con 1], common &&& ++ [(((0,[]),(1,[])),rep_i_mapping, [i === i ++ con 1], common &&&
leq [con 0, i, con 7] &&& leq [con 0,i ++ con 1, con 7])] leq [con 0, i, con 7] &&& leq [con 0,i ++ con 1, con 7])]
,("i", intLiteral 1, intLiteral 6),[exprVariable "i", buildExpr $ Dy (Var "i") A.Add (Lit $ intLiteral 1)],intLiteral 8) ,("i", intLiteral 1, intLiteral 6),[exprVariable "i", buildExpr $ Dy (Var "i") "+" (Lit $ intLiteral 1)],intLiteral 8)
-- Only a constant: -- Only a constant:
,testRep' (210,[(((0,[]),(0,[])),rep_i_mapping,[con 4 === con 4],ij_16 &&& [i <== j ++ con (-1)] &&& (concat $ replicate 2 $ leq [con 0, con 4, con 7]))] ,testRep' (210,[(((0,[]),(0,[])),rep_i_mapping,[con 4 === con 4],ij_16 &&& [i <== j ++ con (-1)] &&& (concat $ replicate 2 $ leq [con 0, con 4, con 7]))]
@ -436,7 +442,7 @@ testMakeEquations = TestLabel "testMakeEquations" $ TestList
&&& leq [con 0, i ++ 3**k, con 7] &&& leq [con 0, j ++ 3**m, con 7] &&& leq [con 0, i ++ 3**k, con 7] &&& leq [con 0, j ++ 3**m, con 7]
&&& [m >== con 0, k >== con 0, i <== con (-1), j <== con (-1)] &&& [m >== con 0, k >== con 0, i <== con (-1), j <== con (-1)]
&&& leq [con (-2), i ++ 3**k, con 0] &&& leq [con (-2), j ++ 3**m, con 0]) &&& leq [con (-2), i ++ 3**k, con 0] &&& leq [con (-2), j ++ 3**m, con 0])
],("i", intLiteral 1, intLiteral 6),[buildExpr $ Dy (Var "i") A.Rem (Lit $ intLiteral 3)], intLiteral 8) ],("i", intLiteral 1, intLiteral 6),[buildExpr $ Dy (Var "i") "\\" (Lit $ intLiteral 3)], intLiteral 8)
-- TODO test reads and writes are paired properly -- TODO test reads and writes are paired properly
@ -466,15 +472,15 @@ testMakeEquations = TestLabel "testMakeEquations" $ TestList
test' (ind, problems, exprs, upperBound) = test' (ind, problems, exprs, upperBound) =
TestCase $ assertEquivalentProblems ("testMakeEquations " ++ show ind) TestCase $ assertEquivalentProblems ("testMakeEquations " ++ show ind)
(map (\((a0,a1),b,c,d) -> ((lookup exprs a0, lookup exprs a1), b, makeConsistent c d)) problems) (map (\((a0,a1),b,c,d) -> ((lookup exprs a0, lookup exprs a1), b, makeConsistent c d)) problems)
=<< (checkRight $ makeEquations (makeParItems [] exprs) upperBound) =<< (checkRight $ rr $ makeEquations (makeParItems [] exprs) upperBound)
testRep' :: (Integer,[(((Int,[ModuloCase]), (Int,[ModuloCase])), VarMap,[HandyEq],[HandyIneq])],(String, A.Expression, A.Expression),[A.Expression],A.Expression) -> Test testRep' :: (Integer,[(((Int,[ModuloCase]), (Int,[ModuloCase])), VarMap,[HandyEq],[HandyIneq])],(String, A.Expression, A.Expression),[A.Expression],A.Expression) -> Test
testRep' (ind, problems, (repName, repFrom, repFor), exprs, upperBound) = testRep' (ind, problems, (repName, repFrom, repFor), exprs, upperBound) =
TestCase $ assertEquivalentProblems ("testMakeEquations " ++ show ind) TestCase $ assertEquivalentProblems ("testMakeEquations " ++ show ind)
(map (\((a0,a1),b,c,d) -> ((lookup exprs a0, lookup exprs a1), b, makeConsistent c d)) problems) (map (\((a0,a1),b,c,d) -> ((lookup exprs a0, lookup exprs a1), b, makeConsistent c d)) problems)
=<< (checkRight $ makeEquations (RepParItem (simpleName "i", A.For emptyMeta repFrom repFor (makeConstant emptyMeta 1)) $ =<< (checkRight $ rr $ makeEquations (RepParItem (simpleName "i", A.For emptyMeta repFrom repFor (makeConstant emptyMeta 1)) $
makeParItems [Map.fromList [(UsageCheckUtils.Var $ variable "i", makeParItems [Map.fromList [(UsageCheckUtils.Var $ variable "i",
[RepBoundsIncl (variable "i") repFrom (subOne $ addExprs repFrom repFor)])]] exprs) upperBound) [RepBoundsIncl (variable "i") repFrom (subOneInt $ addExprsInt repFrom repFor)])]] exprs) upperBound)
pairLatterTwo (l,a,b,c) = (l,a,(b,c)) pairLatterTwo (l,a,b,c) = (l,a,(b,c))
@ -530,7 +536,8 @@ testMakeEquations = TestLabel "testMakeEquations" $ TestList
testMakeEquation :: TestMonad m r => ([(((A.Expression, [ModuloCase]), (A.Expression, [ModuloCase])), VarMap,[HandyEq],[HandyIneq])],ParItems [A.Expression],A.Expression) -> m () testMakeEquation :: TestMonad m r => ([(((A.Expression, [ModuloCase]), (A.Expression, [ModuloCase])), VarMap,[HandyEq],[HandyIneq])],ParItems [A.Expression],A.Expression) -> m ()
testMakeEquation (problems, exprs, upperBound) = testMakeEquation (problems, exprs, upperBound) =
assertEquivalentProblems "" assertEquivalentProblems ""
(map (\(x,y,z) -> (x, y, uncurry makeConsistent z)) $ map pairLatterTwo problems) =<< (checkRight $ makeEquations (transformParItems pairWithEmpty exprs) upperBound) (map (\(x,y,z) -> (x, y, uncurry makeConsistent z)) $ map pairLatterTwo problems)
=<< (checkRight $ rr $ makeEquations (transformParItems pairWithEmpty exprs) upperBound)
where where
pairWithEmpty a = ([],a,[]) pairWithEmpty a = ([],a,[])
pairLatterTwo (l,a,b,c) = (l,a,(b,c)) pairLatterTwo (l,a,b,c) = (l,a,(b,c))
@ -572,7 +579,7 @@ genNewItem exprDepth specialAllowed
then then
do m <- get do m <- get
let nextId = 1 + maximum (0 : Map.elems m) let nextId = 1 + maximum (0 : Map.elems m)
let exp = A.Dyadic emptyMeta A.Mul (exprVariable $ "y" ++ show nextId) (exprVariable $ "y" ++ show nextId) let exp = mulExprsInt (exprVariable $ "y" ++ show nextId) (exprVariable $ "y" ++ show nextId)
return (exp,Scale 1 (exp, 0), nextId) return (exp,Scale 1 (exp, 0), nextId)
else else
do m <- get do m <- get
@ -582,7 +589,7 @@ genNewItem exprDepth specialAllowed
-- inserting them, only the multiplied item -- inserting them, only the multiplied item
put m put m
let nextId = 1 + maximum (0 : Map.elems m) let nextId = 1 + maximum (0 : Map.elems m)
let exp = A.Dyadic emptyMeta A.Mul (exprVariable $ "y" ++ show nextId) expToMult let exp = mulExprsInt (exprVariable $ "y" ++ show nextId) expToMult
return (exp, Scale 1 (exp, 0), nextId) return (exp, Scale 1 (exp, 0), nextId)
) )
] ++ if not specialAllowed then [] ] ++ if not specialAllowed then []
@ -590,12 +597,12 @@ genNewItem exprDepth specialAllowed
((eB,iB),fB) <- genNewExp (exprDepth - 1) False True ((eB,iB),fB) <- genNewExp (exprDepth - 1) False True
m <- get m <- get
let nextId = 1 + maximum (0 : Map.elems m) let nextId = 1 + maximum (0 : Map.elems m)
return (A.Dyadic emptyMeta A.Rem eT eB, Modulo 1 (errorOrRight $ makeExpSet fT) (errorOrRight $ makeExpSet fB), nextId) return (dyadicExprInt "\\" eT eB, Modulo 1 (errorOrRight $ makeExpSet fT) (errorOrRight $ makeExpSet fB), nextId)
),(10,do ((eT,iT),fT) <- genNewExp (exprDepth - 1) False True ),(10,do ((eT,iT),fT) <- genNewExp (exprDepth - 1) False True
((eB,iB),fB) <- genConst ((eB,iB),fB) <- genConst
m <- get m <- get
let nextId = 1 + maximum (0 : Map.elems m) let nextId = 1 + maximum (0 : Map.elems m)
return (A.Dyadic emptyMeta A.Div eT eB, Divide 1 (errorOrRight $ makeExpSet fT) (Set.singleton fB), nextId) return (divExprsInt eT eB, Divide 1 (errorOrRight $ makeExpSet fT) (Set.singleton fB), nextId)
)] )]
modify (Map.insert fexp nextId) modify (Map.insert fexp nextId)
return ((exp, [(nextId,1)]), fexp) return ((exp, [(nextId,1)]), fexp)
@ -624,7 +631,7 @@ genNewExp exprDepth specialAllowed constAllowed
sign -> do mult' <- lift $ choose (1 :: Integer,10) sign -> do mult' <- lift $ choose (1 :: Integer,10)
let mult = sign * mult' let mult = sign * mult'
return $ transformPair return $ transformPair
(transformPair (A.Dyadic emptyMeta A.Mul (intLiteral mult)) (map (transformPair id (* mult)))) (transformPair (mulExprsInt (intLiteral mult)) (map (transformPair id (* mult))))
(scaleEq mult) unmult (scaleEq mult) unmult
scaleEq :: Integer -> FlattenedExp -> FlattenedExp scaleEq :: Integer -> FlattenedExp -> FlattenedExp
scaleEq k (Const n) = Const (k * n) scaleEq k (Const n) = Const (k * n)
@ -634,7 +641,7 @@ genNewExp exprDepth specialAllowed constAllowed
join :: Maybe (GenEqItems, [FlattenedExp]) -> (GenEqItems,FlattenedExp) -> Maybe (GenEqItems, [FlattenedExp]) join :: Maybe (GenEqItems, [FlattenedExp]) -> (GenEqItems,FlattenedExp) -> Maybe (GenEqItems, [FlattenedExp])
join Nothing (e,f) = Just (e,[f]) join Nothing (e,f) = Just (e,[f])
join (Just ((ex,ix),fxs)) ((ey,iy),fy) = Just ((A.Dyadic emptyMeta A.Add ex ey, ix ++ iy),fxs ++ [fy]) join (Just ((ex,ix),fxs)) ((ey,iy),fy) = Just ((addExprsInt ex ey, ix ++ iy),fxs ++ [fy])
generateEquationInput :: Gen ([(((A.Expression,[ModuloCase]), (A.Expression,[ModuloCase])),VarMap,[HandyEq],[HandyIneq])],ParItems [A.Expression],A.Expression) generateEquationInput :: Gen ([(((A.Expression,[ModuloCase]), (A.Expression,[ModuloCase])),VarMap,[HandyEq],[HandyIneq])],ParItems [A.Expression],A.Expression)
generateEquationInput generateEquationInput
@ -873,8 +880,12 @@ generateMapping msg m0 m1
= do testEqual ("Keys in variable mapping " ++ msg) (Map.keys m0') (Map.keys m1') = do testEqual ("Keys in variable mapping " ++ msg) (Map.keys m0') (Map.keys m1')
return $ Map.elems $ zipMap mergeMaybe m0' m1' return $ Map.elems $ zipMap mergeMaybe m0' m1'
where where
m0' = Map.mapKeys (fmapFlattenedExp canonicalise) m0 m0' = Map.mapKeys (fmapFlattenedExp (fromRight . rr . canonicalise)) m0
m1' = Map.mapKeys (fmapFlattenedExp canonicalise) m1 m1' = Map.mapKeys (fmapFlattenedExp (fromRight . rr . canonicalise)) m1
fromRight :: Either String a -> a
fromRight (Right s) = s
fromRight (Left _) = error "fromRight found Left"
-- | Given a forward mapping list, translates equations across -- | Given a forward mapping list, translates equations across
translateEquations :: forall m r. TestMonad m r => translateEquations :: forall m r. TestMonad m r =>

View File

@ -35,6 +35,7 @@ import Metadata
import OccamEDSL import OccamEDSL
import TestFramework import TestFramework
import TestUtils hiding (Var) import TestUtils hiding (Var)
import Types
import UsageCheckAlgorithms import UsageCheckAlgorithms
import UsageCheckUtils import UsageCheckUtils
import Utils import Utils
@ -68,8 +69,9 @@ ab_eq_cd = A.Assign m [vA,vB] $ A.ExpressionList m [A.ExprVariable m vC,A.ExprVa
ab_eq_ba = A.Assign m [vA,vB] $ A.ExpressionList m [A.ExprVariable m vA,A.ExprVariable m vB] ab_eq_ba = A.Assign m [vA,vB] $ A.ExpressionList m [A.ExprVariable m vA,A.ExprVariable m vB]
ab_eq_b0 = A.Assign m [vA,vB] $ A.ExpressionList m [A.ExprVariable m vB,l0] ab_eq_b0 = A.Assign m [vA,vB] $ A.ExpressionList m [A.ExprVariable m vB,l0]
a_eq_c_plus_d = A.Assign m [vA] $ A.ExpressionList m [A.Dyadic m A.Plus (A.ExprVariable m vC) (A.ExprVariable m vD)] a_eq_c_plus_d = A.Assign m [vA] $ A.ExpressionList m [dyadicExprInt "PLUS" (A.ExprVariable m vC) (A.ExprVariable m vD)]
a_eq_not_b = A.Assign m [vA] $ A.ExpressionList m [A.Monadic m A.MonadicNot (A.ExprVariable m vB)] a_eq_not_b = A.Assign m [vA] $ A.ExpressionList m
[A.FunctionCall m (A.Name m $ occamDefaultOperator "NOT" [A.Bool]) [A.ExprVariable m vB]]
testGetVarProc :: Test testGetVarProc :: Test
testGetVarProc = TestList (map doTest tests) testGetVarProc = TestList (map doTest tests)
@ -127,8 +129,6 @@ testGetVarProc = TestList (map doTest tests)
--TODO test declarations being recorded, when I've decided how to record them --TODO test declarations being recorded, when I've decided how to record them
type TestM = ReaderT CompState (Either String) type TestM = ReaderT CompState (Either String)
instance Die TestM where
dieReport (_,s) = throwError s
instance Warn TestM where instance Warn TestM where
warnReport (_,_,s) = throwError s warnReport (_,_,s) = throwError s

View File

@ -43,6 +43,7 @@ import Pass
import Pattern import Pattern
import TestUtils import TestUtils
import TreeUtils import TreeUtils
import Types
import Utils import Utils
-- The rough rules for converting occam to pseudo-occam are: -- The rough rules for converting occam to pseudo-occam are:
@ -290,7 +291,7 @@ infix 8 *:=
(*+) :: (CanBeExpression e, CanBeExpression e') => e -> e' -> ExpInp (A.Expression) (*+) :: (CanBeExpression e, CanBeExpression e') => e -> e' -> ExpInp (A.Expression)
(*+) x y = do x' <- expr x (*+) x y = do x' <- expr x
y' <- expr y y' <- expr y
return (A.Dyadic emptyMeta A.Add x' y') return $ addExprsInt x' y'
sub :: ExpInp A.Variable -> Int -> ExpInp A.Variable sub :: ExpInp A.Variable -> Int -> ExpInp A.Variable

View File

@ -268,8 +268,8 @@ makeLiteralCharPattern :: Char -> Pattern
makeLiteralCharPattern c = tag3 A.Literal DontCare A.Byte (tag2 A.ByteLiteral DontCare [c]) makeLiteralCharPattern c = tag3 A.Literal DontCare A.Byte (tag2 A.ByteLiteral DontCare [c])
data ExprHelper = data ExprHelper =
Dy ExprHelper A.DyadicOp ExprHelper Dy ExprHelper String ExprHelper
| Mon A.MonadicOp ExprHelper | Mon (String, A.Type) ExprHelper
| Cast A.Type ExprHelper | Cast A.Type ExprHelper
| Var String | Var String
| DirVar A.Direction String | DirVar A.Direction String
@ -281,8 +281,9 @@ buildExprPattern :: ExprHelper -> Pattern
buildExprPattern = (stopCaringPattern emptyMeta) . mkPattern . buildExpr buildExprPattern = (stopCaringPattern emptyMeta) . mkPattern . buildExpr
buildExpr :: ExprHelper -> A.Expression buildExpr :: ExprHelper -> A.Expression
buildExpr (Dy lhs op rhs) = A.Dyadic emptyMeta op (buildExpr lhs) (buildExpr rhs) buildExpr (Dy lhs op rhs) = A.FunctionCall emptyMeta (A.Name emptyMeta
buildExpr (Mon op rhs) = A.Monadic emptyMeta op (buildExpr rhs) $ occamDefaultOperator op [A.Int, A.Int]) [buildExpr lhs, buildExpr rhs]
buildExpr (Mon (op, t) rhs) = A.FunctionCall emptyMeta (A.Name emptyMeta $ occamDefaultOperator op [t]) [buildExpr rhs]
buildExpr (Cast ty rhs) = A.Conversion emptyMeta A.DefaultConversion ty (buildExpr rhs) buildExpr (Cast ty rhs) = A.Conversion emptyMeta A.DefaultConversion ty (buildExpr rhs)
buildExpr (Var n) = A.ExprVariable emptyMeta $ variable n buildExpr (Var n) = A.ExprVariable emptyMeta $ variable n
buildExpr (DirVar dir n) = A.ExprVariable emptyMeta $ (A.DirectedVariable emptyMeta dir $ variable n) buildExpr (DirVar dir n) = A.ExprVariable emptyMeta $ (A.DirectedVariable emptyMeta dir $ variable n)

View File

@ -29,6 +29,7 @@ module Types
, makeAbbrevAM, makeConstant, makeConstant', makeDimension, specificDimSize , makeAbbrevAM, makeConstant, makeConstant', makeDimension, specificDimSize
, addOne, subOne, addExprs, subExprs, mulExprs, divExprs, remExprs , addOne, subOne, addExprs, subExprs, mulExprs, divExprs, remExprs
, addOneInt, subOneInt, addExprsInt, subExprsInt, mulExprsInt, divExprsInt , addOneInt, subOneInt, addExprsInt, subExprsInt, mulExprsInt, divExprsInt
, dyadicExpr, dyadicExprInt
, addDimensions, applyDimension, removeFixedDimensions, trivialSubscriptType, subscriptType, unsubscriptType , addDimensions, applyDimension, removeFixedDimensions, trivialSubscriptType, subscriptType, unsubscriptType
, applyDirection , applyDirection
, recordFields, recordAttr, protocolItems, dirAttr , recordFields, recordAttr, protocolItems, dirAttr
@ -796,7 +797,7 @@ occamOperatorTranslateDefault "AND" = "and"
occamOperatorTranslateDefault "OR" = "or" occamOperatorTranslateDefault "OR" = "or"
occamOperatorTranslateDefault "NOT" = "not" occamOperatorTranslateDefault "NOT" = "not"
occamOperatorTranslateDefault "~" = "not" occamOperatorTranslateDefault "~" = "not"
occamOperatorTranslateDefault cs = '_' : concatMap (show . ord) cs occamOperatorTranslateDefault cs = "op_" ++ concatMap (show . ord) cs
occamDefaultOperator :: String -> [A.Type] -> String occamDefaultOperator :: String -> [A.Type] -> String
occamDefaultOperator op ts = "occam_" ++ occamOperatorTranslateDefault op occamDefaultOperator op ts = "occam_" ++ occamOperatorTranslateDefault op
@ -844,6 +845,9 @@ dyadicExpr op a b = do ta <- astTypeOf a
tb <- astTypeOf b tb <- astTypeOf b
return $ dyadicExpr' (ta, tb) op a b return $ dyadicExpr' (ta, tb) op a b
dyadicExprInt :: String -> DyadicExpr
dyadicExprInt op = dyadicExpr' (A.Int, A.Int) op
-- | Add two expressions. -- | Add two expressions.
addExprs :: DyadicExprM addExprs :: DyadicExprM
addExprs = dyadicExpr "+" addExprs = dyadicExpr "+"

View File

@ -34,6 +34,7 @@ import Test.HUnit hiding (Node, State, Testable)
import Test.QuickCheck import Test.QuickCheck
import qualified AST as A import qualified AST as A
import CompState
import FlowGraph import FlowGraph
import GenericUtils import GenericUtils
import Metadata import Metadata
@ -105,7 +106,7 @@ nextId' inc t
return n return n
Nothing -> do put $ Map.insert m inc mp Nothing -> do put $ Map.insert m inc mp
return 0 return 0
where m = findMeta t where m = findMeta_Data t
-- | Given a test name, a list of nodes, a list of root nodes, a list of edges and an AST fragment, tests that the -- | Given a test name, a list of nodes, a list of root nodes, a list of edges and an AST fragment, tests that the
-- CFG produced from the given AST matches the nodes and edges. The nodes do not have to have -- CFG produced from the given AST matches the nodes and edges. The nodes do not have to have

View File

@ -31,6 +31,7 @@ import CompState
import Metadata import Metadata
import qualified OccamPasses import qualified OccamPasses
import TestUtils import TestUtils
import Types
m :: Meta m :: Meta
m = emptyMeta m = emptyMeta
@ -96,7 +97,7 @@ testFoldConstants = TestList
testSame :: Int -> A.Expression -> Test testSame :: Int -> A.Expression -> Test
testSame n orig = test n orig orig testSame n orig = test n orig orig
add e f = A.Dyadic m A.Add e f add e f = addExprsInt e f
var = exprVariable "var" var = exprVariable "var"
const = exprVariable "const" const = exprVariable "const"
one = intLiteral 1 one = intLiteral 1

View File

@ -127,24 +127,6 @@ testOccamTypes = TestList
, testOK 54 $ A.DerefVariable m mobileIntV , testOK 54 $ A.DerefVariable m mobileIntV
, testFail 55 $ A.DerefVariable m intC , testFail 55 $ A.DerefVariable m intC
-- Operators in expressions
, testOK 100 $ A.Monadic m A.MonadicSubtr intE
, testFail 101 $ A.Monadic m A.MonadicSubtr twoIntsE
, testFail 102 $ A.Monadic m A.MonadicSubtr boolE
, testFail 103 $ A.Monadic m A.MonadicNot intE
, testOK 104 $ A.Monadic m A.MonadicNot boolE
, testOK 105 $ A.Dyadic m A.Add intE intE
, testFail 106 $ A.Dyadic m A.Add intE byteE
, testFail 107 $ A.Dyadic m A.Add byteE intE
, testFail 108 $ A.Dyadic m A.Add byteE boolE
, testOK 109 $ A.Dyadic m A.LeftShift intE intE
, testOK 110 $ A.Dyadic m A.LeftShift byteE intE
, testFail 111 $ A.Dyadic m A.LeftShift intE byteE
, testOK 112 $ A.Dyadic m A.And boolE boolE
, testFail 113 $ A.Dyadic m A.And boolE intE
, testFail 114 $ A.Dyadic m A.And intE boolE
, testFail 115 $ A.Dyadic m A.Add twoIntsE twoIntsE
-- Miscellaneous expressions -- Miscellaneous expressions
, testOK 150 $ A.MostPos m A.Int , testOK 150 $ A.MostPos m A.Int
, testFail 151 $ A.MostPos m twoIntsT , testFail 151 $ A.MostPos m twoIntsT

View File

@ -137,6 +137,7 @@ emptyBlock = A.Seq m emptySeveral
--subExpr' ::= exprItem | monadicArithOp subExpr' | "(" expression ")" --subExpr' ::= exprItem | monadicArithOp subExpr' | "(" expression ")"
{-
testExprs :: [ParseTest A.Expression] testExprs :: [ParseTest A.Expression]
testExprs = testExprs =
[ [
@ -144,28 +145,28 @@ testExprs =
passE ("b", -1, Var "b" ) passE ("b", -1, Var "b" )
--Dyadic operators: --Dyadic operators:
,passE ("b + c", 0 ,Dy (Var "b") A.Plus (Var "c") ) ,passE ("b + c", 0 ,Dy (Var "b") plus (Var "c") )
,passE ("b % c", 0 ,Dy (Var "b") A.Rem (Var "c") ) ,passE ("b % c", 0 ,Dy (Var "b") A.Rem (Var "c") )
,passE ("b == c", 1 ,Dy (Var "b") A.Eq (Var "c") ) ,passE ("b == c", 1 ,Dy (Var "b") eq (Var "c") )
,passE ("(b + c)", 2 ,Dy (Var "b") A.Plus (Var "c") ) ,passE ("(b + c)", 2 ,Dy (Var "b") plus (Var "c") )
,passE ("(b == c)", 3 ,Dy (Var "b") A.Eq (Var "c") ) ,passE ("(b == c)", 3 ,Dy (Var "b") eq (Var "c") )
,passE ("((b + c))", 4 ,Dy (Var "b") A.Plus (Var "c") ) ,passE ("((b + c))", 4 ,Dy (Var "b") plus (Var "c") )
,passE ("((b == c))", 5 ,Dy (Var "b") A.Eq (Var "c") ) ,passE ("((b == c))", 5 ,Dy (Var "b") eq (Var "c") )
,passE ("b - c", 6 ,Dy (Var "b") A.Minus (Var "c" )) ,passE ("b - c", 6 ,Dy (Var "b") A.Minus (Var "c" ))
,passE ("b + c + d", 7, Dy (Dy (Var "b") A.Plus (Var "c")) A.Plus (Var "d") ) ,passE ("b + c + d", 7, Dy (Dy (Var "b") plus (Var "c")) plus (Var "d") )
,passE ("(b + c) + d", 8, Dy (Dy (Var "b") A.Plus (Var "c")) A.Plus (Var "d") ) ,passE ("(b + c) + d", 8, Dy (Dy (Var "b") plus (Var "c")) plus (Var "d") )
,passE ("b + (c + d)", 9, Dy (Var "b") A.Plus (Dy (Var "c") A.Plus (Var "d")) ) ,passE ("b + (c + d)", 9, Dy (Var "b") plus (Dy (Var "c") plus (Var "d")) )
,passE ("b - c * d / e", 10, Dy (Dy (Dy (Var "b") A.Minus (Var "c")) A.Times (Var "d")) A.Div (Var "e") ) ,passE ("b - c * d / e", 10, Dy (Dy (Dy (Var "b") A.Minus (Var "c")) A.Times (Var "d")) A.Div (Var "e") )
,passE ("b + c == d * e", 11, Dy (Dy (Var "b") A.Plus (Var "c")) A.Eq (Dy (Var "d") A.Times (Var "e")) ) ,passE ("b + c == d * e", 11, Dy (Dy (Var "b") plus (Var "c")) eq (Dy (Var "d") A.Times (Var "e")) )
,passE ("(b + c) == d * e", 12, Dy (Dy (Var "b") A.Plus (Var "c")) A.Eq (Dy (Var "d") A.Times (Var "e")) ) ,passE ("(b + c) == d * e", 12, Dy (Dy (Var "b") plus (Var "c")) eq (Dy (Var "d") A.Times (Var "e")) )
,passE ("b + c == (d * e)", 13, Dy (Dy (Var "b") A.Plus (Var "c")) A.Eq (Dy (Var "d") A.Times (Var "e")) ) ,passE ("b + c == (d * e)", 13, Dy (Dy (Var "b") plus (Var "c")) eq (Dy (Var "d") A.Times (Var "e")) )
,passE ("(b + c) == (d * e)", 14, Dy (Dy (Var "b") A.Plus (Var "c")) A.Eq (Dy (Var "d") A.Times (Var "e")) ) ,passE ("(b + c) == (d * e)", 14, Dy (Dy (Var "b") plus (Var "c")) eq (Dy (Var "d") A.Times (Var "e")) )
,passE ("(b == c) + (d == e)", 15, Dy (Dy (Var "b") A.Eq (Var "c")) A.Plus (Dy (Var "d") A.Eq (Var "e")) ) ,passE ("(b == c) + (d == e)", 15, Dy (Dy (Var "b") eq (Var "c")) plus (Dy (Var "d") eq (Var "e")) )
,passE ("(b == c) + d == e", 16, Dy (Dy (Dy (Var "b") A.Eq (Var "c")) A.Plus (Var "d")) A.Eq (Var "e") ) ,passE ("(b == c) + d == e", 16, Dy (Dy (Dy (Var "b") eq (Var "c")) plus (Var "d")) eq (Var "e") )
,passE ("(b == c) == (d == e)", 17, Dy (Dy (Var "b") A.Eq (Var "c")) A.Eq (Dy (Var "d") A.Eq (Var "e")) ) ,passE ("(b == c) == (d == e)", 17, Dy (Dy (Var "b") eq (Var "c")) eq (Dy (Var "d") eq (Var "e")) )
,passE ("(b == c) == d", 18, Dy (Dy (Var "b") A.Eq (Var "c")) A.Eq (Var "d") ) ,passE ("(b == c) == d", 18, Dy (Dy (Var "b") eq (Var "c")) eq (Var "d") )
,failE ("b == c + d == e") ,failE ("b == c + d == e")
,failE ("b == c == d") ,failE ("b == c == d")
@ -179,9 +180,9 @@ testExprs =
,passE ("a - - b", 102, Dy (Var "a") A.Minus (Mon A.MonadicMinus $ Var "b") ) ,passE ("a - - b", 102, Dy (Var "a") A.Minus (Mon A.MonadicMinus $ Var "b") )
,passE ("a--b", 103, Dy (Var "a") A.Minus (Mon A.MonadicMinus $ Var "b") ) ,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 ("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", 105, Dy (Mon A.MonadicMinus $ Var "b") plus (Var "c") )
,passE ("c+-b", 106, Dy (Var "c") A.Plus (Mon A.MonadicMinus $ Var "b") ) ,passE ("c+-b", 106, Dy (Var "c") plus (Mon A.MonadicMinus $ Var "b") )
,passE ("-(b+c)", 107, Mon A.MonadicMinus $ Dy (Var "b") A.Plus (Var "c") ) ,passE ("-(b+c)", 107, Mon A.MonadicMinus $ Dy (Var "b") plus (Var "c") )
--Casting: --Casting:
@ -189,13 +190,13 @@ testExprs =
,passE ("mytype: b", 202, Cast (A.UserDataType $ typeName "mytype") (Var "b")) ,passE ("mytype: b", 202, Cast (A.UserDataType $ typeName "mytype") (Var "b"))
--Should at least parse: --Should at least parse:
,passE ("uint8 : true", 203, Cast A.Byte $ Lit (A.True m) ) ,passE ("uint8 : true", 203, Cast A.Byte $ Lit (A.True m) )
,passE ("uint8 : b == c", 204, Cast A.Byte $ Dy (Var "b") A.Eq (Var "c") ) ,passE ("uint8 : b == c", 204, Cast A.Byte $ Dy (Var "b") eq (Var "c") )
,passE ("uint8 : b + c", 205, Cast A.Byte $ Dy (Var "b") A.Plus (Var "c") ) ,passE ("uint8 : b + c", 205, Cast A.Byte $ Dy (Var "b") plus (Var "c") )
,passE ("uint8 : b + c == d * e", 206, Cast A.Byte $ Dy (Dy (Var "b") A.Plus (Var "c")) A.Eq (Dy (Var "d") A.Times (Var "e")) ) ,passE ("uint8 : b + c == d * e", 206, Cast A.Byte $ Dy (Dy (Var "b") plus (Var "c")) eq (Dy (Var "d") A.Times (Var "e")) )
,passE ("uint8 : b + (uint8 : c)", 207, Cast A.Byte $ Dy (Var "b") A.Plus (Cast A.Byte $ Var "c") ) ,passE ("uint8 : b + (uint8 : c)", 207, Cast A.Byte $ Dy (Var "b") plus (Cast A.Byte $ Var "c") )
,passE ("(uint8 : b) + (uint8 : c)", 208, Dy (Cast A.Byte $ Var "b") A.Plus (Cast A.Byte $ Var "c") ) ,passE ("(uint8 : b) + (uint8 : c)", 208, Dy (Cast A.Byte $ Var "b") plus (Cast A.Byte $ Var "c") )
,passE ("uint8 : b == (uint8 : c)", 209, Cast A.Byte $ Dy (Var "b") A.Eq (Cast A.Byte $ Var "c") ) ,passE ("uint8 : b == (uint8 : c)", 209, Cast A.Byte $ Dy (Var "b") eq (Cast A.Byte $ Var "c") )
,passE ("(uint8 : b) == (uint8 : c)", 210, Dy (Cast A.Byte $ Var "b") A.Eq (Cast A.Byte $ Var "c") ) ,passE ("(uint8 : b) == (uint8 : c)", 210, Dy (Cast A.Byte $ Var "b") eq (Cast A.Byte $ Var "c") )
,failE ("uint8 : b + uint8 : c") ,failE ("uint8 : b + uint8 : c")
,failE ("uint8 : b == uint8 : c") ,failE ("uint8 : b == uint8 : c")
,failE ("(uint8 : b) + uint8 : c") ,failE ("(uint8 : b) + uint8 : c")
@ -209,13 +210,13 @@ testExprs =
,failE ("?c:") ,failE ("?c:")
,failE (":?c") ,failE (":?c")
,passE ("(48 + (uint8: src % 10)) + r",300,Dy (Dy (Lit $ intLiteral 48) A.Plus (Cast A.Byte $ Dy (Var "src") A.Rem (Lit $ intLiteral 10))) A.Plus (Var "r")) ,passE ("(48 + (uint8: src % 10)) + r",300,Dy (Dy (Lit $ intLiteral 48) plus (Cast A.Byte $ Dy (Var "src") A.Rem (Lit $ intLiteral 10))) plus (Var "r"))
-- Function calls: -- Function calls:
,passE ("foo()", 400, Func "foo" []) ,passE ("foo()", 400, Func "foo" [])
,passE ("foo(0)", 401, Func "foo" [Lit $ intLiteral 0]) ,passE ("foo(0)", 401, Func "foo" [Lit $ intLiteral 0])
,passE ("foo(0,1,2,3)", 402, Func "foo" $ map (Lit . intLiteral) [0,1,2,3]) ,passE ("foo(0,1,2,3)", 402, Func "foo" $ map (Lit . intLiteral) [0,1,2,3])
,passE ("2 + foo()", 403, Dy (Lit $ intLiteral 2) A.Plus $ Func "foo" []) ,passE ("2 + foo()", 403, Dy (Lit $ intLiteral 2) plus $ Func "foo" [])
,failE ("foo(") ,failE ("foo(")
,failE ("foo)") ,failE ("foo)")
,failE ("foo + 2()") ,failE ("foo + 2()")
@ -229,6 +230,9 @@ testExprs =
(pat $ buildExprPattern expr)) (pat $ buildExprPattern expr))
failE x = fail (x,RP.expression) failE x = fail (x,RP.expression)
plus = ("+", A.Int, A.Int)
eq = ("=", A.Int, A.Int)
--TODO add support for shared ? and shared !, as well as any2any channels etc --TODO add support for shared ? and shared !, as well as any2any channels etc
testLiteral :: [ParseTest A.Expression] testLiteral :: [ParseTest A.Expression]
@ -748,11 +752,12 @@ testPoison =
,fail ("poison;", RP.statement) ,fail ("poison;", RP.statement)
,fail ("poison", RP.statement) ,fail ("poison", RP.statement)
] ]
-}
--Returns the list of tests: --Returns the list of tests:
tests :: Test tests :: Test
tests = TestLabel "ParseRainTest" $ TestList tests = TestLabel "ParseRainTest" $ TestList
[ [] {-
parseTests testExprs, parseTests testExprs,
parseTests testLiteral, parseTests testLiteral,
parseTests testRange, parseTests testRange,
@ -771,7 +776,7 @@ tests = TestLabel "ParseRainTest" $ TestList
parseTests testDecl, parseTests testDecl,
parseTests testPoison, parseTests testPoison,
parseTests testTopLevelDecl parseTests testTopLevelDecl
] ] -}
--TODO test: --TODO test:
-- input (incl. ext input) -- input (incl. ext input)
--TODO later on: --TODO later on:

View File

@ -46,6 +46,7 @@ import RainTypes
import TagAST import TagAST
import TestUtils import TestUtils
import TreeUtils import TreeUtils
import Types
import Utils import Utils
m :: Meta m :: Meta
@ -63,8 +64,8 @@ castAssertADI x = case (castADI x) of
Nothing -> dieInternal (Nothing, "Pattern successfully matched but did not find item afterwards") Nothing -> dieInternal (Nothing, "Pattern successfully matched but did not find item afterwards")
makeRange :: Integer -> Integer -> A.Expression makeRange :: Integer -> Integer -> A.Expression
makeRange b e = A.Dyadic emptyMeta A.Add (intLiteral 1) makeRange b e = addExprsInt (intLiteral 1)
(A.Dyadic emptyMeta A.Subtr (intLiteral e) (intLiteral b)) (subExprsInt (intLiteral e) (intLiteral b))
testEachRangePass0 :: Test testEachRangePass0 :: Test
testEachRangePass0 = TestCase $ testPass "testEachRangePass0" exp transformEachRange orig (return ()) testEachRangePass0 = TestCase $ testPass "testEachRangePass0" exp transformEachRange orig (return ())

View File

@ -47,7 +47,7 @@ m = emptyMeta
-- | Tests that constants in expressions are folded properly. TODO these tests could do with a lot of expanding. -- | Tests that constants in expressions are folded properly. TODO these tests could do with a lot of expanding.
-- It may even be easiest to use QuickCheck for the testing. -- It may even be easiest to use QuickCheck for the testing.
constantFoldTest :: Test constantFoldTest :: Test
constantFoldTest = TestList constantFoldTest = TestList [] {-
[ [
foldVar 0 $ Var "x" foldVar 0 $ Var "x"
,foldVar 1 $ Dy (Var "x") A.Plus (lit 0) ,foldVar 1 $ Dy (Var "x") A.Plus (lit 0)
@ -57,7 +57,7 @@ constantFoldTest = TestList
,foldCon 102 (lit (- two63)) (Dy (lit $ two63 - 1) A.Plus (lit 1)) ,foldCon 102 (lit (- two63)) (Dy (lit $ two63 - 1) A.Plus (lit 1))
,foldCon 110 (Dy (Var "x") A.Plus (lit 2)) (Dy (Var "x") A.Plus (Dy (lit 1) A.Plus (lit 1))) ,foldCon 110 (Dy (Var "x") A.Plus (lit 2)) (Dy (Var "x") A.Plus (Dy (lit 1) A.Plus (lit 1)))
] ] -}
where where
two63 :: Integer two63 :: Integer
two63 = 9223372036854775808 two63 = 9223372036854775808

View File

@ -34,6 +34,7 @@ import SimplifyExprs
import TagAST import TagAST
import TestUtils import TestUtils
import TreeUtils import TreeUtils
import Types
import Unnest import Unnest
import Utils import Utils
@ -248,7 +249,7 @@ testTransformConstr0 = TestCase $ testPass "transformConstr0" exp transformConst
exprVariable "i") (variable "arr")] $ exprVariable "i") (variable "arr")] $
A.ExpressionList m [exprVariable "x"], A.ExpressionList m [exprVariable "x"],
A.Only m $ A.Assign m [variable "i"] $ A.ExpressionList m A.Only m $ A.Assign m [variable "i"] $ A.ExpressionList m
[A.Dyadic m A.Add (intLiteral 1) (exprVariable "i")]] [addExprsInt (intLiteral 1) (exprVariable "i")]]
] ]
) )
skipP skipP
@ -339,7 +340,7 @@ testOutExprs = TestList
where where
outX = A.OutExpression emptyMeta $ exprVariable "x" outX = A.OutExpression emptyMeta $ exprVariable "x"
outXM n = A.OutExpression emptyMeta $ eXM n outXM n = A.OutExpression emptyMeta $ eXM n
eXM n = buildExpr $ Dy (Var "x") A.Minus (Lit $ intLiteral n) eXM n = buildExpr $ Dy (Var "x") "-" (Lit $ intLiteral n)
abbr key t e = mSpecP abbr key t e = mSpecP
(tag3 A.Specification DontCare (Named key DontCare) (tag3 A.Specification DontCare (Named key DontCare)