With the release of Azin 0.2.0, I thought I'd make a small blog explaining how the compilation process works so far (and more).
We don't have our own backend (yet), so we transpile to C instead and then compile using 1 of 3 compilers, gcc, clang, or MSVC (whatever is available).
Pipeline so far is source.az -> tokens -> AST -> a C file -> C compiler -> binary
Here's an example program:
importc "stdio.h"
fn fib(n: int): int do
var mut a: int = 0
var mut b: int = 1
var mut i: int = 0
loop
if i == n then
stop
end
var next: int = a + b
a = b
b = next
i = i + 1
end
return a
end
fn main: int do
printf("fib(20) = %d\n", fib(20))
return 0
endazc -o fib fib.az will give you an executable fib that prints fib(20) = 6765. The C generated by this looks like this:
#include <stdio.h>
#include <stdbool.h>
int fib(int n) {
int a = 0;
int b = 1;
int i = 0;
for (;;) {
if (i == n) {
break;
}
const int next = a + b;
a = b;
b = next;
i = i + 1;
}
return a;
}
int main() {
printf("fib(20) = %d\n", fib(20));
return 0;
}
It's readable, pretty close to what you'd write by hand. Viewing what the Azin transpiler generates can be done via the --emit-c flag (azc [options] [source.az])
What's new
loop and stop. An infinite loop and the break statement that gets you out, both in the example above. Forms of the loops are being discussed (e.g. conditional, destructure values, numeric ranges, etc)
bool, true, false. I shouldn't need to explain what booleans are. Lowered onto C's stdbool.h
Better error recovery. The parser now returns BadStmt/BadExpr nodes, so one compile reports all your errors, each with a source line and a caret under the offending token (just like how the cool kids do it)
Optimization levels. Configurable at the CLI via the -O flag (not to be confused with -o)
In later versions, we plan on implementing more cool stuff to make Azin even better than before.
And of course, the code is always freely accessible here. Toodles!