{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}

-- |
-- Module      :   Grisette.IR.SymPrim.Data.Prim.InternedTerm.InternedCtors
-- Copyright   :   (c) Sirui Lu 2021-2023
-- License     :   BSD-3-Clause (see the LICENSE file)
--
-- Maintainer  :   siruilu@cs.washington.edu
-- Stability   :   Experimental
-- Portability :   GHC only
module Grisette.IR.SymPrim.Data.Prim.InternedTerm.InternedCtors
  ( constructUnary,
    constructBinary,
    constructTernary,
    conTerm,
    symTerm,
    ssymTerm,
    isymTerm,
    sinfosymTerm,
    iinfosymTerm,
    notTerm,
    orTerm,
    andTerm,
    eqvTerm,
    iteTerm,
    addNumTerm,
    uminusNumTerm,
    timesNumTerm,
    absNumTerm,
    signumNumTerm,
    ltNumTerm,
    leNumTerm,
    andBitsTerm,
    orBitsTerm,
    xorBitsTerm,
    complementBitsTerm,
    shiftBitsTerm,
    rotateBitsTerm,
    bvconcatTerm,
    bvselectTerm,
    bvextendTerm,
    bvsignExtendTerm,
    bvzeroExtendTerm,
    tabularFunApplyTerm,
    generalFunApplyTerm,
    divIntegerTerm,
    modIntegerTerm,
  )
where

import Control.DeepSeq
import Data.Array
import Data.Bits
import qualified Data.HashMap.Strict as M
import Data.Hashable
import Data.IORef (atomicModifyIORef')
import Data.Interned
import Data.Interned.Internal
import GHC.IO (unsafeDupablePerformIO)
import GHC.TypeNats
import Grisette.Core.Data.Class.BitVector
import Grisette.IR.SymPrim.Data.Prim.InternedTerm.Term
import {-# SOURCE #-} Grisette.IR.SymPrim.Data.TabularFun
import Language.Haskell.TH.Syntax
import Type.Reflection

internTerm :: forall t. (SupportedPrim t) => Uninterned (Term t) -> Term t
internTerm :: forall t. SupportedPrim t => Uninterned (Term t) -> Term t
internTerm !Uninterned (Term t)
bt = IO (Term t) -> Term t
forall a. IO a -> a
unsafeDupablePerformIO (IO (Term t) -> Term t) -> IO (Term t) -> Term t
forall a b. (a -> b) -> a -> b
$ IORef (CacheState (Term t))
-> (CacheState (Term t) -> (CacheState (Term t), Term t))
-> IO (Term t)
forall a b. IORef a -> (a -> (a, b)) -> IO b
atomicModifyIORef' IORef (CacheState (Term t))
slot CacheState (Term t) -> (CacheState (Term t), Term t)
go
  where
    slot :: IORef (CacheState (Term t))
slot = Cache (Term t) -> Array Int (IORef (CacheState (Term t)))
forall t. Cache t -> Array Int (IORef (CacheState t))
getCache Cache (Term t)
forall t. Interned t => Cache t
cache Array Int (IORef (CacheState (Term t)))
-> Int -> IORef (CacheState (Term t))
forall i e. Ix i => Array i e -> i -> e
! Int
r
    !dt :: Description (Term t)
dt = Uninterned (Term t) -> Description (Term t)
forall t. Interned t => Uninterned t -> Description t
describe Uninterned (Term t)
bt
    !hdt :: Int
hdt = Description (Term t) -> Int
forall a. Hashable a => a -> Int
hash Description (Term t)
dt
    !wid :: Int
wid = Description (Term t) -> Int
forall t (p :: * -> *). Interned t => p t -> Int
cacheWidth Description (Term t)
dt
    r :: Int
r = Int
hdt Int -> Int -> Int
forall a. Integral a => a -> a -> a
`mod` Int
wid
    go :: CacheState (Term t) -> (CacheState (Term t), Term t)
go (CacheState Int
i HashMap (Description (Term t)) (Term t)
m) = case Description (Term t)
-> HashMap (Description (Term t)) (Term t) -> Maybe (Term t)
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
M.lookup Description (Term t)
dt HashMap (Description (Term t)) (Term t)
m of
      Maybe (Term t)
Nothing -> let t :: Term t
t = Int -> Uninterned (Term t) -> Term t
forall t. Interned t => Int -> Uninterned t -> t
identify (Int
wid Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
r) Uninterned (Term t)
bt in (Int
-> HashMap (Description (Term t)) (Term t) -> CacheState (Term t)
forall t. Int -> HashMap (Description t) t -> CacheState t
CacheState (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Description (Term t)
-> Term t
-> HashMap (Description (Term t)) (Term t)
-> HashMap (Description (Term t)) (Term t)
forall k v.
(Eq k, Hashable k) =>
k -> v -> HashMap k v -> HashMap k v
M.insert Description (Term t)
dt Term t
t HashMap (Description (Term t)) (Term t)
m), Term t
t)
      Just Term t
t -> (Int
-> HashMap (Description (Term t)) (Term t) -> CacheState (Term t)
forall t. Int -> HashMap (Description t) t -> CacheState t
CacheState Int
i HashMap (Description (Term t)) (Term t)
m, Term t
t)

constructUnary ::
  forall tag arg t.
  (SupportedPrim t, UnaryOp tag arg t, Typeable tag, Typeable t, Show tag) =>
  tag ->
  Term arg ->
  Term t
constructUnary :: forall tag arg t.
(SupportedPrim t, UnaryOp tag arg t, Typeable tag, Typeable t,
 Show tag) =>
tag -> Term arg -> Term t
constructUnary tag
tag Term arg
tm = let x :: Term t
x = Uninterned (Term t) -> Term t
forall t. SupportedPrim t => Uninterned (Term t) -> Term t
internTerm (Uninterned (Term t) -> Term t) -> Uninterned (Term t) -> Term t
forall a b. (a -> b) -> a -> b
$ tag -> Term arg -> UTerm t
forall tag arg t. UnaryOp tag arg t => tag -> Term arg -> UTerm t
UUnaryTerm tag
tag Term arg
tm in Term t
x
{-# INLINE constructUnary #-}

constructBinary ::
  forall tag arg1 arg2 t.
  (SupportedPrim t, BinaryOp tag arg1 arg2 t, Typeable tag, Typeable t, Show tag) =>
  tag ->
  Term arg1 ->
  Term arg2 ->
  Term t
constructBinary :: forall tag arg1 arg2 t.
(SupportedPrim t, BinaryOp tag arg1 arg2 t, Typeable tag,
 Typeable t, Show tag) =>
tag -> Term arg1 -> Term arg2 -> Term t
constructBinary tag
tag Term arg1
tm1 Term arg2
tm2 = Uninterned (Term t) -> Term t
forall t. SupportedPrim t => Uninterned (Term t) -> Term t
internTerm (Uninterned (Term t) -> Term t) -> Uninterned (Term t) -> Term t
forall a b. (a -> b) -> a -> b
$ tag -> Term arg1 -> Term arg2 -> UTerm t
forall tag arg1 arg2 t.
BinaryOp tag arg1 arg2 t =>
tag -> Term arg1 -> Term arg2 -> UTerm t
UBinaryTerm tag
tag Term arg1
tm1 Term arg2
tm2
{-# INLINE constructBinary #-}

constructTernary ::
  forall tag arg1 arg2 arg3 t.
  (SupportedPrim t, TernaryOp tag arg1 arg2 arg3 t, Typeable tag, Typeable t, Show tag) =>
  tag ->
  Term arg1 ->
  Term arg2 ->
  Term arg3 ->
  Term t
constructTernary :: forall tag arg1 arg2 arg3 t.
(SupportedPrim t, TernaryOp tag arg1 arg2 arg3 t, Typeable tag,
 Typeable t, Show tag) =>
tag -> Term arg1 -> Term arg2 -> Term arg3 -> Term t
constructTernary tag
tag Term arg1
tm1 Term arg2
tm2 Term arg3
tm3 = Uninterned (Term t) -> Term t
forall t. SupportedPrim t => Uninterned (Term t) -> Term t
internTerm (Uninterned (Term t) -> Term t) -> Uninterned (Term t) -> Term t
forall a b. (a -> b) -> a -> b
$ tag -> Term arg1 -> Term arg2 -> Term arg3 -> UTerm t
forall tag arg1 arg2 arg3 t.
TernaryOp tag arg1 arg2 arg3 t =>
tag -> Term arg1 -> Term arg2 -> Term arg3 -> UTerm t
UTernaryTerm tag
tag Term arg1
tm1 Term arg2
tm2 Term arg3
tm3
{-# INLINE constructTernary #-}

conTerm :: (SupportedPrim t, Typeable t, Hashable t, Eq t, Show t) => t -> Term t
conTerm :: forall t.
(SupportedPrim t, Typeable t, Hashable t, Eq t, Show t) =>
t -> Term t
conTerm t
t = Uninterned (Term t) -> Term t
forall t. SupportedPrim t => Uninterned (Term t) -> Term t
internTerm (Uninterned (Term t) -> Term t) -> Uninterned (Term t) -> Term t
forall a b. (a -> b) -> a -> b
$ t -> UTerm t
forall t. SupportedPrim t => t -> UTerm t
UConTerm t
t
{-# INLINE conTerm #-}

symTerm :: forall t. (SupportedPrim t, Typeable t) => TypedSymbol t -> Term t
symTerm :: forall t. (SupportedPrim t, Typeable t) => TypedSymbol t -> Term t
symTerm TypedSymbol t
t = Uninterned (Term t) -> Term t
forall t. SupportedPrim t => Uninterned (Term t) -> Term t
internTerm (Uninterned (Term t) -> Term t) -> Uninterned (Term t) -> Term t
forall a b. (a -> b) -> a -> b
$ TypedSymbol t -> UTerm t
forall t. SupportedPrim t => TypedSymbol t -> UTerm t
USymTerm TypedSymbol t
t
{-# INLINE symTerm #-}

ssymTerm :: (SupportedPrim t, Typeable t) => String -> Term t
ssymTerm :: forall t. (SupportedPrim t, Typeable t) => String -> Term t
ssymTerm = TypedSymbol t -> Term t
forall t. (SupportedPrim t, Typeable t) => TypedSymbol t -> Term t
symTerm (TypedSymbol t -> Term t)
-> (String -> TypedSymbol t) -> String -> Term t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> TypedSymbol t
forall t. SupportedPrim t => String -> TypedSymbol t
SimpleSymbol
{-# INLINE ssymTerm #-}

isymTerm :: (SupportedPrim t, Typeable t) => String -> Int -> Term t
isymTerm :: forall t. (SupportedPrim t, Typeable t) => String -> Int -> Term t
isymTerm String
str Int
idx = TypedSymbol t -> Term t
forall t. (SupportedPrim t, Typeable t) => TypedSymbol t -> Term t
symTerm (TypedSymbol t -> Term t) -> TypedSymbol t -> Term t
forall a b. (a -> b) -> a -> b
$ String -> Int -> TypedSymbol t
forall t. SupportedPrim t => String -> Int -> TypedSymbol t
IndexedSymbol String
str Int
idx
{-# INLINE isymTerm #-}

sinfosymTerm ::
  (SupportedPrim t, Typeable t, Typeable a, Ord a, Lift a, NFData a, Show a, Hashable a) =>
  String ->
  a ->
  Term t
sinfosymTerm :: forall t a.
(SupportedPrim t, Typeable t, Typeable a, Ord a, Lift a, NFData a,
 Show a, Hashable a) =>
String -> a -> Term t
sinfosymTerm String
s a
info = TypedSymbol t -> Term t
forall t. (SupportedPrim t, Typeable t) => TypedSymbol t -> Term t
symTerm (TypedSymbol t -> Term t) -> TypedSymbol t -> Term t
forall a b. (a -> b) -> a -> b
$ TypedSymbol t -> a -> TypedSymbol t
forall t a.
(SupportedPrim t, Typeable a, Ord a, Lift a, NFData a, Show a,
 Hashable a) =>
TypedSymbol t -> a -> TypedSymbol t
WithInfo (String -> TypedSymbol t
forall t. SupportedPrim t => String -> TypedSymbol t
SimpleSymbol String
s) a
info
{-# INLINE sinfosymTerm #-}

iinfosymTerm ::
  (SupportedPrim t, Typeable t, Typeable a, Ord a, Lift a, NFData a, Show a, Hashable a) =>
  String ->
  Int ->
  a ->
  Term t
iinfosymTerm :: forall t a.
(SupportedPrim t, Typeable t, Typeable a, Ord a, Lift a, NFData a,
 Show a, Hashable a) =>
String -> Int -> a -> Term t
iinfosymTerm String
str Int
idx a
info = TypedSymbol t -> Term t
forall t. (SupportedPrim t, Typeable t) => TypedSymbol t -> Term t
symTerm (TypedSymbol t -> Term t) -> TypedSymbol t -> Term t
forall a b. (a -> b) -> a -> b
$ TypedSymbol t -> a -> TypedSymbol t
forall t a.
(SupportedPrim t, Typeable a, Ord a, Lift a, NFData a, Show a,
 Hashable a) =>
TypedSymbol t -> a -> TypedSymbol t
WithInfo (String -> Int -> TypedSymbol t
forall t. SupportedPrim t => String -> Int -> TypedSymbol t
IndexedSymbol String
str Int
idx) a
info
{-# INLINE iinfosymTerm #-}

notTerm :: Term Bool -> Term Bool
notTerm :: Term Bool -> Term Bool
notTerm = UTerm Bool -> Term Bool
forall t. SupportedPrim t => Uninterned (Term t) -> Term t
internTerm (UTerm Bool -> Term Bool)
-> (Term Bool -> UTerm Bool) -> Term Bool -> Term Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Term Bool -> UTerm Bool
UNotTerm
{-# INLINE notTerm #-}

orTerm :: Term Bool -> Term Bool -> Term Bool
orTerm :: Term Bool -> Term Bool -> Term Bool
orTerm Term Bool
l Term Bool
r = Uninterned (Term Bool) -> Term Bool
forall t. SupportedPrim t => Uninterned (Term t) -> Term t
internTerm (Uninterned (Term Bool) -> Term Bool)
-> Uninterned (Term Bool) -> Term Bool
forall a b. (a -> b) -> a -> b
$ Term Bool -> Term Bool -> UTerm Bool
UOrTerm Term Bool
l Term Bool
r
{-# INLINE orTerm #-}

andTerm :: Term Bool -> Term Bool -> Term Bool
andTerm :: Term Bool -> Term Bool -> Term Bool
andTerm Term Bool
l Term Bool
r = Uninterned (Term Bool) -> Term Bool
forall t. SupportedPrim t => Uninterned (Term t) -> Term t
internTerm (Uninterned (Term Bool) -> Term Bool)
-> Uninterned (Term Bool) -> Term Bool
forall a b. (a -> b) -> a -> b
$ Term Bool -> Term Bool -> UTerm Bool
UAndTerm Term Bool
l Term Bool
r
{-# INLINE andTerm #-}

eqvTerm :: SupportedPrim a => Term a -> Term a -> Term Bool
eqvTerm :: forall a. SupportedPrim a => Term a -> Term a -> Term Bool
eqvTerm Term a
l Term a
r = Uninterned (Term Bool) -> Term Bool
forall t. SupportedPrim t => Uninterned (Term t) -> Term t
internTerm (Uninterned (Term Bool) -> Term Bool)
-> Uninterned (Term Bool) -> Term Bool
forall a b. (a -> b) -> a -> b
$ Term a -> Term a -> UTerm Bool
forall t1. SupportedPrim t1 => Term t1 -> Term t1 -> UTerm Bool
UEqvTerm Term a
l Term a
r
{-# INLINE eqvTerm #-}

iteTerm :: SupportedPrim a => Term Bool -> Term a -> Term a -> Term a
iteTerm :: forall a.
SupportedPrim a =>
Term Bool -> Term a -> Term a -> Term a
iteTerm Term Bool
c Term a
l Term a
r = Uninterned (Term a) -> Term a
forall t. SupportedPrim t => Uninterned (Term t) -> Term t
internTerm (Uninterned (Term a) -> Term a) -> Uninterned (Term a) -> Term a
forall a b. (a -> b) -> a -> b
$ Term Bool -> Term a -> Term a -> UTerm a
forall t.
SupportedPrim t =>
Term Bool -> Term t -> Term t -> UTerm t
UITETerm Term Bool
c Term a
l Term a
r
{-# INLINE iteTerm #-}

addNumTerm :: (SupportedPrim a, Num a) => Term a -> Term a -> Term a
addNumTerm :: forall a. (SupportedPrim a, Num a) => Term a -> Term a -> Term a
addNumTerm Term a
l Term a
r = Uninterned (Term a) -> Term a
forall t. SupportedPrim t => Uninterned (Term t) -> Term t
internTerm (Uninterned (Term a) -> Term a) -> Uninterned (Term a) -> Term a
forall a b. (a -> b) -> a -> b
$ Term a -> Term a -> UTerm a
forall t. (SupportedPrim t, Num t) => Term t -> Term t -> UTerm t
UAddNumTerm Term a
l Term a
r
{-# INLINE addNumTerm #-}

uminusNumTerm :: (SupportedPrim a, Num a) => Term a -> Term a
uminusNumTerm :: forall a. (SupportedPrim a, Num a) => Term a -> Term a
uminusNumTerm = UTerm a -> Term a
forall t. SupportedPrim t => Uninterned (Term t) -> Term t
internTerm (UTerm a -> Term a) -> (Term a -> UTerm a) -> Term a -> Term a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Term a -> UTerm a
forall t. (SupportedPrim t, Num t) => Term t -> UTerm t
UUMinusNumTerm
{-# INLINE uminusNumTerm #-}

timesNumTerm :: (SupportedPrim a, Num a) => Term a -> Term a -> Term a
timesNumTerm :: forall a. (SupportedPrim a, Num a) => Term a -> Term a -> Term a
timesNumTerm Term a
l Term a
r = Uninterned (Term a) -> Term a
forall t. SupportedPrim t => Uninterned (Term t) -> Term t
internTerm (Uninterned (Term a) -> Term a) -> Uninterned (Term a) -> Term a
forall a b. (a -> b) -> a -> b
$ Term a -> Term a -> UTerm a
forall t. (SupportedPrim t, Num t) => Term t -> Term t -> UTerm t
UTimesNumTerm Term a
l Term a
r
{-# INLINE timesNumTerm #-}

absNumTerm :: (SupportedPrim a, Num a) => Term a -> Term a
absNumTerm :: forall a. (SupportedPrim a, Num a) => Term a -> Term a
absNumTerm = UTerm a -> Term a
forall t. SupportedPrim t => Uninterned (Term t) -> Term t
internTerm (UTerm a -> Term a) -> (Term a -> UTerm a) -> Term a -> Term a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Term a -> UTerm a
forall t. (SupportedPrim t, Num t) => Term t -> UTerm t
UAbsNumTerm
{-# INLINE absNumTerm #-}

signumNumTerm :: (SupportedPrim a, Num a) => Term a -> Term a
signumNumTerm :: forall a. (SupportedPrim a, Num a) => Term a -> Term a
signumNumTerm = UTerm a -> Term a
forall t. SupportedPrim t => Uninterned (Term t) -> Term t
internTerm (UTerm a -> Term a) -> (Term a -> UTerm a) -> Term a -> Term a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Term a -> UTerm a
forall t. (SupportedPrim t, Num t) => Term t -> UTerm t
USignumNumTerm
{-# INLINE signumNumTerm #-}

ltNumTerm :: (SupportedPrim a, Num a, Ord a) => Term a -> Term a -> Term Bool
ltNumTerm :: forall a.
(SupportedPrim a, Num a, Ord a) =>
Term a -> Term a -> Term Bool
ltNumTerm Term a
l Term a
r = Uninterned (Term Bool) -> Term Bool
forall t. SupportedPrim t => Uninterned (Term t) -> Term t
internTerm (Uninterned (Term Bool) -> Term Bool)
-> Uninterned (Term Bool) -> Term Bool
forall a b. (a -> b) -> a -> b
$ Term a -> Term a -> UTerm Bool
forall t1.
(SupportedPrim t1, Num t1, Ord t1) =>
Term t1 -> Term t1 -> UTerm Bool
ULTNumTerm Term a
l Term a
r
{-# INLINE ltNumTerm #-}

leNumTerm :: (SupportedPrim a, Num a, Ord a) => Term a -> Term a -> Term Bool
leNumTerm :: forall a.
(SupportedPrim a, Num a, Ord a) =>
Term a -> Term a -> Term Bool
leNumTerm Term a
l Term a
r = Uninterned (Term Bool) -> Term Bool
forall t. SupportedPrim t => Uninterned (Term t) -> Term t
internTerm (Uninterned (Term Bool) -> Term Bool)
-> Uninterned (Term Bool) -> Term Bool
forall a b. (a -> b) -> a -> b
$ Term a -> Term a -> UTerm Bool
forall t1.
(SupportedPrim t1, Num t1, Ord t1) =>
Term t1 -> Term t1 -> UTerm Bool
ULENumTerm Term a
l Term a
r
{-# INLINE leNumTerm #-}

andBitsTerm :: (SupportedPrim a, Bits a) => Term a -> Term a -> Term a
andBitsTerm :: forall a. (SupportedPrim a, Bits a) => Term a -> Term a -> Term a
andBitsTerm Term a
l Term a
r = Uninterned (Term a) -> Term a
forall t. SupportedPrim t => Uninterned (Term t) -> Term t
internTerm (Uninterned (Term a) -> Term a) -> Uninterned (Term a) -> Term a
forall a b. (a -> b) -> a -> b
$ Term a -> Term a -> UTerm a
forall t. (SupportedPrim t, Bits t) => Term t -> Term t -> UTerm t
UAndBitsTerm Term a
l Term a
r
{-# INLINE andBitsTerm #-}

orBitsTerm :: (SupportedPrim a, Bits a) => Term a -> Term a -> Term a
orBitsTerm :: forall a. (SupportedPrim a, Bits a) => Term a -> Term a -> Term a
orBitsTerm Term a
l Term a
r = Uninterned (Term a) -> Term a
forall t. SupportedPrim t => Uninterned (Term t) -> Term t
internTerm (Uninterned (Term a) -> Term a) -> Uninterned (Term a) -> Term a
forall a b. (a -> b) -> a -> b
$ Term a -> Term a -> UTerm a
forall t. (SupportedPrim t, Bits t) => Term t -> Term t -> UTerm t
UOrBitsTerm Term a
l Term a
r
{-# INLINE orBitsTerm #-}

xorBitsTerm :: (SupportedPrim a, Bits a) => Term a -> Term a -> Term a
xorBitsTerm :: forall a. (SupportedPrim a, Bits a) => Term a -> Term a -> Term a
xorBitsTerm Term a
l Term a
r = Uninterned (Term a) -> Term a
forall t. SupportedPrim t => Uninterned (Term t) -> Term t
internTerm (Uninterned (Term a) -> Term a) -> Uninterned (Term a) -> Term a
forall a b. (a -> b) -> a -> b
$ Term a -> Term a -> UTerm a
forall t. (SupportedPrim t, Bits t) => Term t -> Term t -> UTerm t
UXorBitsTerm Term a
l Term a
r
{-# INLINE xorBitsTerm #-}

complementBitsTerm :: (SupportedPrim a, Bits a) => Term a -> Term a
complementBitsTerm :: forall a. (SupportedPrim a, Bits a) => Term a -> Term a
complementBitsTerm = UTerm a -> Term a
forall t. SupportedPrim t => Uninterned (Term t) -> Term t
internTerm (UTerm a -> Term a) -> (Term a -> UTerm a) -> Term a -> Term a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Term a -> UTerm a
forall t. (SupportedPrim t, Bits t) => Term t -> UTerm t
UComplementBitsTerm
{-# INLINE complementBitsTerm #-}

shiftBitsTerm :: (SupportedPrim a, Bits a) => Term a -> Int -> Term a
shiftBitsTerm :: forall a. (SupportedPrim a, Bits a) => Term a -> Int -> Term a
shiftBitsTerm Term a
t Int
n = Uninterned (Term a) -> Term a
forall t. SupportedPrim t => Uninterned (Term t) -> Term t
internTerm (Uninterned (Term a) -> Term a) -> Uninterned (Term a) -> Term a
forall a b. (a -> b) -> a -> b
$ Term a -> Int -> UTerm a
forall t. (SupportedPrim t, Bits t) => Term t -> Int -> UTerm t
UShiftBitsTerm Term a
t Int
n
{-# INLINE shiftBitsTerm #-}

rotateBitsTerm :: (SupportedPrim a, Bits a) => Term a -> Int -> Term a
rotateBitsTerm :: forall a. (SupportedPrim a, Bits a) => Term a -> Int -> Term a
rotateBitsTerm Term a
t Int
n = Uninterned (Term a) -> Term a
forall t. SupportedPrim t => Uninterned (Term t) -> Term t
internTerm (Uninterned (Term a) -> Term a) -> Uninterned (Term a) -> Term a
forall a b. (a -> b) -> a -> b
$ Term a -> Int -> UTerm a
forall t. (SupportedPrim t, Bits t) => Term t -> Int -> UTerm t
URotateBitsTerm Term a
t Int
n
{-# INLINE rotateBitsTerm #-}

bvconcatTerm ::
  ( SupportedPrim (bv a),
    SupportedPrim (bv b),
    SupportedPrim (bv c),
    KnownNat a,
    KnownNat b,
    KnownNat c,
    BVConcat (bv a) (bv b) (bv c)
  ) =>
  Term (bv a) ->
  Term (bv b) ->
  Term (bv c)
bvconcatTerm :: forall (bv :: Nat -> *) (a :: Nat) (b :: Nat) (c :: Nat).
(SupportedPrim (bv a), SupportedPrim (bv b), SupportedPrim (bv c),
 KnownNat a, KnownNat b, KnownNat c,
 BVConcat (bv a) (bv b) (bv c)) =>
Term (bv a) -> Term (bv b) -> Term (bv c)
bvconcatTerm Term (bv a)
l Term (bv b)
r = Uninterned (Term (bv c)) -> Term (bv c)
forall t. SupportedPrim t => Uninterned (Term t) -> Term t
internTerm (Uninterned (Term (bv c)) -> Term (bv c))
-> Uninterned (Term (bv c)) -> Term (bv c)
forall a b. (a -> b) -> a -> b
$ Term (bv a) -> Term (bv b) -> UTerm (bv c)
forall (bv :: Nat -> *) (a :: Nat) (b :: Nat) (c :: Nat).
(SupportedPrim (bv a), SupportedPrim (bv b), SupportedPrim (bv c),
 KnownNat a, KnownNat b, KnownNat c,
 BVConcat (bv a) (bv b) (bv c)) =>
Term (bv a) -> Term (bv b) -> UTerm (bv c)
UBVConcatTerm Term (bv a)
l Term (bv b)
r
{-# INLINE bvconcatTerm #-}

bvselectTerm ::
  forall bv a ix w proxy.
  ( SupportedPrim (bv a),
    SupportedPrim (bv w),
    KnownNat a,
    KnownNat w,
    KnownNat ix,
    BVSelect (bv a) ix w (bv w)
  ) =>
  proxy ix ->
  proxy w ->
  Term (bv a) ->
  Term (bv w)
bvselectTerm :: forall (bv :: Nat -> *) (a :: Nat) (ix :: Nat) (w :: Nat)
       (proxy :: Nat -> *).
(SupportedPrim (bv a), SupportedPrim (bv w), KnownNat a,
 KnownNat w, KnownNat ix, BVSelect (bv a) ix w (bv w)) =>
proxy ix -> proxy w -> Term (bv a) -> Term (bv w)
bvselectTerm proxy ix
_ proxy w
_ Term (bv a)
v = Uninterned (Term (bv w)) -> Term (bv w)
forall t. SupportedPrim t => Uninterned (Term t) -> Term t
internTerm (Uninterned (Term (bv w)) -> Term (bv w))
-> Uninterned (Term (bv w)) -> Term (bv w)
forall a b. (a -> b) -> a -> b
$ TypeRep ix -> TypeRep w -> Term (bv a) -> UTerm (bv w)
forall (bv :: Nat -> *) (a :: Nat) (w :: Nat) (ix :: Nat).
(SupportedPrim (bv a), SupportedPrim (bv w), KnownNat a,
 KnownNat ix, KnownNat w, BVSelect (bv a) ix w (bv w)) =>
TypeRep ix -> TypeRep w -> Term (bv a) -> UTerm (bv w)
UBVSelectTerm (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Nat). Typeable a => TypeRep a
typeRep @ix) (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Nat). Typeable a => TypeRep a
typeRep @w) Term (bv a)
v
{-# INLINE bvselectTerm #-}

bvextendTerm ::
  forall bv a n w proxy.
  ( SupportedPrim (bv a),
    SupportedPrim (bv w),
    KnownNat a,
    KnownNat n,
    KnownNat w,
    BVExtend (bv a) n (bv w)
  ) =>
  Bool ->
  proxy n ->
  Term (bv a) ->
  Term (bv w)
bvextendTerm :: forall (bv :: Nat -> *) (a :: Nat) (n :: Nat) (w :: Nat)
       (proxy :: Nat -> *).
(SupportedPrim (bv a), SupportedPrim (bv w), KnownNat a,
 KnownNat n, KnownNat w, BVExtend (bv a) n (bv w)) =>
Bool -> proxy n -> Term (bv a) -> Term (bv w)
bvextendTerm Bool
signed proxy n
_ Term (bv a)
v = Uninterned (Term (bv w)) -> Term (bv w)
forall t. SupportedPrim t => Uninterned (Term t) -> Term t
internTerm (Uninterned (Term (bv w)) -> Term (bv w))
-> Uninterned (Term (bv w)) -> Term (bv w)
forall a b. (a -> b) -> a -> b
$ Bool -> TypeRep n -> Term (bv a) -> UTerm (bv w)
forall (bv :: Nat -> *) (a :: Nat) (b :: Nat) (n :: Nat).
(SupportedPrim (bv a), SupportedPrim (bv b), KnownNat a,
 KnownNat b, KnownNat n, BVExtend (bv a) n (bv b)) =>
Bool -> TypeRep n -> Term (bv a) -> UTerm (bv b)
UBVExtendTerm Bool
signed (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Nat). Typeable a => TypeRep a
typeRep @n) Term (bv a)
v
{-# INLINE bvextendTerm #-}

bvsignExtendTerm ::
  forall bv a n w proxy.
  ( SupportedPrim (bv a),
    SupportedPrim (bv w),
    KnownNat a,
    KnownNat n,
    KnownNat w,
    BVExtend (bv a) n (bv w)
  ) =>
  proxy n ->
  Term (bv a) ->
  Term (bv w)
bvsignExtendTerm :: forall (bv :: Nat -> *) (a :: Nat) (n :: Nat) (w :: Nat)
       (proxy :: Nat -> *).
(SupportedPrim (bv a), SupportedPrim (bv w), KnownNat a,
 KnownNat n, KnownNat w, BVExtend (bv a) n (bv w)) =>
proxy n -> Term (bv a) -> Term (bv w)
bvsignExtendTerm proxy n
_ Term (bv a)
v = Uninterned (Term (bv w)) -> Term (bv w)
forall t. SupportedPrim t => Uninterned (Term t) -> Term t
internTerm (Uninterned (Term (bv w)) -> Term (bv w))
-> Uninterned (Term (bv w)) -> Term (bv w)
forall a b. (a -> b) -> a -> b
$ Bool -> TypeRep n -> Term (bv a) -> UTerm (bv w)
forall (bv :: Nat -> *) (a :: Nat) (b :: Nat) (n :: Nat).
(SupportedPrim (bv a), SupportedPrim (bv b), KnownNat a,
 KnownNat b, KnownNat n, BVExtend (bv a) n (bv b)) =>
Bool -> TypeRep n -> Term (bv a) -> UTerm (bv b)
UBVExtendTerm Bool
True (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Nat). Typeable a => TypeRep a
typeRep @n) Term (bv a)
v
{-# INLINE bvsignExtendTerm #-}

bvzeroExtendTerm ::
  forall bv a n w proxy.
  ( SupportedPrim (bv a),
    SupportedPrim (bv w),
    KnownNat a,
    KnownNat n,
    KnownNat w,
    BVExtend (bv a) n (bv w)
  ) =>
  proxy n ->
  Term (bv a) ->
  Term (bv w)
bvzeroExtendTerm :: forall (bv :: Nat -> *) (a :: Nat) (n :: Nat) (w :: Nat)
       (proxy :: Nat -> *).
(SupportedPrim (bv a), SupportedPrim (bv w), KnownNat a,
 KnownNat n, KnownNat w, BVExtend (bv a) n (bv w)) =>
proxy n -> Term (bv a) -> Term (bv w)
bvzeroExtendTerm proxy n
_ Term (bv a)
v = Uninterned (Term (bv w)) -> Term (bv w)
forall t. SupportedPrim t => Uninterned (Term t) -> Term t
internTerm (Uninterned (Term (bv w)) -> Term (bv w))
-> Uninterned (Term (bv w)) -> Term (bv w)
forall a b. (a -> b) -> a -> b
$ Bool -> TypeRep n -> Term (bv a) -> UTerm (bv w)
forall (bv :: Nat -> *) (a :: Nat) (b :: Nat) (n :: Nat).
(SupportedPrim (bv a), SupportedPrim (bv b), KnownNat a,
 KnownNat b, KnownNat n, BVExtend (bv a) n (bv b)) =>
Bool -> TypeRep n -> Term (bv a) -> UTerm (bv b)
UBVExtendTerm Bool
False (forall {k} (a :: k). Typeable a => TypeRep a
forall (a :: Nat). Typeable a => TypeRep a
typeRep @n) Term (bv a)
v
{-# INLINE bvzeroExtendTerm #-}

tabularFunApplyTerm :: (SupportedPrim a, SupportedPrim b) => Term (a =-> b) -> Term a -> Term b
tabularFunApplyTerm :: forall a b.
(SupportedPrim a, SupportedPrim b) =>
Term (a =-> b) -> Term a -> Term b
tabularFunApplyTerm Term (a =-> b)
f Term a
a = Uninterned (Term b) -> Term b
forall t. SupportedPrim t => Uninterned (Term t) -> Term t
internTerm (Uninterned (Term b) -> Term b) -> Uninterned (Term b) -> Term b
forall a b. (a -> b) -> a -> b
$ Term (a =-> b) -> Term a -> UTerm b
forall a t.
(SupportedPrim a, SupportedPrim t) =>
Term (a =-> t) -> Term a -> UTerm t
UTabularFunApplyTerm Term (a =-> b)
f Term a
a
{-# INLINE tabularFunApplyTerm #-}

generalFunApplyTerm :: (SupportedPrim a, SupportedPrim b) => Term (a --> b) -> Term a -> Term b
generalFunApplyTerm :: forall a b.
(SupportedPrim a, SupportedPrim b) =>
Term (a --> b) -> Term a -> Term b
generalFunApplyTerm Term (a --> b)
f Term a
a = Uninterned (Term b) -> Term b
forall t. SupportedPrim t => Uninterned (Term t) -> Term t
internTerm (Uninterned (Term b) -> Term b) -> Uninterned (Term b) -> Term b
forall a b. (a -> b) -> a -> b
$ Term (a --> b) -> Term a -> UTerm b
forall a t.
(SupportedPrim a, SupportedPrim t) =>
Term (a --> t) -> Term a -> UTerm t
UGeneralFunApplyTerm Term (a --> b)
f Term a
a
{-# INLINE generalFunApplyTerm #-}

divIntegerTerm :: Term Integer -> Term Integer -> Term Integer
divIntegerTerm :: Term Integer -> Term Integer -> Term Integer
divIntegerTerm Term Integer
l Term Integer
r = Uninterned (Term Integer) -> Term Integer
forall t. SupportedPrim t => Uninterned (Term t) -> Term t
internTerm (Uninterned (Term Integer) -> Term Integer)
-> Uninterned (Term Integer) -> Term Integer
forall a b. (a -> b) -> a -> b
$ Term Integer -> Term Integer -> UTerm Integer
UDivIntegerTerm Term Integer
l Term Integer
r
{-# INLINE divIntegerTerm #-}

modIntegerTerm :: Term Integer -> Term Integer -> Term Integer
modIntegerTerm :: Term Integer -> Term Integer -> Term Integer
modIntegerTerm Term Integer
l Term Integer
r = Uninterned (Term Integer) -> Term Integer
forall t. SupportedPrim t => Uninterned (Term t) -> Term t
internTerm (Uninterned (Term Integer) -> Term Integer)
-> Uninterned (Term Integer) -> Term Integer
forall a b. (a -> b) -> a -> b
$ Term Integer -> Term Integer -> UTerm Integer
UModIntegerTerm Term Integer
l Term Integer
r
{-# INLINE modIntegerTerm #-}