For an overview about rush's syntax, please consult the grammar.
Each rush program consists of an arbitrary amount of functions and global
variables. In order to create a valid program, the main
function needs to be declared.
In rush, there cannot be top-level code other than function declarations and globals.
The main function serves as the entry to a rush program, so that code starts
executing from here. This concept is very similar to the main function in
Rust or in
C. The function
signature of the main function has to look like this:
fn main() {
// ...
}Therefore the main function cannot take any arguments or return a non-unit
type value.
fn exit(code: i32) -> !;The exit function calls the operating system, demanding to quit the program
with the specified exit-code.
| Notation | Example Value | Size | Values |
|---|---|---|---|
int |
42 | 64 bit | |
float |
3.1415 | 64 bit | IEEE float values |
char |
'a' | 8 bit | |
bool |
true | 1 bit |
true and false
|
() (unit) |
no value | 1 bit | no values |
| Operator | Operand Type | Produces (Type) |
|---|---|---|
| - | int |
int |
| ! | bool, int |
same as operand |
| Operator | Operand Types | Produces (Type) |
|---|---|---|
| + | int, char, float |
same as operands |
| - | int, char, float |
same as operands |
| * | int, float |
same as operands |
| / | int, float |
same as operands |
| % | int |
int |
| ** | int |
int |
Note: Division by zero using
/or%is undefined behavior and may vary per backend.
| Operator | Operand Types | Produces (Type) |
|---|---|---|
| << | int |
int |
| >> | int |
int |
| | | int, bool |
same as operands |
| & | int, bool |
same as operands |
| ^ | int, bool |
same as operands |
Note: Shifting by a number outside the range
0..=63is undefined behavior and may vary per backend.
| Operator | Operand Types | Produces (Type) |
|---|---|---|
| && | bool |
bool |
| || | bool |
bool |
| < | int, char, float |
bool |
| <= | int, char, float |
bool |
| > | int, char, float |
bool |
| >= | int, char, float |
bool |
| == | int, float, bool, char |
bool |
| != | int, float, bool, char |
bool |
Note: All logical infix operators require values of equal types on their left- and right-hand sides.
The rush language supports conversion between types. The basic syntax looks like this:
value as type| From | To | Notes |
|---|---|---|
int |
int |
redundant |
int |
float |
|
int |
bool |
res = int != 0 |
int |
char |
defined here |
float |
int |
truncate |
float |
float |
redundant |
float |
bool |
res = float != 0.0 |
float |
char |
defined here |
bool |
bool |
redundant |
bool |
int |
true = 1 | false = 0 |
bool |
float |
|
bool |
char |
|
char |
char |
redundant |
char |
int |
|
char |
float |
|
char |
bool |
res = int(char) != 0 |
When casting int or float values to char, any source value char with the value ASCII characters which lie in the range