git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge remote-tracking branch 'pure11/pure11' into native
43c8b47Andy Arvanitis
src/Language/PureScript/CodeGen/Cpp/Optimizer.hs+2−9
@@ -40,13 +40,11 @@ module Language.PureScript.CodeGen.Cpp.Optimizer (
40
40
41import Prelude.Compat
41import Prelude.Compat
42
42
43−import Control.Monad (liftM)
44import Control.Monad.Reader (MonadReader, ask, asks)
43import Control.Monad.Reader (MonadReader, ask, asks)
45import Control.Monad.Supply.Class (MonadSupply)
44import Control.Monad.Supply.Class (MonadSupply)
46
45
47import Language.PureScript.CodeGen.Cpp.AST
46import Language.PureScript.CodeGen.Cpp.AST
48import Language.PureScript.Options
47import Language.PureScript.Options
49−import qualified Language.PureScript.Constants as C
50
48
51import Language.PureScript.CodeGen.Cpp.Optimizer.Blocks
49import Language.PureScript.CodeGen.Cpp.Optimizer.Blocks
52import Language.PureScript.CodeGen.Cpp.Optimizer.Common
50import Language.PureScript.CodeGen.Cpp.Optimizer.Common
@@ -67,18 +65,14 @@ optimize nm cpp = do
67optimize' :: (MonadReader Options m, MonadSupply m) => NamesMap -> Cpp -> m Cpp
65optimize' :: (MonadReader Options m, MonadSupply m) => NamesMap -> Cpp -> m Cpp
68optimize' nm cpp = do
66optimize' nm cpp = do
69 opts <- ask
67 opts <- ask
70− cpp' <- untilFixedPoint (liftM toAutoVars .
71− inlineFnComposition .
68+ cpp' <- untilFixedPoint (inlineFnComposition .
72 inlineUnsafePartial .
69 inlineUnsafePartial .
73 tidyUp .
70 tidyUp .
74 applyAll
71 applyAll
75 [ inlineCommonValues
72 [ inlineCommonValues
76 , inlineCommonOperators
73 , 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
80 ]) cpp
74 ]) cpp
81− untilFixedPoint (return . tidyUp) . tco opts . magicDo opts $ cpp'
75+ untilFixedPoint (return . removeCurrying nm) . toAutoVars . tidyUp . tco opts . magicDo opts $ cpp'
82 where
76 where
83 tidyUp :: Cpp -> Cpp
77 tidyUp :: Cpp -> Cpp
84 tidyUp = applyAll
78 tidyUp = applyAll
@@ -86,7 +80,6 @@ optimize' nm cpp = do
86 , collapseCtorChecksToSwitch
80 , collapseCtorChecksToSwitch
87 , collapseNestedIfs
81 , collapseNestedIfs
88 , collapseIfElses
82 , collapseIfElses
89− , removeCurrying nm
90 , removeCodeAfterReturnStatements
83 , removeCodeAfterReturnStatements
91 , removeCodeAfterContinueStatements
84 , removeCodeAfterContinueStatements
92 , removeUnusedArg
85 , removeUnusedArg
src/Language/PureScript/CodeGen/Cpp/Optimizer/Inliner.hs+10−6
@@ -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
21− , inlineOperator
22 , inlineCommonOperators
21 , inlineCommonOperators
23 , inlineFnComposition
22 , inlineFnComposition
24 , inlineUnsafePartial
23 , inlineUnsafePartial
@@ -29,7 +28,7 @@ module Language.PureScript.CodeGen.Cpp.Optimizer.Inliner
29 ) where
28 ) where
30
29
31import Prelude.Compat
30import Prelude.Compat
32−import Data.Text (Text)
31+import Data.Text (Text, cons)
33
32
34import Control.Monad.Supply.Class (MonadSupply, freshName)
33import Control.Monad.Supply.Class (MonadSupply, freshName)
35
34
@@ -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)
139
138
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
142 where
141 where
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
149
149
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
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
206 ] ++
210 ] ++
207 []
211 []
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)
444
448
445opNot :: (Text, Text)
449opNot :: (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)
501 match = mkPattern match'
501 match = mkPattern match'
502 where
502 where
503 match' (CppBinary op' v1@(CppStringLiteral _) v2@(CppStringLiteral _))
503 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)
505 match' (CppBinary op' v1 v2)
505 match' (CppBinary op' v1 v2)
506 | op' == op = Just (v1, v2)
506 | op' == op = Just (v1, v2)
507 match' _ = Nothing
507 match' _ = Nothing