git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge remote-tracking branch 'pure11/pure11' into native
commit43c8b4798e1d56ac6d187be845c71b43aa903e9b authorAndy Arvanitis <andyarvanitis@gmail.com> dateFri 17 Feb 2017, 19:55 (10 years ago) parent4d18945b85a92f
3 files changed+13−16
src/Language/PureScript/CodeGen/Cpp/Optimizer.hs+2−9 src/Language/PureScript/CodeGen/Cpp/Optimizer/Inliner.hs+10−6 src/Language/PureScript/Pretty/Cpp.hs+1−1
src/Language/PureScript/CodeGen/Cpp/Optimizer.hs+2−9
@@ -40,13 +40,11 @@ module Language.PureScript.CodeGen.Cpp.Optimizer (
4040
4141import Prelude.Compat
4242
43−import Control.Monad (liftM)
4443import Control.Monad.Reader (MonadReader, ask, asks)
4544import Control.Monad.Supply.Class (MonadSupply)
4645
4746import Language.PureScript.CodeGen.Cpp.AST
4847import Language.PureScript.Options
49−import qualified Language.PureScript.Constants as C
5048
5149import Language.PureScript.CodeGen.Cpp.Optimizer.Blocks
5250import Language.PureScript.CodeGen.Cpp.Optimizer.Common
@@ -67,18 +65,14 @@ optimize nm cpp = do
6765optimize' :: (MonadReader Options m, MonadSupply m) => NamesMap -> Cpp -> m Cpp
6866optimize' nm cpp = do
6967 opts <- ask
70− cpp' <- untilFixedPoint (liftM toAutoVars .
71− inlineFnComposition .
68+ cpp' <- untilFixedPoint (inlineFnComposition .
7269 inlineUnsafePartial .
7370 tidyUp .
7471 applyAll
7572 [ inlineCommonValues
7673 , inlineCommonOperators
77− , inlineOperator (C.dataFunction, C.apply) $ \f x -> CppApp f [x]
78− , inlineOperator (C.dataFunction, C.applyFlipped) $ \x f -> CppApp f [x]
79− , inlineOperator (C.dataArray, C.unsafeIndex) $ flip CppIndexer
8074 ]) cpp
81− untilFixedPoint (return . tidyUp) . tco opts . magicDo opts $ cpp'
75+ untilFixedPoint (return . removeCurrying nm) . toAutoVars . tidyUp . tco opts . magicDo opts $ cpp'
8276 where
8377 tidyUp :: Cpp -> Cpp
8478 tidyUp = applyAll
@@ -86,7 +80,6 @@ optimize' nm cpp = do
8680 , collapseCtorChecksToSwitch
8781 , collapseNestedIfs
8882 , collapseIfElses
89− , removeCurrying nm
9083 , removeCodeAfterReturnStatements
9184 , removeCodeAfterContinueStatements
9285 , removeUnusedArg
src/Language/PureScript/CodeGen/Cpp/Optimizer/Inliner.hs+10−6
@@ -18,7 +18,6 @@
1818module Language.PureScript.CodeGen.Cpp.Optimizer.Inliner
1919 ( inlineVariables
2020 , inlineCommonValues
21− , inlineOperator
2221 , inlineCommonOperators
2322 , inlineFnComposition
2423 , inlineUnsafePartial
@@ -29,7 +28,7 @@ module Language.PureScript.CodeGen.Cpp.Optimizer.Inliner
2928 ) where
3029
3130import Prelude.Compat
32−import Data.Text (Text)
31+import Data.Text (Text, cons)
3332
3433import Control.Monad.Supply.Class (MonadSupply, freshName)
3534
@@ -137,14 +136,15 @@ inlineCommonValues = everywhereOnCpp convert
137136 fnSubtract = (C.dataRing, C.sub)
138137 fnNegate = (C.dataRing, C.negate)
139138
140−inlineOperator :: (Text, Text) -> (Cpp -> Cpp -> Cpp) -> Cpp -> Cpp
141−inlineOperator (m, op) f = everywhereOnCpp convert
139+inlineNonClassFunction :: (Text, Text) -> (Cpp -> Cpp -> Cpp) -> Cpp -> Cpp
140+inlineNonClassFunction (m, op) f = everywhereOnCpp convert
142141 where
143142 convert :: Cpp -> Cpp
144143 convert (CppApp op' [x, y]) | isOp op' = f x y
145144 convert (CppApp (CppApp op' [x]) [y]) | isOp op' = f x y
146145 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))
148148 isOp _ = False
149149
150150inlineCommonOperators :: Cpp -> Cpp
@@ -203,6 +203,10 @@ inlineCommonOperators = applyAll $
203203 , binary' C.dataIntBits C.shr ShiftRight
204204 -- , binary' C.dataIntBits C.zshr ZeroFillShiftRight
205205 , unary' C.dataIntBits C.complement BitwiseNot
206+
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
206210 ] ++
207211 []
208212 -- [ fn | i <- [0..10], fn <- [ mkFn i, runFn i ] ]
@@ -443,4 +447,4 @@ opDisj :: (Text, Text)
443447opDisj = (C.dataHeytingAlgebra, C.disj)
444448
445449opNot :: (Text, Text)
446−opNot = (C.dataHeytingAlgebra, C.not)
450+opNot = (C.dataHeytingAlgebra, safeName C.not)
src/Language/PureScript/Pretty/Cpp.hs+1−1
@@ -501,7 +501,7 @@ binary op str = AssocL match (\v1 v2 -> v1 <> str <> v2)
501501 match = mkPattern match'
502502 where
503503 match' (CppBinary op' v1@(CppStringLiteral _) v2@(CppStringLiteral _))
504− | op' == op = Just (CppApp (CppVar "std::string") [v1], v2)
504+ | op' == op = Just (CppApp (CppVar $ runType stringType) [v1], v2)
505505 match' (CppBinary op' v1 v2)
506506 | op' == op = Just (v1, v2)
507507 match' _ = Nothing