From 7ffb3158f577c48ab5de774abea47767921ef3e9 Mon Sep 17 00:00:00 2001 From: Josh Meredith Date: Wed, 21 Jun 2023 13:37:59 +0000 Subject: [PATCH] Update GHCJS conditions to also support the GHC JavaScript backend --- splitmix.cabal | 2 +- src/System/Random/SplitMix/Init.hs | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/splitmix.cabal b/splitmix.cabal index 9ada26f..53198c8 100644 --- a/splitmix.cabal +++ b/splitmix.cabal @@ -90,7 +90,7 @@ library -- because it's valuable that splitmix and QuickCheck doesn't -- depend on about anything - if impl(ghcjs) + if impl(ghcjs) || arch(javascript) cpp-options: -DSPLITMIX_INIT_GHCJS=1 else diff --git a/src/System/Random/SplitMix/Init.hs b/src/System/Random/SplitMix/Init.hs index 59a97d2..0e4cbbc 100644 --- a/src/System/Random/SplitMix/Init.hs +++ b/src/System/Random/SplitMix/Init.hs @@ -6,7 +6,7 @@ module System.Random.SplitMix.Init ( import Data.Word (Word64) -#if defined(SPLITMIX_INIT_GHCJS) && __GHCJS__ +#if defined(SPLITMIX_INIT_GHCJS) && (__GHCJS__ || defined(javascript_HOST_ARCH)) import Data.Word (Word32) @@ -26,12 +26,17 @@ import System.CPUTime (cpuTimePrecision, getCPUTime) initialSeed :: IO Word64 -#if defined(SPLITMIX_INIT_GHCJS) && __GHCJS__ +#if defined(SPLITMIX_INIT_GHCJS) && (__GHCJS__ || defined(javascript_HOST_ARCH)) initialSeed = fmap fromIntegral initialSeedJS foreign import javascript +#if __GHCJS__ "$r = Math.floor(Math.random()*0x100000000);" +#else + -- defined(javascript_HOST_ARCH) + "(() => { return Math.floor(Math.random()*0x100000000); })" +#endif initialSeedJS :: IO Word32 #else @@ -56,3 +61,4 @@ initialSeed = do #endif #endif +