Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Amejonah1200 committed Oct 8, 2024
1 parent fc8186f commit aa5595f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 65 deletions.
66 changes: 1 addition & 65 deletions crates/typing/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<TypeId>,
},
}

#[derive(Debug, PartialEq, Clone, Eq, Hash)]
pub enum Type {
PrimitiveType(PrimitiveType),
Array {
ty: TypeId,
size: Option<NonZeroUsize>,
},
Ref(TypeId),
Error,
}

#[derive(Clone, Debug, PartialEq, Copy, Hash, Eq, PartialOrd, Ord)]
#[repr(u8)]
pub enum FloatWidth {
_32 = 32,
_64 = 64,
}

impl TryFrom<u8> for FloatWidth {
type Error = ();

fn try_from(value: u8) -> Result<Self, Self::Error> {
FloatWidth::try_from(Into::<u64>::into(value))
}
}

impl TryFrom<u64> for FloatWidth {
type Error = ();

fn try_from(value: u64) -> Result<Self, Self::Error> {
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;
28 changes: 28 additions & 0 deletions crates/typing/src/ty.rs
Original file line number Diff line number Diff line change
@@ -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<NonZeroUsize>,
},
Ref(TypeId),
Error,
}

#[derive(Debug, PartialEq, Clone, Copy, Eq, Hash, Display)]
pub enum PrimitiveType {
String,
Integer(bool, LiteralWidth),
Float(LiteralWidth),
Boolean,
Unit,
Nothing,
}

0 comments on commit aa5595f

Please sign in to comment.