git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Move (!!) to Prelude.Unsafe.unsafeIndex
commit493f9ae3fd0c1818af2b7a7f5ea76f36838ec761 authorGary Burgess <gary.burgess@gmail.com> dateFri 11 Apr 2014, 20:03 (13 years ago) parentb3f6eef
4 files changed+23−19
prelude/prelude.purs+9−8 src/Language/PureScript/Constants.hs+6−3 src/Language/PureScript/Optimizer.hs+3−3 src/Language/PureScript/Optimizer/Inliner.hs+5−5
prelude/prelude.purs+9−8
@@ -329,14 +329,6 @@ module Prelude where
329329 zshr = numZshr
330330 complement = numComplement
331331
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−
340332 infixr 2 ||
341333 infixr 3 &&
342334
@@ -396,6 +388,15 @@ module Data.Eq where
396388 instance eqRef :: Eq (Ref a) where
397389 (==) = liftRef refEq
398390 (/=) = 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
399400
400401module Control.Monad.Eff where
401402
src/Language/PureScript/Constants.hs+6−3
@@ -23,9 +23,6 @@ module Language.PureScript.Constants where
2323(#) :: String
2424(#) = "#"
2525
26−(!!) :: String
27−(!!) = "!!"
28−
2926(++) :: String
3027(++) = "++"
3128
@@ -80,6 +77,9 @@ bar = "|"
8077(||) :: String
8178(||) = "||"
8279
80+unsafeIndex :: String
81+unsafeIndex = "unsafeIndex"
82+
8383-- Prelude Operator Functions
8484
8585negate :: String
@@ -194,6 +194,9 @@ prim = "Prim"
194194prelude :: String
195195prelude = "Prelude"
196196
197+preludeUnsafe :: String
198+preludeUnsafe = "Prelude_Unsafe"
199+
197200eff :: String
198201eff = "Control_Monad_Eff"
199202
src/Language/PureScript/Optimizer.hs+3−3
@@ -63,9 +63,9 @@ optimize opts | optionsNoOptimizations opts = id
6363 , etaConvert
6464 , evaluateIifes
6565 , inlineVariables
66− , inlineOperator (C.$) $ \f x -> JSApp f [x]
67− , inlineOperator (C.#) $ \x f -> JSApp f [x]
68− , inlineOperator (C.!!) $ flip JSIndexer
66+ , inlineOperator (C.prelude, (C.$)) $ \f x -> JSApp f [x]
67+ , inlineOperator (C.prelude, (C.#)) $ \x f -> JSApp f [x]
68+ , inlineOperator (C.preludeUnsafe, C.unsafeIndex) $ flip JSIndexer
6969 , inlineCommonOperators ])
7070
7171untilFixedPoint :: (Eq a) => (a -> a) -> a -> a
src/Language/PureScript/Optimizer/Inliner.hs+5−5
@@ -75,15 +75,15 @@ inlineVariables = everywhere (mkT $ removeFromBlock go)
7575 go (replaceIdent var js sts)
7676 go (s:sts) = s : go sts
7777
78−inlineOperator :: String -> (JS -> JS -> JS) -> JS -> JS
79−inlineOperator op f = everywhere (mkT convert)
78+inlineOperator :: (String, String) -> (JS -> JS -> JS) -> JS -> JS
79+inlineOperator (m, op) f = everywhere (mkT convert)
8080 where
8181 convert :: JS -> JS
8282 convert (JSApp (JSApp op' [x]) [y]) | isOp op' = f x y
8383 convert other = other
84− isOp (JSAccessor longForm (JSAccessor prelude (JSVar _ps))) | prelude == C.prelude &&
85− _ps == C._ps &&
86− longForm == identToJs (Op op) = True
84+ isOp (JSAccessor longForm (JSAccessor m' (JSVar _ps))) | m == m' &&
85+ _ps == C._ps &&
86+ longForm == identToJs (Op op) = True
8787 isOp (JSIndexer (JSStringLiteral op') (JSAccessor prelude (JSVar _ps))) | prelude == C.prelude &&
8888 _ps == C._ps &&
8989 op == op' = True