checkpoint; builds again

This commit is contained in:
2023-12-02 22:38:44 -08:00
parent 71228b9e09
commit 93cac44a99
16 changed files with 1200 additions and 1194 deletions

View File

@@ -6,6 +6,7 @@ use std::{fmt::Display, str::FromStr};
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum PrimitiveType {
Void,
U8,
U16,
U32,
@@ -19,6 +20,7 @@ pub enum PrimitiveType {
impl Display for PrimitiveType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
PrimitiveType::Void => write!(f, "void"),
PrimitiveType::I8 => write!(f, "i8"),
PrimitiveType::I16 => write!(f, "i16"),
PrimitiveType::I32 => write!(f, "i32"),
@@ -100,6 +102,7 @@ impl PrimitiveType {
/// Return true if this type can be safely cast into the target type.
pub fn can_cast_to(&self, target: &PrimitiveType) -> bool {
match self {
PrimitiveType::Void => matches!(target, PrimitiveType::Void),
PrimitiveType::U8 => matches!(
target,
PrimitiveType::U8
@@ -175,16 +178,17 @@ impl PrimitiveType {
}
}
pub fn max_value(&self) -> u64 {
pub fn max_value(&self) -> Option<u64> {
match self {
PrimitiveType::U8 => u8::MAX as u64,
PrimitiveType::U16 => u16::MAX as u64,
PrimitiveType::U32 => u32::MAX as u64,
PrimitiveType::U64 => u64::MAX,
PrimitiveType::I8 => i8::MAX as u64,
PrimitiveType::I16 => i16::MAX as u64,
PrimitiveType::I32 => i32::MAX as u64,
PrimitiveType::I64 => i64::MAX as u64,
PrimitiveType::Void => None,
PrimitiveType::U8 => Some(u8::MAX as u64),
PrimitiveType::U16 => Some(u16::MAX as u64),
PrimitiveType::U32 => Some(u32::MAX as u64),
PrimitiveType::U64 => Some(u64::MAX),
PrimitiveType::I8 => Some(i8::MAX as u64),
PrimitiveType::I16 => Some(i16::MAX as u64),
PrimitiveType::I32 => Some(i32::MAX as u64),
PrimitiveType::I64 => Some(i64::MAX as u64),
}
}
}