git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
C++: more inliner fixes
90ed9e4Andy Arvanitis
src/Language/PureScript/CodeGen/Cpp.hs+7−16
@@ -358,10 +358,10 @@ moduleToCpp otherOpts env (Module _ mn imps _ foreigns decls) = do
358 valueToCpp (Var (_, _, _, Just IsNewtype) ident) = return $ varToCpp ident
358 valueToCpp (Var (_, _, _, Just IsNewtype) ident) = return $ varToCpp ident
359 valueToCpp (Var (_, _, _, Just (IsConstructor _ [])) ident) = return $ CppApp (varToCpp ident) []
359 valueToCpp (Var (_, _, _, Just (IsConstructor _ [])) ident) = return $ CppApp (varToCpp ident) []
360 valueToCpp (Var (_, _, Just ty, _) ident@(Qualified (Just _) _))
360 valueToCpp (Var (_, _, Just ty, _) ident@(Qualified (Just _) _))
361− | arity ty > 0 = return . curriedName' $ varToCpp ident
361+ | arity ty > 0 = return . curriedVar $ varToCpp ident
362 valueToCpp (Var (_, _, Nothing, _) ident@(Qualified (Just _) _))
362 valueToCpp (Var (_, _, Nothing, _) ident@(Qualified (Just _) _))
363 | Just (ty, _, _) <- M.lookup ident (E.names env)
363 | Just (ty, _, _) <- M.lookup ident (E.names env)
364− , arity ty > 0 = return . curriedName' $ varToCpp ident
364+ , arity ty > 0 = return . curriedVar $ varToCpp ident
365 valueToCpp (Var _ ident) = return $ varToCpp ident
365 valueToCpp (Var _ ident) = return $ varToCpp ident
366 valueToCpp (Literal _ (NumericLiteral n)) = return (CppNumericLiteral n)
366 valueToCpp (Literal _ (NumericLiteral n)) = return (CppNumericLiteral n)
367 valueToCpp (Literal _ (StringLiteral s)) = return (CppStringLiteral s)
367 valueToCpp (Literal _ (StringLiteral s)) = return (CppStringLiteral s)
@@ -410,7 +410,7 @@ moduleToCpp otherOpts env (Module _ mn imps _ foreigns decls) = do
410 zip
410 zip
411 (CppSymbol . mkString <$> (sort $ superClassDictionaryNames constraints) ++ (fst <$> fns))
411 (CppSymbol . mkString <$> (sort $ superClassDictionaryNames constraints) ++ (fst <$> fns))
412 args'
412 args'
413− Var _ (Qualified (Just _) _) -> applied f args' curriedName'
413+ Var _ (Qualified (Just _) _) -> applied f args' curriedVar
414 _ -> applied f args' id
414 _ -> applied f args' id
415 where
415 where
416 applied f args g = flip (foldl (\fn a -> CppApp (g fn) [a])) args <$> valueToCpp f
416 applied f args g = flip (foldl (\fn a -> CppApp (g fn) [a])) args <$> valueToCpp f
@@ -745,20 +745,11 @@ optIndexers classes = everywhereOnCpp dictIndexerToEnum
745 dictIndexerToEnum cpp = cpp
745 dictIndexerToEnum cpp = cpp
746
746
747---------------------------------------------------------------------------------------------------
747---------------------------------------------------------------------------------------------------
748−curriedName :: Text -> Text
748+curriedVar :: Cpp -> Cpp
749---------------------------------------------------------------------------------------------------
749---------------------------------------------------------------------------------------------------
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)
750+curriedVar (CppVar name) = CppVar (curriedName name)
760−curriedName' (CppAccessor a b) = CppAccessor (curriedName' a) b
751+curriedVar (CppAccessor a b) = CppAccessor (curriedVar a) b
761−curriedName' cpp = cpp
752+curriedVar cpp = cpp
762
753
763---------------------------------------------------------------------------------------------------
754---------------------------------------------------------------------------------------------------
764primFn :: T.Type -> ([CppType], Maybe CppType)
755primFn :: T.Type -> ([CppType], Maybe CppType)
src/Language/PureScript/CodeGen/Cpp/Common.hs+7
@@ -267,3 +267,10 @@ properNameIsCppReserved name =
267 , "PureScript"
267 , "PureScript"
268 , "SYM"
268 , "SYM"
269 ]
269 ]
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
18import Prelude.Compat
18import Prelude.Compat
19
19
20import Data.Maybe (fromMaybe)
20import Data.Maybe (fromMaybe)
21−import Data.Text (Text, cons)
21+import Data.Text (Text)
22
22
23import Language.PureScript.CodeGen.Cpp.AST
23import Language.PureScript.CodeGen.Cpp.AST
24+import Language.PureScript.CodeGen.Cpp.Common
24
25
25applyAll :: [a -> a] -> a -> a
26applyAll :: [a -> a] -> a -> a
26applyAll = foldl1 (.)
27applyAll = foldl1 (.)
@@ -82,7 +83,7 @@ removeFromBlock _ cpp = cpp
82
83
83isFn :: (Text, Text) -> Cpp -> Bool
84isFn :: (Text, Text) -> Cpp -> Bool
84isFn (moduleName, fnName) (CppAccessor (CppVar x) (CppVar y)) =
85isFn (moduleName, fnName) (CppAccessor (CppVar x) (CppVar y)) =
85− (x == fnName || x == ('*' `cons` fnName)) && y == moduleName
86+ (x == fnName || x == curriedName fnName) && y == moduleName
86isFn _ _ = False
87isFn _ _ = False
87
88
88isDict :: (Text, Text) -> Cpp -> Bool
89isDict :: (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
28 ) where
28 ) where
29
29
30import Prelude.Compat
30import Prelude.Compat
31−import Data.Text (Text, cons)
31+import Data.Text (Text)
32
32
33import Control.Monad.Supply.Class (MonadSupply, freshName)
33import Control.Monad.Supply.Class (MonadSupply, freshName)
34
34
@@ -144,7 +144,7 @@ inlineNonClassFunction (m, op) f = everywhereOnCpp convert
144 convert (CppApp (CppApp op' [x]) [y]) | isOp op' = f x y
144 convert (CppApp (CppApp op' [x]) [y]) | isOp op' = f x y
145 convert other = other
145 convert other = other
146 isOp (CppAccessor (CppVar longForm) (CppVar m')) =
146 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))
148 isOp _ = False
148 isOp _ = False
149
149
150inlineCommonOperators :: Cpp -> Cpp
150inlineCommonOperators :: Cpp -> Cpp
src/Language/PureScript/CodeGen/Cpp/Optimizer/MagicDo.hs+3−2
@@ -86,7 +86,8 @@ magicDo' = everywhereOnCpp undo . everywhereOnCppTopDown convert
86 -- Check if an expression represents the polymorphic pure or return function
86 -- Check if an expression represents the polymorphic pure or return function
87 isPurePoly = isFn (C.controlApplicative, C.pure')
87 isPurePoly = isFn (C.controlApplicative, C.pure')
88 -- Check if an expression represents a function in the Eff module
88 -- 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')
90 isEffFunc _ _ = False
91 isEffFunc _ _ = False
91
92
92 -- Remove __do function applications which remain after desugaring
93 -- Remove __do function applications which remain after desugaring
@@ -131,7 +132,7 @@ inlineST = everywhereOnCpp convertBlock
131 if agg then CppAssignment ref (CppApp func [ref]) else CppAssignment (CppAccessor (CppVar C.stRefValue) ref) (CppApp func [CppAccessor (CppVar C.stRefValue) ref])
132 if agg then CppAssignment ref (CppApp func [ref]) else CppAssignment (CppAccessor (CppVar C.stRefValue) ref) (CppApp func [CppAccessor (CppVar C.stRefValue) ref])
132 convert _ other = other
133 convert _ other = other
133 -- Check if an expression represents a function in the ST module
134 -- 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')
135 isSTFunc _ _ = False
136 isSTFunc _ _ = False
136 -- Find all ST Refs initialized in this block
137 -- Find all ST Refs initialized in this block
137 findSTRefsIn = everythingOnCpp (++) isSTRef
138 findSTRefsIn = everythingOnCpp (++) isSTRef