git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Remove STArray implementation.
1b111f4Phil Freeman
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
883
883
884 foreign import data STRef :: * -> * -> *
884 foreign import data STRef :: * -> * -> *
885
885
886− foreign import data STArray :: * -> * -> *
887−
888 foreign import newSTRef "function newSTRef(val) {\
886 foreign import newSTRef "function newSTRef(val) {\
889 \ return function() {\
887 \ return function() {\
890 \ return { value: val };\
888 \ return { value: val };\
@@ -913,40 +911,7 @@ module Control.Monad.ST where
913 \ };\
911 \ };\
914 \}" :: forall a h r. STRef h a -> a -> Eff (st :: ST h | r) a
912 \}" :: forall a h r. STRef h a -> a -> Eff (st :: ST h | r) a
915
913
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−
946 foreign import runST "function runST(f) {\
914 foreign import runST "function runST(f) {\
947 \ return f;\
915 \ return f;\
948 \}" :: forall a r. (forall h. Eff (st :: ST h | r) a) -> Eff r a
916 \}" :: forall a r. (forall h. Eff (st :: ST h | r) a) -> Eff r a
949
917
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"
123runST :: String
123runST :: String
124runST = "runST"
124runST = "runST"
125
125
126−runSTArray :: String
127−runSTArray = "runSTArray"
128−
129stRefValue :: String
126stRefValue :: String
130stRefValue = "value"
127stRefValue = "value"
131
128
@@ -141,12 +138,6 @@ writeSTRef = "writeSTRef"
141modifySTRef :: String
138modifySTRef :: String
142modifySTRef = "modifySTRef"
139modifySTRef = "modifySTRef"
143
140
144−peekSTArray :: String
145−peekSTArray = "peekSTArray"
146−
147−pokeSTArray :: String
148−pokeSTArray = "pokeSTArray"
149−
150mkFn :: String
141mkFn :: String
151mkFn = "mkFn"
142mkFn = "mkFn"
152
143
src/Language/PureScript/Optimizer/MagicDo.hs+1−5
@@ -119,7 +119,7 @@ inlineST = everywhereOnJS convertBlock
119 -- Look for runST blocks and inline the STRefs there.
119 -- Look for runST blocks and inline the STRefs there.
120 -- If all STRefs are used in the scope of the same runST, only using { read, write, modify }STRef then
120 -- If all STRefs are used in the scope of the same runST, only using { read, write, modify }STRef then
121 -- we can be more aggressive about inlining, and actually turn STRefs into local variables.
121 -- 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 =
123 let refs = nub . findSTRefsIn $ arg
123 let refs = nub . findSTRefsIn $ arg
124 usages = findAllSTUsagesIn arg
124 usages = findAllSTUsagesIn arg
125 allUsagesAreLocalVars = all (\u -> let v = toVar u in isJust v && fromJust v `elem` refs) usages
125 allUsagesAreLocalVars = all (\u -> let v = toVar u in isJust v && fromJust v `elem` refs) usages
@@ -137,10 +137,6 @@ inlineST = everywhereOnJS convertBlock
137 if agg then JSAssignment ref arg else JSAssignment (JSAccessor C.stRefValue ref) arg
137 if agg then JSAssignment ref arg else JSAssignment (JSAccessor C.stRefValue ref) arg
138 convert agg (JSApp (JSApp (JSApp f [ref]) [func]) []) | isSTFunc C.modifySTRef f =
138 convert agg (JSApp (JSApp (JSApp f [ref]) [func]) []) | isSTFunc C.modifySTRef f =
139 if agg then JSAssignment ref (JSApp func [ref]) else JSAssignment (JSAccessor C.stRefValue ref) (JSApp func [JSAccessor C.stRefValue ref])
139 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
144 convert _ other = other
140 convert _ other = other
145 -- Check if an expression represents a function in the ST module
141 -- Check if an expression represents a function in the ST module
146 isSTFunc name (JSAccessor name' (JSVar st)) = st == C.st && name == name'
142 isSTFunc name (JSAccessor name' (JSVar st)) = st == C.st && name == name'