feat: impl display for Program and Term where T: Binder
This commit is contained in:
parent
e70881c27c
commit
198dae7f5d
|
@ -3,6 +3,7 @@ use std::fmt::Display;
|
|||
use crate::{
|
||||
builtins::DefaultFunction,
|
||||
debruijn::{self, Converter},
|
||||
flat::Binder,
|
||||
machine::{
|
||||
cost_model::{CostModel, ExBudget},
|
||||
Machine,
|
||||
|
@ -38,6 +39,15 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, T> Display for Program<T>
|
||||
where
|
||||
T: Binder<'a>,
|
||||
{
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", self.to_pretty())
|
||||
}
|
||||
}
|
||||
|
||||
/// This represents a term in Untyped Plutus Core.
|
||||
/// We need a generic type for the different forms that a program may be in.
|
||||
/// Specifically, `Var` and `parameter_name` in `Lambda` can be a `Name`,
|
||||
|
@ -69,6 +79,15 @@ pub enum Term<T> {
|
|||
Builtin(DefaultFunction),
|
||||
}
|
||||
|
||||
impl<'a, T> Display for Term<T>
|
||||
where
|
||||
T: Binder<'a>,
|
||||
{
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", self.to_pretty())
|
||||
}
|
||||
}
|
||||
|
||||
/// A container for the various constants that are available
|
||||
/// in Untyped Plutus Core. Used in the `Constant` variant of `Term`.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
|
|
@ -12,7 +12,7 @@ pub enum Error {
|
|||
OutOfExError(ExBudget),
|
||||
#[error("Invalid Stepkind: {0}")]
|
||||
InvalidStepKind(u8),
|
||||
#[error("Cannot evaluate an open term:\n\n{0:#?}")]
|
||||
#[error("Cannot evaluate an open term:\n\n{0}")]
|
||||
OpenTermEvaluated(Term<NamedDeBruijn>),
|
||||
#[error("The provided Plutus code called 'error'.")]
|
||||
EvaluationFailure,
|
||||
|
@ -22,9 +22,9 @@ pub enum Error {
|
|||
NonFunctionalApplication(Value),
|
||||
#[error("Type mismatch expected '{0}' got '{1}'")]
|
||||
TypeMismatch(Type, Type),
|
||||
#[error("A builtin received a term argument when something else was expected:\n\n{}\n\nYou probably forgot to wrap the builtin with a force.", .0.to_pretty())]
|
||||
#[error("A builtin received a term argument when something else was expected:\n\n{0}\n\nYou probably forgot to wrap the builtin with a force.")]
|
||||
UnexpectedBuiltinTermArgument(Term<NamedDeBruijn>),
|
||||
#[error("A builtin expected a term argument, but something else was received:\n\n{}\n\nYou probably have an extra force wrapped around a builtin", .0.to_pretty())]
|
||||
#[error("A builtin expected a term argument, but something else was received:\n\n{0}\n\nYou probably have an extra force wrapped around a builtin")]
|
||||
BuiltinTermArgumentExpected(Term<NamedDeBruijn>),
|
||||
#[error("Unable to unlift value because it is not a constant:\n\n{0:#?}")]
|
||||
NotAConstant(Value),
|
||||
|
|
Loading…
Reference in New Issue