@@ -115,11 +115,6 @@ inlineCommonValues = everywhereOnCpp convert
115 | isDict boundedBoolean dict && isFn fnTop fn = CppBooleanLiteral True
115 | isDict boundedBoolean dict && isFn fnTop fn = CppBooleanLiteral True
116 convert (CppApp (CppApp fn [dict]) [x])
116 convert (CppApp (CppApp fn [dict]) [x])
117 | isDict ringInt dict && isFn fnNegate fn = CppUnary Negate x
117 | 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
123 convert (CppApp (CppApp (CppApp fn [dict]) [x]) [y])
118 convert (CppApp (CppApp (CppApp fn [dict]) [x]) [y])
124 | isDict semiringInt dict && isFn fnAdd fn = CppBinary Add x y
119 | isDict semiringInt dict && isFn fnAdd fn = CppBinary Add x y
125 | isDict semiringInt dict && isFn fnMultiply fn = CppBinary Multiply x y
120 | isDict semiringInt dict && isFn fnMultiply fn = CppBinary Multiply x y
@@ -140,7 +135,6 @@ inlineNonClassFunction :: (Text, Text) -> (Cpp -> Cpp -> Cpp) -> Cpp -> Cpp
140inlineNonClassFunction (m, op) f = everywhereOnCpp convert
135inlineNonClassFunction (m, op) f = everywhereOnCpp convert
142 convert :: Cpp -> Cpp
137 convert :: Cpp -> Cpp
143− convert (CppApp op' [x, y]) | isOp op' = f x y
144 convert (CppApp (CppApp op' [x]) [y]) | isOp op' = f x y
138 convert (CppApp (CppApp op' [x]) [y]) | isOp op' = f x y
145 convert other = other
139 convert other = other
146 isOp (CppAccessor (CppVar longForm) (CppVar m')) =
140 isOp (CppAccessor (CppVar longForm) (CppVar m')) =
@@ -225,21 +219,18 @@ inlineCommonOperators = applyAll $
225 binary dict fns op = everywhereOnCpp convert
219 binary dict fns op = everywhereOnCpp convert
227 convert :: Cpp -> Cpp
221 convert :: Cpp -> Cpp
228− convert (CppApp fn [dict', x, y]) | isDict dict dict' && isFn fns fn = CppBinary op x y
229 convert (CppApp (CppApp (CppApp fn [dict']) [x]) [y]) | isDict dict dict' && isFn fns fn = CppBinary op x y
222 convert (CppApp (CppApp (CppApp fn [dict']) [x]) [y]) | isDict dict dict' && isFn fns fn = CppBinary op x y
230 convert other = other
223 convert other = other
231 binary' :: Text -> Text -> BinaryOperator -> Cpp -> Cpp
224 binary' :: Text -> Text -> BinaryOperator -> Cpp -> Cpp
232 binary' moduleName opString op = everywhereOnCpp convert
225 binary' moduleName opString op = everywhereOnCpp convert
234 convert :: Cpp -> Cpp
227 convert :: Cpp -> Cpp
235− convert (CppApp fn [x, y]) | isFn (moduleName, opString) fn = CppBinary op x y
236 convert (CppApp (CppApp fn [x]) [y]) | isFn (moduleName, opString) fn = CppBinary op x y
228 convert (CppApp (CppApp fn [x]) [y]) | isFn (moduleName, opString) fn = CppBinary op x y
237 convert other = other
229 convert other = other
238 unary :: (Text, Text) -> (Text, Text) -> UnaryOperator -> Cpp -> Cpp
230 unary :: (Text, Text) -> (Text, Text) -> UnaryOperator -> Cpp -> Cpp
239 unary dicts fns op = everywhereOnCpp convert
231 unary dicts fns op = everywhereOnCpp convert
241 convert :: Cpp -> Cpp
233 convert :: Cpp -> Cpp
242− convert (CppApp fn [dict', x]) | isDict dicts dict' && isFn fns fn = CppUnary op x
243 convert (CppApp (CppApp fn [dict']) [x]) | isDict dicts dict' && isFn fns fn = CppUnary op x
234 convert (CppApp (CppApp fn [dict']) [x]) | isDict dicts dict' && isFn fns fn = CppUnary op x
244 convert other = other
235 convert other = other
245 unary' :: Text -> Text -> UnaryOperator -> Cpp -> Cpp
236 unary' :: Text -> Text -> UnaryOperator -> Cpp -> Cpp
@@ -289,19 +280,9 @@ inlineCommonOperators = applyAll $
289inlineFnComposition :: forall m. MonadSupply m => Cpp -> m Cpp
280inlineFnComposition :: forall m. MonadSupply m => Cpp -> m Cpp
290inlineFnComposition = everywhereOnCppTopDownM convert where
281inlineFnComposition = everywhereOnCppTopDownM convert where
291 convert :: Cpp -> m Cpp
282 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])
296 | isFnCompose dict' fn = return $ CppApp x [CppApp y [z]]
284 | isFnCompose dict' fn = return $ CppApp x [CppApp y [z]]
297 | isFnComposeFlipped dict' fn = return $ CppApp y [CppApp x [z]]
285 | isFnComposeFlipped dict' fn = return $ CppApp y [CppApp x [z]]
298− convert (CppApp fn [dict', x, y])
299− | isFnCompose dict' fn = do
301− return $ CppLambda [CaptureAll] [(arg, constAnyRef)] Nothing (CppBlock [CppReturn $ CppApp x [CppApp y [CppVar arg]]])
302− | isFnComposeFlipped dict' fn = do
304− return $ CppLambda [CaptureAll] [(arg, constAnyRef)] Nothing (CppBlock [CppReturn $ CppApp y [CppApp x [CppVar arg]]])
305 convert (CppApp (CppApp (CppApp fn [dict']) [x]) [y])
286 convert (CppApp (CppApp (CppApp fn [dict']) [x]) [y])
306 | isFnCompose dict' fn = do
287 | isFnCompose dict' fn = do
307 arg <- freshName
288 arg <- freshName