cl_typeck: Add new primitive types (including joking-point numbers)

This commit is contained in:
2024-07-26 03:24:34 -05:00
parent 4096442f75
commit 524c84be9e
3 changed files with 114 additions and 29 deletions

View File

@@ -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();