git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Move (!!) to Prelude.Unsafe.unsafeIndex
493f9aeGary Burgess
prelude/prelude.purs+9−8
@@ -329,14 +329,6 @@ module Prelude where
329 zshr = numZshr
329 zshr = numZshr
330 complement = numComplement
330 complement = numComplement
331
331
332− infixl 8 !!
333−
334− foreign import (!!) "function $bang$bang(xs) {\
335− \ return function(n) {\
336− \ return xs[n];\
337− \ };\
338− \}" :: forall a. [a] -> Number -> a
339−
340 infixr 2 ||
332 infixr 2 ||
341 infixr 3 &&
333 infixr 3 &&
342
334
@@ -396,6 +388,15 @@ module Data.Eq where
396 instance eqRef :: Eq (Ref a) where
388 instance eqRef :: Eq (Ref a) where
397 (==) = liftRef refEq
389 (==) = liftRef refEq
398 (/=) = liftRef refIneq
390 (/=) = liftRef refIneq
391+
392+module Prelude.Unsafe where
393+
394+ foreign import unsafeIndex
395+ "function unsafeIndex(xs) {\
396+ \ return function(n) {\
397+ \ return xs[n];\
398+ \ };\
399+ \}" :: forall a. [a] -> Number -> a
399
400
400module Control.Monad.Eff where
401module Control.Monad.Eff where
401
402
src/Language/PureScript/Constants.hs+6−3
@@ -23,9 +23,6 @@ module Language.PureScript.Constants where
23(#) :: String
23(#) :: String
24(#) = "#"
24(#) = "#"
25
25
26−(!!) :: String
27−(!!) = "!!"
28−
29(++) :: String
26(++) :: String
30(++) = "++"
27(++) = "++"
31
28
@@ -80,6 +77,9 @@ bar = "|"
80(||) :: String
77(||) :: String
81(||) = "||"
78(||) = "||"
82
79
80+unsafeIndex :: String
81+unsafeIndex = "unsafeIndex"
82+
83-- Prelude Operator Functions
83-- Prelude Operator Functions
84
84
85negate :: String
85negate :: String
@@ -194,6 +194,9 @@ prim = "Prim"
194prelude :: String
194prelude :: String
195prelude = "Prelude"
195prelude = "Prelude"
196
196
197+preludeUnsafe :: String
198+preludeUnsafe = "Prelude_Unsafe"
199+
197eff :: String
200eff :: String
198eff = "Control_Monad_Eff"
201eff = "Control_Monad_Eff"
199
202
src/Language/PureScript/Optimizer.hs+3−3
@@ -63,9 +63,9 @@ optimize opts | optionsNoOptimizations opts = id
63 , etaConvert
63 , etaConvert
64 , evaluateIifes
64 , evaluateIifes
65 , inlineVariables
65 , inlineVariables
66− , inlineOperator (C.$) $ \f x -> JSApp f [x]
66+ , inlineOperator (C.prelude, (C.$)) $ \f x -> JSApp f [x]
67− , inlineOperator (C.#) $ \x f -> JSApp f [x]
67+ , inlineOperator (C.prelude, (C.#)) $ \x f -> JSApp f [x]
68− , inlineOperator (C.!!) $ flip JSIndexer
68+ , inlineOperator (C.preludeUnsafe, C.unsafeIndex) $ flip JSIndexer
69 , inlineCommonOperators ])
69 , inlineCommonOperators ])
70
70
71untilFixedPoint :: (Eq a) => (a -> a) -> a -> a
71untilFixedPoint :: (Eq a) => (a -> a) -> a -> a
src/Language/PureScript/Optimizer/Inliner.hs+5−5
@@ -75,15 +75,15 @@ inlineVariables = everywhere (mkT $ removeFromBlock go)
75 go (replaceIdent var js sts)
75 go (replaceIdent var js sts)
76 go (s:sts) = s : go sts
76 go (s:sts) = s : go sts
77
77
78−inlineOperator :: String -> (JS -> JS -> JS) -> JS -> JS
78+inlineOperator :: (String, String) -> (JS -> JS -> JS) -> JS -> JS
79−inlineOperator op f = everywhere (mkT convert)
79+inlineOperator (m, op) f = everywhere (mkT convert)
80 where
80 where
81 convert :: JS -> JS
81 convert :: JS -> JS
82 convert (JSApp (JSApp op' [x]) [y]) | isOp op' = f x y
82 convert (JSApp (JSApp op' [x]) [y]) | isOp op' = f x y
83 convert other = other
83 convert other = other
84− isOp (JSAccessor longForm (JSAccessor prelude (JSVar _ps))) | prelude == C.prelude &&
84+ isOp (JSAccessor longForm (JSAccessor m' (JSVar _ps))) | m == m' &&
85− _ps == C._ps &&
85+ _ps == C._ps &&
86− longForm == identToJs (Op op) = True
86+ longForm == identToJs (Op op) = True
87 isOp (JSIndexer (JSStringLiteral op') (JSAccessor prelude (JSVar _ps))) | prelude == C.prelude &&
87 isOp (JSIndexer (JSStringLiteral op') (JSAccessor prelude (JSVar _ps))) | prelude == C.prelude &&
88 _ps == C._ps &&
88 _ps == C._ps &&
89 op == op' = True
89 op == op' = True