@@ -18,7 +18,6 @@
18module Language.PureScript.CodeGen.Cpp.Optimizer.Inliner
18module Language.PureScript.CodeGen.Cpp.Optimizer.Inliner
19 ( inlineVariables
19 ( inlineVariables
20 , inlineCommonValues
20 , inlineCommonValues
22 , inlineCommonOperators
21 , inlineCommonOperators
23 , inlineFnComposition
22 , inlineFnComposition
24 , inlineUnsafePartial
23 , inlineUnsafePartial
@@ -29,7 +28,7 @@ module Language.PureScript.CodeGen.Cpp.Optimizer.Inliner
31import Prelude.Compat
30import Prelude.Compat
32−import Data.Text (Text)
31+import Data.Text (Text, cons)
34import Control.Monad.Supply.Class (MonadSupply, freshName)
33import Control.Monad.Supply.Class (MonadSupply, freshName)
@@ -137,14 +136,15 @@ inlineCommonValues = everywhereOnCpp convert
137 fnSubtract = (C.dataRing, C.sub)
136 fnSubtract = (C.dataRing, C.sub)
138 fnNegate = (C.dataRing, C.negate)
137 fnNegate = (C.dataRing, C.negate)
140−inlineOperator :: (Text, Text) -> (Cpp -> Cpp -> Cpp) -> Cpp -> Cpp
139+inlineNonClassFunction :: (Text, Text) -> (Cpp -> Cpp -> Cpp) -> Cpp -> Cpp
141−inlineOperator (m, op) f = everywhereOnCpp convert
140+inlineNonClassFunction (m, op) f = everywhereOnCpp convert
143 convert :: Cpp -> Cpp
142 convert :: Cpp -> Cpp
144 convert (CppApp op' [x, y]) | isOp op' = f x y
143 convert (CppApp op' [x, y]) | isOp op' = f x y
145 convert (CppApp (CppApp op' [x]) [y]) | isOp op' = f x y
144 convert (CppApp (CppApp op' [x]) [y]) | isOp op' = f x y
146 convert other = other
145 convert other = other
147− isOp (CppAccessor (CppVar longForm) (CppVar m')) = m == m' && longForm == safeName op
146+ isOp (CppAccessor (CppVar longForm) (CppVar m')) =
147+ m == m' && (longForm == safeName op || longForm == ('*' `cons` safeName op))
148 isOp _ = False
148 isOp _ = False
150inlineCommonOperators :: Cpp -> Cpp
150inlineCommonOperators :: Cpp -> Cpp
@@ -203,6 +203,10 @@ inlineCommonOperators = applyAll $
203 , binary' C.dataIntBits C.shr ShiftRight
203 , binary' C.dataIntBits C.shr ShiftRight
204 -- , binary' C.dataIntBits C.zshr ZeroFillShiftRight
204 -- , binary' C.dataIntBits C.zshr ZeroFillShiftRight
205 , unary' C.dataIntBits C.complement BitwiseNot
205 , unary' C.dataIntBits C.complement BitwiseNot
207+ , inlineNonClassFunction (C.dataFunction, C.apply) $ \f x -> CppApp f [x]
208+ , inlineNonClassFunction (C.dataFunction, C.applyFlipped) $ \x f -> CppApp f [x]
209+ , inlineNonClassFunction (C.dataArray, C.unsafeIndex) $ flip CppIndexer
208 -- [ fn | i <- [0..10], fn <- [ mkFn i, runFn i ] ]
212 -- [ fn | i <- [0..10], fn <- [ mkFn i, runFn i ] ]
@@ -443,4 +447,4 @@ opDisj :: (Text, Text)
443opDisj = (C.dataHeytingAlgebra, C.disj)
447opDisj = (C.dataHeytingAlgebra, C.disj)
445opNot :: (Text, Text)
449opNot :: (Text, Text)
446−opNot = (C.dataHeytingAlgebra, C.not)
450+opNot = (C.dataHeytingAlgebra, safeName C.not)