From b6e60840d6c1f3c1cfbf6187117a4a8bfccbdf6d Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Tue, 26 Sep 2023 15:46:22 +0300 Subject: [PATCH] impl Print for DeserializeRegister and DeserializeContext --- ergotree-ir/src/chain/address.rs | 7 ++--- ergotree-ir/src/mir/expr.rs | 8 +++--- ergotree-ir/src/pretty_printer/print.rs | 37 ++++++++++++++++++++++--- ergotree-ir/src/source_span.rs | 8 ++---- 4 files changed, 41 insertions(+), 19 deletions(-) diff --git a/ergotree-ir/src/chain/address.rs b/ergotree-ir/src/chain/address.rs index 5a11b1fee..1b4cc4107 100644 --- a/ergotree-ir/src/chain/address.rs +++ b/ergotree-ir/src/chain/address.rs @@ -108,10 +108,8 @@ impl Address { Err(_) => Address::P2S(tree.sigma_serialize_bytes()?), }, Expr::SigmaAnd(SigmaAnd { items }) => { - if let [Expr::BoolToSigmaProp(BoolToSigmaProp { input }), Expr::DeserializeContext(Spanned { - expr: DeserializeContext { tpe, id }, - .. - })] = items.as_slice() + if let [Expr::BoolToSigmaProp(BoolToSigmaProp { input }), Expr::DeserializeContext(DeserializeContext { tpe, id })] = + items.as_slice() { if let ( Expr::BinOp(Spanned { @@ -243,7 +241,6 @@ impl Address { tpe: SType::SSigmaProp, id: 1, } - .into(), ); let sigma_prop = Expr::BoolToSigmaProp(BoolToSigmaProp { input: Box::from(hash_equals), diff --git a/ergotree-ir/src/mir/expr.rs b/ergotree-ir/src/mir/expr.rs index bf11c30e9..f508c5009 100644 --- a/ergotree-ir/src/mir/expr.rs +++ b/ergotree-ir/src/mir/expr.rs @@ -208,12 +208,12 @@ pub enum Expr { GetVar(Spanned), /// Extract register of SELF box as `Coll[Byte]`, deserialize it into Value and inline into /// the executing script. - DeserializeRegister(Spanned), + DeserializeRegister(DeserializeRegister), /// Extracts context variable as `Coll[Byte]`, deserializes it to script and then executes /// this script in the current context. The original `Coll[Byte]` of the script is /// available as `getVar[Coll[Byte]](id)` On evaluation returns the result of the /// script execution in the current context - DeserializeContext(Spanned), + DeserializeContext(DeserializeContext), /// MultiplyGroup op for GroupElement MultiplyGroup(MultiplyGroup), /// Exponentiate op for GroupElement @@ -286,8 +286,8 @@ impl Expr { Expr::DecodePoint(v) => v.tpe(), Expr::SigmaAnd(v) => v.tpe(), Expr::SigmaOr(v) => v.tpe(), - Expr::DeserializeRegister(v) => v.expr().tpe(), - Expr::DeserializeContext(v) => v.expr().tpe(), + Expr::DeserializeRegister(v) => v.tpe(), + Expr::DeserializeContext(v) => v.tpe(), Expr::GetVar(v) => v.expr().tpe(), Expr::MultiplyGroup(v) => v.tpe(), Expr::Exponentiate(v) => v.tpe(), diff --git a/ergotree-ir/src/pretty_printer/print.rs b/ergotree-ir/src/pretty_printer/print.rs index 20fd4e335..d8e15f91d 100644 --- a/ergotree-ir/src/pretty_printer/print.rs +++ b/ergotree-ir/src/pretty_printer/print.rs @@ -24,6 +24,9 @@ use crate::mir::collection::Collection; use crate::mir::constant::Constant; use crate::mir::create_prove_dh_tuple::CreateProveDhTuple; use crate::mir::create_provedlog::CreateProveDlog; +use crate::mir::decode_point::DecodePoint; +use crate::mir::deserialize_context::DeserializeContext; +use crate::mir::deserialize_register::DeserializeRegister; use crate::mir::downcast::Downcast; use crate::mir::expr::Expr; use crate::mir::extract_amount::ExtractAmount; @@ -142,12 +145,12 @@ impl Print for Expr { Expr::CreateProveDlog(v) => v.print(w), Expr::CreateProveDhTuple(v) => v.print(w), Expr::SigmaPropBytes(v) => v.print(w), - Expr::DecodePoint(_) => todo!(), + Expr::DecodePoint(v) => v.print(w), Expr::SigmaAnd(v) => v.print(w), Expr::SigmaOr(v) => v.print(w), Expr::GetVar(v) => v.expr().print(w), - Expr::DeserializeRegister(_) => todo!(), - Expr::DeserializeContext(_) => todo!(), + Expr::DeserializeRegister(v) => v.print(w), + Expr::DeserializeContext(v) => v.print(w), Expr::MultiplyGroup(_) => todo!(), Expr::Exponentiate(_) => todo!(), Expr::XorOf(_) => todo!(), @@ -994,4 +997,30 @@ impl Print for SigmaPropBytes { } .into()) } -} \ No newline at end of file +} + +impl Print for DecodePoint { + fn print(&self, w: &mut dyn Printer) -> Result { + write!(w, "decodePoint(")?; + let input = self.input.print(w)?; + write!(w, ")")?; + Ok(DecodePoint { + input: Box::new(input), + } + .into()) + } +} + +impl Print for DeserializeRegister { + fn print(&self, w: &mut dyn Printer) -> Result { + write!(w, "deserializeRegister({})", self.reg)?; + Ok(self.clone().into()) + } +} + +impl Print for DeserializeContext { + fn print(&self, w: &mut dyn Printer) -> Result { + write!(w, "deserializeContext({})", self.id)?; + Ok(self.clone().into()) + } +} diff --git a/ergotree-ir/src/source_span.rs b/ergotree-ir/src/source_span.rs index 1365f86a2..a48ae4a54 100644 --- a/ergotree-ir/src/source_span.rs +++ b/ergotree-ir/src/source_span.rs @@ -13,8 +13,6 @@ use crate::mir::coll_fold::Fold; use crate::mir::coll_forall::ForAll; use crate::mir::coll_map::Map; use crate::mir::coll_slice::Slice; -use crate::mir::deserialize_context::DeserializeContext; -use crate::mir::deserialize_register::DeserializeRegister; use crate::mir::expr::Expr; use crate::mir::extract_reg_as::ExtractRegisterAs; use crate::mir::get_var::GetVar; @@ -117,8 +115,6 @@ into_expr!(Exists); into_expr!(ForAll); into_expr!(SelectField); into_expr!(GetVar); -into_expr!(DeserializeRegister); -into_expr!(DeserializeContext); into_expr!(TreeLookup); into_expr!(And); into_expr!(Or); @@ -196,8 +192,8 @@ impl Expr { Expr::SigmaAnd(_) => SourceSpan::empty(), Expr::SigmaOr(_) => SourceSpan::empty(), Expr::GetVar(op) => op.source_span, - Expr::DeserializeRegister(op) => op.source_span, - Expr::DeserializeContext(op) => op.source_span, + Expr::DeserializeRegister(_) => SourceSpan::empty(), + Expr::DeserializeContext(_) => SourceSpan::empty(), Expr::MultiplyGroup(_) => SourceSpan::empty(), Expr::Exponentiate(_) => SourceSpan::empty(), Expr::XorOf(_) => SourceSpan::empty(),