Operators are a set of operations that create an expression from one or more sub-expressions. Unless remarked otherwise, all operators support operator overloading and forwarding of fluid
values. In addition, all operators are constexpr (unless they are overloaded, in which case it is overload specific).
Name | Syntax | Supported Builtin Types | Example | Remarks |
---|---|---|---|---|
Addition |
a + b |
|
1 + 2 // 3 |
Type of return is the type of arguments. Integer overflowing is |
Wrapping Addition |
a +% b |
|
1 +% (255 as UI8) // 0 |
Type of return is the type of arguments. Integer overflowing is allowed (two's compliment). |
Saturating Addition |
a +| b |
|
1 +| (255 as UI8) // 255 |
Type of return is the type of arguments. |
Subtraction |
a - b |
|
5 - 2 // 3 |
Type of return is the type of arguments. Integer overflowing is |
Wrapping Subtraction |
a -% b |
|
5 -% (6 as UI8) // 255 |
Type of return is the type of arguments. Integer overflowing is allowed (two's compliment). |
Saturating Subtraction |
a -| b |
|
5 -| (6 as UI8) // 0 |
Type of return is the type of arguments. |
Multiplication |
a * b |
|
5 * 2 // 10 |
Type of return is the type of arguments. Integer overflowing is |
Wrapping Multiplication |
a *% b |
|
32 *% (8 as UI8) // 0 |
Type of return is the type of arguments. Integer overflowing is allowed (two's compliment). |
Saturating Multiplication |
a *| b |
|
32 *| (8 as UI8) // 255 |
Type of return is the type of arguments. |
Division |
a / b |
|
7 / 3 // 2 |
Type of return is the type of arguments. Integer overflowing is |
Division Remainder |
a % b |
|
7 % 3 // 1 |
Type of return is the type of arguments. Integer overflowing is allowed (two's compliment). |
Negate |
-a |
|
-12 // -12 |
Type of return is the type of argument. |
Name | Syntax | Supported Builtin Types | Example | Remarks |
---|---|---|---|---|
Equal To |
a == b |
any compatable types |
12 == 10 // false |
Type of return is |
Not Equal To |
a != b |
any compatable types |
12 != 10 // false |
Type of return is |
Less Than |
a < b |
any compatable types |
12 < 10 // false |
Type of return is |
Less Than or Equal To |
a <= b |
any compatable types |
12 <= 10 // false |
Type of return is |
Greater Than |
a > b |
any compatable types |
12 > 10 // true |
Type of return is |
Greater Than or Equal To |
a >= b |
any compatable types |
12 >= 10 // true |
Type of return is |
Name | Syntax | Supported Builtin Types | Example | Remarks |
---|---|---|---|---|
Bitwise And |
a & b |
|
0b1010 & 0b0110 // 0b0010 |
Type of return is the type of arguments. |
Bitwise Or |
a | b |
|
0b1010 | 0b0110 // 0b1110 |
Type of return is the type of arguments. |
Bitwise Xor |
a ^ b |
|
0b1010 | 0b0110 // 0b1100 |
Type of return is the type of arguments. |
Bit Shift Left |
a << b |
|
0b0101 << 2 // 0b10100 |
Type of return is the type of RHS must be |
Saturating Bit Shift Left |
a <<| b |
|
(0b11 as UI8) << 7 // 255 |
Type of return is the type of RHS must be |
Bit Shift Right |
a >> b |
|
0b11000 >> 2 // 0b110 |
Type of return is the type of RHS must be |
Bitwise Not |
~a |
|
~(0b10101110 as UI8) // 0b01010001 |
Type of return is the type of argument. Does not support fluid values |
Name | Syntax | Supported Builtin Types | Example | Remarks |
---|---|---|---|---|
Address Of |
&a |
Any |
var num: Int = 12; const num_ptr: Int* = # num_ptr.* // 12 |
Argument must be Using on a const object returns a |
Read-Only Address Of |
&|a |
Any |
var num: Int = 12; const num_ptr: Int*| = &|num; num_ptr.* // 12 |
Argument must be |
Dereference |
a.* |
Any |
var num: Int = 12; const num_ptr: Int* = # num_ptr.* // 12 |
Dereferencing a |
Unwrap |
a.? |
Any |
var opt_num: Int? = 12; opt_num.? // 12 |
It is |
Name | Syntax | Supported Builtin Types | Example | Remarks |
---|---|---|---|---|
Logical And |
a && b |
|
|
Type of return is If |
Logical Or |
a || b |
|
|
Type of return is If |
Boolean Not |
!a |
|
|
Type of return is |
copy a
(TODO)
move a
(TODO)
forward a
(TODO)
a as b
(TODO)
a.b
(TODO)
(TODO)
Precedence | Operators |
---|---|
1 | a.b a.* a.? |
2 | &a &|a copy a move a forward a -a !a ~a |
3 | a as b |
4 | a * b a *% b a *| b a / b a % b |
5 | a + b a +% b a +| b a - b a -% b a -| b |
6 | a << b a <<| b a >> b |
7 | a & b a | b a ^ b |
8 | a == b a != b a < b a <= b a > b a >= b |
9 | a && b |
10 | a || b |