From f0dfd804372e4937d599bb3365c529818341da76 Mon Sep 17 00:00:00 2001 From: Grant Wuerker Date: Thu, 9 May 2024 09:35:40 -0600 Subject: [PATCH] hacking --- crates/library2/std/src/num/int/ops.fe | 32 +------------ crates/library2/std/src/ops/arith.fe | 64 ++++++++++++++++++++++++++ crates/library2/std/src/ops/bin.fe | 33 ------------- crates/library2/std/src/ops/comp.fe | 30 ++++++++++++ crates/library2/std/src/ops/logical.fe | 15 ++++++ crates/library2/std/src/ops/mod.fe | 4 ++ crates/library2/std/src/ops/un.fe | 0 7 files changed, 115 insertions(+), 63 deletions(-) create mode 100644 crates/library2/std/src/ops/arith.fe delete mode 100644 crates/library2/std/src/ops/bin.fe create mode 100644 crates/library2/std/src/ops/comp.fe create mode 100644 crates/library2/std/src/ops/logical.fe create mode 100644 crates/library2/std/src/ops/mod.fe delete mode 100644 crates/library2/std/src/ops/un.fe diff --git a/crates/library2/std/src/num/int/ops.fe b/crates/library2/std/src/num/int/ops.fe index 65812fcd3b..cf34002b16 100644 --- a/crates/library2/std/src/num/int/ops.fe +++ b/crates/library2/std/src/num/int/ops.fe @@ -1,14 +1,9 @@ +use ingot::ops::{Add, Sub, Div, Mul, Exp} + extern { fn __invalid() -> ! } - -// Addition `x + y` - -pub trait Add { - fn add(self, rhs: RHS) -> Out -} - impl Add for i8 { fn add(self, rhs: Self) -> Self { __invalid() } } @@ -57,12 +52,6 @@ impl Add for u256 { fn add(self, rhs: Self) -> Self { __invalid() } } -// Subtraction `x - y` - -pub trait Sub { - fn sub(self, rhs: RHS) -> Out -} - impl Sub for i8 { fn sub(self, rhs: Self) -> Self { __invalid() } } @@ -111,12 +100,6 @@ impl Sub for u256 { fn sub(self, rhs: Self) -> Self { __invalid() } } -// Multiplication `x * y` - -pub trait Mul { - fn mul(self, rhs: RHS) -> Out -} - impl Mul for i8 { fn mul(self, rhs: Self) -> Self { __invalid() } } @@ -165,12 +148,6 @@ impl Mul for u256 { fn mul(self, rhs: Self) -> Self { __invalid() } } -// Division `x / y` - -pub trait Div { - fn div(self, rhs: RHS) -> Out -} - impl Div for i8 { fn div(self, rhs: Self) -> Self { __invalid() } } @@ -219,11 +196,6 @@ impl Div for u256 { fn div(self, rhs: Self) -> Self { __invalid() } } -// Exponentiation `x^y` - -pub trait Exp { - fn exp(self, rhs: RHS) -> Out -} impl Exp for i8 { fn exp(self, rhs: Self) -> Self { __invalid() } diff --git a/crates/library2/std/src/ops/arith.fe b/crates/library2/std/src/ops/arith.fe new file mode 100644 index 0000000000..d4eb35ba1f --- /dev/null +++ b/crates/library2/std/src/ops/arith.fe @@ -0,0 +1,64 @@ +/// Addition (e.g. `x + y`) +pub trait Add { + fn add(self, rhs: RHS) -> Out +} + +/// Subtraction (e.g. `x - y`) +pub trait Sub { + fn sub(self, rhs: RHS) -> Out +} + +/// Multiplication (e.g. `x * y`) +pub trait Mul { + fn mul(self, rhs: RHS) -> Out +} + +/// Division (e.g. `x / y`) +pub trait Div { + fn div(self, rhs: RHS) -> Out +} + +/// Modulo (e.g. `x % y`) +pub trait Mod { + fn mod_(self, rhs: RHS) -> Out +} + +/// Exponentiation (e.g. `x ** y`) +pub trait Exp { + fn exp(self, rhs: RHS) -> Out +} + +/// Left shift (e.g. `x << y`) +pub trait Shl { + fn shl(self, rhs: RHS) -> Out +} + +/// Right shift (e.g. `x >> y`) +pub trait Shr { + fn shr(self, rhs: RHS) -> Out +} + +/// Plus (e.g. `+x`) +pub trait Plus { + fn plus(self) -> Out +} + +/// Minus (e.g. `-x`) +pub trait Minus { + fn minus(self) -> Out +} + +/// Bitwise and (e.g. `x && y`) +pub trait BitAnd { + fn bit_and(self, rhs: RHS) -> Out +} + +/// Bitwise or (e.g. `x || y`) +pub trait BitOr { + fn bit_or(self, rhs: RHS) -> Out +} + +/// Bitwise not (e.g. `~x`) +pub trait BitNot { + fn bit_or(self) -> Out +} \ No newline at end of file diff --git a/crates/library2/std/src/ops/bin.fe b/crates/library2/std/src/ops/bin.fe deleted file mode 100644 index 74e41ecbb8..0000000000 --- a/crates/library2/std/src/ops/bin.fe +++ /dev/null @@ -1,33 +0,0 @@ - - -pub trait Add { - fn add(self, rhs: RHS) -> Out -} - -pub trait Sub { - fn sub(self, rhs: RHS) -> Out -} - -pub trait Mul { - fn mul(self, rhs: RHS) -> Out -} - -pub trait Div { - fn div(self, rhs: RHS) -> Out -} - -pub trait Exp { - fn exp(self, rhs: RHS) -> Out -} - -pub trait Mod { - fn exp(self, rhs: RHS) -> Out -} - -pub trait Shl { - fn shl(self, shift: usize) -} - -pub trait Shr { - fn shr(self, shift: usize) -} diff --git a/crates/library2/std/src/ops/comp.fe b/crates/library2/std/src/ops/comp.fe new file mode 100644 index 0000000000..ad48a1edcb --- /dev/null +++ b/crates/library2/std/src/ops/comp.fe @@ -0,0 +1,30 @@ +/// Equal (e.g. `x == y`) +pub trait Eq { + fn eq(self, rhs: RHS) -> Out +} + +/// `Not equal (e.g. `x != y`) +pub trait NotEq { + fn not_eq(self, rhs: RHS) -> Out +} + +/// Less than (e.g. `x < y`) +pub trait Lt { + fn lt(self, rhs: RHS) -> Out +} + +/// Less than or equal (e.g. `x <= y`) +pub trait LtEq { + fn lt_eq(self, rhs: RHS) -> Out +} + +/// Greater than (e.g. `x > y`) +pub trait Gt { + fn gt(self, rhs: RHS) -> Out +} + +/// Greater than or equal (e.g. `x >= y`) +pub trait GtEq { + fn gt_eq(self, rhs: RHS) -> Out +} + diff --git a/crates/library2/std/src/ops/logical.fe b/crates/library2/std/src/ops/logical.fe new file mode 100644 index 0000000000..153fed1499 --- /dev/null +++ b/crates/library2/std/src/ops/logical.fe @@ -0,0 +1,15 @@ +/// Logical and (e.g. `x && y`) +pub trait And { + fn and(self, rhs: RHS) -> Out +} + +/// Logical or (e.g. `x || y`) +pub trait Or { + fn or(self, rhs: RHS) -> Out +} + +/// Logical not (e.g. `!x`) +pub trait Not { + fn not(self) -> Out +} + diff --git a/crates/library2/std/src/ops/mod.fe b/crates/library2/std/src/ops/mod.fe new file mode 100644 index 0000000000..dfdfa436b6 --- /dev/null +++ b/crates/library2/std/src/ops/mod.fe @@ -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. \ No newline at end of file diff --git a/crates/library2/std/src/ops/un.fe b/crates/library2/std/src/ops/un.fe deleted file mode 100644 index e69de29bb2..0000000000