@@ -1034,21 +1034,21 @@ Module IntegerValue.
10341034
10351035 Definition cast_u8 (self : IntegerValue.t) : PartialVMResult.t Z :=
10361036 match self with
1037- | IntegerValue.U8 l => Result.Ok (l)
1037+ | IntegerValue.U8 l => Result.Ok l
10381038 | IntegerValue.U16 l => if l <=? 2^8 - 1
1039- then Result.Ok (l)
1039+ then Result.Ok l
10401040 else Result.Err (PartialVMError.new StatusCode.ARITHMETIC_ERROR)
10411041 | IntegerValue.U32 l => if l <=? 2^8 - 1
1042- then Result.Ok (l)
1042+ then Result.Ok l
10431043 else Result.Err (PartialVMError.new StatusCode.ARITHMETIC_ERROR)
10441044 | IntegerValue.U64 l => if l <=? 2^8 - 1
1045- then Result.Ok (l)
1045+ then Result.Ok l
10461046 else Result.Err (PartialVMError.new StatusCode.ARITHMETIC_ERROR)
10471047 | IntegerValue.U128 l => if l <=? 2^8 - 1
1048- then Result.Ok ( l)
1048+ then Result.Ok l
10491049 else Result.Err (PartialVMError.new StatusCode.ARITHMETIC_ERROR)
10501050 | IntegerValue.U256 l => if l <=? 2^8 - 1
1051- then Result.Ok (l)
1051+ then Result.Ok l
10521052 else Result.Err (PartialVMError.new StatusCode.ARITHMETIC_ERROR)
10531053 end .
10541054
@@ -1614,3 +1614,32 @@ impl IntegerValue {
16141614}
16151615 *)
16161616
1617+ (*
1618+ impl VMValueCast<IntegerValue> for Value {
1619+ fn cast(self) -> PartialVMResult<IntegerValue> {
1620+ match self.0 {
1621+ ValueImpl::U8(x) => Ok(IntegerValue::U8(x)),
1622+ ValueImpl::U16(x) => Ok(IntegerValue::U16(x)),
1623+ ValueImpl::U32(x) => Ok(IntegerValue::U32(x)),
1624+ ValueImpl::U64(x) => Ok(IntegerValue::U64(x)),
1625+ ValueImpl::U128(x) => Ok(IntegerValue::U128(x)),
1626+ ValueImpl::U256(x) => Ok(IntegerValue::U256(x)),
1627+ v => Err(PartialVMError::new(StatusCode::INTERNAL_TYPE_ERROR)
1628+ .with_message(format!("cannot cast {:?} to integer", v,))),
1629+ }
1630+ }
1631+ }
1632+ *)
1633+ Global Instance Impl_VMValueCast_IntegerValue_for_Value :
1634+ VMValueCast.Trait Value.t IntegerValue.t : Set := {
1635+ cast self :=
1636+ match self with
1637+ | ValueImpl.U8 x => return ? $ IntegerValue.U8 x
1638+ | ValueImpl.U16 x => return ? $ IntegerValue.U16 x
1639+ | ValueImpl.U32 x => return ? $ IntegerValue.U32 x
1640+ | ValueImpl.U64 x => return ? $ IntegerValue.U64 x
1641+ | ValueImpl.U128 x => return ? $ IntegerValue.U128 x
1642+ | ValueImpl.U256 x => return ? $ IntegerValue.U256 x
1643+ | _ => Result.Err $ PartialVMError.new StatusCode.INTERNAL_TYPE_ERROR
1644+ end ;
1645+ }.
0 commit comments