@@ -110,7 +110,7 @@ inlineCommonValues = everywhereOnJS convert
110 intOp ss op x y = JSBinary ss BitwiseOr (JSBinary ss op x y) (JSNumericLiteral ss (Left 0))
110 intOp ss op x y = JSBinary ss BitwiseOr (JSBinary ss op x y) (JSNumericLiteral ss (Left 0))
112inlineCommonOperators :: JS -> JS
112inlineCommonOperators :: JS -> JS
113−inlineCommonOperators = applyAll $
113+inlineCommonOperators = everywhereOnJSTopDown $ applyAll $
114 [ binary semiringNumber opAdd Add
114 [ binary semiringNumber opAdd Add
115 , binary semiringNumber opMul Multiply
115 , binary semiringNumber opMul Multiply
@@ -173,38 +173,32 @@ inlineCommonOperators = applyAll $
173 [ fn | i <- [0..10], fn <- [ mkFn i, runFn i ] ]
173 [ fn | i <- [0..10], fn <- [ mkFn i, runFn i ] ]
175 binary :: (Text, PSString) -> (Text, PSString) -> BinaryOperator -> JS -> JS
175 binary :: (Text, PSString) -> (Text, PSString) -> BinaryOperator -> JS -> JS
176− binary dict fns op = everywhereOnJS convert
176+ binary dict fns op = convert where
178 convert :: JS -> JS
177 convert :: JS -> JS
179 convert (JSApp ss (JSApp _ (JSApp _ fn [dict']) [x]) [y]) | isDict dict dict' && isDict fns fn = JSBinary ss op x y
178 convert (JSApp ss (JSApp _ (JSApp _ fn [dict']) [x]) [y]) | isDict dict dict' && isDict fns fn = JSBinary ss op x y
180 convert other = other
179 convert other = other
181 binary' :: Text -> PSString -> BinaryOperator -> JS -> JS
180 binary' :: Text -> PSString -> BinaryOperator -> JS -> JS
182− binary' moduleName opString op = everywhereOnJS convert
181+ binary' moduleName opString op = convert where
184 convert :: JS -> JS
182 convert :: JS -> JS
185 convert (JSApp ss (JSApp _ fn [x]) [y]) | isDict (moduleName, opString) fn = JSBinary ss op x y
183 convert (JSApp ss (JSApp _ fn [x]) [y]) | isDict (moduleName, opString) fn = JSBinary ss op x y
186 convert other = other
184 convert other = other
187 unary :: (Text, PSString) -> (Text, PSString) -> UnaryOperator -> JS -> JS
185 unary :: (Text, PSString) -> (Text, PSString) -> UnaryOperator -> JS -> JS
188− unary dicts fns op = everywhereOnJS convert
186+ unary dicts fns op = convert where
190 convert :: JS -> JS
187 convert :: JS -> JS
191 convert (JSApp ss (JSApp _ fn [dict']) [x]) | isDict dicts dict' && isDict fns fn = JSUnary ss op x
188 convert (JSApp ss (JSApp _ fn [dict']) [x]) | isDict dicts dict' && isDict fns fn = JSUnary ss op x
192 convert other = other
189 convert other = other
193 unary' :: Text -> PSString -> UnaryOperator -> JS -> JS
190 unary' :: Text -> PSString -> UnaryOperator -> JS -> JS
194− unary' moduleName fnName op = everywhereOnJS convert
191+ unary' moduleName fnName op = convert where
196 convert :: JS -> JS
192 convert :: JS -> JS
197 convert (JSApp ss fn [x]) | isDict (moduleName, fnName) fn = JSUnary ss op x
193 convert (JSApp ss fn [x]) | isDict (moduleName, fnName) fn = JSUnary ss op x
198 convert other = other
194 convert other = other
199 mkFn :: Int -> JS -> JS
195 mkFn :: Int -> JS -> JS
200− mkFn 0 = everywhereOnJS convert
196+ mkFn 0 = convert where
202 convert :: JS -> JS
197 convert :: JS -> JS
203 convert (JSApp _ mkFnN [JSFunction s1 Nothing [_] (JSBlock s2 js)]) | isNFn C.mkFn 0 mkFnN =
198 convert (JSApp _ mkFnN [JSFunction s1 Nothing [_] (JSBlock s2 js)]) | isNFn C.mkFn 0 mkFnN =
204 JSFunction s1 Nothing [] (JSBlock s2 js)
199 JSFunction s1 Nothing [] (JSBlock s2 js)
205 convert other = other
200 convert other = other
206− mkFn n = everywhereOnJS convert
201+ mkFn n = convert where
208 convert :: JS -> JS
202 convert :: JS -> JS
209 convert orig@(JSApp ss mkFnN [fn]) | isNFn C.mkFn n mkFnN =
203 convert orig@(JSApp ss mkFnN [fn]) | isNFn C.mkFn n mkFnN =
210 case collectArgs n [] fn of
204 case collectArgs n [] fn of
@@ -223,8 +217,7 @@ inlineCommonOperators = applyAll $
223 isNFn _ _ _ = False
217 isNFn _ _ _ = False
225 runFn :: Int -> JS -> JS
219 runFn :: Int -> JS -> JS
226− runFn n = everywhereOnJS convert
220+ runFn n = convert where
228 convert :: JS -> JS
221 convert :: JS -> JS
229 convert js = fromMaybe js $ go n [] js
222 convert js = fromMaybe js $ go n [] js
@@ -234,8 +227,7 @@ inlineCommonOperators = applyAll $
234 go _ _ _ = Nothing
227 go _ _ _ = Nothing
236 inlineNonClassFunction :: (JS -> Bool) -> (JS -> JS -> JS) -> JS -> JS
229 inlineNonClassFunction :: (JS -> Bool) -> (JS -> JS -> JS) -> JS -> JS
237− inlineNonClassFunction p f = everywhereOnJS convert
230+ inlineNonClassFunction p f = convert where
239 convert :: JS -> JS
231 convert :: JS -> JS
240 convert (JSApp _ (JSApp _ op' [x]) [y]) | p op' = f x y
232 convert (JSApp _ (JSApp _ op' [x]) [y]) | p op' = f x y
241 convert other = other
233 convert other = other