Rewrote transformRangeRep, stopping it requiring constants in ranges
This commit is contained in:
parent
b20a7fcb0b
commit
8f51ead090
|
@ -196,6 +196,9 @@ transformEachRange = doGeneric `ext1M` doStructured
|
||||||
doStructured s = doGeneric s
|
doStructured s = doGeneric s
|
||||||
|
|
||||||
-- | A pass that changes all the Rain range constructor expressions into the more general array constructor expressions
|
-- | A pass that changes all the Rain range constructor expressions into the more general array constructor expressions
|
||||||
|
--
|
||||||
|
-- TODO make sure when the range has a bad order that an empty list is
|
||||||
|
-- returned
|
||||||
transformRangeRep :: Data t => t -> PassM t
|
transformRangeRep :: Data t => t -> PassM t
|
||||||
transformRangeRep = doGeneric `extM` doExpression
|
transformRangeRep = doGeneric `extM` doExpression
|
||||||
where
|
where
|
||||||
|
@ -203,22 +206,12 @@ transformRangeRep = doGeneric `extM` doExpression
|
||||||
doGeneric = makeGeneric transformRangeRep
|
doGeneric = makeGeneric transformRangeRep
|
||||||
|
|
||||||
doExpression :: A.Expression -> PassM A.Expression
|
doExpression :: A.Expression -> PassM A.Expression
|
||||||
doExpression (A.ExprConstr _ (A.RangeConstr m t (A.Literal _ _ beginLit) (A.Literal _ _ endLit)))
|
doExpression (A.ExprConstr _ (A.RangeConstr m t begin end))
|
||||||
= if (isJust $ checkIntegral beginLit) && (isJust $ checkIntegral endLit)
|
= do A.Specification _ rep _ <- makeNonceVariable "rep_constr" m A.Int A.VariableName A.ValAbbrev
|
||||||
then transformRangeRep'' m (fromJust $ checkIntegral beginLit) (fromJust $ checkIntegral endLit)
|
let count = addOne $ subExprs end begin
|
||||||
else dieP m "Items in range constructor (x..y) are not integer literals"
|
|
||||||
where
|
|
||||||
transformRangeRep'' :: Meta -> Integer -> Integer -> PassM A.Expression
|
|
||||||
transformRangeRep'' m begin end
|
|
||||||
= if (end < begin)
|
|
||||||
then dieP m $ "End of range is before beginning: " ++ show begin ++ " > " ++ show end
|
|
||||||
else do A.Specification _ rep _ <- makeNonceVariable "rep_constr" m A.Int A.VariableName A.ValAbbrev
|
|
||||||
let count = end - begin + 1
|
|
||||||
return $ A.ExprConstr m $ A.RepConstr m t
|
return $ A.ExprConstr m $ A.RepConstr m t
|
||||||
(A.For m rep
|
(A.For m rep begin count)
|
||||||
(A.Literal m A.Int (A.IntLiteral m $ show begin))
|
(A.ExprVariable m $ A.Variable m rep)
|
||||||
(A.Literal m A.Int (A.IntLiteral m $ show count))
|
|
||||||
) (A.ExprVariable m $ A.Variable m rep)
|
|
||||||
doExpression e = doGeneric e
|
doExpression e = doGeneric e
|
||||||
|
|
||||||
checkFunction :: Data t => t -> PassM t
|
checkFunction :: Data t => t -> PassM t
|
||||||
|
|
Loading…
Reference in New Issue
Block a user