Skip to content

SneakySelderey/pollux

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

133 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pollux

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.

Main Features

  • 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, and for
  • 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

Build

Requirements:

  • g++
  • C++17 support
  • A Unix-like environment with mmap/mprotect available for the JIT path

Build the project from the repository root:

make

This produces the executable:

./pollux

To remove the binary:

make clean

Usage

General form:

./pollux <source.plx> [--opt] [--jit] [--dis]

Flags:

  • --opt enables bytecode optimization before execution
  • --jit runs the program with the JIT backend instead of the interpreter
  • --dis prints bytecode disassembly before running

Examples:

./pollux benchmarks/factorial.plx
./pollux benchmarks/opt-test.plx --opt
./pollux benchmarks/factorial.plx --jit
./pollux benchmarks/factorial.plx --dis

Language Overview

Supported 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; }
  • print statements
  • return statements inside functions
  • if, else if, else
  • while loops
  • for loops

Example:

int factorial(int n) {
    if (n < 2) {
        return 1;
    }

    return factorial(n - 1) * n;
}

print factorial(10);

Project Structure

  • main.cpp - CLI entrypoint and compiler pipeline orchestration
  • frontend/ - lexer, tokens, AST, parser
  • middle-end/ - semantic analysis, type checking, bytecode generation
  • backend/ - bytecode interpreter, optimizer, JIT compiler, GC/runtime support
  • benchmarks/ - sample Pollux programs used for testing and benchmarking
  • grammar.md - language grammar reference

Benchmarks and Samples

The benchmarks/ folder contains larger example programs, including:

  • factorial.plx for recursion
  • opt-test.plx for optimizer experiments
  • prime-numbers.plx for loops and arrays
  • quicksort.plx for recursion, array mutation, and large workloads
  • nbody.plx for float-heavy numeric code

Notes and Limitations

  • 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 int and float.

About

Pollux programming language

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors