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:
- Header files and forward declarations you have to update by hand whenever a signature changes.
#include, which is literal text pasting, parsed again and again for every translation unit.- Build systems like Make and CMake, a separate ecosystem you have to learn just to compile the code you already wrote.
- Syntax noise: type-first declarations,
->versus., and pointer stars that bind to the name instead of the type.
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.

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:
- Lexer: tracks row and column per token, and knows that
1..is a number followed by a range operator, not a broken float. - 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.
- AST: a shallow C++ hierarchy, every node carrying its exact source location and an
inferred_typefield that starts empty and gets filled during analysis. - 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.
- 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.

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.

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.
- A real-time ASCII raymarcher: an animated 80×40 shaded sphere at 20 fps in the terminal, timed with
__rdtsc(), using structs, globals, nested loops, static arrays, pointers and foreign math functions in one program. - Pluggable terminal shaders: one fixed renderer and a
shader :: (uv, info, intensity) -> floatfunction you swap out. Plasma and animated rings share the same renderer, and only the brightness function changes. - Conway’s Game of Life: a 50×25 grid, 300 generations, a glider and a blinker, wrapping edges and two buffers swapped between generations. State has to stay correct across thousands of updates, which makes it a good silent correctness check.
- An arena allocator written in Pax
3 An arena is a bump allocator, the same idea as the transpiler’s internal pool. This one is written in Pax itself: it keeps its position in an
Arenastruct, chains blocks in a linked list, aligns every request to 8 bytes, and grows blocks that don’t fit., plus linked-list sorting, deep pointer access and raw casts. This is the largest systems-style demo, importing the built-inString.paxandGeneral.paxmodules. - The standard library itself: General.pax, String.pax and Sort.pax (quicksort and mergesort, no polymorphism in Pax yet, so they work on integer arrays). All of it is written in Pax, which proves the language is self-hosting enough for real library 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.