@@ -4,7 +4,6 @@
4module Language.PureScript.CodeGen.JS.Optimizer.Inliner
4module Language.PureScript.CodeGen.JS.Optimizer.Inliner
5 ( inlineVariables
5 ( inlineVariables
6 , inlineCommonValues
6 , inlineCommonValues
8 , inlineCommonOperators
7 , inlineCommonOperators
9 , inlineFnComposition
8 , inlineFnComposition
10 , etaConvert
9 , etaConvert
@@ -100,13 +99,13 @@ inlineCommonValues = everywhereOnJS convert
100 fnSubtract = (C.dataRing, C.sub)
99 fnSubtract = (C.dataRing, C.sub)
101 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))
103−inlineOperator :: (String, String) -> (JS -> JS -> JS) -> JS -> JS
102+inlineNonClassFunction :: (String, String) -> (JS -> JS -> JS) -> JS -> JS
104−inlineOperator (m, op) f = everywhereOnJS convert
103+inlineNonClassFunction (m, op) f = everywhereOnJS convert
106 convert :: JS -> JS
105 convert :: JS -> JS
107 convert (JSApp _ (JSApp _ op' [x]) [y]) | isOp op' = f x y
106 convert (JSApp _ (JSApp _ op' [x]) [y]) | isOp op' = f x y
108 convert other = other
107 convert other = other
109− isOp (JSIndexer _ (JSStringLiteral _ op') (JSVar _ m')) = m == m' && op == op'
108+ isOp (JSAccessor _ op' (JSVar _ m')) = m == m' && op == op'
110 isOp _ = False
109 isOp _ = False
112inlineCommonOperators :: JS -> JS
111inlineCommonOperators :: JS -> JS
@@ -167,6 +166,10 @@ inlineCommonOperators = applyAll $
167 , binary' C.dataIntBits C.shr ShiftRight
166 , binary' C.dataIntBits C.shr ShiftRight
168 , binary' C.dataIntBits C.zshr ZeroFillShiftRight
167 , binary' C.dataIntBits C.zshr ZeroFillShiftRight
169 , unary' C.dataIntBits C.complement BitwiseNot
168 , unary' C.dataIntBits C.complement BitwiseNot
170+ , inlineNonClassFunction (C.dataFunction, C.apply) $ \f x -> JSApp Nothing f [x]
171+ , inlineNonClassFunction (C.dataFunction, C.applyFlipped) $ \x f -> JSApp Nothing f [x]
172+ , inlineNonClassFunction (C.dataArrayUnsafe, C.unsafeIndex) $ flip (JSIndexer Nothing)
171 [ fn | i <- [0..10], fn <- [ mkFn i, runFn i ] ]
174 [ fn | i <- [0..10], fn <- [ mkFn i, runFn i ] ]