-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fc8186f
commit aa5595f
Showing
2 changed files
with
29 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |