git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #526 from joneshf/inlining

Inlining

commit2c231df87cdd5d7e22605935a4991d33597e2134 authorPhil Freeman <paf31@cantab.net> dateSun 3 Aug 2014, 12:06 (12 years ago) parent09271cd681dd8b
3 files changed+22
src/Language/PureScript/Constants.hs+12 src/Language/PureScript/Optimizer/Inliner.hs+1 src/Language/PureScript/Optimizer/MagicDo.hs+9
src/Language/PureScript/Constants.hs+12
@@ -23,6 +23,9 @@ module Language.PureScript.Constants where
2323(#) :: String
2424(#) = "#"
2525
26+(<>) :: String
27+(<>) = "<>"
28+
2629(++) :: String
2730(++) = "++"
2831
@@ -105,6 +108,9 @@ not = "not"
105108return :: String
106109return = "return"
107110
111+pure' :: String
112+pure' = "pure"
113+
108114returnEscaped :: String
109115returnEscaped = "$return"
110116
@@ -152,6 +158,9 @@ runFn = "runFn"
152158monadEffDictionary :: String
153159monadEffDictionary = "monadEff"
154160
161+applicativeEffDictionary :: String
162+applicativeEffDictionary = "applicativeEff"
163+
155164bindEffDictionary :: String
156165bindEffDictionary = "bindEff"
157166
@@ -179,6 +188,9 @@ boolLikeBoolean = "boolLikeBoolean"
179188semigroupString :: String
180189semigroupString = "semigroupString"
181190
191+semigroupoidArr :: String
192+semigroupoidArr = "semigroupoidArr"
193+
182194-- Main module
183195
184196main :: String
src/Language/PureScript/Optimizer/Inliner.hs+1
@@ -112,6 +112,7 @@ inlineCommonOperators = applyAll $
112112 , binary C.eqBoolean (C.==) EqualTo
113113 , binary C.eqBoolean (C./=) NotEqualTo
114114
115+ , binary C.semigroupString (C.<>) Add
115116 , binary C.semigroupString (C.++) Add
116117
117118 , binaryFunction C.bitsNumber C.shl ShiftLeft
src/Language/PureScript/Optimizer/MagicDo.hs+9
@@ -57,6 +57,8 @@ magicDo' = everywhereOnJS undo . everywhereOnJSTopDown convert
5757 convert :: JS -> JS
5858 -- Desugar return
5959 convert (JSApp (JSApp ret [val]) []) | isReturn ret = val
60+ -- Desugar pure
61+ convert (JSApp (JSApp pure' [val]) []) | isPure pure' = val
6062 -- Desugar >>
6163 convert (JSApp (JSApp bind [m]) [JSFunction Nothing ["_"] (JSBlock js)]) | isBind bind && isJSReturn (last js) =
6264 let JSReturn ret = last js in
@@ -78,6 +80,9 @@ magicDo' = everywhereOnJS undo . everywhereOnJSTopDown convert
7880 -- Check if an expression represents a monomorphic call to return for the Eff monad
7981 isReturn (JSApp retPoly [effDict]) | isRetPoly retPoly && isEffDict C.monadEffDictionary effDict = True
8082 isReturn _ = False
83+ -- Check if an expression represents a monomorphic call to pure for the Eff applicative
84+ isPure (JSApp purePoly [effDict]) | isPurePoly purePoly && isEffDict C.applicativeEffDictionary effDict = True
85+ isPure _ = False
8186 -- Check if an expression represents the polymorphic >>= function
8287 isBindPoly (JSAccessor prop (JSVar prelude)) = prelude == C.prelude && prop == identToJs (Op (C.>>=))
8388 isBindPoly (JSIndexer (JSStringLiteral bind) (JSVar prelude)) = prelude == C.prelude && bind == (C.>>=)
@@ -86,6 +91,10 @@ magicDo' = everywhereOnJS undo . everywhereOnJSTopDown convert
8691 isRetPoly (JSAccessor returnEscaped (JSVar prelude)) = prelude == C.prelude && returnEscaped == C.returnEscaped
8792 isRetPoly (JSIndexer (JSStringLiteral return') (JSVar prelude)) = prelude == C.prelude && return' == C.return
8893 isRetPoly _ = False
94+ -- Check if an expression represents the polymorphic pure function
95+ isPurePoly (JSAccessor pure' (JSVar prelude)) = prelude == C.prelude && pure' == C.pure'
96+ isPurePoly (JSIndexer (JSStringLiteral pure') (JSVar prelude)) = prelude == C.prelude && pure' == C.pure'
97+ isPurePoly _ = False
8998 -- Check if an expression represents a function in the Ef module
9099 isEffFunc name (JSAccessor name' (JSVar eff)) = eff == C.eff && name == name'
91100 isEffFunc _ _ = False