diff --git a/ergotree-ir/src/types/sfunc.rs b/ergotree-ir/src/types/sfunc.rs index f838a3304..1add72303 100644 --- a/ergotree-ir/src/types/sfunc.rs +++ b/ergotree-ir/src/types/sfunc.rs @@ -15,6 +15,20 @@ pub struct SFunc { pub tpe_params: Vec, } +impl std::fmt::Display for SFunc { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "(")?; + for (i, item) in self.t_dom.iter().enumerate() { + if i > 0 { + write!(f, ", ")?; + } + item.fmt(f)?; + } + write!(f, ") => ")?; + self.t_range.fmt(f) + } +} + impl SFunc { /// Create new SFunc pub fn new(t_dom: Vec, t_range: SType) -> Self { diff --git a/ergotree-ir/src/types/stuple.rs b/ergotree-ir/src/types/stuple.rs index 95afe5947..51f992d14 100644 --- a/ergotree-ir/src/types/stuple.rs +++ b/ergotree-ir/src/types/stuple.rs @@ -34,6 +34,19 @@ impl std::fmt::Debug for STuple { } } +impl std::fmt::Display for STuple { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "(")?; + for (i, item) in self.items.iter().enumerate() { + if i > 0 { + write!(f, ", ")?; + } + item.fmt(f)?; + } + write!(f, ")") + } +} + impl STuple { /// Create a tuple type for a given type pair pub fn pair(t1: SType, t2: SType) -> Self { diff --git a/ergotree-ir/src/types/stype.rs b/ergotree-ir/src/types/stype.rs index eba90fea1..bc926bdfa 100644 --- a/ergotree-ir/src/types/stype.rs +++ b/ergotree-ir/src/types/stype.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use std::convert::TryInto; +use std::fmt::Debug; use impl_trait_for_tuples::impl_for_tuples; @@ -126,6 +127,34 @@ impl From for SType { } } +impl std::fmt::Display for SType { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + SType::STypeVar(t) => write!(f, "{}", t.as_string()), + SType::SAny => write!(f, "Any"), + SType::SUnit => write!(f, "Unit"), + SType::SBoolean => write!(f, "Boolean"), + SType::SByte => write!(f, "Byte"), + SType::SShort => write!(f, "Short"), + SType::SInt => write!(f, "Int"), + SType::SLong => write!(f, "Long"), + SType::SBigInt => write!(f, "BigInt"), + SType::SGroupElement => write!(f, "GroupElement"), + SType::SSigmaProp => write!(f, "SigmaProp"), + SType::SBox => write!(f, "Box"), + SType::SAvlTree => write!(f, "AvlTree"), + SType::SOption(t) => write!(f, "Option[{}]", t), + SType::SColl(t) => write!(f, "Coll[{}]", t), + SType::STuple(t) => write!(f, "{}", t), + SType::SFunc(t) => write!(f, "{}", t), + SType::SContext => write!(f, "Context"), + SType::SHeader => write!(f, "Header"), + SType::SPreHeader => write!(f, "PreHeader"), + SType::SGlobal => write!(f, "Global"), + } + } +} + /// Conversion to SType pub trait LiftIntoSType { /// get SType