diff --git a/compiler/cl-typeck/src/type_kind.rs b/compiler/cl-typeck/src/type_kind.rs index b8d6f7d..6153c7d 100644 --- a/compiler/cl-typeck/src/type_kind.rs +++ b/compiler/cl-typeck/src/type_kind.rs @@ -54,39 +54,18 @@ pub enum Adt { /// The set of compiler-intrinsic types. /// These primitive types have native implementations of the basic operations. -#[allow(non_camel_case_types)] +#[rustfmt::skip] #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub enum Intrinsic { - /// An 8-bit signed integer: `#[intrinsic = "i8"]` - I8, - /// A 16-bit signed integer: `#[intrinsic = "i16"]` - I16, - /// A 32-bit signed integer: `#[intrinsic = "i32"]` - I32, - /// A 64-bit signed integer: `#[intrinsic = "i32"]` - I64, - // /// A 128-bit signed integer: `#[intrinsic = "i32"]` - // I128, - /// A ptr-len signed integer: `#[intrinsic = "isize"]` - Isize, - /// An 8-bit unsigned integer: `#[intrinsic = "u8"]` - U8, - /// A 16-bit unsigned integer: `#[intrinsic = "u16"]` - U16, - /// A 32-bit unsigned integer: `#[intrinsic = "u32"]` - U32, - /// A 64-bit unsigned integer: `#[intrinsic = "u64"]` - U64, - // /// A 128-bit unsigned integer: `#[intrinsic = "u128"]` - // U128, - /// A ptr-len unsigned integer: `#[intrinsic = "isize"]` - Usize, - /// A boolean (`true` or `false`): `#[intrinsic = "bool"]` - Bool, - /// The unicode codepoint type: #[intrinsic = "char"] - Char, + I8, I16, I32, I64, I128, Isize, // Signed integers + U8, U16, U32, U64, U128, Usize, // Unsigned integers + F8, F16, F32, F64, F128, Fsize, // Floating point numbers + Bool, // boolean value + Char, // Unicode codepoint } +// Author's note: the fsize type is a meme + impl FromStr for Intrinsic { type Err = (); @@ -96,12 +75,20 @@ impl FromStr for Intrinsic { "i16" => Intrinsic::I16, "i32" => Intrinsic::I32, "i64" => Intrinsic::I64, + "i128" => Intrinsic::I128, "isize" => Intrinsic::Isize, "u8" => Intrinsic::U8, "u16" => Intrinsic::U16, "u32" => Intrinsic::U32, "u64" => Intrinsic::U64, + "u128" => Intrinsic::U128, "usize" => Intrinsic::Usize, + "f8" => Intrinsic::F8, + "f16" => Intrinsic::F16, + "f32" => Intrinsic::F32, + "f64" => Intrinsic::F64, + "f128" => Intrinsic::F128, + "fsize" => Intrinsic::Fsize, "bool" => Intrinsic::Bool, "char" => Intrinsic::Char, _ => Err(())?, diff --git a/compiler/cl-typeck/src/type_kind/display.rs b/compiler/cl-typeck/src/type_kind/display.rs index 0c0fda7..70eb6cb 100644 --- a/compiler/cl-typeck/src/type_kind/display.rs +++ b/compiler/cl-typeck/src/type_kind/display.rs @@ -75,12 +75,20 @@ impl Display for Intrinsic { Intrinsic::I16 => f.write_str("i16"), Intrinsic::I32 => f.write_str("i32"), Intrinsic::I64 => f.write_str("i64"), + Intrinsic::I128 => f.write_str("i128"), Intrinsic::Isize => f.write_str("isize"), Intrinsic::U8 => f.write_str("u8"), Intrinsic::U16 => f.write_str("u16"), Intrinsic::U32 => f.write_str("u32"), Intrinsic::U64 => f.write_str("u64"), + Intrinsic::U128 => f.write_str("u128"), Intrinsic::Usize => f.write_str("usize"), + Intrinsic::F8 => f.write_str("f8"), + Intrinsic::F16 => f.write_str("f16"), + Intrinsic::F32 => f.write_str("f32"), + Intrinsic::F64 => f.write_str("f64"), + Intrinsic::F128 => f.write_str("f128"), + Intrinsic::Fsize => f.write_str("fsize"), Intrinsic::Bool => f.write_str("bool"), Intrinsic::Char => f.write_str("char"), } diff --git a/stdlib/std/num.cl b/stdlib/std/num.cl index 39d2fe1..f19ec4d 100644 --- a/stdlib/std/num.cl +++ b/stdlib/std/num.cl @@ -18,6 +18,9 @@ pub type i32; #[intrinsic = "i64"] pub type i64; +#[intrinsic = "i128"] +pub type i128; + #[intrinsic = "isize"] pub type isize; @@ -33,9 +36,18 @@ pub type u32; #[intrinsic = "u64"] pub type u64; +#[intrinsic = "u128"] +pub type u128; + #[intrinsic = "usize"] pub type usize; +#[intrinsic = "f32"] +pub type f32; + +#[intrinsic = "f64"] +pub type f64; + // Contains implementations for (TODO) overloaded operators on num types pub mod ops { use super::*; @@ -226,6 +238,45 @@ pub mod ops { } } + impl u128 { + pub const MIN: Self = 0; + pub const MAX: Self = !0; + pub const BIT_WIDTH: u32 = 8; + pub fn default() -> Self { + 0 + } + pub fn mul(a: Self, b: Self) -> Self { + a * b + } + pub fn div(a: Self, b: Self) -> Self { + a / b + } + pub fn rem(a: Self, b: Self) -> Self { + a % b + } + pub fn add(a: Self, b: Self) -> Self { + a + b + } + pub fn sub(a: Self, b: Self) -> Self { + a - b + } + pub fn shl(a: Self, b: u32) -> Self { + a << b + } + pub fn shr(a: Self, b: u32) -> Self { + a >> b + } + pub fn and(a: Self, b: Self) -> Self { + a & b + } + pub fn or(a: Self, b: Self) -> Self { + a | b + } + pub fn xor(a: Self, b: Self) -> Self { + a ^ b + } + } + impl usize { pub const MIN: Self = __march_ptr_width_unsigned_min(); pub const MAX: Self = __march_ptr_width_unsigned_max(); @@ -421,6 +472,45 @@ pub mod ops { } } + impl i128 { + pub const MIN: Self = !(1 << 128); + pub const MAX: Self = 1 << 128; + pub const BIT_WIDTH: u32 = 8; + pub fn default() -> Self { + 0 + } + pub fn mul(a: Self, b: Self) -> Self { + a * b + } + pub fn div(a: Self, b: Self) -> Self { + a / b + } + pub fn rem(a: Self, b: Self) -> Self { + a % b + } + pub fn add(a: Self, b: Self) -> Self { + a + b + } + pub fn sub(a: Self, b: Self) -> Self { + a - b + } + pub fn shl(a: Self, b: u32) -> Self { + a << b + } + pub fn shr(a: Self, b: u32) -> Self { + a >> b + } + pub fn and(a: Self, b: Self) -> Self { + a & b + } + pub fn or(a: Self, b: Self) -> Self { + a | b + } + pub fn xor(a: Self, b: Self) -> Self { + a ^ b + } + } + impl isize { pub const MIN: Self = __march_ptr_width_signed_min(); pub const MAX: Self = __march_ptr_width_signed_max();