I wrote a programming language for my thesis

Pax is a statically typed systems-programming language that transpiles to a single C file. My bachelor's thesis covers both the language design and the complete compiler frontend, written from scratch.

Nov 16, 2026

You can find the thesis paper Transpiler for Pax language, and source code on my GitHub. This was my bachelor’s project at PW in Warsaw, Poland. It was an ambitious projects and I did way too much work then expected of a bachelor’s thesis.

The language is called Pax, a statically typed, imperative systems language that transpiles to C. The thesis covers both the design of the language and a complete compiler frontend written from scratch, with no parser generators or compiler backends frameworks like LLVM.

Why?

Because why not? Compilers are cool and interesting and everyone should learn to write them, even just a simple toy programming language, that way we will appreciate them more. They help us programmers save so much time from writing literal machine code or optimizing away common code patterns. Ultimately, the less code we have to write the better. At the same time a language should also not abstract away powerful and crucial things like pointers and the memory model, especially if your goal is to write fast and memory efficient programs. We want to still keep that power but reduce the everyday friction.

C has been around for over fifty years, and all that time taught us exactly where the friction is. The low-level model is not the problem. Pointers, manual memory and explicit types are good things for systems work. The friction sits around the code:

Pax still keeps the low-level model. It outputs one single C file, so the C compiler stays as the optimisation backend, while everything about the language itself (parsing, semantic analysis, type checking) belongs to the frontend.

Pax source code is transpiled into a single C file.

The language

Name-first declarations

The core idea is not new. Pascal proved decades ago that name: type reads better than C’s type-first style, but Pascal forced declarations into a separate block. Pax uses the name: type = value form proposed by Sean Barrett  1 The unified name: type = value syntax comes from Sean Barrett’s Stu language (2005) and was popularised by Jonathan Blow’s Jai. Go separately introduced := for inference, while Pax unifies explicit and inferred declarations into one form instead of having two different syntaxes. and folds declaration and initialisation into one statement:

x := 42;                  // type inferred (s64)
x: float32;               // explicit type, zero-initialized
x: int = 42;              // explicit type + initializer

student: Student;         // user-defined struct
ptr := &student;          // pointer inferred

result := compute(a, b);  // inferred from the function's return type

Functions use the same shape, with a double colon, the return type at the end, multiple return values, and default and named parameters:

add :: (a: int, b: int) -> int {
    return a + b;
}

divide :: (a: int, b: int) -> int, int {   // two return values
    return a / b, a % b;                   // quotient, remainder
}
q, r := divide(20, 3);

func :: (a: int = 0) { }
func();                                    // a is passed 0

_, b := ret();   // discard the first return value with '_'

Pointers that read left-to-right

Pointer types use a prefix caret attached to the type, not to the name:

// C
int* a, b, c;   // looks like three pointers, but b and c are plain ints
int *a, *b, *c; // the '*' must be repeated for each variable
// PAX
a, b, c: ^int;  // all three are pointers

Arrays read the same way. a: [4]int is an array of four ints, b: ^[]int is a pointer to an array, and c: [4]^int is an array of pointers.

Auto Dereferencing support

C makes you write obj.x for a struct value and obj->x for a pointer. That is pure refactoring friction: turn a value into a pointer and every access site changes. Pax has a single . operator and the compiler inserts the dereferences for you, to any depth:

s: ^Student;
s.name = "Timmy";           // generated C: ((*s).name = "Timmy");
s.supervisor.name = "Alan"; // generated C: ((*(*s).supervisor).name = "Alan");

Dereferencing an uninitialised pointer is still a compile-time error. The convenience is in the syntax, not in giving up safety.

What matters

Syntax isn’t everything, although it can be daunting when you try writing or even look at langauge like Rust (the ugliest programming language the world has ever seen). Besides that, most languages have sort of nailed down the syntax because they try to be familiar enough to get picked up easily and also not force you to fight your existing programming intuition, which is a good thing obviously.

Lets keep that aside, the bigger half is structural.

Order-independent declarations

Functions and structs can be used before they are defined, in any order. There are no forward declarations and no headers in Pax at all.

main :: () {
    local: Student;         // struct defined below
    local.name = "Timmy";
    print_student(&local);  // function defined below
}

print_student :: (s: ^Student) {
    printf("Name:%s\n", s.name);
}

Student :: struct {         // struct defined at the end
    name: string;
    grade: int;
}

Strings and arrays carry their length

In C an array decays to a pointer and the length becomes someone’s guess. In Pax a string is an ordinary struct, not a compiler builtin, and arrays keep .data and .count implicitly:

string :: struct {
    count: s64;
    data:  ^u8;
}

The length travels with the data, so nothing scans for \0 and nobody passes sizes as a separate parameter. The standard library’s String.pax (heap strings, concat, slice, compare) is written in Pax itself, on top of foreign malloc, memcpy and free.

defer. Cleanup runs when the scope exits, last in first out. Acquire and release live next to each other, and early returns cannot orphan them:

ptr := malloc(sizeof(int) * 10);
defer {
    printf("Freeing memory...\n");
    free(ptr);
}
// ... work, with any number of returns and error paths ...

Single-unit compilation

Pax turns the whole project, the entry point plus every transitively imported module, into one AST and emits one C file. The C compiler parses the generated code once, instead of re-parsing the same header stacks for every translation unit. There is no Makefile, no CMake and no incremental-build machinery to babysit.

Interop without pretending

