Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancements to typed arrays #39

Open
wants to merge 45 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
6d10cb3
Fix GHCJS.Foreign.Export
Aug 31, 2015
8ff920f
Merge pull request #22 from wuzzeb/improved-base
luite Aug 31, 2015
5878a2f
drop JSRef phantom
luite Sep 1, 2015
b8a9e43
xhr must be opened before any modification, also add required exports
eryx67 Sep 5, 2015
c44e6d1
correct previous commit
eryx67 Sep 5, 2015
88b7f91
Merge pull request #23 from eryx67/improved-base
luite Sep 5, 2015
fa28889
updates for adjusted calling convention
luite Sep 18, 2015
2f0365f
Add Nullable
hamishmack Sep 20, 2015
755934b
implement missing JSString read functions and fix existing ones
luite Sep 25, 2015
6e60f18
add h$isBoolean to jsbits. Req'd by GHCJS.Foreign
tavisrudd Sep 19, 2015
c694b0f
Merge pull request #32 from tavisrudd/master
luite Sep 28, 2015
c5f537d
Add JavaScript.Web.Performance
ocharles Aug 4, 2015
9eb215a
Add time stamps to requestAnimationFrame
ocharles Aug 4, 2015
5a47090
Merge pull request #33 from ocharles/raf-timestamp
luite Sep 29, 2015
60276e6
fix JavaScript.Web.Performance
luite Sep 29, 2015
89d1957
Rename JSRef to JSVal
mgsloan Oct 7, 2015
7a9cb3c
Add a JSRef compatibility synonym #421
mgsloan Oct 7, 2015
3d07ea6
Added Float32/64 Typed array types
achirkin Oct 12, 2015
49d9dbc
Merge pull request #36 from mgsloan/jsref-to-jsval
luite Oct 12, 2015
71ed427
Merge pull request #38 from achirkin/patch-1
luite Oct 12, 2015
e4271f1
fix type of listProps foreign import
luite Oct 15, 2015
b37066e
remove duplicate OnBlocked data structure and add three-argument call…
luite Oct 16, 2015
29c1c4f
add missing xhr.js foreign file
luite Oct 16, 2015
cf5ea14
typed arrays redone
achirkin Oct 18, 2015
b56ae21
Fix RegExp constructor
rimmington Oct 25, 2015
18afd47
avoid unneccessary String -> JSString packing for RegExp constructor
luite Oct 27, 2015
619edd0
Fix Data.Text.Lazy macros
kfigiela Oct 20, 2015
9601c2b
make Export newtype and fix unsafeCoerce bug when dereferencing exports
luite Oct 29, 2015
a19de47
fix Export and support Callbacks that return a value
luite Oct 30, 2015
6f801f6
make fewer assumptions about exported items, falsy values can now be …
luite Oct 30, 2015
41f5344
export getData for MessageEvent
luite Oct 30, 2015
bdd8bc3
Fix typo in JavaScript.Web.MessageEvent.js_getData
wereHamster Oct 31, 2015
a0d750d
Merge https://github.com/ghcjs/ghcjs-base
achirkin Nov 3, 2015
85552b5
small fixes to arrays
achirkin Nov 3, 2015
04aac2a
add non-preemptible threads, fix race condition in GHCJS.Concurrent.s…
luite Nov 6, 2015
6328c2d
Removed PFromJSRef (Maybe a) instance
achirkin Nov 11, 2015
4e9c20f
Move Array.from into Array['from'] for closure compiler
achirkin Nov 17, 2015
f8b853f
Replaced JSArray.from for browser compatibility
achirkin Nov 18, 2015
3bf1ab6
implement js_setLineDash and js_lineDashOffSet
bergey Dec 25, 2015
fb7c694
Merge pull request #52 from ghcjs/dashing-canvas
bergey Jan 9, 2016
d4aa0fe
Merge https://github.com/ghcjs/ghcjs-base
achirkin Mar 11, 2016
3ce3a1e
Adapted last merge (Websockets type compatibility)
achirkin Mar 11, 2016
f61860d
Update README.md
achirkin Mar 14, 2016
0549b7d
naming changes
achirkin Mar 14, 2016
a2f662a
modified gitignore
achirkin Mar 14, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*~
*#
/dist
.stack-work/
54 changes: 27 additions & 27 deletions Data/JSString.hs
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,16 @@ import qualified GHC.CString as GHC

import Unsafe.Coerce

import GHCJS.Prim (JSRef)
import GHCJS.Prim (JSVal)

import Data.JSString.Internal.Type
import Data.JSString.Internal.Fusion (stream, unstream)
import qualified Data.JSString.Internal.Fusion as S
import qualified Data.JSString.Internal.Fusion.Common as S

getJSRef :: JSString -> JSRef ()
getJSRef (JSString x) = x
{-# INLINE getJSRef #-}
getJSVal :: JSString -> JSVal
getJSVal (JSString x) = x
{-# INLINE getJSVal #-}

instance Exts.IsString JSString where
fromString = pack
Expand Down Expand Up @@ -241,7 +241,7 @@ unpack = S.unstreamList . stream
{-# INLINE [1] unpack #-}

unpack' :: JSString -> String
unpack' x = case js_unpack x of (# z #) -> z
unpack' x = unsafeCoerce (js_unpack x)
{-# INLINE unpack' #-}

-- | /O(n)/ Convert a literal string into a JSString. Subject to fusion.
Expand Down Expand Up @@ -1181,7 +1181,7 @@ group x = group' x -- fixme, implement lazier version
{-# INLINE group #-}

group' :: JSString -> [JSString]
group' x = case js_group x of (# z #) -> z
group' x = unsafeCoerce (js_group x)
{-# INLINE group' #-}

-- | /O(n^2)/ Return all initial segments of the given 'JSString', shortest
Expand Down Expand Up @@ -1266,7 +1266,7 @@ splitOn' :: JSString
-> [JSString]
splitOn' pat src
| null pat = emptyError "splitOn'"
| otherwise = case js_splitOn pat src of (# z #) -> z
| otherwise = unsafeCoerce (js_splitOn pat src)
{-# NOINLINE splitOn' #-}
--- {-# INLINE [1] splitOn' #-}

Expand Down Expand Up @@ -1314,7 +1314,7 @@ chunksOf (I# k) p = go 0#
-- > chunksOf 3 "foobarbaz" == ["foo","bar","baz"]
-- > chunksOf 4 "haskell.org" == ["hask","ell.","org"]
chunksOf' :: Int -> JSString -> [JSString]
chunksOf' (I# k) p = case js_chunksOf k p of (# z #) -> z
chunksOf' (I# k) p = unsafeCoerce (js_chunksOf k p)
{-# INLINE chunksOf' #-}

-- ----------------------------------------------------------------------------
Expand Down Expand Up @@ -1423,7 +1423,7 @@ breakOnAll' :: JSString -- ^ @needle@ to search for
-> [(JSString, JSString)]
breakOnAll' pat src
| null pat = emptyError "breakOnAll'"
| otherwise = case js_breakOnAll pat src of (# z #) -> z
| otherwise = unsafeCoerce (js_breakOnAll pat src)
{-# INLINE breakOnAll' #-}

-------------------------------------------------------------------------------
Expand Down Expand Up @@ -1512,7 +1512,7 @@ words x = loop 0# -- js_words x {- t@(Text arr off len) = loop 0 0

-- fixme: strict words' that allocates the whole list in one go
words' :: JSString -> [JSString]
words' x = case js_words x of (# z #) -> z
words' x = unsafeCoerce (js_words x)
{-# INLINE words' #-}

-- | /O(n)/ Breaks a 'JSString' up into a list of 'JSString's at
Expand All @@ -1527,7 +1527,7 @@ lines ps = loop 0#
{-# INLINE lines #-}

lines' :: JSString -> [JSString]
lines' ps = case js_lines ps of (# z #) -> z
lines' ps = unsafeCoerce (js_lines ps)
{-# INLINE lines' #-}

{-
Expand Down Expand Up @@ -1619,7 +1619,7 @@ isInfixOf needle haystack = js_isInfixOf needle haystack
-- > fnordLength (stripPrefix "fnord" -> Just suf) = T.length suf
-- > fnordLength _ = -1
stripPrefix :: JSString -> JSString -> Maybe JSString
stripPrefix x y = case js_stripPrefix x y of (# z #) -> z
stripPrefix x y = unsafeCoerce (js_stripPrefix x y)
{-# INLINE stripPrefix #-}

-- | /O(n)/ Find the longest non-empty common prefix of two strings
Expand All @@ -1635,7 +1635,7 @@ stripPrefix x y = case js_stripPrefix x y of (# z #) -> z
-- > commonPrefixes "veeble" "fetzer" == Nothing
-- > commonPrefixes "" "baz" == Nothing
commonPrefixes :: JSString -> JSString -> Maybe (JSString,JSString,JSString)
commonPrefixes x y = case js_commonPrefixes x y of (# z #) -> z
commonPrefixes x y = unsafeCoerce (js_commonPrefixes x y)
{-# INLINE commonPrefixes #-}

-- | /O(n)/ Return the prefix of the second string if its suffix
Expand All @@ -1657,7 +1657,7 @@ commonPrefixes x y = case js_commonPrefixes x y of (# z #) -> z
-- > quuxLength (stripSuffix "quux" -> Just pre) = T.length pre
-- > quuxLength _ = -1
stripSuffix :: JSString -> JSString -> Maybe JSString
stripSuffix x y = case js_stripSuffix x y of (# z #) -> z
stripSuffix x y = unsafeCoerce (js_stripSuffix x y)
{-# INLINE stripSuffix #-}

-- | Add a list of non-negative numbers. Errors out on overflow.
Expand Down Expand Up @@ -1687,7 +1687,7 @@ foreign import javascript unsafe
foreign import javascript unsafe
"$1===''" js_null :: JSString -> Bool
foreign import javascript unsafe
"$1===null" js_isNull :: JSRef () -> Bool
"$1===null" js_isNull :: JSVal -> Bool
foreign import javascript unsafe
"$1===$2" js_eq :: JSString -> JSString -> Bool
foreign import javascript unsafe
Expand All @@ -1699,7 +1699,7 @@ foreign import javascript unsafe
foreign import javascript unsafe
"h$jsstringSingleton" js_singleton :: Char -> JSString
foreign import javascript unsafe
"h$jsstringUnpack" js_unpack :: JSString -> (# String #)
"h$jsstringUnpack" js_unpack :: JSString -> Exts.Any -- String
foreign import javascript unsafe
"h$jsstringCons" js_cons :: Char -> JSString -> JSString
foreign import javascript unsafe
Expand Down Expand Up @@ -1731,13 +1731,13 @@ foreign import javascript unsafe
"h$jsstringLast" js_last :: JSString -> Int#

foreign import javascript unsafe
"h$jsstringInit" js_init :: JSString -> JSRef () -- null for empty string
"h$jsstringInit" js_init :: JSString -> JSVal -- null for empty string
foreign import javascript unsafe
"h$jsstringTail" js_tail :: JSString -> JSRef () -- null for empty string
"h$jsstringTail" js_tail :: JSString -> JSVal -- null for empty string
foreign import javascript unsafe
"h$jsstringReverse" js_reverse :: JSString -> JSString
foreign import javascript unsafe
"h$jsstringGroup" js_group :: JSString -> (# [JSString] #) -- Exts.Any {- [JSString] -}
"h$jsstringGroup" js_group :: JSString -> Exts.Any {- [JSString] -}
--foreign import javascript unsafe
-- "h$jsstringGroup1" js_group1
-- :: Int# -> Bool -> JSString -> (# Int#, JSString #)
Expand All @@ -1751,11 +1751,11 @@ foreign import javascript unsafe
foreign import javascript unsafe
"h$jsstringWords1" js_words1 :: Int# -> JSString -> (# Int#, JSString #)
foreign import javascript unsafe
"h$jsstringWords" js_words :: JSString -> (# [JSString] #) -- Exts.Any {- [JSString] -}
"h$jsstringWords" js_words :: JSString -> Exts.Any -- [JSString]
foreign import javascript unsafe
"h$jsstringLines1" js_lines1 :: Int# -> JSString -> (# Int#, JSString #)
foreign import javascript unsafe
"h$jsstringLines" js_lines :: JSString -> (# [JSString] #) -- Exts.Any {- [JSString] -}
"h$jsstringLines" js_lines :: JSString -> Exts.Any -- [JSString]
foreign import javascript unsafe
"h$jsstringUnlines" js_unlines :: Exts.Any {- [JSString] -} -> JSString
foreign import javascript unsafe
Expand All @@ -1768,16 +1768,16 @@ foreign import javascript unsafe
"h$jsstringIsInfixOf" js_isInfixOf :: JSString -> JSString -> Bool
foreign import javascript unsafe
"h$jsstringStripPrefix" js_stripPrefix
:: JSString -> JSString -> (# Maybe JSString #)
:: JSString -> JSString -> Exts.Any -- Maybe JSString
foreign import javascript unsafe
"h$jsstringStripSuffix" js_stripSuffix
:: JSString -> JSString -> (# Maybe JSString #)
:: JSString -> JSString -> Exts.Any -- Maybe JSString
foreign import javascript unsafe
"h$jsstringCommonPrefixes" js_commonPrefixes
:: JSString -> JSString -> (# Maybe (JSString, JSString, JSString) #)
:: JSString -> JSString -> Exts.Any -- Maybe (JSString, JSString, JSString)
foreign import javascript unsafe
"h$jsstringChunksOf" js_chunksOf
:: Int# -> JSString -> (# [JSString] #)
:: Int# -> JSString -> Exts.Any -- [JSString]
foreign import javascript unsafe
"h$jsstringChunksOf1" js_chunksOf1
:: Int# -> Int# -> JSString -> (# Int#, JSString #)
Expand All @@ -1786,7 +1786,7 @@ foreign import javascript unsafe
:: Int# -> JSString -> (# JSString, JSString #)
foreign import javascript unsafe
"h$jsstringSplitOn" js_splitOn
:: JSString -> JSString -> (# [JSString] #)
:: JSString -> JSString -> Exts.Any -- [JSString]
foreign import javascript unsafe
"h$jsstringSplitOn1" js_splitOn1
:: Int# -> JSString -> JSString -> (# Int#, JSString #)
Expand All @@ -1798,7 +1798,7 @@ foreign import javascript unsafe
:: JSString -> JSString -> (# JSString, JSString #)
foreign import javascript unsafe
"h$jsstringBreakOnAll" js_breakOnAll
:: JSString -> JSString -> (# [(JSString, JSString)] #)
:: JSString -> JSString -> Exts.Any -- [(JSString, JSString)]
foreign import javascript unsafe
"h$jsstringBreakOnAll1" js_breakOnAll1
:: Int# -> JSString -> JSString -> (# Int#, JSString, JSString #)
Expand Down
4 changes: 2 additions & 2 deletions Data/JSString/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import Control.DeepSeq (NFData(..))
import qualified GHC.Exts as Exts

import Unsafe.Coerce
import GHCJS.Prim (JSRef)
import GHCJS.Prim (JSVal)

newtype JSString = JSString (JSRef ())
newtype JSString = JSString (JSVal ())

instance Monoid JSString where
mempty = empty
Expand Down
8 changes: 4 additions & 4 deletions Data/JSString/Internal/Fusion.hs
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ foreign import javascript unsafe
foreign import javascript unsafe
"$1.length" js_length :: JSString -> Int#
foreign import javascript unsafe
"$r = [$1];" js_newSingletonArray :: Char -> IO (JSRef ())
"$r = [$1];" js_newSingletonArray :: Char -> IO JSVal
foreign import javascript unsafe
"$3[$2] = $1;" js_writeArray :: Char -> Int -> (JSRef ()) -> IO ()
"$3[$2] = $1;" js_writeArray :: Char -> Int -> JSVal -> IO ()
foreign import javascript unsafe
"h$jsstringPackArray" js_packString :: (JSRef ()) -> IO JSString
"h$jsstringPackArray" js_packString :: JSVal -> IO JSString
foreign import javascript unsafe
"h$jsstringPackArrayReverse" js_packReverse :: (JSRef ()) -> IO JSString
"h$jsstringPackArrayReverse" js_packReverse :: JSVal -> IO JSString
8 changes: 5 additions & 3 deletions Data/JSString/Internal/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ import Data.Int (Int32, Int64)
import Data.Typeable (Typeable)
import GHC.Exts (Char(..), ord#, andI#, (/=#), isTrue#)

import GHCJS.Prim (JSRef)
import GHCJS.Prim (JSVal)

import GHCJS.Internal.Types

-- | A wrapper around a JavaScript string
newtype JSString = JSString { unJSString :: JSRef () }
deriving Typeable
newtype JSString = JSString JSVal
instance IsJSVal JSString

instance NFData JSString where rnf !x = ()

Expand Down
6 changes: 3 additions & 3 deletions Data/JSString/Raw.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{-# LANGUAGE ForeignFunctionInterface, JavaScriptFFI,
MagicHash, UnboxedTuples, UnliftedFFITypes
MagicHash, UnboxedTuples, UnliftedFFITypes, GHCForeignImportPrim
#-}

{-
Expand Down Expand Up @@ -110,7 +110,7 @@ rawChunksOf (I# k) x =
{-# INLINE rawChunksOf #-}

rawChunksOf' :: Int -> JSString -> [JSString]
rawChunksOf' (I# k) x = case js_rawChunksOf k x of (# z #) -> z
rawChunksOf' (I# k) x = unsafeCoerce (js_rawChunksOf k x)
{-# INLINE rawChunksOf' #-}

rawSplitAt :: Int -> JSString -> (JSString, JSString)
Expand Down Expand Up @@ -144,5 +144,5 @@ foreign import javascript unsafe
foreign import javascript unsafe
"$2.charCodeAt($1)" js_charCodeAt :: Int# -> JSString -> Int#
foreign import javascript unsafe
"$hsRawChunksOf" js_rawChunksOf :: Int# -> JSString -> (# [JSString] #)
"$hsRawChunksOf" js_rawChunksOf :: Int# -> JSString -> Exts.Any -- [JSString]

27 changes: 18 additions & 9 deletions Data/JSString/Read.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,23 @@ module Data.JSString.Read ( isInteger
, isNatural
, readInt
, readIntMaybe
, lenientReadInt
, readInt64
, readInt64Maybe
, readWord64
, readWord64Maybe
, readDouble
, readDoubleMaybe
, readInteger
, readIntegerMaybe
) where
import GHC.Exts (ByteArray#, Int#, Int64#, Word64#, Int(..))

import GHCJS.Types

import GHC.Exts (Any, Int#, Int64#, Word64#, Int(..))
import GHC.Int (Int64(..))
import GHC.Word (Word64(..))
import Unsafe.Coerce
import Data.Maybe
import Data.JSString

Expand Down Expand Up @@ -127,10 +136,10 @@ readIntegerMaybe j = convertNullMaybe js_readInteger j

-- ----------------------------------------------------------------------------

convertNullMaybe :: (JSString -> ByteArray#) -> JSString -> Maybe a
convertNullMaybe :: (JSString -> JSVal) -> JSString -> Maybe a
convertNullMaybe f j
| js_isNull r = Nothing
| otherwise = case js_toHeapObject r of (# h #) -> Just h
| otherwise = Just (unsafeCoerce (js_toHeapObject r))
where
r = f j
{-# INLINE convertNullMaybe #-}
Expand All @@ -141,21 +150,21 @@ readError xs = error ("Data.JSString.Read." ++ xs)
-- ----------------------------------------------------------------------------

foreign import javascript unsafe
"$1===null" js_isNull :: ByteArray# -> Bool
"$r = $1===null;" js_isNull :: JSVal -> Bool
foreign import javascript unsafe
"$r=$1;" js_toHeapObject :: ByteArray# -> (# a #)
"$r=$1;" js_toHeapObject :: JSVal -> Any
foreign import javascript unsafe
"h$jsstringReadInteger" js_readInteger :: JSString -> ByteArray#
"h$jsstringReadInteger" js_readInteger :: JSString -> JSVal
foreign import javascript unsafe
"h$jsstringReadInt" js_readInt :: JSString -> ByteArray#
"h$jsstringReadInt" js_readInt :: JSString -> JSVal
foreign import javascript unsafe
"h$jsstringLenientReadInt" js_lenientReadInt :: JSString -> ByteArray#
"h$jsstringLenientReadInt" js_lenientReadInt :: JSString -> JSVal
foreign import javascript unsafe
"h$jsstringReadInt64" js_readInt64 :: JSString -> (# Int#, Int64# #)
foreign import javascript unsafe
"h$jsstringReadWord64" js_readWord64 :: JSString -> (# Int#, Word64# #)
foreign import javascript unsafe
"h$jsstringReadDouble" js_readDouble :: JSString -> ByteArray#
"h$jsstringReadDouble" js_readDouble :: JSString -> JSVal
foreign import javascript unsafe
"h$jsstringIsInteger" js_isInteger :: JSString -> Bool
foreign import javascript unsafe
Expand Down
Loading