git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Inlined `<>` for string, `<<<` and `>>>` for `->`.
commit0b6d00787797071ddb50041bcf1c1e5698451ea3 authorjoneshf <jones3.hardy@gmail.com> dateFri 1 Aug 2014, 12:07 (12 years ago) parente7ab8ab
3 files changed+48
src/Language/PureScript/Constants.hs+18 src/Language/PureScript/Optimizer.hs+2 src/Language/PureScript/Optimizer/Inliner.hs+28
src/Language/PureScript/Constants.hs+18
@@ -23,6 +23,15 @@ module Language.PureScript.Constants where
2323(#) :: String
2424(#) = "#"
2525
26+(<<<) :: String
27+(<<<) = "<<<"
28+
29+(>>>) :: String
30+(>>>) = ">>>"
31+
32+(<>) :: String
33+(<>) = "<>"
34+
2635(++) :: String
2736(++) = "++"
2837
@@ -105,6 +114,9 @@ not = "not"
105114return :: String
106115return = "return"
107116
117+pure' :: String
118+pure' = "pure"
119+
108120returnEscaped :: String
109121returnEscaped = "$return"
110122
@@ -152,6 +164,9 @@ runFn = "runFn"
152164monadEffDictionary :: String
153165monadEffDictionary = "monadEff"
154166
167+applicativeEffDictionary :: String
168+applicativeEffDictionary = "applicativeEff"
169+
155170bindEffDictionary :: String
156171bindEffDictionary = "bindEff"
157172
@@ -179,6 +194,9 @@ boolLikeBoolean = "boolLikeBoolean"
179194semigroupString :: String
180195semigroupString = "semigroupString"
181196
197+semigroupoidArr :: String
198+semigroupoidArr = "semigroupoidArr"
199+
182200-- Main module
183201
184202main :: String
src/Language/PureScript/Optimizer.hs+2
@@ -61,6 +61,8 @@ optimize opts | optionsNoOptimizations opts = id
6161 , etaConvert
6262 , evaluateIifes
6363 , inlineVariables
64+ , inlinePure
65+ , inlineCompose
6466 , inlineOperator (C.prelude, (C.$)) $ \f x -> JSApp f [x]
6567 , inlineOperator (C.prelude, (C.#)) $ \x f -> JSApp f [x]
6668 , inlineOperator (C.preludeUnsafe, C.unsafeIndex) $ flip JSIndexer
src/Language/PureScript/Optimizer/Inliner.hs+28
@@ -15,6 +15,8 @@
1515
1616module Language.PureScript.Optimizer.Inliner (
1717 inlineVariables,
18+ inlinePure,
19+ inlineCompose,
1820 inlineOperator,
1921 inlineCommonOperators,
2022 etaConvert,
@@ -71,6 +73,31 @@ evaluateIifes = everywhereOnJS convert
7173 convert (JSApp (JSFunction Nothing [] (JSBlock [JSReturn ret])) []) = ret
7274 convert js = js
7375
76+inlinePure :: JS -> JS
77+inlinePure = everywhereOnJS convert
78+ where
79+ convert :: JS -> JS
80+ convert (JSApp (JSApp p eff) [js]) | isPure p && isEff eff = JSFunction Nothing [] (JSBlock [JSReturn js])
81+ convert other = other
82+ isPure (JSAccessor f (JSVar prelude)) = (f == C.pure' || f == C.return) && prelude == C.prelude
83+ isPure _ = False
84+ isEff [JSApp (JSAccessor app (JSVar eff)) _] = app == C.applicativeEffDictionary && eff == C.eff
85+ isEff _ = False
86+
87+inlineCompose :: JS -> JS
88+inlineCompose = everywhereOnJS convert
89+ where
90+ convert :: JS -> JS
91+ convert (JSApp (JSApp comp [f]) [g]) | isBackwardComp comp = JSFunction Nothing ["x"] (JSBlock [JSReturn (JSApp f [JSApp g [JSVar "x"]])])
92+ convert (JSApp (JSApp comp [f]) [g]) | isForwardComp comp = JSFunction Nothing ["x"] (JSBlock [JSReturn (JSApp g [JSApp f [JSVar "x"]])])
93+ convert other = other
94+ isBackwardComp (JSApp (JSIndexer (JSStringLiteral comp) (JSVar prelude)) semi) = comp == (C.<<<) && prelude == C.prelude && isSemi semi
95+ isBackwardComp _ = False
96+ isForwardComp (JSApp (JSIndexer (JSStringLiteral comp) (JSVar prelude)) semi) = comp == (C.>>>) && prelude == C.prelude && isSemi semi
97+ isForwardComp _ = False
98+ isSemi [JSApp (JSAccessor semi (JSVar prelude)) _] = semi == C.semigroupoidArr && prelude == C.prelude
99+ isSemi _ = False
100+
74101inlineVariables :: JS -> JS
75102inlineVariables = everywhereOnJS $ removeFromBlock go
76103 where
@@ -112,6 +139,7 @@ inlineCommonOperators = applyAll $
112139 , binary C.eqBoolean (C.==) EqualTo
113140 , binary C.eqBoolean (C./=) NotEqualTo
114141
142+ , binary C.semigroupString (C.<>) Add
115143 , binary C.semigroupString (C.++) Add
116144
117145 , binaryFunction C.bitsNumber C.shl ShiftLeft