Toy language created in Rust for educational purposes.
Simple program to calculate the factorial of a number (n) and exit with the factorial.
let fact = 1;
let n = 5;
if(n == 0 or n == 1) {
fact = 1;
}
while (n>1) {
fact *= n;
n-=1;
}
}
exit(fact);
Pluto is a lightweight and simple programming language. It is very early in development. Pluto runs on the (Basm)[https://github.com/Quan1umMango/bytecode] (name yet to be changed) Virtual machine.
cargo run <project-name>.tl
Currently, there is no printing to the screen directly.
You have to use the exit()
function with some integer exit code and it prints the code and exits.
Variables are declared with the let
keyword.
// Comments begin with two /. They are ignored by the compiler
let x = 34;
let y = x + 1;
let z = true;
let arr = [1,2,3];
let arr2 = [1;10]; // Creates a array of size 10, all elements as 1;
- Bool
- Int32
- Infer
- Array where type is any other datatype
- Slice
- Pointer
- Void
let b = true;
let int = 420;
Infer
type is for the compiler when it doesn't know what value the variable has. All variables are set to Infer then converted to whatever type there is on the other side of the assignment. You would almost never have to use this.
Variables cannot be assigned different types.
Void
is still in development.
Variable once created, cannot change their type.
let int = 1;
int = false;
Gives an error saying you can't assign int which has the type int32 to bool.
If and else statements
if (some_condition) {
}else if (some_other_condition) {
}else {
}
While loop:
while(condition) {
}
Comparisions and other assignment also included.
They start with the fn
keyword.
General Structure:
fn <ident>(<type> <argIdent1>, <type> <argIdent2>,...,<type> <argIdentN>) : <optional-return-type> {
function body;
}
Example: Program to get the nth number in the fibbonacci series.
fn fib(int32 n): int32 {
let ans = 1;
let prev1 = 1;
let prev2 = 0;
while(n!=0) {
ans = prev1+prev2;
prev2 = prev1;
prev1 = ans;
n -= 1;
}
return ans;
}
exit(fib(40));