{-# LANGUAGE CPP #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE StrictData #-}
module PlutusCore.Builtin.Runtime where
import PlutusPrelude
import PlutusCore.Builtin.KnownType
import PlutusCore.Evaluation.Machine.ExBudgetStream
import Control.DeepSeq
import Control.Monad.Except (throwError)
import NoThunks.Class
data BuiltinRuntime val
= BuiltinCostedResult ExBudgetStream ~(BuiltinResult val)
| BuiltinExpectArgument (val -> BuiltinRuntime val)
| BuiltinExpectForce (BuiltinRuntime val)
instance NoThunks (BuiltinRuntime val) where
wNoThunks :: Context -> BuiltinRuntime val -> IO (Maybe ThunkInfo)
wNoThunks Context
ctx = \case
#if MIN_VERSION_nothunks(0,2,0)
BuiltinCostedResult ExBudgetStream
_ BuiltinResult val
_ -> Maybe ThunkInfo -> IO (Maybe ThunkInfo)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe ThunkInfo -> IO (Maybe ThunkInfo))
-> (Either Context String -> Maybe ThunkInfo)
-> Either Context String
-> IO (Maybe ThunkInfo)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ThunkInfo -> Maybe ThunkInfo
forall a. a -> Maybe a
Just (ThunkInfo -> Maybe ThunkInfo)
-> (Either Context String -> ThunkInfo)
-> Either Context String
-> Maybe ThunkInfo
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Either Context String -> ThunkInfo
ThunkInfo (Either Context String -> IO (Maybe ThunkInfo))
-> Either Context String -> IO (Maybe ThunkInfo)
forall a b. (a -> b) -> a -> b
$ Context -> Either Context String
forall a b. a -> Either a b
Left Context
ctx
#else
BuiltinCostedResult _ _ -> pure . Just $ ThunkInfo ctx
#endif
BuiltinExpectArgument val -> BuiltinRuntime val
f -> Context -> (val -> BuiltinRuntime val) -> IO (Maybe ThunkInfo)
forall a. NoThunks a => Context -> a -> IO (Maybe ThunkInfo)
noThunks Context
ctx val -> BuiltinRuntime val
f
BuiltinExpectForce BuiltinRuntime val
runtime -> Context -> BuiltinRuntime val -> IO (Maybe ThunkInfo)
forall a. NoThunks a => Context -> a -> IO (Maybe ThunkInfo)
noThunks Context
ctx BuiltinRuntime val
runtime
showTypeOf :: Proxy (BuiltinRuntime val) -> String
showTypeOf = String -> Proxy (BuiltinRuntime val) -> String
forall a b. a -> b -> a
const String
"PlutusCore.Builtin.Runtime.BuiltinRuntime"
instance NFData (BuiltinRuntime val) where
rnf :: BuiltinRuntime val -> ()
rnf = BuiltinRuntime val -> ()
forall a. a -> ()
rwhnf
data BuiltinsRuntime fun val = BuiltinsRuntime
{ forall fun val.
BuiltinsRuntime fun val -> fun -> BuiltinRuntime val
unBuiltinsRuntime :: fun -> BuiltinRuntime val
}
instance (Bounded fun, Enum fun) => NFData (BuiltinsRuntime fun val) where
rnf :: BuiltinsRuntime fun val -> ()
rnf (BuiltinsRuntime fun -> BuiltinRuntime val
env) = (fun -> () -> ()) -> () -> [fun] -> ()
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\fun
fun ()
res -> fun -> BuiltinRuntime val
env fun
fun BuiltinRuntime val -> () -> ()
forall a b. a -> b -> b
`seq` ()
res) () [fun]
forall a. (Enum a, Bounded a) => [a]
enumerate
instance (Bounded fun, Enum fun) => NoThunks (BuiltinsRuntime fun val) where
wNoThunks :: Context -> BuiltinsRuntime fun val -> IO (Maybe ThunkInfo)
wNoThunks Context
ctx (BuiltinsRuntime fun -> BuiltinRuntime val
env) = [IO (Maybe ThunkInfo)] -> IO (Maybe ThunkInfo)
allNoThunks ([IO (Maybe ThunkInfo)] -> IO (Maybe ThunkInfo))
-> [IO (Maybe ThunkInfo)] -> IO (Maybe ThunkInfo)
forall a b. (a -> b) -> a -> b
$ (fun -> IO (Maybe ThunkInfo)) -> [fun] -> [IO (Maybe ThunkInfo)]
forall a b. (a -> b) -> [a] -> [b]
map (Context -> BuiltinRuntime val -> IO (Maybe ThunkInfo)
forall a. NoThunks a => Context -> a -> IO (Maybe ThunkInfo)
wNoThunks Context
ctx (BuiltinRuntime val -> IO (Maybe ThunkInfo))
-> (fun -> BuiltinRuntime val) -> fun -> IO (Maybe ThunkInfo)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. fun -> BuiltinRuntime val
env) [fun]
forall a. (Enum a, Bounded a) => [a]
enumerate
showTypeOf :: Proxy (BuiltinsRuntime fun val) -> String
showTypeOf = String -> Proxy (BuiltinsRuntime fun val) -> String
forall a b. a -> b -> a
const String
"PlutusCore.Builtin.Runtime.BuiltinsRuntime"
builtinRuntimeFailure :: BuiltinError -> BuiltinRuntime val
builtinRuntimeFailure :: forall val. BuiltinError -> BuiltinRuntime val
builtinRuntimeFailure = ExBudgetStream -> BuiltinResult val -> BuiltinRuntime val
forall val.
ExBudgetStream -> BuiltinResult val -> BuiltinRuntime val
BuiltinCostedResult (ExBudget -> ExBudgetStream
ExBudgetLast ExBudget
forall a. Monoid a => a
mempty) (BuiltinResult val -> BuiltinRuntime val)
-> (BuiltinError -> BuiltinResult val)
-> BuiltinError
-> BuiltinRuntime val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BuiltinError -> BuiltinResult val
forall a. BuiltinError -> BuiltinResult a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError
{-# OPAQUE builtinRuntimeFailure #-}
lookupBuiltin :: fun -> BuiltinsRuntime fun val -> BuiltinRuntime val
lookupBuiltin :: forall fun val.
fun -> BuiltinsRuntime fun val -> BuiltinRuntime val
lookupBuiltin fun
fun (BuiltinsRuntime fun -> BuiltinRuntime val
env) = fun -> BuiltinRuntime val
env fun
fun
{-# INLINE lookupBuiltin #-}