git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge remote-tracking branch 'pure11/pure11' into native
d49ac41Andy Arvanitis
src/Language/PureScript/CodeGen/Cpp/Optimizer.hs+16−11
@@ -67,14 +67,26 @@ optimize nm cpp = do
67optimize' :: (MonadReader Options m, MonadSupply m) => NamesMap -> Cpp -> m Cpp
67optimize' :: (MonadReader Options m, MonadSupply m) => NamesMap -> Cpp -> m Cpp
68optimize' nm cpp = do
68optimize' nm cpp = do
69 opts <- ask
69 opts <- ask
70− untilFixedPoint (liftM toAutoVars . inlineFnComposition . inlineUnsafePartial . applyAll
70+ cpp' <- untilFixedPoint (liftM toAutoVars .
71+ inlineFnComposition .
72+ inlineUnsafePartial .
73+ tidyUp .
74+ applyAll
75+ [ inlineCommonValues
76+ , 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
81+ untilFixedPoint (return . tidyUp) . tco opts . magicDo opts $ cpp'
82+ where
83+ tidyUp :: Cpp -> Cpp
84+ tidyUp = applyAll
71 [ collapseNestedBlocks
85 [ collapseNestedBlocks
72 , collapseCtorChecksToSwitch
86 , collapseCtorChecksToSwitch
73 , collapseNestedIfs
87 , collapseNestedIfs
74 , collapseIfElses
88 , collapseIfElses
75 , removeCurrying nm
89 , removeCurrying nm
76− , tco opts
77− , magicDo opts
78 , removeCodeAfterReturnStatements
90 , removeCodeAfterReturnStatements
79 , removeCodeAfterContinueStatements
91 , removeCodeAfterContinueStatements
80 , removeUnusedArg
92 , removeUnusedArg
@@ -82,14 +94,7 @@ optimize' nm cpp = do
82 , etaConvert
94 , etaConvert
83 , evaluateIifes
95 , evaluateIifes
84 , inlineVariables
96 , inlineVariables
85− , inlineCommonValues
97+ ]
86− , inlineOperator (C.prelude, (C.$)) $ \f x -> CppApp f [x]
87− , inlineOperator (C.dataFunction, C.apply) $ \f x -> CppApp f [x]
88− , inlineOperator (C.prelude, (C.#)) $ \x f -> CppApp f [x]
89− , inlineOperator (C.dataFunction, C.applyFlipped) $ \x f -> CppApp f [x]
90− , inlineOperator (C.dataArray, C.unsafeIndex) $ flip CppIndexer
91− , inlineCommonOperators
92− ]) cpp
93
98
94untilFixedPoint :: (Monad m, Eq a) => (a -> m a) -> a -> m a
99untilFixedPoint :: (Monad m, Eq a) => (a -> m a) -> a -> m a
95untilFixedPoint f = go
100untilFixedPoint f = go
src/Language/PureScript/CodeGen/Cpp/Optimizer/Inliner.hs+4−2
@@ -108,8 +108,10 @@ inlineCommonValues = everywhereOnCpp convert
108 where
108 where
109 convert :: Cpp -> Cpp
109 convert :: Cpp -> Cpp
110 convert (CppApp fn [dict])
110 convert (CppApp fn [dict])
111− | isDict' [semiringNumber, semiringInt] dict && isFn fnZero fn = CppNumericLiteral (Left 0)
111+ | isDict semiringInt dict && isFn fnZero fn = CppNumericLiteral (Left 0)
112+ | isDict semiringInt dict && isFn fnOne fn = CppNumericLiteral (Left 1)
113+ | isDict semiringNumber dict && isFn fnZero fn = CppNumericLiteral (Right 0.0)
112− | isDict' [semiringNumber, semiringInt] dict && isFn fnOne fn = CppNumericLiteral (Left 1)
114+ | isDict semiringNumber dict && isFn fnOne fn = CppNumericLiteral (Right 1.0)
113 | isDict boundedBoolean dict && isFn fnBottom fn = CppBooleanLiteral False
115 | isDict boundedBoolean dict && isFn fnBottom fn = CppBooleanLiteral False
114 | isDict boundedBoolean dict && isFn fnTop fn = CppBooleanLiteral True
116 | isDict boundedBoolean dict && isFn fnTop fn = CppBooleanLiteral True
115 convert (CppApp (CppApp fn [dict]) [x])
117 convert (CppApp (CppApp fn [dict]) [x])
src/Language/PureScript/CodeGen/Cpp/Recursion.hs+15−5
@@ -18,7 +18,7 @@ module Language.PureScript.CodeGen.Cpp.Recursion
18
18
19import Prelude.Compat
19import Prelude.Compat
20import Data.List
20import Data.List
21−import Data.Maybe (fromJust)
21+import Data.Maybe (catMaybes, fromJust)
22import Data.Monoid ((<>))
22import Data.Monoid ((<>))
23import Data.Text (Text)
23import Data.Text (Text)
24
24
@@ -68,7 +68,10 @@ convertRecursiveLets = everywhereOnCpp go
68convertRecursive :: [Text] -> [Cpp] -> [Cpp]
68convertRecursive :: [Text] -> [Cpp] -> [Cpp]
69-------------------------------------------------------------------------------------------------
69-------------------------------------------------------------------------------------------------
70convertRecursive names cpps
70convertRecursive names cpps
71+ | (_:_) <- lets
71− | (_:_) <- lets = (everywhereOnCppTopDown remRecLet <$> cpps) ++ undefines
72+ = let recLets = everywhereOnCppTopDown convRecLet <$> cpps
73+ letDeps = catMaybes (letDep <$> cpps)
74+ in nub (letDeps ++ recLets) ++ undefines
72 where
75 where
73 tableName :: Text
76 tableName :: Text
74 tableName = "let"
77 tableName = "let"
@@ -88,12 +91,19 @@ convertRecursive names cpps
88 | name `elem` names = [cpp]
91 | name `elem` names = [cpp]
89 recLet _ = []
92 recLet _ = []
90 --
93 --
91− remRecLet :: Cpp -> Cpp
94+ convRecLet :: Cpp -> Cpp
92− remRecLet cpp@(CppVariableIntroduction (name, _) _ (Just _))
95+ convRecLet cpp@(CppVariableIntroduction (name, _) _ (Just _))
93 | name == head names = CppNamespace "" $ defines ++ [letTable]
96 | name == head names = CppNamespace "" $ defines ++ [letTable]
94 | name `elem` names = CppNoOp
97 | name `elem` names = CppNoOp
95 | otherwise = cpp
98 | otherwise = cpp
96− remRecLet cpp = cpp
99+ convRecLet cpp = cpp
100+ --
101+ letDep :: Cpp -> Maybe Cpp
102+ letDep cpp@(CppVariableIntroduction (name, _) _ (Just _))
103+ | name `elem` names = Nothing
104+ | everythingOnCpp (||) (\v -> v == CppVar name) letTable = Just cpp
105+ | otherwise = Nothing
106+ letDep _ = Nothing
97 --
107 --
98 tableItem :: Cpp -> (Text, Cpp)
108 tableItem :: Cpp -> (Text, Cpp)
99 tableItem (CppVariableIntroduction (name, _) _ (Just body)) =
109 tableItem (CppVariableIntroduction (name, _) _ (Just body)) =