{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE TupleSections #-}

module GHC.JS.Transform
  ( identsS
  , identsV
  , identsE
  -- * Saturation
  , satJStat
  , satJExpr
  -- * Generic traversal (via compos)
  , JMacro(..)
  , JMGadt(..)
  , Compos(..)
  , composOp
  , composOpM
  , composOpM_
  , composOpFold
  )
where

import GHC.Prelude

import qualified GHC.JS.Syntax as Sat
import GHC.JS.Unsat.Syntax

import Data.Functor.Identity
import Control.Monad
import Data.List (sortBy)

import GHC.Data.FastString
import GHC.Utils.Monad.State.Strict
import GHC.Types.Unique.Map
import GHC.Types.Unique.FM


{-# INLINE identsS #-}
identsS :: Sat.JStat -> [Ident]
identsS :: JStat -> [Ident]
identsS = \case
  Sat.DeclStat Ident
i Maybe JExpr
e       -> [Ident
i] [Ident] -> [Ident] -> [Ident]
forall a. [a] -> [a] -> [a]
++ [Ident] -> (JExpr -> [Ident]) -> Maybe JExpr -> [Ident]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] JExpr -> [Ident]
identsE Maybe JExpr
e
  Sat.ReturnStat JExpr
e       -> JExpr -> [Ident]
identsE JExpr
e
  Sat.IfStat JExpr
e JStat
s1 JStat
s2     -> JExpr -> [Ident]
identsE JExpr
e [Ident] -> [Ident] -> [Ident]
forall a. [a] -> [a] -> [a]
++ JStat -> [Ident]
identsS JStat
s1 [Ident] -> [Ident] -> [Ident]
forall a. [a] -> [a] -> [a]
++ JStat -> [Ident]
identsS JStat
s2
  Sat.WhileStat Bool
_ JExpr
e JStat
s    -> JExpr -> [Ident]
identsE JExpr
e [Ident] -> [Ident] -> [Ident]
forall a. [a] -> [a] -> [a]
++ JStat -> [Ident]
identsS JStat
s
  Sat.ForStat JStat
init JExpr
p JStat
step JStat
body -> JStat -> [Ident]
identsS JStat
init [Ident] -> [Ident] -> [Ident]
forall a. [a] -> [a] -> [a]
++ JExpr -> [Ident]
identsE JExpr
p [Ident] -> [Ident] -> [Ident]
forall a. [a] -> [a] -> [a]
++ JStat -> [Ident]
identsS JStat
step [Ident] -> [Ident] -> [Ident]
forall a. [a] -> [a] -> [a]
++ JStat -> [Ident]
identsS JStat
body
  Sat.ForInStat Bool
_ Ident
i JExpr
e JStat
s  -> [Ident
i] [Ident] -> [Ident] -> [Ident]
forall a. [a] -> [a] -> [a]
++ JExpr -> [Ident]
identsE JExpr
e [Ident] -> [Ident] -> [Ident]
forall a. [a] -> [a] -> [a]
++ JStat -> [Ident]
identsS JStat
s
  Sat.SwitchStat JExpr
e [(JExpr, JStat)]
xs JStat
s  -> JExpr -> [Ident]
identsE JExpr
e [Ident] -> [Ident] -> [Ident]
forall a. [a] -> [a] -> [a]
++ ((JExpr, JStat) -> [Ident]) -> [(JExpr, JStat)] -> [Ident]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (JExpr, JStat) -> [Ident]
traverseCase [(JExpr, JStat)]
xs [Ident] -> [Ident] -> [Ident]
forall a. [a] -> [a] -> [a]
++ JStat -> [Ident]
identsS JStat
s
                               where traverseCase :: (JExpr, JStat) -> [Ident]
traverseCase (JExpr
e,JStat
s) = JExpr -> [Ident]
identsE JExpr
e [Ident] -> [Ident] -> [Ident]
forall a. [a] -> [a] -> [a]
++ JStat -> [Ident]
identsS JStat
s
  Sat.TryStat JStat
s1 Ident
i JStat
s2 JStat
s3 -> JStat -> [Ident]
identsS JStat
s1 [Ident] -> [Ident] -> [Ident]
forall a. [a] -> [a] -> [a]
++ [Ident
i] [Ident] -> [Ident] -> [Ident]
forall a. [a] -> [a] -> [a]
++ JStat -> [Ident]
identsS JStat
s2 [Ident] -> [Ident] -> [Ident]
forall a. [a] -> [a] -> [a]
++ JStat -> [Ident]
identsS JStat
s3
  Sat.BlockStat [JStat]
xs       -> (JStat -> [Ident]) -> [JStat] -> [Ident]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap JStat -> [Ident]
identsS [JStat]
xs
  Sat.ApplStat JExpr
e [JExpr]
es      -> JExpr -> [Ident]
identsE JExpr
e [Ident] -> [Ident] -> [Ident]
forall a. [a] -> [a] -> [a]
++ (JExpr -> [Ident]) -> [JExpr] -> [Ident]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap JExpr -> [Ident]
identsE [JExpr]
es
  Sat.UOpStat UOp
_op JExpr
e      -> JExpr -> [Ident]
identsE JExpr
e
  Sat.AssignStat JExpr
e1 AOp
_op JExpr
e2 -> JExpr -> [Ident]
identsE JExpr
e1 [Ident] -> [Ident] -> [Ident]
forall a. [a] -> [a] -> [a]
++ JExpr -> [Ident]
identsE JExpr
e2
  Sat.LabelStat JLabel
_l JStat
s     -> JStat -> [Ident]
identsS JStat
s
  Sat.BreakStat{}        -> []
  Sat.ContinueStat{}     -> []
  Sat.FuncStat Ident
i [Ident]
args JStat
body -> [Ident
i] [Ident] -> [Ident] -> [Ident]
forall a. [a] -> [a] -> [a]
++ [Ident]
args [Ident] -> [Ident] -> [Ident]
forall a. [a] -> [a] -> [a]
++ JStat -> [Ident]
identsS JStat
body

{-# INLINE identsE #-}
identsE :: Sat.JExpr -> [Ident]
identsE :: JExpr -> [Ident]
identsE = \case
  Sat.ValExpr JVal
v         -> JVal -> [Ident]
identsV JVal
v
  Sat.SelExpr JExpr
e Ident
_i      -> JExpr -> [Ident]
identsE JExpr
e -- do not rename properties
  Sat.IdxExpr JExpr
e1 JExpr
e2     -> JExpr -> [Ident]
identsE JExpr
e1 [Ident] -> [Ident] -> [Ident]
forall a. [a] -> [a] -> [a]
++ JExpr -> [Ident]
identsE JExpr
e2
  Sat.InfixExpr Op
_ JExpr
e1 JExpr
e2 -> JExpr -> [Ident]
identsE JExpr
e1 [Ident] -> [Ident] -> [Ident]
forall a. [a] -> [a] -> [a]
++ JExpr -> [Ident]
identsE JExpr
e2
  Sat.UOpExpr UOp
_ JExpr
e       -> JExpr -> [Ident]
identsE JExpr
e
  Sat.IfExpr JExpr
e1 JExpr
e2 JExpr
e3   -> JExpr -> [Ident]
identsE JExpr
e1 [Ident] -> [Ident] -> [Ident]
forall a. [a] -> [a] -> [a]
++ JExpr -> [Ident]
identsE JExpr
e2 [Ident] -> [Ident] -> [Ident]
forall a. [a] -> [a] -> [a]
++ JExpr -> [Ident]
identsE JExpr
e3
  Sat.ApplExpr JExpr
e [JExpr]
es     -> JExpr -> [Ident]
identsE JExpr
e  [Ident] -> [Ident] -> [Ident]
forall a. [a] -> [a] -> [a]
++ (JExpr -> [Ident]) -> [JExpr] -> [Ident]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap JExpr -> [Ident]
identsE [JExpr]
es

{-# INLINE identsV #-}
identsV :: Sat.JVal -> [Ident]
identsV :: JVal -> [Ident]
identsV = \case
  Sat.JVar Ident
i       -> [Ident
i]
  Sat.JList [JExpr]
xs     -> (JExpr -> [Ident]) -> [JExpr] -> [Ident]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap JExpr -> [Ident]
identsE [JExpr]
xs
  Sat.JDouble{}    -> []
  Sat.JInt{}       -> []
  Sat.JStr{}       -> []
  Sat.JRegEx{}     -> []
  Sat.JHash UniqMap FastString JExpr
m      -> (JExpr -> [Ident]) -> [JExpr] -> [Ident]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap JExpr -> [Ident]
identsE (UniqMap FastString JExpr -> [JExpr]
forall k a. UniqMap k a -> [a]
nonDetEltsUniqMap UniqMap FastString JExpr
m)
  Sat.JFunc [Ident]
args JStat
s -> [Ident]
args [Ident] -> [Ident] -> [Ident]
forall a. [a] -> [a] -> [a]
++ JStat -> [Ident]
identsS JStat
s


{--------------------------------------------------------------------
  Compos
--------------------------------------------------------------------}
-- | Compos and ops for generic traversal as defined over
-- the JMacro ADT.

-- | Utility class to coerce the ADT into a regular structure.

class JMacro a where
    jtoGADT :: a -> JMGadt a
    jfromGADT :: JMGadt a -> a

instance JMacro Ident where
    jtoGADT :: Ident -> JMGadt Ident
jtoGADT = Ident -> JMGadt Ident
JMGId
    jfromGADT :: JMGadt Ident -> Ident
jfromGADT (JMGId Ident
x) = Ident
x

instance JMacro JStat where
    jtoGADT :: JStat -> JMGadt JStat
jtoGADT = JStat -> JMGadt JStat
JMGStat
    jfromGADT :: JMGadt JStat -> JStat
jfromGADT (JMGStat JStat
x) = JStat
x

instance JMacro JExpr where
    jtoGADT :: JExpr -> JMGadt JExpr
jtoGADT = JExpr -> JMGadt JExpr
JMGExpr
    jfromGADT :: JMGadt JExpr -> JExpr
jfromGADT (JMGExpr JExpr
x) = JExpr
x

instance JMacro JVal where
    jtoGADT :: JVal -> JMGadt JVal
jtoGADT = JVal -> JMGadt JVal
JMGVal
    jfromGADT :: JMGadt JVal -> JVal
jfromGADT (JMGVal JVal
x) = JVal
x

-- | Union type to allow regular traversal by compos.
data JMGadt a where
    JMGId   :: Ident -> JMGadt Ident
    JMGStat :: JStat -> JMGadt JStat
    JMGExpr :: JExpr -> JMGadt JExpr
    JMGVal  :: JVal  -> JMGadt JVal

composOp :: Compos t => (forall a. t a -> t a) -> t b -> t b
composOp :: forall (t :: * -> *) b.
Compos t =>
(forall a. t a -> t a) -> t b -> t b
composOp forall a. t a -> t a
f = Identity (t b) -> t b
forall a. Identity a -> a
runIdentity (Identity (t b) -> t b) -> (t b -> Identity (t b)) -> t b -> t b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. t a -> Identity (t a)) -> t b -> Identity (t b)
forall (t :: * -> *) (m :: * -> *) b.
(Compos t, Monad m) =>
(forall a. t a -> m (t a)) -> t b -> m (t b)
composOpM (t a -> Identity (t a)
forall a. a -> Identity a
Identity (t a -> Identity (t a)) -> (t a -> t a) -> t a -> Identity (t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t a -> t a
forall a. t a -> t a
f)

composOpM :: (Compos t, Monad m) => (forall a. t a -> m (t a)) -> t b -> m (t b)
composOpM :: forall (t :: * -> *) (m :: * -> *) b.
(Compos t, Monad m) =>
(forall a. t a -> m (t a)) -> t b -> m (t b)
composOpM = (forall a. a -> m a)
-> (forall a b. m (a -> b) -> m a -> m b)
-> (forall a. t a -> m (t a))
-> t b
-> m (t b)
forall (t :: * -> *) (m :: * -> *) c.
Compos t =>
(forall a. a -> m a)
-> (forall a b. m (a -> b) -> m a -> m b)
-> (forall a. t a -> m (t a))
-> t c
-> m (t c)
forall (m :: * -> *) c.
(forall a. a -> m a)
-> (forall a b. m (a -> b) -> m a -> m b)
-> (forall a. t a -> m (t a))
-> t c
-> m (t c)
compos a -> m a
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return m (a -> b) -> m a -> m b
forall a b. m (a -> b) -> m a -> m b
forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
ap

composOpM_ :: (Compos t, Monad m) => (forall a. t a -> m ()) -> t b -> m ()
composOpM_ :: forall (t :: * -> *) (m :: * -> *) b.
(Compos t, Monad m) =>
(forall a. t a -> m ()) -> t b -> m ()
composOpM_ = m ()
-> (m () -> m () -> m ()) -> (forall a. t a -> m ()) -> t b -> m ()
forall (t :: * -> *) b c.
Compos t =>
b -> (b -> b -> b) -> (forall a. t a -> b) -> t c -> b
composOpFold (() -> m ()
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()) m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
(>>)

composOpFold :: Compos t => b -> (b -> b -> b) -> (forall a. t a -> b) -> t c -> b
composOpFold :: forall (t :: * -> *) b c.
Compos t =>
b -> (b -> b -> b) -> (forall a. t a -> b) -> t c -> b
composOpFold b
z b -> b -> b
c forall a. t a -> b
f = C b (t c) -> b
forall b a. C b a -> b
unC (C b (t c) -> b) -> (t c -> C b (t c)) -> t c -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. a -> C b a)
-> (forall a b. C b (a -> b) -> C b a -> C b b)
-> (forall a. t a -> C b (t a))
-> t c
-> C b (t c)
forall (t :: * -> *) (m :: * -> *) c.
Compos t =>
(forall a. a -> m a)
-> (forall a b. m (a -> b) -> m a -> m b)
-> (forall a. t a -> m (t a))
-> t c
-> m (t c)
forall (m :: * -> *) c.
(forall a. a -> m a)
-> (forall a b. m (a -> b) -> m a -> m b)
-> (forall a. t a -> m (t a))
-> t c
-> m (t c)
compos (\a
_ -> b -> C b a
forall b a. b -> C b a
C b
z) (\(C b
x) (C b
y) -> b -> C b b
forall b a. b -> C b a
C (b -> b -> b
c b
x b
y)) (b -> C b (t a)
forall b a. b -> C b a
C (b -> C b (t a)) -> (t a -> b) -> t a -> C b (t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t a -> b
forall a. t a -> b
f)

newtype C b a = C { forall b a. C b a -> b
unC :: b }

class Compos t where
    compos :: (forall a. a -> m a) -> (forall a b. m (a -> b) -> m a -> m b)
           -> (forall a. t a -> m (t a)) -> t c -> m (t c)

instance Compos JMGadt where
    compos :: forall (m :: * -> *) c.
(forall a. a -> m a)
-> (forall a b. m (a -> b) -> m a -> m b)
-> (forall a. JMGadt a -> m (JMGadt a))
-> JMGadt c
-> m (JMGadt c)
compos = (forall a. a -> m a)
-> (forall a b. m (a -> b) -> m a -> m b)
-> (forall a. JMGadt a -> m (JMGadt a))
-> JMGadt c
-> m (JMGadt c)
forall (m :: * -> *) c.
(forall a. a -> m a)
-> (forall a b. m (a -> b) -> m a -> m b)
-> (forall a. JMGadt a -> m (JMGadt a))
-> JMGadt c
-> m (JMGadt c)
jmcompos

jmcompos :: forall m c. (forall a. a -> m a) -> (forall a b. m (a -> b) -> m a -> m b) -> (forall a. JMGadt a -> m (JMGadt a)) -> JMGadt c -> m (JMGadt c)
jmcompos :: forall (m :: * -> *) c.
(forall a. a -> m a)
-> (forall a b. m (a -> b) -> m a -> m b)
-> (forall a. JMGadt a -> m (JMGadt a))
-> JMGadt c
-> m (JMGadt c)
jmcompos forall a. a -> m a
ret forall a b. m (a -> b) -> m a -> m b
app forall a. JMGadt a -> m (JMGadt a)
f' JMGadt c
v =
    case JMGadt c
v of
     JMGId Ident
_ -> JMGadt c -> m (JMGadt c)
forall a. a -> m a
ret JMGadt c
v
     JMGStat JStat
v' -> (JStat -> JMGadt c) -> m (JStat -> JMGadt c)
forall a. a -> m a
ret JStat -> JMGadt c
JStat -> JMGadt JStat
JMGStat m (JStat -> JMGadt c) -> m JStat -> m (JMGadt c)
forall a b. m (a -> b) -> m a -> m b
`app` case JStat
v' of
           DeclStat Ident
i Maybe JExpr
e -> (Ident -> Maybe JExpr -> JStat)
-> m (Ident -> Maybe JExpr -> JStat)
forall a. a -> m a
ret Ident -> Maybe JExpr -> JStat
DeclStat m (Ident -> Maybe JExpr -> JStat)
-> m Ident -> m (Maybe JExpr -> JStat)
forall a b. m (a -> b) -> m a -> m b
`app` Ident -> m Ident
forall b. JMacro b => b -> m b
f Ident
i m (Maybe JExpr -> JStat) -> m (Maybe JExpr) -> m JStat
forall a b. m (a -> b) -> m a -> m b
`app` (JExpr -> m JExpr) -> Maybe JExpr -> m (Maybe JExpr)
forall a. (a -> m a) -> Maybe a -> m (Maybe a)
mapMaybeM' JExpr -> m JExpr
forall b. JMacro b => b -> m b
f Maybe JExpr
e
           ReturnStat JExpr
i -> (JExpr -> JStat) -> m (JExpr -> JStat)
forall a. a -> m a
ret JExpr -> JStat
ReturnStat m (JExpr -> JStat) -> m JExpr -> m JStat
forall a b. m (a -> b) -> m a -> m b
`app` JExpr -> m JExpr
forall b. JMacro b => b -> m b
f JExpr
i
           IfStat JExpr
e JStat
s JStat
s' -> (JExpr -> JStat -> JStat -> JStat)
-> m (JExpr -> JStat -> JStat -> JStat)
forall a. a -> m a
ret JExpr -> JStat -> JStat -> JStat
IfStat m (JExpr -> JStat -> JStat -> JStat)
-> m JExpr -> m (JStat -> JStat -> JStat)
forall a b. m (a -> b) -> m a -> m b
`app` JExpr -> m JExpr
forall b. JMacro b => b -> m b
f JExpr
e m (JStat -> JStat -> JStat) -> m JStat -> m (JStat -> JStat)
forall a b. m (a -> b) -> m a -> m b
`app` JStat -> m JStat
forall b. JMacro b => b -> m b
f JStat
s m (JStat -> JStat) -> m JStat -> m JStat
forall a b. m (a -> b) -> m a -> m b
`app` JStat -> m JStat
forall b. JMacro b => b -> m b
f JStat
s'
           WhileStat Bool
b JExpr
e JStat
s -> (JExpr -> JStat -> JStat) -> m (JExpr -> JStat -> JStat)
forall a. a -> m a
ret (Bool -> JExpr -> JStat -> JStat
WhileStat Bool
b) m (JExpr -> JStat -> JStat) -> m JExpr -> m (JStat -> JStat)
forall a b. m (a -> b) -> m a -> m b
`app` JExpr -> m JExpr
forall b. JMacro b => b -> m b
f JExpr
e m (JStat -> JStat) -> m JStat -> m JStat
forall a b. m (a -> b) -> m a -> m b
`app` JStat -> m JStat
forall b. JMacro b => b -> m b
f JStat
s
           ForStat JStat
init JExpr
p JStat
step JStat
body -> (JStat -> JExpr -> JStat -> JStat -> JStat)
-> m (JStat -> JExpr -> JStat -> JStat -> JStat)
forall a. a -> m a
ret JStat -> JExpr -> JStat -> JStat -> JStat
ForStat  m (JStat -> JExpr -> JStat -> JStat -> JStat)
-> m JStat -> m (JExpr -> JStat -> JStat -> JStat)
forall a b. m (a -> b) -> m a -> m b
`app` JStat -> m JStat
forall b. JMacro b => b -> m b
f JStat
init m (JExpr -> JStat -> JStat -> JStat)
-> m JExpr -> m (JStat -> JStat -> JStat)
forall a b. m (a -> b) -> m a -> m b
`app` JExpr -> m JExpr
forall b. JMacro b => b -> m b
f JExpr
p
                                           m (JStat -> JStat -> JStat) -> m JStat -> m (JStat -> JStat)
forall a b. m (a -> b) -> m a -> m b
`app` JStat -> m JStat
forall b. JMacro b => b -> m b
f JStat
step m (JStat -> JStat) -> m JStat -> m JStat
forall a b. m (a -> b) -> m a -> m b
`app` JStat -> m JStat
forall b. JMacro b => b -> m b
f JStat
body
           ForInStat Bool
b Ident
i JExpr
e JStat
s -> (Ident -> JExpr -> JStat -> JStat)
-> m (Ident -> JExpr -> JStat -> JStat)
forall a. a -> m a
ret (Bool -> Ident -> JExpr -> JStat -> JStat
ForInStat Bool
b) m (Ident -> JExpr -> JStat -> JStat)
-> m Ident -> m (JExpr -> JStat -> JStat)
forall a b. m (a -> b) -> m a -> m b
`app` Ident -> m Ident
forall b. JMacro b => b -> m b
f Ident
i m (JExpr -> JStat -> JStat) -> m JExpr -> m (JStat -> JStat)
forall a b. m (a -> b) -> m a -> m b
`app` JExpr -> m JExpr
forall b. JMacro b => b -> m b
f JExpr
e m (JStat -> JStat) -> m JStat -> m JStat
forall a b. m (a -> b) -> m a -> m b
`app` JStat -> m JStat
forall b. JMacro b => b -> m b
f JStat
s
           SwitchStat JExpr
e [(JExpr, JStat)]
l JStat
d -> (JExpr -> [(JExpr, JStat)] -> JStat -> JStat)
-> m (JExpr -> [(JExpr, JStat)] -> JStat -> JStat)
forall a. a -> m a
ret JExpr -> [(JExpr, JStat)] -> JStat -> JStat
SwitchStat m (JExpr -> [(JExpr, JStat)] -> JStat -> JStat)
-> m JExpr -> m ([(JExpr, JStat)] -> JStat -> JStat)
forall a b. m (a -> b) -> m a -> m b
`app` JExpr -> m JExpr
forall b. JMacro b => b -> m b
f JExpr
e m ([(JExpr, JStat)] -> JStat -> JStat)
-> m [(JExpr, JStat)] -> m (JStat -> JStat)
forall a b. m (a -> b) -> m a -> m b
`app` m [(JExpr, JStat)]
l' m (JStat -> JStat) -> m JStat -> m JStat
forall a b. m (a -> b) -> m a -> m b
`app` JStat -> m JStat
forall b. JMacro b => b -> m b
f JStat
d
               where l' :: m [(JExpr, JStat)]
l' = ((JExpr, JStat) -> m (JExpr, JStat))
-> [(JExpr, JStat)] -> m [(JExpr, JStat)]
forall a. (a -> m a) -> [a] -> m [a]
mapM' (\(JExpr
c,JStat
s) -> (JExpr -> JStat -> (JExpr, JStat))
-> m (JExpr -> JStat -> (JExpr, JStat))
forall a. a -> m a
ret (,) m (JExpr -> JStat -> (JExpr, JStat))
-> m JExpr -> m (JStat -> (JExpr, JStat))
forall a b. m (a -> b) -> m a -> m b
`app` JExpr -> m JExpr
forall b. JMacro b => b -> m b
f JExpr
c m (JStat -> (JExpr, JStat)) -> m JStat -> m (JExpr, JStat)
forall a b. m (a -> b) -> m a -> m b
`app` JStat -> m JStat
forall b. JMacro b => b -> m b
f JStat
s) [(JExpr, JStat)]
l
           BlockStat [JStat]
xs -> ([JStat] -> JStat) -> m ([JStat] -> JStat)
forall a. a -> m a
ret [JStat] -> JStat
BlockStat m ([JStat] -> JStat) -> m [JStat] -> m JStat
forall a b. m (a -> b) -> m a -> m b
`app` (JStat -> m JStat) -> [JStat] -> m [JStat]
forall a. (a -> m a) -> [a] -> m [a]
mapM' JStat -> m JStat
forall b. JMacro b => b -> m b
f [JStat]
xs
           ApplStat  JExpr
e [JExpr]
xs -> (JExpr -> [JExpr] -> JStat) -> m (JExpr -> [JExpr] -> JStat)
forall a. a -> m a
ret JExpr -> [JExpr] -> JStat
ApplStat m (JExpr -> [JExpr] -> JStat) -> m JExpr -> m ([JExpr] -> JStat)
forall a b. m (a -> b) -> m a -> m b
`app` JExpr -> m JExpr
forall b. JMacro b => b -> m b
f JExpr
e m ([JExpr] -> JStat) -> m [JExpr] -> m JStat
forall a b. m (a -> b) -> m a -> m b
`app` (JExpr -> m JExpr) -> [JExpr] -> m [JExpr]
forall a. (a -> m a) -> [a] -> m [a]
mapM' JExpr -> m JExpr
forall b. JMacro b => b -> m b
f [JExpr]
xs
           TryStat JStat
s Ident
i JStat
s1 JStat
s2 -> (JStat -> Ident -> JStat -> JStat -> JStat)
-> m (JStat -> Ident -> JStat -> JStat -> JStat)
forall a. a -> m a
ret JStat -> Ident -> JStat -> JStat -> JStat
TryStat m (JStat -> Ident -> JStat -> JStat -> JStat)
-> m JStat -> m (Ident -> JStat -> JStat -> JStat)
forall a b. m (a -> b) -> m a -> m b
`app` JStat -> m JStat
forall b. JMacro b => b -> m b
f JStat
s m (Ident -> JStat -> JStat -> JStat)
-> m Ident -> m (JStat -> JStat -> JStat)
forall a b. m (a -> b) -> m a -> m b
`app` Ident -> m Ident
forall b. JMacro b => b -> m b
f Ident
i m (JStat -> JStat -> JStat) -> m JStat -> m (JStat -> JStat)
forall a b. m (a -> b) -> m a -> m b
`app` JStat -> m JStat
forall b. JMacro b => b -> m b
f JStat
s1 m (JStat -> JStat) -> m JStat -> m JStat
forall a b. m (a -> b) -> m a -> m b
`app` JStat -> m JStat
forall b. JMacro b => b -> m b
f JStat
s2
           UOpStat JUOp
o JExpr
e -> (JExpr -> JStat) -> m (JExpr -> JStat)
forall a. a -> m a
ret (JUOp -> JExpr -> JStat
UOpStat JUOp
o) m (JExpr -> JStat) -> m JExpr -> m JStat
forall a b. m (a -> b) -> m a -> m b
`app` JExpr -> m JExpr
forall b. JMacro b => b -> m b
f JExpr
e
           AssignStat JExpr
e JExpr
e' -> (JExpr -> JExpr -> JStat) -> m (JExpr -> JExpr -> JStat)
forall a. a -> m a
ret JExpr -> JExpr -> JStat
AssignStat m (JExpr -> JExpr -> JStat) -> m JExpr -> m (JExpr -> JStat)
forall a b. m (a -> b) -> m a -> m b
`app` JExpr -> m JExpr
forall b. JMacro b => b -> m b
f JExpr
e m (JExpr -> JStat) -> m JExpr -> m JStat
forall a b. m (a -> b) -> m a -> m b
`app` JExpr -> m JExpr
forall b. JMacro b => b -> m b
f JExpr
e'
           UnsatBlock IdentSupply JStat
_ -> JStat -> m JStat
forall a. a -> m a
ret JStat
v'
           ContinueStat Maybe JLabel
l -> JStat -> m JStat
forall a. a -> m a
ret (Maybe JLabel -> JStat
ContinueStat Maybe JLabel
l)
           FuncStat Ident
i [Ident]
args JStat
body -> (Ident -> [Ident] -> JStat -> JStat)
-> m (Ident -> [Ident] -> JStat -> JStat)
forall a. a -> m a
ret Ident -> [Ident] -> JStat -> JStat
FuncStat m (Ident -> [Ident] -> JStat -> JStat)
-> m Ident -> m ([Ident] -> JStat -> JStat)
forall a b. m (a -> b) -> m a -> m b
`app` Ident -> m Ident
forall b. JMacro b => b -> m b
f Ident
i m ([Ident] -> JStat -> JStat) -> m [Ident] -> m (JStat -> JStat)
forall a b. m (a -> b) -> m a -> m b
`app` (Ident -> m Ident) -> [Ident] -> m [Ident]
forall a. (a -> m a) -> [a] -> m [a]
mapM' Ident -> m Ident
forall b. JMacro b => b -> m b
f [Ident]
args m (JStat -> JStat) -> m JStat -> m JStat
forall a b. m (a -> b) -> m a -> m b
`app` JStat -> m JStat
forall b. JMacro b => b -> m b
f JStat
body
           BreakStat Maybe JLabel
l -> JStat -> m JStat
forall a. a -> m a
ret (Maybe JLabel -> JStat
BreakStat Maybe JLabel
l)
           LabelStat JLabel
l JStat
s -> (JStat -> JStat) -> m (JStat -> JStat)
forall a. a -> m a
ret (JLabel -> JStat -> JStat
LabelStat JLabel
l) m (JStat -> JStat) -> m JStat -> m JStat
forall a b. m (a -> b) -> m a -> m b
`app` JStat -> m JStat
forall b. JMacro b => b -> m b
f JStat
s
     JMGExpr JExpr
v' -> (JExpr -> JMGadt c) -> m (JExpr -> JMGadt c)
forall a. a -> m a
ret JExpr -> JMGadt c
JExpr -> JMGadt JExpr
JMGExpr m (JExpr -> JMGadt c) -> m JExpr -> m (JMGadt c)
forall a b. m (a -> b) -> m a -> m b
`app` case JExpr
v' of
           ValExpr JVal
e -> (JVal -> JExpr) -> m (JVal -> JExpr)
forall a. a -> m a
ret JVal -> JExpr
ValExpr m (JVal -> JExpr) -> m JVal -> m JExpr
forall a b. m (a -> b) -> m a -> m b
`app` JVal -> m JVal
forall b. JMacro b => b -> m b
f JVal
e
           SelExpr JExpr
e Ident
e' -> (JExpr -> Ident -> JExpr) -> m (JExpr -> Ident -> JExpr)
forall a. a -> m a
ret JExpr -> Ident -> JExpr
SelExpr m (JExpr -> Ident -> JExpr) -> m JExpr -> m (Ident -> JExpr)
forall a b. m (a -> b) -> m a -> m b
`app` JExpr -> m JExpr
forall b. JMacro b => b -> m b
f JExpr
e m (Ident -> JExpr) -> m Ident -> m JExpr
forall a b. m (a -> b) -> m a -> m b
`app` Ident -> m Ident
forall b. JMacro b => b -> m b
f Ident
e'
           IdxExpr JExpr
e JExpr
e' -> (JExpr -> JExpr -> JExpr) -> m (JExpr -> JExpr -> JExpr)
forall a. a -> m a
ret JExpr -> JExpr -> JExpr
IdxExpr m (JExpr -> JExpr -> JExpr) -> m JExpr -> m (JExpr -> JExpr)
forall a b. m (a -> b) -> m a -> m b
`app` JExpr -> m JExpr
forall b. JMacro b => b -> m b
f JExpr
e m (JExpr -> JExpr) -> m JExpr -> m JExpr
forall a b. m (a -> b) -> m a -> m b
`app` JExpr -> m JExpr
forall b. JMacro b => b -> m b
f JExpr
e'
           InfixExpr JOp
o JExpr
e JExpr
e' -> (JExpr -> JExpr -> JExpr) -> m (JExpr -> JExpr -> JExpr)
forall a. a -> m a
ret (JOp -> JExpr -> JExpr -> JExpr
InfixExpr JOp
o) m (JExpr -> JExpr -> JExpr) -> m JExpr -> m (JExpr -> JExpr)
forall a b. m (a -> b) -> m a -> m b
`app` JExpr -> m JExpr
forall b. JMacro b => b -> m b
f JExpr
e m (JExpr -> JExpr) -> m JExpr -> m JExpr
forall a b. m (a -> b) -> m a -> m b
`app` JExpr -> m JExpr
forall b. JMacro b => b -> m b
f JExpr
e'
           UOpExpr JUOp
o JExpr
e -> (JExpr -> JExpr) -> m (JExpr -> JExpr)
forall a. a -> m a
ret (JUOp -> JExpr -> JExpr
UOpExpr JUOp
o) m (JExpr -> JExpr) -> m JExpr -> m JExpr
forall a b. m (a -> b) -> m a -> m b
`app` JExpr -> m JExpr
forall b. JMacro b => b -> m b
f JExpr
e
           IfExpr JExpr
e JExpr
e' JExpr
e'' -> (JExpr -> JExpr -> JExpr -> JExpr)
-> m (JExpr -> JExpr -> JExpr -> JExpr)
forall a. a -> m a
ret JExpr -> JExpr -> JExpr -> JExpr
IfExpr m (JExpr -> JExpr -> JExpr -> JExpr)
-> m JExpr -> m (JExpr -> JExpr -> JExpr)
forall a b. m (a -> b) -> m a -> m b
`app` JExpr -> m JExpr
forall b. JMacro b => b -> m b
f JExpr
e m (JExpr -> JExpr -> JExpr) -> m JExpr -> m (JExpr -> JExpr)
forall a b. m (a -> b) -> m a -> m b
`app` JExpr -> m JExpr
forall b. JMacro b => b -> m b
f JExpr
e' m (JExpr -> JExpr) -> m JExpr -> m JExpr
forall a b. m (a -> b) -> m a -> m b
`app` JExpr -> m JExpr
forall b. JMacro b => b -> m b
f JExpr
e''
           ApplExpr JExpr
e [JExpr]
xs -> (JExpr -> [JExpr] -> JExpr) -> m (JExpr -> [JExpr] -> JExpr)
forall a. a -> m a
ret JExpr -> [JExpr] -> JExpr
ApplExpr m (JExpr -> [JExpr] -> JExpr) -> m JExpr -> m ([JExpr] -> JExpr)
forall a b. m (a -> b) -> m a -> m b
`app` JExpr -> m JExpr
forall b. JMacro b => b -> m b
f JExpr
e m ([JExpr] -> JExpr) -> m [JExpr] -> m JExpr
forall a b. m (a -> b) -> m a -> m b
`app` (JExpr -> m JExpr) -> [JExpr] -> m [JExpr]
forall a. (a -> m a) -> [a] -> m [a]
mapM' JExpr -> m JExpr
forall b. JMacro b => b -> m b
f [JExpr]
xs
           UnsatExpr IdentSupply JExpr
_ -> JExpr -> m JExpr
forall a. a -> m a
ret JExpr
v'
     JMGVal JVal
v' -> (JVal -> JMGadt c) -> m (JVal -> JMGadt c)
forall a. a -> m a
ret JVal -> JMGadt c
JVal -> JMGadt JVal
JMGVal m (JVal -> JMGadt c) -> m JVal -> m (JMGadt c)
forall a b. m (a -> b) -> m a -> m b
`app` case JVal
v' of
           JVar Ident
i -> (Ident -> JVal) -> m (Ident -> JVal)
forall a. a -> m a
ret Ident -> JVal
JVar m (Ident -> JVal) -> m Ident -> m JVal
forall a b. m (a -> b) -> m a -> m b
`app` Ident -> m Ident
forall b. JMacro b => b -> m b
f Ident
i
           JList [JExpr]
xs -> ([JExpr] -> JVal) -> m ([JExpr] -> JVal)
forall a. a -> m a
ret [JExpr] -> JVal
JList m ([JExpr] -> JVal) -> m [JExpr] -> m JVal
forall a b. m (a -> b) -> m a -> m b
`app` (JExpr -> m JExpr) -> [JExpr] -> m [JExpr]
forall a. (a -> m a) -> [a] -> m [a]
mapM' JExpr -> m JExpr
forall b. JMacro b => b -> m b
f [JExpr]
xs
           JDouble SaneDouble
_ -> JVal -> m JVal
forall a. a -> m a
ret JVal
v'
           JInt    Integer
_ -> JVal -> m JVal
forall a. a -> m a
ret JVal
v'
           JStr    FastString
_ -> JVal -> m JVal
forall a. a -> m a
ret JVal
v'
           JRegEx  FastString
_ -> JVal -> m JVal
forall a. a -> m a
ret JVal
v'
           JHash   UniqMap FastString JExpr
m -> (UniqMap FastString JExpr -> JVal)
-> m (UniqMap FastString JExpr -> JVal)
forall a. a -> m a
ret UniqMap FastString JExpr -> JVal
JHash m (UniqMap FastString JExpr -> JVal)
-> m (UniqMap FastString JExpr) -> m JVal
forall a b. m (a -> b) -> m a -> m b
`app` m (UniqMap FastString JExpr)
m'
               -- nonDetEltsUniqMap doesn't introduce nondeterminism here because the
               -- elements are treated independently before being re-added to a UniqMap
               where ([FastString]
ls, [JExpr]
vs) = [(FastString, JExpr)] -> ([FastString], [JExpr])
forall a b. [(a, b)] -> ([a], [b])
unzip (UniqMap FastString JExpr -> [(FastString, JExpr)]
forall k a. UniqMap k a -> [(k, a)]
nonDetUniqMapToList UniqMap FastString JExpr
m)
                     m' :: m (UniqMap FastString JExpr)
m' = ([JExpr] -> UniqMap FastString JExpr)
-> m ([JExpr] -> UniqMap FastString JExpr)
forall a. a -> m a
ret ([(FastString, JExpr)] -> UniqMap FastString JExpr
forall k a. Uniquable k => [(k, a)] -> UniqMap k a
listToUniqMap ([(FastString, JExpr)] -> UniqMap FastString JExpr)
-> ([JExpr] -> [(FastString, JExpr)])
-> [JExpr]
-> UniqMap FastString JExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [FastString] -> [JExpr] -> [(FastString, JExpr)]
forall a b. [a] -> [b] -> [(a, b)]
zip [FastString]
ls) m ([JExpr] -> UniqMap FastString JExpr)
-> m [JExpr] -> m (UniqMap FastString JExpr)
forall a b. m (a -> b) -> m a -> m b
`app` (JExpr -> m JExpr) -> [JExpr] -> m [JExpr]
forall a. (a -> m a) -> [a] -> m [a]
mapM' JExpr -> m JExpr
forall b. JMacro b => b -> m b
f [JExpr]
vs
           JFunc [Ident]
xs JStat
s -> ([Ident] -> JStat -> JVal) -> m ([Ident] -> JStat -> JVal)
forall a. a -> m a
ret [Ident] -> JStat -> JVal
JFunc m ([Ident] -> JStat -> JVal) -> m [Ident] -> m (JStat -> JVal)
forall a b. m (a -> b) -> m a -> m b
`app` (Ident -> m Ident) -> [Ident] -> m [Ident]
forall a. (a -> m a) -> [a] -> m [a]
mapM' Ident -> m Ident
forall b. JMacro b => b -> m b
f [Ident]
xs m (JStat -> JVal) -> m JStat -> m JVal
forall a b. m (a -> b) -> m a -> m b
`app` JStat -> m JStat
forall b. JMacro b => b -> m b
f JStat
s
           UnsatVal IdentSupply JVal
_ -> JVal -> m JVal
forall a. a -> m a
ret JVal
v'

  where
    mapM' :: forall a. (a -> m a) -> [a] -> m [a]
    mapM' :: forall a. (a -> m a) -> [a] -> m [a]
mapM' a -> m a
g = (a -> m [a] -> m [a]) -> m [a] -> [a] -> m [a]
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (m ([a] -> [a]) -> m [a] -> m [a]
forall a b. m (a -> b) -> m a -> m b
app (m ([a] -> [a]) -> m [a] -> m [a])
-> (a -> m ([a] -> [a])) -> a -> m [a] -> m [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (a -> [a] -> [a]) -> m a -> m ([a] -> [a])
forall a b. m (a -> b) -> m a -> m b
app ((a -> [a] -> [a]) -> m (a -> [a] -> [a])
forall a. a -> m a
ret (:)) (m a -> m ([a] -> [a])) -> (a -> m a) -> a -> m ([a] -> [a])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> m a
g) ([a] -> m [a]
forall a. a -> m a
ret [])
    mapMaybeM' :: forall a. (a -> m a) -> Maybe a -> m (Maybe a)
    mapMaybeM' :: forall a. (a -> m a) -> Maybe a -> m (Maybe a)
mapMaybeM' a -> m a
g = \case
      Maybe a
Nothing -> Maybe a -> m (Maybe a)
forall a. a -> m a
ret Maybe a
forall a. Maybe a
Nothing
      Just a
a  -> m (a -> Maybe a) -> m a -> m (Maybe a)
forall a b. m (a -> b) -> m a -> m b
app ((a -> Maybe a) -> m (a -> Maybe a)
forall a. a -> m a
ret a -> Maybe a
forall a. a -> Maybe a
Just) (a -> m a
g a
a)
    f :: forall b. JMacro b => b -> m b
    f :: forall b. JMacro b => b -> m b
f b
x = (JMGadt b -> b) -> m (JMGadt b -> b)
forall a. a -> m a
ret JMGadt b -> b
forall a. JMacro a => JMGadt a -> a
jfromGADT m (JMGadt b -> b) -> m (JMGadt b) -> m b
forall a b. m (a -> b) -> m a -> m b
`app` JMGadt b -> m (JMGadt b)
forall a. JMGadt a -> m (JMGadt a)
f' (b -> JMGadt b
forall a. JMacro a => a -> JMGadt a
jtoGADT b
x)

{--------------------------------------------------------------------
  Saturation
--------------------------------------------------------------------}

-- | Given an optional prefix, fills in all free variable names with a supply
-- of names generated by the prefix.
satJStat :: Maybe FastString -> JStat -> Sat.JStat
satJStat :: Maybe FastString -> JStat -> JStat
satJStat Maybe FastString
str JStat
x = State [Ident] JStat -> [Ident] -> JStat
forall s a. State s a -> s -> a
evalState (JStat -> State [Ident] JStat
jsSaturateS JStat
x) (Maybe FastString -> [Ident]
newIdentSupply Maybe FastString
str)

satJExpr :: Maybe FastString -> JExpr -> Sat.JExpr
satJExpr :: Maybe FastString -> JExpr -> JExpr
satJExpr Maybe FastString
str JExpr
x = State [Ident] JExpr -> [Ident] -> JExpr
forall s a. State s a -> s -> a
evalState (JExpr -> State [Ident] JExpr
jsSaturateE JExpr
x) (Maybe FastString -> [Ident]
newIdentSupply Maybe FastString
str)

jsSaturateS :: JStat -> State [Ident] Sat.JStat
jsSaturateS :: JStat -> State [Ident] JStat
jsSaturateS  = \case
  DeclStat Ident
i Maybe JExpr
rhs        -> Ident -> Maybe JExpr -> JStat
Sat.DeclStat Ident
i (Maybe JExpr -> JStat)
-> State [Ident] (Maybe JExpr) -> State [Ident] JStat
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (JExpr -> State [Ident] JExpr)
-> Maybe JExpr -> State [Ident] (Maybe JExpr)
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Maybe a -> m (Maybe b)
mapM JExpr -> State [Ident] JExpr
jsSaturateE Maybe JExpr
rhs
  ReturnStat JExpr
e          -> JExpr -> JStat
Sat.ReturnStat (JExpr -> JStat) -> State [Ident] JExpr -> State [Ident] JStat
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JExpr -> State [Ident] JExpr
jsSaturateE JExpr
e
  IfStat JExpr
c JStat
t JStat
e          -> JExpr -> JStat -> JStat -> JStat
Sat.IfStat (JExpr -> JStat -> JStat -> JStat)
-> State [Ident] JExpr -> State [Ident] (JStat -> JStat -> JStat)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JExpr -> State [Ident] JExpr
jsSaturateE JExpr
c State [Ident] (JStat -> JStat -> JStat)
-> State [Ident] JStat -> State [Ident] (JStat -> JStat)
forall a b.
State [Ident] (a -> b) -> State [Ident] a -> State [Ident] b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JStat -> State [Ident] JStat
jsSaturateS JStat
t State [Ident] (JStat -> JStat)
-> State [Ident] JStat -> State [Ident] JStat
forall a b.
State [Ident] (a -> b) -> State [Ident] a -> State [Ident] b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JStat -> State [Ident] JStat
jsSaturateS JStat
e
  WhileStat Bool
is_do JExpr
c JStat
e   -> Bool -> JExpr -> JStat -> JStat
Sat.WhileStat Bool
is_do (JExpr -> JStat -> JStat)
-> State [Ident] JExpr -> State [Ident] (JStat -> JStat)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JExpr -> State [Ident] JExpr
jsSaturateE JExpr
c State [Ident] (JStat -> JStat)
-> State [Ident] JStat -> State [Ident] JStat
forall a b.
State [Ident] (a -> b) -> State [Ident] a -> State [Ident] b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JStat -> State [Ident] JStat
jsSaturateS JStat
e
  ForStat JStat
init JExpr
p JStat
step JStat
body -> JStat -> JExpr -> JStat -> JStat -> JStat
Sat.ForStat (JStat -> JExpr -> JStat -> JStat -> JStat)
-> State [Ident] JStat
-> State [Ident] (JExpr -> JStat -> JStat -> JStat)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JStat -> State [Ident] JStat
jsSaturateS JStat
init State [Ident] (JExpr -> JStat -> JStat -> JStat)
-> State [Ident] JExpr -> State [Ident] (JStat -> JStat -> JStat)
forall a b.
State [Ident] (a -> b) -> State [Ident] a -> State [Ident] b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JExpr -> State [Ident] JExpr
jsSaturateE JExpr
p
                                          State [Ident] (JStat -> JStat -> JStat)
-> State [Ident] JStat -> State [Ident] (JStat -> JStat)
forall a b.
State [Ident] (a -> b) -> State [Ident] a -> State [Ident] b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JStat -> State [Ident] JStat
jsSaturateS JStat
step State [Ident] (JStat -> JStat)
-> State [Ident] JStat -> State [Ident] JStat
forall a b.
State [Ident] (a -> b) -> State [Ident] a -> State [Ident] b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JStat -> State [Ident] JStat
jsSaturateS JStat
body
  ForInStat Bool
is_each Ident
i JExpr
iter JStat
body -> Bool -> Ident -> JExpr -> JStat -> JStat
Sat.ForInStat Bool
is_each Ident
i (JExpr -> JStat -> JStat)
-> State [Ident] JExpr -> State [Ident] (JStat -> JStat)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JExpr -> State [Ident] JExpr
jsSaturateE JExpr
iter State [Ident] (JStat -> JStat)
-> State [Ident] JStat -> State [Ident] JStat
forall a b.
State [Ident] (a -> b) -> State [Ident] a -> State [Ident] b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JStat -> State [Ident] JStat
jsSaturateS JStat
body
  SwitchStat JExpr
struct [(JExpr, JStat)]
ps JStat
def -> JExpr -> [(JExpr, JStat)] -> JStat -> JStat
Sat.SwitchStat (JExpr -> [(JExpr, JStat)] -> JStat -> JStat)
-> State [Ident] JExpr
-> State [Ident] ([(JExpr, JStat)] -> JStat -> JStat)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JExpr -> State [Ident] JExpr
jsSaturateE JExpr
struct
                                             State [Ident] ([(JExpr, JStat)] -> JStat -> JStat)
-> State [Ident] [(JExpr, JStat)] -> State [Ident] (JStat -> JStat)
forall a b.
State [Ident] (a -> b) -> State [Ident] a -> State [Ident] b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((JExpr, JStat) -> State [Ident] (JExpr, JStat))
-> [(JExpr, JStat)] -> State [Ident] [(JExpr, JStat)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (\(JExpr
p1, JStat
p2) -> (,) (JExpr -> JStat -> (JExpr, JStat))
-> State [Ident] JExpr -> State [Ident] (JStat -> (JExpr, JStat))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JExpr -> State [Ident] JExpr
jsSaturateE JExpr
p1 State [Ident] (JStat -> (JExpr, JStat))
-> State [Ident] JStat -> State [Ident] (JExpr, JStat)
forall a b.
State [Ident] (a -> b) -> State [Ident] a -> State [Ident] b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JStat -> State [Ident] JStat
jsSaturateS JStat
p2) [(JExpr, JStat)]
ps
                                             State [Ident] (JStat -> JStat)
-> State [Ident] JStat -> State [Ident] JStat
forall a b.
State [Ident] (a -> b) -> State [Ident] a -> State [Ident] b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JStat -> State [Ident] JStat
jsSaturateS JStat
def
  TryStat JStat
t Ident
i JStat
c JStat
f       -> JStat -> Ident -> JStat -> JStat -> JStat
Sat.TryStat (JStat -> Ident -> JStat -> JStat -> JStat)
-> State [Ident] JStat
-> State [Ident] (Ident -> JStat -> JStat -> JStat)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JStat -> State [Ident] JStat
jsSaturateS JStat
t State [Ident] (Ident -> JStat -> JStat -> JStat)
-> State [Ident] Ident -> State [Ident] (JStat -> JStat -> JStat)
forall a b.
State [Ident] (a -> b) -> State [Ident] a -> State [Ident] b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ident -> State [Ident] Ident
forall a. a -> State [Ident] a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Ident
i State [Ident] (JStat -> JStat -> JStat)
-> State [Ident] JStat -> State [Ident] (JStat -> JStat)
forall a b.
State [Ident] (a -> b) -> State [Ident] a -> State [Ident] b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JStat -> State [Ident] JStat
jsSaturateS JStat
c State [Ident] (JStat -> JStat)
-> State [Ident] JStat -> State [Ident] JStat
forall a b.
State [Ident] (a -> b) -> State [Ident] a -> State [Ident] b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JStat -> State [Ident] JStat
jsSaturateS JStat
f
  BlockStat [JStat]
bs          -> ([JStat] -> JStat) -> State [Ident] [JStat] -> State [Ident] JStat
forall a b. (a -> b) -> State [Ident] a -> State [Ident] b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [JStat] -> JStat
Sat.BlockStat (State [Ident] [JStat] -> State [Ident] JStat)
-> State [Ident] [JStat] -> State [Ident] JStat
forall a b. (a -> b) -> a -> b
$! (JStat -> State [Ident] JStat) -> [JStat] -> State [Ident] [JStat]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM JStat -> State [Ident] JStat
jsSaturateS [JStat]
bs
  ApplStat JExpr
rator [JExpr]
rand   -> JExpr -> [JExpr] -> JStat
Sat.ApplStat (JExpr -> [JExpr] -> JStat)
-> State [Ident] JExpr -> State [Ident] ([JExpr] -> JStat)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JExpr -> State [Ident] JExpr
jsSaturateE JExpr
rator State [Ident] ([JExpr] -> JStat)
-> State [Ident] [JExpr] -> State [Ident] JStat
forall a b.
State [Ident] (a -> b) -> State [Ident] a -> State [Ident] b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (JExpr -> State [Ident] JExpr) -> [JExpr] -> State [Ident] [JExpr]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM JExpr -> State [Ident] JExpr
jsSaturateE [JExpr]
rand
  UOpStat  JUOp
rator JExpr
rand   -> UOp -> JExpr -> JStat
Sat.UOpStat (JUOp -> UOp
satJUOp JUOp
rator) (JExpr -> JStat) -> State [Ident] JExpr -> State [Ident] JStat
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JExpr -> State [Ident] JExpr
jsSaturateE JExpr
rand
  AssignStat JExpr
lhs JExpr
rhs    -> JExpr -> AOp -> JExpr -> JStat
Sat.AssignStat (JExpr -> AOp -> JExpr -> JStat)
-> State [Ident] JExpr -> State [Ident] (AOp -> JExpr -> JStat)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JExpr -> State [Ident] JExpr
jsSaturateE JExpr
lhs State [Ident] (AOp -> JExpr -> JStat)
-> State [Ident] AOp -> State [Ident] (JExpr -> JStat)
forall a b.
State [Ident] (a -> b) -> State [Ident] a -> State [Ident] b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> AOp -> State [Ident] AOp
forall a. a -> State [Ident] a
forall (f :: * -> *) a. Applicative f => a -> f a
pure AOp
Sat.AssignOp State [Ident] (JExpr -> JStat)
-> State [Ident] JExpr -> State [Ident] JStat
forall a b.
State [Ident] (a -> b) -> State [Ident] a -> State [Ident] b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JExpr -> State [Ident] JExpr
jsSaturateE JExpr
rhs
  LabelStat JLabel
lbl JStat
stmt    -> JLabel -> JStat -> JStat
Sat.LabelStat JLabel
lbl (JStat -> JStat) -> State [Ident] JStat -> State [Ident] JStat
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JStat -> State [Ident] JStat
jsSaturateS JStat
stmt
  BreakStat Maybe JLabel
m_l         -> JStat -> State [Ident] JStat
forall a. a -> State [Ident] a
forall (m :: * -> *) a. Monad m => a -> m a
return (JStat -> State [Ident] JStat) -> JStat -> State [Ident] JStat
forall a b. (a -> b) -> a -> b
$ Maybe JLabel -> JStat
Sat.BreakStat (Maybe JLabel -> JStat) -> Maybe JLabel -> JStat
forall a b. (a -> b) -> a -> b
$! Maybe JLabel
m_l
  ContinueStat Maybe JLabel
m_l      -> JStat -> State [Ident] JStat
forall a. a -> State [Ident] a
forall (m :: * -> *) a. Monad m => a -> m a
return (JStat -> State [Ident] JStat) -> JStat -> State [Ident] JStat
forall a b. (a -> b) -> a -> b
$ Maybe JLabel -> JStat
Sat.ContinueStat (Maybe JLabel -> JStat) -> Maybe JLabel -> JStat
forall a b. (a -> b) -> a -> b
$! Maybe JLabel
m_l
  FuncStat Ident
i [Ident]
args JStat
body  -> Ident -> [Ident] -> JStat -> JStat
Sat.FuncStat Ident
i [Ident]
args (JStat -> JStat) -> State [Ident] JStat -> State [Ident] JStat
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JStat -> State [Ident] JStat
jsSaturateS JStat
body
  UnsatBlock IdentSupply JStat
us         -> JStat -> State [Ident] JStat
jsSaturateS (JStat -> State [Ident] JStat)
-> State [Ident] JStat -> State [Ident] JStat
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< IdentSupply JStat -> State [Ident] JStat
forall a. IdentSupply a -> State [Ident] a
runIdentSupply IdentSupply JStat
us

jsSaturateE :: JExpr -> State [Ident] Sat.JExpr
jsSaturateE :: JExpr -> State [Ident] JExpr
jsSaturateE = \case
  ValExpr JVal
v            -> JVal -> JExpr
Sat.ValExpr (JVal -> JExpr) -> State [Ident] JVal -> State [Ident] JExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JVal -> State [Ident] JVal
jsSaturateV JVal
v
  SelExpr JExpr
obj Ident
i        -> JExpr -> Ident -> JExpr
Sat.SelExpr (JExpr -> Ident -> JExpr)
-> State [Ident] JExpr -> State [Ident] (Ident -> JExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JExpr -> State [Ident] JExpr
jsSaturateE JExpr
obj State [Ident] (Ident -> JExpr)
-> State [Ident] Ident -> State [Ident] JExpr
forall a b.
State [Ident] (a -> b) -> State [Ident] a -> State [Ident] b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ident -> State [Ident] Ident
forall a. a -> State [Ident] a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Ident
i
  IdxExpr JExpr
o JExpr
i          -> JExpr -> JExpr -> JExpr
Sat.IdxExpr (JExpr -> JExpr -> JExpr)
-> State [Ident] JExpr -> State [Ident] (JExpr -> JExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JExpr -> State [Ident] JExpr
jsSaturateE JExpr
o State [Ident] (JExpr -> JExpr)
-> State [Ident] JExpr -> State [Ident] JExpr
forall a b.
State [Ident] (a -> b) -> State [Ident] a -> State [Ident] b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JExpr -> State [Ident] JExpr
jsSaturateE JExpr
i
  InfixExpr JOp
op JExpr
l JExpr
r     -> Op -> JExpr -> JExpr -> JExpr
Sat.InfixExpr (JOp -> Op
satJOp JOp
op) (JExpr -> JExpr -> JExpr)
-> State [Ident] JExpr -> State [Ident] (JExpr -> JExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JExpr -> State [Ident] JExpr
jsSaturateE JExpr
l State [Ident] (JExpr -> JExpr)
-> State [Ident] JExpr -> State [Ident] JExpr
forall a b.
State [Ident] (a -> b) -> State [Ident] a -> State [Ident] b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JExpr -> State [Ident] JExpr
jsSaturateE JExpr
r
  UOpExpr JUOp
op JExpr
r         -> UOp -> JExpr -> JExpr
Sat.UOpExpr (JUOp -> UOp
satJUOp JUOp
op) (JExpr -> JExpr) -> State [Ident] JExpr -> State [Ident] JExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JExpr -> State [Ident] JExpr
jsSaturateE JExpr
r
  IfExpr JExpr
c JExpr
t JExpr
e         -> JExpr -> JExpr -> JExpr -> JExpr
Sat.IfExpr (JExpr -> JExpr -> JExpr -> JExpr)
-> State [Ident] JExpr -> State [Ident] (JExpr -> JExpr -> JExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JExpr -> State [Ident] JExpr
jsSaturateE JExpr
c State [Ident] (JExpr -> JExpr -> JExpr)
-> State [Ident] JExpr -> State [Ident] (JExpr -> JExpr)
forall a b.
State [Ident] (a -> b) -> State [Ident] a -> State [Ident] b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JExpr -> State [Ident] JExpr
jsSaturateE JExpr
t State [Ident] (JExpr -> JExpr)
-> State [Ident] JExpr -> State [Ident] JExpr
forall a b.
State [Ident] (a -> b) -> State [Ident] a -> State [Ident] b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> JExpr -> State [Ident] JExpr
jsSaturateE JExpr
e
  ApplExpr JExpr
rator [JExpr]
rands -> JExpr -> [JExpr] -> JExpr
Sat.ApplExpr (JExpr -> [JExpr] -> JExpr)
-> State [Ident] JExpr -> State [Ident] ([JExpr] -> JExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JExpr -> State [Ident] JExpr
jsSaturateE JExpr
rator State [Ident] ([JExpr] -> JExpr)
-> State [Ident] [JExpr] -> State [Ident] JExpr
forall a b.
State [Ident] (a -> b) -> State [Ident] a -> State [Ident] b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (JExpr -> State [Ident] JExpr) -> [JExpr] -> State [Ident] [JExpr]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM JExpr -> State [Ident] JExpr
jsSaturateE [JExpr]
rands
  UnsatExpr IdentSupply JExpr
us         -> JExpr -> State [Ident] JExpr
jsSaturateE (JExpr -> State [Ident] JExpr)
-> State [Ident] JExpr -> State [Ident] JExpr
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< IdentSupply JExpr -> State [Ident] JExpr
forall a. IdentSupply a -> State [Ident] a
runIdentSupply IdentSupply JExpr
us

jsSaturateV :: JVal -> State [Ident] Sat.JVal
jsSaturateV :: JVal -> State [Ident] JVal
jsSaturateV = \case
  JVar Ident
i   -> JVal -> State [Ident] JVal
forall a. a -> State [Ident] a
forall (m :: * -> *) a. Monad m => a -> m a
return (JVal -> State [Ident] JVal) -> JVal -> State [Ident] JVal
forall a b. (a -> b) -> a -> b
$ Ident -> JVal
Sat.JVar Ident
i
  JList [JExpr]
xs -> [JExpr] -> JVal
Sat.JList ([JExpr] -> JVal) -> State [Ident] [JExpr] -> State [Ident] JVal
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (JExpr -> State [Ident] JExpr) -> [JExpr] -> State [Ident] [JExpr]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM JExpr -> State [Ident] JExpr
jsSaturateE [JExpr]
xs
  JDouble SaneDouble
d -> JVal -> State [Ident] JVal
forall a. a -> State [Ident] a
forall (m :: * -> *) a. Monad m => a -> m a
return (JVal -> State [Ident] JVal) -> JVal -> State [Ident] JVal
forall a b. (a -> b) -> a -> b
$ SaneDouble -> JVal
Sat.JDouble (Double -> SaneDouble
Sat.SaneDouble (SaneDouble -> Double
unSaneDouble SaneDouble
d))
  JInt Integer
i    -> JVal -> State [Ident] JVal
forall a. a -> State [Ident] a
forall (m :: * -> *) a. Monad m => a -> m a
return (JVal -> State [Ident] JVal) -> JVal -> State [Ident] JVal
forall a b. (a -> b) -> a -> b
$ Integer -> JVal
Sat.JInt   Integer
i
  JStr FastString
s    -> JVal -> State [Ident] JVal
forall a. a -> State [Ident] a
forall (m :: * -> *) a. Monad m => a -> m a
return (JVal -> State [Ident] JVal) -> JVal -> State [Ident] JVal
forall a b. (a -> b) -> a -> b
$ FastString -> JVal
Sat.JStr   FastString
s
  JRegEx FastString
f  -> JVal -> State [Ident] JVal
forall a. a -> State [Ident] a
forall (m :: * -> *) a. Monad m => a -> m a
return (JVal -> State [Ident] JVal) -> JVal -> State [Ident] JVal
forall a b. (a -> b) -> a -> b
$ FastString -> JVal
Sat.JRegEx FastString
f
  JHash UniqMap FastString JExpr
m   -> UniqMap FastString JExpr -> JVal
Sat.JHash (UniqMap FastString JExpr -> JVal)
-> State [Ident] (UniqMap FastString JExpr) -> State [Ident] JVal
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((FastString, JExpr)
 -> State [Ident] (FastString, (FastString, JExpr)))
-> UniqMap FastString JExpr
-> State [Ident] (UniqMap FastString JExpr)
forall {f :: * -> *} {k} {b} {a}.
(Uniquable k, Monad f) =>
((FastString, b) -> f (k, (k, a)))
-> UniqMap FastString b -> f (UniqMap k a)
mapUniqMapM (FastString, JExpr)
-> State [Ident] (FastString, (FastString, JExpr))
forall {t}. (t, JExpr) -> State [Ident] (t, (t, JExpr))
satHash UniqMap FastString JExpr
m
    where
      satHash :: (t, JExpr) -> State [Ident] (t, (t, JExpr))
satHash (t
i, JExpr
x) = (t
i,) ((t, JExpr) -> (t, (t, JExpr)))
-> (JExpr -> (t, JExpr)) -> JExpr -> (t, (t, JExpr))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (t
i,) (JExpr -> (t, (t, JExpr)))
-> State [Ident] JExpr -> State [Ident] (t, (t, JExpr))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JExpr -> State [Ident] JExpr
jsSaturateE JExpr
x
      compareHash :: (FastString, b) -> (FastString, b) -> Ordering
compareHash (FastString
i,b
_) (FastString
j,b
_) = FastString -> FastString -> Ordering
lexicalCompareFS FastString
i FastString
j
      -- By lexically sorting the elements, the non-determinism introduced by nonDetEltsUFM is avoided
      mapUniqMapM :: ((FastString, b) -> f (k, (k, a)))
-> UniqMap FastString b -> f (UniqMap k a)
mapUniqMapM (FastString, b) -> f (k, (k, a))
f (UniqMap UniqFM FastString (FastString, b)
m) = UniqFM k (k, a) -> UniqMap k a
forall k a. UniqFM k (k, a) -> UniqMap k a
UniqMap (UniqFM k (k, a) -> UniqMap k a)
-> ([(k, (k, a))] -> UniqFM k (k, a))
-> [(k, (k, a))]
-> UniqMap k a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(k, (k, a))] -> UniqFM k (k, a)
forall key elt. Uniquable key => [(key, elt)] -> UniqFM key elt
listToUFM ([(k, (k, a))] -> UniqMap k a)
-> f [(k, (k, a))] -> f (UniqMap k a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (((FastString, b) -> f (k, (k, a)))
-> [(FastString, b)] -> f [(k, (k, a))]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (FastString, b) -> f (k, (k, a))
f ([(FastString, b)] -> f [(k, (k, a))])
-> ([(FastString, b)] -> [(FastString, b)])
-> [(FastString, b)]
-> f [(k, (k, a))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((FastString, b) -> (FastString, b) -> Ordering)
-> [(FastString, b)] -> [(FastString, b)]
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy (FastString, b) -> (FastString, b) -> Ordering
forall {b} {b}. (FastString, b) -> (FastString, b) -> Ordering
compareHash ([(FastString, b)] -> f [(k, (k, a))])
-> [(FastString, b)] -> f [(k, (k, a))]
forall a b. (a -> b) -> a -> b
$ UniqFM FastString (FastString, b) -> [(FastString, b)]
forall key elt. UniqFM key elt -> [elt]
nonDetEltsUFM UniqFM FastString (FastString, b)
m)
  JFunc [Ident]
args JStat
body   -> [Ident] -> JStat -> JVal
Sat.JFunc [Ident]
args (JStat -> JVal) -> State [Ident] JStat -> State [Ident] JVal
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> JStat -> State [Ident] JStat
jsSaturateS JStat
body
  UnsatVal IdentSupply JVal
us       -> JVal -> State [Ident] JVal
jsSaturateV (JVal -> State [Ident] JVal)
-> State [Ident] JVal -> State [Ident] JVal
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< IdentSupply JVal -> State [Ident] JVal
forall a. IdentSupply a -> State [Ident] a
runIdentSupply IdentSupply JVal
us

satJOp :: JOp -> Sat.Op
satJOp :: JOp -> Op
satJOp = JOp -> Op
go
  where
    go :: JOp -> Op
go JOp
EqOp         = Op
Sat.EqOp
    go JOp
StrictEqOp   = Op
Sat.StrictEqOp
    go JOp
NeqOp        = Op
Sat.NeqOp
    go JOp
StrictNeqOp  = Op
Sat.StrictNeqOp
    go JOp
GtOp         = Op
Sat.GtOp
    go JOp
GeOp         = Op
Sat.GeOp
    go JOp
LtOp         = Op
Sat.LtOp
    go JOp
LeOp         = Op
Sat.LeOp
    go JOp
AddOp        = Op
Sat.AddOp
    go JOp
SubOp        = Op
Sat.SubOp
    go JOp
MulOp        = Op
Sat.MulOp
    go JOp
DivOp        = Op
Sat.DivOp
    go JOp
ModOp        = Op
Sat.ModOp
    go JOp
LeftShiftOp  = Op
Sat.LeftShiftOp
    go JOp
RightShiftOp = Op
Sat.RightShiftOp
    go JOp
ZRightShiftOp = Op
Sat.ZRightShiftOp
    go JOp
BAndOp       = Op
Sat.BAndOp
    go JOp
BOrOp        = Op
Sat.BOrOp
    go JOp
BXorOp       = Op
Sat.BXorOp
    go JOp
LAndOp       = Op
Sat.LAndOp
    go JOp
LOrOp        = Op
Sat.LOrOp
    go JOp
InstanceofOp = Op
Sat.InstanceofOp
    go JOp
InOp         = Op
Sat.InOp

satJUOp :: JUOp -> Sat.UOp
satJUOp :: JUOp -> UOp
satJUOp = JUOp -> UOp
go
  where
    go :: JUOp -> UOp
go JUOp
NotOp     = UOp
Sat.NotOp
    go JUOp
BNotOp    = UOp
Sat.BNotOp
    go JUOp
NegOp     = UOp
Sat.NegOp
    go JUOp
PlusOp    = UOp
Sat.PlusOp
    go JUOp
NewOp     = UOp
Sat.NewOp
    go JUOp
TypeofOp  = UOp
Sat.TypeofOp
    go JUOp
DeleteOp  = UOp
Sat.DeleteOp
    go JUOp
YieldOp   = UOp
Sat.YieldOp
    go JUOp
VoidOp    = UOp
Sat.VoidOp
    go JUOp
PreIncOp  = UOp
Sat.PreIncOp
    go JUOp
PostIncOp = UOp
Sat.PostIncOp
    go JUOp
PreDecOp  = UOp
Sat.PreDecOp
    go JUOp
PostDecOp = UOp
Sat.PostDecOp