Coy is a small programming language with algebraic data types and pattern matching; it has a Rust-like syntax and compiles to LLVM IR.
An extensive example is available at examples/lux.coy,
containing a partial implementation of Ray Tracing in One Weekend.
This example shows off most of Coy's features; it has no arrays, first-class functions, mutable variables, references, etc.
Coy uses stack to manage its build process.
Coy compiles its input to LLVM IR, relying on Clang for code generation. It
targets LLVM 9, because that's what llvm-hs-pretty supports. The provided
clang.nix Nix expression is a convenient way of setting up an
environment with a compatible Clang version through nix-shell.
An an example, let's compile examples/lux.coy.
First, build and run Coy:
$ stack run -- --output=lux.ll examples/lux.coy
This produces a lux.ll file that contains the LLVM IR generated by Coy.
Now, open a shell that contains Clang:
$ nix-shell clang.nix
… compile the LLVM IR generated by Coy:
[nix-shell]$ clang -O3 -o lux lux.ll
… and run the generated executable:
[nix-shell]$ ./lux > lux.ppm
This produces an image in plain PPM format that you can open in your favorite image viewer.