void comptimenumber type for easier erroring on non-value ast nodes
This commit is contained in:
parent
464baa7bd7
commit
4e27002fb9
|
@ -1520,6 +1520,10 @@ pub enum Error {
|
|||
FloatingCmp,
|
||||
#[error("Not a comptime expression.")]
|
||||
NotComptime,
|
||||
#[error("void conversion.")]
|
||||
VoidConversion,
|
||||
#[error("invalid conversion.")]
|
||||
InvalidConversion,
|
||||
}
|
||||
|
||||
pub type Result<T> = core::result::Result<T, Error>;
|
||||
|
@ -1967,6 +1971,7 @@ pub enum ComptimeNumber {
|
|||
Integral(ComptimeInt),
|
||||
Bool(bool),
|
||||
Floating(ComptimeFloat),
|
||||
Void,
|
||||
}
|
||||
|
||||
impl From<bool> for ComptimeNumber {
|
||||
|
@ -2017,6 +2022,7 @@ impl ComptimeNumber {
|
|||
ComptimeFloat::Binary32(_) => 32,
|
||||
ComptimeFloat::Binary64(_) => 64,
|
||||
},
|
||||
ComptimeNumber::Void => 0,
|
||||
}
|
||||
}
|
||||
pub fn add(self, other: Self) -> Result<Self> {
|
||||
|
@ -2248,6 +2254,9 @@ impl ComptimeNumber {
|
|||
ComptimeFloat::Binary32(f) => Ok((f as u128 & ty.u128_bitmask(), ty).into()),
|
||||
ComptimeFloat::Binary64(f) => Ok((f as u128 & ty.u128_bitmask(), ty).into()),
|
||||
},
|
||||
ComptimeNumber::Void => {
|
||||
return Err(Error::VoidConversion);
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn into_float(self, ty: FloatingType) -> Result<Self> {
|
||||
|
@ -2269,6 +2278,9 @@ impl ComptimeNumber {
|
|||
ComptimeFloat::Binary32(f) => f as f64,
|
||||
ComptimeFloat::Binary64(f) => f as f64,
|
||||
},
|
||||
ComptimeNumber::Void => {
|
||||
return Err(Error::VoidConversion);
|
||||
}
|
||||
};
|
||||
|
||||
match ty {
|
||||
|
@ -2305,6 +2317,7 @@ impl ComptimeNumber {
|
|||
Type::Floating(FloatingType::Binary64),
|
||||
),
|
||||
},
|
||||
ComptimeNumber::Void => (vec![], Type::Void),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue