git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Remove STArray implementation.
commit1b111f4dc1fbd7927ab40cdccbd2991a34ccca14 authorPhil Freeman <paf31@cantab.net> dateWed 26 Nov 2014, 17:46 (12 years ago) parentf82c9e6
4 files changed+1−74
examples/passing/STArray.purs−25 prelude/prelude.purs−35 src/Language/PureScript/Constants.hs−9 src/Language/PureScript/Optimizer/MagicDo.hs+1−5
examples/passing/STArray.pursdeleted−25
@@ -1,25 +0,0 @@
1−module Main where
2−
3−import Prelude
4−import Control.Monad.Eff
5−import Control.Monad.ST
6−import Debug.Trace
7−
8−test = runSTArray (do
9− a <- newSTArray 2 0
10− pokeSTArray a 0 1
11− pokeSTArray a 1 2
12− return a)
13−
14−fromTo lo hi = runSTArray (do
15− arr <- newSTArray (hi - lo + 1) 0
16− (let
17− go lo hi _ arr | lo > hi = return arr
18− go lo hi i arr = do
19− pokeSTArray arr i lo
20− go (lo + 1) hi (i + 1) arr
21− in go lo hi 0 arr))
22−
23−main = do
24− let t1 = runPure (fromTo 10 20)
25− trace "Done"
prelude/prelude.purs−35
@@ -883,8 +883,6 @@ module Control.Monad.ST where
883883
884884 foreign import data STRef :: * -> * -> *
885885
886− foreign import data STArray :: * -> * -> *
887−
888886 foreign import newSTRef "function newSTRef(val) {\
889887 \ return function() {\
890888 \ return { value: val };\
@@ -913,40 +911,7 @@ module Control.Monad.ST where
913911 \ };\
914912 \}" :: forall a h r. STRef h a -> a -> Eff (st :: ST h | r) a
915913
916− foreign import newSTArray "function newSTArray(len) {\
917− \ return function(a) {\
918− \ return function() {\
919− \ var arr = [];\
920− \ for (var i = 0; i < len; i++) {\
921− \ arr[i] = a;\
922− \ };\
923− \ return arr;\
924− \ };\
925− \ };\
926− \}" :: forall a h r. Number -> a -> Eff (st :: ST h | r) (STArray h a)
927−
928− foreign import peekSTArray "function peekSTArray(arr) {\
929− \ return function(i) {\
930− \ return function() {\
931− \ return arr[i];\
932− \ };\
933− \ };\
934− \}" :: forall a h r. STArray h a -> Number -> Eff (st :: ST h | r) a
935−
936− foreign import pokeSTArray "function pokeSTArray(arr) {\
937− \ return function(i) {\
938− \ return function(a) {\
939− \ return function() {\
940− \ return arr[i] = a;\
941− \ };\
942− \ };\
943− \ };\
944− \}" :: forall a h r. STArray h a -> Number -> a -> Eff (st :: ST h | r) a
945−
946914 foreign import runST "function runST(f) {\
947915 \ return f;\
948916 \}" :: forall a r. (forall h. Eff (st :: ST h | r) a) -> Eff r a
949917
950− foreign import runSTArray "function runSTArray(f) {\
951− \ return f;\
952− \}" :: forall a r. (forall h. Eff (st :: ST h | r) (STArray h a)) -> Eff r [a]
src/Language/PureScript/Constants.hs−9
@@ -123,9 +123,6 @@ whileE = "whileE"
123123runST :: String
124124runST = "runST"
125125
126−runSTArray :: String
127−runSTArray = "runSTArray"
128−
129126stRefValue :: String
130127stRefValue = "value"
131128
@@ -141,12 +138,6 @@ writeSTRef = "writeSTRef"
141138modifySTRef :: String
142139modifySTRef = "modifySTRef"
143140
144−peekSTArray :: String
145−peekSTArray = "peekSTArray"
146−
147−pokeSTArray :: String
148−pokeSTArray = "pokeSTArray"
149−
150141mkFn :: String
151142mkFn = "mkFn"
152143
src/Language/PureScript/Optimizer/MagicDo.hs+1−5
@@ -119,7 +119,7 @@ inlineST = everywhereOnJS convertBlock
119119 -- Look for runST blocks and inline the STRefs there.
120120 -- If all STRefs are used in the scope of the same runST, only using { read, write, modify }STRef then
121121 -- we can be more aggressive about inlining, and actually turn STRefs into local variables.
122− convertBlock (JSApp f [arg]) | isSTFunc C.runST f || isSTFunc C.runSTArray f =
122+ convertBlock (JSApp f [arg]) | isSTFunc C.runST f =
123123 let refs = nub . findSTRefsIn $ arg
124124 usages = findAllSTUsagesIn arg
125125 allUsagesAreLocalVars = all (\u -> let v = toVar u in isJust v && fromJust v `elem` refs) usages
@@ -137,10 +137,6 @@ inlineST = everywhereOnJS convertBlock
137137 if agg then JSAssignment ref arg else JSAssignment (JSAccessor C.stRefValue ref) arg
138138 convert agg (JSApp (JSApp (JSApp f [ref]) [func]) []) | isSTFunc C.modifySTRef f =
139139 if agg then JSAssignment ref (JSApp func [ref]) else JSAssignment (JSAccessor C.stRefValue ref) (JSApp func [JSAccessor C.stRefValue ref])
140− convert _ (JSApp (JSApp (JSApp f [arr]) [i]) []) | isSTFunc C.peekSTArray f =
141− JSIndexer i arr
142− convert _ (JSApp (JSApp (JSApp (JSApp f [arr]) [i]) [val]) []) | isSTFunc C.pokeSTArray f =
143− JSAssignment (JSIndexer i arr) val
144140 convert _ other = other
145141 -- Check if an expression represents a function in the ST module
146142 isSTFunc name (JSAccessor name' (JSVar st)) = st == C.st && name == name'