Skip to content

Commit

Permalink
make TValue hold Value instead of Constant;
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat committed Nov 20, 2020
1 parent 23b5556 commit d6b45ef
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 18 deletions.
6 changes: 3 additions & 3 deletions ergo-lib/src/ast/context_methods.rs
Expand Up @@ -35,10 +35,10 @@ impl Evaluable for ContextM {
ctx: &crate::eval::context::Context,
) -> Result<Value, EvalError> {
match self {
ContextM::Height => Ok(ctx.height.v.v.clone()),
ContextM::Height => Ok(ctx.height.v.clone()),
// TODO: test
ContextM::SelfBox => Ok(ctx.self_box.v.v.clone()),
ContextM::Outputs => Ok(ctx.outputs.v.v.clone()),
ContextM::SelfBox => Ok(ctx.self_box.v.clone()),
ContextM::Outputs => Ok(ctx.outputs.v.clone()),
_ => Err(EvalError::UnexpectedExpr),
}
}
Expand Down
5 changes: 3 additions & 2 deletions ergo-lib/src/eval.rs
Expand Up @@ -8,10 +8,11 @@ use thiserror::Error;

use self::context::Context;

mod costs;

pub(crate) mod context;
pub(crate) mod cost_accum;
mod costs;
mod tvalue;
pub(crate) mod tvalue;

/// Environment for the interpreter
pub struct Env();
Expand Down
17 changes: 4 additions & 13 deletions ergo-lib/src/eval/tvalue.rs
@@ -1,6 +1,5 @@
use std::marker::PhantomData;

use crate::ast::constant::Constant;
use crate::ast::value::StoredNonPrimitive;
use crate::ast::value::Value;
use crate::chain::ergo_box::ErgoBox;
Expand All @@ -23,10 +22,9 @@ pub struct SCollT<T: STypeT> {

impl<T: STypeT> STypeT for SCollT<T> {}

// TODO: rename to ConstantT?
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct TValue<T: STypeT> {
pub v: Constant,
pub v: Value,
p: PhantomData<T>,
}

Expand All @@ -50,16 +48,9 @@ impl From<i32> for TValue<SIntT> {

impl<T: LiftIntoSType + StoredNonPrimitive + Into<Value>, S: STypeT> From<Vec<T>> for TValue<S> {
fn from(raw: Vec<T>) -> Self {
let v = Constant {
tpe: Vec::<T>::stype(),
TValue {
v: raw.into(),
};
TValue { v, p: PhantomData }
}
}

impl<T: STypeT> From<TValue<T>> for Constant {
fn from(v: TValue<T>) -> Self {
v.v
p: PhantomData,
}
}
}
2 changes: 2 additions & 0 deletions ergo-lib/src/serialization/data.rs
Expand Up @@ -23,11 +23,13 @@ impl DataSerializer {
Value::Byte(v) => w.put_i8(*v),
Value::Short(v) => w.put_i16(*v),
Value::Int(v) => w.put_i32(*v),
// Value::TInt(v) => w.put_i32(v.raw),
Value::Long(v) => w.put_i64(*v),
Value::BigInt => todo!(),
Value::GroupElement(ecp) => ecp.sigma_serialize(w),
Value::SigmaProp(s) => s.value().sigma_serialize(w),
Value::CBox(_) => todo!(),
// Value::TBox(_) => todo!(),
Value::AvlTree => todo!(),
Value::Coll(ct) => match ct {
Coll::Primitive(CollPrim::CollByte(b)) => {
Expand Down
28 changes: 28 additions & 0 deletions ergo-lib/src/types/stype.rs
Expand Up @@ -2,6 +2,10 @@

use crate::chain::ergo_box::ErgoBox;
use crate::serialization::types::TypeCode;
use crate::sigma_protocol::sigma_boolean::ProveDlog;
use crate::sigma_protocol::sigma_boolean::SigmaBoolean;
use crate::sigma_protocol::sigma_boolean::SigmaProofOfKnowledgeTree;
use crate::sigma_protocol::sigma_boolean::SigmaProp;

use super::sfunc::SFunc;
use super::stype_companion::STypeCompanion;
Expand Down Expand Up @@ -122,6 +126,30 @@ impl LiftIntoSType for ErgoBox {
}
}

impl LiftIntoSType for SigmaBoolean {
fn stype() -> SType {
SType::SSigmaProp
}
}

impl LiftIntoSType for SigmaProofOfKnowledgeTree {
fn stype() -> SType {
SType::SSigmaProp
}
}

impl LiftIntoSType for SigmaProp {
fn stype() -> SType {
SType::SSigmaProp
}
}

impl LiftIntoSType for ProveDlog {
fn stype() -> SType {
SType::SSigmaProp
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit d6b45ef

Please sign in to comment.