Pax calls C directly through #foreign declarations. The frontend type-checks the call against the signature and then emits the call:

malloc :: (size: s64) -> ^void #foreign;
free   :: (ptr: ^void) #foreign;
printf :: (fmt: ^u8, ..) -> int #foreign;

A crash handler built in

In debug mode the generated C ships with a small Windows-API crash handler, and #line directives map everything back to the Pax source. Crash a program and you get a stack trace in your code:

 --- RUNTIME CRASH STACK TRACE ---

******* C:\pax\tests\demo_runtime_crash_handler.pax:5  deref_null_ptr
        C:\pax\tests\demo_runtime_crash_handler.pax:10  main

 --- END OF STACK TRACE ---

(Stack overflows get a special case. The handler needs stack space to run, so all it can print is STACK OVERFLOW.)

Not just a regular transpiler

Calling Pax a transpiler actually undersells it. Because actually its a full compiler frontend: lexing, parsing, semantic analysis and type inference are completed before any C get emitted. The deal I made with the C compiler is simple. It is purely a code-generation backend. If your Pax code compiles, the generated C is correct. If the C compiler ever complains, that is a bug in my transpiler, not your problem. Errors always point at the line you wrote, never at generated code you never wrote.

The pipeline is the classic one and all of it is handwritten:

  1. Lexer: tracks row and column per token, and knows that 1.. is a number followed by a range operator, not a broken float.
  2. Parser: recursive descent for statements and declarations, and a Pratt parser for expressions  2 Vaughan Pratt, Top Down Operator Precedence, POPL 1973. The old recursive-descent expression parser still exists commented out in the source, as a readable comparison point., where precedence lives in one table instead of one function per level.
  3. AST: a shallow C++ hierarchy, every node carrying its exact source location and an inferred_type field that starts empty and gets filled during analysis.
  4. Semantic analyser: two-pass symbol resolution. Because declarations can be used before they are defined, a single top-to-bottom pass cannot work. Pass one resolves everything currently visible and queues the rest together with the lexical scope they appeared in. Pass two retries them once every declaration is known. Only what fails both passes is a real error.
  5. C converter: walks the fully resolved, typed tree and prints one C file with typedefs, structs topologically sorted so C sees dependencies first, prototypes, globals, bodies and main.

The Pax frontend pipeline, from .pax source through lexer and parser, AST, semantic analyser and C converter to a single C file. The frontend recursively parses imported Pax modules.

What the compiler does behind your back

A friendly surface means the converter has to make a lot of implicit things explicit. My favourite one-liner from the test suite is:

stud.name = "Timmy";   // stud: ^Student

and it becomes:

(((*stud).name) = string{ (u64) 5, (u8*)"Timmy" });

One dereference inserted, one string literal turned into a string struct. Multiple return values do not exist in C, so every such function gets a hidden struct that call sites unpack:

struct divide_ret { int _0; int _1; };
struct divide_ret __pax_uret = divide(20, 3);
int q = __pax_uret._0;
int r = __pax_uret._1;

In debug builds, every statement is also preceded by a #line directive:

#line 5 "C:/pax/tests/demo_if_and_while.pax"
    s64 i = 0;
#line 6 "C:/pax/tests/demo_if_and_while.pax"
    while(((i < 10) && ((i != 5) || false))){

That is what lets the debugger step through Pax source directly, and what feeds the crash handler its file:line pairs. The whole generated file is emitted in one fixed order:

Code emission order

The generated file starts with a small boilerplate that defines the Pax primitive types as C typedefs (u64, s64, float32 and the rest). After that come the struct definitions in dependency order, the function prototypes, the global variables, the function bodies and finally the main entry point. Since Pax does not need forward declarations, the converter emits structs topologically sorted so the C compiler sees them in the correct order. The whole file is written in one fixed sequence, shown below.

Order in which the C converter emits the generated C source file.

So how did I test if all this actually works?

A compiler is only as real as the programs it runs. The thesis test suite has more than 50 test files and over 2500 lines of pure Pax code.

And these are not screenshots. I ran the actual programs and recorded their terminal output. Here is the raymarcher, demo_sphere_shader, at 20 fps:

The plasma shader, demo_shader, at 72×28, looping over a short excerpt. The renderer is fixed and the shader function supplies brightness; the rings effect in the thesis is a different body for the same function:

And Conway’s Game of Life, demo_game_of_life, for all 300 generations. The glider keeps moving diagonally while the blinker keeps blinking:

Finally

None of these ideas are new. Name-first declarations come from Pascal, defer comes from Go, wide pointers show up in every “fat pointer” design, and Pratt parsing is from 1973. The contribution of the thesis is that they were designed together, implemented in one working compiler frontend, and tested heavily.

Pax language design is heavily insipired by Jonathan Blow’s jai language (which is still in closed beta), because I did not want to wait for access to it and I had a project to think about I just decided to write a compiler for it myself. So the Pax compiler is fully written by myself from scratch, and made it run real programs. That felt like the right place to stop for now.

Future work (As if this was not enough)

The next direction for Pax is a native compiler backend. The current frontend already does the heavy lifting and provides the base needed for an intermediate representation and an eventual native LLVM IR or x64 converter. Another future direction is making better use of the stored type information. The compiler already tracks the types of all symbols and expressions, which can later drive automatic struct layout and packing, as well as a Pax-native implementation of C’s printf() with automatic type specifiers. The standard library can also grow further. General.pax, Sort.pax, and String.pax are a good start, so more modules can be added and implemented in Pax itself.