morley-1.19.1: Developer tools for the Michelson Language
Safe HaskellSafe-Inferred
LanguageHaskell2010

Morley.Michelson.Interpret

Description

Module, containing function to interpret Michelson instructions against given context and input stack.

Synopsis

Documentation

data ContractEnv' m Source #

Environment for contract execution. Parametrized by the execution monad, i.e. EvalOp by default, but downstream consumers may define their own if using low-level runners.

Constructors

ContractEnv 

Fields

Instances

Instances details
MonadReader ContractEnv EvalOp Source # 
Instance details

Defined in Morley.Michelson.Interpret

data InterpreterState Source #

Instances

Instances details
Generic InterpreterState Source # 
Instance details

Defined in Morley.Michelson.Interpret

Associated Types

type Rep InterpreterState :: Type -> Type #

Show InterpreterState Source # 
Instance details

Defined in Morley.Michelson.Interpret

NFData InterpreterState Source # 
Instance details

Defined in Morley.Michelson.Interpret

Methods

rnf :: InterpreterState -> () #

MonadState InterpreterState EvalOp Source # 
Instance details

Defined in Morley.Michelson.Interpret

Monad m => InterpreterStateMonad (StateT InterpreterState m) Source # 
Instance details

Defined in Morley.Michelson.Interpret

(Monad m, Monoid w) => InterpreterStateMonad (RWST r w InterpreterState m) Source # 
Instance details

Defined in Morley.Michelson.Interpret

type Rep InterpreterState Source # 
Instance details

Defined in Morley.Michelson.Interpret

