Pollux is a small compiled language project written in C++17. It takes .plx source code through a full pipeline:
source -> lexer -> parser -> type checker -> bytecode generator -> optimizer -> interpreter or JIT
The repository is organized like a teaching compiler, with separate frontend, middle-end, and backend stages plus benchmark programs for stress testing and performance experiments.
- Statically typed language with
int,float,bool,nil, and typed arrays (int[],float[],bool[]) - Variable declarations and assignments
- Arithmetic and comparisons:
+,-,*,/,^,<,>,==,!= - Control flow:
if / else if / else,while, andfor - Functions with typed parameters and typed return values
- Recursive calls
- Dynamic array indexing and assignment
- Bytecode optimizer with constant folding and simple peephole optimizations
- Two execution backends: a bytecode interpreter and a JIT compiler
- Optional bytecode disassembly for debugging
Requirements:
g++- C++17 support
- A Unix-like environment with
mmap/mprotectavailable for the JIT path
Build the project from the repository root:
makeThis produces the executable:
./polluxTo remove the binary:
make cleanGeneral form:
./pollux <source.plx> [--opt] [--jit] [--dis]Flags:
--optenables bytecode optimization before execution--jitruns the program with the JIT backend instead of the interpreter--disprints bytecode disassembly before running
Examples:
./pollux benchmarks/factorial.plx
./pollux benchmarks/opt-test.plx --opt
./pollux benchmarks/factorial.plx --jit
./pollux benchmarks/factorial.plx --disSupported constructs in Pollux include:
- Primitive types:
int,float,bool - Array types:
int[],float[],bool[] - Literals: integers, floats,
true,false,nil - Blocks with lexical scoping via
{ ... } - Variable declarations with optional initialization
- Sized arrays such as
int data[100]; - Function declarations such as
int add(int a, int b) { return a + b; } printstatementsreturnstatements inside functionsif,else if,elsewhileloopsforloops
Example:
int factorial(int n) {
if (n < 2) {
return 1;
}
return factorial(n - 1) * n;
}
print factorial(10);main.cpp- CLI entrypoint and compiler pipeline orchestrationfrontend/- lexer, tokens, AST, parsermiddle-end/- semantic analysis, type checking, bytecode generationbackend/- bytecode interpreter, optimizer, JIT compiler, GC/runtime supportbenchmarks/- sample Pollux programs used for testing and benchmarkinggrammar.md- language grammar reference
The benchmarks/ folder contains larger example programs, including:
factorial.plxfor recursionopt-test.plxfor optimizer experimentsprime-numbers.plxfor loops and arraysquicksort.plxfor recursion, array mutation, and large workloadsnbody.plxfor float-heavy numeric code
- The current integer type is implemented with C++
long long, so very large integer results can overflow. - Type checking is strict: there are no implicit numeric conversions between
intandfloat.