diff --git a/crates/typing/src/lib.rs b/crates/typing/src/lib.rs index 12039c6..3544191 100644 --- a/crates/typing/src/lib.rs +++ b/crates/typing/src/lib.rs @@ -1,65 +1 @@ -use std::num::NonZeroUsize; - -use slotmap::new_key_type; -use strum_macros::Display; - -use aplang_parser::parsers::number::LiteralWidth; - -new_key_type! { pub struct TypeId; } - -#[derive(Debug, PartialEq, Clone, Eq, Hash)] -pub enum OperationResult { - If { - condition: TypeId, - then: TypeId, - other: Option, - }, -} - -#[derive(Debug, PartialEq, Clone, Eq, Hash)] -pub enum Type { - PrimitiveType(PrimitiveType), - Array { - ty: TypeId, - size: Option, - }, - Ref(TypeId), - Error, -} - -#[derive(Clone, Debug, PartialEq, Copy, Hash, Eq, PartialOrd, Ord)] -#[repr(u8)] -pub enum FloatWidth { - _32 = 32, - _64 = 64, -} - -impl TryFrom for FloatWidth { - type Error = (); - - fn try_from(value: u8) -> Result { - FloatWidth::try_from(Into::::into(value)) - } -} - -impl TryFrom for FloatWidth { - type Error = (); - - fn try_from(value: u64) -> Result { - Ok(match value { - 32 => FloatWidth::_32, - 64 => FloatWidth::_64, - _ => return Err(()), - }) - } -} - -#[derive(Debug, PartialEq, Clone, Copy, Eq, Hash, Display)] -pub enum PrimitiveType { - String, - Integer(bool, LiteralWidth), - Float(FloatWidth), - Boolean, - Unit, - Nothing, -} +pub mod ty; \ No newline at end of file diff --git a/crates/typing/src/ty.rs b/crates/typing/src/ty.rs new file mode 100644 index 0000000..6b47bad --- /dev/null +++ b/crates/typing/src/ty.rs @@ -0,0 +1,28 @@ +use std::num::NonZeroUsize; + +use aplang_parser::parsers::number::LiteralWidth; +use slotmap::new_key_type; +use strum_macros::Display; + +new_key_type! { pub struct TypeId; } + +#[derive(Debug, PartialEq, Clone, Eq, Hash)] +pub enum Type { + PrimitiveType(PrimitiveType), + Array { + ty: TypeId, + size: Option, + }, + Ref(TypeId), + Error, +} + +#[derive(Debug, PartialEq, Clone, Copy, Eq, Hash, Display)] +pub enum PrimitiveType { + String, + Integer(bool, LiteralWidth), + Float(LiteralWidth), + Boolean, + Unit, + Nothing, +}