Skip to content

Commit

Permalink
impl Print for DeserializeRegister and DeserializeContext
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat committed Sep 26, 2023
1 parent 0bd29ad commit b6e6084
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 19 deletions.
7 changes: 2 additions & 5 deletions ergotree-ir/src/chain/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -243,7 +241,6 @@ impl Address {
tpe: SType::SSigmaProp,
id: 1,
}
.into(),
);
let sigma_prop = Expr::BoolToSigmaProp(BoolToSigmaProp {
input: Box::from(hash_equals),
Expand Down
8 changes: 4 additions & 4 deletions ergotree-ir/src/mir/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,12 @@ pub enum Expr {
GetVar(Spanned<GetVar>),
/// Extract register of SELF box as `Coll[Byte]`, deserialize it into Value and inline into
/// the executing script.
DeserializeRegister(Spanned<DeserializeRegister>),
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(DeserializeContext),
/// MultiplyGroup op for GroupElement
MultiplyGroup(MultiplyGroup),
/// Exponentiate op for GroupElement
Expand Down Expand Up @@ -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(),
Expand Down
37 changes: 33 additions & 4 deletions ergotree-ir/src/pretty_printer/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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!(),
Expand Down Expand Up @@ -994,4 +997,30 @@ impl Print for SigmaPropBytes {
}
.into())
}
}
}

impl Print for DecodePoint {
fn print(&self, w: &mut dyn Printer) -> Result<Expr, PrintError> {
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<Expr, PrintError> {
write!(w, "deserializeRegister({})", self.reg)?;
Ok(self.clone().into())
}
}

impl Print for DeserializeContext {
fn print(&self, w: &mut dyn Printer) -> Result<Expr, PrintError> {
write!(w, "deserializeContext({})", self.id)?;
Ok(self.clone().into())
}
}
8 changes: 2 additions & 6 deletions ergotree-ir/src/source_span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit b6e6084

Please sign in to comment.