2018-08-15 14:01:40 -05:00
|
|
|
use super::{Scalar, ScalarMaybeUndef, EvalResult};
|
2018-05-01 11:13:22 -05:00
|
|
|
|
2018-08-15 14:01:40 -05:00
|
|
|
pub trait FalibleScalarExt {
|
|
|
|
/// HACK: this function just extracts all bits if `defined != 0`
|
|
|
|
/// Mainly used for args of C-functions and we should totally correctly fetch the size
|
|
|
|
/// of their arguments
|
|
|
|
fn to_bytes(self) -> EvalResult<'static, u128>;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FalibleScalarExt for Scalar {
|
|
|
|
fn to_bytes(self) -> EvalResult<'static, u128> {
|
|
|
|
match self {
|
|
|
|
Scalar::Bits { bits, size } => {
|
|
|
|
assert_ne!(size, 0);
|
|
|
|
Ok(bits)
|
|
|
|
},
|
|
|
|
Scalar::Ptr(_) => err!(ReadPointerAsBytes),
|
2018-07-10 10:32:38 -05:00
|
|
|
}
|
2017-07-28 06:08:27 -05:00
|
|
|
}
|
2018-08-15 14:01:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl FalibleScalarExt for ScalarMaybeUndef {
|
|
|
|
fn to_bytes(self) -> EvalResult<'static, u128> {
|
|
|
|
self.not_undef()?.to_bytes()
|
2018-05-09 04:52:41 -05:00
|
|
|
}
|
2017-07-28 06:08:27 -05:00
|
|
|
}
|