Skip to content

Commit

Permalink
impl Print for LongToByteArray and CalcSha256;
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat committed Sep 22, 2023
1 parent 0eefaef commit 7c99195
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions ergotree-ir/src/pretty_printer/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::mir::bool_to_sigma::BoolToSigmaProp;
use crate::mir::byte_array_to_bigint::ByteArrayToBigInt;
use crate::mir::byte_array_to_long::ByteArrayToLong;
use crate::mir::calc_blake2b256::CalcBlake2b256;
use crate::mir::calc_sha256::CalcSha256;
use crate::mir::coll_append::Append;
use crate::mir::coll_by_index::ByIndex;
use crate::mir::coll_exists::Exists;
Expand All @@ -29,6 +30,7 @@ use crate::mir::get_var::GetVar;
use crate::mir::global_vars::GlobalVars;
use crate::mir::if_op::If;
use crate::mir::logical_not::LogicalNot;
use crate::mir::long_to_byte_array::LongToByteArray;
use crate::mir::method_call::MethodCall;
use crate::mir::negation::Negation;
use crate::mir::option_get::OptionGet;
Expand Down Expand Up @@ -78,11 +80,11 @@ impl Print for Expr {
Expr::SubstConstants(_) => todo!(),
Expr::ByteArrayToLong(v) => v.expr().print(w),
Expr::ByteArrayToBigInt(v) => v.expr().print(w),
Expr::LongToByteArray(_) => todo!(),
Expr::LongToByteArray(v) => v.print(w),
Expr::Collection(v) => v.print(w),
Expr::Tuple(v) => v.print(w),
Expr::CalcBlake2b256(v) => v.print(w),
Expr::CalcSha256(_) => todo!(),
Expr::CalcSha256(v) => v.print(w),
Expr::Context => {
write!(w, "CONTEXT")?;
Ok(self.clone())
Expand Down Expand Up @@ -745,4 +747,28 @@ impl Print for ByteArrayToBigInt {
}
.into())
}
}

impl Print for LongToByteArray {
fn print(&self, w: &mut dyn Printer) -> Result<Expr, PrintError> {
write!(w, "longToByteArray(")?;
let input = self.input.print(w)?;
write!(w, ")")?;
Ok(LongToByteArray {
input: Box::new(input),
}
.into())
}
}

impl Print for CalcSha256 {
fn print(&self, w: &mut dyn Printer) -> Result<Expr, PrintError> {
write!(w, "sha256(")?;
let input = self.input.print(w)?;
write!(w, ")")?;
Ok(CalcSha256 {
input: Box::new(input),
}
.into())
}
}

0 comments on commit 7c99195

Please sign in to comment.