plutarch-1.9.0
Safe HaskellSafe-Inferred
LanguageGHC2021

Plutarch.Evaluate

Synopsis

Documentation

evalScript :: Script -> (Either EvalError Script, ExBudget, [Text]) Source #

Evaluate a script with a big budget, returning the trace log and term result.

evalScriptHuge :: Script -> (Either EvalError Script, ExBudget, [Text]) Source #

Evaluate a script with a huge budget, returning the trace log and term result.

evalScript' :: ExBudget -> Script -> (Either (CekEvaluationException NamedDeBruijn DefaultUni DefaultFun) Script, ExBudget, [Text]) Source #

Evaluate a script with a specific budget, returning the trace log and term result.

evalScriptUnlimited :: Script -> (Either (CekEvaluationException NamedDeBruijn DefaultUni DefaultFun) Script, ExBudget, [Text]) Source #

Evaluate a script without budget limit

@since WIP

type EvalError = CekEvaluationException NamedDeBruijn DefaultUni DefaultFun Source #

evalTerm :: Config -> ClosedTerm a -> Either Text (Either EvalError (ClosedTerm a), ExBudget, [Text]) Source #

Compile and evaluate term.

unsafeEvalTerm :: Config -> ClosedTerm a -> ClosedTerm a Source #

Compile and evaluate a ClosedTerm Useful for pre-evaluating terms so that they can be used as constants in an onchain script. Consider the following: _________________________________________________________________________ term :: Term _ PInteger term = unsafeEvalTerm NoTracing foo

foo :: Term s PInteger foo = (pconstant 1 #+ pconstant 5) #* pconstant 3

bar :: Term s (PInteger :--> PInteger) bar = plam x -> x + foo

bar2 :: Term s (PInteger :--> PInteger) bar2 = plam x -> x + term

PI.compile PI.NoTracing bar Right (Script {unScript = Program {_progAnn = (), _progVer = Version {_versionMajor = 1, _versionMinor = 0, _versionPatch = 0}, _progTerm = LamAbs () (DeBruijn {dbnIndex = 0}) (Apply () (Apply () (Builtin () AddInteger) (Var () (DeBruijn {dbnIndex = 1}))) (Apply () (Apply () (Builtin () MultiplyInteger) (Apply () (Apply () (Builtin () AddInteger) (Constant () (Some (ValueOf DefaultUniInteger 1)))) (Constant () (Some (ValueOf DefaultUniInteger 5))))) (Constant () (Some (ValueOf DefaultUniInteger 3)))))}}) PI.compile PI.NoTracing bar2 Right (Script {unScript = Program {_progAnn = (), _progVer = Version {_versionMajor = 1, _versionMinor = 0, _versionPatch = 0}, _progTerm = LamAbs () (DeBruijn {dbnIndex = 0}) (Apply () (Apply () (Builtin () AddInteger) (Var () (DeBruijn {dbnIndex = 1}))) (Constant () (Some (ValueOf DefaultUniInteger 18))))}}) _________________________________________________________________________

In bar, foo is an unevaluated term and thus must be evaluated. In bar2, foo has been pre-evaluated with unsafeEvalTerm and thus appears as a constant.

Error if the compilation or evaluation fails.

applyArguments :: Script -> [Data] -> Script Source #

Given a compiled Script representing a function that takes arguments, and a list of those Data-encoded arguments, produce a new script with those arguments applied.

Since: 1.8.1