-
int: 64 bit signed integer -
float: 64 bit signed float -
bool: 64 bit integer representing a bool (value of 1 for true, 0 for false) -
str: Represents a string of characters, you can calllen(str)to get the length, but strings are immutable under the hood, so be aware of that -
Struct: structs are special first class datatypes because while you can pass and return them from functions, there is noMY_STRUCT[]type, instead usestruct[](which is "first class" in the same way structs are) orany[](which is second class) - I touched on it above but all first class types can have n dimensional arrays declared like
int[][]for an integer matrix. Lengths are not necessary and the arrays behave like vectors in the strict sense, as they are contiguously allocated in memory, but can grow, and will be able to shrink in the future
-
Void: represents a function that does not return, stability and compilation are guaranteed when using it as a return type from a function, and for no other place -
Any: Will disable the typechecker when used, so it assumes you have manually checked your types, if they are wrong you will get a nasty error, while the following is allowed: functions may returnany, and takeanyas parameters, variables may assigned to any, and you may makeany[]'s it is highly unstable for all other use cases and should be avoided if at all possible - Functions: This language has 0, nada, nil functional features. Maybe they will be added later but for now treat all functions like C functions
To declare a variable, use:
let x = 9;
The type is automatically inferred. If you want to explicitly specify a type:
let x: str = "hello world";
Notice the semicolons!!!
Variable reassignment and compound operators are also supported
let x: float = 9.2;
x += 315.2;
You can use an if statement as follows
let x = true && !false;
if x {
println("it worked");
} else {
println("it failed");
}
Else is supported, but else-if chains are not.
You already saw a function call above but here is the general syntax for functions
fn add(a: int, b: int): int {
return a + b;
}
let x = add(9, 3);
All function parameters and return types (including void) must be stated explicitly, here is a void example
fn my_println(s: str): void {
println(s);
}
my_println("hi mom!!!");
You can see a list of builtin functions at the bottom
Currently only while loops are supported, but iteration loops (for) will be in the (very) distant future
let i = 0;
while i < 7 {
if i == 3{
continue;
}
if i == 6 {
break;
}
println(i);
}
will print 1, 2, 4, 5,
Arrays are also fully supported
let arr = [0, 1, 2, 3, 4];
arr = [9, 2];
let x = arr[0];
println(arr);
prints [9, 2]
Structs are also fully supported
struct Point{
x: float,
y: float
}
let origin = Point{x: 0.0, y: 0.0};
fn print_point(p: Point): void{
print("Point{x: ");
print(p.x);
print(", y: ");
print(p.y);
print("};");
}
You can bind methods to structs like this, lets redo that print_point
struct Point{
x: float,
y: float
}
for Point {
fn print_point(){// note the inferred return type of void
print("Point{x: ");
print(this.x);//notice this keyword
print(", y: ");
print(this.y);
print("};");
}
}
let origin = Point{x: 0.0, y: 0.0};
origin.print_point(); //outputs Point{x: 0.0000, y: 0.0000};
-
print(s: any): voidprints an output to the standard output -
println(s: any): voidprints an output to the standard output with a newline -
len(v: any): intthe signature takes an any but can only be called on a string or an array, will return the number of characters or elements respectively -
int(i: any): intreturns the integer value of a value an object if it is a string of "17" it will become 17 otherwise it will panic, and for floats it will round -
str(s: any): strreturns the string value of any convertible object, for booleans false => "false", true is the same, for an integer 7 => "7", and same with floats -
float(f: any): floatreturns a float from a convertible value, will turn "5.3" => 5.3, false => 0.0, true => 1.0, will turn 1 => 1.0 -
bool(b: any): boolwill turn "true" => true, same with false and will panic for any other string, will turn 1 => true, 0 => false and wil panic otherwise, and will round a float and use do the same
python setup_build_system.py #will install build system
cargo run -- --repl # will get you a repl
cargo run -- PATH_TO_FILE # will compile a .toy file