cl_typeck: Add new primitive types (including joking-point numbers)
This commit is contained in:
parent
4096442f75
commit
524c84be9e
@ -54,39 +54,18 @@ pub enum Adt {
|
|||||||
|
|
||||||
/// The set of compiler-intrinsic types.
|
/// The set of compiler-intrinsic types.
|
||||||
/// These primitive types have native implementations of the basic operations.
|
/// These primitive types have native implementations of the basic operations.
|
||||||
#[allow(non_camel_case_types)]
|
#[rustfmt::skip]
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
pub enum Intrinsic {
|
pub enum Intrinsic {
|
||||||
/// An 8-bit signed integer: `#[intrinsic = "i8"]`
|
I8, I16, I32, I64, I128, Isize, // Signed integers
|
||||||
I8,
|
U8, U16, U32, U64, U128, Usize, // Unsigned integers
|
||||||
/// A 16-bit signed integer: `#[intrinsic = "i16"]`
|
F8, F16, F32, F64, F128, Fsize, // Floating point numbers
|
||||||
I16,
|
Bool, // boolean value
|
||||||
/// A 32-bit signed integer: `#[intrinsic = "i32"]`
|
Char, // Unicode codepoint
|
||||||
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,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Author's note: the fsize type is a meme
|
||||||
|
|
||||||
impl FromStr for Intrinsic {
|
impl FromStr for Intrinsic {
|
||||||
type Err = ();
|
type Err = ();
|
||||||
|
|
||||||
@ -96,12 +75,20 @@ impl FromStr for Intrinsic {
|
|||||||
"i16" => Intrinsic::I16,
|
"i16" => Intrinsic::I16,
|
||||||
"i32" => Intrinsic::I32,
|
"i32" => Intrinsic::I32,
|
||||||
"i64" => Intrinsic::I64,
|
"i64" => Intrinsic::I64,
|
||||||
|
"i128" => Intrinsic::I128,
|
||||||
"isize" => Intrinsic::Isize,
|
"isize" => Intrinsic::Isize,
|
||||||
"u8" => Intrinsic::U8,
|
"u8" => Intrinsic::U8,
|
||||||
"u16" => Intrinsic::U16,
|
"u16" => Intrinsic::U16,
|
||||||
"u32" => Intrinsic::U32,
|
"u32" => Intrinsic::U32,
|
||||||
"u64" => Intrinsic::U64,
|
"u64" => Intrinsic::U64,
|
||||||
|
"u128" => Intrinsic::U128,
|
||||||
"usize" => Intrinsic::Usize,
|
"usize" => Intrinsic::Usize,
|
||||||
|
"f8" => Intrinsic::F8,
|
||||||
|
"f16" => Intrinsic::F16,
|
||||||
|
"f32" => Intrinsic::F32,
|
||||||
|
"f64" => Intrinsic::F64,
|
||||||
|
"f128" => Intrinsic::F128,
|
||||||
|
"fsize" => Intrinsic::Fsize,
|
||||||
"bool" => Intrinsic::Bool,
|
"bool" => Intrinsic::Bool,
|
||||||
"char" => Intrinsic::Char,
|
"char" => Intrinsic::Char,
|
||||||
_ => Err(())?,
|
_ => Err(())?,
|
||||||
|
@ -75,12 +75,20 @@ impl Display for Intrinsic {
|
|||||||
Intrinsic::I16 => f.write_str("i16"),
|
Intrinsic::I16 => f.write_str("i16"),
|
||||||
Intrinsic::I32 => f.write_str("i32"),
|
Intrinsic::I32 => f.write_str("i32"),
|
||||||
Intrinsic::I64 => f.write_str("i64"),
|
Intrinsic::I64 => f.write_str("i64"),
|
||||||
|
Intrinsic::I128 => f.write_str("i128"),
|
||||||
Intrinsic::Isize => f.write_str("isize"),
|
Intrinsic::Isize => f.write_str("isize"),
|
||||||
Intrinsic::U8 => f.write_str("u8"),
|
Intrinsic::U8 => f.write_str("u8"),
|
||||||
Intrinsic::U16 => f.write_str("u16"),
|
Intrinsic::U16 => f.write_str("u16"),
|
||||||
Intrinsic::U32 => f.write_str("u32"),
|
Intrinsic::U32 => f.write_str("u32"),
|
||||||
Intrinsic::U64 => f.write_str("u64"),
|
Intrinsic::U64 => f.write_str("u64"),
|
||||||
|
Intrinsic::U128 => f.write_str("u128"),
|
||||||
Intrinsic::Usize => f.write_str("usize"),
|
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::Bool => f.write_str("bool"),
|
||||||
Intrinsic::Char => f.write_str("char"),
|
Intrinsic::Char => f.write_str("char"),
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,9 @@ pub type i32;
|
|||||||
#[intrinsic = "i64"]
|
#[intrinsic = "i64"]
|
||||||
pub type i64;
|
pub type i64;
|
||||||
|
|
||||||
|
#[intrinsic = "i128"]
|
||||||
|
pub type i128;
|
||||||
|
|
||||||
#[intrinsic = "isize"]
|
#[intrinsic = "isize"]
|
||||||
pub type isize;
|
pub type isize;
|
||||||
|
|
||||||
@ -33,9 +36,18 @@ pub type u32;
|
|||||||
#[intrinsic = "u64"]
|
#[intrinsic = "u64"]
|
||||||
pub type u64;
|
pub type u64;
|
||||||
|
|
||||||
|
#[intrinsic = "u128"]
|
||||||
|
pub type u128;
|
||||||
|
|
||||||
#[intrinsic = "usize"]
|
#[intrinsic = "usize"]
|
||||||
pub type usize;
|
pub type usize;
|
||||||
|
|
||||||
|
#[intrinsic = "f32"]
|
||||||
|
pub type f32;
|
||||||
|
|
||||||
|
#[intrinsic = "f64"]
|
||||||
|
pub type f64;
|
||||||
|
|
||||||
// Contains implementations for (TODO) overloaded operators on num types
|
// Contains implementations for (TODO) overloaded operators on num types
|
||||||
pub mod ops {
|
pub mod ops {
|
||||||
use super::*;
|
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 {
|
impl usize {
|
||||||
pub const MIN: Self = __march_ptr_width_unsigned_min();
|
pub const MIN: Self = __march_ptr_width_unsigned_min();
|
||||||
pub const MAX: Self = __march_ptr_width_unsigned_max();
|
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 {
|
impl isize {
|
||||||
pub const MIN: Self = __march_ptr_width_signed_min();
|
pub const MIN: Self = __march_ptr_width_signed_min();
|
||||||
pub const MAX: Self = __march_ptr_width_signed_max();
|
pub const MAX: Self = __march_ptr_width_signed_max();
|
||||||
|
Loading…
Reference in New Issue
Block a user