@@ -99,15 +99,6 @@ inlineCommonValues = everywhereOnJS convert
99 fnSubtract = (C.dataRing, C.sub)
99 fnSubtract = (C.dataRing, C.sub)
100 intOp ss op x y = JSBinary ss BitwiseOr (JSBinary ss op x y) (JSNumericLiteral ss (Left 0))
100 intOp ss op x y = JSBinary ss BitwiseOr (JSBinary ss op x y) (JSNumericLiteral ss (Left 0))
102−inlineNonClassFunction :: (String, String) -> (JS -> JS -> JS) -> JS -> JS
103−inlineNonClassFunction (m, op) f = everywhereOnJS convert
106− convert (JSApp _ (JSApp _ op' [x]) [y]) | isOp op' = f x y
107− convert other = other
108− isOp (JSAccessor _ op' (JSVar _ m')) = m == m' && op == op'
111inlineCommonOperators :: JS -> JS
102inlineCommonOperators :: JS -> JS
112inlineCommonOperators = applyAll $
103inlineCommonOperators = applyAll $
113 [ binary semiringNumber opAdd Add
104 [ binary semiringNumber opAdd Add
@@ -167,9 +158,9 @@ inlineCommonOperators = applyAll $
167 , binary' C.dataIntBits C.zshr ZeroFillShiftRight
158 , binary' C.dataIntBits C.zshr ZeroFillShiftRight
168 , unary' C.dataIntBits C.complement BitwiseNot
159 , unary' C.dataIntBits C.complement BitwiseNot
170− , inlineNonClassFunction (C.dataFunction, C.apply) $ \f x -> JSApp Nothing f [x]
161+ , inlineNonClassFunction (isModFn (C.dataFunction, C.apply)) $ \f x -> JSApp Nothing f [x]
171− , inlineNonClassFunction (C.dataFunction, C.applyFlipped) $ \x f -> JSApp Nothing f [x]
162+ , inlineNonClassFunction (isModFn (C.dataFunction, C.applyFlipped)) $ \x f -> JSApp Nothing f [x]
172− , inlineNonClassFunction (C.dataArray, C.unsafeIndex) $ flip (JSIndexer Nothing)
163+ , inlineNonClassFunction (isModFnWithDict (C.dataArray, C.unsafeIndex)) $ flip (JSIndexer Nothing)
174 [ fn | i <- [0..10], fn <- [ mkFn i, runFn i ] ]
165 [ fn | i <- [0..10], fn <- [ mkFn i, runFn i ] ]
@@ -233,6 +224,21 @@ inlineCommonOperators = applyAll $
233 go m acc (JSApp _ lhs [arg]) = go (m - 1) (arg : acc) lhs
224 go m acc (JSApp _ lhs [arg]) = go (m - 1) (arg : acc) lhs
234 go _ _ _ = Nothing
225 go _ _ _ = Nothing
227+ inlineNonClassFunction :: (JS -> Bool) -> (JS -> JS -> JS) -> JS -> JS
228+ inlineNonClassFunction p f = everywhereOnJS convert
231+ convert (JSApp _ (JSApp _ op' [x]) [y]) | p op' = f x y
232+ convert other = other
234+ isModFn :: (String, String) -> JS -> Bool
235+ isModFn (m, op) (JSAccessor _ op' (JSVar _ m')) = m == m' && op == op'
238+ isModFnWithDict :: (String, String) -> JS -> Bool
239+ isModFnWithDict (m, op) (JSApp _ (JSAccessor _ op' (JSVar _ m')) [(JSVar _ _)]) = m == m' && op == op'
240+ isModFnWithDict _ _ = False
236-- (f <<< g $ x) = f (g x)
242-- (f <<< g $ x) = f (g x)
237-- (f <<< g) = \x -> f (g x)
243-- (f <<< g) = \x -> f (g x)
238inlineFnComposition :: (MonadSupply m) => JS -> m JS
244inlineFnComposition :: (MonadSupply m) => JS -> m JS