git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
C++: more inliner fixes
commit90ed9e4157d0109eb8e2d0d57645e15ac5b61306 authorAndy Arvanitis <andyarvanitis@gmail.com> dateMon 20 Feb 2017, 20:56 (10 years ago) parent46dddf5
5 files changed+22−22
src/Language/PureScript/CodeGen/Cpp.hs+7−16 src/Language/PureScript/CodeGen/Cpp/Common.hs+7 src/Language/PureScript/CodeGen/Cpp/Optimizer/Common.hs+3−2 src/Language/PureScript/CodeGen/Cpp/Optimizer/Inliner.hs+2−2 src/Language/PureScript/CodeGen/Cpp/Optimizer/MagicDo.hs+3−2
src/Language/PureScript/CodeGen/Cpp.hs+7−16
@@ -358,10 +358,10 @@ moduleToCpp otherOpts env (Module _ mn imps _ foreigns decls) = do
358358 valueToCpp (Var (_, _, _, Just IsNewtype) ident) = return $ varToCpp ident
359359 valueToCpp (Var (_, _, _, Just (IsConstructor _ [])) ident) = return $ CppApp (varToCpp ident) []
360360 valueToCpp (Var (_, _, Just ty, _) ident@(Qualified (Just _) _))
361− | arity ty > 0 = return . curriedName' $ varToCpp ident
361+ | arity ty > 0 = return . curriedVar $ varToCpp ident
362362 valueToCpp (Var (_, _, Nothing, _) ident@(Qualified (Just _) _))
363363 | Just (ty, _, _) <- M.lookup ident (E.names env)
364− , arity ty > 0 = return . curriedName' $ varToCpp ident
364+ , arity ty > 0 = return . curriedVar $ varToCpp ident
365365 valueToCpp (Var _ ident) = return $ varToCpp ident
366366 valueToCpp (Literal _ (NumericLiteral n)) = return (CppNumericLiteral n)
367367 valueToCpp (Literal _ (StringLiteral s)) = return (CppStringLiteral s)
@@ -410,7 +410,7 @@ moduleToCpp otherOpts env (Module _ mn imps _ foreigns decls) = do
410410 zip
411411 (CppSymbol . mkString <$> (sort $ superClassDictionaryNames constraints) ++ (fst <$> fns))
412412 args'
413− Var _ (Qualified (Just _) _) -> applied f args' curriedName'
413+ Var _ (Qualified (Just _) _) -> applied f args' curriedVar
414414 _ -> applied f args' id
415415 where
416416 applied f args g = flip (foldl (\fn a -> CppApp (g fn) [a])) args <$> valueToCpp f
@@ -745,20 +745,11 @@ optIndexers classes = everywhereOnCpp dictIndexerToEnum
745745 dictIndexerToEnum cpp = cpp
746746
747747---------------------------------------------------------------------------------------------------
748−curriedName :: Text -> Text
748+curriedVar :: Cpp -> Cpp
749749---------------------------------------------------------------------------------------------------
750−curriedName name
751− | Text.null name = name
752−curriedName name
753− | Text.head name == '*' = name
754− | otherwise = '*' `Text.cons` name
755−
756−---------------------------------------------------------------------------------------------------
757−curriedName' :: Cpp -> Cpp
758−---------------------------------------------------------------------------------------------------
759−curriedName' (CppVar name) = CppVar (curriedName name)
760−curriedName' (CppAccessor a b) = CppAccessor (curriedName' a) b
761−curriedName' cpp = cpp
750+curriedVar (CppVar name) = CppVar (curriedName name)
751+curriedVar (CppAccessor a b) = CppAccessor (curriedVar a) b
752+curriedVar cpp = cpp
762753
763754---------------------------------------------------------------------------------------------------
764755primFn :: T.Type -> ([CppType], Maybe CppType)
src/Language/PureScript/CodeGen/Cpp/Common.hs+7
@@ -267,3 +267,10 @@ properNameIsCppReserved name =
267267 , "PureScript"
268268 , "SYM"
269269 ]
270+
271+curriedName :: Text -> Text
272+curriedName name
273+ | T.null name = name
274+curriedName name
275+ | T.head name == '*' = name
276+ | otherwise = '*' `T.cons` name
src/Language/PureScript/CodeGen/Cpp/Optimizer/Common.hs+3−2
@@ -18,9 +18,10 @@ module Language.PureScript.CodeGen.Cpp.Optimizer.Common where
1818import Prelude.Compat
1919
2020import Data.Maybe (fromMaybe)
21−import Data.Text (Text, cons)
21+import Data.Text (Text)
2222
2323import Language.PureScript.CodeGen.Cpp.AST
24+import Language.PureScript.CodeGen.Cpp.Common
2425
2526applyAll :: [a -> a] -> a -> a
2627applyAll = foldl1 (.)
@@ -82,7 +83,7 @@ removeFromBlock _ cpp = cpp
8283
8384isFn :: (Text, Text) -> Cpp -> Bool
8485isFn (moduleName, fnName) (CppAccessor (CppVar x) (CppVar y)) =
85− (x == fnName || x == ('*' `cons` fnName)) && y == moduleName
86+ (x == fnName || x == curriedName fnName) && y == moduleName
8687isFn _ _ = False
8788
8889isDict :: (Text, Text) -> Cpp -> Bool
src/Language/PureScript/CodeGen/Cpp/Optimizer/Inliner.hs+2−2
@@ -28,7 +28,7 @@ module Language.PureScript.CodeGen.Cpp.Optimizer.Inliner
2828 ) where
2929
3030import Prelude.Compat
31−import Data.Text (Text, cons)
31+import Data.Text (Text)
3232
3333import Control.Monad.Supply.Class (MonadSupply, freshName)
3434
@@ -144,7 +144,7 @@ inlineNonClassFunction (m, op) f = everywhereOnCpp convert
144144 convert (CppApp (CppApp op' [x]) [y]) | isOp op' = f x y
145145 convert other = other
146146 isOp (CppAccessor (CppVar longForm) (CppVar m')) =
147− m == m' && (longForm == safeName op || longForm == ('*' `cons` safeName op))
147+ m == m' && (longForm == safeName op || longForm == (curriedName $ safeName op))
148148 isOp _ = False
149149
150150inlineCommonOperators :: Cpp -> Cpp
src/Language/PureScript/CodeGen/Cpp/Optimizer/MagicDo.hs+3−2
@@ -86,7 +86,8 @@ magicDo' = everywhereOnCpp undo . everywhereOnCppTopDown convert
8686 -- Check if an expression represents the polymorphic pure or return function
8787 isPurePoly = isFn (C.controlApplicative, C.pure')
8888 -- Check if an expression represents a function in the Eff module
89− isEffFunc name (CppAccessor (CppVar name') (CppVar eff)) = eff == C.eff && name == name'
89+ isEffFunc name (CppAccessor (CppVar name') (CppVar eff)) =
90+ eff == C.eff && (name == name' || curriedName name == name')
9091 isEffFunc _ _ = False
9192
9293 -- Remove __do function applications which remain after desugaring
@@ -131,7 +132,7 @@ inlineST = everywhereOnCpp convertBlock
131132 if agg then CppAssignment ref (CppApp func [ref]) else CppAssignment (CppAccessor (CppVar C.stRefValue) ref) (CppApp func [CppAccessor (CppVar C.stRefValue) ref])
132133 convert _ other = other
133134 -- Check if an expression represents a function in the ST module
134− isSTFunc name (CppAccessor (CppVar name') (CppVar st)) = st == C.st && name == name'
135+ isSTFunc name (CppAccessor (CppVar name') (CppVar st)) = st == C.st && (name == name' || curriedName name == name')
135136 isSTFunc _ _ = False
136137 -- Find all ST Refs initialized in this block
137138 findSTRefsIn = everythingOnCpp (++) isSTRef