G

A low-level programming language inspired by C & Swift.

Examples

Factorial function

fn fac(n: i64) -> i64 {
    guard n >= 2 else { return 1; }
    return n * fac(n - 1);
}

Summing numbers in arrays

// Sum of a bounded array (pointer and size)
fn sumBounded(numbers: i64[]) -> i64 {
    var sum = 0;
    for n in numbers {
        sum += n;
    }
    return sum;
}

// Sum of an unbounded array and length (indexable pointer)
fn sumUnbounded(numbers: i64[!], count: i64) -> i64 {
    var sum = 0;
    for i in 0 ..< count {
        sum += numbers[i];
    }
    return sum;
}

Reversing a linked list:

struct ListI64 {
    let value: i64;
    var next: ListI64*? = nil;
}

fn reverse(head: ListI64*?) -> ListI64*? {
    var head = head;
    var prev: ListI64*? = nil;

    while let current = head {
        let next = current@.next;
        current@.next = prev;
        prev = current;
        head = next;
    }

    return prev;
}

Roadmap

Features

In the not-too-distant future:

Architecture

Mid-level IR

Currently the AST is the only IR before lowering to LLVM. The AST stores pointers for resolutions and types, and some nodes are "decorated" during type checking with wrapper nodes for operations like sign extension. Nodes in the AST will have reasonable locality due to the use of a bump-pointer allocator, but any added decorator nodes means that references will be "jumping around" much more during codegen.

By implementing a new IR between AST and lowering to LLVM IR, the following can be achieved: