A compiler for the Volette programming language, written in Rust.
Volette is an expression-oriented, statically-typed programming language that compiles to native code using a heavily modified Citadel backend. It's designed to be simple, straightforward, with a focus on a powerful type system.
Currently only aarch64 macOS is supported.
Here's a simple Volette program that calculates factorial:
fn factorial(n: i32): i32 {
let result = 1
let i = 1
while i <= n {
result *= i
i += 1
}
return result
}
fn fib(n: i32): i32 {
let a = 0
let b = 1
let i = 0
while i < n {
let tmp = a + b
a = b
b = tmp
i += 1
}
return a
}cargo run -- build subjects/example.vt -o subjects/example.s
as -o subjects/example.o subjects/example.sCreate a C wrapper to call functions:
// subjects/main.c
#include <stdio.h>
extern int factorial(int n);
extern int fib(int n);
int main() {
printf("factorial(5) = %d\n", factorial(5));
printf("fib(10) = %d\n", fib(10));
return 0;
}Link and compile:
gcc subjects/main.c subjects/example.o -o subjects/exampleNote that semicolons are optional
- Integers:
i32,i64,isize,usizeetc - Floats:
f32,f64 - Booleans:
bool(withtrueandfalseliterals) - Unit type:
unit(represents empty/void, value as{}) - Structs: User-defined types with named fields, anonymous structs
Variables are declared with let and are immutable by default:
let x: i32 = 42
let y = 3.14; // Type inference
Mutable variables use let mut (when supported).
Functions are declared with the fn keyword:
fn add(a: i32, b: i32): i32 {
return a + b
}
// Expression-oriented: last expression is the return value
fn multiply(a: i32, b: i32): i32 {
a * b
}If expressions:
let max = if a > b { a } else { b }While loops:
while condition {
// loop body
if done { break }
if skip { continue }
}- Arithmetic:
+,-,*,/,% - Comparison:
==,!=,<,>,<=,>= - Logical:
&&,||,! - Assignment:
=,+=,-=,*=,/=,%= - Type casting:
as(e.g.,x as f64)
struct Point {
x: f32,
y: f32
}
struct Entity {
id: i32,
position: {
x: f32,
y: f32
}
}