-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2110cc9
commit e58691d
Showing
1 changed file
with
195 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
// Copyright 2024 The Jule Programming Language. | ||
// Use of this source code is governed by a BSD 3-Clause | ||
// license that can be found in the LICENSE file. | ||
|
||
struct Int { | ||
x: int | ||
} | ||
|
||
impl Int { | ||
pub fn add(self, y: Int): Int { | ||
ret Int{self.x + y.x} | ||
} | ||
|
||
pub fn add_assign(mut self, y: Int) { | ||
self.x += y.x | ||
} | ||
|
||
pub fn sub(self, y: Int): Int { | ||
ret Int{self.x - y.x} | ||
} | ||
|
||
pub fn sub_assign(mut self, y: Int) { | ||
self.x -= y.x | ||
} | ||
|
||
pub fn mul(self, y: Int): Int { | ||
ret Int{self.x * y.x} | ||
} | ||
|
||
pub fn mul_assign(mut self, y: Int) { | ||
self.x *= y.x | ||
} | ||
|
||
pub fn div(self, y: Int): Int { | ||
ret Int{self.x / y.x} | ||
} | ||
|
||
pub fn div_assign(mut self, y: Int) { | ||
self.x /= y.x | ||
} | ||
|
||
pub fn mod(self, y: Int): Int { | ||
ret Int{self.x % y.x} | ||
} | ||
|
||
pub fn mod_assign(mut self, y: Int) { | ||
self.x %= y.x | ||
} | ||
|
||
pub fn shl(self, y: Int): Int { | ||
ret Int{self.x << y.x} | ||
} | ||
|
||
pub fn shl_assign(mut self, y: Int) { | ||
self.x <<= y.x | ||
} | ||
|
||
pub fn shr(self, y: Int): Int { | ||
ret Int{self.x >> y.x} | ||
} | ||
|
||
pub fn shr_assign(mut self, y: Int) { | ||
self.x >>= y.x | ||
} | ||
|
||
pub fn bit_or(self, y: Int): Int { | ||
ret Int{self.x | y.x} | ||
} | ||
|
||
pub fn bit_or_assign(mut self, y: Int) { | ||
self.x |= y.x | ||
} | ||
|
||
pub fn bit_and(self, y: Int): Int { | ||
ret Int{self.x & y.x} | ||
} | ||
|
||
pub fn bit_and_assign(mut self, y: Int) { | ||
self.x &= y.x | ||
} | ||
|
||
pub fn bit_xor(self, y: Int): Int { | ||
ret Int{self.x ^ y.x} | ||
} | ||
|
||
pub fn bit_xor_assign(mut self, y: Int) { | ||
self.x ^= y.x | ||
} | ||
|
||
pub fn bit_not(self): Int { | ||
ret Int{^self.x} | ||
} | ||
|
||
pub fn neg(self): Int { | ||
ret Int{-self.x} | ||
} | ||
|
||
pub fn pos(self): Int { | ||
ret Int{+self.x} | ||
} | ||
} | ||
|
||
struct Number[T] { | ||
x: T | ||
} | ||
|
||
impl Number { | ||
pub fn add(self, y: Number[T]): Number[T] { | ||
ret Number[T]{self.x + y.x} | ||
} | ||
|
||
pub fn add_assign(mut self, y: Number[T]) { | ||
self.x += y.x | ||
} | ||
|
||
pub fn sub(self, y: Number[T]): Number[T] { | ||
ret Number[T]{self.x - y.x} | ||
} | ||
|
||
pub fn sub_assign(mut self, y: Number[T]) { | ||
self.x -= y.x | ||
} | ||
|
||
pub fn mul(self, y: Number[T]): Number[T] { | ||
ret Number[T]{self.x * y.x} | ||
} | ||
|
||
pub fn mul_assign(mut self, y: Number[T]) { | ||
self.x *= y.x | ||
} | ||
|
||
pub fn div(self, y: Number[T]): Number[T] { | ||
ret Number[T]{self.x / y.x} | ||
} | ||
|
||
pub fn div_assign(mut self, y: Number[T]) { | ||
self.x /= y.x | ||
} | ||
|
||
pub fn neg(self): Number[T] { | ||
ret Number[T]{-self.x} | ||
} | ||
|
||
pub fn pos(self): Number[T] { | ||
ret Number[T]{+self.x} | ||
} | ||
} | ||
|
||
fn test_int() { | ||
let mut x = Int{10} | ||
let y = Int{20} | ||
_ = x + y | ||
x += y | ||
_ = x - y | ||
x -= y | ||
_ = x * y | ||
x *= y | ||
_ = x / y | ||
x /= y | ||
_ = x % y | ||
x %= y | ||
_ = x << y | ||
x <<= y | ||
_ = x >> y | ||
x >>= y | ||
_ = x | y | ||
x |= y | ||
_ = x & y | ||
x &= y | ||
_ = x ^ y | ||
x ^= y | ||
_ = ^x | ||
_ = -x | ||
_ = +x | ||
} | ||
|
||
fn test_number() { | ||
let mut x = Number[f64]{10} | ||
let y = Number[f64]{20} | ||
_ = x + y | ||
x += y | ||
_ = x - y | ||
x -= y | ||
_ = x * y | ||
x *= y | ||
_ = x / y | ||
x /= y | ||
_ = -x | ||
_ = +x | ||
} | ||
|
||
fn main() { | ||
test_int() | ||
test_number() | ||
} |