git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #526 from joneshf/inlining
2c231dfPhil Freeman
src/Language/PureScript/Constants.hs+12
@@ -23,6 +23,9 @@ module Language.PureScript.Constants where
23(#) :: String
23(#) :: String
24(#) = "#"
24(#) = "#"
25
25
26+(<>) :: String
27+(<>) = "<>"
28+
26(++) :: String
29(++) :: String
27(++) = "++"
30(++) = "++"
28
31
@@ -105,6 +108,9 @@ not = "not"
105return :: String
108return :: String
106return = "return"
109return = "return"
107
110
111+pure' :: String
112+pure' = "pure"
113+
108returnEscaped :: String
114returnEscaped :: String
109returnEscaped = "$return"
115returnEscaped = "$return"
110
116
@@ -152,6 +158,9 @@ runFn = "runFn"
152monadEffDictionary :: String
158monadEffDictionary :: String
153monadEffDictionary = "monadEff"
159monadEffDictionary = "monadEff"
154
160
161+applicativeEffDictionary :: String
162+applicativeEffDictionary = "applicativeEff"
163+
155bindEffDictionary :: String
164bindEffDictionary :: String
156bindEffDictionary = "bindEff"
165bindEffDictionary = "bindEff"
157
166
@@ -179,6 +188,9 @@ boolLikeBoolean = "boolLikeBoolean"
179semigroupString :: String
188semigroupString :: String
180semigroupString = "semigroupString"
189semigroupString = "semigroupString"
181
190
191+semigroupoidArr :: String
192+semigroupoidArr = "semigroupoidArr"
193+
182-- Main module
194-- Main module
183
195
184main :: String
196main :: String
src/Language/PureScript/Optimizer/Inliner.hs+1
@@ -112,6 +112,7 @@ inlineCommonOperators = applyAll $
112 , binary C.eqBoolean (C.==) EqualTo
112 , binary C.eqBoolean (C.==) EqualTo
113 , binary C.eqBoolean (C./=) NotEqualTo
113 , binary C.eqBoolean (C./=) NotEqualTo
114
114
115+ , binary C.semigroupString (C.<>) Add
115 , binary C.semigroupString (C.++) Add
116 , binary C.semigroupString (C.++) Add
116
117
117 , binaryFunction C.bitsNumber C.shl ShiftLeft
118 , binaryFunction C.bitsNumber C.shl ShiftLeft
src/Language/PureScript/Optimizer/MagicDo.hs+9
@@ -57,6 +57,8 @@ magicDo' = everywhereOnJS undo . everywhereOnJSTopDown convert
57 convert :: JS -> JS
57 convert :: JS -> JS
58 -- Desugar return
58 -- Desugar return
59 convert (JSApp (JSApp ret [val]) []) | isReturn ret = val
59 convert (JSApp (JSApp ret [val]) []) | isReturn ret = val
60+ -- Desugar pure
61+ convert (JSApp (JSApp pure' [val]) []) | isPure pure' = val
60 -- Desugar >>
62 -- Desugar >>
61 convert (JSApp (JSApp bind [m]) [JSFunction Nothing ["_"] (JSBlock js)]) | isBind bind && isJSReturn (last js) =
63 convert (JSApp (JSApp bind [m]) [JSFunction Nothing ["_"] (JSBlock js)]) | isBind bind && isJSReturn (last js) =
62 let JSReturn ret = last js in
64 let JSReturn ret = last js in
@@ -78,6 +80,9 @@ magicDo' = everywhereOnJS undo . everywhereOnJSTopDown convert
78 -- Check if an expression represents a monomorphic call to return for the Eff monad
80 -- Check if an expression represents a monomorphic call to return for the Eff monad
79 isReturn (JSApp retPoly [effDict]) | isRetPoly retPoly && isEffDict C.monadEffDictionary effDict = True
81 isReturn (JSApp retPoly [effDict]) | isRetPoly retPoly && isEffDict C.monadEffDictionary effDict = True
80 isReturn _ = False
82 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
81 -- Check if an expression represents the polymorphic >>= function
86 -- Check if an expression represents the polymorphic >>= function
82 isBindPoly (JSAccessor prop (JSVar prelude)) = prelude == C.prelude && prop == identToJs (Op (C.>>=))
87 isBindPoly (JSAccessor prop (JSVar prelude)) = prelude == C.prelude && prop == identToJs (Op (C.>>=))
83 isBindPoly (JSIndexer (JSStringLiteral bind) (JSVar prelude)) = prelude == C.prelude && bind == (C.>>=)
88 isBindPoly (JSIndexer (JSStringLiteral bind) (JSVar prelude)) = prelude == C.prelude && bind == (C.>>=)
@@ -86,6 +91,10 @@ magicDo' = everywhereOnJS undo . everywhereOnJSTopDown convert
86 isRetPoly (JSAccessor returnEscaped (JSVar prelude)) = prelude == C.prelude && returnEscaped == C.returnEscaped
91 isRetPoly (JSAccessor returnEscaped (JSVar prelude)) = prelude == C.prelude && returnEscaped == C.returnEscaped
87 isRetPoly (JSIndexer (JSStringLiteral return') (JSVar prelude)) = prelude == C.prelude && return' == C.return
92 isRetPoly (JSIndexer (JSStringLiteral return') (JSVar prelude)) = prelude == C.prelude && return' == C.return
88 isRetPoly _ = False
93 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
89 -- Check if an expression represents a function in the Ef module
98 -- Check if an expression represents a function in the Ef module
90 isEffFunc name (JSAccessor name' (JSVar eff)) = eff == C.eff && name == name'
99 isEffFunc name (JSAccessor name' (JSVar eff)) = eff == C.eff && name == name'
91 isEffFunc _ _ = False
100 isEffFunc _ _ = False