The Oxigen programming language

Oxigen is a general-purpose language with readable syntax, structs and enums, pattern matching and optional type annotations that are checked when the program runs. Programs compile to bytecode, and a Cranelift JIT compiles the functions called most often to machine code.

Oxigen
introduce strings

main {
    name := "Oxigen"
    println("Hello from {name}!")
    each word in strings.split("read it out loud", " ") {
        println("{word} has {len(word)} letters")
    }
}
Output
Hello from Oxigen!
read has 4 letters
it has 2 letters
out has 3 letters
loud has 4 letters

This runs on the Oxigen interpreter compiled to WebAssembly. Open the playground to edit it.

Learn

Start with the guide to installing Oxigen and writing a first program, then work through the examples.

Download

Latest version: 0.2.3. Prebuilt for Linux and macOS on x86-64 and ARM64.

Documentation

The language guide, and a reference page for each of the 25 standard library modules.

Get involved

Oxigen is developed in the open. Report bugs, suggest changes and send pull requests on GitHub.

The language

Oxigen aims for one obvious way to write each thing, so code reads the same whoever wrote it.

Bytecode VM and JIT

Programs compile to bytecode. A function called about 50 times is compiled to machine code by a Cranelift JIT, without any annotation.

How the JIT works

Named patterns

Write a condition once with pattern, then branch on it with choose. A long chain of if becomes a readable list.

Pattern matching

Optional types

Leave a variable untyped, or declare it <int> and it stays an int. Parameter types are checked on every call.

Type system

Errors as values

An error stops the program unless it is caught. With <Error> it becomes a value you can pass around and inspect later.

Error handling

Structs and enums

Structs with typed fields, methods and single inheritance. Enums with plain, tuple and struct variants.

Structs

Concurrency without shared memory

diverge runs work on another thread and converge collects the result. Tasks exchange values, not memory, so there are no locks.

Concurrency

Standard library

25 modules, including JSON, TOML, regular expressions, an HTTP client and server, TCP and UDP, dates, hashing, files and processes.

Standard library

Embeddable

Run the VM inside a Rust program, grant scripts only the capabilities you choose, and limit how long they may run.

Embedding

Examples

Each example runs in this page. Open one in the playground to change it.

Oxigen
introduce strings

main {
    name := "Oxigen"
    println("Hello from {name}!")
    each word in strings.split("read it out loud", " ") {
        println("{word} has {len(word)} letters")
    }
}

Performance

On the benchmark suite, Oxigen 0.1.4 with the JIT on, which is the default, was faster than CPython 3.14.6 on 10 of 10 programs. The median speed-up was 18×, and the largest 65×, on tight loops. CPython ran with its own JIT enabled.

Without the JIT, the interpreter alone is slower than CPython.

All results and how they were measured

Times faster than CPython 3.14.6Fastest of 5 runs after 3 warm-ups. Longer is better.
  1. Nested loops, large65×
  2. Counting loop53×
  3. Nested loops41×
  4. Primes, serial21×
  5. Primes, parallel19×
  6. Collatz17×
  7. Struct methods7.3×
  8. Closures6.7×
  9. Arithmetic2.5×
  10. Recursive Fibonacci2.3×

Concurrency

diverge each runs a block for every item on a pool of threads and returns the results in order. This example counts the primes below a million on four cores. It needs real threads, so it runs on your machine rather than in the browser.

Concurrency guide

Oxigen
fun is_prime(n <int>) {
    give False when n < 2
    d := 2
    repeat when d * d <= n {
        give False when n % d == 0
        d++
    }
    True
}

fun count_primes(lo <int>, hi <int>) {
    count := 0
    each n in range(lo, hi) {
        count++ when is_prime(n)
    }
    count
}

main {
    counts := diverge each start in [0, 250000, 500000, 750000] {
        count_primes(start, start + 250000)
    }
    total := counts[0] + counts[1] + counts[2] + counts[3]
    println("primes below a million: {total}")
}

Testing and tools

Write <test> blocks with expect(...) and run oxigen test. It finds every *_test.oxi file and exits non-zero when a test fails.

  • oxigen fmt formats code; --check fails when a file isn't formatted.
  • oxigen check prints diagnostics as JSON for editors.
  • oxigen explain E0031 explains an error code.
  • A language server, with a Neovim configuration in the repository.
Oxigen
introduce strings

fun slug(title <str>) { strings.replace(strings.lower(strings.trim(title)), " ", "-") }

<test>("slug lower-cases and hyphenates") {
    expect(slug("  Hello Oxigen ")).eq("hello-oxigen")
}

<test>("slug keeps words in order") {
    expect(slug("A B C")).eq("a-b-c")
}

Who makes Oxigen

Oxigen is designed and built by Javan Hutchinson: the language, the compiler, the bytecode VM, the Cranelift JIT, the standard library, the formatter, the test runner and the language server. The source and the full history are on GitHub.

About the project · Javan Hutchinson on GitHub