Skip to content

Commit d866f68

Browse files
committed
Updates & fixes for JS inliner
1 parent 63e7a56 commit d866f68

5 files changed

Lines changed: 320 additions & 230 deletions

File tree

src/Language/PureScript/CodeGen/JS/Optimizer.hs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
1-
-----------------------------------------------------------------------------
2-
--
3-
-- Module : Language.PureScript.CodeGen.JS.Optimizer
4-
-- Copyright : (c) Phil Freeman 2013
5-
-- License : MIT
6-
--
7-
-- Maintainer : Phil Freeman <paf31@cantab.net>
8-
-- Stability : experimental
9-
-- Portability :
10-
--
1+
{-# LANGUAGE FlexibleContexts #-}
2+
113
-- |
124
-- This module optimizes code in the simplified-Javascript intermediate representation.
135
--
@@ -29,13 +21,7 @@
2921
--
3022
-- * Inlining primitive Javascript operators
3123
--
32-
-----------------------------------------------------------------------------
33-
34-
{-# LANGUAGE FlexibleContexts #-}
35-
36-
module Language.PureScript.CodeGen.JS.Optimizer (
37-
optimize
38-
) where
24+
module Language.PureScript.CodeGen.JS.Optimizer (optimize) where
3925

4026
import Prelude ()
4127
import Prelude.Compat
@@ -79,7 +65,9 @@ optimize' js = do
7965
, inlineVariables
8066
, inlineValues
8167
, inlineOperator (C.prelude, (C.$)) $ \f x -> JSApp f [x]
68+
, inlineOperator (C.dataFunction, C.apply) $ \f x -> JSApp f [x]
8269
, inlineOperator (C.prelude, (C.#)) $ \x f -> JSApp f [x]
70+
, inlineOperator (C.dataFunction, C.applyFlipped) $ \x f -> JSApp f [x]
8371
, inlineOperator (C.dataArrayUnsafe, C.unsafeIndex) $ flip JSIndexer
8472
, inlineCommonOperators ]) js
8573

src/Language/PureScript/CodeGen/JS/Optimizer/Common.hs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
-----------------------------------------------------------------------------
2-
--
3-
-- Module : Language.PureScript.CodeGen.JS.Optimizer.Common
4-
-- Copyright : (c) Phil Freeman 2013-14
5-
-- License : MIT
6-
--
7-
-- Maintainer : Phil Freeman <paf31@cantab.net>
8-
-- Stability : experimental
9-
-- Portability :
10-
--
111
-- |
122
-- Common functions used by the various optimizer phases
133
--
14-
-----------------------------------------------------------------------------
15-
164
module Language.PureScript.CodeGen.JS.Optimizer.Common where
175

186
import Data.Maybe (fromMaybe)
@@ -76,3 +64,18 @@ isUpdated var1 = everythingOnJS (||) check
7664
removeFromBlock :: ([JS] -> [JS]) -> JS -> JS
7765
removeFromBlock go (JSBlock sts) = JSBlock (go sts)
7866
removeFromBlock _ js = js
67+
68+
isFn :: (String, String) -> JS -> Bool
69+
isFn (moduleName, fnName) (JSAccessor x (JSVar y)) = x == fnName && y == moduleName
70+
isFn (moduleName, fnName) (JSIndexer (JSStringLiteral x) (JSVar y)) = x == fnName && y == moduleName
71+
isFn _ _ = False
72+
73+
isFn' :: [(String, String)] -> JS -> Bool
74+
isFn' xs js = any (`isFn` js) xs
75+
76+
isDict :: (String, String) -> JS -> Bool
77+
isDict (moduleName, dictName) (JSAccessor x (JSVar y)) = x == dictName && y == moduleName
78+
isDict _ _ = False
79+
80+
isDict' :: [(String, String)] -> JS -> Bool
81+
isDict' xs js = any (`isDict` js) xs

0 commit comments

Comments
 (0)