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::{
|
use crate::{
|
||||||
builtins::DefaultFunction,
|
builtins::DefaultFunction,
|
||||||
debruijn::{self, Converter},
|
debruijn::{self, Converter},
|
||||||
|
flat::Binder,
|
||||||
machine::{
|
machine::{
|
||||||
cost_model::{CostModel, ExBudget},
|
cost_model::{CostModel, ExBudget},
|
||||||
Machine,
|
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.
|
/// This represents a term in Untyped Plutus Core.
|
||||||
/// We need a generic type for the different forms that a program may be in.
|
/// 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`,
|
/// Specifically, `Var` and `parameter_name` in `Lambda` can be a `Name`,
|
||||||
|
@ -69,6 +79,15 @@ pub enum Term<T> {
|
||||||
Builtin(DefaultFunction),
|
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
|
/// A container for the various constants that are available
|
||||||
/// in Untyped Plutus Core. Used in the `Constant` variant of `Term`.
|
/// in Untyped Plutus Core. Used in the `Constant` variant of `Term`.
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
|
|
@ -12,7 +12,7 @@ pub enum Error {
|
||||||
OutOfExError(ExBudget),
|
OutOfExError(ExBudget),
|
||||||
#[error("Invalid Stepkind: {0}")]
|
#[error("Invalid Stepkind: {0}")]
|
||||||
InvalidStepKind(u8),
|
InvalidStepKind(u8),
|
||||||
#[error("Cannot evaluate an open term:\n\n{0:#?}")]
|
#[error("Cannot evaluate an open term:\n\n{0}")]
|
||||||
OpenTermEvaluated(Term<NamedDeBruijn>),
|
OpenTermEvaluated(Term<NamedDeBruijn>),
|
||||||
#[error("The provided Plutus code called 'error'.")]
|
#[error("The provided Plutus code called 'error'.")]
|
||||||
EvaluationFailure,
|
EvaluationFailure,
|
||||||
|
@ -22,9 +22,9 @@ pub enum Error {
|
||||||
NonFunctionalApplication(Value),
|
NonFunctionalApplication(Value),
|
||||||
#[error("Type mismatch expected '{0}' got '{1}'")]
|
#[error("Type mismatch expected '{0}' got '{1}'")]
|
||||||
TypeMismatch(Type, Type),
|
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>),
|
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>),
|
BuiltinTermArgumentExpected(Term<NamedDeBruijn>),
|
||||||
#[error("Unable to unlift value because it is not a constant:\n\n{0:#?}")]
|
#[error("Unable to unlift value because it is not a constant:\n\n{0:#?}")]
|
||||||
NotAConstant(Value),
|
NotAConstant(Value),
|
||||||
|
|
Loading…
Reference in New Issue