Perk
Perk is a modern low level programming language, compiled to C. It builds on C's simplicity, adding features such as option types, lambdas and typeclasses. Its current goal is to replace C in the implementation of the MellOS operating system.
Run Perk with nix
bash
1nix run github:Alex23087/Perk -- [files]
This will build the perkc
compiler and run it directly (you can pass any arguments after --
).
Documentation
We are using ocamldoc
to generate the documentation. Use the command make docs
to generate the documentation.
Integration with C
Import C libraries using import "libname.h"
. The compiler will automatically add most of the prototypes from the C source to the typechecker. This is not yet perfect, and does not yet work for custom include paths (check out this issue), nor does it currently include macros.
Features
1fun main () : int {
2 // No need to write the type here!
3 let x := 3;
4 return 0;
5}
1let position: (float * float) = (200.,200.)
- Option types, with implicit boxing at assignment
1 let z : (int*)? = nothing;
2 z = just &x;
- Typeclass system (Archetypes and Models)
1archetype Drawable {
2 position : (float * float),
3 rotation : float,
4 texture : SDL_Texture*,
5 size : (float * float),
6 draw : SDL -> void
7}
1model Character: Drawable, PhysicsObject {
2 let position: (float * float) = (200.,200.),
3 let velocity: (float * float) = (0., 0.),
4 ...
5
6 fun constructor (sdl : SDL) : void {
7 ...
8 },
9
10 fun draw (sdl : SDL) : void {
11 ...
12 }
13}
- Parametric generic functions through archetype sums
1let f := (x: <Drawable+PhysicsObject>) : void {...}
2
3f(drawable_physics_thing as Drawable+PhysicsObject)
- Capturing anonymous functions
1fun streq (s1 : char*) : char* => int {
2 return (s2 : char*) : int {return (strcmp (s1, s2) == 0)}
3}
- Static subset (only uses the stack, only allows non-capturing lambdas)