From 198dae7f5d1b059d166b7878cd99089aae107b82 Mon Sep 17 00:00:00 2001 From: rvcas Date: Wed, 3 Aug 2022 21:59:57 -0400 Subject: [PATCH] feat: impl display for Program and Term where T: Binder --- crates/uplc/src/ast.rs | 19 +++++++++++++++++++ crates/uplc/src/machine/error.rs | 6 +++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/crates/uplc/src/ast.rs b/crates/uplc/src/ast.rs index b83dc1fd..5f64d602 100644 --- a/crates/uplc/src/ast.rs +++ b/crates/uplc/src/ast.rs @@ -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 +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 { Builtin(DefaultFunction), } +impl<'a, T> Display for Term +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)] diff --git a/crates/uplc/src/machine/error.rs b/crates/uplc/src/machine/error.rs index 2860c56f..590a06bf 100644 --- a/crates/uplc/src/machine/error.rs +++ b/crates/uplc/src/machine/error.rs @@ -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), #[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), - #[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), #[error("Unable to unlift value because it is not a constant:\n\n{0:#?}")] NotAConstant(Value),