git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Use undefined over unit
1b46a84Gary Burgess
src/Language/PureScript/CodeGen/JS.hs+1
@@ -307,6 +307,7 @@ varToJs m qual = qualifiedToJS m id qual
307-- variable that may have a qualified name.
307-- variable that may have a qualified name.
308--
308--
309qualifiedToJS :: ModuleName -> (a -> Ident) -> Qualified a -> JS
309qualifiedToJS :: ModuleName -> (a -> Ident) -> Qualified a -> JS
310+qualifiedToJS _ f (Qualified (Just (ModuleName [ProperName mn])) a) | mn == C.prim = JSVar . runIdent $ f a
310qualifiedToJS m f (Qualified (Just m') a) | m /= m' = accessor (f a) (JSVar (moduleNameToJs m'))
311qualifiedToJS m f (Qualified (Just m') a) | m /= m' = accessor (f a) (JSVar (moduleNameToJs m'))
311qualifiedToJS _ f (Qualified _ a) = JSVar $ identToJs (f a)
312qualifiedToJS _ f (Qualified _ a) = JSVar $ identToJs (f a)
312
313
src/Language/PureScript/CodeGen/JS/AST.hs+2−2
@@ -247,8 +247,8 @@ data JS
247-- |
247-- |
248-- Javascript representation of the unit value.
248-- Javascript representation of the unit value.
249--
249--
250−jsUnit :: JS
250+jsUndefined :: JS
251−jsUnit = JSAccessor C.unit (JSVar C.prelude)
251+jsUndefined = JSVar C.undefined
252
252
253--
253--
254-- Traversals
254-- Traversals
src/Language/PureScript/Constants.hs+4−2
@@ -153,8 +153,10 @@ mkFn = "mkFn"
153runFn :: String
153runFn :: String
154runFn = "runFn"
154runFn = "runFn"
155
155
156+-- Prim values
157+
156−unit :: String
158+undefined :: String
157−unit = "unit"
159+undefined = "undefined"
158
160
159-- Type Class Dictionary Names
161-- Type Class Dictionary Names
160
162
src/Language/PureScript/Optimizer/Inliner.hs+2−2
@@ -50,7 +50,7 @@ etaConvert = everywhereOnJS convert
50 not (any (`isRebound` block) args)
50 not (any (`isRebound` block) args)
51 = JSBlock (map (replaceIdents (zip idents args)) body)
51 = JSBlock (map (replaceIdents (zip idents args)) body)
52 convert (JSFunction Nothing [arg] (JSBlock [JSReturn (JSApp fn@JSVar{} [val])]))
52 convert (JSFunction Nothing [arg] (JSBlock [JSReturn (JSApp fn@JSVar{} [val])]))
53− | arg == C.__unused && val == jsUnit = fn
53+ | arg == C.__unused && val == jsUndefined = fn
54 convert js = js
54 convert js = js
55
55
56unThunk :: JS -> JS
56unThunk :: JS -> JS
@@ -154,7 +154,7 @@ inlineCommonOperators = applyAll $
154 convert other = other
154 convert other = other
155 isOp (JSAccessor fnName' (JSVar prelude)) = prelude == C.prelude && fnName' == fnName
155 isOp (JSAccessor fnName' (JSVar prelude)) = prelude == C.prelude && fnName' == fnName
156 isOp _ = False
156 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
158 isOpDict _ _ = False
158 isOpDict _ _ = False
159 mkFn :: Int -> JS -> JS
159 mkFn :: Int -> JS -> JS
160 mkFn 0 = everywhereOnJS convert
160 mkFn 0 = everywhereOnJS convert
src/Language/PureScript/Optimizer/MagicDo.hs+4−4
@@ -69,10 +69,10 @@ magicDo' = everywhereOnJS undo . everywhereOnJSTopDown convert
69 JSFunction (Just fnName) [] $ JSBlock (JSVariableIntroduction arg (Just (JSApp m [])) : init js ++ [JSReturn (JSApp ret [])] )
69 JSFunction (Just fnName) [] $ JSBlock (JSVariableIntroduction arg (Just (JSApp m [])) : init js ++ [JSReturn (JSApp ret [])] )
70 -- Desugar untilE
70 -- Desugar untilE
71 convert (JSApp (JSApp f [arg]) []) | isEffFunc C.untilE f =
71 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 []])) []
73 -- Desugar whileE
73 -- Desugar whileE
74 convert (JSApp (JSApp (JSApp f [arg1]) [arg2]) []) | isEffFunc C.whileE f =
74 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 []])) []
76 convert other = other
76 convert other = other
77 -- Check if an expression represents a monomorphic call to >>= for the Eff monad
77 -- Check if an expression represents a monomorphic call to >>= for the Eff monad
78 isBind (JSApp bindPoly [effDict]) | isBindPoly bindPoly && isEffDict C.bindEffDictionary effDict = True
78 isBind (JSApp bindPoly [effDict]) | isBindPoly bindPoly && isEffDict C.bindEffDictionary effDict = True
@@ -99,8 +99,8 @@ magicDo' = everywhereOnJS undo . everywhereOnJSTopDown convert
99 isEffFunc name (JSAccessor name' (JSVar eff)) = eff == C.eff && name == name'
99 isEffFunc name (JSAccessor name' (JSVar eff)) = eff == C.eff && name == name'
100 isEffFunc _ _ = False
100 isEffFunc _ _ = False
101 -- Check if an expression represents the Monad Eff dictionary
101 -- Check if an expression represents the Monad Eff dictionary
102− isEffDict name (JSApp (JSVar ident) [val]) | ident == name && val == jsUnit = True
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 == jsUnit
103+ isEffDict name (JSApp (JSAccessor prop (JSVar eff)) [val]) = eff == C.eff && prop == name && val == jsUndefined
104 isEffDict _ _ = False
104 isEffDict _ _ = False
105 -- Remove __do function applications which remain after desugaring
105 -- Remove __do function applications which remain after desugaring
106 undo :: JS -> JS
106 undo :: JS -> JS
src/Language/PureScript/TypeChecker/Types.hs+1−1
@@ -394,7 +394,7 @@ entails env moduleName context = solve (sortedNubBy canonicalizeDictionary (filt
394 dictTrace other = other
394 dictTrace other = other
395
395
396 valUnit :: Expr
396 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))
398
398
399-- |
399-- |
400-- Check all values in a list pairwise match a predicate
400-- Check all values in a list pairwise match a predicate