From 4e9f39444cfb665f40b72bb77bbda5d8fc0c3cfc Mon Sep 17 00:00:00 2001 From: Sergey Pepyakin Date: Fri, 15 Jun 2018 13:06:45 +0300 Subject: [PATCH] Clean --- src/validation/func.rs | 100 ++++++++++++++++++++--------------------- 1 file changed, 49 insertions(+), 51 deletions(-) diff --git a/src/validation/func.rs b/src/validation/func.rs index 7f55eea..d882f93 100644 --- a/src/validation/func.rs +++ b/src/validation/func.rs @@ -103,6 +103,54 @@ enum StackValueType { Specific(ValueType), } +impl StackValueType { + fn is_any(&self) -> bool { + match self { + &StackValueType::Any => true, + _ => false, + } + } + + fn value_type(&self) -> ValueType { + match self { + &StackValueType::Any => unreachable!("must be checked by caller"), + &StackValueType::Specific(value_type) => value_type, + } + } +} + +impl From for StackValueType { + fn from(value_type: ValueType) -> Self { + StackValueType::Specific(value_type) + } +} + +impl PartialEq for StackValueType { + fn eq(&self, other: &StackValueType) -> bool { + if self.is_any() || other.is_any() { + true + } else { + self.value_type() == other.value_type() + } + } +} + +impl PartialEq for StackValueType { + fn eq(&self, other: &ValueType) -> bool { + if self.is_any() { + true + } else { + self.value_type() == *other + } + } +} + +impl PartialEq for ValueType { + fn eq(&self, other: &StackValueType) -> bool { + other == self + } +} + /// Function validator. pub struct Validator; @@ -376,10 +424,8 @@ impl Validator { ); } TeeLocal(index) => { - // We need to calculate relative depth before validation since - // it will change value stack size. - let depth = context.relative_local_depth(index)?; Validator::validate_tee_local(context, index)?; + let depth = context.relative_local_depth(index)?; context.sink.emit( isa::Instruction::TeeLocal(depth), ); @@ -1480,54 +1526,6 @@ impl<'a> FunctionValidationContext<'a> { } } -impl StackValueType { - fn is_any(&self) -> bool { - match self { - &StackValueType::Any => true, - _ => false, - } - } - - fn value_type(&self) -> ValueType { - match self { - &StackValueType::Any => unreachable!("must be checked by caller"), - &StackValueType::Specific(value_type) => value_type, - } - } -} - -impl From for StackValueType { - fn from(value_type: ValueType) -> Self { - StackValueType::Specific(value_type) - } -} - -impl PartialEq for StackValueType { - fn eq(&self, other: &StackValueType) -> bool { - if self.is_any() || other.is_any() { - true - } else { - self.value_type() == other.value_type() - } - } -} - -impl PartialEq for StackValueType { - fn eq(&self, other: &ValueType) -> bool { - if self.is_any() { - true - } else { - self.value_type() == *other - } - } -} - -impl PartialEq for ValueType { - fn eq(&self, other: &StackValueType) -> bool { - other == self - } -} - #[derive(Clone)] struct DropKeep { drop: u32,