git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge remote-tracking branch 'pure11/pure11' into native
commitd49ac41aa4fc4406fab78ff8653da2172beb5647 authorAndy Arvanitis <andyarvanitis@gmail.com> dateMon 6 Feb 2017, 15:34 (10 years ago) parent3e3783a838dc61
3 files changed+35−18
src/Language/PureScript/CodeGen/Cpp/Optimizer.hs+16−11 src/Language/PureScript/CodeGen/Cpp/Optimizer/Inliner.hs+4−2 src/Language/PureScript/CodeGen/Cpp/Recursion.hs+15−5
src/Language/PureScript/CodeGen/Cpp/Optimizer.hs+16−11
@@ -67,14 +67,26 @@ optimize nm cpp = do
6767optimize' :: (MonadReader Options m, MonadSupply m) => NamesMap -> Cpp -> m Cpp
6868optimize' nm cpp = do
6969 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
7185 [ collapseNestedBlocks
7286 , collapseCtorChecksToSwitch
7387 , collapseNestedIfs
7488 , collapseIfElses
7589 , removeCurrying nm
76− , tco opts
77− , magicDo opts
7890 , removeCodeAfterReturnStatements
7991 , removeCodeAfterContinueStatements
8092 , removeUnusedArg
@@ -82,14 +94,7 @@ optimize' nm cpp = do
8294 , etaConvert
8395 , evaluateIifes
8496 , inlineVariables
85− , inlineCommonValues
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
97+ ]
9398
9499untilFixedPoint :: (Monad m, Eq a) => (a -> m a) -> a -> m a
95100untilFixedPoint f = go
src/Language/PureScript/CodeGen/Cpp/Optimizer/Inliner.hs+4−2
@@ -108,8 +108,10 @@ inlineCommonValues = everywhereOnCpp convert
108108 where
109109 convert :: Cpp -> Cpp
110110 convert (CppApp fn [dict])
111− | isDict' [semiringNumber, semiringInt] dict && isFn fnZero fn = CppNumericLiteral (Left 0)
112− | isDict' [semiringNumber, semiringInt] dict && isFn fnOne fn = CppNumericLiteral (Left 1)
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)
114+ | isDict semiringNumber dict && isFn fnOne fn = CppNumericLiteral (Right 1.0)
113115 | isDict boundedBoolean dict && isFn fnBottom fn = CppBooleanLiteral False
114116 | isDict boundedBoolean dict && isFn fnTop fn = CppBooleanLiteral True
115117 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
1818
1919import Prelude.Compat
2020import Data.List
21−import Data.Maybe (fromJust)
21+import Data.Maybe (catMaybes, fromJust)
2222import Data.Monoid ((<>))
2323import Data.Text (Text)
2424
@@ -68,7 +68,10 @@ convertRecursiveLets = everywhereOnCpp go
6868convertRecursive :: [Text] -> [Cpp] -> [Cpp]
6969-------------------------------------------------------------------------------------------------
7070convertRecursive names cpps
71− | (_:_) <- lets = (everywhereOnCppTopDown remRecLet <$> cpps) ++ undefines
71+ | (_:_) <- lets
72+ = let recLets = everywhereOnCppTopDown convRecLet <$> cpps
73+ letDeps = catMaybes (letDep <$> cpps)
74+ in nub (letDeps ++ recLets) ++ undefines
7275 where
7376 tableName :: Text
7477 tableName = "let"
@@ -88,12 +91,19 @@ convertRecursive names cpps
8891 | name `elem` names = [cpp]
8992 recLet _ = []
9093 --
91− remRecLet :: Cpp -> Cpp
92− remRecLet cpp@(CppVariableIntroduction (name, _) _ (Just _))
94+ convRecLet :: Cpp -> Cpp
95+ convRecLet cpp@(CppVariableIntroduction (name, _) _ (Just _))
9396 | name == head names = CppNamespace "" $ defines ++ [letTable]
9497 | name `elem` names = CppNoOp
9598 | 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
97107 --
98108 tableItem :: Cpp -> (Text, Cpp)
99109 tableItem (CppVariableIntroduction (name, _) _ (Just body)) =