Skip to content

Commit

Permalink
hacking
Browse files Browse the repository at this point in the history
  • Loading branch information
Grant Wuerker committed Apr 30, 2024
1 parent 4339031 commit d9589bd
Showing 1 changed file with 23 additions and 49 deletions.
72 changes: 23 additions & 49 deletions crates/library2/std/src/ops.fe
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ type usize = u256

extern {
fn __add(x: usize, y: usize) -> usize
fn __sadd(x: isize, y: isize) -> isize
fn __sub(x: usize, y: usize) -> usize
fn __ssub(x: isize, y: isize) -> isize
fn __mul(x: usize, y: usize) -> usize
fn __smul(x: isize, y: isize) -> isize
fn __div(x: usize, y: usize) -> usize
Expand Down Expand Up @@ -38,7 +40,7 @@ extern {
fn __u128_saturate(_ x: usize) -> u128

fn __u8_truncate(_ x: usize) -> u8
fn __u16_truncate(_ x: usize -> u16
fn __u16_truncate(_ x: usize) -> u16
fn __u32_truncate(_ x: usize) -> u32
fn __u64_truncate(_ x: usize) -> u64
fn __u128_truncate(_ x: usize) -> u128
Expand All @@ -56,7 +58,7 @@ extern {
fn __i128_saturate(_ x: isize) -> i128

fn __i8_truncate(_ x: isize) -> i8
fn __i16_truncate(_ x: isize -> i16
fn __i16_truncate(_ x: isize) -> i16
fn __i32_truncate(_ x: isize) -> i32
fn __i64_truncate(_ x: isize) -> i64
fn __i128_truncate(_ x: isize) -> i128
Expand All @@ -66,70 +68,42 @@ extern {
fn __i32_extend(_ x: i32) -> isize
fn __i64_extend(_ x: i64) -> isize
fn __i128_extend(_ x: i128) -> isize

}

pub trait Add {
fn add(self, rhs: Self) -> Self
}

pub trait Sub {
fn sub(self, rhs: Self) -> Self
pub trait Saturate<T> {
fn saturate(_ value: T) -> Self
}

pub trait Mul {
fn mul(self, rhs: Self) -> Self
}

pub trait Div {
fn div(self, rhs: Self) -> Self
}

impl Add for u8 {
fn add(self, rhs: Self) -> Self {
__u8_saturate(__add(x: __u8_extend(self), y: __u8_extend(rhs)))
impl Saturate<i256> for i8 {
fn saturate(_ value: i256) -> Self {
__i8_saturate(value)
}
}

impl Sub for u8 {
fn sub(self, rhs: Self) -> Self {
__u8_saturate(__sub(x: __u8_extend(self), y: __u8_extend(rhs)))
}
pub trait Extend<T> {
fn extend(self) -> T
}

impl Mul for u8 {
fn mul(self, rhs: Self) -> Self {
__u8_saturate(__mul(x: __u8_extend(self), y: __u8_extend(rhs)))
impl Extend<i256> for i8 {
fn extend(self) -> i256 {
__i8_extend(self)
}
}

impl Div for u8 {
fn div(self, rhs: Self) -> Self {
__u8_saturate(__div(x: __u8_extend(self), y: __u8_extend(rhs)))
}
pub trait Add {
fn add(self, rhs: Self) -> Self
}

impl Add for i8 {
fn add(self, rhs: Self) -> Self {
__i8_saturate(__add(x: __i8_extend(self), y: __i8_extend(rhs)))
}
}

impl Sub for i8 {
fn sub(self, rhs: Self) -> Self {
__i8_saturate(__sub(x: __i8_extend(self), y: __i8_extend(rhs)))
i8::saturate(__sadd(x: self.extend(), y: rhs.extend()))
}
}

impl Mul for i8 {
fn mul(self, rhs: Self) -> Self {
__i8_saturate(__mul(x: __i8_extend(self), y: __i8_extend(rhs)))
}
}

impl Div for i8 {
fn div(self, rhs: Self) -> Self {
__i8_saturate(__sdiv(x: __i8_extend(self), y: __i8_extend(rhs)))
}
}

fn my_test() {
let a: i8 = 42
let b: i8 = 26
a.add(rhs: b)
()
}

0 comments on commit d9589bd

Please sign in to comment.