Threadon

a programming language with C-like performance and Python-like syntax

Threadon 3.0 · release name “Suicidal wasp”

What it is

Threadon is a compiled programming language. It compiles down to LLVM IR, the intermediate language written by the LLVM project. That means no interpreter, no virtual machine, no garbage collector. The code you write is turned straight into native machine code.

Threadon is still young. It has functions, structs, imports, a small standard library, and strict type checking. Some things are not done yet, and this documentation is honest about that. The last page, Limits, lists what's missing.

Here's an example:

struct Point:
    x: Int32
    y: Int32

def length(p: Point) -> Int32
    return p.x * p.x + p.y * p.y

def main() -> Int32
    p: Point = Point(x=3, y=4)
    print(length(p))
    return 0
25

Quick start

You need four things to run Threadon:

Install with pip and you're ready

sudo apt install llvm
pip3 install threadon

The compiler lives in the compiler/ folder. You call it as a Python module. All examples in this documentation assume you run them from the root of the repository.

Put this in a file called hello.th:

def main() -> Int32
    print("Hello, world!")
    return 0

Compile and run it:

python3 -m threadon --run hello.th
Hello, world!

You can also turn it into a real native executable:

python3 -m threadon --exe hello hello.th
./hello

Or just look at the LLVM IR it produces:

python3 -m threadon hello.th

That prints the IR to your terminal. Add -o out.ll to save it to a file. See the command line reference for the full list of flags.

Take the tour

The documentation is split over several pages. Each page covers one topic and stands on its own. Start with Basics if you're new.

Basics

What a program looks like. Comments, indentation, literals, the shape of a file.

Types

Integers, floats, bools, strings, and how values wrap around.

Variables

Declaring and changing variables, and the rules around scope.

Operators

Arithmetic, comparison, and boolean operators. Precedence too.

Casts

Converting between types, including strings to numbers.

Flow

if, elif, else, and how to repeat without loops.

Functions

Defining functions, return rules, recursion, and the entry point.

Structs

Grouping values together, nesting, and reading and writing fields.

Unions

One variable that holds one of several types, with compile-time narrowing.

References

The ^ operator and how to point at a variable.

Builtins

print and input, the two functions always available.

Std lib

The bundled standard library: abs, max, min, and friends.

Imports

Splitting code across files, and all the ways to import.

CLI

Every flag the compiler accepts, and what it does.

Debug

Runtime checks that catch silent bugs while you develop.

Examples

The example programs in the repo, with their output.

Limits

What doesn't work yet, and gotchas that will trip you up.

Reading this documentation

Every code block that produces output is followed by a box showing the output. That box shows exactly what the compiler printed when the code was run.

Some things in Threadon are rough edges right now. They are documented anyway, with a clear note, so you don't waste an hour fighting them. The Limits page collects all of them in one place.

The compiler is the source of truth. If this documentation and the compiler disagree, the compiler wins. If you find something wrong here, that's a bug worth reporting.