@@ -1034,21 +1034,21 @@ Module IntegerValue.
1034
1034
1035
1035
Definition cast_u8 (self : IntegerValue.t) : PartialVMResult.t Z :=
1036
1036
match self with
1037
- | IntegerValue.U8 l => Result.Ok (l)
1037
+ | IntegerValue.U8 l => Result.Ok l
1038
1038
| IntegerValue.U16 l => if l <=? 2^8 - 1
1039
- then Result.Ok (l)
1039
+ then Result.Ok l
1040
1040
else Result.Err (PartialVMError.new StatusCode.ARITHMETIC_ERROR)
1041
1041
| IntegerValue.U32 l => if l <=? 2^8 - 1
1042
- then Result.Ok (l)
1042
+ then Result.Ok l
1043
1043
else Result.Err (PartialVMError.new StatusCode.ARITHMETIC_ERROR)
1044
1044
| IntegerValue.U64 l => if l <=? 2^8 - 1
1045
- then Result.Ok (l)
1045
+ then Result.Ok l
1046
1046
else Result.Err (PartialVMError.new StatusCode.ARITHMETIC_ERROR)
1047
1047
| IntegerValue.U128 l => if l <=? 2^8 - 1
1048
- then Result.Ok ( l)
1048
+ then Result.Ok l
1049
1049
else Result.Err (PartialVMError.new StatusCode.ARITHMETIC_ERROR)
1050
1050
| IntegerValue.U256 l => if l <=? 2^8 - 1
1051
- then Result.Ok (l)
1051
+ then Result.Ok l
1052
1052
else Result.Err (PartialVMError.new StatusCode.ARITHMETIC_ERROR)
1053
1053
end .
1054
1054
@@ -1614,3 +1614,32 @@ impl IntegerValue {
1614
1614
}
1615
1615
*)
1616
1616
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