Skip to content

Commit

Permalink
hacking
Browse files Browse the repository at this point in the history
  • Loading branch information
Grant Wuerker committed May 9, 2024
1 parent 07e060a commit f0dfd80
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 63 deletions.
32 changes: 2 additions & 30 deletions crates/library2/std/src/num/int/ops.fe
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
use ingot::ops::{Add, Sub, Div, Mul, Exp}

extern {
fn __invalid() -> !
}


// Addition `x + y`

pub trait Add<RHS, Out> {
fn add(self, rhs: RHS) -> Out
}

impl Add<Self, Self> for i8 {
fn add(self, rhs: Self) -> Self { __invalid() }
}
Expand Down Expand Up @@ -57,12 +52,6 @@ impl Add<Self, Self> for u256 {
fn add(self, rhs: Self) -> Self { __invalid() }
}

// Subtraction `x - y`

pub trait Sub<RHS, Out> {
fn sub(self, rhs: RHS) -> Out
}

impl Sub<Self, Self> for i8 {
fn sub(self, rhs: Self) -> Self { __invalid() }
}
Expand Down Expand Up @@ -111,12 +100,6 @@ impl Sub<Self, Self> for u256 {
fn sub(self, rhs: Self) -> Self { __invalid() }
}

// Multiplication `x * y`

pub trait Mul<RHS, Out> {
fn mul(self, rhs: RHS) -> Out
}

impl Mul<Self, Self> for i8 {
fn mul(self, rhs: Self) -> Self { __invalid() }
}
Expand Down Expand Up @@ -165,12 +148,6 @@ impl Mul<Self, Self> for u256 {
fn mul(self, rhs: Self) -> Self { __invalid() }
}

// Division `x / y`

pub trait Div<RHS, Out> {
fn div(self, rhs: RHS) -> Out
}

impl Div<Self, Self> for i8 {
fn div(self, rhs: Self) -> Self { __invalid() }
}
Expand Down Expand Up @@ -219,11 +196,6 @@ impl Div<Self, Self> for u256 {
fn div(self, rhs: Self) -> Self { __invalid() }
}

// Exponentiation `x^y`

pub trait Exp<RHS, Out> {
fn exp(self, rhs: RHS) -> Out
}

impl Exp<Self, Self> for i8 {
fn exp(self, rhs: Self) -> Self { __invalid() }
Expand Down
64 changes: 64 additions & 0 deletions crates/library2/std/src/ops/arith.fe
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/// Addition (e.g. `x + y`)
pub trait Add<RHS, Out> {
fn add(self, rhs: RHS) -> Out
}

/// Subtraction (e.g. `x - y`)
pub trait Sub<RHS, Out> {
fn sub(self, rhs: RHS) -> Out
}

/// Multiplication (e.g. `x * y`)
pub trait Mul<RHS, Out> {
fn mul(self, rhs: RHS) -> Out
}

/// Division (e.g. `x / y`)
pub trait Div<RHS, Out> {
fn div(self, rhs: RHS) -> Out
}

/// Modulo (e.g. `x % y`)
pub trait Mod<RHS, Out> {
fn mod_(self, rhs: RHS) -> Out
}

/// Exponentiation (e.g. `x ** y`)
pub trait Exp<RHS, Out> {
fn exp(self, rhs: RHS) -> Out
}

/// Left shift (e.g. `x << y`)
pub trait Shl<RHS, Out> {
fn shl(self, rhs: RHS) -> Out
}

/// Right shift (e.g. `x >> y`)
pub trait Shr<RHS, Out> {
fn shr(self, rhs: RHS) -> Out
}

/// Plus (e.g. `+x`)
pub trait Plus<Out> {
fn plus(self) -> Out
}

/// Minus (e.g. `-x`)
pub trait Minus<Out> {
fn minus(self) -> Out
}

/// Bitwise and (e.g. `x && y`)
pub trait BitAnd<RHS, Out> {
fn bit_and(self, rhs: RHS) -> Out
}

/// Bitwise or (e.g. `x || y`)
pub trait BitOr<RHS, Out> {
fn bit_or(self, rhs: RHS) -> Out
}

/// Bitwise not (e.g. `~x`)
pub trait BitNot<Out> {
fn bit_or(self) -> Out
}
33 changes: 0 additions & 33 deletions crates/library2/std/src/ops/bin.fe

This file was deleted.

30 changes: 30 additions & 0 deletions crates/library2/std/src/ops/comp.fe
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/// Equal (e.g. `x == y`)
pub trait Eq<RHS, Out> {
fn eq(self, rhs: RHS) -> Out
}

/// `Not equal (e.g. `x != y`)
pub trait NotEq<RHS, Out> {
fn not_eq(self, rhs: RHS) -> Out
}

/// Less than (e.g. `x < y`)
pub trait Lt<RHS, Out> {
fn lt(self, rhs: RHS) -> Out
}

/// Less than or equal (e.g. `x <= y`)
pub trait LtEq<RHS, Out> {
fn lt_eq(self, rhs: RHS) -> Out
}

/// Greater than (e.g. `x > y`)
pub trait Gt<RHS, Out> {
fn gt(self, rhs: RHS) -> Out
}

/// Greater than or equal (e.g. `x >= y`)
pub trait GtEq<RHS, Out> {
fn gt_eq(self, rhs: RHS) -> Out
}

15 changes: 15 additions & 0 deletions crates/library2/std/src/ops/logical.fe
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/// Logical and (e.g. `x && y`)
pub trait And<RHS, Out> {
fn and(self, rhs: RHS) -> Out
}

/// Logical or (e.g. `x || y`)
pub trait Or<RHS, Out> {
fn or(self, rhs: RHS) -> Out
}

/// Logical not (e.g. `!x`)
pub trait Not<Out> {
fn not(self) -> Out
}

4 changes: 4 additions & 0 deletions crates/library2/std/src/ops/mod.fe
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// / Overloaded operations of Fe.
// /
// / Each trait in this module corresponds with a syntax opperator. During compilation,
// / these syntax opperators are replaced with calls to the trait methods defiend here.
Empty file removed crates/library2/std/src/ops/un.fe
Empty file.

0 comments on commit f0dfd80

Please sign in to comment.