git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Use undefined over unit
commit1b46a84b4bf92d7cd0e5a4bb19007ce5eb44d907 authorGary Burgess <gary.burgess@gmail.com> dateTue 12 Aug 2014, 20:34 (12 years ago) parent8b58631
6 files changed+14−11
src/Language/PureScript/CodeGen/JS.hs+1 src/Language/PureScript/CodeGen/JS/AST.hs+2−2 src/Language/PureScript/Constants.hs+4−2 src/Language/PureScript/Optimizer/Inliner.hs+2−2 src/Language/PureScript/Optimizer/MagicDo.hs+4−4 src/Language/PureScript/TypeChecker/Types.hs+1−1
src/Language/PureScript/CodeGen/JS.hs+1
@@ -307,6 +307,7 @@ varToJs m qual = qualifiedToJS m id qual
307307-- variable that may have a qualified name.
308308--
309309qualifiedToJS :: ModuleName -> (a -> Ident) -> Qualified a -> JS
310+qualifiedToJS _ f (Qualified (Just (ModuleName [ProperName mn])) a) | mn == C.prim = JSVar . runIdent $ f a
310311qualifiedToJS m f (Qualified (Just m') a) | m /= m' = accessor (f a) (JSVar (moduleNameToJs m'))
311312qualifiedToJS _ f (Qualified _ a) = JSVar $ identToJs (f a)
312313
src/Language/PureScript/CodeGen/JS/AST.hs+2−2
@@ -247,8 +247,8 @@ data JS
247247-- |
248248-- Javascript representation of the unit value.
249249--
250−jsUnit :: JS
251−jsUnit = JSAccessor C.unit (JSVar C.prelude)
250+jsUndefined :: JS
251+jsUndefined = JSVar C.undefined
252252
253253--
254254-- Traversals
src/Language/PureScript/Constants.hs+4−2
@@ -153,8 +153,10 @@ mkFn = "mkFn"
153153runFn :: String
154154runFn = "runFn"
155155
156−unit :: String
157−unit = "unit"
156+-- Prim values
157+
158+undefined :: String
159+undefined = "undefined"
158160
159161-- Type Class Dictionary Names
160162
src/Language/PureScript/Optimizer/Inliner.hs+2−2
@@ -50,7 +50,7 @@ etaConvert = everywhereOnJS convert
5050 not (any (`isRebound` block) args)
5151 = JSBlock (map (replaceIdents (zip idents args)) body)
5252 convert (JSFunction Nothing [arg] (JSBlock [JSReturn (JSApp fn@JSVar{} [val])]))
53− | arg == C.__unused && val == jsUnit = fn
53+ | arg == C.__unused && val == jsUndefined = fn
5454 convert js = js
5555
5656unThunk :: 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)) [val]) = prelude == C.prelude && prop == dictName && val == jsUnit
157+ isOpDict dictName (JSApp (JSAccessor prop (JSVar prelude)) [val]) = prelude == C.prelude && prop == dictName && val == jsUndefined
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 jsUnit ])) []
72+ JSApp (JSFunction Nothing [] (JSBlock [ JSWhile (JSUnary Not (JSApp arg [])) (JSBlock []), JSReturn $ JSObjectLiteral []])) []
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 jsUnit ])) []
75+ JSApp (JSFunction Nothing [] (JSBlock [ JSWhile (JSApp arg1 []) (JSBlock [ JSApp arg2 [] ]), JSReturn $ JSObjectLiteral []])) []
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) [val]) | ident == name && val == jsUnit = True
103− isEffDict name (JSApp (JSAccessor prop (JSVar eff)) [val]) = eff == C.eff && prop == name && val == jsUnit
102+ isEffDict name (JSApp (JSVar ident) [val]) | ident == name && val == jsUndefined = True
103+ isEffDict name (JSApp (JSAccessor prop (JSVar eff)) [val]) = eff == C.eff && prop == name && val == jsUndefined
104104 isEffDict _ _ = False
105105 -- Remove __do function applications which remain after desugaring
106106 undo :: JS -> JS
src/Language/PureScript/TypeChecker/Types.hs+1−1
@@ -394,7 +394,7 @@ entails env moduleName context = solve (sortedNubBy canonicalizeDictionary (filt
394394 dictTrace other = other
395395
396396 valUnit :: Expr
397− valUnit = Var (Qualified (Just (ModuleName [ProperName C.prelude])) (Ident C.unit))
397+ valUnit = Var (Qualified (Just (ModuleName [ProperName C.prim])) (Ident C.undefined))
398398
399399-- |
400400-- Check all values in a list pairwise match a predicate