From db50683c8a20f79c04c385f3ec43dc5730d966ce Mon Sep 17 00:00:00 2001 From: Sylvain Henry Date: Fri, 12 May 2023 17:47:42 +0200 Subject: [PATCH] Fix build with JS backend --- Data/JSString.hs | 6 +- Data/JSString/Int.hs | 42 +++++++------- Data/JSString/Internal/Fusion.hs | 2 +- Data/JSString/Internal/Type.hs | 2 +- Data/JSString/Raw.hs | 2 +- Data/JSString/RegExp.hs | 2 +- Data/JSString/Text.hs | 8 +-- GHCJS/Buffer.hs | 2 +- GHCJS/Concurrent.hs | 2 +- GHCJS/Foreign/Callback.hs | 2 +- GHCJS/Foreign/Export.hs | 2 +- GHCJS/Foreign/Internal.hs | 2 +- GHCJS/Internal/Types.hs | 2 +- GHCJS/Marshal/Internal.hs | 2 +- GHCJS/Marshal/Pure.hs | 28 +++++----- GHCJS/Nullable.hs | 2 +- GHCJS/Types.hs | 2 +- JavaScript/Array.hs | 2 +- JavaScript/Array/Internal.hs | 2 +- JavaScript/Cast.hs | 2 +- JavaScript/JSON/Types/Generic.hs | 2 +- JavaScript/JSON/Types/Instances.hs | 8 +-- JavaScript/JSON/Types/Internal.hs | 2 +- JavaScript/Object/Internal.hs | 2 +- JavaScript/TypedArray/DataView.hs | 2 +- JavaScript/TypedArray/DataView/Internal.hs | 2 +- JavaScript/TypedArray/DataView/ST.hs | 2 +- JavaScript/TypedArray/Internal.hs | 56 +++++++++---------- JavaScript/TypedArray/ST.hs | 10 ++-- JavaScript/Web/WebSocket.hs | 2 +- JavaScript/Web/Worker.hs | 2 +- JavaScript/Web/XMLHttpRequest.hs | 2 +- ghcjs-base.cabal | 29 +++++----- ...animationFrame.js.pp => animationFrame.js} | 1 + jsbits/{array.js.pp => array.js} | 2 +- jsbits/{export.js.pp => export.js} | 1 + jsbits/{foreign.js.pp => foreign.js} | 1 + jsbits/json.js.pp | 4 -- jsbits/{jsstring.js.pp => jsstring.js} | 2 +- jsbits/{jsstringRaw.js.pp => jsstringRaw.js} | 2 +- jsbits/object.js.pp | 2 - jsbits/{text.js.pp => text.js} | 2 +- jsbits/{utils.js.pp => utils.js} | 2 +- jsbits/{websocket.js.pp => websocket.js} | 2 +- jsbits/{xhr.js.pp => xhr.js} | 1 + 45 files changed, 127 insertions(+), 132 deletions(-) rename jsbits/{animationFrame.js.pp => animationFrame.js} (96%) rename jsbits/{array.js.pp => array.js} (97%) rename jsbits/{export.js.pp => export.js} (97%) rename jsbits/{foreign.js.pp => foreign.js} (91%) delete mode 100644 jsbits/json.js.pp rename jsbits/{jsstring.js.pp => jsstring.js} (99%) rename jsbits/{jsstringRaw.js.pp => jsstringRaw.js} (96%) delete mode 100644 jsbits/object.js.pp rename jsbits/{text.js.pp => text.js} (98%) rename jsbits/{utils.js.pp => utils.js} (98%) rename jsbits/{websocket.js.pp => websocket.js} (98%) rename jsbits/{xhr.js.pp => xhr.js} (94%) diff --git a/Data/JSString.hs b/Data/JSString.hs index 36fb370..821b6b6 100644 --- a/Data/JSString.hs +++ b/Data/JSString.hs @@ -167,8 +167,8 @@ import Data.Semigroup (Semigroup(..)) import Unsafe.Coerce -import GHCJS.Prim (JSVal) -import qualified GHCJS.Prim as Prim +import GHC.JS.Prim (JSVal) +import qualified GHC.JS.Prim as Prim import Data.JSString.Internal.Type import Data.JSString.Internal.Fusion (stream, unstream) @@ -300,11 +300,13 @@ unpackCString# addr# = unstream (S.streamCString# addr#) unstream (S.map safe (S.streamList [a])) = singleton a #-} +#ifdef MIN_VERSION_ghcjs_prim #if MIN_VERSION_ghcjs_prim(0,1,1) {-# RULES "JSSTRING literal prim" [0] forall a. unpackCString# a = JSString (Prim.unsafeUnpackJSStringUtf8# a) #-} #endif +#endif -- | /O(1)/ Convert a character into a 'JSString'. Subject to fusion. -- Performs replacement on invalid scalar values. diff --git a/Data/JSString/Int.hs b/Data/JSString/Int.hs index 1c8ecb3..844a6f2 100644 --- a/Data/JSString/Int.hs +++ b/Data/JSString/Int.hs @@ -16,14 +16,10 @@ import Data.Monoid import GHC.Int import GHC.Word -import GHC.Exts ( ByteArray# - , Int(..), Int#, Int64# - , Word(..), Word#, Word64# - , (<#), (<=#), isTrue# ) - -import GHC.Integer.GMP.Internals +import GHC.Exts hiding (Any) +import GHC.Num.Integer import Unsafe.Coerce -import GHCJS.Prim +import GHC.JS.Prim decimal :: Integral a => a -> JSString decimal i = decimal' i @@ -56,15 +52,15 @@ decimalI (I# x) = js_decI x {-# INLINE decimalI #-} decimalI8 :: Int8 -> JSString -decimalI8 (I8# x) = js_decI x +decimalI8 (I8# x) = js_decI (int8ToInt# x) {-# INLINE decimalI8 #-} decimalI16 :: Int16 -> JSString -decimalI16 (I16# x) = js_decI x +decimalI16 (I16# x) = js_decI (int16ToInt# x) {-# INLINE decimalI16 #-} decimalI32 :: Int32 -> JSString -decimalI32 (I32# x) = js_decI x +decimalI32 (I32# x) = js_decI (int32ToInt# x) {-# INLINE decimalI32 #-} decimalI64 :: Int64 -> JSString @@ -72,15 +68,15 @@ decimalI64 (I64# x) = js_decI64 x {-# INLINE decimalI64 #-} decimalW8 :: Word8 -> JSString -decimalW8 (W8# x) = js_decW x +decimalW8 (W8# x) = js_decW (word8ToWord# x) {-# INLINE decimalW8 #-} decimalW16 :: Word16 -> JSString -decimalW16 (W16# x) = js_decW x +decimalW16 (W16# x) = js_decW (word16ToWord# x) {-# INLINE decimalW16 #-} decimalW32 :: Word32 -> JSString -decimalW32 (W32# x) = js_decW32 x +decimalW32 (W32# x) = js_decW32 (word32ToWord# x) {-# INLINE decimalW32 #-} decimalW64 :: Word64 -> JSString @@ -163,23 +159,23 @@ hexI (I# x) = if isTrue# (x <# 0#) hexI8 :: Int8 -> JSString hexI8 (I8# x) = - if isTrue# (x <# 0#) + if isTrue# (int8ToInt# x <# 0#) then error hexErrMsg - else js_hexI x + else js_hexI (int8ToInt# x) {-# INLINE hexI8 #-} hexI16 :: Int16 -> JSString hexI16 (I16# x) = - if isTrue# (x <# 0#) + if isTrue# (int16ToInt# x <# 0#) then error hexErrMsg - else js_hexI x + else js_hexI (int16ToInt# x) {-# INLINE hexI16 #-} hexI32 :: Int32 -> JSString hexI32 (I32# x) = - if isTrue# (x <# 0#) + if isTrue# (int32ToInt# x <# 0#) then error hexErrMsg - else js_hexI x + else js_hexI (int32ToInt# x) {-# INLINE hexI32 #-} hexI64 :: Int64 -> JSString @@ -190,15 +186,15 @@ hexI64 i@(I64# x) = {-# INLINE hexI64 #-} hexW :: Word -> JSString -hexW (W# x) = js_hexW32 x +hexW (W# x) = js_hexW x {-# INLINE hexW #-} hexW8 :: Word8 -> JSString -hexW8 (W8# x) = js_hexW x +hexW8 (W8# x) = js_hexW (word8ToWord# x) {-# INLINE hexW8 #-} hexW16 :: Word16 -> JSString -hexW16 (W16# x) = js_hexW x +hexW16 (W16# x) = js_hexW (word16ToWord# x) {-# INLINE hexW16 #-} hexW32 :: Word32 -> JSString @@ -246,7 +242,7 @@ foreign import javascript unsafe js_hexW :: Word# -> JSString foreign import javascript unsafe "(($1>=0)?$1:($1+4294967296)).toString(16)" - js_hexW32 :: Word# -> JSString + js_hexW32 :: Word32# -> JSString foreign import javascript unsafe "h$jsstringHexW64($1_1, $1_2)" js_hexW64 :: Word64# -> JSString diff --git a/Data/JSString/Internal/Fusion.hs b/Data/JSString/Internal/Fusion.hs index 4118acb..c7578e3 100644 --- a/Data/JSString/Internal/Fusion.hs +++ b/Data/JSString/Internal/Fusion.hs @@ -43,7 +43,7 @@ import qualified Data.JSString.Internal.Fusion.Common as S import System.IO.Unsafe -import GHCJS.Prim +import GHC.JS.Prim default (Int) diff --git a/Data/JSString/Internal/Type.hs b/Data/JSString/Internal/Type.hs index 4fff668..0f1c611 100644 --- a/Data/JSString/Internal/Type.hs +++ b/Data/JSString/Internal/Type.hs @@ -36,7 +36,7 @@ import Data.Int (Int32, Int64) import Data.Typeable (Typeable) import GHC.Exts (Char(..), ord#, andI#, (/=#), isTrue#) -import GHCJS.Prim (JSVal) +import GHC.JS.Prim (JSVal) import GHCJS.Internal.Types diff --git a/Data/JSString/Raw.hs b/Data/JSString/Raw.hs index 58142c3..7c9c9d8 100644 --- a/Data/JSString/Raw.hs +++ b/Data/JSString/Raw.hs @@ -25,7 +25,7 @@ import GHC.Exts , (+#), (-#), (>=#), (<#) , isTrue#, chr#) import qualified GHC.Exts as Exts -import GHCJS.Prim (JSVal) +import GHC.JS.Prim (JSVal) import Unsafe.Coerce diff --git a/Data/JSString/RegExp.hs b/Data/JSString/RegExp.hs index 0ec8e1c..2b98f73 100644 --- a/Data/JSString/RegExp.hs +++ b/Data/JSString/RegExp.hs @@ -18,7 +18,7 @@ module Data.JSString.RegExp ( RegExp , execNext ) where -import GHCJS.Prim +import GHC.JS.Prim import GHC.Exts (Any, Int#, Int(..)) import Unsafe.Coerce (unsafeCoerce) diff --git a/Data/JSString/Text.hs b/Data/JSString/Text.hs index 897880f..1d0c858 100644 --- a/Data/JSString/Text.hs +++ b/Data/JSString/Text.hs @@ -15,7 +15,7 @@ module Data.JSString.Text , lazyTextFromJSVal ) where -import GHCJS.Prim +import GHC.JS.Prim import GHC.Exts (ByteArray#, Int(..), Int#, Any) @@ -31,7 +31,7 @@ import Data.JSString.Internal.Type import Unsafe.Coerce textToJSString :: T.Text -> JSString -textToJSString (T.Text (A.Array ba) (I# offset) (I# length)) = +textToJSString (T.Text (A.ByteArray ba) (I# offset) (I# length)) = js_toString ba offset length {-# INLINE textToJSString #-} @@ -39,7 +39,7 @@ textFromJSString :: JSString -> T.Text textFromJSString j = case js_fromString j of (# _ , 0# #) -> T.empty - (# ba, length #) -> T.Text (A.Array ba) 0 (I# length) + (# ba, length #) -> T.Text (A.ByteArray ba) 0 (I# length) {-# INLINE textFromJSString #-} lazyTextToJSString :: TL.Text -> JSString @@ -54,7 +54,7 @@ lazyTextFromJSString = TL.fromStrict . textFromJSString textFromJSVal :: JSVal -> T.Text textFromJSVal j = case js_fromString' j of (# _, 0# #) -> T.empty - (# ba, length #) -> T.Text (A.Array ba) 0 (I# length) + (# ba, length #) -> T.Text (A.ByteArray ba) 0 (I# length) {-# INLINE textFromJSVal #-} -- | returns the empty Text if not a string diff --git a/GHCJS/Buffer.hs b/GHCJS/Buffer.hs index b9cc421..8e11b46 100644 --- a/GHCJS/Buffer.hs +++ b/GHCJS/Buffer.hs @@ -41,7 +41,7 @@ module GHCJS.Buffer import GHC.Exts (ByteArray#, MutableByteArray#, Addr#, Ptr(..), Any) import GHCJS.Buffer.Types -import GHCJS.Prim +import GHC.JS.Prim import GHCJS.Internal.Types import Data.Int diff --git a/GHCJS/Concurrent.hs b/GHCJS/Concurrent.hs index 74735af..80b2a18 100644 --- a/GHCJS/Concurrent.hs +++ b/GHCJS/Concurrent.hs @@ -33,7 +33,7 @@ module GHCJS.Concurrent ( isThreadSynchronous , synchronously ) where -import GHCJS.Prim +import GHC.JS.Prim import Control.Applicative import Control.Concurrent diff --git a/GHCJS/Foreign/Callback.hs b/GHCJS/Foreign/Callback.hs index 7e8e846..a5f7b8a 100644 --- a/GHCJS/Foreign/Callback.hs +++ b/GHCJS/Foreign/Callback.hs @@ -25,7 +25,7 @@ import GHCJS.Concurrent import GHCJS.Marshal import GHCJS.Marshal.Pure import GHCJS.Foreign.Callback.Internal -import GHCJS.Prim +import GHC.JS.Prim import GHCJS.Types import qualified GHC.Exts as Exts diff --git a/GHCJS/Foreign/Export.hs b/GHCJS/Foreign/Export.hs index f14f968..31de434 100644 --- a/GHCJS/Foreign/Export.hs +++ b/GHCJS/Foreign/Export.hs @@ -27,7 +27,7 @@ import Data.Word import Unsafe.Coerce import qualified GHC.Exts as Exts -import GHCJS.Prim +import GHC.JS.Prim import GHCJS.Types newtype Export a = Export JSVal diff --git a/GHCJS/Foreign/Internal.hs b/GHCJS/Foreign/Internal.hs index 8a16901..8196ec6 100644 --- a/GHCJS/Foreign/Internal.hs +++ b/GHCJS/Foreign/Internal.hs @@ -80,7 +80,7 @@ module GHCJS.Foreign.Internal ( JSType(..) ) where import GHCJS.Types -import qualified GHCJS.Prim as Prim +import qualified GHC.JS.Prim as Prim import GHC.Prim import GHC.Exts diff --git a/GHCJS/Internal/Types.hs b/GHCJS/Internal/Types.hs index ded5112..4965719 100644 --- a/GHCJS/Internal/Types.hs +++ b/GHCJS/Internal/Types.hs @@ -13,7 +13,7 @@ import Unsafe.Coerce import Control.DeepSeq -import GHCJS.Prim (JSVal) +import GHC.JS.Prim (JSVal) instance NFData JSVal where rnf x = x `seq` () diff --git a/GHCJS/Marshal/Internal.hs b/GHCJS/Marshal/Internal.hs index 0b4884a..a26ec26 100644 --- a/GHCJS/Marshal/Internal.hs +++ b/GHCJS/Marshal/Internal.hs @@ -23,7 +23,7 @@ import Data.Typeable import GHC.Generics -import qualified GHCJS.Prim as Prim +import qualified GHC.JS.Prim as Prim import qualified GHCJS.Foreign as F import GHCJS.Types diff --git a/GHCJS/Marshal/Pure.hs b/GHCJS/Marshal/Pure.hs index 902fa20..17cb26c 100644 --- a/GHCJS/Marshal/Pure.hs +++ b/GHCJS/Marshal/Pure.hs @@ -42,7 +42,7 @@ import GHC.Float import GHC.Prim import GHCJS.Types -import qualified GHCJS.Prim as Prim +import qualified GHC.JS.Prim as Prim import GHCJS.Foreign.Internal import GHCJS.Marshal.Internal @@ -77,7 +77,7 @@ instance PFromJSVal Int8 where pFromJSVal x = I8# (jsvalToInt8 x) {-# INLINE pFromJSVal #-} instance PFromJSVal Int16 where pFromJSVal x = I16# (jsvalToInt16 x) {-# INLINE pFromJSVal #-} -instance PFromJSVal Int32 where pFromJSVal x = I32# (jsvalToInt x) +instance PFromJSVal Int32 where pFromJSVal x = I32# (jsvalToInt32 x) {-# INLINE pFromJSVal #-} instance PFromJSVal Word where pFromJSVal x = W# (jsvalToWord x) {-# INLINE pFromJSVal #-} @@ -85,7 +85,7 @@ instance PFromJSVal Word8 where pFromJSVal x = W8# (jsvalToWord8 x) {-# INLINE pFromJSVal #-} instance PFromJSVal Word16 where pFromJSVal x = W16# (jsvalToWord16 x) {-# INLINE pFromJSVal #-} -instance PFromJSVal Word32 where pFromJSVal x = W32# (jsvalToWord x) +instance PFromJSVal Word32 where pFromJSVal x = W32# (jsvalToWord32 x) {-# INLINE pFromJSVal #-} instance PFromJSVal Float where pFromJSVal x = F# (jsvalToFloat x) {-# INLINE pFromJSVal #-} @@ -112,19 +112,19 @@ instance PToJSVal Bool where pToJSVal True = jsTrue {-# INLINE pToJSVal #-} instance PToJSVal Int where pToJSVal (I# x) = intToJSVal x {-# INLINE pToJSVal #-} -instance PToJSVal Int8 where pToJSVal (I8# x) = intToJSVal x +instance PToJSVal Int8 where pToJSVal (I8# x) = intToJSVal (int8ToInt# x) {-# INLINE pToJSVal #-} -instance PToJSVal Int16 where pToJSVal (I16# x) = intToJSVal x +instance PToJSVal Int16 where pToJSVal (I16# x) = intToJSVal (int16ToInt# x) {-# INLINE pToJSVal #-} -instance PToJSVal Int32 where pToJSVal (I32# x) = intToJSVal x +instance PToJSVal Int32 where pToJSVal (I32# x) = intToJSVal (int32ToInt# x) {-# INLINE pToJSVal #-} instance PToJSVal Word where pToJSVal (W# x) = wordToJSVal x {-# INLINE pToJSVal #-} -instance PToJSVal Word8 where pToJSVal (W8# x) = wordToJSVal x +instance PToJSVal Word8 where pToJSVal (W8# x) = wordToJSVal (word8ToWord# x) {-# INLINE pToJSVal #-} -instance PToJSVal Word16 where pToJSVal (W16# x) = wordToJSVal x +instance PToJSVal Word16 where pToJSVal (W16# x) = wordToJSVal (word16ToWord# x) {-# INLINE pToJSVal #-} -instance PToJSVal Word32 where pToJSVal (W32# x) = wordToJSVal x +instance PToJSVal Word32 where pToJSVal (W32# x) = wordToJSVal (word32ToWord# x) {-# INLINE pToJSVal #-} instance PToJSVal Float where pToJSVal (F# x) = floatToJSVal x {-# INLINE pToJSVal #-} @@ -137,11 +137,13 @@ instance PToJSVal a => PToJSVal (Maybe a) where {-# INLINE pToJSVal #-} foreign import javascript unsafe "$r = $1|0;" jsvalToWord :: JSVal -> Word# -foreign import javascript unsafe "$r = $1&0xff;" jsvalToWord8 :: JSVal -> Word# -foreign import javascript unsafe "$r = $1&0xffff;" jsvalToWord16 :: JSVal -> Word# +foreign import javascript unsafe "$r = $1&0xff;" jsvalToWord8 :: JSVal -> Word8# +foreign import javascript unsafe "$r = $1&0xffff;" jsvalToWord16 :: JSVal -> Word16# +foreign import javascript unsafe "$r = $1|0;" jsvalToWord32 :: JSVal -> Word32# foreign import javascript unsafe "$r = $1|0;" jsvalToInt :: JSVal -> Int# -foreign import javascript unsafe "$r = $1<<24>>24;" jsvalToInt8 :: JSVal -> Int# -foreign import javascript unsafe "$r = $1<<16>>16;" jsvalToInt16 :: JSVal -> Int# +foreign import javascript unsafe "$r = $1<<24>>24;" jsvalToInt8 :: JSVal -> Int8# +foreign import javascript unsafe "$r = $1<<16>>16;" jsvalToInt16 :: JSVal -> Int16# +foreign import javascript unsafe "$r = $1|0;" jsvalToInt32 :: JSVal -> Int32# foreign import javascript unsafe "$r = +$1;" jsvalToFloat :: JSVal -> Float# foreign import javascript unsafe "$r = +$1;" jsvalToDouble :: JSVal -> Double# foreign import javascript unsafe "$r = $1&0x7fffffff;" jsvalToChar :: JSVal -> Char# diff --git a/GHCJS/Nullable.hs b/GHCJS/Nullable.hs index bad2c56..3cc98c3 100644 --- a/GHCJS/Nullable.hs +++ b/GHCJS/Nullable.hs @@ -3,7 +3,7 @@ module GHCJS.Nullable ( Nullable(..) , maybeToNullable ) where -import GHCJS.Prim (JSVal(..)) +import GHC.JS.Prim (JSVal(..)) import GHCJS.Marshal.Pure (PToJSVal(..), PFromJSVal(..)) newtype Nullable a = Nullable JSVal diff --git a/GHCJS/Types.hs b/GHCJS/Types.hs index 9ef0892..6ac7ab4 100644 --- a/GHCJS/Types.hs +++ b/GHCJS/Types.hs @@ -24,7 +24,7 @@ module GHCJS.Types ( JSVal import Data.JSString.Internal.Type (JSString) import GHCJS.Internal.Types -import GHCJS.Prim +import GHC.JS.Prim import GHC.Int import GHC.Types diff --git a/JavaScript/Array.hs b/JavaScript/Array.hs index 33fd4b9..2294557 100644 --- a/JavaScript/Array.hs +++ b/JavaScript/Array.hs @@ -33,7 +33,7 @@ module JavaScript.Array import Prelude hiding (length, drop, read, take, reverse, null) -import qualified GHCJS.Prim as Prim +import qualified GHC.JS.Prim as Prim import GHCJS.Types import JavaScript.Array.Internal (JSArray(..)) diff --git a/JavaScript/Array/Internal.hs b/JavaScript/Array/Internal.hs index 135fe5a..3964feb 100644 --- a/JavaScript/Array/Internal.hs +++ b/JavaScript/Array/Internal.hs @@ -16,7 +16,7 @@ import qualified GHC.Exts as Exts import GHC.Exts (State#) import GHCJS.Internal.Types -import qualified GHCJS.Prim as Prim +import qualified GHC.JS.Prim as Prim import GHCJS.Types newtype SomeJSArray (m :: MutabilityType s) = SomeJSArray JSVal diff --git a/JavaScript/Cast.hs b/JavaScript/Cast.hs index 517b36a..9282278 100644 --- a/JavaScript/Cast.hs +++ b/JavaScript/Cast.hs @@ -5,7 +5,7 @@ module JavaScript.Cast ( Cast(..) , unsafeCast ) where -import GHCJS.Prim +import GHC.JS.Prim cast :: forall a. Cast a => JSVal -> Maybe a cast x | js_checkCast x (instanceRef (undefined :: a)) = Just (unsafeWrap x) diff --git a/JavaScript/JSON/Types/Generic.hs b/JavaScript/JSON/Types/Generic.hs index 7cb5abd..2e5df98 100644 --- a/JavaScript/JSON/Types/Generic.hs +++ b/JavaScript/JSON/Types/Generic.hs @@ -28,7 +28,7 @@ import qualified Data.JSString as JSS import qualified JavaScript.JSON.Types.Internal as I import qualified JavaScript.Array as JSA import qualified JavaScript.Array.ST as JSAST -import Data.Bits +import Data.Bits hiding (And) import Data.DList (DList, toList, empty) diff --git a/JavaScript/JSON/Types/Instances.hs b/JavaScript/JSON/Types/Instances.hs index 2b288ec..a57374a 100644 --- a/JavaScript/JSON/Types/Instances.hs +++ b/JavaScript/JSON/Types/Instances.hs @@ -77,7 +77,7 @@ import Data.Monoid (Dual(..), First(..), Last(..), mappend) import Data.Ratio (Ratio, (%), numerator, denominator) import Data.Text (Text, pack, unpack) import Data.Time (UTCTime, ZonedTime(..), TimeZone(..)) -import Data.Time.Format (FormatTime, formatTime, parseTime) +import Data.Time.Format (FormatTime, formatTime, parseTimeM) import Data.Traversable (traverse) import Data.Vector (Vector) import Data.Word (Word, Word8, Word16, Word32, Word64) @@ -491,7 +491,7 @@ instance FromJSON DotNetTime where parseJSON = withJSString "DotNetTime" $ \t -> let (s,m) = JSS.splitAt (JSS.length t - 5) t t' = JSS.concat [s,".",m] - in case parseTime defaultTimeLocale "/Date(%s%Q)/" (JSS.unpack t') of + in case parseTimeM True defaultTimeLocale "/Date(%s%Q)/" (JSS.unpack t') of Just d -> pure (DotNetTime d) _ -> fail "could not parse .NET time" {-# INLINE parseJSON #-} @@ -513,7 +513,7 @@ instance FromJSON ZonedTime where <|> fail "could not parse ECMA-262 ISO-8601 date" where tryFormat f = - case parseTime defaultTimeLocale f (JSS.unpack t) of + case parseTimeM True defaultTimeLocale f (JSS.unpack t) of Just d -> pure d Nothing -> empty tryFormats = foldr1 (<|>) . map tryFormat @@ -536,7 +536,7 @@ instance ToJSON UTCTime where instance FromJSON UTCTime where parseJSON = withJSString "UTCTime" $ \t -> - case parseTime defaultTimeLocale "%FT%T%QZ" (JSS.unpack t) of + case parseTimeM True defaultTimeLocale "%FT%T%QZ" (JSS.unpack t) of Just d -> pure d _ -> fail "could not parse ISO-8601 date" {-# INLINE parseJSON #-} diff --git a/JavaScript/JSON/Types/Internal.hs b/JavaScript/JSON/Types/Internal.hs index f68689f..c2a6579 100644 --- a/JavaScript/JSON/Types/Internal.hs +++ b/JavaScript/JSON/Types/Internal.hs @@ -72,7 +72,7 @@ import GHC.Types (IO(..)) import qualified GHCJS.Foreign as F import GHCJS.Internal.Types import GHCJS.Types -import qualified GHCJS.Prim.Internal.Build as IB +import qualified GHC.JS.Prim.Internal.Build as IB import qualified JavaScript.Array as A import qualified JavaScript.Array.Internal as AI diff --git a/JavaScript/Object/Internal.hs b/JavaScript/Object/Internal.hs index aa05cb3..7b6ae30 100644 --- a/JavaScript/Object/Internal.hs +++ b/JavaScript/Object/Internal.hs @@ -21,7 +21,7 @@ module JavaScript.Object.Internal import Data.JSString import Data.Typeable -import qualified GHCJS.Prim as Prim +import qualified GHC.JS.Prim as Prim import GHCJS.Types import qualified JavaScript.Array as JA diff --git a/JavaScript/TypedArray/DataView.hs b/JavaScript/TypedArray/DataView.hs index 83e074b..4fcb05e 100644 --- a/JavaScript/TypedArray/DataView.hs +++ b/JavaScript/TypedArray/DataView.hs @@ -40,7 +40,7 @@ import GHC.Types (IO(..)) import Data.Int import Data.Word -import GHCJS.Prim +import GHC.JS.Prim import JavaScript.TypedArray.ArrayBuffer.Internal ( SomeArrayBuffer(..), ArrayBuffer, MutableArrayBuffer ) diff --git a/JavaScript/TypedArray/DataView/Internal.hs b/JavaScript/TypedArray/DataView/Internal.hs index e304cc6..0b53f6d 100644 --- a/JavaScript/TypedArray/DataView/Internal.hs +++ b/JavaScript/TypedArray/DataView/Internal.hs @@ -18,7 +18,7 @@ import Data.Word import GHC.Exts ( State# ) -import GHCJS.Prim +import GHC.JS.Prim import GHCJS.Internal.Types import JavaScript.TypedArray.ArrayBuffer.Internal diff --git a/JavaScript/TypedArray/DataView/ST.hs b/JavaScript/TypedArray/DataView/ST.hs index 1e2a59b..09b19dd 100644 --- a/JavaScript/TypedArray/DataView/ST.hs +++ b/JavaScript/TypedArray/DataView/ST.hs @@ -28,7 +28,7 @@ import Data.Word import GHC.ST -import GHCJS.Prim +import GHC.JS.Prim import JavaScript.TypedArray.ArrayBuffer.ST import JavaScript.TypedArray.ArrayBuffer.Internal as AI diff --git a/JavaScript/TypedArray/Internal.hs b/JavaScript/TypedArray/Internal.hs index 1118f86..126c7f6 100644 --- a/JavaScript/TypedArray/Internal.hs +++ b/JavaScript/TypedArray/Internal.hs @@ -48,10 +48,10 @@ elemSize a = js_elemSize a instance TypedArray IOInt8Array where index i a = IO (indexI8 i a) unsafeIndex i a = IO (unsafeIndexI8 i a) - setIndex i (I8# x) a = IO (setIndexI i x a) - unsafeSetIndex i (I8# x) a = IO (unsafeSetIndexI i x a) - indexOf s (I8# x) a = IO (indexOfI s x a) - lastIndexOf s (I8# x) a = IO (lastIndexOfI s x a) + setIndex i (I8# x) a = IO (setIndexI i (int8ToInt# x) a) + unsafeSetIndex i (I8# x) a = IO (unsafeSetIndexI i (int8ToInt# x) a) + indexOf s (I8# x) a = IO (indexOfI s (int8ToInt# x) a) + lastIndexOf s (I8# x) a = IO (lastIndexOfI s (int8ToInt# x) a) create l = IO (js_createInt8Array l) fromArray a = int8ArrayFrom a fromArrayBuffer b = undefined @@ -59,10 +59,10 @@ instance TypedArray IOInt8Array where instance TypedArray IOInt16Array where index i a = IO (indexI16 i a) unsafeIndex i a = IO (unsafeIndexI16 i a) - setIndex i (I16# x) a = IO (setIndexI i x a) - unsafeSetIndex i (I16# x) a = IO (unsafeSetIndexI i x a) - indexOf s (I16# x) a = IO (indexOfI s x a) - lastIndexOf s (I16# x) a = IO (lastIndexOfI s x a) + setIndex i (I16# x) a = IO (setIndexI i (int16ToInt# x) a) + unsafeSetIndex i (I16# x) a = IO (unsafeSetIndexI i (int16ToInt# x) a) + indexOf s (I16# x) a = IO (indexOfI s (int16ToInt# x) a) + lastIndexOf s (I16# x) a = IO (lastIndexOfI s (int16ToInt# x) a) create l = IO (js_createInt16Array l) fromArray a = int16ArrayFrom a fromArrayBuffer b = undefined @@ -81,10 +81,10 @@ instance TypedArray IOInt32Array where instance TypedArray IOUint8ClampedArray where index i a = IO (indexW8 i a) unsafeIndex i a = IO (unsafeIndexW8 i a) - setIndex i (W8# x) a = IO (setIndexW i x a) - unsafeSetIndex i (W8# x) a = IO (unsafeSetIndexW i x a) - indexOf s (W8# x) a = IO (indexOfW s x a) - lastIndexOf s (W8# x) a = IO (lastIndexOfW s x a) + setIndex i (W8# x) a = IO (setIndexW i (word8ToWord# x) a) + unsafeSetIndex i (W8# x) a = IO (unsafeSetIndexW i (word8ToWord# x) a) + indexOf s (W8# x) a = IO (indexOfW s (word8ToWord# x) a) + lastIndexOf s (W8# x) a = IO (lastIndexOfW s (word8ToWord# x) a) create l = IO (js_createUint8ClampedArray l) fromArray a = uint8ClampedArrayFrom a fromArrayBuffer b = undefined @@ -92,10 +92,10 @@ instance TypedArray IOUint8ClampedArray where instance TypedArray IOUint8Array where index i a = IO (indexW8 i a) unsafeIndex i a = IO (unsafeIndexW8 i a) - setIndex i (W8# x) a = IO (setIndexW i x a) - unsafeSetIndex i (W8# x) a = IO (unsafeSetIndexW i x a) - indexOf s (W8# x) a = IO (indexOfW s x a) - lastIndexOf s (W8# x) a = IO (lastIndexOfW s x a) + setIndex i (W8# x) a = IO (setIndexW i (word8ToWord# x) a) + unsafeSetIndex i (W8# x) a = IO (unsafeSetIndexW i (word8ToWord# x) a) + indexOf s (W8# x) a = IO (indexOfW s (word8ToWord# x) a) + lastIndexOf s (W8# x) a = IO (lastIndexOfW s (word8ToWord# x) a) create l = IO (js_createUint8Array l) fromArray a = uint8ArrayFrom a fromArrayBuffer b = undefined @@ -103,10 +103,10 @@ instance TypedArray IOUint8Array where instance TypedArray IOUint16Array where index i a = IO (indexW16 i a) unsafeIndex i a = IO (unsafeIndexW16 i a) - setIndex i (W16# x) a = IO (setIndexW i x a) - unsafeSetIndex i (W16# x) a = IO (unsafeSetIndexW i x a) - indexOf s (W16# x) a = IO (indexOfW s x a) - lastIndexOf s (W16# x) a = IO (lastIndexOfW s x a) + setIndex i (W16# x) a = IO (setIndexW i (word16ToWord# x) a) + unsafeSetIndex i (W16# x) a = IO (unsafeSetIndexW i (word16ToWord# x) a) + indexOf s (W16# x) a = IO (indexOfW s (word16ToWord# x) a) + lastIndexOf s (W16# x) a = IO (lastIndexOfW s (word16ToWord# x) a) create l = IO (js_createUint16Array l) fromArray a = uint16ArrayFrom a fromArrayBuffer b = undefined @@ -163,11 +163,11 @@ indexI a i = \s -> case js_indexI a i s of (# s', v #) -> (# s', I# v #) {-# INLINE indexI #-} indexI16 :: Int -> SomeTypedArray e m -> State# s -> (# State# s, Int16 #) -indexI16 a i = \s -> case js_indexI a i s of (# s', v #) -> (# s', I16# v #) +indexI16 a i = \s -> case js_indexI a i s of (# s', v #) -> (# s', I16# (intToInt16# v) #) {-# INLINE indexI16 #-} indexI8 :: Int -> SomeTypedArray e m -> State# s -> (# State# s, Int8 #) -indexI8 a i = \s -> case js_indexI a i s of (# s', v #) -> (# s', I8# v #) +indexI8 a i = \s -> case js_indexI a i s of (# s', v #) -> (# s', I8# (intToInt8# v) #) {-# INLINE indexI8 #-} indexW :: Int -> SomeTypedArray e m -> State# s -> (# State# s, Word #) @@ -175,11 +175,11 @@ indexW a i = \s -> case js_indexW a i s of (# s', v #) -> (# s', W# v #) {-# INLINE indexW #-} indexW16 :: Int -> SomeTypedArray e m -> State# s -> (# State# s, Word16 #) -indexW16 a i = \s -> case js_indexW a i s of (# s', v #) -> (# s', W16# v #) +indexW16 a i = \s -> case js_indexW a i s of (# s', v #) -> (# s', W16# (wordToWord16# v) #) {-# INLINE indexW16 #-} indexW8 :: Int -> SomeTypedArray e m -> State# s -> (# State# s, Word8 #) -indexW8 a i = \s -> case js_indexW a i s of (# s', v #) -> (# s', W8# v #) +indexW8 a i = \s -> case js_indexW a i s of (# s', v #) -> (# s', W8# (wordToWord8# v) #) {-# INLINE indexW8 #-} indexD :: Int -> SomeTypedArray e m -> State# s -> (# State# s, Double #) @@ -193,11 +193,11 @@ unsafeIndexI a i = \s -> case js_unsafeIndexI a i s of (# s', v #) -> (# s', I# {-# INLINE unsafeIndexI #-} unsafeIndexI16 :: Int -> SomeTypedArray e m -> State# s -> (# State# s, Int16 #) -unsafeIndexI16 a i = \s -> case js_unsafeIndexI a i s of (# s', v #) -> (# s', I16# v #) +unsafeIndexI16 a i = \s -> case js_unsafeIndexI a i s of (# s', v #) -> (# s', I16# (intToInt16# v) #) {-# INLINE unsafeIndexI16 #-} unsafeIndexI8 :: Int -> SomeTypedArray e m -> State# s -> (# State# s, Int8 #) -unsafeIndexI8 a i = \s -> case js_unsafeIndexI a i s of (# s', v #) -> (# s', I8# v #) +unsafeIndexI8 a i = \s -> case js_unsafeIndexI a i s of (# s', v #) -> (# s', I8# (intToInt8# v) #) {-# INLINE unsafeIndexI8 #-} unsafeIndexW :: Int -> SomeTypedArray e m -> State# s -> (# State# s, Word #) @@ -205,11 +205,11 @@ unsafeIndexW a i = \s -> case js_unsafeIndexW a i s of (# s', v #) -> (# s', W# {-# INLINE unsafeIndexW #-} unsafeIndexW16 :: Int -> SomeTypedArray e m -> State# s -> (# State# s, Word16 #) -unsafeIndexW16 a i = \s -> case js_unsafeIndexW a i s of (# s', v #) -> (# s', W16# v #) +unsafeIndexW16 a i = \s -> case js_unsafeIndexW a i s of (# s', v #) -> (# s', W16# (wordToWord16# v) #) {-# INLINE unsafeIndexW16 #-} unsafeIndexW8 :: Int -> SomeTypedArray e m -> State# s -> (# State# s, Word8 #) -unsafeIndexW8 a i = \s -> case js_unsafeIndexW a i s of (# s', v #) -> (# s', W8# v #) +unsafeIndexW8 a i = \s -> case js_unsafeIndexW a i s of (# s', v #) -> (# s', W8# (wordToWord8# v) #) {-# INLINE unsafeIndexW8 #-} unsafeIndexD :: Int -> SomeTypedArray e m -> State# s -> (# State# s, Double #) diff --git a/JavaScript/TypedArray/ST.hs b/JavaScript/TypedArray/ST.hs index 6fbe27a..a34a660 100644 --- a/JavaScript/TypedArray/ST.hs +++ b/JavaScript/TypedArray/ST.hs @@ -24,7 +24,7 @@ import GHC.Word import GHCJS.Types import GHCJS.Buffer.Types -import GHCJS.Prim +import GHC.JS.Prim import GHCJS.Internal.Types import qualified Data.ByteString as B @@ -53,11 +53,11 @@ class STTypedArray s a where instance STTypedArray s (STInt8Array s) where index i a = ST (I.indexI8 i a) unsafeIndex i a = ST (I.unsafeIndexI8 i a) - setIndex i (I8# x) a = ST (I.setIndexI i x a) - unsafeSetIndex i (I8# x) a = ST (I.unsafeSetIndexI i x a) - indexOf s (I8# x) a = ST (I.indexOfI s x a) + setIndex i (I8# x) a = ST (I.setIndexI i (int8ToInt# x) a) + unsafeSetIndex i (I8# x) a = ST (I.unsafeSetIndexI i (int8ToInt# x) a) + indexOf s (I8# x) a = ST (I.indexOfI s (int8ToInt# x) a) fromBuffer = undefined - lastIndexOf s (I8# x) a = ST (I.lastIndexOfI s x a) + lastIndexOf s (I8# x) a = ST (I.lastIndexOfI s (int8ToInt# x) a) create l = ST (I.js_createInt8Array l) -- --------------------------------------------------------------------------- diff --git a/JavaScript/Web/WebSocket.hs b/JavaScript/Web/WebSocket.hs index b298b83..4f42aa8 100644 --- a/JavaScript/Web/WebSocket.hs +++ b/JavaScript/Web/WebSocket.hs @@ -27,7 +27,7 @@ module JavaScript.Web.WebSocket ( WebSocket ) where import GHCJS.Concurrent -import GHCJS.Prim +import GHC.JS.Prim import GHCJS.Foreign.Callback.Internal (Callback(..)) import qualified GHCJS.Foreign.Callback as CB diff --git a/JavaScript/Web/Worker.hs b/JavaScript/Web/Worker.hs index ef5f93d..f086023 100644 --- a/JavaScript/Web/Worker.hs +++ b/JavaScript/Web/Worker.hs @@ -6,7 +6,7 @@ module JavaScript.Web.Worker ( Worker , terminate ) where -import GHCJS.Prim +import GHC.JS.Prim import Data.JSString import Data.Typeable diff --git a/JavaScript/Web/XMLHttpRequest.hs b/JavaScript/Web/XMLHttpRequest.hs index 70a3f8e..f378107 100644 --- a/JavaScript/Web/XMLHttpRequest.hs +++ b/JavaScript/Web/XMLHttpRequest.hs @@ -22,7 +22,7 @@ import Control.Exception import Control.Monad import GHCJS.Types -import GHCJS.Prim +import GHC.JS.Prim import GHCJS.Marshal import GHCJS.Marshal.Pure import GHCJS.Internal.Types diff --git a/ghcjs-base.cabal b/ghcjs-base.cabal index 94b9cc5..cc61c3a 100644 --- a/ghcjs-base.cabal +++ b/ghcjs-base.cabal @@ -16,16 +16,16 @@ source-repository head library if impl(ghc >= 8.10.1) - js-sources: jsbits/array.js.pp - jsbits/animationFrame.js.pp - jsbits/export.js.pp - jsbits/jsstring.js.pp - jsbits/jsstringRaw.js.pp - jsbits/foreign.js.pp - jsbits/text.js.pp - jsbits/utils.js.pp - jsbits/xhr.js.pp - jsbits/websocket.js.pp + js-sources: jsbits/array.js + jsbits/animationFrame.js + jsbits/export.js + jsbits/jsstring.js + jsbits/jsstringRaw.js + jsbits/foreign.js + jsbits/text.js + jsbits/utils.js + jsbits/xhr.js + jsbits/websocket.js else js-sources: jsbits-old/array.js jsbits-old/animationFrame.js @@ -40,7 +40,7 @@ library other-extensions: DeriveDataTypeable DeriveGeneric ForeignFunctionInterface - JavaScriptFFI +-- JavaScriptFFI GHCForeignImportPrim MagicHash UnboxedTuples @@ -140,8 +140,6 @@ library JavaScript.TypedArray.DataView.Internal build-depends: base >= 4.7 && < 5, ghc-prim, - ghcjs-prim, - integer-gmp, binary >= 0.8 && < 0.11, bytestring >= 0.10 && < 0.11, text >= 1.1 && < 1.3, @@ -158,7 +156,7 @@ library deepseq >= 1.3 && < 1.5, dlist >= 0.7 && < 1.1 default-language: Haskell2010 - if !impl(ghcjs) && !os(ghcjs) + if !arch(javascript) buildable: False test-suite tests @@ -184,7 +182,6 @@ test-suite tests deepseq, directory, ghc-prim, - ghcjs-prim, ghcjs-base, primitive, quickcheck-unicode, @@ -193,5 +190,5 @@ test-suite tests test-framework-hunit >= 0.2, test-framework-quickcheck2 >= 0.2 default-language: Haskell2010 - if !impl(ghcjs) && !os(ghcjs) + if !arch(javascript) buildable: False diff --git a/jsbits/animationFrame.js.pp b/jsbits/animationFrame.js similarity index 96% rename from jsbits/animationFrame.js.pp rename to jsbits/animationFrame.js index 7a3e942..bac2d4c 100644 --- a/jsbits/animationFrame.js.pp +++ b/jsbits/animationFrame.js @@ -1,3 +1,4 @@ +//#OPTIONS: CPP function h$animationFrameCancel(h) { if(h.handle) window.cancelAnimationFrame(h.handle); if(h.callback) { diff --git a/jsbits/array.js.pp b/jsbits/array.js similarity index 97% rename from jsbits/array.js.pp rename to jsbits/array.js index 8230cdf..d179ead 100644 --- a/jsbits/array.js.pp +++ b/jsbits/array.js @@ -1,4 +1,4 @@ -#include +//#OPTIONS: CPP /* convert an array to a Haskell list, wrapping each element in a diff --git a/jsbits/export.js.pp b/jsbits/export.js similarity index 97% rename from jsbits/export.js.pp rename to jsbits/export.js index cc3043a..9ea6902 100644 --- a/jsbits/export.js.pp +++ b/jsbits/export.js @@ -1,3 +1,4 @@ +//#OPTIONS: CPP function h$exportValue(fp1a,fp1b,fp2a,fp2b,o) { var e = { fp1a: fp1a , fp1b: fp1b diff --git a/jsbits/foreign.js.pp b/jsbits/foreign.js similarity index 91% rename from jsbits/foreign.js.pp rename to jsbits/foreign.js index a4e4cf0..34cd7c6 100644 --- a/jsbits/foreign.js.pp +++ b/jsbits/foreign.js @@ -1,3 +1,4 @@ +//#OPTIONS: CPP function h$foreignListProps(o) { var r = HS_NIL; if(typeof o === 'undefined' || o === null) return null; diff --git a/jsbits/json.js.pp b/jsbits/json.js.pp deleted file mode 100644 index 15d2ee3..0000000 --- a/jsbits/json.js.pp +++ /dev/null @@ -1,4 +0,0 @@ -#include - - - diff --git a/jsbits/jsstring.js.pp b/jsbits/jsstring.js similarity index 99% rename from jsbits/jsstring.js.pp rename to jsbits/jsstring.js index e8a4ef9..d476ee8 100644 --- a/jsbits/jsstring.js.pp +++ b/jsbits/jsstring.js @@ -1,4 +1,4 @@ -#include +//#OPTIONS: CPP /* * Support code for the Data.JSString module. This code presents a JSString diff --git a/jsbits/jsstringRaw.js.pp b/jsbits/jsstringRaw.js similarity index 96% rename from jsbits/jsstringRaw.js.pp rename to jsbits/jsstringRaw.js index 4d31c3c..3a4e457 100644 --- a/jsbits/jsstringRaw.js.pp +++ b/jsbits/jsstringRaw.js @@ -1,4 +1,4 @@ -#include +//#OPTIONS: CPP /* * Functions that directly access JavaScript strings, ignoring character diff --git a/jsbits/object.js.pp b/jsbits/object.js.pp deleted file mode 100644 index 44e0ca3..0000000 --- a/jsbits/object.js.pp +++ /dev/null @@ -1,2 +0,0 @@ -// object manipulation - diff --git a/jsbits/text.js.pp b/jsbits/text.js similarity index 98% rename from jsbits/text.js.pp rename to jsbits/text.js index 7046d36..e55c952 100644 --- a/jsbits/text.js.pp +++ b/jsbits/text.js @@ -1,5 +1,5 @@ +//#OPTIONS: CPP // conversion between JavaScript string and Data.Text -#include /* diff --git a/jsbits/utils.js.pp b/jsbits/utils.js similarity index 98% rename from jsbits/utils.js.pp rename to jsbits/utils.js index 722b793..202c523 100644 --- a/jsbits/utils.js.pp +++ b/jsbits/utils.js @@ -1,4 +1,4 @@ -#include +//#OPTIONS: CPP function h$allProps(o) { var a = [], i = 0; diff --git a/jsbits/websocket.js.pp b/jsbits/websocket.js similarity index 98% rename from jsbits/websocket.js.pp rename to jsbits/websocket.js index 25df07b..fb0e0da 100644 --- a/jsbits/websocket.js.pp +++ b/jsbits/websocket.js @@ -1,4 +1,4 @@ -#include +//#OPTIONS: CPP function h$createWebSocket(url, protocols) { return new WebSocket(url, protocols); diff --git a/jsbits/xhr.js.pp b/jsbits/xhr.js similarity index 94% rename from jsbits/xhr.js.pp rename to jsbits/xhr.js index 419cfe7..7520f7d 100644 --- a/jsbits/xhr.js.pp +++ b/jsbits/xhr.js @@ -1,3 +1,4 @@ +//#OPTIONS: CPP function h$sendXHR(xhr, d, cont) { xhr.addEventListener('error', function () { cont(2);