{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE GADTs #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module GHC.JS.Make
(
ToJExpr(..)
, ToStat(..)
, var
, jString
, jLam, jFun, jFunction, jVar, jFor, jForNoDecl, jForIn, jForEachIn, jTryCatchFinally
, (||=), (|=), (.==.), (.===.), (.!=.), (.!==.), (.!)
, (.>.), (.>=.), (.<.), (.<=.)
, (.<<.), (.>>.), (.>>>.)
, (.|.), (.||.), (.&&.)
, if_, if10, if01, ifS, ifBlockS
, jwhenS
, app, appS, returnS
, loop, loopBlockS
, preIncrS, postIncrS
, preDecrS, postDecrS
, off8, off16, off32, off64
, mask8, mask16
, signExtend8, signExtend16
, typeof
, returnStack, assignAllEqual, assignAll, assignAllReverseOrder
, declAssignAll
, nullStat, (.^)
, trace
, jhEmpty
, jhSingle
, jhAdd
, jhFromList
, null_
, undefined_
, false_
, true_
, zero_
, one_
, two_
, three_
, math_log, math_sin, math_cos, math_tan, math_exp, math_acos, math_asin,
math_atan, math_abs, math_pow, math_sqrt, math_asinh, math_acosh, math_atanh,
math_cosh, math_sinh, math_tanh, math_expm1, math_log1p, math_fround
, decl
)
where
import GHC.Prelude hiding ((.|.))
import GHC.JS.Unsat.Syntax
import Control.Arrow ((***))
import qualified Data.Map as M
import GHC.Data.FastString
import GHC.Utils.Monad.State.Strict
import GHC.Utils.Misc
import GHC.Types.Unique.Map
class ToJExpr a where
toJExpr :: a -> JExpr
toJExprFromList :: [a] -> JExpr
toJExprFromList = JVal -> JExpr
ValExpr (JVal -> JExpr) -> ([a] -> JVal) -> [a] -> JExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [JExpr] -> JVal
JList ([JExpr] -> JVal) -> ([a] -> [JExpr]) -> [a] -> JVal
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> JExpr) -> [a] -> [JExpr]
forall a b. (a -> b) -> [a] -> [b]
map a -> JExpr
forall a. ToJExpr a => a -> JExpr
toJExpr
instance ToJExpr a => ToJExpr [a] where
toJExpr :: [a] -> JExpr
toJExpr = [a] -> JExpr
forall a. ToJExpr a => [a] -> JExpr
toJExprFromList
instance ToJExpr JExpr where
toJExpr :: JExpr -> JExpr
toJExpr = JExpr -> JExpr
forall a. a -> a
id
instance ToJExpr () where
toJExpr :: () -> JExpr
toJExpr ()
_ = JVal -> JExpr
ValExpr (JVal -> JExpr) -> JVal -> JExpr
forall a b. (a -> b) -> a -> b
$ [JExpr] -> JVal
JList []
instance ToJExpr Bool where
toJExpr :: Bool -> JExpr
toJExpr Bool
True = FastString -> JExpr
var FastString
"true"
toJExpr Bool
False = FastString -> JExpr
var FastString
"false"
instance ToJExpr JVal where
toJExpr :: JVal -> JExpr
toJExpr = JVal -> JExpr
ValExpr
instance ToJExpr a => ToJExpr (UniqMap FastString a) where
toJExpr :: UniqMap FastString a -> JExpr
toJExpr = JVal -> JExpr
ValExpr (JVal -> JExpr)
-> (UniqMap FastString a -> JVal) -> UniqMap FastString a -> JExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UniqMap FastString JExpr -> JVal
JHash (UniqMap FastString JExpr -> JVal)
-> (UniqMap FastString a -> UniqMap FastString JExpr)
-> UniqMap FastString a
-> JVal
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> JExpr) -> UniqMap FastString a -> UniqMap FastString JExpr
forall a b k. (a -> b) -> UniqMap k a -> UniqMap k b
mapUniqMap a -> JExpr
forall a. ToJExpr a => a -> JExpr
toJExpr
instance ToJExpr a => ToJExpr (M.Map String a) where
toJExpr :: Map String a -> JExpr
toJExpr = JVal -> JExpr
ValExpr (JVal -> JExpr) -> (Map String a -> JVal) -> Map String a -> JExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UniqMap FastString JExpr -> JVal
JHash (UniqMap FastString JExpr -> JVal)
-> (Map String a -> UniqMap FastString JExpr)
-> Map String a
-> JVal
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(FastString, JExpr)] -> UniqMap FastString JExpr
forall k a. Uniquable k => [(k, a)] -> UniqMap k a
listToUniqMap ([(FastString, JExpr)] -> UniqMap FastString JExpr)
-> (Map String a -> [(FastString, JExpr)])
-> Map String a
-> UniqMap FastString JExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((String, a) -> (FastString, JExpr))
-> [(String, a)] -> [(FastString, JExpr)]
forall a b. (a -> b) -> [a] -> [b]
map (String -> FastString
mkFastString (String -> FastString)
-> (a -> JExpr) -> (String, a) -> (FastString, JExpr)
forall b c b' c'. (b -> c) -> (b' -> c') -> (b, b') -> (c, c')
forall (a :: * -> * -> *) b c b' c'.
Arrow a =>
a b c -> a b' c' -> a (b, b') (c, c')
*** a -> JExpr
forall a. ToJExpr a => a -> JExpr
toJExpr) ([(String, a)] -> [(FastString, JExpr)])
-> (Map String a -> [(String, a)])
-> Map String a
-> [(FastString, JExpr)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map String a -> [(String, a)]
forall k a. Map k a -> [(k, a)]
M.toList
instance ToJExpr Double where
toJExpr :: Double -> JExpr
toJExpr = JVal -> JExpr
ValExpr (JVal -> JExpr) -> (Double -> JVal) -> Double -> JExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SaneDouble -> JVal
JDouble (SaneDouble -> JVal) -> (Double -> SaneDouble) -> Double -> JVal
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> SaneDouble
SaneDouble
instance ToJExpr Int where
toJExpr :: Int -> JExpr
toJExpr = JVal -> JExpr
ValExpr (JVal -> JExpr) -> (Int -> JVal) -> Int -> JExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> JVal
JInt (Integer -> JVal) -> (Int -> Integer) -> Int -> JVal
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral
instance ToJExpr Integer where
toJExpr :: Integer -> JExpr
toJExpr = JVal -> JExpr
ValExpr (JVal -> JExpr) -> (Integer -> JVal) -> Integer -> JExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> JVal
JInt
instance ToJExpr Char where
toJExpr :: Char -> JExpr
toJExpr = JVal -> JExpr
ValExpr (JVal -> JExpr) -> (Char -> JVal) -> Char -> JExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FastString -> JVal
JStr (FastString -> JVal) -> (Char -> FastString) -> Char -> JVal
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> FastString
mkFastString (String -> FastString) -> (Char -> String) -> Char -> FastString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> String -> String
forall a. a -> [a] -> [a]
:[])
toJExprFromList :: String -> JExpr
toJExprFromList = JVal -> JExpr
ValExpr (JVal -> JExpr) -> (String -> JVal) -> String -> JExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FastString -> JVal
JStr (FastString -> JVal) -> (String -> FastString) -> String -> JVal
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> FastString
mkFastString
instance ToJExpr Ident where
toJExpr :: Ident -> JExpr
toJExpr = JVal -> JExpr
ValExpr (JVal -> JExpr) -> (Ident -> JVal) -> Ident -> JExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ident -> JVal
JVar
instance ToJExpr FastString where
toJExpr :: FastString -> JExpr
toJExpr = JVal -> JExpr
ValExpr (JVal -> JExpr) -> (FastString -> JVal) -> FastString -> JExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FastString -> JVal
JStr
instance (ToJExpr a, ToJExpr b) => ToJExpr (a,b) where
toJExpr :: (a, b) -> JExpr
toJExpr (a
a,b
b) = JVal -> JExpr
ValExpr (JVal -> JExpr) -> ([JExpr] -> JVal) -> [JExpr] -> JExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [JExpr] -> JVal
JList ([JExpr] -> JExpr) -> [JExpr] -> JExpr
forall a b. (a -> b) -> a -> b
$ [a -> JExpr
forall a. ToJExpr a => a -> JExpr
toJExpr a
a, b -> JExpr
forall a. ToJExpr a => a -> JExpr
toJExpr b
b]
instance (ToJExpr a, ToJExpr b, ToJExpr c) => ToJExpr (a,b,c) where
toJExpr :: (a, b, c) -> JExpr
toJExpr (a
a,b
b,c
c) = JVal -> JExpr
ValExpr (JVal -> JExpr) -> ([JExpr] -> JVal) -> [JExpr] -> JExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [JExpr] -> JVal
JList ([JExpr] -> JExpr) -> [JExpr] -> JExpr
forall a b. (a -> b) -> a -> b
$ [a -> JExpr
forall a. ToJExpr a => a -> JExpr
toJExpr a
a, b -> JExpr
forall a. ToJExpr a => a -> JExpr
toJExpr b
b, c -> JExpr
forall a. ToJExpr a => a -> JExpr
toJExpr c
c]
instance (ToJExpr a, ToJExpr b, ToJExpr c, ToJExpr d) => ToJExpr (a,b,c,d) where
toJExpr :: (a, b, c, d) -> JExpr
toJExpr (a
a,b
b,c
c,d
d) = JVal -> JExpr
ValExpr (JVal -> JExpr) -> ([JExpr] -> JVal) -> [JExpr] -> JExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [JExpr] -> JVal
JList ([JExpr] -> JExpr) -> [JExpr] -> JExpr
forall a b. (a -> b) -> a -> b
$ [a -> JExpr
forall a. ToJExpr a => a -> JExpr
toJExpr a
a, b -> JExpr
forall a. ToJExpr a => a -> JExpr
toJExpr b
b, c -> JExpr
forall a. ToJExpr a => a -> JExpr
toJExpr c
c, d -> JExpr
forall a. ToJExpr a => a -> JExpr
toJExpr d
d]
instance (ToJExpr a, ToJExpr b, ToJExpr c, ToJExpr d, ToJExpr e) => ToJExpr (a,b,c,d,e) where
toJExpr :: (a, b, c, d, e) -> JExpr
toJExpr (a
a,b
b,c
c,d
d,e
e) = JVal -> JExpr
ValExpr (JVal -> JExpr) -> ([JExpr] -> JVal) -> [JExpr] -> JExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [JExpr] -> JVal
JList ([JExpr] -> JExpr) -> [JExpr] -> JExpr
forall a b. (a -> b) -> a -> b
$ [a -> JExpr
forall a. ToJExpr a => a -> JExpr
toJExpr a
a, b -> JExpr
forall a. ToJExpr a => a -> JExpr
toJExpr b
b, c -> JExpr
forall a. ToJExpr a => a -> JExpr
toJExpr c
c, d -> JExpr
forall a. ToJExpr a => a -> JExpr
toJExpr d
d, e -> JExpr
forall a. ToJExpr a => a -> JExpr
toJExpr e
e]
instance (ToJExpr a, ToJExpr b, ToJExpr c, ToJExpr d, ToJExpr e, ToJExpr f) => ToJExpr (a,b,c,d,e,f) where
toJExpr :: (a, b, c, d, e, f) -> JExpr
toJExpr (a
a,b
b,c
c,d
d,e
e,f
f) = JVal -> JExpr
ValExpr (JVal -> JExpr) -> ([JExpr] -> JVal) -> [JExpr] -> JExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [JExpr] -> JVal
JList ([JExpr] -> JExpr) -> [JExpr] -> JExpr
forall a b. (a -> b) -> a -> b
$ [a -> JExpr
forall a. ToJExpr a => a -> JExpr
toJExpr a
a, b -> JExpr
forall a. ToJExpr a => a -> JExpr
toJExpr b
b, c -> JExpr
forall a. ToJExpr a => a -> JExpr
toJExpr c
c, d -> JExpr
forall a. ToJExpr a => a -> JExpr
toJExpr d
d, e -> JExpr
forall a. ToJExpr a => a -> JExpr
toJExpr e
e, f -> JExpr
forall a. ToJExpr a => a -> JExpr
toJExpr f
f]
class ToStat a where
toStat :: a -> JStat
instance ToStat JStat where
toStat :: JStat -> JStat
toStat = JStat -> JStat
forall a. a -> a
id
instance ToStat [JStat] where
toStat :: [JStat] -> JStat
toStat = [JStat] -> JStat
BlockStat
instance ToStat JExpr where
toStat :: JExpr -> JStat
toStat = JExpr -> JStat
expr2stat
instance ToStat [JExpr] where
toStat :: [JExpr] -> JStat
toStat = [JStat] -> JStat
BlockStat ([JStat] -> JStat) -> ([JExpr] -> [JStat]) -> [JExpr] -> JStat
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (JExpr -> JStat) -> [JExpr] -> [JStat]
forall a b. (a -> b) -> [a] -> [b]
map JExpr -> JStat
expr2stat
jLam :: ToSat a => a -> JExpr
jLam :: forall a. ToSat a => a -> JExpr
jLam a
f = JVal -> JExpr
ValExpr (JVal -> JExpr)
-> (State [Ident] JVal -> JVal) -> State [Ident] JVal -> JExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IdentSupply JVal -> JVal
UnsatVal (IdentSupply JVal -> JVal)
-> (State [Ident] JVal -> IdentSupply JVal)
-> State [Ident] JVal
-> JVal
forall b c a. (b -> c) -> (a -> b) -> a -> c
. State [Ident] JVal -> IdentSupply JVal
forall a. State [Ident] a -> IdentSupply a
IS (State [Ident] JVal -> JExpr) -> State [Ident] JVal -> JExpr
forall a b. (a -> b) -> a -> b
$ do
(JStat
block,[Ident]
is) <- IdentSupply (JStat, [Ident]) -> State [Ident] (JStat, [Ident])
forall a. IdentSupply a -> State [Ident] a
runIdentSupply (IdentSupply (JStat, [Ident]) -> State [Ident] (JStat, [Ident]))
-> IdentSupply (JStat, [Ident]) -> State [Ident] (JStat, [Ident])
forall a b. (a -> b) -> a -> b
$ a -> [Ident] -> IdentSupply (JStat, [Ident])
forall a. ToSat a => a -> [Ident] -> IdentSupply (JStat, [Ident])
toSat_ a
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
$ [Ident] -> JStat -> JVal
JFunc [Ident]
is JStat
block
jFun :: ToSat a => Ident -> a -> JStat
jFun :: forall a. ToSat a => Ident -> a -> JStat
jFun Ident
n a
f = IdentSupply JStat -> JStat
UnsatBlock (IdentSupply JStat -> JStat)
-> (State [Ident] JStat -> IdentSupply JStat)
-> State [Ident] JStat
-> JStat
forall b c a. (b -> c) -> (a -> b) -> a -> c
. State [Ident] JStat -> IdentSupply JStat
forall a. State [Ident] a -> IdentSupply a
IS (State [Ident] JStat -> JStat) -> State [Ident] JStat -> JStat
forall a b. (a -> b) -> a -> b
$ do
(JStat
block,[Ident]
is) <- IdentSupply (JStat, [Ident]) -> State [Ident] (JStat, [Ident])
forall a. IdentSupply a -> State [Ident] a
runIdentSupply (IdentSupply (JStat, [Ident]) -> State [Ident] (JStat, [Ident]))
-> IdentSupply (JStat, [Ident]) -> State [Ident] (JStat, [Ident])
forall a b. (a -> b) -> a -> b
$ a -> [Ident] -> IdentSupply (JStat, [Ident])
forall a. ToSat a => a -> [Ident] -> IdentSupply (JStat, [Ident])
toSat_ a
f []
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
$ Ident -> [Ident] -> JStat -> JStat
FuncStat Ident
n [Ident]
is JStat
block
jVar :: ToSat a => a -> JStat
jVar :: forall a. ToSat a => a -> JStat
jVar a
f = IdentSupply JStat -> JStat
UnsatBlock (IdentSupply JStat -> JStat)
-> (State [Ident] JStat -> IdentSupply JStat)
-> State [Ident] JStat
-> JStat
forall b c a. (b -> c) -> (a -> b) -> a -> c
. State [Ident] JStat -> IdentSupply JStat
forall a. State [Ident] a -> IdentSupply a
IS (State [Ident] JStat -> JStat) -> State [Ident] JStat -> JStat
forall a b. (a -> b) -> a -> b
$ do
(JStat
block, [Ident]
is) <- IdentSupply (JStat, [Ident]) -> State [Ident] (JStat, [Ident])
forall a. IdentSupply a -> State [Ident] a
runIdentSupply (IdentSupply (JStat, [Ident]) -> State [Ident] (JStat, [Ident]))
-> IdentSupply (JStat, [Ident]) -> State [Ident] (JStat, [Ident])
forall a b. (a -> b) -> a -> b
$ a -> [Ident] -> IdentSupply (JStat, [Ident])
forall a. ToSat a => a -> [Ident] -> IdentSupply (JStat, [Ident])
toSat_ a
f []
let addDecls :: JStat -> JStat
addDecls (BlockStat [JStat]
ss) =
[JStat] -> JStat
BlockStat ([JStat] -> JStat) -> [JStat] -> JStat
forall a b. (a -> b) -> a -> b
$ (Ident -> JStat) -> [Ident] -> [JStat]
forall a b. (a -> b) -> [a] -> [b]
map Ident -> JStat
decl [Ident]
is [JStat] -> [JStat] -> [JStat]
forall a. [a] -> [a] -> [a]
++ [JStat]
ss
addDecls JStat
x = JStat
x
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
$ JStat -> JStat
addDecls JStat
block
jFunction :: Ident -> [Ident] -> JStat -> JStat
jFunction :: Ident -> [Ident] -> JStat -> JStat
jFunction Ident
name [Ident]
args JStat
body = Ident -> [Ident] -> JStat -> JStat
FuncStat Ident
name [Ident]
args JStat
body
jForIn :: ToSat a => JExpr -> (JExpr -> a) -> JStat
jForIn :: forall a. ToSat a => JExpr -> (JExpr -> a) -> JStat
jForIn JExpr
e JExpr -> a
f = IdentSupply JStat -> JStat
UnsatBlock (IdentSupply JStat -> JStat)
-> (State [Ident] JStat -> IdentSupply JStat)
-> State [Ident] JStat
-> JStat
forall b c a. (b -> c) -> (a -> b) -> a -> c
. State [Ident] JStat -> IdentSupply JStat
forall a. State [Ident] a -> IdentSupply a
IS (State [Ident] JStat -> JStat) -> State [Ident] JStat -> JStat
forall a b. (a -> b) -> a -> b
$ do
(JStat
block, [Ident]
is) <- IdentSupply (JStat, [Ident]) -> State [Ident] (JStat, [Ident])
forall a. IdentSupply a -> State [Ident] a
runIdentSupply (IdentSupply (JStat, [Ident]) -> State [Ident] (JStat, [Ident]))
-> IdentSupply (JStat, [Ident]) -> State [Ident] (JStat, [Ident])
forall a b. (a -> b) -> a -> b
$ (JExpr -> a) -> [Ident] -> IdentSupply (JStat, [Ident])
forall a. ToSat a => a -> [Ident] -> IdentSupply (JStat, [Ident])
toSat_ JExpr -> a
f []
let i :: Ident
i = [Ident] -> Ident
forall a. HasCallStack => [a] -> a
head [Ident]
is
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
$ Ident -> JStat
decl Ident
i JStat -> JStat -> JStat
forall a. Monoid a => a -> a -> a
`mappend` Bool -> Ident -> JExpr -> JStat -> JStat
ForInStat Bool
False Ident
i JExpr
e JStat
block
jForEachIn :: ToSat a => JExpr -> (JExpr -> a) -> JStat
jForEachIn :: forall a. ToSat a => JExpr -> (JExpr -> a) -> JStat
jForEachIn JExpr
e JExpr -> a
f = IdentSupply JStat -> JStat
UnsatBlock (IdentSupply JStat -> JStat)
-> (State [Ident] JStat -> IdentSupply JStat)
-> State [Ident] JStat
-> JStat
forall b c a. (b -> c) -> (a -> b) -> a -> c
. State [Ident] JStat -> IdentSupply JStat
forall a. State [Ident] a -> IdentSupply a
IS (State [Ident] JStat -> JStat) -> State [Ident] JStat -> JStat
forall a b. (a -> b) -> a -> b
$ do
(JStat
block, [Ident]
is) <- IdentSupply (JStat, [Ident]) -> State [Ident] (JStat, [Ident])
forall a. IdentSupply a -> State [Ident] a
runIdentSupply (IdentSupply (JStat, [Ident]) -> State [Ident] (JStat, [Ident]))
-> IdentSupply (JStat, [Ident]) -> State [Ident] (JStat, [Ident])
forall a b. (a -> b) -> a -> b
$ (JExpr -> a) -> [Ident] -> IdentSupply (JStat, [Ident])
forall a. ToSat a => a -> [Ident] -> IdentSupply (JStat, [Ident])
toSat_ JExpr -> a
f []
let i :: Ident
i = [Ident] -> Ident
forall a. HasCallStack => [a] -> a
head [Ident]
is
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
$ Ident -> JStat
decl Ident
i JStat -> JStat -> JStat
forall a. Monoid a => a -> a -> a
`mappend` Bool -> Ident -> JExpr -> JStat -> JStat
ForInStat Bool
True Ident
i JExpr
e JStat
block
jFor :: (JExpr -> JStat)
-> (JExpr -> JExpr)
-> (JExpr -> JStat)
-> (JExpr -> JStat)
-> JStat
jFor :: (JExpr -> JStat)
-> (JExpr -> JExpr)
-> (JExpr -> JStat)
-> (JExpr -> JStat)
-> JStat
jFor JExpr -> JStat
init JExpr -> JExpr
pred JExpr -> JStat
step JExpr -> JStat
body = (JExpr -> JStat) -> JStat
forall a. ToSat a => a -> JStat
jVar ((JExpr -> JStat) -> JStat) -> (JExpr -> JStat) -> JStat
forall a b. (a -> b) -> a -> b
$ \JExpr
i -> JStat -> JExpr -> JStat -> JStat -> JStat
ForStat (JExpr -> JStat
init JExpr
i) (JExpr -> JExpr
pred JExpr
i) (JExpr -> JStat
step JExpr
i) (JExpr -> JStat
body JExpr
i)
jForNoDecl :: Ident -> JExpr -> JExpr -> JStat -> JStat -> JStat
jForNoDecl :: Ident -> JExpr -> JExpr -> JStat -> JStat -> JStat
jForNoDecl Ident
i JExpr
initial JExpr
p JStat
step JStat
body = JStat -> JExpr -> JStat -> JStat -> JStat
ForStat (Ident -> JExpr
forall a. ToJExpr a => a -> JExpr
toJExpr Ident
i JExpr -> JExpr -> JStat
|= JExpr
initial) JExpr
p JStat
step JStat
body
jTryCatchFinally :: (ToSat a) => JStat -> a -> JStat -> JStat
jTryCatchFinally :: forall a. ToSat a => JStat -> a -> JStat -> JStat
jTryCatchFinally JStat
s a
f JStat
s2 = IdentSupply JStat -> JStat
UnsatBlock (IdentSupply JStat -> JStat)
-> (State [Ident] JStat -> IdentSupply JStat)
-> State [Ident] JStat
-> JStat
forall b c a. (b -> c) -> (a -> b) -> a -> c
. State [Ident] JStat -> IdentSupply JStat
forall a. State [Ident] a -> IdentSupply a
IS (State [Ident] JStat -> JStat) -> State [Ident] JStat -> JStat
forall a b. (a -> b) -> a -> b
$ do
(JStat
block, [Ident]
is) <- IdentSupply (JStat, [Ident]) -> State [Ident] (JStat, [Ident])
forall a. IdentSupply a -> State [Ident] a
runIdentSupply (IdentSupply (JStat, [Ident]) -> State [Ident] (JStat, [Ident]))
-> IdentSupply (JStat, [Ident]) -> State [Ident] (JStat, [Ident])
forall a b. (a -> b) -> a -> b
$ a -> [Ident] -> IdentSupply (JStat, [Ident])
forall a. ToSat a => a -> [Ident] -> IdentSupply (JStat, [Ident])
toSat_ a
f []
let i :: Ident
i = [Ident] -> Ident
forall a. HasCallStack => [a] -> a
head [Ident]
is
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
$ JStat -> Ident -> JStat -> JStat -> JStat
TryStat JStat
s Ident
i JStat
block JStat
s2
var :: FastString -> JExpr
var :: FastString -> JExpr
var = JVal -> JExpr
ValExpr (JVal -> JExpr) -> (FastString -> JVal) -> FastString -> JExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ident -> JVal
JVar (Ident -> JVal) -> (FastString -> Ident) -> FastString -> JVal
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FastString -> Ident
TxtI
jString :: FastString -> JExpr
jString :: FastString -> JExpr
jString = FastString -> JExpr
forall a. ToJExpr a => a -> JExpr
toJExpr
decl :: Ident -> JStat
decl :: Ident -> JStat
decl Ident
i = Ident -> Maybe JExpr -> JStat
DeclStat Ident
i Maybe JExpr
forall a. Maybe a
Nothing
jhEmpty :: M.Map k JExpr
jhEmpty :: forall k. Map k JExpr
jhEmpty = Map k JExpr
forall k a. Map k a
M.empty
jhSingle :: (Ord k, ToJExpr a) => k -> a -> M.Map k JExpr
jhSingle :: forall k a. (Ord k, ToJExpr a) => k -> a -> Map k JExpr
jhSingle k
k a
v = k -> a -> Map k JExpr -> Map k JExpr
forall k a.
(Ord k, ToJExpr a) =>
k -> a -> Map k JExpr -> Map k JExpr
jhAdd k
k a
v Map k JExpr
forall k. Map k JExpr
jhEmpty
jhAdd :: (Ord k, ToJExpr a) => k -> a -> M.Map k JExpr -> M.Map k JExpr
jhAdd :: forall k a.
(Ord k, ToJExpr a) =>
k -> a -> Map k JExpr -> Map k JExpr
jhAdd k
k a
v Map k JExpr
m = k -> JExpr -> Map k JExpr -> Map k JExpr
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert k
k (a -> JExpr
forall a. ToJExpr a => a -> JExpr
toJExpr a
v) Map k JExpr
m
jhFromList :: [(FastString, JExpr)] -> JVal
jhFromList :: [(FastString, JExpr)] -> JVal
jhFromList = UniqMap FastString JExpr -> JVal
JHash (UniqMap FastString JExpr -> JVal)
-> ([(FastString, JExpr)] -> UniqMap FastString JExpr)
-> [(FastString, JExpr)]
-> JVal
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(FastString, JExpr)] -> UniqMap FastString JExpr
forall k a. Uniquable k => [(k, a)] -> UniqMap k a
listToUniqMap
nullStat :: JStat
nullStat :: JStat
nullStat = [JStat] -> JStat
BlockStat []
(.==.), (.===.), (.!=.), (.!==.) :: JExpr -> JExpr -> JExpr
.==. :: JExpr -> JExpr -> JExpr
(.==.) = JOp -> JExpr -> JExpr -> JExpr
InfixExpr JOp
EqOp
.===. :: JExpr -> JExpr -> JExpr
(.===.) = JOp -> JExpr -> JExpr -> JExpr
InfixExpr JOp
StrictEqOp
.!=. :: JExpr -> JExpr -> JExpr
(.!=.) = JOp -> JExpr -> JExpr -> JExpr
InfixExpr JOp
NeqOp
.!==. :: JExpr -> JExpr -> JExpr
(.!==.) = JOp -> JExpr -> JExpr -> JExpr
InfixExpr JOp
StrictNeqOp
infixl 6 .==., .===., .!=., .!==.
(.>.), (.>=.), (.<.), (.<=.) :: JExpr -> JExpr -> JExpr
.>. :: JExpr -> JExpr -> JExpr
(.>.) = JOp -> JExpr -> JExpr -> JExpr
InfixExpr JOp
GtOp
.>=. :: JExpr -> JExpr -> JExpr
(.>=.) = JOp -> JExpr -> JExpr -> JExpr
InfixExpr JOp
GeOp
.<. :: JExpr -> JExpr -> JExpr
(.<.) = JOp -> JExpr -> JExpr -> JExpr
InfixExpr JOp
LtOp
.<=. :: JExpr -> JExpr -> JExpr
(.<=.) = JOp -> JExpr -> JExpr -> JExpr
InfixExpr JOp
LeOp
infixl 7 .>., .>=., .<., .<=.
(.|.), (.||.), (.&&.) :: JExpr -> JExpr -> JExpr
.|. :: JExpr -> JExpr -> JExpr
(.|.) = JOp -> JExpr -> JExpr -> JExpr
InfixExpr JOp
BOrOp
.||. :: JExpr -> JExpr -> JExpr
(.||.) = JOp -> JExpr -> JExpr -> JExpr
InfixExpr JOp
LOrOp
.&&. :: JExpr -> JExpr -> JExpr
(.&&.) = JOp -> JExpr -> JExpr -> JExpr
InfixExpr JOp
LAndOp
infixl 8 .||., .&&.
(.<<.), (.>>.), (.>>>.) :: JExpr -> JExpr -> JExpr
.<<. :: JExpr -> JExpr -> JExpr
(.<<.) = JOp -> JExpr -> JExpr -> JExpr
InfixExpr JOp
LeftShiftOp
.>>. :: JExpr -> JExpr -> JExpr
(.>>.) = JOp -> JExpr -> JExpr -> JExpr
InfixExpr JOp
RightShiftOp
.>>>. :: JExpr -> JExpr -> JExpr
(.>>>.) = JOp -> JExpr -> JExpr -> JExpr
InfixExpr JOp
ZRightShiftOp
infixl 9 .<<., .>>., .>>>.
typeof :: JExpr -> JExpr
typeof :: JExpr -> JExpr
typeof = JUOp -> JExpr -> JExpr
UOpExpr JUOp
TypeofOp
if_ :: JExpr -> JExpr -> JExpr -> JExpr
if_ :: JExpr -> JExpr -> JExpr -> JExpr
if_ JExpr
e1 JExpr
e2 JExpr
e3 = JExpr -> JExpr -> JExpr -> JExpr
IfExpr JExpr
e1 JExpr
e2 JExpr
e3
ifS :: JExpr -> JStat -> JStat -> JStat
ifS :: JExpr -> JStat -> JStat -> JStat
ifS JExpr
e JStat
s1 JStat
s2 = JExpr -> JStat -> JStat -> JStat
IfStat JExpr
e JStat
s1 JStat
s2
jwhenS :: JExpr -> JStat -> JStat
jwhenS :: JExpr -> JStat -> JStat
jwhenS JExpr
cond JStat
block = JExpr -> JStat -> JStat -> JStat
ifS JExpr
cond JStat
block JStat
forall a. Monoid a => a
mempty
ifBlockS :: JExpr -> [JStat] -> [JStat] -> JStat
ifBlockS :: JExpr -> [JStat] -> [JStat] -> JStat
ifBlockS JExpr
e [JStat]
s1 [JStat]
s2 = JExpr -> JStat -> JStat -> JStat
IfStat JExpr
e ([JStat] -> JStat
forall a. Monoid a => [a] -> a
mconcat [JStat]
s1) ([JStat] -> JStat
forall a. Monoid a => [a] -> a
mconcat [JStat]
s2)
if10 :: JExpr -> JExpr
if10 :: JExpr -> JExpr
if10 JExpr
e = JExpr -> JExpr -> JExpr -> JExpr
IfExpr JExpr
e JExpr
one_ JExpr
zero_
if01 :: JExpr -> JExpr
if01 :: JExpr -> JExpr
if01 JExpr
e = JExpr -> JExpr -> JExpr -> JExpr
IfExpr JExpr
e JExpr
zero_ JExpr
one_
app :: FastString -> [JExpr] -> JExpr
app :: FastString -> [JExpr] -> JExpr
app FastString
f [JExpr]
xs = JExpr -> [JExpr] -> JExpr
ApplExpr (FastString -> JExpr
var FastString
f) [JExpr]
xs
appS :: FastString -> [JExpr] -> JStat
appS :: FastString -> [JExpr] -> JStat
appS FastString
f [JExpr]
xs = JExpr -> [JExpr] -> JStat
ApplStat (FastString -> JExpr
var FastString
f) [JExpr]
xs
returnS :: JExpr -> JStat
returnS :: JExpr -> JStat
returnS JExpr
e = JExpr -> JStat
ReturnStat JExpr
e
loop :: JExpr -> (JExpr -> JExpr) -> (JExpr -> JStat) -> JStat
loop :: JExpr -> (JExpr -> JExpr) -> (JExpr -> JStat) -> JStat
loop JExpr
initial JExpr -> JExpr
test JExpr -> JStat
body = (JExpr -> JStat) -> JStat
forall a. ToSat a => a -> JStat
jVar ((JExpr -> JStat) -> JStat) -> (JExpr -> JStat) -> JStat
forall a b. (a -> b) -> a -> b
$ \JExpr
i ->
[JStat] -> JStat
forall a. Monoid a => [a] -> a
mconcat [ JExpr
i JExpr -> JExpr -> JStat
|= JExpr
initial
, Bool -> JExpr -> JStat -> JStat
WhileStat Bool
False (JExpr -> JExpr
test JExpr
i) (JExpr -> JStat
body JExpr
i)
]
loopBlockS :: JExpr -> (JExpr -> JExpr) -> (JExpr -> [JStat]) -> JStat
loopBlockS :: JExpr -> (JExpr -> JExpr) -> (JExpr -> [JStat]) -> JStat
loopBlockS JExpr
initial JExpr -> JExpr
test JExpr -> [JStat]
body = (JExpr -> JStat) -> JStat
forall a. ToSat a => a -> JStat
jVar ((JExpr -> JStat) -> JStat) -> (JExpr -> JStat) -> JStat
forall a b. (a -> b) -> a -> b
$ \JExpr
i ->
[JStat] -> JStat
forall a. Monoid a => [a] -> a
mconcat [ JExpr
i JExpr -> JExpr -> JStat
|= JExpr
initial
, Bool -> JExpr -> JStat -> JStat
WhileStat Bool
False (JExpr -> JExpr
test JExpr
i) ([JStat] -> JStat
forall a. Monoid a => [a] -> a
mconcat (JExpr -> [JStat]
body JExpr
i))
]
preIncrS :: JExpr -> JStat
preIncrS :: JExpr -> JStat
preIncrS JExpr
x = JUOp -> JExpr -> JStat
UOpStat JUOp
PreIncOp JExpr
x
postIncrS :: JExpr -> JStat
postIncrS :: JExpr -> JStat
postIncrS JExpr
x = JUOp -> JExpr -> JStat
UOpStat JUOp
PostIncOp JExpr
x
preDecrS :: JExpr -> JStat
preDecrS :: JExpr -> JStat
preDecrS JExpr
x = JUOp -> JExpr -> JStat
UOpStat JUOp
PreDecOp JExpr
x
postDecrS :: JExpr -> JStat
postDecrS :: JExpr -> JStat
postDecrS JExpr
x = JUOp -> JExpr -> JStat
UOpStat JUOp
PostDecOp JExpr
x
off64 :: JExpr -> JExpr -> JExpr
off64 :: JExpr -> JExpr -> JExpr
off64 JExpr
o JExpr
i = JExpr -> JExpr -> JExpr
Add JExpr
o (JExpr
i JExpr -> JExpr -> JExpr
.<<. JExpr
three_)
off32 :: JExpr -> JExpr -> JExpr
off32 :: JExpr -> JExpr -> JExpr
off32 JExpr
o JExpr
i = JExpr -> JExpr -> JExpr
Add JExpr
o (JExpr
i JExpr -> JExpr -> JExpr
.<<. JExpr
two_)
off16 :: JExpr -> JExpr -> JExpr
off16 :: JExpr -> JExpr -> JExpr
off16 JExpr
o JExpr
i = JExpr -> JExpr -> JExpr
Add JExpr
o (JExpr
i JExpr -> JExpr -> JExpr
.<<. JExpr
one_)
off8 :: JExpr -> JExpr -> JExpr
off8 :: JExpr -> JExpr -> JExpr
off8 JExpr
o JExpr
i = JExpr -> JExpr -> JExpr
Add JExpr
o JExpr
i
mask8 :: JExpr -> JExpr
mask8 :: JExpr -> JExpr
mask8 JExpr
x = JExpr -> JExpr -> JExpr
BAnd JExpr
x (Integer -> JExpr
Int Integer
0xFF)
mask16 :: JExpr -> JExpr
mask16 :: JExpr -> JExpr
mask16 JExpr
x = JExpr -> JExpr -> JExpr
BAnd JExpr
x (Integer -> JExpr
Int Integer
0xFFFF)
signExtend8 :: JExpr -> JExpr
signExtend8 :: JExpr -> JExpr
signExtend8 JExpr
x = (JExpr -> JExpr -> JExpr
BAnd JExpr
x (Integer -> JExpr
Int Integer
0x7F )) JExpr -> JExpr -> JExpr
`Sub` (JExpr -> JExpr -> JExpr
BAnd JExpr
x (Integer -> JExpr
Int Integer
0x80))
signExtend16 :: JExpr -> JExpr
signExtend16 :: JExpr -> JExpr
signExtend16 JExpr
x = (JExpr -> JExpr -> JExpr
BAnd JExpr
x (Integer -> JExpr
Int Integer
0x7FFF)) JExpr -> JExpr -> JExpr
`Sub` (JExpr -> JExpr -> JExpr
BAnd JExpr
x (Integer -> JExpr
Int Integer
0x8000))
(.^) :: JExpr -> FastString -> JExpr
JExpr
obj .^ :: JExpr -> FastString -> JExpr
.^ FastString
prop = JExpr -> Ident -> JExpr
SelExpr JExpr
obj (FastString -> Ident
TxtI FastString
prop)
infixl 8 .^
(|=) :: JExpr -> JExpr -> JStat
|= :: JExpr -> JExpr -> JStat
(|=) = JExpr -> JExpr -> JStat
AssignStat
(||=) :: Ident -> JExpr -> JStat
Ident
i ||= :: Ident -> JExpr -> JStat
||= JExpr
ex = Ident -> Maybe JExpr -> JStat
DeclStat Ident
i (JExpr -> Maybe JExpr
forall a. a -> Maybe a
Just JExpr
ex)
infixl 2 ||=, |=
(.!) :: JExpr -> JExpr -> JExpr
.! :: JExpr -> JExpr -> JExpr
(.!) = JExpr -> JExpr -> JExpr
IdxExpr
infixl 8 .!
assignAllEqual :: HasDebugCallStack => [JExpr] -> [JExpr] -> JStat
assignAllEqual :: HasDebugCallStack => [JExpr] -> [JExpr] -> JStat
assignAllEqual [JExpr]
xs [JExpr]
ys = [JStat] -> JStat
forall a. Monoid a => [a] -> a
mconcat (String
-> (JExpr -> JExpr -> JStat) -> [JExpr] -> [JExpr] -> [JStat]
forall a b c.
HasDebugCallStack =>
String -> (a -> b -> c) -> [a] -> [b] -> [c]
zipWithEqual String
"assignAllEqual" JExpr -> JExpr -> JStat
(|=) [JExpr]
xs [JExpr]
ys)
assignAll :: [JExpr] -> [JExpr] -> JStat
assignAll :: [JExpr] -> [JExpr] -> JStat
assignAll [JExpr]
xs [JExpr]
ys = [JStat] -> JStat
forall a. Monoid a => [a] -> a
mconcat ((JExpr -> JExpr -> JStat) -> [JExpr] -> [JExpr] -> [JStat]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith JExpr -> JExpr -> JStat
(|=) [JExpr]
xs [JExpr]
ys)
assignAllReverseOrder :: [JExpr] -> [JExpr] -> JStat
assignAllReverseOrder :: [JExpr] -> [JExpr] -> JStat
assignAllReverseOrder [JExpr]
xs [JExpr]
ys = [JStat] -> JStat
forall a. Monoid a => [a] -> a
mconcat ([JStat] -> [JStat]
forall a. [a] -> [a]
reverse ((JExpr -> JExpr -> JStat) -> [JExpr] -> [JExpr] -> [JStat]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith JExpr -> JExpr -> JStat
(|=) [JExpr]
xs [JExpr]
ys))
declAssignAll :: [Ident] -> [JExpr] -> JStat
declAssignAll :: [Ident] -> [JExpr] -> JStat
declAssignAll [Ident]
xs [JExpr]
ys = [JStat] -> JStat
forall a. Monoid a => [a] -> a
mconcat ((Ident -> JExpr -> JStat) -> [Ident] -> [JExpr] -> [JStat]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith Ident -> JExpr -> JStat
(||=) [Ident]
xs [JExpr]
ys)
trace :: ToJExpr a => a -> JStat
trace :: forall a. ToJExpr a => a -> JStat
trace a
ex = FastString -> [JExpr] -> JStat
appS FastString
"h$log" [a -> JExpr
forall a. ToJExpr a => a -> JExpr
toJExpr a
ex]
null_ :: JExpr
null_ :: JExpr
null_ = FastString -> JExpr
var FastString
"null"
zero_ :: JExpr
zero_ :: JExpr
zero_ = Integer -> JExpr
Int Integer
0
one_ :: JExpr
one_ :: JExpr
one_ = Integer -> JExpr
Int Integer
1
two_ :: JExpr
two_ :: JExpr
two_ = Integer -> JExpr
Int Integer
2
three_ :: JExpr
three_ :: JExpr
three_ = Integer -> JExpr
Int Integer
3
undefined_ :: JExpr
undefined_ :: JExpr
undefined_ = FastString -> JExpr
var FastString
"undefined"
true_ :: JExpr
true_ :: JExpr
true_ = FastString -> JExpr
var FastString
"true"
false_ :: JExpr
false_ :: JExpr
false_ = FastString -> JExpr
var FastString
"false"
returnStack :: JStat
returnStack :: JStat
returnStack = JExpr -> JStat
ReturnStat (JExpr -> [JExpr] -> JExpr
ApplExpr (FastString -> JExpr
var FastString
"h$rs") [])
math :: JExpr
math :: JExpr
math = FastString -> JExpr
var FastString
"Math"
math_ :: FastString -> [JExpr] -> JExpr
math_ :: FastString -> [JExpr] -> JExpr
math_ FastString
op [JExpr]
args = JExpr -> [JExpr] -> JExpr
ApplExpr (JExpr
math JExpr -> FastString -> JExpr
.^ FastString
op) [JExpr]
args
math_log, math_sin, math_cos, math_tan, math_exp, math_acos, math_asin, math_atan,
math_abs, math_pow, math_sqrt, math_asinh, math_acosh, math_atanh, math_sign,
math_sinh, math_cosh, math_tanh, math_expm1, math_log1p, math_fround
:: [JExpr] -> JExpr
math_log :: [JExpr] -> JExpr
math_log = FastString -> [JExpr] -> JExpr
math_ FastString
"log"
math_sin :: [JExpr] -> JExpr
math_sin = FastString -> [JExpr] -> JExpr
math_ FastString
"sin"
math_cos :: [JExpr] -> JExpr
math_cos = FastString -> [JExpr] -> JExpr
math_ FastString
"cos"
math_tan :: [JExpr] -> JExpr
math_tan = FastString -> [JExpr] -> JExpr
math_ FastString
"tan"
math_exp :: [JExpr] -> JExpr
math_exp = FastString -> [JExpr] -> JExpr
math_ FastString
"exp"
math_acos :: [JExpr] -> JExpr
math_acos = FastString -> [JExpr] -> JExpr
math_ FastString
"acos"
math_asin :: [JExpr] -> JExpr
math_asin = FastString -> [JExpr] -> JExpr
math_ FastString
"asin"
math_atan :: [JExpr] -> JExpr
math_atan = FastString -> [JExpr] -> JExpr
math_ FastString
"atan"
math_abs :: [JExpr] -> JExpr
math_abs = FastString -> [JExpr] -> JExpr
math_ FastString
"abs"
math_pow :: [JExpr] -> JExpr
math_pow = FastString -> [JExpr] -> JExpr
math_ FastString
"pow"
math_sign :: [JExpr] -> JExpr
math_sign = FastString -> [JExpr] -> JExpr
math_ FastString
"sign"
math_sqrt :: [JExpr] -> JExpr
math_sqrt = FastString -> [JExpr] -> JExpr
math_ FastString
"sqrt"
math_asinh :: [JExpr] -> JExpr
math_asinh = FastString -> [JExpr] -> JExpr
math_ FastString
"asinh"
math_acosh :: [JExpr] -> JExpr
math_acosh = FastString -> [JExpr] -> JExpr
math_ FastString
"acosh"
math_atanh :: [JExpr] -> JExpr
math_atanh = FastString -> [JExpr] -> JExpr
math_ FastString
"atanh"
math_sinh :: [JExpr] -> JExpr
math_sinh = FastString -> [JExpr] -> JExpr
math_ FastString
"sinh"
math_cosh :: [JExpr] -> JExpr
math_cosh = FastString -> [JExpr] -> JExpr
math_ FastString
"cosh"
math_tanh :: [JExpr] -> JExpr
math_tanh = FastString -> [JExpr] -> JExpr
math_ FastString
"tanh"
math_expm1 :: [JExpr] -> JExpr
math_expm1 = FastString -> [JExpr] -> JExpr
math_ FastString
"expm1"
math_log1p :: [JExpr] -> JExpr
math_log1p = FastString -> [JExpr] -> JExpr
math_ FastString
"log1p"
math_fround :: [JExpr] -> JExpr
math_fround = FastString -> [JExpr] -> JExpr
math_ FastString
"fround"
instance Num JExpr where
JExpr
x + :: JExpr -> JExpr -> JExpr
+ JExpr
y = JOp -> JExpr -> JExpr -> JExpr
InfixExpr JOp
AddOp JExpr
x JExpr
y
JExpr
x - :: JExpr -> JExpr -> JExpr
- JExpr
y = JOp -> JExpr -> JExpr -> JExpr
InfixExpr JOp
SubOp JExpr
x JExpr
y
JExpr
x * :: JExpr -> JExpr -> JExpr
* JExpr
y = JOp -> JExpr -> JExpr -> JExpr
InfixExpr JOp
MulOp JExpr
x JExpr
y
abs :: JExpr -> JExpr
abs JExpr
x = [JExpr] -> JExpr
math_abs [JExpr
x]
negate :: JExpr -> JExpr
negate JExpr
x = JUOp -> JExpr -> JExpr
UOpExpr JUOp
NegOp JExpr
x
signum :: JExpr -> JExpr
signum JExpr
x = [JExpr] -> JExpr
math_sign [JExpr
x]
fromInteger :: Integer -> JExpr
fromInteger Integer
x = JVal -> JExpr
ValExpr (Integer -> JVal
JInt Integer
x)
instance Fractional JExpr where
JExpr
x / :: JExpr -> JExpr -> JExpr
/ JExpr
y = JOp -> JExpr -> JExpr -> JExpr
InfixExpr JOp
DivOp JExpr
x JExpr
y
fromRational :: Rational -> JExpr
fromRational Rational
x = JVal -> JExpr
ValExpr (SaneDouble -> JVal
JDouble (Rational -> SaneDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Rational
x))
class ToSat a where
toSat_ :: a -> [Ident] -> IdentSupply (JStat, [Ident])
instance ToSat [JStat] where
toSat_ :: [JStat] -> [Ident] -> IdentSupply (JStat, [Ident])
toSat_ [JStat]
f [Ident]
vs = State [Ident] (JStat, [Ident]) -> IdentSupply (JStat, [Ident])
forall a. State [Ident] a -> IdentSupply a
IS (State [Ident] (JStat, [Ident]) -> IdentSupply (JStat, [Ident]))
-> State [Ident] (JStat, [Ident]) -> IdentSupply (JStat, [Ident])
forall a b. (a -> b) -> a -> b
$ (JStat, [Ident]) -> State [Ident] (JStat, [Ident])
forall a. a -> State [Ident] a
forall (m :: * -> *) a. Monad m => a -> m a
return ((JStat, [Ident]) -> State [Ident] (JStat, [Ident]))
-> (JStat, [Ident]) -> State [Ident] (JStat, [Ident])
forall a b. (a -> b) -> a -> b
$ ([JStat] -> JStat
BlockStat [JStat]
f, [Ident] -> [Ident]
forall a. [a] -> [a]
reverse [Ident]
vs)
instance ToSat JStat where
toSat_ :: JStat -> [Ident] -> IdentSupply (JStat, [Ident])
toSat_ JStat
f [Ident]
vs = State [Ident] (JStat, [Ident]) -> IdentSupply (JStat, [Ident])
forall a. State [Ident] a -> IdentSupply a
IS (State [Ident] (JStat, [Ident]) -> IdentSupply (JStat, [Ident]))
-> State [Ident] (JStat, [Ident]) -> IdentSupply (JStat, [Ident])
forall a b. (a -> b) -> a -> b
$ (JStat, [Ident]) -> State [Ident] (JStat, [Ident])
forall a. a -> State [Ident] a
forall (m :: * -> *) a. Monad m => a -> m a
return ((JStat, [Ident]) -> State [Ident] (JStat, [Ident]))
-> (JStat, [Ident]) -> State [Ident] (JStat, [Ident])
forall a b. (a -> b) -> a -> b
$ (JStat
f, [Ident] -> [Ident]
forall a. [a] -> [a]
reverse [Ident]
vs)
instance ToSat JExpr where
toSat_ :: JExpr -> [Ident] -> IdentSupply (JStat, [Ident])
toSat_ JExpr
f [Ident]
vs = State [Ident] (JStat, [Ident]) -> IdentSupply (JStat, [Ident])
forall a. State [Ident] a -> IdentSupply a
IS (State [Ident] (JStat, [Ident]) -> IdentSupply (JStat, [Ident]))
-> State [Ident] (JStat, [Ident]) -> IdentSupply (JStat, [Ident])
forall a b. (a -> b) -> a -> b
$ (JStat, [Ident]) -> State [Ident] (JStat, [Ident])
forall a. a -> State [Ident] a
forall (m :: * -> *) a. Monad m => a -> m a
return ((JStat, [Ident]) -> State [Ident] (JStat, [Ident]))
-> (JStat, [Ident]) -> State [Ident] (JStat, [Ident])
forall a b. (a -> b) -> a -> b
$ (JExpr -> JStat
forall a. ToStat a => a -> JStat
toStat JExpr
f, [Ident] -> [Ident]
forall a. [a] -> [a]
reverse [Ident]
vs)
instance ToSat [JExpr] where
toSat_ :: [JExpr] -> [Ident] -> IdentSupply (JStat, [Ident])
toSat_ [JExpr]
f [Ident]
vs = State [Ident] (JStat, [Ident]) -> IdentSupply (JStat, [Ident])
forall a. State [Ident] a -> IdentSupply a
IS (State [Ident] (JStat, [Ident]) -> IdentSupply (JStat, [Ident]))
-> State [Ident] (JStat, [Ident]) -> IdentSupply (JStat, [Ident])
forall a b. (a -> b) -> a -> b
$ (JStat, [Ident]) -> State [Ident] (JStat, [Ident])
forall a. a -> State [Ident] a
forall (m :: * -> *) a. Monad m => a -> m a
return ((JStat, [Ident]) -> State [Ident] (JStat, [Ident]))
-> (JStat, [Ident]) -> State [Ident] (JStat, [Ident])
forall a b. (a -> b) -> a -> b
$ ([JStat] -> JStat
BlockStat ([JStat] -> JStat) -> [JStat] -> JStat
forall a b. (a -> b) -> a -> b
$ (JExpr -> JStat) -> [JExpr] -> [JStat]
forall a b. (a -> b) -> [a] -> [b]
map JExpr -> JStat
expr2stat [JExpr]
f, [Ident] -> [Ident]
forall a. [a] -> [a]
reverse [Ident]
vs)
instance (ToSat a, b ~ JExpr) => ToSat (b -> a) where
toSat_ :: (b -> a) -> [Ident] -> IdentSupply (JStat, [Ident])
toSat_ b -> a
f [Ident]
vs = State [Ident] (JStat, [Ident]) -> IdentSupply (JStat, [Ident])
forall a. State [Ident] a -> IdentSupply a
IS (State [Ident] (JStat, [Ident]) -> IdentSupply (JStat, [Ident]))
-> State [Ident] (JStat, [Ident]) -> IdentSupply (JStat, [Ident])
forall a b. (a -> b) -> a -> b
$ do
Ident
x <- State [Ident] Ident
takeOneIdent
IdentSupply (JStat, [Ident]) -> State [Ident] (JStat, [Ident])
forall a. IdentSupply a -> State [Ident] a
runIdentSupply (IdentSupply (JStat, [Ident]) -> State [Ident] (JStat, [Ident]))
-> IdentSupply (JStat, [Ident]) -> State [Ident] (JStat, [Ident])
forall a b. (a -> b) -> a -> b
$ a -> [Ident] -> IdentSupply (JStat, [Ident])
forall a. ToSat a => a -> [Ident] -> IdentSupply (JStat, [Ident])
toSat_ (b -> a
f (JVal -> JExpr
ValExpr (JVal -> JExpr) -> JVal -> JExpr
forall a b. (a -> b) -> a -> b
$ Ident -> JVal
JVar Ident
x)) (Ident
xIdent -> [Ident] -> [Ident]
forall a. a -> [a] -> [a]
:[Ident]
vs)
expr2stat :: JExpr -> JStat
expr2stat :: JExpr -> JStat
expr2stat (ApplExpr JExpr
x [JExpr]
y) = (JExpr -> [JExpr] -> JStat
ApplStat JExpr
x [JExpr]
y)
expr2stat (IfExpr JExpr
x JExpr
y JExpr
z) = JExpr -> JStat -> JStat -> JStat
IfStat JExpr
x (JExpr -> JStat
expr2stat JExpr
y) (JExpr -> JStat
expr2stat JExpr
z)
expr2stat (UOpExpr JUOp
o JExpr
x) = JUOp -> JExpr -> JStat
UOpStat JUOp
o JExpr
x
expr2stat JExpr
_ = JStat
nullStat
takeOneIdent :: State [Ident] Ident
takeOneIdent :: State [Ident] Ident
takeOneIdent = do
[Ident]
xxs <- State [Ident] [Ident]
forall s. State s s
get
case [Ident]
xxs of
(Ident
x:[Ident]
xs) -> do
[Ident] -> State [Ident] ()
forall s. s -> State s ()
put [Ident]
xs
Ident -> State [Ident] Ident
forall a. a -> State [Ident] a
forall (m :: * -> *) a. Monad m => a -> m a
return Ident
x
[Ident]
_ -> String -> State [Ident] Ident
forall a. HasCallStack => String -> a
error String
"takeOneIdent: empty list"