Graviton

Published:

What is it?

It is a simple statically typed nearly everything is an expression language implemented in Rust. The compiler is meant to be simple and easy to read. The language has a small scope similar to Lua in terms of simplicity.

Current status

It is going through a rebuild as of now. I’m working on rebuilding the AST to make it more specific and I’m working on replacing the Pratt recursive descent parser with a modified hand written shift reduce parser to give it a speed boost and use less stack memory.

Future plans

I’m planning on having it transpile to C rather than use Cranelift to give it the ability to compile on almost any platform so I can use this for future projects.

Example

import "/std";

println("Iterative Fibonacci example");

let fib = (n: I32) {
    let mut prevprevn = 0;
    let mut prevn = 0;
    let mut curn = 1;

    let mut i = 2;

    while i <= n {

        prevprevn = prevn;

        prevn = curn;

        curn = prevprevn + prevn;

        i = i + 1;

    };

    curn
};

print("Enter a number: ");
let n = read_num();

let fib_number: I32 = fib(n);

let output = if fib_number != fib(14) {
        fib_number
    } else {
        println("Input was 14 so result will be negated for demonstration");
        -fib_number
    };

print("Fibonacci of ");
printn(n);
print(" is ");
printnln(fib(n));
println("");

In this fibonacci example, you can see the language is similar to its parent langage, Rust. However it’s not exactly the same. Functions are declared like any other variable since they can be passed into functions as if they were variables. The reason for the many different variants of the print function is because I don’t have variadic functions in the language and most likely won’t implement that. I’ll take a similar path to Rust and implement some kind of simple macro system.

With the fib function, it doesn’t have an explicit return type. All functions, variables can have implicit return types unless the function is recursive, then it must have an explicit return type.