From 31a3da27132a3ca72bf7e43d352e29fea9d005be Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Fri, 11 Aug 2023 12:51:44 +0300 Subject: [PATCH] impl Print for GlobalVars; --- ergotree-ir/src/mir/global_vars.rs | 15 +++++++++++++++ ergotree-ir/src/pretty_printer.rs | 9 +++++++++ 2 files changed, 24 insertions(+) diff --git a/ergotree-ir/src/mir/global_vars.rs b/ergotree-ir/src/mir/global_vars.rs index b2b40c196..8fc23fbb4 100644 --- a/ergotree-ir/src/mir/global_vars.rs +++ b/ergotree-ir/src/mir/global_vars.rs @@ -1,5 +1,7 @@ //! Global variables +use std::fmt::Display; + use crate::has_opcode::HasOpCode; use crate::serialization::op_code::OpCode; use crate::types::stype::SType; @@ -49,6 +51,19 @@ impl HasOpCode for GlobalVars { } } +impl Display for GlobalVars { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + GlobalVars::SelfBox => write!(f, "SELF_BOX"), + GlobalVars::Inputs => write!(f, "INPUTS"), + GlobalVars::Outputs => write!(f, "OUTPUTS"), + GlobalVars::Height => write!(f, "HEIGHT"), + GlobalVars::MinerPubKey => write!(f, "MINER_PUBKEY"), + GlobalVars::GroupGenerator => write!(f, "GROUP_GENERATOR"), + } + } +} + #[cfg(test)] #[cfg(feature = "arbitrary")] mod tests { diff --git a/ergotree-ir/src/pretty_printer.rs b/ergotree-ir/src/pretty_printer.rs index 71241eb52..4f07998d7 100644 --- a/ergotree-ir/src/pretty_printer.rs +++ b/ergotree-ir/src/pretty_printer.rs @@ -9,6 +9,7 @@ use crate::mir::block::BlockValue; use crate::mir::coll_append::Append; use crate::mir::constant::Constant; use crate::mir::expr::Expr; +use crate::mir::global_vars::GlobalVars; use crate::mir::val_def::ValDef; use crate::mir::val_use::ValUse; use crate::source_span::SourceSpan; @@ -128,6 +129,13 @@ impl Print for BinOp { } } +impl Print for GlobalVars { + fn print(&self, w: &mut dyn Printer) -> Result { + write!(w, "{}", self)?; + Ok(self.clone().into()) + } +} + #[allow(clippy::panic)] impl Print for Expr { fn print(&self, w: &mut dyn Printer) -> Result { @@ -138,6 +146,7 @@ impl Print for Expr { Expr::ValUse(v) => v.print(w), Expr::Const(v) => v.print(w), Expr::BinOp(v) => v.expr().print(w), + Expr::GlobalVars(v) => v.print(w), e => panic!("Not implemented: {:?}", e), } }