git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Add `jsUnit` value
commit53f67be733d3e03981e8022c8efa693886a3554b authorGary Burgess <gary.burgess@gmail.com> dateMon 11 Aug 2014, 18:59 (12 years ago) parentb55d164
3 files changed+14−8
src/Language/PureScript/CodeGen/JS/AST.hs+6 src/Language/PureScript/Optimizer/Inliner.hs+4−4 src/Language/PureScript/Optimizer/MagicDo.hs+4−4
src/Language/PureScript/CodeGen/JS/AST.hs+6
@@ -242,6 +242,12 @@ data JS
242242 --
243243 | JSRaw String deriving (Show, Eq, Data, Typeable)
244244
245+-- |
246+-- Javascript representation of the unit value.
247+--
248+jsUnit :: JS
249+jsUnit = JSObjectLiteral []
250+
245251--
246252-- Traversals
247253--
src/Language/PureScript/Optimizer/Inliner.hs+4−4
@@ -49,8 +49,8 @@ etaConvert = everywhereOnJS convert
4949 not (any (`isRebound` block) (map JSVar idents)) &&
5050 not (any (`isRebound` block) args)
5151 = JSBlock (map (replaceIdents (zip idents args)) body)
52− convert (JSFunction Nothing [arg] (JSBlock [JSReturn (JSApp fn@JSVar{} [JSObjectLiteral []])]))
53− | arg == C.__unused = fn
52+ convert (JSFunction Nothing [arg] (JSBlock [JSReturn (JSApp fn@JSVar{} [val])]))
53+ | arg == C.__unused && val == jsUnit = fn
5454 convert js = js
5555
5656unThunk :: JS -> JS
@@ -59,7 +59,7 @@ unThunk = everywhereOnJS convert
5959 convert :: JS -> JS
6060 convert (JSBlock []) = JSBlock []
6161 convert (JSBlock jss) =
62− case (last jss) of
62+ case last jss of
6363 JSReturn (JSApp (JSFunction Nothing [] (JSBlock body)) []) -> JSBlock $ init jss ++ body
6464 _ -> JSBlock jss
6565 convert js = js
@@ -154,7 +154,7 @@ inlineCommonOperators = applyAll $
154154 convert other = other
155155 isOp (JSAccessor fnName' (JSVar prelude)) = prelude == C.prelude && fnName' == fnName
156156 isOp _ = False
157− isOpDict dictName (JSApp (JSAccessor prop (JSVar prelude)) [JSObjectLiteral []]) = prelude == C.prelude && prop == dictName
157+ isOpDict dictName (JSApp (JSAccessor prop (JSVar prelude)) [val]) = prelude == C.prelude && prop == dictName && val == jsUnit
158158 isOpDict _ _ = False
159159 mkFn :: Int -> JS -> JS
160160 mkFn 0 = everywhereOnJS convert
src/Language/PureScript/Optimizer/MagicDo.hs+4−4
@@ -69,10 +69,10 @@ magicDo' = everywhereOnJS undo . everywhereOnJSTopDown convert
6969 JSFunction (Just fnName) [] $ JSBlock (JSVariableIntroduction arg (Just (JSApp m [])) : init js ++ [JSReturn (JSApp ret [])] )
7070 -- Desugar untilE
7171 convert (JSApp (JSApp f [arg]) []) | isEffFunc C.untilE f =
72− JSApp (JSFunction Nothing [] (JSBlock [ JSWhile (JSUnary Not (JSApp arg [])) (JSBlock []), JSReturn (JSObjectLiteral []) ])) []
72+ JSApp (JSFunction Nothing [] (JSBlock [ JSWhile (JSUnary Not (JSApp arg [])) (JSBlock []), JSReturn jsUnit ])) []
7373 -- Desugar whileE
7474 convert (JSApp (JSApp (JSApp f [arg1]) [arg2]) []) | isEffFunc C.whileE f =
75− JSApp (JSFunction Nothing [] (JSBlock [ JSWhile (JSApp arg1 []) (JSBlock [ JSApp arg2 [] ]), JSReturn (JSObjectLiteral []) ])) []
75+ JSApp (JSFunction Nothing [] (JSBlock [ JSWhile (JSApp arg1 []) (JSBlock [ JSApp arg2 [] ]), JSReturn jsUnit ])) []
7676 convert other = other
7777 -- Check if an expression represents a monomorphic call to >>= for the Eff monad
7878 isBind (JSApp bindPoly [effDict]) | isBindPoly bindPoly && isEffDict C.bindEffDictionary effDict = True
@@ -99,8 +99,8 @@ magicDo' = everywhereOnJS undo . everywhereOnJSTopDown convert
9999 isEffFunc name (JSAccessor name' (JSVar eff)) = eff == C.eff && name == name'
100100 isEffFunc _ _ = False
101101 -- Check if an expression represents the Monad Eff dictionary
102− isEffDict name (JSApp (JSVar ident) [JSObjectLiteral []]) | ident == name = True
103− isEffDict name (JSApp (JSAccessor prop (JSVar eff)) [JSObjectLiteral []]) = eff == C.eff && prop == name
102+ isEffDict name (JSApp (JSVar ident) [val]) | ident == name && val == jsUnit = True
103+ isEffDict name (JSApp (JSAccessor prop (JSVar eff)) [val]) = eff == C.eff && prop == name && val == jsUnit
104104 isEffDict _ _ = False
105105 -- Remove __do function applications which remain after desugaring
106106 undo :: JS -> JS