git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
remove JSAccessor; replace with JSIndexer (#2554)
1bb6acdMichael Ficarra
src/Language/PureScript/CodeGen/JS.hs+12−17
@@ -35,7 +35,7 @@ import Language.PureScript.Errors (ErrorMessageHint(..), SimpleErrorMessage(..),
35 errorMessage, rethrowWithPosition, addHint)
35 errorMessage, rethrowWithPosition, addHint)
36import Language.PureScript.Names
36import Language.PureScript.Names
37import Language.PureScript.Options
37import Language.PureScript.Options
38−import Language.PureScript.PSString (PSString, mkString, decodeString)
38+import Language.PureScript.PSString (PSString, mkString)
39import Language.PureScript.Traversals (sndM)
39import Language.PureScript.Traversals (sndM)
40import qualified Language.PureScript.Constants as C
40import qualified Language.PureScript.Constants as C
41
41
@@ -69,7 +69,7 @@ moduleToJs (Module coms mn imps exps foreigns decls) foreign_ =
69 let standardExps = exps \\ foreignExps
69 let standardExps = exps \\ foreignExps
70 let exps' = JSObjectLiteral Nothing $ map (mkString . runIdent &&& JSVar Nothing . identToJs) standardExps
70 let exps' = JSObjectLiteral Nothing $ map (mkString . runIdent &&& JSVar Nothing . identToJs) standardExps
71 ++ map (mkString . runIdent &&& foreignIdent) foreignExps
71 ++ map (mkString . runIdent &&& foreignIdent) foreignExps
72− return $ moduleBody ++ [JSAssignment Nothing (JSAccessor Nothing "exports" (JSVar Nothing "module")) exps']
72+ return $ moduleBody ++ [JSAssignment Nothing (accessorString "exports" (JSVar Nothing "module")) exps']
73
73
74 where
74 where
75
75
@@ -182,12 +182,7 @@ moduleToJs (Module coms mn imps exps foreigns decls) foreign_ =
182 accessor (GenIdent _ _) = internalError "GenIdent in accessor"
182 accessor (GenIdent _ _) = internalError "GenIdent in accessor"
183
183
184 accessorString :: PSString -> JS -> JS
184 accessorString :: PSString -> JS -> JS
185− accessorString prop =
186− case decodeString prop of
187− Just s | not (identNeedsEscaping s) ->
188− JSAccessor Nothing s
189− _ ->
190− JSIndexer Nothing (JSStringLiteral Nothing prop)
185+ accessorString prop = JSIndexer Nothing (JSStringLiteral Nothing prop)
191
186
192 -- |
187 -- |
193 -- Generate code in the simplified Javascript intermediate representation for a value or expression.
188 -- Generate code in the simplified Javascript intermediate representation for a value or expression.
@@ -201,9 +196,9 @@ moduleToJs (Module coms mn imps exps foreigns decls) foreign_ =
201 valueToJs' (Literal (pos, _, _, _) l) =
196 valueToJs' (Literal (pos, _, _, _) l) =
202 maybe id rethrowWithPosition pos $ literalToValueJS l
197 maybe id rethrowWithPosition pos $ literalToValueJS l
203 valueToJs' (Var (_, _, _, Just (IsConstructor _ [])) name) =
198 valueToJs' (Var (_, _, _, Just (IsConstructor _ [])) name) =
204− return $ JSAccessor Nothing "value" $ qualifiedToJS id name
199+ return $ accessorString "value" $ qualifiedToJS id name
205 valueToJs' (Var (_, _, _, Just (IsConstructor _ _)) name) =
200 valueToJs' (Var (_, _, _, Just (IsConstructor _ _)) name) =
206− return $ JSAccessor Nothing "create" $ qualifiedToJS id name
201+ return $ accessorString "create" $ qualifiedToJS id name
207 valueToJs' (Accessor _ prop val) =
202 valueToJs' (Accessor _ prop val) =
208 accessorString prop <$> valueToJs val
203 accessorString prop <$> valueToJs val
209 valueToJs' (ObjectUpdate _ o ps) = do
204 valueToJs' (ObjectUpdate _ o ps) = do
@@ -258,17 +253,17 @@ moduleToJs (Module coms mn imps exps foreigns decls) foreign_ =
258 (JSBlock Nothing [JSReturn Nothing $ JSVar Nothing "value"]))])
253 (JSBlock Nothing [JSReturn Nothing $ JSVar Nothing "value"]))])
259 valueToJs' (Constructor _ _ (ProperName ctor) []) =
254 valueToJs' (Constructor _ _ (ProperName ctor) []) =
260 return $ iife (properToJs ctor) [ JSFunction Nothing (Just (properToJs ctor)) [] (JSBlock Nothing [])
255 return $ iife (properToJs ctor) [ JSFunction Nothing (Just (properToJs ctor)) [] (JSBlock Nothing [])
261− , JSAssignment Nothing (JSAccessor Nothing "value" (JSVar Nothing (properToJs ctor)))
256+ , JSAssignment Nothing (accessorString "value" (JSVar Nothing (properToJs ctor)))
262 (JSUnary Nothing JSNew $ JSApp Nothing (JSVar Nothing (properToJs ctor)) []) ]
257 (JSUnary Nothing JSNew $ JSApp Nothing (JSVar Nothing (properToJs ctor)) []) ]
263 valueToJs' (Constructor _ _ (ProperName ctor) fields) =
258 valueToJs' (Constructor _ _ (ProperName ctor) fields) =
264 let constructor =
259 let constructor =
265− let body = [ JSAssignment Nothing (JSAccessor Nothing (identToJs f) (JSVar Nothing "this")) (var f) | f <- fields ]
260+ let body = [ JSAssignment Nothing ((accessorString $ mkString $ identToJs f) (JSVar Nothing "this")) (var f) | f <- fields ]
266 in JSFunction Nothing (Just (properToJs ctor)) (identToJs `map` fields) (JSBlock Nothing body)
261 in JSFunction Nothing (Just (properToJs ctor)) (identToJs `map` fields) (JSBlock Nothing body)
267 createFn =
262 createFn =
268 let body = JSUnary Nothing JSNew $ JSApp Nothing (JSVar Nothing (properToJs ctor)) (var `map` fields)
263 let body = JSUnary Nothing JSNew $ JSApp Nothing (JSVar Nothing (properToJs ctor)) (var `map` fields)
269 in foldr (\f inner -> JSFunction Nothing Nothing [identToJs f] (JSBlock Nothing [JSReturn Nothing inner])) body fields
264 in foldr (\f inner -> JSFunction Nothing Nothing [identToJs f] (JSBlock Nothing [JSReturn Nothing inner])) body fields
270 in return $ iife (properToJs ctor) [ constructor
265 in return $ iife (properToJs ctor) [ constructor
271− , JSAssignment Nothing (JSAccessor Nothing "create" (JSVar Nothing (properToJs ctor))) createFn
266+ , JSAssignment Nothing (accessorString "create" (JSVar Nothing (properToJs ctor))) createFn
272 ]
267 ]
273
268
274 iife :: Text -> [JS] -> JS
269 iife :: Text -> [JS] -> JS
@@ -299,7 +294,7 @@ moduleToJs (Module coms mn imps exps foreigns decls) foreign_ =
299 evaluate = JSVariableIntroduction Nothing evaluatedObj (Just obj)
294 evaluate = JSVariableIntroduction Nothing evaluatedObj (Just obj)
300 objAssign = JSVariableIntroduction Nothing newObj (Just $ JSObjectLiteral Nothing [])
295 objAssign = JSVariableIntroduction Nothing newObj (Just $ JSObjectLiteral Nothing [])
301 copy = JSForIn Nothing key jsEvaluatedObj $ JSBlock Nothing [JSIfElse Nothing cond assign Nothing]
296 copy = JSForIn Nothing key jsEvaluatedObj $ JSBlock Nothing [JSIfElse Nothing cond assign Nothing]
302− cond = JSApp Nothing (JSAccessor Nothing "call" (JSAccessor Nothing "hasOwnProperty" (JSObjectLiteral Nothing []))) [jsEvaluatedObj, jsKey]
297+ cond = JSApp Nothing (accessorString "call" (accessorString "hasOwnProperty" (JSObjectLiteral Nothing []))) [jsEvaluatedObj, jsKey]
303 assign = JSBlock Nothing [JSAssignment Nothing (JSIndexer Nothing jsKey jsNewObj) (JSIndexer Nothing jsKey jsEvaluatedObj)]
298 assign = JSBlock Nothing [JSAssignment Nothing (JSIndexer Nothing jsKey jsNewObj) (JSIndexer Nothing jsKey jsEvaluatedObj)]
304 stToAssign (s, js) = JSAssignment Nothing (accessorString s jsNewObj) js
299 stToAssign (s, js) = JSAssignment Nothing (accessorString s jsNewObj) js
305 extend = map stToAssign sts
300 extend = map stToAssign sts
@@ -356,7 +351,7 @@ moduleToJs (Module coms mn imps exps foreigns decls) foreign_ =
356 valueError _ l@(JSNumericLiteral _ _) = l
351 valueError _ l@(JSNumericLiteral _ _) = l
357 valueError _ l@(JSStringLiteral _ _) = l
352 valueError _ l@(JSStringLiteral _ _) = l
358 valueError _ l@(JSBooleanLiteral _ _) = l
353 valueError _ l@(JSBooleanLiteral _ _) = l
359− valueError s _ = JSAccessor Nothing "name" . JSAccessor Nothing "constructor" $ JSVar Nothing s
354+ valueError s _ = accessorString "name" . accessorString "constructor" $ JSVar Nothing s
360
355
361 guardsToJs :: Either [(Guard Ann, Expr Ann)] (Expr Ann) -> m [JS]
356 guardsToJs :: Either [(Guard Ann, Expr Ann)] (Expr Ann) -> m [JS]
362 guardsToJs (Left gs) = forM gs $ \(cond, val) -> do
357 guardsToJs (Left gs) = forM gs $ \(cond, val) -> do
@@ -397,7 +392,7 @@ moduleToJs (Module coms mn imps exps foreigns decls) foreign_ =
397 argVar <- freshName
392 argVar <- freshName
398 done'' <- go remain done'
393 done'' <- go remain done'
399 js <- binderToJs argVar done'' binder
394 js <- binderToJs argVar done'' binder
400− return (JSVariableIntroduction Nothing argVar (Just (JSAccessor Nothing (identToJs field) (JSVar Nothing varName))) : js)
395+ return (JSVariableIntroduction Nothing argVar (Just $ accessorString (mkString $ identToJs field) $ JSVar Nothing varName) : js)
401 binderToJs' _ _ ConstructorBinder{} =
396 binderToJs' _ _ ConstructorBinder{} =
402 internalError "binderToJs: Invalid ConstructorBinder in binderToJs"
397 internalError "binderToJs: Invalid ConstructorBinder in binderToJs"
403 binderToJs' varName done (NamedBinder _ ident binder) = do
398 binderToJs' varName done (NamedBinder _ ident binder) = do
@@ -426,7 +421,7 @@ moduleToJs (Module coms mn imps exps foreigns decls) foreign_ =
426 return (JSVariableIntroduction Nothing propVar (Just (accessorString prop (JSVar Nothing varName))) : js)
421 return (JSVariableIntroduction Nothing propVar (Just (accessorString prop (JSVar Nothing varName))) : js)
427 literalToBinderJS varName done (ArrayLiteral bs) = do
422 literalToBinderJS varName done (ArrayLiteral bs) = do
428 js <- go done 0 bs
423 js <- go done 0 bs
429− return [JSIfElse Nothing (JSBinary Nothing EqualTo (JSAccessor Nothing "length" (JSVar Nothing varName)) (JSNumericLiteral Nothing (Left (fromIntegral $ length bs)))) (JSBlock Nothing js) Nothing]
424+ return [JSIfElse Nothing (JSBinary Nothing EqualTo (accessorString "length" (JSVar Nothing varName)) (JSNumericLiteral Nothing (Left (fromIntegral $ length bs)))) (JSBlock Nothing js) Nothing]
430 where
425 where
431 go :: [JS] -> Integer -> [Binder Ann] -> m [JS]
426 go :: [JS] -> Integer -> [Binder Ann] -> m [JS]
432 go done' _ [] = return done'
427 go done' _ [] = return done'
src/Language/PureScript/CodeGen/JS/AST.hs−9
@@ -159,10 +159,6 @@ data JS
159 --
159 --
160 | JSObjectLiteral (Maybe SourceSpan) [(PSString, JS)]
160 | JSObjectLiteral (Maybe SourceSpan) [(PSString, JS)]
161 -- |
161 -- |
162− -- An object property accessor expression
163− --
164− | JSAccessor (Maybe SourceSpan) Text JS
165− -- |
166 -- A function introduction (optional name, arguments, body)
162 -- A function introduction (optional name, arguments, body)
167 --
163 --
168 | JSFunction (Maybe SourceSpan) (Maybe Text) [Text] JS
164 | JSFunction (Maybe SourceSpan) (Maybe Text) [Text] JS
@@ -259,7 +255,6 @@ withSourceSpan withSpan = go
259 go (JSArrayLiteral _ js) = JSArrayLiteral ss js
255 go (JSArrayLiteral _ js) = JSArrayLiteral ss js
260 go (JSIndexer _ j1 j2) = JSIndexer ss j1 j2
256 go (JSIndexer _ j1 j2) = JSIndexer ss j1 j2
261 go (JSObjectLiteral _ js) = JSObjectLiteral ss js
257 go (JSObjectLiteral _ js) = JSObjectLiteral ss js
262− go (JSAccessor _ prop j) = JSAccessor ss prop j
263 go (JSFunction _ name args j) = JSFunction ss name args j
258 go (JSFunction _ name args j) = JSFunction ss name args j
264 go (JSApp _ j js) = JSApp ss j js
259 go (JSApp _ j js) = JSApp ss j js
265 go (JSVar _ s) = JSVar ss s
260 go (JSVar _ s) = JSVar ss s
@@ -293,7 +288,6 @@ getSourceSpan = go
293 go (JSArrayLiteral ss _) = ss
288 go (JSArrayLiteral ss _) = ss
294 go (JSIndexer ss _ _) = ss
289 go (JSIndexer ss _ _) = ss
295 go (JSObjectLiteral ss _) = ss
290 go (JSObjectLiteral ss _) = ss
296− go (JSAccessor ss _ _) = ss
297 go (JSFunction ss _ _ _) = ss
291 go (JSFunction ss _ _ _) = ss
298 go (JSApp ss _ _) = ss
292 go (JSApp ss _ _) = ss
299 go (JSVar ss _) = ss
293 go (JSVar ss _) = ss
@@ -328,7 +322,6 @@ everywhereOnJS f = go
328 go (JSArrayLiteral ss js) = f (JSArrayLiteral ss (map go js))
322 go (JSArrayLiteral ss js) = f (JSArrayLiteral ss (map go js))
329 go (JSIndexer ss j1 j2) = f (JSIndexer ss (go j1) (go j2))
323 go (JSIndexer ss j1 j2) = f (JSIndexer ss (go j1) (go j2))
330 go (JSObjectLiteral ss js) = f (JSObjectLiteral ss (map (fmap go) js))
324 go (JSObjectLiteral ss js) = f (JSObjectLiteral ss (map (fmap go) js))
331− go (JSAccessor ss prop j) = f (JSAccessor ss prop (go j))
332 go (JSFunction ss name args j) = f (JSFunction ss name args (go j))
325 go (JSFunction ss name args j) = f (JSFunction ss name args (go j))
333 go (JSApp ss j js) = f (JSApp ss (go j) (map go js))
326 go (JSApp ss j js) = f (JSApp ss (go j) (map go js))
334 go (JSConditional ss j1 j2 j3) = f (JSConditional ss (go j1) (go j2) (go j3))
327 go (JSConditional ss j1 j2 j3) = f (JSConditional ss (go j1) (go j2) (go j3))
@@ -359,7 +352,6 @@ everywhereOnJSTopDownM f = f >=> go
359 go (JSArrayLiteral ss js) = JSArrayLiteral ss <$> traverse f' js
352 go (JSArrayLiteral ss js) = JSArrayLiteral ss <$> traverse f' js
360 go (JSIndexer ss j1 j2) = JSIndexer ss <$> f' j1 <*> f' j2
353 go (JSIndexer ss j1 j2) = JSIndexer ss <$> f' j1 <*> f' j2
361 go (JSObjectLiteral ss js) = JSObjectLiteral ss <$> traverse (sndM f') js
354 go (JSObjectLiteral ss js) = JSObjectLiteral ss <$> traverse (sndM f') js
362− go (JSAccessor ss prop j) = JSAccessor ss prop <$> f' j
363 go (JSFunction ss name args j) = JSFunction ss name args <$> f' j
355 go (JSFunction ss name args j) = JSFunction ss name args <$> f' j
364 go (JSApp ss j js) = JSApp ss <$> f' j <*> traverse f' js
356 go (JSApp ss j js) = JSApp ss <$> f' j <*> traverse f' js
365 go (JSConditional ss j1 j2 j3) = JSConditional ss <$> f' j1 <*> f' j2 <*> f' j3
357 go (JSConditional ss j1 j2 j3) = JSConditional ss <$> f' j1 <*> f' j2 <*> f' j3
@@ -386,7 +378,6 @@ everythingOnJS (<>) f = go
386 go j@(JSArrayLiteral _ js) = foldl (<>) (f j) (map go js)
378 go j@(JSArrayLiteral _ js) = foldl (<>) (f j) (map go js)
387 go j@(JSIndexer _ j1 j2) = f j <> go j1 <> go j2
379 go j@(JSIndexer _ j1 j2) = f j <> go j1 <> go j2
388 go j@(JSObjectLiteral _ js) = foldl (<>) (f j) (map (go . snd) js)
380 go j@(JSObjectLiteral _ js) = foldl (<>) (f j) (map (go . snd) js)
389− go j@(JSAccessor _ _ j1) = f j <> go j1
390 go j@(JSFunction _ _ _ j1) = f j <> go j1
381 go j@(JSFunction _ _ _ j1) = f j <> go j1
391 go j@(JSApp _ j1 js) = foldl (<>) (f j <> go j1) (map go js)
382 go j@(JSApp _ j1 js) = foldl (<>) (f j <> go j1) (map go js)
392 go j@(JSConditional _ j1 j2 j3) = f j <> go j1 <> go j2 <> go j3
383 go j@(JSConditional _ j1 j2 j3) = f j <> go j1 <> go j2 <> go j3
src/Language/PureScript/CodeGen/JS/Optimizer/Common.hs+5−12
@@ -11,7 +11,7 @@ import Data.Maybe (fromMaybe)
11
11
12import Language.PureScript.Crash
12import Language.PureScript.Crash
13import Language.PureScript.CodeGen.JS.AST
13import Language.PureScript.CodeGen.JS.AST
14−import Language.PureScript.PSString (mkString)
14+import Language.PureScript.PSString (PSString)
15
15
16applyAll :: [a -> a] -> a -> a
16applyAll :: [a -> a] -> a -> a
17applyAll = foldl' (.) id
17applyAll = foldl' (.) id
@@ -55,7 +55,6 @@ isUsed var1 = everythingOnJS (||) check
55
55
56targetVariable :: JS -> Text
56targetVariable :: JS -> Text
57targetVariable (JSVar _ var) = var
57targetVariable (JSVar _ var) = var
58−targetVariable (JSAccessor _ _ tgt) = targetVariable tgt
59targetVariable (JSIndexer _ _ tgt) = targetVariable tgt
58targetVariable (JSIndexer _ _ tgt) = targetVariable tgt
60targetVariable _ = internalError "Invalid argument to targetVariable"
59targetVariable _ = internalError "Invalid argument to targetVariable"
61
60
@@ -70,16 +69,10 @@ removeFromBlock :: ([JS] -> [JS]) -> JS -> JS
70removeFromBlock go (JSBlock ss sts) = JSBlock ss (go sts)
69removeFromBlock go (JSBlock ss sts) = JSBlock ss (go sts)
71removeFromBlock _ js = js
70removeFromBlock _ js = js
72
71
73−isFn :: (Text, Text) -> JS -> Bool
72+isDict :: (Text, PSString) -> JS -> Bool
74−isFn (moduleName, fnName) (JSAccessor _ x (JSVar _ y)) =
75− x == fnName && y == moduleName
76−isFn (moduleName, fnName) (JSIndexer _ (JSStringLiteral _ x) (JSVar _ y)) =
73+isDict (moduleName, dictName) (JSIndexer _ (JSStringLiteral _ x) (JSVar _ y)) =
77− x == mkString fnName && y == moduleName
78−isFn _ _ = False
79−
80−isDict :: (Text, Text) -> JS -> Bool
81−isDict (moduleName, dictName) (JSAccessor _ x (JSVar _ y)) = x == dictName && y == moduleName
74+ x == dictName && y == moduleName
82isDict _ _ = False
75isDict _ _ = False
83
76
84−isDict' :: [(Text, Text)] -> JS -> Bool
77+isDict' :: [(Text, PSString)] -> JS -> Bool
85isDict' xs js = any (`isDict` js) xs
78isDict' xs js = any (`isDict` js) xs
src/Language/PureScript/CodeGen/JS/Optimizer/Inliner.hs+67−63
@@ -17,9 +17,11 @@ import Control.Monad.Supply.Class (MonadSupply, freshName)
17
17
18import Data.Maybe (fromMaybe)
18import Data.Maybe (fromMaybe)
19import Data.Monoid ((<>))
19import Data.Monoid ((<>))
20+import Data.String (IsString, fromString)
20import Data.Text (Text)
21import Data.Text (Text)
21import qualified Data.Text as T
22import qualified Data.Text as T
22
23
24+import Language.PureScript.PSString (PSString)
23import Language.PureScript.CodeGen.JS.AST
25import Language.PureScript.CodeGen.JS.AST
24import Language.PureScript.CodeGen.JS.Optimizer.Common
26import Language.PureScript.CodeGen.JS.Optimizer.Common
25import qualified Language.PureScript.Constants as C
27import qualified Language.PureScript.Constants as C
@@ -33,7 +35,6 @@ shouldInline (JSVar _ _) = True
33shouldInline (JSNumericLiteral _ _) = True
35shouldInline (JSNumericLiteral _ _) = True
34shouldInline (JSStringLiteral _ _) = True
36shouldInline (JSStringLiteral _ _) = True
35shouldInline (JSBooleanLiteral _ _) = True
37shouldInline (JSBooleanLiteral _ _) = True
36−shouldInline (JSAccessor _ _ val) = shouldInline val
37shouldInline (JSIndexer _ index val) = shouldInline index && shouldInline val
38shouldInline (JSIndexer _ index val) = shouldInline index && shouldInline val
38shouldInline _ = False
39shouldInline _ = False
39
40
@@ -82,17 +83,17 @@ inlineCommonValues = everywhereOnJS convert
82 where
83 where
83 convert :: JS -> JS
84 convert :: JS -> JS
84 convert (JSApp ss fn [dict])
85 convert (JSApp ss fn [dict])
85− | isDict' [semiringNumber, semiringInt] dict && isFn fnZero fn = JSNumericLiteral ss (Left 0)
86+ | isDict' [semiringNumber, semiringInt] dict && isDict fnZero fn = JSNumericLiteral ss (Left 0)
86− | isDict' [semiringNumber, semiringInt] dict && isFn fnOne fn = JSNumericLiteral ss (Left 1)
87+ | isDict' [semiringNumber, semiringInt] dict && isDict fnOne fn = JSNumericLiteral ss (Left 1)
87− | isDict boundedBoolean dict && isFn fnBottom fn = JSBooleanLiteral ss False
88+ | isDict boundedBoolean dict && isDict fnBottom fn = JSBooleanLiteral ss False
88− | isDict boundedBoolean dict && isFn fnTop fn = JSBooleanLiteral ss True
89+ | isDict boundedBoolean dict && isDict fnTop fn = JSBooleanLiteral ss True
89 convert (JSApp ss (JSApp _ fn [dict]) [x])
90 convert (JSApp ss (JSApp _ fn [dict]) [x])
90− | isDict ringInt dict && isFn fnNegate fn = JSBinary ss BitwiseOr (JSUnary ss Negate x) (JSNumericLiteral ss (Left 0))
91+ | isDict ringInt dict && isDict fnNegate fn = JSBinary ss BitwiseOr (JSUnary ss Negate x) (JSNumericLiteral ss (Left 0))
91 convert (JSApp ss (JSApp _ (JSApp _ fn [dict]) [x]) [y])
92 convert (JSApp ss (JSApp _ (JSApp _ fn [dict]) [x]) [y])
92− | isDict semiringInt dict && isFn fnAdd fn = intOp ss Add x y
93+ | isDict semiringInt dict && isDict fnAdd fn = intOp ss Add x y
93− | isDict semiringInt dict && isFn fnMultiply fn = intOp ss Multiply x y
94+ | isDict semiringInt dict && isDict fnMultiply fn = intOp ss Multiply x y
94− | isDict euclideanRingInt dict && isFn fnDivide fn = intOp ss Divide x y
95+ | isDict euclideanRingInt dict && isDict fnDivide fn = intOp ss Divide x y
95− | isDict ringInt dict && isFn fnSubtract fn = intOp ss Subtract x y
96+ | isDict ringInt dict && isDict fnSubtract fn = intOp ss Subtract x y
96 convert other = other
97 convert other = other
97 fnZero = (C.dataSemiring, C.zero)
98 fnZero = (C.dataSemiring, C.zero)
98 fnOne = (C.dataSemiring, C.one)
99 fnOne = (C.dataSemiring, C.one)
@@ -168,29 +169,29 @@ inlineCommonOperators = applyAll $
168 ] ++
169 ] ++
169 [ fn | i <- [0..10], fn <- [ mkFn i, runFn i ] ]
170 [ fn | i <- [0..10], fn <- [ mkFn i, runFn i ] ]
170 where
171 where
171− binary :: (Text, Text) -> (Text, Text) -> BinaryOperator -> JS -> JS
172+ binary :: (Text, PSString) -> (Text, PSString) -> BinaryOperator -> JS -> JS
172 binary dict fns op = everywhereOnJS convert
173 binary dict fns op = everywhereOnJS convert
173 where
174 where
174 convert :: JS -> JS
175 convert :: JS -> JS
175− convert (JSApp ss (JSApp _ (JSApp _ fn [dict']) [x]) [y]) | isDict dict dict' && isFn fns fn = JSBinary ss op x y
176+ convert (JSApp ss (JSApp _ (JSApp _ fn [dict']) [x]) [y]) | isDict dict dict' && isDict fns fn = JSBinary ss op x y
176 convert other = other
177 convert other = other
177− binary' :: Text -> Text -> BinaryOperator -> JS -> JS
178+ binary' :: Text -> PSString -> BinaryOperator -> JS -> JS
178 binary' moduleName opString op = everywhereOnJS convert
179 binary' moduleName opString op = everywhereOnJS convert
179 where
180 where
180 convert :: JS -> JS
181 convert :: JS -> JS
181− convert (JSApp ss (JSApp _ fn [x]) [y]) | isFn (moduleName, opString) fn = JSBinary ss op x y
182+ convert (JSApp ss (JSApp _ fn [x]) [y]) | isDict (moduleName, opString) fn = JSBinary ss op x y
182 convert other = other
183 convert other = other
183− unary :: (Text, Text) -> (Text, Text) -> UnaryOperator -> JS -> JS
184+ unary :: (Text, PSString) -> (Text, PSString) -> UnaryOperator -> JS -> JS
184 unary dicts fns op = everywhereOnJS convert
185 unary dicts fns op = everywhereOnJS convert
185 where
186 where
186 convert :: JS -> JS
187 convert :: JS -> JS
187− convert (JSApp ss (JSApp _ fn [dict']) [x]) | isDict dicts dict' && isFn fns fn = JSUnary ss op x
188+ convert (JSApp ss (JSApp _ fn [dict']) [x]) | isDict dicts dict' && isDict fns fn = JSUnary ss op x
188 convert other = other
189 convert other = other
189− unary' :: Text -> Text -> UnaryOperator -> JS -> JS
190+ unary' :: Text -> PSString -> UnaryOperator -> JS -> JS
190 unary' moduleName fnName op = everywhereOnJS convert
191 unary' moduleName fnName op = everywhereOnJS convert
191 where
192 where
192 convert :: JS -> JS
193 convert :: JS -> JS
193− convert (JSApp ss fn [x]) | isFn (moduleName, fnName) fn = JSUnary ss op x
194+ convert (JSApp ss fn [x]) | isDict (moduleName, fnName) fn = JSUnary ss op x
194 convert other = other
195 convert other = other
195 mkFn :: Int -> JS -> JS
196 mkFn :: Int -> JS -> JS
196 mkFn 0 = everywhereOnJS convert
197 mkFn 0 = everywhereOnJS convert
@@ -214,7 +215,8 @@ inlineCommonOperators = applyAll $
214
215
215 isNFn :: Text -> Int -> JS -> Bool
216 isNFn :: Text -> Int -> JS -> Bool
216 isNFn prefix n (JSVar _ name) = name == (prefix <> T.pack (show n))
217 isNFn prefix n (JSVar _ name) = name == (prefix <> T.pack (show n))
217− isNFn prefix n (JSAccessor _ name (JSVar _ dataFunctionUncurried)) | dataFunctionUncurried == C.dataFunctionUncurried = name == (prefix <> T.pack (show n))
218+ isNFn prefix n (JSIndexer _ (JSStringLiteral _ name) (JSVar _ dataFunctionUncurried)) | dataFunctionUncurried == C.dataFunctionUncurried =
219+ name == fromString (T.unpack prefix <> show n)
218 isNFn _ _ _ = False
220 isNFn _ _ _ = False
219
221
220 runFn :: Int -> JS -> JS
222 runFn :: Int -> JS -> JS
@@ -235,12 +237,14 @@ inlineCommonOperators = applyAll $
235 convert (JSApp _ (JSApp _ op' [x]) [y]) | p op' = f x y
237 convert (JSApp _ (JSApp _ op' [x]) [y]) | p op' = f x y
236 convert other = other
238 convert other = other
237
239
238− isModFn :: (Text, Text) -> JS -> Bool
240+ isModFn :: (Text, PSString) -> JS -> Bool
239− isModFn (m, op) (JSAccessor _ op' (JSVar _ m')) = m == m' && op == op'
241+ isModFn (m, op) (JSIndexer _ (JSStringLiteral _ op') (JSVar _ m')) =
242+ m == m' && op == op'
240 isModFn _ _ = False
243 isModFn _ _ = False
241
244
242− isModFnWithDict :: (Text, Text) -> JS -> Bool
245+ isModFnWithDict :: (Text, PSString) -> JS -> Bool
243− isModFnWithDict (m, op) (JSApp _ (JSAccessor _ op' (JSVar _ m')) [JSVar _ _]) = m == m' && op == op'
246+ isModFnWithDict (m, op) (JSApp _ (JSIndexer _ (JSStringLiteral _ op') (JSVar _ m')) [JSVar _ _]) =
247+ m == m' && op == op'
244 isModFnWithDict _ _ = False
248 isModFnWithDict _ _ = False
245
249
246-- (f <<< g $ x) = f (g x)
250-- (f <<< g $ x) = f (g x)
@@ -261,118 +265,118 @@ inlineFnComposition = everywhereOnJSTopDownM convert
261 return $ JSFunction ss Nothing [arg] (JSBlock ss [JSReturn Nothing $ JSApp Nothing y [JSApp Nothing x [JSVar Nothing arg]]])
265 return $ JSFunction ss Nothing [arg] (JSBlock ss [JSReturn Nothing $ JSApp Nothing y [JSApp Nothing x [JSVar Nothing arg]]])
262 convert other = return other
266 convert other = return other
263 isFnCompose :: JS -> JS -> Bool
267 isFnCompose :: JS -> JS -> Bool
264− isFnCompose dict' fn = isDict semigroupoidFn dict' && isFn fnCompose fn
268+ isFnCompose dict' fn = isDict semigroupoidFn dict' && isDict fnCompose fn
265 isFnComposeFlipped :: JS -> JS -> Bool
269 isFnComposeFlipped :: JS -> JS -> Bool
266− isFnComposeFlipped dict' fn = isDict semigroupoidFn dict' && isFn fnComposeFlipped fn
270+ isFnComposeFlipped dict' fn = isDict semigroupoidFn dict' && isDict fnComposeFlipped fn
267− fnCompose :: (Text, Text)
271+ fnCompose :: forall a b. (IsString a, IsString b) => (a, b)
268 fnCompose = (C.controlSemigroupoid, C.compose)
272 fnCompose = (C.controlSemigroupoid, C.compose)
269− fnComposeFlipped :: (Text, Text)
273+ fnComposeFlipped :: forall a b. (IsString a, IsString b) => (a, b)
270 fnComposeFlipped = (C.controlSemigroupoid, C.composeFlipped)
274 fnComposeFlipped = (C.controlSemigroupoid, C.composeFlipped)
271
275
272−semiringNumber :: (Text, Text)
276+semiringNumber :: forall a b. (IsString a, IsString b) => (a, b)
273semiringNumber = (C.dataSemiring, C.semiringNumber)
277semiringNumber = (C.dataSemiring, C.semiringNumber)
274
278
275−semiringInt :: (Text, Text)
279+semiringInt :: forall a b. (IsString a, IsString b) => (a, b)
276semiringInt = (C.dataSemiring, C.semiringInt)
280semiringInt = (C.dataSemiring, C.semiringInt)
277
281
278−ringNumber :: (Text, Text)
282+ringNumber :: forall a b. (IsString a, IsString b) => (a, b)
279ringNumber = (C.dataRing, C.ringNumber)
283ringNumber = (C.dataRing, C.ringNumber)
280
284
281−ringInt :: (Text, Text)
285+ringInt :: forall a b. (IsString a, IsString b) => (a, b)
282ringInt = (C.dataRing, C.ringInt)
286ringInt = (C.dataRing, C.ringInt)
283
287
284−euclideanRingNumber :: (Text, Text)
288+euclideanRingNumber :: forall a b. (IsString a, IsString b) => (a, b)
285euclideanRingNumber = (C.dataEuclideanRing, C.euclideanRingNumber)
289euclideanRingNumber = (C.dataEuclideanRing, C.euclideanRingNumber)
286
290
287−euclideanRingInt :: (Text, Text)
291+euclideanRingInt :: forall a b. (IsString a, IsString b) => (a, b)
288euclideanRingInt = (C.dataEuclideanRing, C.euclideanRingInt)
292euclideanRingInt = (C.dataEuclideanRing, C.euclideanRingInt)
289
293
290−eqNumber :: (Text, Text)
294+eqNumber :: forall a b. (IsString a, IsString b) => (a, b)
291eqNumber = (C.dataEq, C.eqNumber)
295eqNumber = (C.dataEq, C.eqNumber)
292
296
293−eqInt :: (Text, Text)
297+eqInt :: forall a b. (IsString a, IsString b) => (a, b)
294eqInt = (C.dataEq, C.eqInt)
298eqInt = (C.dataEq, C.eqInt)
295
299
296−eqString :: (Text, Text)
300+eqString :: forall a b. (IsString a, IsString b) => (a, b)
297eqString = (C.dataEq, C.eqString)
301eqString = (C.dataEq, C.eqString)
298
302
299−eqChar :: (Text, Text)
303+eqChar :: forall a b. (IsString a, IsString b) => (a, b)
300eqChar = (C.dataEq, C.eqChar)
304eqChar = (C.dataEq, C.eqChar)
301
305
302−eqBoolean :: (Text, Text)
306+eqBoolean :: forall a b. (IsString a, IsString b) => (a, b)
303eqBoolean = (C.dataEq, C.eqBoolean)
307eqBoolean = (C.dataEq, C.eqBoolean)
304
308
305−ordBoolean :: (Text, Text)
309+ordBoolean :: forall a b. (IsString a, IsString b) => (a, b)
306ordBoolean = (C.dataOrd, C.ordBoolean)
310ordBoolean = (C.dataOrd, C.ordBoolean)
307
311
308−ordNumber :: (Text, Text)
312+ordNumber :: forall a b. (IsString a, IsString b) => (a, b)
309ordNumber = (C.dataOrd, C.ordNumber)
313ordNumber = (C.dataOrd, C.ordNumber)
310
314
311−ordInt :: (Text, Text)
315+ordInt :: forall a b. (IsString a, IsString b) => (a, b)
312ordInt = (C.dataOrd, C.ordInt)
316ordInt = (C.dataOrd, C.ordInt)
313
317
314−ordString :: (Text, Text)
318+ordString :: forall a b. (IsString a, IsString b) => (a, b)
315ordString = (C.dataOrd, C.ordString)
319ordString = (C.dataOrd, C.ordString)
316
320
317−ordChar :: (Text, Text)
321+ordChar :: forall a b. (IsString a, IsString b) => (a, b)
318ordChar = (C.dataOrd, C.ordChar)
322ordChar = (C.dataOrd, C.ordChar)
319
323
320−semigroupString :: (Text, Text)
324+semigroupString :: forall a b. (IsString a, IsString b) => (a, b)
321semigroupString = (C.dataSemigroup, C.semigroupString)
325semigroupString = (C.dataSemigroup, C.semigroupString)
322
326
323−boundedBoolean :: (Text, Text)
327+boundedBoolean :: forall a b. (IsString a, IsString b) => (a, b)
324boundedBoolean = (C.dataBounded, C.boundedBoolean)
328boundedBoolean = (C.dataBounded, C.boundedBoolean)
325
329
326−heytingAlgebraBoolean :: (Text, Text)
330+heytingAlgebraBoolean :: forall a b. (IsString a, IsString b) => (a, b)
327heytingAlgebraBoolean = (C.dataHeytingAlgebra, C.heytingAlgebraBoolean)
331heytingAlgebraBoolean = (C.dataHeytingAlgebra, C.heytingAlgebraBoolean)
328
332
329−semigroupoidFn :: (Text, Text)
333+semigroupoidFn :: forall a b. (IsString a, IsString b) => (a, b)
330semigroupoidFn = (C.controlSemigroupoid, C.semigroupoidFn)
334semigroupoidFn = (C.controlSemigroupoid, C.semigroupoidFn)
331
335
332−opAdd :: (Text, Text)
336+opAdd :: forall a b. (IsString a, IsString b) => (a, b)
333opAdd = (C.dataSemiring, C.add)
337opAdd = (C.dataSemiring, C.add)
334
338
335−opMul :: (Text, Text)
339+opMul :: forall a b. (IsString a, IsString b) => (a, b)
336opMul = (C.dataSemiring, C.mul)
340opMul = (C.dataSemiring, C.mul)
337
341
338−opEq :: (Text, Text)
342+opEq :: forall a b. (IsString a, IsString b) => (a, b)
339opEq = (C.dataEq, C.eq)
343opEq = (C.dataEq, C.eq)
340
344
341−opNotEq :: (Text, Text)
345+opNotEq :: forall a b. (IsString a, IsString b) => (a, b)
342opNotEq = (C.dataEq, C.notEq)
346opNotEq = (C.dataEq, C.notEq)
343
347
344−opLessThan :: (Text, Text)
348+opLessThan :: forall a b. (IsString a, IsString b) => (a, b)
345opLessThan = (C.dataOrd, C.lessThan)
349opLessThan = (C.dataOrd, C.lessThan)
346
350
347−opLessThanOrEq :: (Text, Text)
351+opLessThanOrEq :: forall a b. (IsString a, IsString b) => (a, b)
348opLessThanOrEq = (C.dataOrd, C.lessThanOrEq)
352opLessThanOrEq = (C.dataOrd, C.lessThanOrEq)
349
353
350−opGreaterThan :: (Text, Text)
354+opGreaterThan :: forall a b. (IsString a, IsString b) => (a, b)
351opGreaterThan = (C.dataOrd, C.greaterThan)
355opGreaterThan = (C.dataOrd, C.greaterThan)
352
356
353−opGreaterThanOrEq :: (Text, Text)
357+opGreaterThanOrEq :: forall a b. (IsString a, IsString b) => (a, b)
354opGreaterThanOrEq = (C.dataOrd, C.greaterThanOrEq)
358opGreaterThanOrEq = (C.dataOrd, C.greaterThanOrEq)
355
359
356−opAppend :: (Text, Text)
360+opAppend :: forall a b. (IsString a, IsString b) => (a, b)
357opAppend = (C.dataSemigroup, C.append)
361opAppend = (C.dataSemigroup, C.append)
358
362
359−opSub :: (Text, Text)
363+opSub :: forall a b. (IsString a, IsString b) => (a, b)
360opSub = (C.dataRing, C.sub)
364opSub = (C.dataRing, C.sub)
361
365
362−opNegate :: (Text, Text)
366+opNegate :: forall a b. (IsString a, IsString b) => (a, b)
363opNegate = (C.dataRing, C.negate)
367opNegate = (C.dataRing, C.negate)
364
368
365−opDiv :: (Text, Text)
369+opDiv :: forall a b. (IsString a, IsString b) => (a, b)
366opDiv = (C.dataEuclideanRing, C.div)
370opDiv = (C.dataEuclideanRing, C.div)
367
371
368−opMod :: (Text, Text)
372+opMod :: forall a b. (IsString a, IsString b) => (a, b)
369opMod = (C.dataEuclideanRing, C.mod)
373opMod = (C.dataEuclideanRing, C.mod)
370
374
371−opConj :: (Text, Text)
375+opConj :: forall a b. (IsString a, IsString b) => (a, b)
372opConj = (C.dataHeytingAlgebra, C.conj)
376opConj = (C.dataHeytingAlgebra, C.conj)
373
377
374−opDisj :: (Text, Text)
378+opDisj :: forall a b. (IsString a, IsString b) => (a, b)
375opDisj = (C.dataHeytingAlgebra, C.disj)
379opDisj = (C.dataHeytingAlgebra, C.disj)
376
380
377−opNot :: (Text, Text)
381+opNot :: forall a b. (IsString a, IsString b) => (a, b)
378opNot = (C.dataHeytingAlgebra, C.not)
382opNot = (C.dataHeytingAlgebra, C.not)
src/Language/PureScript/CodeGen/JS/Optimizer/MagicDo.hs+7−7
@@ -64,11 +64,11 @@ magicDo' = everywhereOnJS undo . everywhereOnJSTopDown convert
64 isPure (JSApp _ fn [dict]) | isDict (C.eff, C.applicativeEffDictionary) dict && isPurePoly fn = True
64 isPure (JSApp _ fn [dict]) | isDict (C.eff, C.applicativeEffDictionary) dict && isPurePoly fn = True
65 isPure _ = False
65 isPure _ = False
66 -- Check if an expression represents the polymorphic >>= function
66 -- Check if an expression represents the polymorphic >>= function
67− isBindPoly = isFn (C.controlBind, C.bind)
67+ isBindPoly = isDict (C.controlBind, C.bind)
68 -- Check if an expression represents the polymorphic pure or return function
68 -- Check if an expression represents the polymorphic pure or return function
69− isPurePoly = isFn (C.controlApplicative, C.pure')
69+ isPurePoly = isDict (C.controlApplicative, C.pure')
70 -- Check if an expression represents a function in the Eff module
70 -- Check if an expression represents a function in the Eff module
71− isEffFunc name (JSAccessor _ name' (JSVar _ eff)) = eff == C.eff && name == name'
71+ isEffFunc name (JSIndexer _ (JSStringLiteral _ name') (JSVar _ eff)) = eff == C.eff && name == name'
72 isEffFunc _ _ = False
72 isEffFunc _ _ = False
73
73
74 -- Remove __do function applications which remain after desugaring
74 -- Remove __do function applications which remain after desugaring
@@ -107,14 +107,14 @@ inlineST = everywhereOnJS convertBlock
107 convert agg (JSApp s1 f [arg]) | isSTFunc C.newSTRef f =
107 convert agg (JSApp s1 f [arg]) | isSTFunc C.newSTRef f =
108 JSFunction s1 Nothing [] (JSBlock s1 [JSReturn s1 $ if agg then arg else JSObjectLiteral s1 [(mkString C.stRefValue, arg)]])
108 JSFunction s1 Nothing [] (JSBlock s1 [JSReturn s1 $ if agg then arg else JSObjectLiteral s1 [(mkString C.stRefValue, arg)]])
109 convert agg (JSApp _ (JSApp s1 f [ref]) []) | isSTFunc C.readSTRef f =
109 convert agg (JSApp _ (JSApp s1 f [ref]) []) | isSTFunc C.readSTRef f =
110− if agg then ref else JSAccessor s1 C.stRefValue ref
110+ if agg then ref else JSIndexer s1 (JSStringLiteral s1 C.stRefValue) ref
111 convert agg (JSApp _ (JSApp _ (JSApp s1 f [ref]) [arg]) []) | isSTFunc C.writeSTRef f =
111 convert agg (JSApp _ (JSApp _ (JSApp s1 f [ref]) [arg]) []) | isSTFunc C.writeSTRef f =
112− if agg then JSAssignment s1 ref arg else JSAssignment s1 (JSAccessor s1 C.stRefValue ref) arg
112+ if agg then JSAssignment s1 ref arg else JSAssignment s1 (JSIndexer s1 (JSStringLiteral s1 C.stRefValue) ref) arg
113 convert agg (JSApp _ (JSApp _ (JSApp s1 f [ref]) [func]) []) | isSTFunc C.modifySTRef f =
113 convert agg (JSApp _ (JSApp _ (JSApp s1 f [ref]) [func]) []) | isSTFunc C.modifySTRef f =
114− if agg then JSAssignment s1 ref (JSApp s1 func [ref]) else JSAssignment s1 (JSAccessor s1 C.stRefValue ref) (JSApp s1 func [JSAccessor s1 C.stRefValue ref])
114+ if agg then JSAssignment s1 ref (JSApp s1 func [ref]) else JSAssignment s1 (JSIndexer s1 (JSStringLiteral s1 C.stRefValue) ref) (JSApp s1 func [JSIndexer s1 (JSStringLiteral s1 C.stRefValue) ref])
115 convert _ other = other
115 convert _ other = other
116 -- Check if an expression represents a function in the ST module
116 -- Check if an expression represents a function in the ST module
117− isSTFunc name (JSAccessor _ name' (JSVar _ st)) = st == C.st && name == name'
117+ isSTFunc name (JSIndexer _ (JSStringLiteral _ name') (JSVar _ st)) = st == C.st && name == name'
118 isSTFunc _ _ = False
118 isSTFunc _ _ = False
119 -- Find all ST Refs initialized in this block
119 -- Find all ST Refs initialized in this block
120 findSTRefsIn = everythingOnJS (++) isSTRef
120 findSTRefsIn = everythingOnJS (++) isSTRef
src/Language/PureScript/Constants.hs+127−127
@@ -2,319 +2,319 @@
2module Language.PureScript.Constants where
2module Language.PureScript.Constants where
3
3
4import Prelude.Compat
4import Prelude.Compat
5−import Data.Text (Text)
5+import Data.String (IsString)
6import Language.PureScript.Names
6import Language.PureScript.Names
7
7
8-- Operators
8-- Operators
9
9
10−($) :: Text
10+($) :: forall a. (IsString a) => a
11($) = "$"
11($) = "$"
12
12
13−apply :: Text
13+apply :: forall a. (IsString a) => a
14apply = "apply"
14apply = "apply"
15
15
16−(#) :: Text
16+(#) :: forall a. (IsString a) => a
17(#) = "#"
17(#) = "#"
18
18
19−applyFlipped :: Text
19+applyFlipped :: forall a. (IsString a) => a
20applyFlipped = "applyFlipped"
20applyFlipped = "applyFlipped"
21
21
22−(<>) :: Text
22+(<>) :: forall a. (IsString a) => a
23(<>) = "<>"
23(<>) = "<>"
24
24
25−(++) :: Text
25+(++) :: forall a. (IsString a) => a
26(++) = "++"
26(++) = "++"
27
27
28−append :: Text
28+append :: forall a. (IsString a) => a
29append = "append"
29append = "append"
30
30
31−(>>=) :: Text
31+(>>=) :: forall a. (IsString a) => a
32(>>=) = ">>="
32(>>=) = ">>="
33
33
34−bind :: Text
34+bind :: forall a. (IsString a) => a
35bind = "bind"
35bind = "bind"
36
36
37−(+) :: Text
37+(+) :: forall a. (IsString a) => a
38(+) = "+"
38(+) = "+"
39
39
40−add :: Text
40+add :: forall a. (IsString a) => a
41add = "add"
41add = "add"
42
42
43−(-) :: Text
43+(-) :: forall a. (IsString a) => a
44(-) = "-"
44(-) = "-"
45
45
46−sub :: Text
46+sub :: forall a. (IsString a) => a
47sub = "sub"
47sub = "sub"
48
48
49−(*) :: Text
49+(*) :: forall a. (IsString a) => a
50(*) = "*"
50(*) = "*"
51
51
52−mul :: Text
52+mul :: forall a. (IsString a) => a
53mul = "mul"
53mul = "mul"
54
54
55−(/) :: Text
55+(/) :: forall a. (IsString a) => a
56(/) = "/"
56(/) = "/"
57
57
58−div :: Text
58+div :: forall a. (IsString a) => a
59div = "div"
59div = "div"
60
60
61−(%) :: Text
61+(%) :: forall a. (IsString a) => a
62(%) = "%"
62(%) = "%"
63
63
64−mod :: Text
64+mod :: forall a. (IsString a) => a
65mod = "mod"
65mod = "mod"
66
66
67−(<) :: Text
67+(<) :: forall a. (IsString a) => a
68(<) = "<"
68(<) = "<"
69
69
70−lessThan :: Text
70+lessThan :: forall a. (IsString a) => a
71lessThan = "lessThan"
71lessThan = "lessThan"
72
72
73−(>) :: Text
73+(>) :: forall a. (IsString a) => a
74(>) = ">"
74(>) = ">"
75
75
76−greaterThan :: Text
76+greaterThan :: forall a. (IsString a) => a
77greaterThan = "greaterThan"
77greaterThan = "greaterThan"
78
78
79−(<=) :: Text
79+(<=) :: forall a. (IsString a) => a
80(<=) = "<="
80(<=) = "<="
81
81
82−lessThanOrEq :: Text
82+lessThanOrEq :: forall a. (IsString a) => a
83lessThanOrEq = "lessThanOrEq"
83lessThanOrEq = "lessThanOrEq"
84
84
85−(>=) :: Text
85+(>=) :: forall a. (IsString a) => a
86(>=) = ">="
86(>=) = ">="
87
87
88−greaterThanOrEq :: Text
88+greaterThanOrEq :: forall a. (IsString a) => a
89greaterThanOrEq = "greaterThanOrEq"
89greaterThanOrEq = "greaterThanOrEq"
90
90
91−(==) :: Text
91+(==) :: forall a. (IsString a) => a
92(==) = "=="
92(==) = "=="
93
93
94−eq :: Text
94+eq :: forall a. (IsString a) => a
95eq = "eq"
95eq = "eq"
96
96
97−(/=) :: Text
97+(/=) :: forall a. (IsString a) => a
98(/=) = "/="
98(/=) = "/="
99
99
100−notEq :: Text
100+notEq :: forall a. (IsString a) => a
101notEq = "notEq"
101notEq = "notEq"
102
102
103−compare :: Text
103+compare :: forall a. (IsString a) => a
104compare = "compare"
104compare = "compare"
105
105
106−(&&) :: Text
106+(&&) :: forall a. (IsString a) => a
107(&&) = "&&"
107(&&) = "&&"
108
108
109−conj :: Text
109+conj :: forall a. (IsString a) => a
110conj = "conj"
110conj = "conj"
111
111
112−(||) :: Text
112+(||) :: forall a. (IsString a) => a
113(||) = "||"
113(||) = "||"
114
114
115−disj :: Text
115+disj :: forall a. (IsString a) => a
116disj = "disj"
116disj = "disj"
117
117
118−unsafeIndex :: Text
118+unsafeIndex :: forall a. (IsString a) => a
119unsafeIndex = "unsafeIndex"
119unsafeIndex = "unsafeIndex"
120
120
121−or :: Text
121+or :: forall a. (IsString a) => a
122or = "or"
122or = "or"
123
123
124−and :: Text
124+and :: forall a. (IsString a) => a
125and = "and"
125and = "and"
126
126
127−xor :: Text
127+xor :: forall a. (IsString a) => a
128xor = "xor"
128xor = "xor"
129
129
130−(<<<) :: Text
130+(<<<) :: forall a. (IsString a) => a
131(<<<) = "<<<"
131(<<<) = "<<<"
132
132
133−compose :: Text
133+compose :: forall a. (IsString a) => a
134compose = "compose"
134compose = "compose"
135
135
136−(>>>) :: Text
136+(>>>) :: forall a. (IsString a) => a
137(>>>) = ">>>"
137(>>>) = ">>>"
138
138
139−composeFlipped :: Text
139+composeFlipped :: forall a. (IsString a) => a
140composeFlipped = "composeFlipped"
140composeFlipped = "composeFlipped"
141
141
142−map :: Text
142+map :: forall a. (IsString a) => a
143map = "map"
143map = "map"
144
144
145-- Functions
145-- Functions
146
146
147−negate :: Text
147+negate :: forall a. (IsString a) => a
148negate = "negate"
148negate = "negate"
149
149
150−not :: Text
150+not :: forall a. (IsString a) => a
151not = "not"
151not = "not"
152
152
153−shl :: Text
153+shl :: forall a. (IsString a) => a
154shl = "shl"
154shl = "shl"
155
155
156−shr :: Text
156+shr :: forall a. (IsString a) => a
157shr = "shr"
157shr = "shr"
158
158
159−zshr :: Text
159+zshr :: forall a. (IsString a) => a
160zshr = "zshr"
160zshr = "zshr"
161
161
162−complement :: Text
162+complement :: forall a. (IsString a) => a
163complement = "complement"
163complement = "complement"
164
164
165-- Prelude Values
165-- Prelude Values
166
166
167−zero :: Text
167+zero :: forall a. (IsString a) => a
168zero = "zero"
168zero = "zero"
169
169
170−one :: Text
170+one :: forall a. (IsString a) => a
171one = "one"
171one = "one"
172
172
173−bottom :: Text
173+bottom :: forall a. (IsString a) => a
174bottom = "bottom"
174bottom = "bottom"
175
175
176−top :: Text
176+top :: forall a. (IsString a) => a
177top = "top"
177top = "top"
178
178
179−return :: Text
179+return :: forall a. (IsString a) => a
180return = "return"
180return = "return"
181
181
182−pure' :: Text
182+pure' :: forall a. (IsString a) => a
183pure' = "pure"
183pure' = "pure"
184
184
185−returnEscaped :: Text
185+returnEscaped :: forall a. (IsString a) => a
186returnEscaped = "$return"
186returnEscaped = "$return"
187
187
188−untilE :: Text
188+untilE :: forall a. (IsString a) => a
189untilE = "untilE"
189untilE = "untilE"
190
190
191−whileE :: Text
191+whileE :: forall a. (IsString a) => a
192whileE = "whileE"
192whileE = "whileE"
193
193
194−runST :: Text
194+runST :: forall a. (IsString a) => a
195runST = "runST"
195runST = "runST"
196
196
197−stRefValue :: Text
197+stRefValue :: forall a. (IsString a) => a
198stRefValue = "value"
198stRefValue = "value"
199
199
200−newSTRef :: Text
200+newSTRef :: forall a. (IsString a) => a
201newSTRef = "newSTRef"
201newSTRef = "newSTRef"
202
202
203−readSTRef :: Text
203+readSTRef :: forall a. (IsString a) => a
204readSTRef = "readSTRef"
204readSTRef = "readSTRef"
205
205
206−writeSTRef :: Text
206+writeSTRef :: forall a. (IsString a) => a
207writeSTRef = "writeSTRef"
207writeSTRef = "writeSTRef"
208
208
209−modifySTRef :: Text
209+modifySTRef :: forall a. (IsString a) => a
210modifySTRef = "modifySTRef"
210modifySTRef = "modifySTRef"
211
211
212−mkFn :: Text
212+mkFn :: forall a. (IsString a) => a
213mkFn = "mkFn"
213mkFn = "mkFn"
214
214
215−runFn :: Text
215+runFn :: forall a. (IsString a) => a
216runFn = "runFn"
216runFn = "runFn"
217
217
218−unit :: Text
218+unit :: forall a. (IsString a) => a
219unit = "unit"
219unit = "unit"
220
220
221-- Prim values
221-- Prim values
222
222
223−undefined :: Text
223+undefined :: forall a. (IsString a) => a
224undefined = "undefined"
224undefined = "undefined"
225
225
226-- Type Class Dictionary Names
226-- Type Class Dictionary Names
227
227
228−monadEffDictionary :: Text
228+monadEffDictionary :: forall a. (IsString a) => a
229monadEffDictionary = "monadEff"
229monadEffDictionary = "monadEff"
230
230
231−applicativeEffDictionary :: Text
231+applicativeEffDictionary :: forall a. (IsString a) => a
232applicativeEffDictionary = "applicativeEff"
232applicativeEffDictionary = "applicativeEff"
233
233
234−bindEffDictionary :: Text
234+bindEffDictionary :: forall a. (IsString a) => a
235bindEffDictionary = "bindEff"
235bindEffDictionary = "bindEff"
236
236
237−semiringNumber :: Text
237+semiringNumber :: forall a. (IsString a) => a
238semiringNumber = "semiringNumber"
238semiringNumber = "semiringNumber"
239
239
240−semiringInt :: Text
240+semiringInt :: forall a. (IsString a) => a
241semiringInt = "semiringInt"
241semiringInt = "semiringInt"
242
242
243−ringNumber :: Text
243+ringNumber :: forall a. (IsString a) => a
244ringNumber = "ringNumber"
244ringNumber = "ringNumber"
245
245
246−ringInt :: Text
246+ringInt :: forall a. (IsString a) => a
247ringInt = "ringInt"
247ringInt = "ringInt"
248
248
249−moduloSemiringNumber :: Text
249+moduloSemiringNumber :: forall a. (IsString a) => a
250moduloSemiringNumber = "moduloSemiringNumber"
250moduloSemiringNumber = "moduloSemiringNumber"
251
251
252−moduloSemiringInt :: Text
252+moduloSemiringInt :: forall a. (IsString a) => a
253moduloSemiringInt = "moduloSemiringInt"
253moduloSemiringInt = "moduloSemiringInt"
254
254
255−euclideanRingNumber :: Text
255+euclideanRingNumber :: forall a. (IsString a) => a
256euclideanRingNumber = "euclideanRingNumber"
256euclideanRingNumber = "euclideanRingNumber"
257
257
258−euclideanRingInt :: Text
258+euclideanRingInt :: forall a. (IsString a) => a
259euclideanRingInt = "euclideanRingInt"
259euclideanRingInt = "euclideanRingInt"
260
260
261−ordBoolean :: Text
261+ordBoolean :: forall a. (IsString a) => a
262ordBoolean = "ordBoolean"
262ordBoolean = "ordBoolean"
263
263
264−ordNumber :: Text
264+ordNumber :: forall a. (IsString a) => a
265ordNumber = "ordNumber"
265ordNumber = "ordNumber"
266
266
267−ordInt :: Text
267+ordInt :: forall a. (IsString a) => a
268ordInt = "ordInt"
268ordInt = "ordInt"
269
269
270−ordString :: Text
270+ordString :: forall a. (IsString a) => a
271ordString = "ordString"
271ordString = "ordString"
272
272
273−ordChar :: Text
273+ordChar :: forall a. (IsString a) => a
274ordChar = "ordChar"
274ordChar = "ordChar"
275
275
276−eqNumber :: Text
276+eqNumber :: forall a. (IsString a) => a
277eqNumber = "eqNumber"
277eqNumber = "eqNumber"
278
278
279−eqInt :: Text
279+eqInt :: forall a. (IsString a) => a
280eqInt = "eqInt"
280eqInt = "eqInt"
281
281
282−eqString :: Text
282+eqString :: forall a. (IsString a) => a
283eqString = "eqString"
283eqString = "eqString"
284
284
285−eqChar :: Text
285+eqChar :: forall a. (IsString a) => a
286eqChar = "eqChar"
286eqChar = "eqChar"
287
287
288−eqBoolean :: Text
288+eqBoolean :: forall a. (IsString a) => a
289eqBoolean = "eqBoolean"
289eqBoolean = "eqBoolean"
290
290
291−boundedBoolean :: Text
291+boundedBoolean :: forall a. (IsString a) => a
292boundedBoolean = "boundedBoolean"
292boundedBoolean = "boundedBoolean"
293
293
294−booleanAlgebraBoolean :: Text
294+booleanAlgebraBoolean :: forall a. (IsString a) => a
295booleanAlgebraBoolean = "booleanAlgebraBoolean"
295booleanAlgebraBoolean = "booleanAlgebraBoolean"
296
296
297−heytingAlgebraBoolean :: Text
297+heytingAlgebraBoolean :: forall a. (IsString a) => a
298heytingAlgebraBoolean = "heytingAlgebraBoolean"
298heytingAlgebraBoolean = "heytingAlgebraBoolean"
299
299
300−semigroupString :: Text
300+semigroupString :: forall a. (IsString a) => a
301semigroupString = "semigroupString"
301semigroupString = "semigroupString"
302
302
303−semigroupoidFn :: Text
303+semigroupoidFn :: forall a. (IsString a) => a
304semigroupoidFn = "semigroupoidFn"
304semigroupoidFn = "semigroupoidFn"
305
305
306-- Generic Deriving
306-- Generic Deriving
307
307
308−generic :: Text
308+generic :: forall a. (IsString a) => a
309generic = "Generic"
309generic = "Generic"
310
310
311−toSpine :: Text
311+toSpine :: forall a. (IsString a) => a
312toSpine = "toSpine"
312toSpine = "toSpine"
313
313
314−fromSpine :: Text
314+fromSpine :: forall a. (IsString a) => a
315fromSpine = "fromSpine"
315fromSpine = "fromSpine"
316
316
317−toSignature :: Text
317+toSignature :: forall a. (IsString a) => a
318toSignature = "toSignature"
318toSignature = "toSignature"
319
319
320-- Data.Symbol
320-- Data.Symbol
@@ -352,12 +352,12 @@ orderingGT = Qualified (Just typeDataOrdering) (ProperName "GT")
352
352
353-- Main module
353-- Main module
354
354
355−main :: Text
355+main :: forall a. (IsString a) => a
356main = "main"
356main = "main"
357
357
358-- Prim
358-- Prim
359
359
360−partial :: Text
360+partial :: forall a. (IsString a) => a
361partial = "Partial"
361partial = "Partial"
362
362
363pattern Prim :: ModuleName
363pattern Prim :: ModuleName
@@ -369,78 +369,78 @@ pattern Partial = Qualified (Just Prim) (ProperName "Partial")
369pattern Fail :: Qualified (ProperName 'ClassName)
369pattern Fail :: Qualified (ProperName 'ClassName)
370pattern Fail = Qualified (Just Prim) (ProperName "Fail")
370pattern Fail = Qualified (Just Prim) (ProperName "Fail")
371
371
372−typ :: Text
372+typ :: forall a. (IsString a) => a
373typ = "Type"
373typ = "Type"
374
374
375−effect :: Text
375+effect :: forall a. (IsString a) => a
376effect = "Effect"
376effect = "Effect"
377
377
378−symbol :: Text
378+symbol :: forall a. (IsString a) => a
379symbol = "Symbol"
379symbol = "Symbol"
380
380
381-- Code Generation
381-- Code Generation
382
382
383−__superclass_ :: Text
383+__superclass_ :: forall a. (IsString a) => a
384__superclass_ = "__superclass_"
384__superclass_ = "__superclass_"
385
385
386−__unused :: Text
386+__unused :: forall a. (IsString a) => a
387__unused = "__unused"
387__unused = "__unused"
388
388
389-- Modules
389-- Modules
390
390
391−prim :: Text
391+prim :: forall a. (IsString a) => a
392prim = "Prim"
392prim = "Prim"
393
393
394−prelude :: Text
394+prelude :: forall a. (IsString a) => a
395prelude = "Prelude"
395prelude = "Prelude"
396
396
397−dataArray :: Text
397+dataArray :: forall a. (IsString a) => a
398dataArray = "Data_Array"
398dataArray = "Data_Array"
399
399
400−eff :: Text
400+eff :: forall a. (IsString a) => a
401eff = "Control_Monad_Eff"
401eff = "Control_Monad_Eff"
402
402
403−st :: Text
403+st :: forall a. (IsString a) => a
404st = "Control_Monad_ST"
404st = "Control_Monad_ST"
405
405
406−controlApplicative :: Text
406+controlApplicative :: forall a. (IsString a) => a
407controlApplicative = "Control_Applicative"
407controlApplicative = "Control_Applicative"
408
408
409−controlSemigroupoid :: Text
409+controlSemigroupoid :: forall a. (IsString a) => a
410controlSemigroupoid = "Control_Semigroupoid"
410controlSemigroupoid = "Control_Semigroupoid"
411
411
412−controlBind :: Text
412+controlBind :: forall a. (IsString a) => a
413controlBind = "Control_Bind"
413controlBind = "Control_Bind"
414
414
415−dataBounded :: Text
415+dataBounded :: forall a. (IsString a) => a
416dataBounded = "Data_Bounded"
416dataBounded = "Data_Bounded"
417
417
418−dataSemigroup :: Text
418+dataSemigroup :: forall a. (IsString a) => a
419dataSemigroup = "Data_Semigroup"
419dataSemigroup = "Data_Semigroup"
420
420
421−dataHeytingAlgebra :: Text
421+dataHeytingAlgebra :: forall a. (IsString a) => a
422dataHeytingAlgebra = "Data_HeytingAlgebra"
422dataHeytingAlgebra = "Data_HeytingAlgebra"
423
423
424−dataEq :: Text
424+dataEq :: forall a. (IsString a) => a
425dataEq = "Data_Eq"
425dataEq = "Data_Eq"
426
426
427−dataOrd :: Text
427+dataOrd :: forall a. (IsString a) => a
428dataOrd = "Data_Ord"
428dataOrd = "Data_Ord"
429
429
430−dataSemiring :: Text
430+dataSemiring :: forall a. (IsString a) => a
431dataSemiring = "Data_Semiring"
431dataSemiring = "Data_Semiring"
432
432
433−dataRing :: Text
433+dataRing :: forall a. (IsString a) => a
434dataRing = "Data_Ring"
434dataRing = "Data_Ring"
435
435
436−dataEuclideanRing :: Text
436+dataEuclideanRing :: forall a. (IsString a) => a
437dataEuclideanRing = "Data_EuclideanRing"
437dataEuclideanRing = "Data_EuclideanRing"
438
438
439−dataFunction :: Text
439+dataFunction :: forall a. (IsString a) => a
440dataFunction = "Data_Function"
440dataFunction = "Data_Function"
441
441
442−dataFunctionUncurried :: Text
442+dataFunctionUncurried :: forall a. (IsString a) => a
443dataFunctionUncurried = "Data_Function_Uncurried"
443dataFunctionUncurried = "Data_Function_Uncurried"
444
444
445−dataIntBits :: Text
445+dataIntBits :: forall a. (IsString a) => a
446dataIntBits = "Data_Int_Bits"
446dataIntBits = "Data_Int_Bits"
src/Language/PureScript/Pretty/JS.hs+4−2
@@ -162,8 +162,10 @@ conditional = mkPattern match
162accessor :: (Emit gen) => Pattern PrinterState JS (gen, JS)
162accessor :: (Emit gen) => Pattern PrinterState JS (gen, JS)
163accessor = mkPattern match
163accessor = mkPattern match
164 where
164 where
165− -- WARN: if `prop` does not match the `IdentifierName` grammar, this will generate invalid code; see #2513
165+ match (JSIndexer _ (JSStringLiteral _ prop) val) =
166− match (JSAccessor _ prop val) = Just (emit prop, val)
166+ case decodeString prop of
167+ Just s | not (identNeedsEscaping s) -> Just (emit s, val)
168+ _ -> Nothing
167 match _ = Nothing
169 match _ = Nothing
168
170
169indexer :: (Emit gen) => Pattern PrinterState JS (gen, JS)
171indexer :: (Emit gen) => Pattern PrinterState JS (gen, JS)