SeraphScript/src/prim_type.rs

39 lines
868 B
Rust
Raw Normal View History

2022-04-02 21:30:05 +00:00
use crate::defines::PointerSize;
#[cfg(test)]
use serde_derive::{Deserialize, Serialize};
2022-04-02 21:30:05 +00:00
#[derive(Eq, PartialEq, Debug)]
#[cfg_attr(test, derive(Serialize, Deserialize))]
2022-04-02 21:30:05 +00:00
pub enum PrimitiveType {
Void,
Int8,
Int16,
Int32,
Int64,
UInt8,
UInt16,
UInt32,
UInt64,
Float,
Double,
Bool,
}
2022-04-03 13:25:26 +00:00
#[allow(dead_code)]
2022-04-02 21:30:05 +00:00
pub fn get_primitive_type_byte_size(t: PrimitiveType) -> PointerSize {
match t {
PrimitiveType::Void => 0,
PrimitiveType::Int8 => 1,
PrimitiveType::Int16 => 2,
PrimitiveType::Int32 => 4,
PrimitiveType::Int64 => 8,
PrimitiveType::UInt8 => 1,
PrimitiveType::UInt16 => 2,
PrimitiveType::UInt32 => 4,
PrimitiveType::UInt64 => 8,
PrimitiveType::Float => 4,
PrimitiveType::Double => 8,
PrimitiveType::Bool => 1,
}
}