type Rep InterpreterState = D1 ('MetaData "InterpreterState" "Morley.Michelson.Interpret" "morley-1.19.1-inplace" 'False) (C1 ('MetaCons "InterpreterState" 'PrefixI 'True) (S1 ('MetaSel ('Just "isRemainingSteps") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 RemainingSteps) :*: (S1 ('MetaSel ('Just "isGlobalCounter") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 GlobalCounter) :*: S1 ('MetaSel ('Just "isBigMapCounter") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 BigMapCounter))))

data MichelsonFailed ext where Source #

Errors that can be thrown by the interpreter. The ext type variable allow the downstreams consumer to add additional exceptions.

Constructors

MichelsonFailedWith 

Fields

MichelsonArithError :: (Typeable n, Typeable m) => ArithError (Value n) (Value m) -> MichelsonFailed ext 
MichelsonGasExhaustion :: MichelsonFailed ext 
MichelsonFailedTestAssert :: Text -> MichelsonFailed ext 
MichelsonUnsupported :: Text -> MichelsonFailed ext 
MichelsonExt :: ext -> MichelsonFailed ext 

Instances

Instances details
Show ext => Show (MichelsonFailed ext) Source # 
Instance details

Defined in Morley.Michelson.Interpret

NFData ext => NFData (MichelsonFailed ext) Source # 
Instance details

Defined in Morley.Michelson.Interpret

Methods

rnf :: MichelsonFailed ext -> () #

Buildable ext => Buildable (MichelsonFailed ext) Source # 
Instance details

Defined in Morley.Michelson.Interpret

Methods

build :: MichelsonFailed ext -> Builder #

Eq ext => Eq (MichelsonFailed ext) Source # 
Instance details

Defined in Morley.Michelson.Interpret

data MichelsonFailureWithStack ext Source #

Carries a MichelsonFailed ext error and the ErrorSrcPos at which it was raised

Instances

Instances details
Generic (MichelsonFailureWithStack ext) Source # 
Instance details

Defined in Morley.Michelson.Interpret

Associated Types

type Rep (MichelsonFailureWithStack ext) :: Type -> Type #

Show ext => Show (MichelsonFailureWithStack ext) Source # 
Instance details

Defined in Morley.Michelson.Interpret

NFData ext => NFData (MichelsonFailureWithStack ext) Source # 
Instance details

Defined in Morley.Michelson.Interpret

Methods

rnf :: MichelsonFailureWithStack ext -> () #

Buildable ext => Buildable (MichelsonFailureWithStack ext) Source # 
Instance details

Defined in Morley.Michelson.Interpret

Eq ext => Eq (MichelsonFailureWithStack ext) Source # 
Instance details

Defined in Morley.Michelson.Interpret

MonadError (MichelsonFailureWithStack Void) EvalOp Source # 
Instance details

Defined in Morley.Michelson.Interpret

type Rep (MichelsonFailureWithStack ext) Source # 
Instance details

Defined in Morley.Michelson.Interpret

type Rep (MichelsonFailureWithStack ext) = D1 ('MetaData "MichelsonFailureWithStack" "Morley.Michelson.Interpret" "morley-1.19.1-inplace" 'False) (C1 ('MetaCons "MichelsonFailureWithStack" 'PrefixI 'True) (S1 ('MetaSel ('Just "mfwsFailed") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (MichelsonFailed ext)) :*: S1 ('MetaSel ('Just "mfwsErrorSrcPos") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 ErrorSrcPos)))

newtype RemainingSteps Source #

Constructors

RemainingSteps Word64 

Instances

Instances details
Generic RemainingSteps Source # 
Instance details

Defined in Morley.Michelson.Interpret

Associated Types

type Rep RemainingSteps :: Type -> Type #

Num RemainingSteps Source # 
Instance details

Defined in Morley.Michelson.Interpret

Show RemainingSteps Source # 
Instance details

Defined in Morley.Michelson.Interpret

NFData RemainingSteps Source # 
Instance details

Defined in Morley.Michelson.Interpret

Methods

rnf :: RemainingSteps -> () #

Buildable RemainingSteps Source # 
Instance details

Defined in Morley.Michelson.Interpret

Eq RemainingSteps Source # 
Instance details

Defined in Morley.Michelson.Interpret

Ord RemainingSteps Source # 
Instance details

Defined in Morley.Michelson.Interpret

type Rep RemainingSteps Source # 
Instance details

Defined in Morley.Michelson.Interpret

type Rep RemainingSteps = D1 ('MetaData "RemainingSteps" "Morley.Michelson.Interpret" "morley-1.19.1-inplace" 'True) (C1 ('MetaCons "RemainingSteps" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word64)))

data SomeItStack where Source #

Constructors

SomeItStack :: ExtInstr inp -> Rec StkEl inp -> SomeItStack 

newtype MorleyLogs Source #

Morley logs appearing as interpreter result.

Constructors

MorleyLogs 

Fields

Instances

Instances details
Monoid MorleyLogs Source # 
Instance details

Defined in Morley.Michelson.Interpret

Semigroup MorleyLogs Source # 
Instance details

Defined in Morley.Michelson.Interpret

Generic MorleyLogs Source # 
Instance details

Defined in Morley.Michelson.Interpret

Associated Types

type Rep MorleyLogs :: Type -> Type #

Show MorleyLogs Source # 
Instance details

Defined in Morley.Michelson.Interpret

NFData MorleyLogs Source # 
Instance details

Defined in Morley.Michelson.Interpret

Methods

rnf :: MorleyLogs -> () #

Buildable MorleyLogs Source # 
Instance details

Defined in Morley.Michelson.Interpret

Methods

build :: MorleyLogs -> Builder #

Eq MorleyLogs Source # 
Instance details

Defined in Morley.Michelson.Interpret

type Rep MorleyLogs Source # 
Instance details

Defined in Morley.Michelson.Interpret

type Rep MorleyLogs = D1 ('MetaData "MorleyLogs" "Morley.Michelson.Interpret" "morley-1.19.1-inplace" 'True) (C1 ('MetaCons "MorleyLogs" 'PrefixI 'True) (S1 ('MetaSel ('Just "unMorleyLogs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Text])))

newtype MorleyLogsBuilder Source #

Morley logs accumulator, for incremental building.

Constructors

MorleyLogsBuilder (Endo [Text]) 

Instances

Instances details
Monoid MorleyLogsBuilder Source # 
Instance details

Defined in Morley.Michelson.Interpret

Semigroup MorleyLogsBuilder Source # 
Instance details

Defined in Morley.Michelson.Interpret

Generic MorleyLogsBuilder Source # 
Instance details

Defined in Morley.Michelson.Interpret

Associated Types

type Rep MorleyLogsBuilder :: Type -> Type #

Default MorleyLogsBuilder Source # 
Instance details

Defined in Morley.Michelson.Interpret

One MorleyLogsBuilder Source # 
Instance details

Defined in Morley.Michelson.Interpret

Associated Types

type OneItem MorleyLogsBuilder #

MonadWriter MorleyLogsBuilder EvalOp Source # 
Instance details

Defined in Morley.Michelson.Interpret

type Rep MorleyLogsBuilder Source # 
Instance details

Defined in Morley.Michelson.Interpret

type Rep MorleyLogsBuilder = D1 ('MetaData "MorleyLogsBuilder" "Morley.Michelson.Interpret" "morley-1.19.1-inplace" 'True) (C1 ('MetaCons "MorleyLogsBuilder" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Endo [Text]))))
type OneItem MorleyLogsBuilder Source # 
Instance details

Defined in Morley.Michelson.Interpret

interpretInstr :: ContractEnv -> Instr inp out -> Rec Value inp -> Either (MichelsonFailureWithStack Void) (Rec Value out) Source #

Interpret an instruction in vacuum, putting no extra constraints on its execution.

Mostly for testing purposes.

interpretInstrAnnotated :: ContractEnv -> Instr inp out -> Rec Value inp -> Either (MichelsonFailureWithStack Void) (Rec StkEl out) Source #

Interpret an instruction in vacuum, putting no extra constraints on its execution while preserving its annotations.

Mostly for testing purposes.

type InterpretReturn ty = RunEvalOpReturn (Value ty) Source #

Result of interpretView. A version of RunEvalOpReturn specialized to Value.

type ContractReturn st = InterpretReturn (ContractOut1 st) Source #

Result of interpret. A version of InterpretReturn specialized to ContractOut1.

type RunEvalOpReturn a = ResultStateLogs (Either (MichelsonFailureWithStack Void) a) Source #

Result of runEvalOp. Essentially, return value (possibly failing), state and logs.

data ResultStateLogs res Source #

Instances

Instances details
Foldable ResultStateLogs Source # 
Instance details

Defined in Morley.Michelson.Interpret

Methods

fold :: Monoid m => ResultStateLogs m -> m #

foldMap :: Monoid m => (a -> m) -> ResultStateLogs a -> m #

foldMap' :: Monoid m => (a -> m) -> ResultStateLogs a -> m #

foldr :: (a -> b -> b) -> b -> ResultStateLogs a -> b #

foldr' :: (a -> b -> b) -> b -> ResultStateLogs a -> b #

foldl :: (b -> a -> b) -> b -> ResultStateLogs a -> b #

foldl' :: (b -> a -> b) -> b -> ResultStateLogs a -> b #

foldr1 :: (a -> a -> a) -> ResultStateLogs a -> a #

foldl1 :: (a -> a -> a) -> ResultStateLogs a -> a #

toList :: ResultStateLogs a -> [a] #

null :: ResultStateLogs a -> Bool #

length :: ResultStateLogs a -> Int #

elem :: Eq a => a -> ResultStateLogs a -> Bool #

maximum :: Ord a => ResultStateLogs a -> a #

minimum :: Ord a => ResultStateLogs a -> a #

sum :: Num a => ResultStateLogs a -> a #

product :: Num a => ResultStateLogs a -> a #

Traversable ResultStateLogs Source # 
Instance details

Defined in Morley.Michelson.Interpret

Methods

traverse :: Applicative f => (a -> f b) -> ResultStateLogs a -> f (ResultStateLogs b) #

sequenceA :: Applicative f => ResultStateLogs (f a) -> f (ResultStateLogs a) #

mapM :: Monad m => (a -> m b) -> ResultStateLogs a -> m (ResultStateLogs b) #

sequence :: Monad m => ResultStateLogs (m a) -> m (ResultStateLogs a) #

Functor ResultStateLogs Source # 
Instance details

Defined in Morley.Michelson.Interpret

Methods

fmap :: (a -> b) -> ResultStateLogs a -> ResultStateLogs b #

(<$) :: a -> ResultStateLogs b -> ResultStateLogs a #

Generic (ResultStateLogs res) Source # 
Instance details

Defined in Morley.Michelson.Interpret

Associated Types

type Rep (ResultStateLogs res) :: Type -> Type #

Methods

from :: ResultStateLogs res -> Rep (ResultStateLogs res) x #

to :: Rep (ResultStateLogs res) x -> ResultStateLogs res #

Show res => Show (ResultStateLogs res) Source # 
Instance details

Defined in Morley.Michelson.Interpret

NFData res => NFData (ResultStateLogs res) Source # 
Instance details

Defined in Morley.Michelson.Interpret

Methods

rnf :: ResultStateLogs res -> () #

type Rep (ResultStateLogs res) Source # 
Instance details

Defined in Morley.Michelson.Interpret

type Rep (ResultStateLogs res) = D1 ('MetaData "ResultStateLogs" "Morley.Michelson.Interpret" "morley-1.19.1-inplace" 'False) (C1 ('MetaCons "ResultStateLogs" 'PrefixI 'True) (S1 ('MetaSel ('Just "rslResult") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 res) :*: (S1 ('MetaSel ('Just "rslState") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 InterpreterState) :*: S1 ('MetaSel ('Just "rslLogs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 MorleyLogs))))

mkInitStack :: Value param -> Value st -> Rec StkEl (ContractInp param st) Source #

data InterpretError ext Source #

Instances

Instances details
Generic (InterpretError ext) Source # 
Instance details

Defined in Morley.Michelson.Interpret

Associated Types

type Rep (InterpretError ext) :: Type -> Type #

Methods

from :: InterpretError ext -> Rep (InterpretError ext) x #

to :: Rep (InterpretError ext) x -> InterpretError ext #

Show ext => Show (InterpretError ext) Source # 
Instance details

Defined in Morley.Michelson.Interpret

Buildable ext => Buildable (InterpretError ext) Source # 
Instance details

Defined in Morley.Michelson.Interpret

Methods

build :: InterpretError ext -> Builder #

type Rep (InterpretError ext) Source # 
Instance details

Defined in Morley.Michelson.Interpret

type Rep (InterpretError ext) = D1 ('MetaData "InterpretError" "Morley.Michelson.Interpret" "morley-1.19.1-inplace" 'False) (C1 ('MetaCons "InterpretError" 'PrefixI 'True) (S1 ('MetaSel ('Just "ieLogs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 MorleyLogs) :*: S1 ('MetaSel ('Just "ieFailure") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (MichelsonFailureWithStack ext))))

type InterpretResult ty = ResultStateLogs (Value ty) Source #

Pure result of an interpretation, i.e. return value, final interpreter state and execution logs.

type ContractResult ty = InterpretResult (ContractOut1 ty) Source #

Pure result of contract interpretation. A specialized version of InterpretResult.

extractValOps :: Value (ContractOut1 st) -> ([Operation], Value st) Source #

Extract list of operations from ContractOut1 Value.

type EvalM m = EvalM' Void m Source #

class Monad m => InterpreterStateMonad m where Source #

Minimal complete definition

Nothing

Instances

Instances details
InterpreterStateMonad EvalOp Source # 
Instance details

Defined in Morley.Michelson.Interpret

InterpreterStateMonad m => InterpreterStateMonad (ExceptT e m) Source # 
Instance details

Defined in Morley.Michelson.Interpret

InterpreterStateMonad m => InterpreterStateMonad (ReaderT r m) Source # 
Instance details

Defined in Morley.Michelson.Interpret

Monad m => InterpreterStateMonad (StateT InterpreterState m) Source # 
Instance details

Defined in Morley.Michelson.Interpret

InterpreterStateMonad m => InterpreterStateMonad (StateT w m) Source # 
Instance details

Defined in Morley.Michelson.Interpret

(InterpreterStateMonad m, Monoid w) => InterpreterStateMonad (WriterT w m) Source # 
Instance details

Defined in Morley.Michelson.Interpret

(Monad m, Monoid w) => InterpreterStateMonad (RWST r w InterpreterState m) Source # 
Instance details

Defined in Morley.Michelson.Interpret

(InterpreterStateMonad m, Monoid w) => InterpreterStateMonad (RWST r w s m) Source # 
Instance details

Defined in Morley.Michelson.Interpret

newtype StkEl t Source #

Constructors

StkEl 

Fields

Instances

Instances details
Show (StkEl t) Source # 
Instance details

Defined in Morley.Michelson.Interpret

Methods

showsPrec :: Int -> StkEl t -> ShowS #

show :: StkEl t -> String #

showList :: [StkEl t] -> ShowS #

Eq (StkEl t) Source # 
Instance details

Defined in Morley.Michelson.Interpret

Methods

(==) :: StkEl t -> StkEl t -> Bool #

(/=) :: StkEl t -> StkEl t -> Bool #

type InstrRunner m = forall inp out. Instr inp out -> Rec StkEl inp -> m (Rec StkEl out) Source #

runInstr :: EvalM' ext m => InstrRunner m Source #

Function to change amount of remaining steps stored in State monad.

runUnpack :: forall t. UnpackedValScope t => ByteString -> Either UnpackError (Value t) Source #

Unpacks given raw data into a typed value.

Views

interpretView :: View arg st ret -> Value st -> Value arg -> ContractEnv -> InterpreterState -> InterpretReturn ret Source #

Interpret a contract's view for given ContractEnv and initial InterpreterState. It is assumed ContractEnv is suitable for the view call, that is, the view is executed exactly in the env that's passed here.

getViewByName :: Contract cp st -> ViewName -> Either ViewLookupError (SomeView st) Source #

Attempt to find a view with a given name in a given contract.

getViewByNameAndType :: forall arg ret cp st. (SingI arg, SingI ret) => Contract cp st -> ViewName -> Either ViewLookupError (View arg st ret) Source #

Attempt to find a view with a given name and given type in a given contract.

Internals

handleReturn :: InterpretReturn res -> Either (InterpretError Void) (ResultStateLogs (Value res)) Source #

On failure, attach logs to failure, but throw away the final state.

runInstrImpl :: forall ext m. EvalM' ext m => InstrRunner m -> InstrRunner m Source #

Function to interpret Michelson instruction(s) against given stack. The ext type variable specifies additional exceptions that can be thrown from the inner runner function (via MichelsonExt). In Morley, it's set to Void, but downstream consumers may use other type here.

assignBigMapIds Source #

Arguments

:: MonadState BigMapCounter m 
=> Bool

If true, assign a new ID even if the bigmap already has one. Otherwise, assign IDs only to bigmaps that don't have one yet.

-> Value t 
-> m (Value t) 

All big_maps stored in a chain have a globally unique ID.

We use this function to assign a new ID whenever a big_map is created.

interpretView' :: forall ret st m arg ext. EvalM' ext m => (forall inp out. Instr inp out -> Rec StkEl inp -> m (Rec StkEl out)) -> (ContractEnv' m -> ContractEnv' m) -> View arg st ret -> Value st -> Value arg -> m (Value ret) Source #

EvalM view interpretation helper.

newtype EvalOp a Source #

The main interpreter monad. Downstream consumers which use runInstrImpl directly may define their own monad similar to this one.

This is a newtype and not a type synonym due to the reader environment, i.e. ContractEnv, being parameterized by this monad.

Instances

Instances details
Applicative EvalOp Source # 
Instance details

Defined in Morley.Michelson.Interpret

Methods

pure :: a -> EvalOp a #

(<*>) :: EvalOp (a -> b) -> EvalOp a -> EvalOp b #

liftA2 :: (a -> b -> c) -> EvalOp a -> EvalOp b -> EvalOp c #

(*>) :: EvalOp a -> EvalOp b -> EvalOp b #

(<*) :: EvalOp a -> EvalOp b -> EvalOp a #

Functor EvalOp Source # 
Instance details

Defined in Morley.Michelson.Interpret

Methods

fmap :: (a -> b) -> EvalOp a -> EvalOp b #

(<$) :: a -> EvalOp b -> EvalOp a #

Monad EvalOp Source # 
Instance details

Defined in Morley.Michelson.Interpret

Methods

(>>=) :: EvalOp a -> (a -> EvalOp b) -> EvalOp b #

(>>) :: EvalOp a -> EvalOp b -> EvalOp b #

return :: a -> EvalOp a #

InterpreterStateMonad EvalOp Source # 
Instance details

Defined in Morley.Michelson.Interpret

MonadReader ContractEnv EvalOp Source # 
Instance details

Defined in Morley.Michelson.Interpret

MonadState InterpreterState EvalOp Source # 
Instance details

Defined in Morley.Michelson.Interpret

MonadWriter MorleyLogsBuilder EvalOp Source # 
Instance details

Defined in Morley.Michelson.Interpret

MonadError (MichelsonFailureWithStack Void) EvalOp Source # 
Instance details

Defined in Morley.Michelson.Interpret

Prisms