Skip to content

Commit

Permalink
Remove STArray implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
paf31 committed Nov 27, 2014
1 parent f82c9e6 commit 1b111f4
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 74 deletions.
25 changes: 0 additions & 25 deletions examples/passing/STArray.purs

This file was deleted.

35 changes: 0 additions & 35 deletions prelude/prelude.purs
Original file line number Diff line number Diff line change
Expand Up @@ -883,8 +883,6 @@ module Control.Monad.ST where

foreign import data STRef :: * -> * -> *

foreign import data STArray :: * -> * -> *

foreign import newSTRef "function newSTRef(val) {\
\ return function() {\
\ return { value: val };\
Expand Down Expand Up @@ -913,40 +911,7 @@ module Control.Monad.ST where
\ };\
\}" :: forall a h r. STRef h a -> a -> Eff (st :: ST h | r) a

foreign import newSTArray "function newSTArray(len) {\
\ return function(a) {\
\ return function() {\
\ var arr = [];\
\ for (var i = 0; i < len; i++) {\
\ arr[i] = a;\
\ };\
\ return arr;\
\ };\
\ };\
\}" :: forall a h r. Number -> a -> Eff (st :: ST h | r) (STArray h a)

foreign import peekSTArray "function peekSTArray(arr) {\
\ return function(i) {\
\ return function() {\
\ return arr[i];\
\ };\
\ };\
\}" :: forall a h r. STArray h a -> Number -> Eff (st :: ST h | r) a

foreign import pokeSTArray "function pokeSTArray(arr) {\
\ return function(i) {\
\ return function(a) {\
\ return function() {\
\ return arr[i] = a;\
\ };\
\ };\
\ };\
\}" :: forall a h r. STArray h a -> Number -> a -> Eff (st :: ST h | r) a

foreign import runST "function runST(f) {\
\ return f;\
\}" :: forall a r. (forall h. Eff (st :: ST h | r) a) -> Eff r a

foreign import runSTArray "function runSTArray(f) {\
\ return f;\
\}" :: forall a r. (forall h. Eff (st :: ST h | r) (STArray h a)) -> Eff r [a]
9 changes: 0 additions & 9 deletions src/Language/PureScript/Constants.hs
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@ whileE = "whileE"
runST :: String
runST = "runST"

runSTArray :: String
runSTArray = "runSTArray"

stRefValue :: String
stRefValue = "value"

Expand All @@ -141,12 +138,6 @@ writeSTRef = "writeSTRef"
modifySTRef :: String
modifySTRef = "modifySTRef"

peekSTArray :: String
peekSTArray = "peekSTArray"

pokeSTArray :: String
pokeSTArray = "pokeSTArray"

mkFn :: String
mkFn = "mkFn"

Expand Down
6 changes: 1 addition & 5 deletions src/Language/PureScript/Optimizer/MagicDo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ inlineST = everywhereOnJS convertBlock
-- Look for runST blocks and inline the STRefs there.
-- If all STRefs are used in the scope of the same runST, only using { read, write, modify }STRef then
-- we can be more aggressive about inlining, and actually turn STRefs into local variables.
convertBlock (JSApp f [arg]) | isSTFunc C.runST f || isSTFunc C.runSTArray f =
convertBlock (JSApp f [arg]) | isSTFunc C.runST f =
let refs = nub . findSTRefsIn $ arg
usages = findAllSTUsagesIn arg
allUsagesAreLocalVars = all (\u -> let v = toVar u in isJust v && fromJust v `elem` refs) usages
Expand All @@ -137,10 +137,6 @@ inlineST = everywhereOnJS convertBlock
if agg then JSAssignment ref arg else JSAssignment (JSAccessor C.stRefValue ref) arg
convert agg (JSApp (JSApp (JSApp f [ref]) [func]) []) | isSTFunc C.modifySTRef f =
if agg then JSAssignment ref (JSApp func [ref]) else JSAssignment (JSAccessor C.stRefValue ref) (JSApp func [JSAccessor C.stRefValue ref])
convert _ (JSApp (JSApp (JSApp f [arr]) [i]) []) | isSTFunc C.peekSTArray f =
JSIndexer i arr
convert _ (JSApp (JSApp (JSApp (JSApp f [arr]) [i]) [val]) []) | isSTFunc C.pokeSTArray f =
JSAssignment (JSIndexer i arr) val
convert _ other = other
-- Check if an expression represents a function in the ST module
isSTFunc name (JSAccessor name' (JSVar st)) = st == C.st && name == name'
Expand Down

0 comments on commit 1b111f4

Please sign in to comment.