git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
C++: clean up inliner (remove uncurried cases)
commit36a2ed7be7cb3703b8979373ae621fdf5ce5ea47 authorAndy Arvanitis <andyarvanitis@gmail.com> dateThu 16 Mar 2017, 17:09 (10 years ago) parentbf64471
2 files changed+1−22
src/Language/PureScript/CodeGen/Cpp/Optimizer/Inliner.hs+1−20 src/Language/PureScript/CodeGen/Cpp/Optimizer/MagicDo.hs−2
src/Language/PureScript/CodeGen/Cpp/Optimizer/Inliner.hs+1−20
@@ -115,11 +115,6 @@ inlineCommonValues = everywhereOnCpp convert
115115 | isDict boundedBoolean dict && isFn fnTop fn = CppBooleanLiteral True
116116 convert (CppApp (CppApp fn [dict]) [x])
117117 | isDict ringInt dict && isFn fnNegate fn = CppUnary Negate x
118− convert (CppApp fn [dict, x, y])
119− | isDict semiringInt dict && isFn fnAdd fn = CppBinary Add x y
120− | isDict semiringInt dict && isFn fnMultiply fn = CppBinary Multiply x y
121− | isDict euclideanRingInt dict && isFn fnDivide fn = CppBinary Divide x y
122− | isDict ringInt dict && isFn fnSubtract fn = CppBinary Subtract x y
123118 convert (CppApp (CppApp (CppApp fn [dict]) [x]) [y])
124119 | isDict semiringInt dict && isFn fnAdd fn = CppBinary Add x y
125120 | isDict semiringInt dict && isFn fnMultiply fn = CppBinary Multiply x y
@@ -140,7 +135,6 @@ inlineNonClassFunction :: (Text, Text) -> (Cpp -> Cpp -> Cpp) -> Cpp -> Cpp
140135inlineNonClassFunction (m, op) f = everywhereOnCpp convert
141136 where
142137 convert :: Cpp -> Cpp
143− convert (CppApp op' [x, y]) | isOp op' = f x y
144138 convert (CppApp (CppApp op' [x]) [y]) | isOp op' = f x y
145139 convert other = other
146140 isOp (CppAccessor (CppVar longForm) (CppVar m')) =
@@ -225,21 +219,18 @@ inlineCommonOperators = applyAll $
225219 binary dict fns op = everywhereOnCpp convert
226220 where
227221 convert :: Cpp -> Cpp
228− convert (CppApp fn [dict', x, y]) | isDict dict dict' && isFn fns fn = CppBinary op x y
229222 convert (CppApp (CppApp (CppApp fn [dict']) [x]) [y]) | isDict dict dict' && isFn fns fn = CppBinary op x y
230223 convert other = other
231224 binary' :: Text -> Text -> BinaryOperator -> Cpp -> Cpp
232225 binary' moduleName opString op = everywhereOnCpp convert
233226 where
234227 convert :: Cpp -> Cpp
235− convert (CppApp fn [x, y]) | isFn (moduleName, opString) fn = CppBinary op x y
236228 convert (CppApp (CppApp fn [x]) [y]) | isFn (moduleName, opString) fn = CppBinary op x y
237229 convert other = other
238230 unary :: (Text, Text) -> (Text, Text) -> UnaryOperator -> Cpp -> Cpp
239231 unary dicts fns op = everywhereOnCpp convert
240232 where
241233 convert :: Cpp -> Cpp
242− convert (CppApp fn [dict', x]) | isDict dicts dict' && isFn fns fn = CppUnary op x
243234 convert (CppApp (CppApp fn [dict']) [x]) | isDict dicts dict' && isFn fns fn = CppUnary op x
244235 convert other = other
245236 unary' :: Text -> Text -> UnaryOperator -> Cpp -> Cpp
@@ -289,19 +280,9 @@ inlineCommonOperators = applyAll $
289280inlineFnComposition :: forall m. MonadSupply m => Cpp -> m Cpp
290281inlineFnComposition = everywhereOnCppTopDownM convert where
291282 convert :: Cpp -> m Cpp
292− convert (CppApp fn [dict', x, y, z])
293− | isFnCompose dict' fn = return $ CppApp x [CppApp y [z]]
294− | isFnComposeFlipped dict' fn = return $ CppApp y [CppApp x [z]]
295− convert (CppApp (CppApp (CppApp (CppApp fn [dict']) [x]) [y]) [z])
283+ convert (CppApp (CppApp (CppApp (CppApp fn [dict']) [x]) [y]) [z])
296284 | isFnCompose dict' fn = return $ CppApp x [CppApp y [z]]
297285 | isFnComposeFlipped dict' fn = return $ CppApp y [CppApp x [z]]
298− convert (CppApp fn [dict', x, y])
299− | isFnCompose dict' fn = do
300− arg <- freshName
301− return $ CppLambda [CaptureAll] [(arg, constAnyRef)] Nothing (CppBlock [CppReturn $ CppApp x [CppApp y [CppVar arg]]])
302− | isFnComposeFlipped dict' fn = do
303− arg <- freshName
304− return $ CppLambda [CaptureAll] [(arg, constAnyRef)] Nothing (CppBlock [CppReturn $ CppApp y [CppApp x [CppVar arg]]])
305286 convert (CppApp (CppApp (CppApp fn [dict']) [x]) [y])
306287 | isFnCompose dict' fn = do
307288 arg <- freshName
src/Language/PureScript/CodeGen/Cpp/Optimizer/MagicDo.hs−2
@@ -70,8 +70,6 @@ magicDo' = everywhereOnCpp undo . everywhereOnCppTopDown convert
7070 convert (CppApp (CppApp f [arg]) []) | isEffFunc C.untilE f =
7171 CppApp (CppLambda [CaptureAll] [] Nothing (CppBlock [ CppWhile (CppUnary Not (CppApp arg [])) (CppBlock []), CppReturn $ CppVar "nullptr"])) []
7272 -- Desugar whileE
73− convert (CppApp (CppApp f [arg1, arg2]) []) | isEffFunc C.whileE f =
74− CppApp (CppLambda [CaptureAll] [] Nothing (CppBlock [ CppWhile (CppApp arg1 []) (CppBlock [ CppApp arg2 [] ]), CppReturn $ CppVar "nullptr"])) []
7573 convert (CppApp (CppApp (CppApp f [arg1]) [arg2]) []) | isEffFunc C.whileE f =
7674 CppApp (CppLambda [CaptureAll] [] Nothing (CppBlock [ CppWhile (CppApp arg1 []) (CppBlock [ CppApp arg2 [] ]), CppReturn $ CppVar "nullptr"])) []
7775 convert other = other