Skip to content

Complete compiler implemented in Haskell, targets x86-64 assembly

Notifications You must be signed in to change notification settings

ArktinenKarpalo/compiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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/

Usage

Compile e.g. file program.src with

cabal run compiler < program.src

Run the resulting binary ./out/main/main

Test

cabal test

With docker

Build

docker build . -t compiler

Test

docker run --rm compiler cabal test

With nix

Develop

Run nix-shell to use shell.nix

Test

Execute test-nix

About

Complete compiler implemented in Haskell, targets x86-64 assembly

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published