Rain: fixed the constant folding pass to work with constant sub-expressions
This commit is contained in:
parent
e35873f01c
commit
989f12b051
|
@ -48,13 +48,19 @@ recordInfNameTypes = everywhereM (mkM recordInfNameTypes')
|
|||
return input
|
||||
recordInfNameTypes' r = return r
|
||||
|
||||
-- | Folds all constants.
|
||||
constantFoldPass :: Data t => t -> PassM t
|
||||
constantFoldPass = doGeneric `extM` doExpression
|
||||
everywhereASTM :: (Data s, Data t) => (s -> PassM s) -> t -> PassM t
|
||||
everywhereASTM f = doGeneric `extM` (doSpecific f)
|
||||
where
|
||||
doGeneric :: Data t => t -> PassM t
|
||||
doGeneric = makeGeneric constantFoldPass
|
||||
doGeneric = makeGeneric (everywhereASTM f)
|
||||
|
||||
doSpecific :: Data t => (t -> PassM t) -> t -> PassM t
|
||||
doSpecific f x = (doGeneric x >>= f)
|
||||
|
||||
-- | Folds all constants.
|
||||
constantFoldPass :: Data t => t -> PassM t
|
||||
constantFoldPass = everywhereASTM doExpression
|
||||
where
|
||||
doExpression :: A.Expression -> PassM A.Expression
|
||||
doExpression = (liftM (\(x,_,_) -> x)) . constantFold
|
||||
|
||||
|
|
|
@ -35,6 +35,8 @@ constantFoldTest = TestList
|
|||
,foldCon 100 (lit 2) (Dy (lit 1) A.Plus (lit 1))
|
||||
,foldCon 101 (lit 65537) (Dy (lit 2) A.Plus (lit 65535))
|
||||
,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)))
|
||||
]
|
||||
where
|
||||
two63 :: Integer
|
||||
|
|
Loading…
Reference in New Issue
Block a user