Complete compiler implemented in Haskell.
It will compile language described in spec.md into x86-64 Assembly language.
All stages are implemented purely in Haskell: Tokenizing, Parsing, Type checking, IR generation, assembly generation.
Example program:
fun collatz(n: Int): Unit {
print_int(n);
while n > 1 do {
if n % 2 == 0 then {
n = n / 2;
} else {
n = 3 * n + 1;
};
print_int(n);
}
}
var n: Int = read_int();
collatz(n);
More example programs in test_suite/
Compile e.g. file program.src with
cabal run compiler < program.src
Run the resulting binary ./out/main/main
Test
cabal test
Build
docker build . -t compiler
Test
docker run --rm compiler cabal test
Develop
Run nix-shell to use shell.nix
Test
Execute test-nix